dcx Subroutine

public subroutine dcx()

Calculates Direct Charge Exchange (DCX) neutral density and spectra

Arguments

None

Calls

proc~~dcx~~CallsGraph proc~dcx dcx proc~get_nlaunch get_nlaunch proc~dcx->proc~get_nlaunch proc~track track proc~dcx->proc~track interface~store_neutrals store_neutrals proc~dcx->interface~store_neutrals proc~get_plasma get_plasma proc~dcx->proc~get_plasma proc~mc_halo mc_halo proc~dcx->proc~mc_halo proc~in_plasma in_plasma proc~track->proc~in_plasma proc~get_indices get_indices proc~track->proc~get_indices proc~store_neutrals_track store_neutrals_track interface~store_neutrals->proc~store_neutrals_track proc~store_neutrals_cell store_neutrals_cell interface~store_neutrals->proc~store_neutrals_cell proc~get_plasma->proc~in_plasma proc~mc_halo->proc~get_plasma proc~randu randu proc~mc_halo->proc~randu proc~randn randn proc~mc_halo->proc~randn proc~rng_uniform rng_uniform proc~randu->proc~rng_uniform omp_get_thread_num omp_get_thread_num proc~randu->omp_get_thread_num interface~interpol_coeff interpol_coeff proc~in_plasma->interface~interpol_coeff proc~xyz_to_uvw xyz_to_uvw proc~in_plasma->proc~xyz_to_uvw proc~randn->omp_get_thread_num proc~rng_normal rng_normal proc~randn->proc~rng_normal proc~interpol2d_coeff interpol2D_coeff interface~interpol_coeff->proc~interpol2d_coeff proc~interpol1d_coeff interpol1D_coeff interface~interpol_coeff->proc~interpol1d_coeff proc~interpol2d_coeff_arr interpol2D_coeff_arr interface~interpol_coeff->proc~interpol2d_coeff_arr proc~interpol1d_coeff_arr interpol1D_coeff_arr interface~interpol_coeff->proc~interpol1d_coeff_arr proc~rng_normal->proc~rng_uniform proc~interpol2d_coeff_arr->proc~interpol2d_coeff proc~interpol1d_coeff_arr->proc~interpol1d_coeff

Called by

proc~~dcx~~CalledByGraph proc~dcx dcx program~fidasim fidasim program~fidasim->proc~dcx

Contents

Source Code

dcx

Source Code

subroutine dcx
    !+ Calculates Direct Charge Exchange (DCX) neutral density and spectra
    integer :: i,j,k !indices of cells
    integer(Int64) :: idcx !! counter
    real(Float64), dimension(3) :: ri    !! start position
    real(Float64), dimension(3) :: vihalo
    integer,dimension(3) :: ind    !! actual cell
    integer,dimension(3) :: neut_types = [1,2,3]
    !! Determination of the CX probability
    type(LocalProfiles) :: plasma
    real(Float64), dimension(nlevs) :: denn    !!  neutral dens (n=1-4)
    real(Float64), dimension(nlevs) :: rates    !!  CX rates
    !! Collisiional radiative model along track
    real(Float64), dimension(nlevs) :: states  ! Density of n-states
    integer :: ncell
    type(ParticleTrack), dimension(beam_grid%ntrack) :: tracks  !! Particle tracks
    integer :: jj       !! counter along track
    real(Float64):: tot_denn, photons  !! photon flux
    real(Float64), dimension(beam_grid%nx,beam_grid%ny,beam_grid%nz) :: papprox, nlaunch !! approx. density
    real(Float64) :: papprox_tot, ccnt, inv_ng, r_nlaunchijk

    halo_iter_dens(halo_type) = 0.d0
    papprox=0.d0
    papprox_tot=0.d0
    tot_denn=0.d0
    do k=1,beam_grid%nz
        do j=1,beam_grid%ny
            do i=1,beam_grid%nx
                ind = [i,j,k]
                call get_plasma(plasma,ind=ind)
                tot_denn = sum(neut%dens(:,nbif_type,i,j,k)) + &
                           sum(neut%dens(:,nbih_type,i,j,k)) + &
                           sum(neut%dens(:,nbit_type,i,j,k))
                papprox(i,j,k)= tot_denn*(plasma%denp-plasma%denf)
                if(plasma%in_plasma) papprox_tot=papprox_tot+papprox(i,j,k)
            enddo
        enddo
    enddo

    call get_nlaunch(inputs%n_dcx,papprox,papprox_tot,nlaunch)

    if(inputs%verbose.ge.1) then
       write(*,'(T6,"# of markers: ",i9)') int(sum(nlaunch),Int64)
    endif

    ccnt=0.d0
    inv_ng = 100.0/real(beam_grid%ngrid)
    !$OMP PARALLEL DO collapse(3) schedule(dynamic,1) private(k,j,i,idcx,ind,vihalo, &
    !$OMP& ri,tracks,ncell,rates,denn,states,jj,photons,plasma,r_nlaunchijk)
    loop_along_z: do k = 1, beam_grid%nz
        loop_along_y: do j = 1, beam_grid%ny
            loop_along_x: do i = 1, beam_grid%nx
                !! Loop over the markers
                loop_over_dcx: do idcx=1,int(nlaunch(i,j,k),Int64)
                    !! Calculate ri,vhalo and track
                    ind = [i, j, k]
                    r_nlaunchijk = 1.d0/nlaunch(i,j,k)
                    call mc_halo(ind,vihalo,ri)
                    call track(ri,vihalo,tracks,ncell)
                    if(ncell.eq.0) cycle loop_over_dcx

                    !! Calculate CX probability
                    call get_beam_cx_rate(tracks(1)%ind,ri,vihalo,thermal_ion,neut_types,rates)
                    if(sum(rates).le.0.) cycle loop_over_dcx

                    !! Solve collisional radiative model along track
                    call get_plasma(plasma,pos=tracks(1)%pos)

                    !! Weight CX rates by ion source density
                    states = rates*(plasma%denp - plasma%denf)

                    loop_along_track: do jj=1,ncell
                        call get_plasma(plasma,pos=tracks(jj)%pos)

                        call colrad(plasma,thermal_ion,vihalo,tracks(jj)%time,states,denn,photons)
                        tracks(jj)%dens = denn*r_nlaunchijk

                        if((photons.gt.0.d0).and.(inputs%calc_bes.ge.1)) then
                          call store_bes_photons(tracks(jj)%pos,vihalo,photons*r_nlaunchijk,halo_type)
                        endif

                    enddo loop_along_track
                    call store_neutrals(tracks, ncell, halo_type)
                enddo loop_over_dcx
                ccnt=ccnt+1
                if (inputs%verbose.ge.2)then
                    WRITE(*,'(f7.2,"% completed",a,$)') ccnt*inv_ng,char(13)
                endif
            enddo loop_along_x
        enddo loop_along_y
    enddo loop_along_z

end subroutine dcx