Skip to content

Commit

Permalink
remove global variables n_r_maxStr, n_theta_maxStr, n_phi_maxStr
Browse files Browse the repository at this point in the history
Those were useless with the proper handling of memory allocation
  • Loading branch information
tgastine committed Dec 14, 2023
1 parent 84ce078 commit 51ea649
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 52 deletions.
2 changes: 0 additions & 2 deletions src/Namelists.f90
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ subroutine readNamelists(tscheme)
!-- Determine what has to be calculated depending on mode:
lMagMem =1
ldtBMem =0
lStressMem=0
l_conv =.true.
l_conv_nl=.true.
l_mag =.true.
Expand Down Expand Up @@ -746,7 +745,6 @@ subroutine readNamelists(tscheme)
& ( l_rot_ic .and. kbotv == 2 ) ) l_z10mat= .true.

!-- Check whether memory has been reserved:
if ( l_TO ) lStressMem=1
if ( l_RMS .or. l_DTrMagSpec ) ldtBMem=1

!-- Output of angular moment?
Expand Down
70 changes: 35 additions & 35 deletions src/TO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module torsional_oscillations
use iso_fortran_env, only: output_unit
use precision_mod
use mem_alloc, only: bytes_allocated
use truncation, only: n_phi_maxStr, n_r_maxStr, l_max, n_theta_maxStr, lm_max, &
use truncation, only: n_phi_max, n_r_max, l_max, n_theta_max, lm_max, &
& nlat_padded
use radial_data, only: nRstart, nRstop
use radial_functions, only: or1, or2, or3, or4, beta, orho1, dbeta
Expand Down Expand Up @@ -47,19 +47,19 @@ subroutine initialize_TO
! Allocate the memory needed
!

allocate( dzStrAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( dzRstrAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( dzAStrAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( dzCorAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( dzdVpAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( dzddVpAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( VAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( V2AS_Rloc(n_theta_maxStr,nRstart:nRstop) )
bytes_allocated = bytes_allocated+8*(nRstop-nRstart+1)*n_theta_maxStr* &
allocate( dzStrAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( dzRstrAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( dzAStrAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( dzCorAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( dzdVpAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( dzddVpAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( VAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( V2AS_Rloc(n_theta_max,nRstart:nRstop) )
bytes_allocated = bytes_allocated+8*(nRstop-nRstart+1)*n_theta_max* &
& SIZEOF_DEF_REAL
if ( l_phase_field ) then
allocate( dzPenAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
bytes_allocated = bytes_allocated+(nRstop-nRstart+1)*n_theta_maxStr* &
allocate( dzPenAS_Rloc(n_theta_max,nRstart:nRstop) )
bytes_allocated = bytes_allocated+(nRstop-nRstart+1)*n_theta_max* &
& SIZEOF_DEF_REAL
end if

Expand All @@ -72,8 +72,8 @@ subroutine initialize_TO
allocate( ddzASL(l_max+1,nRstart:nRstop) )
bytes_allocated = bytes_allocated+(l_max+1)*(nRstop-nRstart+1)*SIZEOF_DEF_REAL
else
allocate( ddzASL(l_max+1,n_r_maxStr) )
bytes_allocated = bytes_allocated+(l_max+1)*n_r_maxStr*SIZEOF_DEF_REAL
allocate( ddzASL(l_max+1,n_r_max) )
bytes_allocated = bytes_allocated+(l_max+1)*n_r_max*SIZEOF_DEF_REAL
end if
allocate( zASL(l_max+1), dzASL(l_max+1) )
bytes_allocated = bytes_allocated+2*(l_max+1)*SIZEOF_DEF_REAL
Expand All @@ -82,22 +82,22 @@ subroutine initialize_TO
zASL(:) =0.0_cp

if ( l_mag ) then
allocate( dzLFAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( Bs2AS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BszAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BspAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BpzAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BspdAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BpsdAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BzpdAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
allocate( BpzdAS_Rloc(n_theta_maxStr,nRstart:nRstop) )
bytes_allocated = bytes_allocated+9*(nRstop-nRstart+1)*n_theta_maxStr* &
allocate( dzLFAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( Bs2AS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BszAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BspAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BpzAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BspdAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BpsdAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BzpdAS_Rloc(n_theta_max,nRstart:nRstop) )
allocate( BpzdAS_Rloc(n_theta_max,nRstart:nRstop) )
bytes_allocated = bytes_allocated+9*(nRstop-nRstart+1)*n_theta_max* &
& SIZEOF_DEF_REAL

allocate( BsLast(n_theta_maxStr,n_phi_maxStr,nRstart:nRstop) )
allocate( BpLast(n_theta_maxStr,n_phi_maxStr,nRstart:nRstop) )
allocate( BzLast(n_theta_maxStr,n_phi_maxStr,nRstart:nRstop) )
bytes_allocated = bytes_allocated+3*n_phi_maxStr*n_theta_maxStr* &
allocate( BsLast(n_theta_max,n_phi_max,nRstart:nRstop) )
allocate( BpLast(n_theta_max,n_phi_max,nRstart:nRstop) )
allocate( BzLast(n_theta_max,n_phi_max,nRstart:nRstop) )
bytes_allocated = bytes_allocated+3*n_phi_max*n_theta_max* &
& (nRstop-nRstart+1)*SIZEOF_DEF_REAL
end if

Expand Down Expand Up @@ -173,10 +173,10 @@ subroutine getTO(vr,vt,vp,cvr,dvpdr,br,bt,bp,cbr,cbt,phase,dtLast,nR)

if ( lVerbose ) write(output_unit,*) '! Starting getTO!'

phiNorm=one/real(n_phi_maxStr, kind=cp)
phiNorm=one/real(n_phi_max, kind=cp)

!-- Set values to zero before filling it
do nTheta=1,n_theta_maxStr
do nTheta=1,n_theta_max
dzCorAS_Rloc(nTheta,nR) =0.0_cp
dzRstrAS_Rloc(nTheta,nR)=0.0_cp
dzAstrAS_Rloc(nTheta,nR)=0.0_cp
Expand All @@ -185,7 +185,7 @@ subroutine getTO(vr,vt,vp,cvr,dvpdr,br,bt,bp,cbr,cbt,phase,dtLast,nR)
end do

!-- Big loop over thetas in block:
do nTheta=1,n_theta_maxStr
do nTheta=1,n_theta_max
nTheta1=n_theta_cal2ord(nTheta)
sinT =sinTheta(nTheta)
cosT =cosTheta(nTheta)
Expand Down Expand Up @@ -226,7 +226,7 @@ subroutine getTO(vr,vt,vp,cvr,dvpdr,br,bt,bp,cbr,cbt,phase,dtLast,nR)
BzpdMean =0.0_cp
BpzdMean =0.0_cp
end if
do nPhi=1,n_phi_maxStr
do nPhi=1,n_phi_max
VrMean =VrMean +vr(nTheta,nPhi)
VtMean =VtMean +vt(nTheta,nPhi)
VpMean =VpMean +vp(nTheta,nPhi)
Expand Down Expand Up @@ -335,8 +335,8 @@ subroutine getTOnext(br,bt,bp,lTONext,lTONext2,dt,dtLast,nR)
if ( l_mag ) then
!$omp parallel do default(shared) &
!$omp& private(nPhi, nTh)
do nPhi=1,n_phi_maxStr
do nTh=1,n_theta_maxStr
do nPhi=1,n_phi_max
do nTh=1,n_theta_max
BsLast(nTh,nPhi,nR)=or2(nR)*sinTheta(nTh)*br(nTh,nPhi) + &
& or1(nR)*cosTheta(nTh)*O_sin_theta(nTh)*bt(nTh,nPhi)
BpLast(nTh,nPhi,nR)=or1(nR)*bp(nTh,nPhi)*O_sin_theta(nTh)
Expand Down Expand Up @@ -419,7 +419,7 @@ subroutine get_PAS(Tlm,Bp,nR)
call toraxi_to_spat(Tl_AX(1:l_max+1), tmpt(:), tmpp(:))

!-- Unscramble theta
do nTheta=1,n_theta_maxStr
do nTheta=1,n_theta_max
nTheta1=n_theta_cal2ord(nTheta)
Bp(nTheta1)=O_sin_theta(nTheta)*tmpp(nTheta)*or1(nR)
end do
Expand Down
16 changes: 1 addition & 15 deletions src/truncation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ module truncation
integer :: n_r_max_dtB ! Number of radial points for movie output
integer :: n_r_ic_max_dtB ! Number of IC radial points for movie output

!--- Memory control for stress output:
integer :: lStressMem ! Memory for stress output
integer :: n_r_maxStr ! Number of radial points for stress output
integer :: n_theta_maxStr ! Number of theta points for stress output
integer :: n_phi_maxStr ! Number of phi points for stress output

contains

subroutine initialize_truncation

integer :: n_r_maxML,n_r_ic_maxML,n_r_totML,l_maxML,lm_maxML
integer :: lm_max_dL,n_r_max_dL,n_r_ic_max_dL
integer :: n_r_maxSL,n_theta_maxSL,n_phi_maxSL, l, m
integer :: l, m

if ( .not. l_axi ) then
if ( l_max == 0 ) then
Expand Down Expand Up @@ -144,14 +138,6 @@ subroutine initialize_truncation
n_r_max_dtB =max(n_r_max_DL,1)
n_r_ic_max_dtB=max(n_r_ic_max_DL,1)

!--- Memory control for stress output:
n_r_maxSL =lStressMem*n_r_max
n_theta_maxSL =lStressMem*n_theta_max
n_phi_maxSL =lStressMem*n_phi_max
n_r_maxStr =max(n_r_maxSL,1)
n_theta_maxStr=max(n_theta_maxSL,1)
n_phi_maxStr =max(n_phi_maxSL,1)

end subroutine initialize_truncation
!--------------------------------------------------------------------------------
subroutine checkTruncation
Expand Down

0 comments on commit 51ea649

Please sign in to comment.