R5-X2 - Calculation of the line-integrated plasma bremsstrahlung emission (for parallel processing or GPU) Calculation of the line-integrated plasma bremsstrahlung emission (for parallel processing or GPU) by Yves Peysson(CEA/IRFM,yves.peysson@cea.fr) and Joan Decker (CEA/IRFM,joan.decker@cea.fr)
0001 function [brem_bd_out,lchord] = loop_brem_chord_yp(mode,kphot,cL,ZZIB,datahxr_in) 0002 %R5-X2 - Calculation of the line-integrated plasma bremsstrahlung emission (for parallel processing or GPU) 0003 % 0004 % Calculation of the line-integrated plasma bremsstrahlung emission (for parallel processing or GPU) 0005 % 0006 % by Yves Peysson(CEA/IRFM,yves.peysson@cea.fr) and Joan Decker (CEA/IRFM,joan.decker@cea.fr) 0007 % 0008 s_mask = ~isnan(datahxr_in.vschords(7,:));%Location where chord is inside the plasma 0009 s_length = sum(s_mask);%Number of points along the chord inside the plasma 0010 ir_spsi = datahxr_in.vschords(8,s_mask); 0011 it_st = datahxr_in.vschords(9,s_mask); 0012 % 0013 n_pol = size(cL,1) - 1; 0014 nk = length(kphot); 0015 % 0016 IB1 = zeros(n_pol + 1,s_length,nk); 0017 % 0018 nstep = 199;%In order to avoid use of too large multidimensional tables (limitation of MatLab) 0019 jmax = floor(s_length/nstep)+1; 0020 % 0021 index_test = [(jmax-1)*nstep+1:jmax*nstep]; 0022 index_test = index_test(index_test<=s_length); 0023 if length(index_test) == 1,%In order to avoid this case which generates an error for the line "IB1(:,index,:) = permute(squeeze(IB(:,1,:,:)),[2,1,3]);" 0024 nstep = nstep - 1; 0025 jmax = floor(s_length/nstep)+1; 0026 end 0027 % 0028 for j = 1:jmax, 0029 index = [(j-1)*nstep+1:j*nstep]; 0030 index = index(index<=s_length); 0031 if isempty(index) ~= 1 0032 IB = ZZIB(ir_spsi(index),it_st(index),:,:); 0033 IB1(:,index,:) = permute(squeeze(IB(:,1,:,:)),[2,1,3]); 0034 end 0035 end 0036 % 0037 sksid = datahxr_in.vschords(10,s_mask);%nothing when taking the exact magnetic topology 0038 if mode == 0, 0039 sksid = sksid*0;%exact perpendicular observation, no heliticity effect 0040 elseif mode == 1, 0041 sksid = sksid*0 + 1;%exact forward observation, no heliticity effect 0042 elseif mode == -1, 0043 sksid = sksid*0 - 1;%exact backward observation, no heliticity effect 0044 end 0045 % 0046 [Pm_bd] = leg_dke_yp(sksid,n_pol);%Legendre polynomial for the cosine of the angle between magnetic field line and line of sight (negative sign because electrons are flowing in the opposite direction to the plasma current) 0047 Pm_bd1 = repmat(Pm_bd,[1,1,length(kphot)]); 0048 % 0049 cL1 = repmat(cL,[1,length(ir_spsi),nk]); 0050 % 0051 brem_bd = squeeze(sum(Pm_bd1.*IB1.*cL1,1));%Local bremsstrahlung emission in the direction of the detector 0052 % 0053 s = datahxr_in.vschords(1,s_mask); 0054 if size(s,2) > 0 0055 s = s - s(1);%s=0 where the chord enter the plasma towards the detector 0056 ds = [diff(s),0];%Elementary chord length for integration 0057 ds1 = repmat(ds',[1,nk]); 0058 % 0059 brem_bd_out = sum(ds1.*brem_bd,1)*datahxr_in.EG_hxr;%Integration along the chord and multiplication by the geometrical factor 0060 lchord = sum(ds);%Chord length calculation 0061 else 0062 brem_bd_out = zeros(1,nk);%Integration along the chord and multiplication by the geometrical factor 0063 lchord = 0;%Chord length calculation 0064 end 0065 %