diff --git a/cellular_automata_global.F90 b/cellular_automata_global.F90 index a815aaef..2f3f236c 100644 --- a/cellular_automata_global.F90 +++ b/cellular_automata_global.F90 @@ -1,7 +1,7 @@ module cellular_automata_global_mod use update_ca, only : domain_global,iscnx_g,iecnx_g,jscnx_g,jecnx_g,isdnx_g,iednx_g,jsdnx_g,jednx_g, & - nxncells_g,nyncells_g,csum + nxncells_g,nyncells_g,csum,cold_start_ca_global implicit none contains diff --git a/cellular_automata_sgs.F90 b/cellular_automata_sgs.F90 index 1628ef4f..2bd47f6b 100644 --- a/cellular_automata_sgs.F90 +++ b/cellular_automata_sgs.F90 @@ -1,6 +1,6 @@ module cellular_automata_sgs_mod -use update_ca, only : domain_global,domain_sgs,iscnx,iecnx,jscnx,jecnx,isdnx,iednx,jsdnx,jednx,nxncells,nyncells +use update_ca, only : domain_global,domain_sgs,iscnx,iecnx,jscnx,jecnx,isdnx,iednx,jsdnx,jednx,nxncells,nyncells,cold_start_ca_sgs implicit none @@ -161,6 +161,8 @@ subroutine cellular_automata_sgs(kstep,dtf,restart,first_time_step,sst,lsmsk,lak allocate(CA_DEEP(nlon,nlat)) !Initialize: + ilives_in(:,:,:) = 0 + iini(:,:,:) = 0 !Put the blocks of model fields into a 2d array - can't use nlev and blocksize directly, !because the arguments to define_blocks_packed are intent(inout) and not intent(in). @@ -228,7 +230,7 @@ subroutine cellular_automata_sgs(kstep,dtf,restart,first_time_step,sst,lsmsk,lak endif !Generate random number, following stochastic physics code: -if (.not. restart) then +if (cold_start_ca_sgs) then if(kstep == initialize_ca) then nx_full=int(ncells,kind=8)*int(npx-1,kind=8) allocate(noise(nxc,nyc,nca)) @@ -271,7 +273,7 @@ subroutine cellular_automata_sgs(kstep,dtf,restart,first_time_step,sst,lsmsk,lak deallocate(noise) endif ! -endif ! restart +endif ! cold_start_ca_sgs !Calculate neighbours and update the automata do nf=1,nca diff --git a/unit_tests/input.nml.ca_template b/unit_tests/input.nml.ca_template index b4cd0439..dcd9745d 100644 --- a/unit_tests/input.nml.ca_template +++ b/unit_tests/input.nml.ca_template @@ -51,8 +51,8 @@ ca_sgs = CA_SGS ca_global = CA_GLOBAL nca = 1 - scells = 2600 - tlives = 1800 + ncells = 5 + nlives = 12 nseed = 100 nfracseed = 0.5 rcell = 0.72 diff --git a/unit_tests/run_unit_tests_ca.sh b/unit_tests/run_unit_tests_ca.sh index 77c4f04c..0a9553d5 100755 --- a/unit_tests/run_unit_tests_ca.sh +++ b/unit_tests/run_unit_tests_ca.sh @@ -10,7 +10,7 @@ RES=96 NPX=`expr $RES + 1` NPY=`expr $RES + 1` -DO_CA_SGS=.false. +DO_CA_SGS=.true. DO_CA_GLOBAL=.true. source ./module-setup.sh @@ -19,7 +19,7 @@ module use $( pwd -P ) module load modules.stoch EXEC=standalone_ca.x # compile codes -#sh compile_standalone_ca.hera.intel +sh compile_standalone_ca.hera.intel if [ ! -f $EXEC ];then echo "compilation errors" exit 1 @@ -78,6 +78,37 @@ mkdir -p RESTART echo "unit test 1 successful" fi set OMP_NUM_THREADS=2 + + cp input.nml.ca_template input.nml + ct=1 + while [ $ct -le 6 ];do + rm INPUT/ca_data.tile${ct}.nc + ct=`expr $ct + 1` + done + sed -i -e "s/LOX/1/g" input.nml + sed -i -e "s/LOY/1/g" input.nml + sed -i -e "s/NPX/$NPX/g" input.nml + sed -i -e "s/NPY/$NPY/g" input.nml + sed -i -e "s/RES/$RES/g" input.nml + sed -i -e "s/CA_SGS/${DO_CA_SGS}/g" input.nml + sed -i -e "s/CA_GLOBAL/${DO_CA_GLOBAL}/g" input.nml + sed -i -e "s/WARM_START/.true./g" input.nml + time srun --label -n 6 $EXEC >& stdout.1x1_restart2 + mkdir ca_layout_1x1_restart2 + mv ca_out* ca_layout_1x1_restart2 + ct=1 + while [ $ct -le 6 ];do + diff RESTART/ca_data.tile${ct}.nc RESTART/run1_end_ca_data.tile${ct}.nc + if [ $? -ne 0 ];then + echo "restart test failed" + exit 1 + fi + ct=`expr $ct + 1` + done + if [ $? -eq 0 ];then + echo "unit test 1 successful" + fi + set OMP_NUM_THREADS=2 cp input.nml.ca_template input.nml sed -i -e "s/LOX/1/g" input.nml sed -i -e "s/LOY/4/g" input.nml diff --git a/unit_tests/standalone_ca.F90 b/unit_tests/standalone_ca.F90 index 498a558a..5f560638 100644 --- a/unit_tests/standalone_ca.F90 +++ b/unit_tests/standalone_ca.F90 @@ -38,8 +38,8 @@ program standalone_ca_global type(grid_box_type) :: grid_box !---cellular automata control parameters integer :: nca !< number of independent cellular automata -integer :: tlives !< cellular automata lifetime -integer :: scells !< cellular automata finer grid +integer :: nlives !< cellular automata lifetime +integer :: ncells !< cellular automata finer grid integer :: nca_g !< number of independent cellular automata integer :: nlives_g !< cellular automata lifetime integer :: ncells_g !< cellular automata finer grid @@ -65,7 +65,7 @@ program standalone_ca_global real(kind=kind_phys), dimension(:,:), allocatable :: ca1, ca2, ca3 -NAMELIST /gfs_physics_nml/ do_ca, ca_sgs, ca_global, nca, scells, tlives, nseed, & +NAMELIST /gfs_physics_nml/ do_ca, ca_sgs, ca_global, nca, ncells, nlives, nseed, & nfracseed, rcell, ca_trigger, ca_entr, ca_closure, nca_g, & ncells_g, nlives_g, nseed_g, ca_smooth, nspinup, iseed_ca, & nsmooth, ca_amplitude, warm_start @@ -316,7 +316,7 @@ program standalone_ca_global dump_time=50 if (warm_start) then istart=dump_time+1 - call read_ca_restart(Atm(1)%domain,scells,nca,ncells_g,nca_g) + call read_ca_restart(Atm(1)%domain,ncells,nca,ncells_g,nca_g) else istart=1 endif @@ -328,7 +328,7 @@ program standalone_ca_global sst,lmsk,lake,condition,ca_deep,ca_turb,ca_shal, & Atm(1)%domain_for_coupler,nblks, & isc,iec,jsc,jec,Atm(1)%npx,Atm(1)%npy, levs, & - nthresh,rcell,Atm(1)%tile_of_mosaic,nca,scells,tlives,nfracseed, & ! for new random number + nthresh,Atm(1)%tile_of_mosaic,nca,ncells,nlives,nfracseed, & ! for new random number nseed,iseed_ca ,nspinup,ca_trigger,blksz,root_pe,comm) endif if (ca_global) then diff --git a/update_ca.F90 b/update_ca.F90 index 8ad01fde..485a89b8 100644 --- a/update_ca.F90 +++ b/update_ca.F90 @@ -34,6 +34,7 @@ module update_ca integer,public :: iscnx_g,iecnx_g,jscnx_g,jecnx_g integer*8, public :: csum type(domain2D),public :: domain_sgs,domain_global +logical, public :: cold_start_ca_sgs=.true.,cold_start_ca_global=.true. contains @@ -233,8 +234,10 @@ subroutine read_ca_restart(domain_in,ncells,nca,ncells_g,nca_g) call mpp_error(NOTE,'reading CA_sgs restart data from INPUT/ca_data.tile*.nc') call read_restart(CA_restart) call close_file(CA_restart) + cold_start_ca_sgs=.false. else call mpp_error(NOTE,'No CA_sgs restarts - cold starting CA') + cold_start_ca_sgs=.true. endif endif @@ -262,9 +265,11 @@ subroutine read_ca_restart(domain_in,ncells,nca,ncells_g,nca_g) call mpp_error(NOTE,'reading CA_global restart data from INPUT/ca_data.tile*.nc') call read_restart(CA_restart) call close_file(CA_restart) + cold_start_ca_global=.false. else call mpp_error(NOTE,'No CA_global restarts - cold starting CA') + cold_start_ca_global=.true. endif endif @@ -320,9 +325,11 @@ subroutine update_cells_sgs(kstep,initialize_ca,iseed_ca,first_flag,restart,firs if (.not. allocated(board))then allocate(board(nxc,nyc,nca)) + board=0.0 endif if (.not. allocated(lives))then allocate(lives(nxc,nyc,nca)) + lives=0.0 endif if(.not. allocated(board_halo))then allocate(board_halo(nxch,nych,1)) @@ -602,7 +609,7 @@ subroutine update_cells_global(kstep,first_time_step,iseed_ca,restart,nca,nxc,ny if (.not. allocated(lives_g)) allocate(lives_g(nxc,nyc,nca)) if (.not. allocated(board_halo)) allocate(board_halo(nxch,nych,1)) - if(first_time_step .and. .not. restart)then + if(first_time_step .and. cold_start_ca_global)then do j=1,nyc do i=1,nxc board_g(i,j,nf) = iini_g(i,j,nf) @@ -643,7 +650,7 @@ subroutine update_cells_global(kstep,first_time_step,iseed_ca,restart,nca,nxc,ny enddo endif - if(first_time_step .and. .not. restart)then + if(first_time_step .and. cold_start_ca_global)then spinup=nspinup else spinup = 1