Calculate neutron emission rate using a fast-ion distribution function F(E,p,r,z)
subroutine neutron_f
!+ Calculate neutron emission rate using a fast-ion distribution function F(E,p,r,z)
integer :: ir, iphi, iz, ie, ip, igamma, ngamma
type(LocalProfiles) :: plasma
type(LocalEMFields) :: fields
real(Float64) :: eb,pitch
real(Float64) :: erel, rate
real(Float64), dimension(3) :: ri
real(Float64), dimension(3) :: vi
real(Float64), dimension(3) :: uvw, uvw_vi
real(Float64) :: vnet_square, factor
real(Float64) :: s, c
if(.not.any(thermal_mass.eq.H2_amu)) then
write(*,'(T2,a)') 'NEUTRON_F: Thermal Deuterium is not present in plasma'
return
endif
if(any(thermal_mass.eq.H3_amu)) then
write(*,'(T2,a)') 'NEUTRON_F: D-T neutron production is not implemented'
endif
if(beam_mass.ne.H2_amu) then
write(*,'(T2,a)') 'NEUTRON_F: Fast-ion species is not Deuterium'
return
endif
if(inputs%calc_neutron.ge.2) then
allocate(neutron%weight(fbm%nenergy,fbm%npitch,fbm%nr,fbm%nz,fbm%nphi))
neutron%weight = 0.d0
allocate(neutron%emis(fbm%nr,fbm%nz,fbm%nphi))
neutron%emis = 0.d0
endif
ngamma = 20
rate = 0
!$OMP PARALLEL DO schedule(guided) private(fields,vi,ri,pitch,eb,&
!$OMP& ir,iphi,iz,ie,ip,igamma,plasma,factor,uvw,uvw_vi,vnet_square,rate,erel,s,c)
z_loop: do iz = istart, fbm%nz, istep
r_loop: do ir=1, fbm%nr
phi_loop: do iphi = 1, fbm%nphi
!! Calculate position
if(fbm%nphi.eq.1) then
s = 0.d0
c = 1.d0
else
s = sin(fbm%phi(iphi))
c = cos(fbm%phi(iphi))
endif
uvw(1) = fbm%r(ir)*c
uvw(2) = fbm%r(ir)*s
uvw(3) = fbm%z(iz)
!! Get fields
call get_fields(fields,pos=uvw,input_coords=1)
if(.not.fields%in_plasma) cycle r_loop
factor = fbm%r(ir)*fbm%dE*fbm%dp*fbm%dr*fbm%dz*fbm%dphi/ngamma
!! 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)
gyro_loop: do igamma=1, ngamma
call gyro_correction(fields,eb,pitch,fbm%A,ri,vi)
!! Get plasma parameters at particle position
call get_plasma(plasma,pos=ri)
if(.not.plasma%in_plasma) cycle gyro_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 neutron production rate
call get_dd_rate(plasma, erel, rate, branch=2)
if(inputs%calc_neutron.ge.2) then
neutron%weight(ie,ip,ir,iz,iphi) = neutron%weight(ie,ip,ir,iz,iphi) &
+ rate * factor
!$OMP CRITICAL(neutron_emis)
neutron%emis(ir,iz,iphi) = neutron%emis(ir,iz,iphi) &
+ rate * fbm%f(ie,ip,ir,iz,iphi) &
* factor
!$OMP END CRITICAL(neutron_emis)
endif
rate = rate*fbm%f(ie,ip,ir,iz,iphi)*factor
!! Store neutrons
call store_neutrons(rate)
enddo gyro_loop
enddo energy_loop
enddo pitch_loop
enddo phi_loop
enddo r_loop
enddo z_loop
!$OMP END PARALLEL DO
#ifdef _MPI
call parallel_sum(neutron%rate)
if(inputs%calc_neutron.ge.2) then
call parallel_sum(neutron%weight)
call parallel_sum(neutron%emis)
endif
#endif
if(inputs%verbose.ge.1) then
write(*,'(T4,A,ES14.5," [neutrons/s]")') 'Rate: ',sum(neutron%rate)
write(*,'(30X,a)') ''
write(*,*) 'write neutrons: ' , time_string(time_start)
endif
#ifdef _MPI
if(my_rank().eq.0) call write_neutrons()
#else
call write_neutrons()
#endif
end subroutine neutron_f