program uDALES
!!----------------------------------------------------------------
!! 0.0 USE STATEMENTS FOR CORE MODULES
!!----------------------------------------------------------------
use mpi
use modmpi, only : initmpi,exitmpi,starttimer,myid
use modglobal, only : initglobal,rk3step,timeleft
use modglobal, only : runmode,RUN_COLDSTART,RUN_WARMSTART,RUN_DRIVER,RUN_STRATSTART,TEST_SPARSE_IJK,TEST_2DCOMP_INIT_EXIT,TEST_MPI_OPERATORS
use modstartup, only : readnamelists,init2decomp,checkinitvalues,readinitfiles,exitmodules
use modfields, only : initfields
use modsave, only : writerestartfiles
use modboundary, only : initboundary,boundary,grwdamp,halos
use modthermodynamics, only : initthermodynamics,thermodynamics
use modsubgrid, only : initsubgrid,subgrid
use modforces, only : calcfluidvolumes,forces,coriolis,lstend,fixuinf1,fixuinf2,fixthetainf,nudge,masscorr,shiftedPBCs,periodicEBcorr
use modpois, only : initpois,poisson
use modibm, only : initibm,createmasks,ibmwallfun,ibmnorm,bottom
use vegetation, only : init_vegetation, vegetation_forcing
use modpurifiers, only : createpurifiers,purifiers
use modheatpump, only : init_heatpump,heatpump,exit_heatpump
use initfac, only : readfacetfiles
use modEB, only : initEB,EB
use moddriver, only : initdriver
use modadvection, only : advection
use modtstep, only : tstep_update,tstep_integrate
use modscalsource, only : createscals,scalsource
!----------------------------------------------------------------
! 0.1 USE STATEMENTS FOR ADDONS STATISTICAL ROUTINES
!----------------------------------------------------------------
use modchecksim, only : initchecksim,checksim
use modstat_nc, only : initstat_nc
use modfielddump, only : initfielddump,fielddump,exitfielddump
use modstatsdump, only : initstatsdump,statsdump,exitstatsdump !tg3315
use modtimedep, only : inittimedep,timedep
use tests, only : tests_read_sparse_ijk,tests_2decomp_init_exit,tests_mpi_operators
implicit none
real :: stime
!----------------------------------------------------------------
! 0 READ NAMELISTS,INITIALISE GRID, CONSTANTS AND FIELDS
!----------------------------------------------------------------
call initmpi
stime = MPI_Wtime()
!call startup
call readnamelists
call init2decomp
call checkinitvalues
call initglobal
! Execute tests if needed
call execute_runmode_actions
call initfields
call initboundary
call initthermodynamics
call initsubgrid
! call initinlet
call initdriver
call initpois
call readfacetfiles
! These should be combined once file format is sorted
call initibm
call createmasks
call calcfluidvolumes
call readinitfiles
call createscals
!---------------------------------------------------------
! 2 INITIALIZE STATISTICAL ROUTINES AND ADD-ONS
!---------------------------------------------------------
call initchecksim ! Could be deprecated
call initstat_nc ! Could be deprecated
call initstatsdump
call initEB
call inittimedep
call initfielddump
call boundary
call init_vegetation
call createpurifiers
call init_heatpump
!call fielddump
call print_time('After initialization')
!------------------------------------------------------
! 3.0 MAIN TIME LOOP
!------------------------------------------------------
call starttimer
do while ((timeleft>0) .or. (rk3step < 3))
call tstep_update
call timedep
!-----------------------------------------------------
! 3.2 ADVECTION AND DIFFUSION
!-----------------------------------------------------
call advection ! includes predicted pressure gradient term
call shiftedPBCs
call subgrid
!-----------------------------------------------------
! 3.3 THE SURFACE LAYER
!-----------------------------------------------------
call bottom
!-----------------------------------------------------
! 3.4 REMAINING TERMS
!-----------------------------------------------------
call coriolis !remaining terms of ns equation
call forces !remaining terms of ns equation
call lstend !large scale forcings
call nudge ! nudge top cells of fields to enforce steady-state
call ibmwallfun ! immersed boundary forcing: only shear forces.
call periodicEBcorr
call masscorr ! correct pred. velocity pup to get correct mass flow
call ibmnorm ! immersed boundary forcing: set normal velocities to zero
call EB
call vegetation_forcing
call heatpump
call scalsource ! adds continuous forces in specified region of domain
!------------------------------------------------------
! 3.4 EXECUTE ADD ONS
!------------------------------------------------------
call fixuinf2
call fixuinf1
!-----------------------------------------------------------------------
! 3.5 PRESSURE FLUCTUATIONS, TIME INTEGRATION AND BOUNDARY CONDITIONS
!-----------------------------------------------------------------------
call grwdamp !damping at top of the model
call poisson
call purifiers !placing of purifiers here may need to be checked
call tstep_integrate
call halos
call checksim
call fielddump
call statsdump
call boundary
!call fixthetainf ! deprecated
!-----------------------------------------------------
! 3.6 LIQUID WATER CONTENT AND DIAGNOSTIC FIELDS
!-----------------------------------------------------
call thermodynamics
!-----------------------------------------------------
! 3.7 WRITE RESTARTFILES AND DO STATISTICS
!------------------------------------------------------
call writerestartfiles
end do
!-------------------------------------------------------
! END OF TIME LOOP
!-------------------------------------------------------
call print_time('After main time loop')
!--------------------------------------------------------
! 4 FINALIZE ADD ONS AND THE MAIN PROGRAM
!-------------------------------------------------------
call exitfielddump
call exitstatsdump !tg3315
call exit_heatpump
!call exitmodules
!call exittest
call print_time('After finalization')
call exitmpi
contains
subroutine print_time(phase_name)
use modmpi, only : comm3d, mpierr
implicit none
character(len=*), intent(in) :: phase_name
real :: tnow
call MPI_BARRIER(comm3d, mpierr)
tnow = MPI_Wtime()
if (myid == 0) then
write(6,'(3A,F12.6,A)') 'Wall time for phase [', trim(phase_name), '] : ', tnow - stime, ' seconds'
end if
stime = tnow
end subroutine print_time
subroutine execute_runmode_actions
logical :: test_failed
logical :: invalid_runmode
test_failed = .false.
invalid_runmode = .false.
select case (runmode)
case (RUN_COLDSTART, RUN_WARMSTART, RUN_DRIVER, RUN_STRATSTART)
return
! Normal execution mode, do nothing special here
case (TEST_SPARSE_IJK)
! Execute tests for reading sparse arrays
test_failed = .not. tests_read_sparse_ijk()
case (TEST_MPI_OPERATORS)
test_failed = .not. tests_mpi_operators()
case (TEST_2DCOMP_INIT_EXIT)
call tests_2decomp_init_exit
case default
write(*,*) 'Unknown runmode:', runmode
invalid_runmode = .true.
end select
call exitmpi
if (invalid_runmode) then
stop 1
end if
! Return appropriate exit code for unit tests:
! 0 = success, 1 = failure
if (test_failed) then
stop 1
else
stop 0
end if
end subroutine execute_runmode_actions
end program uDALES