From 3ba7b78fff92c787f7eb9b3c65501200920cf33e Mon Sep 17 00:00:00 2001 From: Thomas Gastine Date: Mon, 9 Sep 2024 15:12:08 +0200 Subject: [PATCH] remove useless dtB_arrays module Rather use local private arrays in dtB directly --- src/Makefile | 5 +- src/debugging.f90 | 119 ------------------------------------------ src/dtB.f90 | 50 ++++++++++-------- src/dtB_arrays.f90 | 69 ------------------------ src/out_dtB_frame.f90 | 4 +- src/rIter.f90 | 24 ++------- 6 files changed, 33 insertions(+), 238 deletions(-) delete mode 100644 src/debugging.f90 delete mode 100644 src/dtB_arrays.f90 diff --git a/src/Makefile b/src/Makefile index aee0e0f9..06fe08a8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -343,8 +343,6 @@ mem_alloc.o : parallel.o precision_mod.o output_data.o out_TO.o : truncation.o horizontal.o num_param.o logic.o\ phys_param.o radial.o parallel.o integration.o\ constants.o output_data.o TO.o useful.o mem_alloc.o -dtB_arrays.o : truncation.o precision_mod.o constants.o\ - mem_alloc.o courant.o : truncation.o blocking.o num_param.o\ phys_param.o radial.o horizontal.o logic.o\ useful.o radial_data.o parallel.o @@ -417,10 +415,9 @@ LMLoop.o : truncation.o blocking.o parallel.o time_array.o\ logic.o radial_data.o updateWPS.o\ output_data.o fields.o dt_fieldsLast.o\ updateS.o updateB.o mem_alloc.o updateXI.o\ - updateZ.o updateWP.o debugging.o + updateZ.o updateWP.o mpi_transpose.o : precision_mod.o truncation.o radial_data.o\ mem_alloc.o parallel.o blocking.o -debugging.o : precision_mod.o precision_mod.o timing.o : parallel.o precision_mod.o radial_derivatives.o : $(DCT_OBJS) constants.o precision_mod.o chebyshev.o output.o : truncation.o blocking.o phys_param.o\ diff --git a/src/debugging.f90 b/src/debugging.f90 deleted file mode 100644 index 0034a193..00000000 --- a/src/debugging.f90 +++ /dev/null @@ -1,119 +0,0 @@ -module debugging - - use precision_mod - - implicit none - - private - - interface debug_write - module procedure debug_write_2D,debug_write_1D - end interface - - public :: debug_write - -contains - - subroutine debug_write_2D(arr,dim1,dim2,label,timestep,form) - - !-- Input variables - integer, intent(in) :: dim1, dim2 - complex(cp), intent(in) :: arr(dim1,dim2) - character(len=*), intent(in) :: label - integer, intent(in) :: timestep - character(len=1), optional, intent(in) :: form - - !-- Local variables - character(len=50) :: filename - logical :: write_unformatted,write_exponent - integer :: i,j,fileHandle - - if (present(form)) then - if ((form == 'U').or.(form == 'u')) then - write_unformatted=.true. - elseif (form == 'E') then - write_unformatted=.false. - write_exponent=.true. - else - write_unformatted=.false. - write_exponent=.false. - end if - else - write_unformatted=.true. - end if - - if (write_unformatted) then - write(filename,"(A,I4.4,A)") trim(label),timestep,".dat" - open(newunit=fileHandle,file=trim(filename),form="unformatted") - write(fileHandle) arr - close(fileHandle) - else - write(filename,"(A,I4.4,A)") trim(label),timestep,".txt" - open(newunit=fileHandle,file=trim(filename)) - do j=1,dim2 - do i=1,dim1 - if (write_exponent) then - write(fileHandle,"(2(I4,F21.18))") exponent(real(arr(i,j))),& - & fraction(real(arr(i,j))), exponent(aimag(arr(i,j))), & - & fraction(aimag(arr(i,j))) - else - write(fileHandle,"(2ES22.15)") arr(i,j) - end if - end do - end do - close(fileHandle) - end if - - end subroutine debug_write_2D -!------------------------------------------------------------------------------ - subroutine debug_write_1D(arr,dim1,label,timestep,form) - - !-- Input variables: - integer, intent(in) :: dim1 - complex(cp), intent(in) :: arr(dim1) - character(len=*), intent(in) :: label - integer, intent(in) :: timestep - character(len=1), optional, intent(in) :: form - - !-- Local variables - character(len=50) :: filename - logical :: write_unformatted,write_exponent - integer :: i, fileHandle - - if (present(form)) then - if ((form == 'U').or.(form == 'u')) then - write_unformatted=.true. - elseif (form == 'E') then - write_unformatted=.false. - write_exponent=.true. - else - write_unformatted=.false. - write_exponent=.false. - end if - else - write_unformatted=.true. - end if - - if (write_unformatted) then - write(filename,"(A,I4.4,A)") trim(label),timestep,".dat" - open(newunit=fileHandle,file=trim(filename),form="unformatted") - write(fileHandle) arr - close(fileHandle) - else - write(filename,"(A,I4.4,A)") trim(label),timestep,".txt" - open(newunit=fileHandle,file=trim(filename)) - do i=1,dim1 - if (write_exponent) then - write(fileHandle,"(2(I4,F21.18))") exponent(real(arr(i))), & - & fraction(real(arr(i))), exponent(aimag(arr(i))), & - & fraction(aimag(arr(i))) - else - write(fileHandle,"(2ES22.15)") arr(i) - end if - end do - close(fileHandle) - end if - - end subroutine debug_write_1D -!------------------------------------------------------------------------------ -end module debugging diff --git a/src/dtB.f90 b/src/dtB.f90 index ccbd01e8..fad0d024 100644 --- a/src/dtB.f90 +++ b/src/dtB.f90 @@ -24,7 +24,7 @@ module dtB_mod & lm2lmS, lm2lmA use radial_spectra ! rBrSpec, rBpSpec use sht, only: scal_to_SH, spat_to_sphertor - use constants, only: two, ci + use constants, only: zero, two, ci use radial_der, only: get_dr implicit none @@ -57,6 +57,12 @@ module dtB_mod complex(cp), public, allocatable :: PadvLMIC_LMloc(:,:), PdifLMIC_LMloc(:,:) complex(cp), public, allocatable :: TadvLMIC_LMloc(:,:), TdifLMIC_LMloc(:,:) + !-- Local private complex arrays for SH transforms + complex(cp), allocatable :: BtVrLM(:), BpVrLM(:), BrVtLM(:) + complex(cp), allocatable :: BtVpLM(:), BpVtLM(:), BrVpLM(:) + complex(cp), allocatable :: BpVtBtVpCotLM(:), BpVtBtVpSn2LM(:) + complex(cp), allocatable :: BtVZLM(:), BtVZsn2LM(:), BrVZLM(:) + class(type_mpitransp), pointer :: r2lo_dtB public :: initialize_dtB_mod, get_dtBLMfinish, get_dtBLM, get_dH_dtBLM, & @@ -73,7 +79,6 @@ subroutine initialize_dtB_mod ! The remaining global arrays should be suppressed, they are only ! needed because of some movie outputs ! - if ( l_dtBmovie ) then if ( rank == 0 ) then allocate( PstrLM(lm_max,n_r_max), PadvLM(lm_max,n_r_max) ) @@ -96,6 +101,23 @@ subroutine initialize_dtB_mod end if end if + allocate( BtVrLM(lm_max), BpVrLM(lm_max), BrVtLM(lm_max), BrVpLM(lm_max) ) + allocate( BtVpLM(lm_max), BpVtLM(lm_max), BpVtBtVpCotLM(lm_max) ) + allocate( BpVtBtVpSn2LM(lm_max), BrVZLM(lm_max), BtVZLM(lm_max) ) + allocate( BtVZsn2LM(lm_max) ) + bytes_allocated = bytes_allocated+ 11*lm_max*SIZEOF_DEF_COMPLEX + BtVrLM(:) = zero + BpVrLM(:) = zero + BrVtLM(:) = zero + BrVpLM(:) = zero + BtVpLM(:) = zero + BpVtLM(:) = zero + BrVZLM(:) = zero + BtVZLM(:) = zero + BpVtBtVpCotLM(:) = zero + BpVtBtVpSn2LM(:) = zero + BtVZsn2LM(:) = zero + allocate( PdifLM_LMloc(llmMag:ulmMag,n_r_max) ) allocate( TdifLM_LMloc(llmMag:ulmMag,n_r_max) ) bytes_allocated = bytes_allocated+ & @@ -147,6 +169,8 @@ subroutine finalize_dtB_mod deallocate( TdifLMIC, TadvLMIC, PdifLMIC, PadvLMIC, TdifLM, PdifLM ) end if + deallocate( BtVrLM, BpVrLM, BrVtLM, BrVpLM, BtVpLM, BpVtLM ) + deallocate( BpVtBtVpCotLM, BpVtBtVpSn2LM, BrVZLM, BtVZLM, BtVZsn2LM ) deallocate( PdifLM_LMloc, TdifLM_LMloc, PadvLMIC_LMloc, PdifLMIC_LMloc ) deallocate( TadvLMIC_LMloc, TdifLMIC_LMloc ) deallocate( dtB_Rloc_container, dtB_LMloc_container ) @@ -176,9 +200,7 @@ subroutine dtb_gather_lo_on_rank0 end subroutine dtb_gather_lo_on_rank0 !---------------------------------------------------------------------------- - subroutine get_dtBLM(nR,vr,vt,vp,br,bt,bp,BtVrLM,BpVrLM,BrVtLM,BrVpLM, & - & BtVpLM,BpVtLM,BrVZLM,BtVZLM,BpVtBtVpCotLM, & - & BpVtBtVpSn2LM,BtVZsn2LM) + subroutine get_dtBLM(nR,vr,vt,vp,br,bt,bp) ! ! This subroutine calculates non-linear products in grid-space for radial ! level nR. @@ -189,15 +211,6 @@ subroutine get_dtBLM(nR,vr,vt,vp,br,bt,bp,BtVrLM,BpVrLM,BrVtLM,BrVpLM, & real(cp), intent(in) :: vr(:,:),vt(:,:),vp(:,:) real(cp), intent(in) :: br(:,:),bt(:,:),bp(:,:) - !-- Output variables: - complex(cp), intent(out) :: BtVrLM(:),BpVrLM(:) - complex(cp), intent(out) :: BrVtLM(:),BrVpLM(:) - complex(cp), intent(out) :: BtVpLM(:),BpVtLM(:) - complex(cp), intent(out) :: BrVZLM(:),BtVZLM(:) - complex(cp), intent(out) :: BpVtBtVpCotLM(:) - complex(cp), intent(out) :: BpVtBtVpSn2LM(:) - complex(cp), intent(out) :: BtVZsn2LM(:) - !-- Local variables: integer :: n_theta,n_phi real(cp) :: fac,facCot @@ -270,8 +283,7 @@ subroutine get_dtBLM(nR,vr,vt,vp,br,bt,bp,BtVrLM,BpVrLM,BrVtLM,BrVpLM, & end subroutine get_dtBLM !----------------------------------------------------------------------- - subroutine get_dH_dtBLM(nR,BtVrLM,BpVrLM,BrVtLM,BrVpLM,BtVpLM,BpVtLM, & - & BrVZLM,BtVZLM,BpVtBtVpCotLM,BpVtBtVpSn2LM) + subroutine get_dH_dtBLM(nR) ! ! Purpose of this routine is to calculate theta and phi ! derivative related terms of the magnetic production and @@ -280,12 +292,6 @@ subroutine get_dH_dtBLM(nR,BtVrLM,BpVrLM,BrVtLM,BrVpLM,BtVpLM,BpVtLM, & !-- Input variables: integer, intent(in) :: nR - complex(cp), intent(in) :: BtVrLM(*),BpVrLM(*) - complex(cp), intent(in) :: BrVtLM(*),BrVpLM(*) - complex(cp), intent(in) :: BtVpLM(*),BpVtLM(*) - complex(cp), intent(in) :: BpVtBtVpCotLM(*) - complex(cp), intent(in) :: BpVtBtVpSn2LM(*) - complex(cp), intent(in) :: BrVZLM(*),BtVZLM(*) !-- Local variables: integer :: l,m,lm,lmS,lmA diff --git a/src/dtB_arrays.f90 b/src/dtB_arrays.f90 deleted file mode 100644 index 9a676786..00000000 --- a/src/dtB_arrays.f90 +++ /dev/null @@ -1,69 +0,0 @@ -module dtB_arrays_mod - - use truncation, only: lm_max - use mem_alloc, only: bytes_allocated - use precision_mod - use constants, only: zero - - implicit none - - private - - type, public :: dtB_arrays_t - !----- Local dtB output stuff: - complex(cp), allocatable :: BtVrLM(:), BpVrLM(:), BrVtLM(:) - complex(cp), allocatable :: BtVpLM(:), BpVtLM(:), BrVpLM(:) - complex(cp), allocatable :: BpVtBtVpCotLM(:), BpVtBtVpSn2LM(:) - complex(cp), allocatable :: BrVZLM(:), BtVZLM(:), BtVZsn2LM(:) - contains - procedure :: initialize - procedure :: finalize - procedure :: set_zero - end type dtB_arrays_t - -contains - - subroutine initialize(this) - - class(dtB_arrays_t) :: this - - allocate( this%BtVrLM(lm_max), this%BpVrLM(lm_max) ) - allocate( this%BrVtLM(lm_max), this%BrVpLM(lm_max) ) - allocate( this%BtVpLM(lm_max), this%BpVtLM(lm_max) ) - allocate( this%BpVtBtVpCotLM(lm_max), this%BpVtBtVpSn2LM(lm_max) ) - allocate( this%BrVZLM(lm_max), this%BtVZLM(lm_max) ) - allocate( this%BtVZsn2LM(lm_max) ) - bytes_allocated = bytes_allocated+ 11*lm_max*SIZEOF_DEF_COMPLEX - - end subroutine initialize -!---------------------------------------------------------------------------- - subroutine finalize(this) - - class(dtB_arrays_t) :: this - - deallocate( this%BtVrLM, this%BpVrLM, this%BrVtLM ) - deallocate( this%BrVpLM, this%BtVpLM, this%BpVtLM ) - deallocate( this%BpVtBtVpCotLM, this%BpVtBtVpSn2LM ) - deallocate( this%BrVZLM, this%BtVZLM, this%BtVZsn2LM ) - - end subroutine finalize -!---------------------------------------------------------------------------- - subroutine set_zero(this) - - class(dtB_arrays_t) :: this - - this%BtVrLM(:) = zero - this%BpVrLM(:) = zero - this%BrVtLM(:) = zero - this%BrVpLM(:) = zero - this%BtVpLM(:) = zero - this%BpVtLM(:) = zero - this%BrVZLM(:) = zero - this%BtVZLM(:) = zero - this%BpVtBtVpCotLM(:) = zero - this%BpVtBtVpSn2LM(:) = zero - this%BtVZsn2LM(:) = zero - - end subroutine set_zero -!---------------------------------------------------------------------------- -end module dtB_arrays_mod diff --git a/src/out_dtB_frame.f90 b/src/out_dtB_frame.f90 index 4c36dbd3..f7a50e79 100644 --- a/src/out_dtB_frame.f90 +++ b/src/out_dtB_frame.f90 @@ -83,7 +83,6 @@ subroutine write_dtB_frame(n_movie,b,db,aj,dj,b_ic,db_ic,aj_ic,dj_ic) const =movie_const(n_movie) !--- Axisymmetric dtFL or dtAB: - if ( n_type == 31 .or. n_type == 32 .or. n_type == 33 .or. & & n_type == 41 .or. n_type == 42 .or. n_type == 43 ) then @@ -150,7 +149,7 @@ subroutine write_dtB_frame(n_movie,b,db,aj,dj,b_ic,db_ic,aj_ic,dj_ic) end do - !--- dtBr: + !--- dtBr: else ! non-axisymmetric fields do n_field=1,n_fields @@ -184,7 +183,6 @@ subroutine write_dtB_frame(n_movie,b,db,aj,dj,b_ic,db_ic,aj_ic,dj_ic) end if !------ Outer core contribution: - !------ Calculate needed radial derivatives: if ( n_field_type == 35 ) then call get_dr(PstrLM,workA,lm_max,1,lm_max, & diff --git a/src/rIter.f90 b/src/rIter.f90 index 1a73cea7..576c3f47 100644 --- a/src/rIter.f90 +++ b/src/rIter.f90 @@ -28,7 +28,6 @@ module rIter_mod use constants, only: zero use nonlinear_lm_mod, only: nonlinear_lm_t use grid_space_arrays_mod, only: grid_space_arrays_t - use dtB_arrays_mod, only: dtB_arrays_t use torsional_oscillations, only: prep_TO_axi, getTO, getTOnext, getTOfinish #ifdef WITH_MPI use graphOut_mod, only: graphOut_mpi, graphOut_mpi_header @@ -63,7 +62,6 @@ module rIter_mod type, public, extends(rIter_t) :: rIter_single_t type(grid_space_arrays_t) :: gsa - type(dtB_arrays_t) :: dtB_arrays type(nonlinear_lm_t) :: nl_lm contains procedure :: initialize @@ -80,7 +78,6 @@ subroutine initialize(this) class(rIter_single_t) :: this call this%gsa%initialize() - if ( l_RMS .or. l_DTrMagSpec ) call this%dtB_arrays%initialize() call this%nl_lm%initialize(lm_max) end subroutine initialize @@ -90,7 +87,6 @@ subroutine finalize(this) class(rIter_single_t) :: this call this%gsa%finalize() - if ( l_RMS .or. l_DTrMagSpec ) call this%dtB_arrays%finalize() call this%nl_lm%finalize() end subroutine finalize @@ -390,15 +386,8 @@ subroutine radialLoop(this,l_graph,l_frame,time,timeStage,tscheme,dtLast, & !--------- Calculation of magnetic field production and advection terms ! for graphic output: if ( l_dtB ) then - call get_dtBLM(nR,this%gsa%vrc,this%gsa%vtc,this%gsa%vpc, & - & this%gsa%brc,this%gsa%btc,this%gsa%bpc, & - & this%dtB_arrays%BtVrLM,this%dtB_arrays%BpVrLM, & - & this%dtB_arrays%BrVtLM,this%dtB_arrays%BrVpLM, & - & this%dtB_arrays%BtVpLM,this%dtB_arrays%BpVtLM, & - & this%dtB_arrays%BrVZLM,this%dtB_arrays%BtVZLM, & - & this%dtB_arrays%BpVtBtVpCotLM, & - & this%dtB_arrays%BpVtBtVpSn2LM, & - & this%dtB_arrays%BtVZsn2LM) + call get_dtBLM(nR,this%gsa%vrc,this%gsa%vtc,this%gsa%vpc, & + & this%gsa%brc,this%gsa%btc,this%gsa%bpc) end if @@ -450,14 +439,7 @@ subroutine radialLoop(this,l_graph,l_frame,time,timeStage,tscheme,dtLast, & !--- Form partial horizontal derivaties of magnetic production and ! advection terms: - if ( l_dtB ) then - call get_dH_dtBLM(nR,this%dtB_arrays%BtVrLM,this%dtB_arrays%BpVrLM, & - & this%dtB_arrays%BrVtLM,this%dtB_arrays%BrVpLM, & - & this%dtB_arrays%BtVpLM,this%dtB_arrays%BpVtLM, & - & this%dtB_arrays%BrVZLM,this%dtB_arrays%BtVZLM, & - & this%dtB_arrays%BpVtBtVpCotLM, & - & this%dtB_arrays%BpVtBtVpSn2LM) - end if + if ( l_dtB ) call get_dH_dtBLM(nR) end do