From 3ca882926fe0d6edb7159541de4a7f91e257a39b Mon Sep 17 00:00:00 2001 From: SM Yang Date: Mon, 2 Nov 2026 10:55:47 -0500 Subject: [PATCH] GPEC - ENHANCEMENT - div-free option for psi,theta grid fields and arzphifun grad(zeta) update For fast-ion calculations a divergence-free perturbed field can matter. With reg_flag=t the psi,theta grid output field is not divergence-free, so a new output option reg_div_flag (default f) damps only the (n,m) projection of (bwt,bwz) in gpout_xbrzphifun, which keeps div b = 0; bwp, xi and all other outputs are unchanged. gpout_arzphifun now takes the grad(zeta) components w(3,1:2) from the chain rule through grad(psi) and grad(theta), as in gpeq.f, so that curl A is consistent with the xbrzphifun field. input/gpec.in template updated. --- gpec/gpec.f | 2 ++ gpec/gpglobal.F | 1 + gpec/gpout.f | 34 ++++++++++++++++++++++++++++++++-- input/gpec.in | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gpec/gpec.f b/gpec/gpec.f index 840b2e50..641f6db3 100644 --- a/gpec/gpec.f +++ b/gpec/gpec.f @@ -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, @@ -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. diff --git a/gpec/gpglobal.F b/gpec/gpglobal.F index fdd88ae5..23eaa5bf 100644 --- a/gpec/gpglobal.F +++ b/gpec/gpglobal.F @@ -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, diff --git a/gpec/gpout.f b/gpec/gpout.f index 897b60bd..6ef22638 100644 --- a/gpec/gpout.f +++ b/gpec/gpout.f @@ -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----------------------------------------------------------------------- @@ -5362,6 +5365,8 @@ 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) @@ -5369,6 +5374,26 @@ SUBROUTINE gpout_xbrzphifun(egnum,xspmn) 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----------------------------------------------------------------------- @@ -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)) diff --git a/input/gpec.in b/input/gpec.in index a4b43aff..70a81b05 100644 --- a/input/gpec.in +++ b/input/gpec.in @@ -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