Skip to content

Commit

Permalink
put free subroutines into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanschatzlmayr committed Feb 11, 2025
1 parent 6fa2bfc commit db53f83
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 140 deletions.
2 changes: 1 addition & 1 deletion EXAMPLES/example_7/test_gorilla_main.x
10 changes: 1 addition & 9 deletions SRC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,11 @@ if ("$ENV{GORILLA_COVERAGE}" STREQUAL "TRUE")
)
endif()

add_executable(test_gorilla_main.x
test_gorilla_main.f90
)

target_link_libraries(test_gorilla_main.x GORILLA netcdff netcdf lapack)

set_target_properties (GORILLA PROPERTIES
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

target_include_directories(GORILLA PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

if ("$ENV{GORILLA_COVERAGE}" STREQUAL "TRUE")
add_subdirectory(TESTS)
endif()


endif()
4 changes: 4 additions & 0 deletions SRC/bdivfree.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ subroutine smear_formfactors(nmodes_ff,nsqpsi_ff,sqpsimin_ff,sqpsimax_ff, &
!
use inthecore_mod, only : psi_sep,psi_cut
use theta_rz_mod, only : psiaxis
use field_divB0_mod, only: inthecore, localizer
!
implicit none
!
Expand Down Expand Up @@ -1056,6 +1057,7 @@ subroutine vector_potentials(nr_in,np_in,nz_in,ntor_in, &
!
use bdivfree_mod
use spline5_RZ_mod, only: s2dcut
use field_divB0_mod, only: stretch_coords
!
implicit none
!
Expand Down Expand Up @@ -1614,6 +1616,8 @@ subroutine field_fourier_derivs(r,phi,z,Br,Bp,Bz,dBrdR,dBrdp,dBrdZ &
! Computes the field and its derivatives using central differences
! for the field components computed by "field_fourier".
!
use field_divB0_mod, only: field_eq, stretch_coords, inthecore

implicit none
!
double precision, parameter :: eps=1.d-7
Expand Down
1 change: 1 addition & 0 deletions SRC/circular_mesh_SOLEDGE3X_EIRENE.f90
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ subroutine extrude_points(verts_per_slice, n_slices,phi_position, points)
subroutine vector_potential_rz(r,z,A_phi)
!
use field_eq_mod, only : rtf,btf,psif
use field_divB0_mod, only: field
!
implicit none
!
Expand Down
89 changes: 12 additions & 77 deletions SRC/field_divB0.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ end module inthecore_mod
!
!cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
! -----------------------------------------------------------------
!
module field_divB0_mod

implicit none

contains

subroutine field(r,p,z,Br,Bp,Bz,dBrdR,dBrdp,dBrdZ &
,dBpdR,dBpdp,dBpdZ,dBzdR,dBzdp,dBzdZ)
!
Expand Down Expand Up @@ -203,6 +210,7 @@ subroutine field(r,p,z,Br,Bp,Bz,dBrdR,dBrdp,dBrdZ &
!
return
end subroutine field

! ========================================================================
subroutine field_eq(r,ppp,z,Brad,Bphi,Bzet,dBrdR,dBrdp,dBrdZ &
,dBpdR,dBpdp,dBpdZ,dBzdR,dBzdp,dBzdZ)
Expand Down Expand Up @@ -419,7 +427,7 @@ end subroutine read_dimeq0

subroutine read_eqfile0(nrad, nzet, psib, btf, rtf, rad, zet, psi)
use input_files
integer :: nrad, nzet, dum
integer :: nrad, nzet, dum, i, j, k
real(kind=8) :: psib, btf, rtf
real(kind=8) :: rad(nrad), zet(nzet)
real(kind=8) :: psi(nrad,nzet)
Expand Down Expand Up @@ -477,7 +485,6 @@ subroutine read_eqfile0(nrad, nzet, psib, btf, rtf, rad, zet, psi)
113 format(5(e17.4))
end subroutine read_eqfile0


! ----------- Read gfile directly --------------------------------
subroutine read_dimeq1(nwEQD,nhEQD)
use input_files
Expand All @@ -496,7 +503,6 @@ subroutine read_dimeq1(nwEQD,nhEQD)
250 print *, 'READ_EQDIM1: Error reading ',trim(gfile); STOP
end subroutine read_dimeq1


subroutine read_eqfile1(nwEQD,nhEQD,psiSep, bt0, rzero, rad, zet, psiRZ)
use input_files
implicit none
Expand Down Expand Up @@ -618,7 +624,6 @@ subroutine read_eqfile2(nwEQD,nhEQD,psiAxis,psiSep,bt0,rzero,fpol,rad,zet,psiRZ)

end subroutine read_eqfile2


subroutine set_eqcoords(nwEQD,nhEQD,xdim,zdim,r1,zmid,rad,zet)
implicit none
integer :: j,k,nwEQD,nhEQD
Expand Down Expand Up @@ -733,78 +738,6 @@ subroutine field_c(rrr,ppp,zzz,Brad,Bphi,Bzet,dBrdR,dBrdp,dBrdZ &
return
end subroutine field_c



! ===========================================================================
subroutine read_field0(rad,phi,zet,rmin,pmin,zmin,hrm1,hpm1,hzm1,Br,Bp,Bz)
!
use input_files
parameter(nr=64,np=37,nz=64)
real, parameter :: pi=3.14159265358979d0
parameter (mp=4) ! power of Lagrange's polynomial =3
dimension Bz(nr,np,nz)
dimension Br(nr,np,nz),Bp(nr,np,nz)
dimension rad(nr), phi(np), zet(nz)
dimension xp(mp),yp(mp),zp(mp),fp(mp,mp,mp)
integer indx(mp), indy(mp), indz(mp)
data icall/0/
save
!
!-------first call: read data from disk-------------------------------
open(1,file=cfile,status='old',action='read')
read(1,*)
read(1,*)
read(1,*)
read(1,*)
read(1,*)

!---Input B -->T = V*s/m/m
do j=1,np-1 !only npmax-1 points are given
do k=nz,1,-1 !reverse order of probe data
do i=1,nr
read(1,*) Br(i,j,k), Bp(i,j,k), Bz(i,j,k)

Br(i,j,k) = Br(i,j,k)*1.d4
Bp(i,j,k) = Bp(i,j,k)*1.d4
Bz(i,j,k) = Bz(i,j,k)*1.d4

enddo
read(1,*)
enddo
read(1,*)
enddo
close(1)
!
rmin = 84.
rmax = 254.
zmin = -160.
zmax = 160.
pmin = 0.
pmax = 2.*pi


hrad = (rmax - rmin)/(nr-1)
hphi = (pmax - pmin)/(np-1)
hzet = (zmax - zmin)/(nz-1)

do i=1,nr
rad(i) = rmin + hrad*(i-1)
enddo
do i=1,np
phi(i) = pmin + hphi*(i-1)
enddo
do i=1,nz
zet(i) = zmin + hzet*(i-1)
enddo

do i=1,nr
do k=1,nz
Br(i,np,k) = Br(i,1,k)
Bp(i,np,k) = Bp(i,1,k)
Bz(i,np,k) = Bz(i,1,k)
enddo
enddo
end subroutine read_field0
!
subroutine read_field1(icftype,nr,np,nz,rmin,rmax,pmin,pmax,zmin,zmax,Br,Bp,Bz)
!
Expand Down Expand Up @@ -1223,7 +1156,7 @@ subroutine read_field4(nr,np,nz,rmin,rmax,pmin,pmax,zmin,zmax,Br,Bp,Bz)
close(iunit)
!
end subroutine read_field4

!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine spline_fpol
Expand Down Expand Up @@ -1321,3 +1254,5 @@ subroutine read_eqfile_west(nrad, nzet, psib, btf, rtf, rad, zet, psi)
btf=btf/rtf
!
end subroutine read_eqfile_west

end module field_divB0_mod
4 changes: 4 additions & 0 deletions SRC/field_line_integration_for_SYNCH.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ subroutine field_line_integration_for_SYNCH(nstep,nsurfmax,nlabel,ntheta, &
use field_line_integration_mod, only: circ_mesh_scale, o_point, x_point, &
& theta_axis, theta0
use plag_coeff_mod, only: plag_coeff
use field_divB0_mod, only: field_eq
!
implicit none
!
Expand Down Expand Up @@ -395,6 +396,8 @@ end subroutine field_line_integration_for_SYNCH

subroutine rhs_axis(phi,y,dy)
!
use field_divB0_mod, only: field_eq

implicit none
!
integer, parameter :: ndim = 4
Expand All @@ -420,6 +423,7 @@ end subroutine rhs_axis
subroutine rhs_surf(phi,y,dy)
!
use rhs_surf_mod , only: dr_dphi, dz_dphi
use field_divB0_mod, only: field_eq
!
implicit none
!
Expand Down
114 changes: 62 additions & 52 deletions SRC/get_canonical_coordinates.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ end module exchange_get_cancoord_mod
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
module get_canonical_coordinates_mod

implicit none

contains

subroutine get_canonical_coordinates
!
use odeint_mod, only: odeint_allroutines
Expand All @@ -32,7 +38,7 @@ subroutine get_canonical_coordinates
double precision :: r,r1,r2,G_beg,dG_c_dt,dG_c_dp
integer :: is
!
external rhs_cancoord
!external rhs_cancoord
!
!
ns_c=ns
Expand Down Expand Up @@ -403,6 +409,60 @@ end subroutine spline_can_coord
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine can_to_vmec(r,vartheta_c_in,varphi_c_in,theta_vmec,varphi_vmec)
!
use exchange_get_cancoord_mod, only : vartheta_c,varphi_c,theta
!
implicit none
!
logical :: fullset
double precision :: theta_vmec,varphi_vmec
double precision :: r,vartheta_c_in,varphi_c_in, &
A_phi,A_theta,dA_phi_dr,dA_theta_dr,d2A_phi_dr2, &
sqg_c,dsqg_c_dr,dsqg_c_dt,dsqg_c_dp, &
B_vartheta_c,dB_vartheta_c_dr,dB_vartheta_c_dt,dB_vartheta_c_dp, &
B_varphi_c,dB_varphi_c_dr,dB_varphi_c_dt,dB_varphi_c_dp,G_c
double precision, dimension(1) :: y,dy
!
fullset=.true.
!
call splint_can_coord(r,vartheta_c_in,varphi_c_in, &
A_theta,A_phi,dA_theta_dr,dA_phi_dr,d2A_phi_dr2, &
sqg_c,dsqg_c_dr,dsqg_c_dt,dsqg_c_dp, &
B_vartheta_c,dB_vartheta_c_dr,dB_vartheta_c_dt,dB_vartheta_c_dp, &
B_varphi_c,dB_varphi_c_dr,dB_varphi_c_dt,dB_varphi_c_dp, &
fullset,G_c)
!
vartheta_c=vartheta_c_in
varphi_c=varphi_c_in
y(1)=G_c
!
call rhs_cancoord(r,y,dy)
!
theta_vmec=theta
varphi_vmec=varphi_c_in+G_c
!
end subroutine can_to_vmec
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine deallocate_can_coord
!
use canonical_coordinates_mod, only : s_sqg_c,s_B_vartheta_c,s_B_varphi_c,s_G_c
!
implicit none
!
deallocate(s_sqg_c,s_B_vartheta_c,s_B_varphi_c)
if(allocated(s_G_c)) deallocate(s_G_c)
!
end subroutine deallocate_can_coord

end module get_canonical_coordinates_mod

!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!

subroutine splint_can_coord(r,vartheta_c,varphi_c, &
A_theta,A_phi,dA_theta_dr,dA_phi_dr,d2A_phi_dr2, &
sqg_c,dsqg_c_dr,dsqg_c_dt,dsqg_c_dp, &
Expand Down Expand Up @@ -582,54 +642,4 @@ subroutine splint_can_coord(r,vartheta_c,varphi_c,
!
! End interpolation over $\varphi$
!
end subroutine splint_can_coord
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine can_to_vmec(r,vartheta_c_in,varphi_c_in,theta_vmec,varphi_vmec)
!
use exchange_get_cancoord_mod, only : vartheta_c,varphi_c,theta
!
implicit none
!
logical :: fullset
double precision :: theta_vmec,varphi_vmec
double precision :: r,vartheta_c_in,varphi_c_in, &
A_phi,A_theta,dA_phi_dr,dA_theta_dr,d2A_phi_dr2, &
sqg_c,dsqg_c_dr,dsqg_c_dt,dsqg_c_dp, &
B_vartheta_c,dB_vartheta_c_dr,dB_vartheta_c_dt,dB_vartheta_c_dp, &
B_varphi_c,dB_varphi_c_dr,dB_varphi_c_dt,dB_varphi_c_dp,G_c
double precision, dimension(1) :: y,dy
!
fullset=.true.
!
call splint_can_coord(r,vartheta_c_in,varphi_c_in, &
A_theta,A_phi,dA_theta_dr,dA_phi_dr,d2A_phi_dr2, &
sqg_c,dsqg_c_dr,dsqg_c_dt,dsqg_c_dp, &
B_vartheta_c,dB_vartheta_c_dr,dB_vartheta_c_dt,dB_vartheta_c_dp, &
B_varphi_c,dB_varphi_c_dr,dB_varphi_c_dt,dB_varphi_c_dp, &
fullset,G_c)
!
vartheta_c=vartheta_c_in
varphi_c=varphi_c_in
y(1)=G_c
!
call rhs_cancoord(r,y,dy)
!
theta_vmec=theta
varphi_vmec=varphi_c_in+G_c
!
end subroutine can_to_vmec
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
subroutine deallocate_can_coord
!
use canonical_coordinates_mod, only : s_sqg_c,s_B_vartheta_c,s_B_varphi_c,s_G_c
!
implicit none
!
deallocate(s_sqg_c,s_B_vartheta_c,s_B_varphi_c)
if(allocated(s_G_c)) deallocate(s_G_c)
!
end subroutine deallocate_can_coord
end subroutine splint_can_coord
8 changes: 8 additions & 0 deletions SRC/magdata_in_symfluxcoord.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ end module magdata_in_symfluxcoor_mod
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
module magdata_in_symfluxcoordinates_mod

implicit none

contains

subroutine load_magdata_in_symfluxcoord
!
! Reads and splines magnetic data over theta
Expand Down Expand Up @@ -235,3 +241,5 @@ subroutine magdata_in_symfluxcoord_ext(inp_label,s,psi,theta,q,dq_ds, &
end subroutine magdata_in_symfluxcoord_ext
!
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!
end module magdata_in_symfluxcoordinates_mod
Loading

0 comments on commit db53f83

Please sign in to comment.