Skip to content

Commit

Permalink
Added analytic AORSA fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashika Ghai committed Aug 2, 2023
1 parent e684722 commit 27d708e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/korc_fields.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,7 @@ subroutine initialize_fields(params,F)
F%AORSA_AMP_Scale=AORSA_AMP_Scale
F%AORSA_freq=AORSA_freq
F%AORSA_nmode=AORSA_nmode
F%AORSA_mmode=AORSA_mmode
F%width=width
F%psir=psir
F%useLCFS = useLCFS
Expand Down
2 changes: 2 additions & 0 deletions src/korc_initialize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ subroutine initialize_particles(params,F,P,spp)
spp(ii)%sigmaZ = sigmaZ(ii)
spp(ii)%theta_gauss = theta_gauss(ii)
spp(ii)%psi_max = psi_max(ii)
spp(ii)%PSIp_min=PSIp_min(ii)
spp(ii)%Spong_w = Spong_w(ii)
spp(ii)%Spong_b = Spong_b(ii)
spp(ii)%Spong_dlam = Spong_dlam(ii)
Expand Down Expand Up @@ -652,6 +653,7 @@ subroutine initialize_particles(params,F,P,spp)
DEALLOCATE(sigmaZ)
DEALLOCATE(theta_gauss)
DEALLOCATE(psi_max)
DEALLOCATE(PSIp_min)
DEALLOCATE(Spong_b)
DEALLOCATE(Spong_w)
DEALLOCATE(Spong_dlam)
Expand Down
8 changes: 5 additions & 3 deletions src/korc_input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module korc_input
REAL(rp), DIMENSION(:), ALLOCATABLE :: sigmaR
REAL(rp), DIMENSION(:), ALLOCATABLE :: sigmaZ
REAL(rp), DIMENSION(:), ALLOCATABLE :: theta_gauss
REAL(rp), DIMENSION(:), ALLOCATABLE :: psi_max
REAL(rp), DIMENSION(:), ALLOCATABLE :: psi_max,PSIp_min
!! Maximum value of the argument of the 2D gaussian exponential, used for an
!! indicator function that limits the region of MH sampling
! goes as R^2 for HOLLMANN-3D, is psiN_max for HOLLMANN-3D-PSI
Expand Down Expand Up @@ -212,6 +212,7 @@ module korc_input
REAL(rp) :: psir=0.0
REAL(rp) :: width=0.0
REAL(rp) :: AORSA_nmode=0.0
REAL(rp) :: AORSA_mmode=0.0
CHARACTER(30) :: Analytic_IWL='NONE'
INTEGER :: ntiles=42
REAL(rp) :: circumradius=1.016
Expand Down Expand Up @@ -446,7 +447,7 @@ subroutine read_namelist(params,infile,echo_in,outdir)
NAMELIST /plasma_species/ ppp,q,m,Eno,etao,Eo_lims,etao_lims,runaway, &
spatial_distribution,energy_distribution,pitch_distribution,Ro, &
PHIo,Zo,r_inner,r_outter,falloff_rate,shear_factor,sigmaR,sigmaZ, &
theta_gauss,psi_max,Xtrace,Spong_b,Spong_w,Spong_dlam,dth,dR,dZ,dgam,&
theta_gauss,psi_max,PSIp_min,Xtrace,Spong_b,Spong_w,Spong_dlam,dth,dR,dZ,dgam,&
pinit
NAMELIST /analytical_fields_params/ Bo,minor_radius,major_radius,&
qa,qo,Eo,current_direction,nR,nZ,nPHI,dim_1D,dt_E_SC,Ip_exp, &
Expand All @@ -455,7 +456,7 @@ subroutine read_namelist(params,infile,echo_in,outdir)
axisymmetric_fields, Eo,E_dyn,E_pulse,E_width,res_double, &
dim_1D,dt_E_SC,Ip_exp,PSIp_lim,Dim2x1t,t0_2x1t,E_2x1t,ReInterp_2x1t, &
ind0_2x1t,PSIp_0,B1field,psip_conv,MARS_AMP_Scale,Analytic_IWL, &
ntiles,circumradius,AORSA_AMP_Scale,AORSA_freq,AORSA_nmode,width,psir,E1field, &
ntiles,circumradius,AORSA_AMP_Scale,AORSA_freq,AORSA_nmode,AORSA_mmode,width,psir,E1field, &
useLCFS
NAMELIST /plasmaProfiles/ radius_profile,ne_profile,neo,n_ne,a_ne, &
Te_profile,Teo,n_Te,a_Te,n_REr0,n_tauion,n_lamfront,n_lamback, &
Expand Down Expand Up @@ -548,6 +549,7 @@ subroutine read_namelist(params,infile,echo_in,outdir)
ALLOCATE(sigmaZ(num_species))
ALLOCATE(theta_gauss(num_species))
ALLOCATE(psi_max(num_species))
ALLOCATE(PSIp_min(num_species))
ALLOCATE(falloff_rate(num_species))
ALLOCATE(energy_distribution(num_species))
ALLOCATE(pitch_distribution(num_species))
Expand Down
44 changes: 26 additions & 18 deletions src/korc_interp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ subroutine initialize_fields_interpolant(params,F)
b1Refield_2dx%X%x1 = F%X%R
b1Refield_2dx%X%x2 = F%X%Z

!write(output_unit_write,'("R",E17.10)') F%X%R
!write(output_unit_write,'("Z",E17.10)') F%X%Z
! write(6,'("R",E17.10)') F%X%R
! write(6,'("Z",E17.10)') F%X%Z

call EZspline_setup(b1Refield_2dx%X, F%B1Re_2DX%X, ezerr, .TRUE.)
call EZspline_error(ezerr)
Expand Down Expand Up @@ -3325,7 +3325,7 @@ subroutine interp_FOfields_aorsa(prtcls, F, params)

psip_conv=F%psip_conv
amp=F%AMP
mmode=40
mmode=F%AORSA_mmode
nmode=F%AORSA_nmode


Expand Down Expand Up @@ -3359,23 +3359,27 @@ subroutine interp_FOfields_aorsa(prtcls, F, params)
B0_Z = -psip_conv*A(1,2)/prtcls%Y(pp,1)

cnP=cos(mmode*theta-nmode*Y_PHI)
snP=sin(mmode*theta-nmode*Y_PHI)
!snP=sin(nmode*Y_PHI)

cP=cos(Y_PHI)
!sP=sin(Y_PHI)
BXavg=6.95E-07/params%cpp%Bo
BYavg=1.184E-06/params%cpp%Bo
BZavg=1.118E-06/params%cpp%Bo
BXavg=6.95E-07/params%cpp%Bo
BYavg=1.184E-06/params%cpp%Bo
BZavg=1.118E-06/params%cpp%Bo
! BXavg=0.0
! BYavg=0.0
! BZavg=0.0
B1_X = amp*(BXavg*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*cnp)
B1_Y = amp*(BYavg*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*cnp)
B1_Z = amp*(BZavg*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*cnp)
B1_Y = amp*(BYavg*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*snp)
B1_Z =-amp*(BZavg*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*cnp)

EXavg=76.2/params%cpp%Eo
EYavg=57.7/params%cpp%Eo
EZavg=9.25/params%cpp%Eo
E1_X= amp*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*EXavg*cnp
E1_X= amp*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*EXavg*snp
E1_Y= amp*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*EYavg*cnp
E1_Z= amp*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*EZavg*cnp
E1_Z=-amp*((1/cosh((prtcls%PSI_P-psirr)/widthh))**2)*EZavg*snp
prtcls%E(pp,1)=E1_X(1)
prtcls%E(pp,2)=E1_Y(1)
prtcls%E(pp,3)=E1_Z(1)
Expand Down Expand Up @@ -3444,7 +3448,7 @@ subroutine interp_FOfields_aorsa_p(time,params,pchunk,F,Y_R,Y_PHI,Y_Z, &
amp=F%AMP
nmode=F%AORSA_nmode
omega=2*C_PI*F%AORSA_freq
mmode=40
mmode=F%AORSA_mmode

call check_if_in_fields_domain_p(pchunk,F,Y_R,Y_PHI,Y_Z,flag_cache)

Expand Down Expand Up @@ -3479,13 +3483,17 @@ subroutine interp_FOfields_aorsa_p(time,params,pchunk,F,Y_R,Y_PHI,Y_Z, &


cnP(cc)=cos(mmode*theta(cc)-omega*params%time-nmode*Y_PHI(cc))
snP(cc)=sin(mmode*theta(cc)-omega*params%time-nmode*Y_PHI(cc))
! snP(cc)=sin(mmode*theta-omega*time-nmode*Y_PHI(cc))
BXavg=6.95E-07/params%cpp%Bo
BYavg=1.184E-06/params%cpp%Bo
BZavg=1.118E-06/params%cpp%Bo
BXavg=6.95E-07/params%cpp%Bo
BYavg=1.184E-06/params%cpp%Bo
BZavg=1.118E-06/params%cpp%Bo
! BXavg=0.0
! BYavg=0.0
! BZavg=0.0
B1_X(cc) = amp*(BXavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
B1_Y(cc) = amp*(BYavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
B1_Z(cc) = amp*(BZavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
B1_Y(cc) = amp*(BYavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*snp(cc)
B1_Z(cc) = -amp*(BZavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)

B_X(cc) = B0_X(cc)+B1_X(cc)
B_Y(cc) = B0_Y(cc)+B1_Y(cc)
Expand All @@ -3494,9 +3502,9 @@ subroutine interp_FOfields_aorsa_p(time,params,pchunk,F,Y_R,Y_PHI,Y_Z, &
EXavg=76.2/params%cpp%Eo
EYavg=57.7/params%cpp%Eo
EZavg=9.25/params%cpp%Eo
E_X(cc) = amp*(EXavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
E_X(cc) = -amp*(EXavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*snp(cc)
E_Y(cc) = amp*(EYavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
E_Z(cc) = amp*(EZavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*cnp(cc)
E_Z(cc) = amp*(EZavg*((1/cosh((PSIp(cc)-psirr)/widthh))**2))*snp(cc)


end do
Expand Down
49 changes: 32 additions & 17 deletions src/korc_spatial_distribution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ MODULE korc_spatial_distribution
fzero,&
MH_gaussian_elliptic_torus,&
indicator,&
indicatortwo,&
PSI_ROT,&
Spong_3D,&
Spong_2D, &
Expand Down Expand Up @@ -151,7 +152,7 @@ subroutine torus(params,spp)
call set_random_dist(0.0_rp, 1.0_rp)
call get_randoms(r)

r = SQRT((spp%r_outter**2 - spp%r_inner**2)*r + spp%r_inner**2)
r = SQRT((spp%r_outter**2 - spp%r_inner**2)*r + spp%r_inner**2)

!$OMP PARALLEL WORKSHARE
spp%vars%X(:,1) = ( spp%Ro + r*COS(theta) )*SIN(zeta)
Expand Down Expand Up @@ -735,6 +736,18 @@ FUNCTION indicator(psi,psi_max)
END FUNCTION indicator


FUNCTION indicatortwo(psi,PSIp_min)

REAL(rp), INTENT(IN) :: psi
REAL(rp), INTENT(IN) :: PSIp_min
REAL(rp) :: indicatortwo

IF (psi.GT.PSIp_min) THEN
indicatortwo=1
ELSE
indicatortwo=0
END IF
END FUNCTION indicatortwo
FUNCTION random_norm(mean,sigma)
REAL(rp), INTENT(IN) :: mean
REAL(rp), INTENT(IN) :: sigma
Expand Down Expand Up @@ -1283,6 +1296,8 @@ subroutine MH_psi(params,spp,F)
TYPE(KORC_PARAMS), INTENT(INOUT) :: params
!! Core KORC simulation parameters.
TYPE(SPECIES), INTENT(INOUT) :: spp
!! An instance of the derived type SPECIES containing all the parameters
!! and simulation variables of the different species in the simulation.
TYPE(FIELDS), INTENT(IN) :: F
!! An instance of the KORC derived type FIELDS.
REAL(rp), DIMENSION(:), ALLOCATABLE :: R_samples,X_samples,Y_samples
Expand All @@ -1308,7 +1323,7 @@ subroutine MH_psi(params,spp,F)
!! Present sample of Z location
REAL(rp) :: PHI_test

REAL(rp) :: psi_max,psi_max_buff
REAL(rp) :: psi_max,PSIp_min,psi_max_buff
REAL(rp) :: PSIp_lim,PSIP0,PSIN,PSIN0,PSIN1,sigma,psi0,psi1

REAL(rp) :: rand_unif
Expand All @@ -1333,7 +1348,7 @@ subroutine MH_psi(params,spp,F)

params%GC_coords=.TRUE.
PSIp_lim=F%PSIp_lim

!changed_YG
if (params%field_model.eq.'M3D_C1') then
min_R=params%rmin/params%cpp%length
max_R=params%rmax/params%cpp%length
Expand All @@ -1349,16 +1364,18 @@ subroutine MH_psi(params,spp,F)
min_Z=minval(F%X%Z)
max_Z=maxval(F%X%Z)

! changed YG PSIp0=F%PSIP_min
PSIp0=0.0498
! changed YG psi_max = spp%psi_max
psi_max = 0.05
PSIp0=F%PSIP_min
psi_max = spp%psi_max/(params%cpp%Bo*params%cpp%length**2)
psi_max_buff = spp%psi_max*2._rp
PSIp_min=spp%PSIp_min/(params%cpp%Bo*params%cpp%length**2)
! psi_max=(psi_max-PSIp0)/(PSIp_lim-PSIp0)
! PSIp_min=(PSIp_min-PSIp0)/(PSIp_lim-PSIp0)
! write(6,*)"psip0",PSIp0,"psi_max",psi_max,"PSIp_min",PSIp_min,"PSIp_lim", PSIp_lim
end if

sigma=spp%sigmaR*params%cpp%length

!write(output_unit_write,*) min_R,max_R
write(6,*) "sigma",sigma
!write(output_unit_write,*) min_Z,max_Z


Expand Down Expand Up @@ -1406,9 +1423,6 @@ subroutine MH_psi(params,spp,F)
Z_test = Z_buffer + get_random_N()*spp%dZ





do while ((R_test.GT.max_R).OR.(R_test .LT. min_R))
!eta_test = eta_buffer + random_norm(0.0_rp,spp%dth)
!eta_test = eta_buffer + get_random_mkl_N(0.0_rp,spp%dth)
Expand All @@ -1421,6 +1435,7 @@ subroutine MH_psi(params,spp,F)
Z_test = Z_buffer + get_random_N()*spp%dZ
end do
PHI_test = 2.0_rp*C_PI*get_random_U()
! write(6,*)"R_test",R_test,"Z_test",Z_test


! initialize 2D gaussian argument and distribution function, or
Expand Down Expand Up @@ -1506,9 +1521,9 @@ subroutine MH_psi(params,spp,F)
if (.not.F%useLCFS) spp%vars%initLCFS(1)=1_is
ratio = real(spp%vars%flagCon(1))*real(spp%vars%initLCFS(1))* &
indicator(PSIN1,psi_max)* &
indicatortwo(PSIN1,PSIp_min)* &
R_test*EXP(-PSIN1/sigma)/ &
(R_buffer*EXP(-PSIN0/sigma))

! ratio = f1*sin(deg2rad(eta_test))/(f0*sin(deg2rad(eta_buffer)))

accepted=.false.
Expand Down Expand Up @@ -1544,10 +1559,9 @@ subroutine MH_psi(params,spp,F)
! write(output_unit_write,'("sample:",I15)') ii

#if DBG_CHECK
#else
if (modulo(ii,nsamples/10).eq.0) then
!write(output_unit_write,'("Sample: ",I10)') ii
end if
if (modulo(ii,nsamples/10).eq.0) then
write(output_unit_write,'("Sample: ",I10)') ii
end if
#endif

!R_test = R_buffer + random_norm(0.0_rp,spp%dR)
Expand Down Expand Up @@ -1615,6 +1629,7 @@ subroutine MH_psi(params,spp,F)
if (.not.F%useLCFS) spp%vars%initLCFS(1)=1_is
ratio = real(spp%vars%flagCon(1))*real(spp%vars%initLCFS(1))* &
indicator(PSIN1,psi_max)* &
indicatortwo(PSIN1,PSIp_min)* &
R_test*EXP(-PSIN1/sigma)/ &
(R_buffer*EXP(-PSIN0/sigma))

Expand Down Expand Up @@ -1644,7 +1659,7 @@ subroutine MH_psi(params,spp,F)
! Only accept sample if it is within desired boundary, but
! add to MC above if within buffer. This helps make the boundary
! more defined.
IF ((INT(indicator(PSIN1,psi_max)).EQ.1).AND. &
IF ((INT(indicator(PSIN1,psi_max)).EQ.1).AND.(INT(indicatortwo(PSIN1,PSIp_min)).EQ.1).AND. &
ACCEPTED) THEN
R_samples(ii) = R_buffer
Z_samples(ii) = Z_buffer
Expand Down
3 changes: 2 additions & 1 deletion src/korc_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ module korc_types
REAL(rp) :: theta_gauss
!! Angle of counter-clockwise rotation (in degrees) of 2D Gaussian
!! distribution relative to R,Z
REAL(rp) :: psi_max
REAL(rp) :: psi_max,PSIp_min
!! Maximum value of the argument of the 2D gaussian exponential, used
!! for an indicator function that limits the region of MH sampling
REAL(rp) :: Spong_b
Expand Down Expand Up @@ -623,6 +623,7 @@ module korc_types
REAL(rp) :: psir
REAL(rp) :: width
REAL(rp) :: AORSA_nmode
REAL(rp) :: AORSA_mmode
!! interpolated E field
CHARACTER(30) :: Analytic_IWL
INTEGER :: ntiles
Expand Down

0 comments on commit 27d708e

Please sign in to comment.