Calculate charged fusion product count rate and weight function using a fast-ion distribution function F(E,p,r,z)
subroutine cfpd_f
!+ Calculate charged fusion product count rate and weight function using a fast-ion distribution function F(E,p,r,z)
real(Float64), dimension(3) :: vi, vi_norm, v3_xyz, xyz, r_gyro
type(LocalProfiles) :: plasma
type(LocalEMFields) :: fields
real(Float64) :: pgyro, vnet_square, factor, vabs
real(Float64) :: eb, pitch, erel, rate, kappa, gyro, fbm_denf
integer :: ie, ip, ich, ie3, iray, ist, cnt
if(.not.any(thermal_mass.eq.H2_amu)) then
write(*,'(T2,a)') 'CFPD_F: Thermal Deuterium is not present in plasma'
return
endif
if(any(thermal_mass.eq.H3_amu)) then
write(*,'(T2,a)') 'CFPD_F: D-T cfpd production is not implemented'
endif
if(beam_mass.ne.H2_amu) then
write(*,'(T2,a)') 'CFPD_F: Fast-ion species is not Deuterium'
return
endif
allocate(cfpd%flux(ctable%nenergy, ctable%nchan))
allocate(cfpd%prob(ctable%nenergy, ctable%nchan))
allocate(cfpd%gam(ctable%nenergy, ctable%nchan))
allocate(cfpd%weight(ctable%nenergy, ctable%nchan, fbm%nenergy, fbm%npitch))
cfpd%flux = 0.d0
cfpd%prob = 0.d0
cfpd%gam = 0.d0
cfpd%weight = 0.d0
rate = 0.d0
factor = 0.5d0*fbm%dE*fbm%dp*ctable%dl !0.5 for TRANSP-pitch (E,p) space factor
!$OMP PARALLEL DO schedule(guided) private(vi,vi_norm,v3_xyz,xyz,r_gyro,plasma,fields,pgyro,&
!$OMP& vnet_square,vabs,eb,pitch,erel,rate,kappa,gyro,fbm_denf,ie,ip,ich,ie3,iray,ist,cnt)
channel_loop: do ich=1, ctable%nchan
E3_loop: do ie3=1, ctable%nenergy
cnt = 0
ray_loop: do iray=1, ctable%nrays
step_loop: do ist=1, ctable%nsteps
if (ist.gt.ctable%nactual(ie3,iray,ich)) cycle ray_loop
!! Calculate position and velocity in beam coordinates
call convert_sightline_to_xyz(ie3, ist, iray, ich, xyz, v3_xyz)
!! Get fields at sightline position
call get_fields(fields, pos=xyz)
if(.not.fields%in_plasma) cycle step_loop
!! Get plasma parameters at sightline position
call get_plasma(plasma, pos=xyz)
if(.not.plasma%in_plasma) cycle step_loop
!! Loop over energy/pitch/gamma
pitch_loop: do ip = 1, fbm%npitch
pitch = fbm%pitch(ip)
energy_loop: do ie =1, fbm%nenergy
eb = fbm%energy(ie)
!! Get the probability factor
call get_pgyro(fields,ctable%earray(ie3),eb,pitch,plasma,v3_xyz,pgyro,gyro)
if (pgyro.le.0.d0) cycle energy_loop
cnt = cnt + 1
!! Calculate fast-ion velocity
call pitch_to_vec(pitch, gyro, fields, vi_norm)
vabs = sqrt(eb/(v2_to_E_per_amu*fbm%A))
vi = vi_norm*vabs
!!Correct for gyro orbit
call gyro_step(vi,fields,fbm%A,r_gyro)
fbm_denf=0
if (inputs%dist_type.eq.1) then
!get F at guiding center position
call get_ep_denf(eb,pitch,fbm_denf,pos=(xyz+r_gyro))
endif
if (fbm_denf.ne.fbm_denf) cycle energy_loop
!! Calculate effective beam energy
vnet_square=dot_product(vi-plasma%vrot,vi-plasma%vrot) ![cm/s]
erel = v2_to_E_per_amu*fbm%A*vnet_square ![kev]
!! Get the cfpd production rate and anisotropy term
call get_dd_rate(plasma, erel, rate, branch=1)
call get_ddpt_anisotropy(plasma, vi, v3_xyz, kappa)
!$OMP CRITICAL(cfpd_weight)
cfpd%weight(ie3,ich,ie,ip) = cfpd%weight(ie3,ich,ie,ip) &
+ rate * kappa * pgyro &
* ctable%daomega(ie3,iray,ich) &
* factor / (fbm%dE*fbm%dp)
cfpd%prob(ie3,ich) = cfpd%prob(ie3,ich) + pgyro
cfpd%gam(ie3,ich) = cfpd%gam(ie3,ich) + gyro
cfpd%flux(ie3,ich) = cfpd%flux(ie3,ich) + rate * kappa * pgyro &
* ctable%daomega(ie3,iray,ich) &
* fbm_denf * factor
!$OMP END CRITICAL(cfpd_weight)
enddo energy_loop
enddo pitch_loop
enddo step_loop
enddo ray_loop
!$OMP CRITICAL(pweight_cnt)
cfpd%prob(ie3,ich) = cfpd%prob(ie3,ich) / cnt
cfpd%gam(ie3,ich) = cfpd%gam(ie3,ich) / cnt
!$OMP END CRITICAL(pweight_cnt)
enddo E3_loop
enddo channel_loop
!$OMP END PARALLEL DO
#ifdef _MPI
call parallel_sum(cfpd%flux)
call parallel_sum(cfpd%weight)
call parallel_sum(cfpd%prob)
call parallel_sum(cfpd%gam)
#endif
if(inputs%verbose.ge.1) then
write(*,'(30X,a)') ''
write(*,*) 'write charged fusion products: ' , time_string(time_start)
endif
#ifdef _MPI
if(my_rank().eq.0) call write_cfpd_weights()
#else
call write_cfpd_weights()
#endif
end subroutine cfpd_f