0001 function [varargout] = Bfit_dke_ds(theta,psin,equil,equil_fit,Bsolve)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 5, Bsolve = 0;end
0023
0024 rho = psi2rho_jd(equil,psin);
0025
0026 Bx_a0_fit = ppval_yp(equil_fit.Bx_fit.pp_a0,rho);
0027 Bx_an_fit = ppval_yp(equil_fit.Bx_fit.pp_an,rho);
0028 Bx_bn_fit = ppval_yp(equil_fit.Bx_fit.pp_bn,rho);
0029
0030 By_a0_fit = ppval_yp(equil_fit.By_fit.pp_a0,rho);
0031 By_an_fit = ppval_yp(equil_fit.By_fit.pp_an,rho);
0032 By_bn_fit = ppval_yp(equil_fit.By_fit.pp_bn,rho);
0033
0034 BPHI_a0_fit = ppval_yp(equil_fit.BPHI_fit.pp_a0,rho);
0035 BPHI_an_fit = ppval_yp(equil_fit.BPHI_fit.pp_an,rho);
0036 BPHI_bn_fit = ppval_yp(equil_fit.BPHI_fit.pp_bn,rho);
0037
0038
0039
0040 [BR_fit,dBRdtheta_fit] = calcval_yp(equil_fit,theta,Bx_a0_fit(:),Bx_an_fit,Bx_bn_fit);
0041 [BZ_fit,dBZdtheta_fit] = calcval_yp(equil_fit,theta,By_a0_fit(:),By_an_fit,By_bn_fit);
0042 [BPHI_fit,dBPHIdtheta_fit] = calcval_yp(equil_fit,theta,BPHI_a0_fit(:),BPHI_an_fit,BPHI_bn_fit);
0043
0044 BP_fit = sqrt(BR_fit(:).^2 + BZ_fit(:).^2);
0045 dBPdtheta_fit = (BR_fit(:).*dBRdtheta_fit(:) + BZ_fit(:).*dBZdtheta_fit(:))./BP_fit(:);
0046
0047 B_fit = sqrt(BR_fit(:).^2 + BZ_fit(:).^2 + BPHI_fit(:).^2);
0048 dBdtheta_fit = (BR_fit(:).*dBRdtheta_fit(:) + BZ_fit(:).*dBZdtheta_fit(:) + BPHI_fit(:).*dBPHIdtheta_fit(:))./B_fit(:);
0049
0050 B_fitsolve = B_fit - Bsolve;
0051
0052 if nargout >= 1, varargout{1} = B_fitsolve;end
0053 if nargout >= 2, varargout{2} = dBdtheta_fit;end