Skip to content

Commit

Permalink
subroutines of two more files wrapped in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanschatzlmayr committed Feb 10, 2025
1 parent 895bc4f commit 02c1481
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ SOURCES = SetWorkingPrecision.f90\
vmecin_mod.f90 \
spline5_RZ_mod.f90 \
spl_three_to_five_mod.f90 \
spline_vmec_data.f90 \
new_vmec_allocation_stuff.f90 \
new_vmec_allocation_stuff_mod.f90 \
spline_vmec_data_mod.f90 \
binsrc_mod.f90 \
field_divB0.f90 \
scaling_r_theta.f90\
plag_coeff_mod.f90 \
field_line_integration_for_SYNCH_mod.f90 \
preload_for_SYNCH_mod.f90 \
plag_coeff.f90 \
magdata_in_symfluxcoord.f90 \
points_2d.f90\
circular_mesh.f90\
Expand Down
5 changes: 5 additions & 0 deletions SRC/circular_mesh.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module circular_mesh
subroutine create_points(verts_per_ring, n_slices, points_rphiz, points_sthetaphi, efit_vmec,n_field_periods_in,n_verts, &
verts_theta_vmec,r_scaling_func, theta_scaling_func,repeat_center_point)
use points_2d, only: create_points_2d, create_points_2d_vmec, scaling_func
use spline_vmec_data_mod, only: splint_vmec_data

integer, intent(in) :: n_slices,efit_vmec,n_field_periods_in
integer, dimension(:), intent(in) :: verts_per_ring ! without center vert; e.g. (/6, 8, 10/)
Expand Down Expand Up @@ -166,6 +167,8 @@ subroutine extrude_points(verts_per_slice, n_slices,phi_position, points)

function theta_vmec2theta_sym_flux(s,theta_vmec,varphi) result(theta_sym_flux)
!
use spline_vmec_data_mod, only: splint_vmec_data

implicit none
!
double precision :: s,theta_vmec,theta_sym_flux,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,aiota, &
Expand All @@ -179,6 +182,8 @@ function theta_vmec2theta_sym_flux(s,theta_vmec,varphi) result(theta_sym_flux)
end function theta_vmec2theta_sym_flux
!
function theta_sym_flux2theta_vmec(s,theta_sym_flux,varphi) result(theta_vmec)
!
use spline_vmec_data_mod, only: splint_lambda
!
implicit none
!
Expand Down
1 change: 1 addition & 0 deletions SRC/field_line_integration_for_SYNCH_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ subroutine field_line_integration_for_SYNCH(nstep,nsurfmax,nlabel,ntheta, &
use tetra_grid_settings_mod, only: theta0_at_xpoint
use field_line_integration_mod, only: circ_mesh_scale, o_point, x_point, &
& theta_axis, theta0
use plag_coeff_mod, only: plag_coeff
!
implicit none
!
Expand Down
2 changes: 2 additions & 0 deletions SRC/get_canonical_coordinates.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ subroutine get_canonical_coordinates
use exchange_get_cancoord_mod, only : vartheta_c,varphi_c,sqg,aiota,Bcovar_vartheta,Bcovar_varphi, &
theta,onlytheta
use new_vmec_stuff_mod, only : n_theta,n_phi,h_theta,h_phi,ns_s,ns_tp
use spline_vmec_data_mod, only: deallocate_vmec_spline
!
implicit none
!
Expand Down Expand Up @@ -179,6 +180,7 @@ subroutine rhs_cancoord(r,y,dy)
!
use exchange_get_cancoord_mod, only : vartheta_c,varphi_c,sqg,aiota,Bcovar_vartheta,Bcovar_varphi, &
theta,onlytheta
use spline_vmec_data_mod, only: splint_iota, splint_lambda!, vmec_field
!
implicit none
!
Expand Down
1 change: 1 addition & 0 deletions SRC/magdata_in_symfluxcoord.f90
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ subroutine magdata_in_symfluxcoord_ext(inp_label,s,psi,theta,q,dq_ds, &
!
use magdata_in_symfluxcoor_mod
use binsrc_mod, only: binsrc
use plag_coeff_mod, only: plag_coeff
!
implicit none
!
Expand Down
2 changes: 2 additions & 0 deletions SRC/magfie.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ subroutine magfie_vmec(x,bmod,sqrtg,bder,hcovar,hctrvr,hcurl)
!
! Called routines: vmec_field
!
!
!use spline_vmec_data_mod, only: vmec_field
!
implicit none
!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module new_vmec_allocation_stuff_mod

implicit none

contains
!
subroutine new_allocate_vmec_stuff
!
Expand Down Expand Up @@ -40,3 +45,5 @@ subroutine new_deallocate_vmec_stuff
deallocate(axm,axn,soa,aiota,sps,phi,s,rmn,zmn,almn)
!
end subroutine new_deallocate_vmec_stuff

end module new_vmec_allocation_stuff_mod
10 changes: 8 additions & 2 deletions SRC/plag_coeff.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
module plag_coeff_mod

implicit none

contains

SUBROUTINE plag_coeff(npoi,nder,x,xp,coef)
!
! npoi - number of points (determines the order of Lagrange
Expand Down Expand Up @@ -58,3 +62,5 @@ SUBROUTINE plag_coeff(npoi,nder,x,xp,coef)
RETURN
END SUBROUTINE plag_coeff

end module plag_coeff_mod

1 change: 1 addition & 0 deletions SRC/points_2d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ subroutine theta_geom2theta_flux(inp_label, s, psi, theta_geom_vec,theta_flux_ve
use field_line_integration_mod, only: theta0
use tetra_grid_settings_mod, only: theta0_at_xpoint
use binsrc_mod, only: binsrc
use plag_coeff_mod, only: plag_coeff
!
implicit none
!
Expand Down
113 changes: 62 additions & 51 deletions SRC/spline_vmec_data.f90 → SRC/spline_vmec_data_mod.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module spline_vmec_data_mod

implicit none

contains
!
subroutine spline_vmec_data
!
use new_vmec_stuff_mod
use vector_potentail_mod, only : ns,hs,torflux,sA_phi
use spl_three_to_five_mod
use vmecin_mod, only: vmecin
use new_vmec_allocation_stuff_mod, only: new_allocate_vmec_stuff, new_deallocate_vmec_stuff
!
implicit none
!
Expand Down Expand Up @@ -451,57 +457,6 @@ subroutine splint_vmec_data(s,theta,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,a
end subroutine splint_vmec_data
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine vmec_field(s,theta,varphi,A_theta,A_phi,dA_theta_ds,dA_phi_ds,aiota, &
sqg,alam,dl_ds,dl_dt,dl_dp,Bctrvr_vartheta,Bctrvr_varphi, &
Bcovar_r,Bcovar_vartheta,Bcovar_varphi)

!
implicit none
!
double precision :: s,theta,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,aiota, &
R,Z,alam,dR_ds,dR_dt,dR_dp,dZ_ds,dZ_dt,dZ_dp,dl_ds,dl_dt,dl_dp
double precision :: Bctrvr_vartheta,Bctrvr_varphi,Bcovar_vartheta,Bcovar_varphi,sqg
double precision :: cjac,sqgV,Bcovar_r
double precision, dimension(3,3) :: cmat,gV,g
!
!
call splint_vmec_data(s,theta,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,aiota, &
R,Z,alam,dR_ds,dR_dt,dR_dp,dZ_ds,dZ_dt,dZ_dp,dl_ds,dl_dt,dl_dp)
!
gV(1,1)=dR_ds**2+dZ_ds**2
gV(1,2)=dR_ds*dR_dt+dZ_ds*dZ_dt
gV(1,3)=dR_ds*dR_dp+dZ_ds*dZ_dp
gV(2,1)=gV(1,2)
gV(2,2)=dR_dt**2+dZ_dt**2
gV(2,3)=dR_dt*dR_dp+dZ_dt*dZ_dp
gV(3,1)=gV(1,3)
gV(3,2)=gV(2,3)
gV(3,3)=R**2+dR_dp**2+dZ_dp**2
sqgV=R*(dR_dt*dZ_ds-dR_ds*dZ_dt)
!
cjac=1.d0/(1.d0+dl_dt)
sqg=sqgV*cjac
Bctrvr_vartheta=-dA_phi_ds/sqg
Bctrvr_varphi=dA_theta_ds/sqg
!
cmat(1,2:3)=0.d0
cmat(3,1:2)=0.d0
cmat(1,1)=1.d0
cmat(3,3)=1.d0
cmat(2,1)=-dl_ds*cjac
cmat(2,2)=cjac
cmat(2,3)=-dl_dp*cjac
!
g=matmul(transpose(cmat),matmul(gV,cmat))
!
Bcovar_r=g(1,2)*Bctrvr_vartheta+g(1,3)*Bctrvr_varphi
Bcovar_vartheta=g(2,2)*Bctrvr_vartheta+g(2,3)*Bctrvr_varphi
Bcovar_varphi=g(3,2)*Bctrvr_vartheta+g(3,3)*Bctrvr_varphi
!
end subroutine vmec_field
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine splint_iota(s,aiota,daiota_ds)
!
Expand Down Expand Up @@ -696,3 +651,59 @@ subroutine s_to_rho_healaxis(m,ns,nrho,nheal,arr_in,arr_out)
deallocate(splcoe)
!
end subroutine s_to_rho_healaxis

end module spline_vmec_data_mod

!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine vmec_field(s,theta,varphi,A_theta,A_phi,dA_theta_ds,dA_phi_ds,aiota, &
sqg,alam,dl_ds,dl_dt,dl_dp,Bctrvr_vartheta,Bctrvr_varphi, &
Bcovar_r,Bcovar_vartheta,Bcovar_varphi)

use spline_vmec_data_mod, only: splint_vmec_data

!
implicit none
!
double precision :: s,theta,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,aiota, &
R,Z,alam,dR_ds,dR_dt,dR_dp,dZ_ds,dZ_dt,dZ_dp,dl_ds,dl_dt,dl_dp
double precision :: Bctrvr_vartheta,Bctrvr_varphi,Bcovar_vartheta,Bcovar_varphi,sqg
double precision :: cjac,sqgV,Bcovar_r
double precision, dimension(3,3) :: cmat,gV,g
!
!
call splint_vmec_data(s,theta,varphi,A_phi,A_theta,dA_phi_ds,dA_theta_ds,aiota, &
R,Z,alam,dR_ds,dR_dt,dR_dp,dZ_ds,dZ_dt,dZ_dp,dl_ds,dl_dt,dl_dp)
!
gV(1,1)=dR_ds**2+dZ_ds**2
gV(1,2)=dR_ds*dR_dt+dZ_ds*dZ_dt
gV(1,3)=dR_ds*dR_dp+dZ_ds*dZ_dp
gV(2,1)=gV(1,2)
gV(2,2)=dR_dt**2+dZ_dt**2
gV(2,3)=dR_dt*dR_dp+dZ_dt*dZ_dp
gV(3,1)=gV(1,3)
gV(3,2)=gV(2,3)
gV(3,3)=R**2+dR_dp**2+dZ_dp**2
sqgV=R*(dR_dt*dZ_ds-dR_ds*dZ_dt)
!
cjac=1.d0/(1.d0+dl_dt)
sqg=sqgV*cjac
Bctrvr_vartheta=-dA_phi_ds/sqg
Bctrvr_varphi=dA_theta_ds/sqg
!
cmat(1,2:3)=0.d0
cmat(3,1:2)=0.d0
cmat(1,1)=1.d0
cmat(3,3)=1.d0
cmat(2,1)=-dl_ds*cjac
cmat(2,2)=cjac
cmat(2,3)=-dl_dp*cjac
!
g=matmul(transpose(cmat),matmul(gV,cmat))
!
Bcovar_r=g(1,2)*Bctrvr_vartheta+g(1,3)*Bctrvr_varphi
Bcovar_vartheta=g(2,2)*Bctrvr_vartheta+g(2,3)*Bctrvr_varphi
Bcovar_varphi=g(3,2)*Bctrvr_vartheta+g(3,3)*Bctrvr_varphi
!
end subroutine vmec_field
4 changes: 4 additions & 0 deletions SRC/supporting_functions_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ subroutine sym_flux_in_cyl(sym_flux_filename,cyl_filename,n_additional_col)
!
use tetra_physics_mod, only: coord_system
use tetra_grid_settings_mod, only: grid_kind
use spline_vmec_data_mod, only: splint_vmec_data
!
implicit none
!
Expand Down Expand Up @@ -114,6 +115,8 @@ subroutine sym_flux_in_cyl(sym_flux_filename,cyl_filename,n_additional_col)
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
function theta_sym_flux2theta_vmec(s,theta_sym_flux,varphi) result(theta_vmec)
!
use spline_vmec_data_mod, only: splint_lambda
!
implicit none
!
Expand Down Expand Up @@ -144,6 +147,7 @@ end function theta_sym_flux2theta_vmec
function theta_vmec2theta_sym_flux(s,theta_vmec,varphi) result(theta_sym_flux)
!
use constants, only: pi
use spline_vmec_data_mod, only: splint_vmec_data
!
implicit none
!
Expand Down
1 change: 1 addition & 0 deletions SRC/tetra_grid_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ subroutine make_tetra_grid()
& n_field_periods,set_grid_size,set_n_field_periods, &
& boole_write_mesh_obj,filename_mesh_rphiz,filename_mesh_sthetaphi
use new_vmec_stuff_mod, only: nper
use spline_vmec_data_mod, only: spline_vmec_data
!use make_grid_rect_mod, only: make_grid_rect
!
implicit none
Expand Down
3 changes: 3 additions & 0 deletions SRC/tetra_physics_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ subroutine make_tetra_physics(coord_system_in,ipert_in,bmod_multiplier_in)
& non_axi_noise_eps_A, boole_strong_electric_field, boole_save_electric, boole_pert_from_mephit
use strong_electric_field_mod, only: get_electric_field, save_electric_field, get_v_E, save_v_E
use differentiate_mod, only: differentiate
use spline_vmec_data_mod, only: splint_vmec_data
!
integer, intent(in) :: ipert_in,coord_system_in
double precision, intent(in),optional :: bmod_multiplier_in
Expand Down Expand Up @@ -1125,6 +1126,8 @@ end subroutine vector_potential_sthetaphi
subroutine vector_potential_sthetaphi_vmec(s,theta,phi,ipert,bmod_multiplier,A_s,A_theta,A_phi, &
& B_s,B_vartheta,B_varphi,bmod,sqg,dR_ds,dZ_ds)
!
use spline_vmec_data_mod, only: splint_vmec_data!, vmec_field

implicit none
!
integer, intent(in) :: ipert
Expand Down

0 comments on commit 02c1481

Please sign in to comment.