Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c287b24

Browse files
Add ensemble functionality (#259)
This commit adds some functionalities needed for running ensemble experiments with SIS2. The changes to SIS_get_input.F90 mean that the user can run a perturbed sea ice physics ensemble by passing unique SIS_override files to SIS_input_nml via: parameter_filename = 'INPUT/SIS_input','INPUT/SIS_layout','INPUT/SIS_override_%E' The changes to SIS_sum_output.F90 mean that a seaice.stats file will be created for each ensemble member, allowing the user to track conservation statistics for each member. The changes to SIS_fixed_initialization.F90 mean that a sea_ice_geometry file will not be created for each ensemble member, but only for the first one. This was needed because the simulation crashes during initialization when running a large (30-member) perturbed sea ice physics ensemble from a cold start (input_filename = 'n'). It seemed like all the ensemble members were trying to read/write the same sea_ice_geometry file. This has been fixed by only having the first ensemble member write its version of the sea_ice_geometry file.
1 parent 0372a89 commit c287b24

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

src/SIS_fixed_initialization.F90

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module SIS_fixed_initialization
1414
use MOM_error_handler, only : callTree_enter, callTree_leave, callTree_waypoint
1515
use MOM_file_parser, only : get_param, read_param, log_param, log_version, param_file_type
1616
use MOM_grid_initialize, only : initialize_masks, set_grid_metrics
17-
use MOM_io, only : slasher
17+
use MOM_io, only : slasher, get_filename_appendix
1818
! use MOM_shared_initialization, only : MOM_shared_init_init
1919
use MOM_shared_initialization, only : MOM_initialize_rotation, MOM_calculate_grad_Coriolis
2020
use MOM_shared_initialization, only : initialize_topography_from_file, apply_topography_edits_from_file
@@ -48,6 +48,7 @@ subroutine SIS_initialize_fixed(G, US, PF, write_geom, output_dir, OBC)
4848
character(len=200) :: inputdir ! The directory where NetCDF input files are.
4949
character(len=200) :: config
5050
character(len=40) :: mdl = "SIS_initialize_fixed" ! This module's name.
51+
character(len=32) :: filename_appendix = "" !fms appendix to filename for ensemble runs
5152
logical :: debug
5253
! This include declares and sets the variable "version".
5354
#include "version_variable.h"
@@ -126,8 +127,15 @@ subroutine SIS_initialize_fixed(G, US, PF, write_geom, output_dir, OBC)
126127
call initialize_grid_rotation_angle(G, PF)
127128

128129
! Write out all of the grid data used by this run.
129-
if (write_geom) call write_ocean_geometry_file(G, PF, output_dir, &
130-
geom_file="sea_ice_geometry", US=US)
130+
if (write_geom) then
131+
!query fms_io if there is a filename_appendix (for ensemble runs)
132+
call get_filename_appendix(filename_appendix)
133+
if ((len_trim(filename_appendix) == 0) .or. (filename_appendix == "ens_01")) then
134+
call write_ocean_geometry_file(G, PF, output_dir, &
135+
geom_file="sea_ice_geometry", US=US)
136+
endif
137+
138+
endif
131139

132140
call callTree_leave('SIS_initialize_fixed()')
133141

src/SIS_get_input.F90

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ module SIS_get_input
2929

3030
!> Get_SIS_input reads the SIS namelist entries to see if the run is to be started from
3131
!! a saved restart file, and get the names of the parameter files, I/O directories.
32-
subroutine Get_SIS_Input(param_file, dirs, check_params, component)
32+
subroutine Get_SIS_Input(param_file, dirs, check_params, component, ensemble_num)
3333
type(param_file_type), optional, intent(out) :: param_file !< A structure to parse for run-time parameters
3434
type(directories), optional, intent(out) :: dirs !< Container for paths and parameter file names.
3535
logical, optional, intent(in) :: check_params !< If present and False will stop error checking for
3636
!! run-time parameters.
3737
character(len=*), optional, intent(in) :: component !< An alternate component name, the default is "SIS"
3838

39+
integer, optional, intent(in) :: ensemble_num !< The ensemble id of the current member
40+
3941
! See if the run is to be started from saved conditions, and get !
4042
! the names of the I/O directories and initialization file. This !
4143
! subroutine also calls the subroutine that allows run-time changes !
@@ -67,20 +69,27 @@ subroutine Get_SIS_Input(param_file, dirs, check_params, component)
6769
enddo
6870
10 call close_file(unit)
6971
if (present(dirs)) then
70-
dirs%output_directory = trim(slasher(ensembler(output_directory)))
71-
dirs%restart_output_dir = trim(slasher(ensembler(restart_output_dir)))
72-
dirs%restart_input_dir = trim(slasher(ensembler(restart_input_dir)))
73-
dirs%input_filename = trim(ensembler(input_filename))
72+
if (present(ensemble_num)) then
73+
dirs%output_directory = trim(slasher(ensembler(output_directory,ensemble_num)))
74+
dirs%restart_output_dir = trim(slasher(ensembler(restart_output_dir,ensemble_num)))
75+
dirs%restart_input_dir = trim(slasher(ensembler(restart_input_dir,ensemble_num)))
76+
dirs%input_filename = trim(ensembler(input_filename,ensemble_num))
77+
else
78+
dirs%output_directory = trim(slasher(ensembler(output_directory)))
79+
dirs%restart_output_dir = trim(slasher(ensembler(restart_output_dir)))
80+
dirs%restart_input_dir = trim(slasher(ensembler(restart_input_dir)))
81+
dirs%input_filename = trim(ensembler(input_filename))
82+
endif
7483
endif
7584

7685
comp = "SIS" ; if (present(component)) comp = trim(adjustl(component))
7786

7887
if (present(param_file)) then
7988
output_dir = trim(slasher(ensembler(output_directory)))
8089
valid_param_files = 0
81-
do io = 1, npf
90+
do io = 1, npf
8291
if (len_trim(trim(parameter_filename(io))) > 0) then
83-
call open_param_file(trim(parameter_filename(io)), param_file, &
92+
call open_param_file(trim(ensembler(parameter_filename(io),ensemble_num)), param_file, &
8493
check_params, component=comp, &
8594
doc_file_dir=output_dir)
8695
valid_param_files = valid_param_files + 1
@@ -92,4 +101,4 @@ subroutine Get_SIS_Input(param_file, dirs, check_params, component)
92101

93102
end subroutine Get_SIS_Input
94103

95-
end module SIS_get_input
104+
end module SIS_get_input

src/SIS_sum_output.F90

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module SIS_sum_output
2020
use MOM_file_parser, only : get_param, log_param, log_version, param_file_type
2121
! use MOM_io, only : create_file, fieldtype, flush_file, reopen_file, vardesc, write_field
2222
use MOM_io, only : open_ASCII_file, APPEND_FILE, ASCII_FILE, SINGLE_FILE, WRITEONLY_FILE
23+
use MOM_io, only : get_filename_appendix
2324
use MOM_string_functions, only : slasher
2425
use MOM_time_manager, only : time_type, get_time, operator(>), operator(-)
2526
use MOM_time_manager, only : get_date, get_calendar_type, NO_CALENDAR
@@ -110,6 +111,8 @@ subroutine SIS_sum_output_init(G, param_file, directory, Input_start_time, US, C
110111
! Local variables
111112
character(len=40) :: mdl = "SIS_sum_output" ! This module's name.
112113
character(len=200) :: statsfile ! The name of the statistics file.
114+
character(len=32) :: filename_appendix = "" !fms appendix to filename for ensemble runs
115+
113116
! This include declares and sets the variable "version".
114117
# include "version_variable.h"
115118

@@ -146,8 +149,15 @@ subroutine SIS_sum_output_init(G, param_file, directory, Input_start_time, US, C
146149
"The file to use to write the globally integrated "//&
147150
"statistics.", default="seaice.stats")
148151

149-
CS%statsfile = trim(slasher(directory))//trim(statsfile)
152+
!query fms_io if there is a filename_appendix (for ensemble runs)
153+
call get_filename_appendix(filename_appendix)
154+
if (len_trim(filename_appendix) > 0) then
155+
CS%statsfile = trim(slasher(directory))//trim(statsfile)//'.'//trim(filename_appendix)
156+
else
157+
CS%statsfile = trim(slasher(directory))//trim(statsfile)
158+
endif
150159
call log_param(param_file, mdl, "output_path/STATISTICS_FILE", CS%statsfile)
160+
151161
#ifdef STATSLABEL
152162
CS%statsfile = trim(CS%statsfile)//"."//trim(adjustl(STATSLABEL))
153163
#endif

0 commit comments

Comments
 (0)