Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gpec/gpec.f
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PROGRAM gpec_main
$ jac_out,power_bout,power_rout,power_bpout,power_rcout,
$ tmag_out,mlim_out,eqbrzphi_flag,brzphi_flag,xrzphi_flag,
$ vbrzphi_flag,vvbrzphi_flag,divzero_flag,dw_flag,opsi1,opsi2,
$ reg_div_flag,
$ bin_flag,bin_2d_flag,fun_flag,flux_flag,bwp_pest_flag,
$ vsbrzphi_flag,ss_flag,arzphifun_flag,xbrzphifun_flag,
$ vsingfld_flag,vbnormal_flag,eigm_flag,xbtangent_flag,
Expand Down Expand Up @@ -177,6 +178,7 @@ PROGRAM gpec_main
ENDDO
arzphifun_flag=.FALSE.
xbrzphifun_flag=.FALSE.
reg_div_flag=.FALSE.
bwp_pest_flag=.TRUE.
dw_flag = .FALSE.

Expand Down
1 change: 1 addition & 0 deletions gpec/gpglobal.F
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MODULE gpglobal_mod
c-----------------------------------------------------------------------
LOGICAL :: power_flag,fft_flag,edge_flag,pbrzphi_flag,
$ eqbrzphi_flag,brzphi_flag,xrzphi_flag,divzero_flag,
$ reg_div_flag,
$ vbrzphi_flag,vvbrzphi_flag,div_flag,surface_flag,
$ data_flag,harmonic_flag,mode_flag,resp_flag,
$ bin_flag,bin_2d_flag,fixed_boundary_flag,reg_flag,
Expand Down
34 changes: 32 additions & 2 deletions gpec/gpout.f
Original file line number Diff line number Diff line change
Expand Up @@ -5350,6 +5350,9 @@ SUBROUTINE gpout_xbrzphifun(egnum,xspmn)
$ xwt_fun,bwt_fun,xvz_fun,bvz_fun
COMPLEX(r8), DIMENSION(:,:), ALLOCATABLE :: xrr_fun,brr_fun,
$ xrz_fun,brz_fun,xrp_fun,brp_fun
REAL(r8) :: qr
REAL(r8), DIMENSION(mpert) :: freg_mn
COMPLEX(r8), DIMENSION(mpert) :: tproj_mn
c-----------------------------------------------------------------------
c allocation puts memory in heap, avoiding stack overfill
c-----------------------------------------------------------------------
Expand All @@ -5362,13 +5365,35 @@ SUBROUTINE gpout_xbrzphifun(egnum,xspmn)
c-----------------------------------------------------------------------
IF(timeit) CALL gpec_timer(2)
IF(verbose) WRITE(*,*)"Computing x and b rzphi functions"
IF(verbose .AND. reg_div_flag .AND. reg_flag) WRITE(*,*)
$ " reg_div_flag: divergence-consistent regularization"

CALL idcon_build(egnum,xspmn)

CALL gpeq_alloc
DO istep=1,mstep
IF(verbose) CALL progressbar(istep,1,mstep,op_percent=10)
CALL gpeq_sol(psifac(istep))
c-----------------------------------------------------------------------
c reg_div_flag: divergence-consistent regularization, output only.
c div b = 0 reads d(bwp)/dpsi + 2 pi i (m bwt - n bwz) = 0, so only
c the combination m*b^theta - n*b^phi is tied to the untouched bwp.
c gpeq_sol damps the whole singular vector (bwt,bwz) by the Lorentz
c -ian f, which changes that combination and breaks div b = 0 at the
c rational surfaces. The singular part of the ideal solution lies
c along (n,m) in (bwt,bwz) space, so here only that projection T is
c damped: m*bmt - n*bmz is unchanged, div b = 0 holds exactly, and
c bwp, xi and every other output are untouched (gpeq_sol resets the
c module arrays on each call).
c-----------------------------------------------------------------------
IF(reg_div_flag .AND. reg_flag)THEN
CALL spline_eval(sq,psifac(istep),0)
qr=sq%f(4)
freg_mn=(mfac-nn*qr)**2/((mfac-nn*qr)**2+reg_spot**2)
tproj_mn=(nn*bwt_mn+mfac*bwz_mn)/REAL(nn**2+mfac**2,r8)
bmt_mn=bwt_mn-(1-freg_mn)*nn*tproj_mn
bmz_mn=bwz_mn-(1-freg_mn)*mfac*tproj_mn
ENDIF
CALL gpeq_contra(psifac(istep))
CALL gpeq_cova(psifac(istep))
c-----------------------------------------------------------------------
Expand Down Expand Up @@ -5589,8 +5614,13 @@ SUBROUTINE gpout_arzphifun(egnum,xspmn)
w(1,2)=-rzphi%fy(1)*pi*rs(istep,itheta)/(rfac*jac)
w(2,1)=-rzphi%fx(2)*twopi**2*rs(istep,itheta)*rfac/jac
w(2,2)=rzphi%fx(1)*pi*rs(istep,itheta)/(rfac*jac)
w(3,1)=rzphi%fx(3)*2*rfac
w(3,2)=rzphi%fy(3)/(twopi*rfac)
c poloidal part of grad(zeta): phi = 2 pi zeta + dphi(psi,theta), so
c grad(zeta)_pol = -grad(dphi)/(2 pi), grad(dphi) by the chain rule
c through grad(psi)=w(1,:) and grad(theta)=w(2,:). (The previous
c 2*rfac*dphi_psi, dphi_theta/(2 pi rfac) was a circular, rho^2=psi
c approximation and gave A_R, A_z inconsistent with curl A = b.)
w(3,1)=(rzphi%fx(3)*w(1,1)+rzphi%fy(3)*w(2,1))/twopi
w(3,2)=(rzphi%fx(3)*w(1,2)+rzphi%fy(3)*w(2,2))/twopi
w(3,3)=1.0/(twopi*rs(istep,itheta))
ear(itheta)=chi1*psifac(istep)*(qfac(istep)*w(2,1)-w(3,1))
eat(itheta)=chi1*psifac(istep)*(qfac(istep)*w(2,2)-w(3,2))
Expand Down
1 change: 1 addition & 0 deletions input/gpec.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
ss_flag(3)=f ! Outputs the field on regular (r,z) grid due to the 3rd singular surface current, etc.
xbrzphifun_flag=f ! Outputs r,z, and perturbation vectors on psi,theta grid
arzphifun_flag=f ! Outputs r,z, and vector potential on psi,theta grid
reg_div_flag=f ! With reg_flag=t: divergence-consistent regularization of the psi,theta grid field outputs (damps only the (n,m) projection of the tangential field; b_normal and xi unchanged)

nr = 128 ! Number of radial grid points in rzphi outputs
nz = 128 ! Number of vertical grid points in rzphi outputs
Expand Down
Loading