Skip to content

Commit 0abf9c2

Browse files
committed
Merge branch 'Hallberg-NOAA-restart_lock' into dev/gfdl
2 parents 9267708 + 321ced4 commit 0abf9c2

File tree

5 files changed

+191
-68
lines changed

5 files changed

+191
-68
lines changed

src/core/MOM.F90

+34-30
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module MOM
4141
use MOM_io, only : slasher, file_exists, MOM_read_data
4242
use MOM_obsolete_params, only : find_obsolete_params
4343
use MOM_restart, only : register_restart_field, register_restart_pair
44-
use MOM_restart, only : query_initialized, save_restart
44+
use MOM_restart, only : query_initialized, save_restart, restart_registry_lock
4545
use MOM_restart, only : restart_init, is_new_run, determine_is_new_run, MOM_restart_CS
4646
use MOM_spatial_means, only : global_mass_integral
4747
use MOM_time_manager, only : time_type, real_to_time, time_type_to_real, operator(+)
@@ -2145,8 +2145,7 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
21452145
if (associated(OBC_in)) then
21462146
! TODO: General OBC index rotations is not yet supported.
21472147
if (modulo(turns, 4) /= 1) &
2148-
call MOM_error(FATAL, "OBC index rotation of 180 and 270 degrees is " &
2149-
// "not yet unsupported.")
2148+
call MOM_error(FATAL, "OBC index rotation of 180 and 270 degrees is not yet supported.")
21502149
allocate(CS%OBC)
21512150
call rotate_OBC_config(OBC_in, dG_in, CS%OBC, dG, turns)
21522151
endif
@@ -2167,8 +2166,6 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
21672166

21682167
call MOM_timing_init(CS)
21692168

2170-
if (associated(CS%OBC)) call call_OBC_register(param_file, CS%update_OBC_CSp, US, CS%OBC)
2171-
21722169
call tracer_registry_init(param_file, CS%tracer_Reg)
21732170

21742171
! Allocate and initialize space for the primary time-varying MOM variables.
@@ -2222,21 +2219,8 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
22222219
flux_scale=conv2salt, convergence_units='kg m-2 s-1', &
22232220
convergence_scale=0.001*GV%H_to_kg_m2, CMOR_tendprefix="osalt", diag_form=2)
22242221
endif
2225-
! NOTE: register_temp_salt_segments includes allocation of tracer fields
2226-
! along segments. Bit reproducibility requires that MOM_initialize_state
2227-
! be called on the input index map, so we must setup both OBC and OBC_in.
2228-
!
2229-
! XXX: This call on OBC_in allocates the tracer fields on the unrotated
2230-
! grid, but also incorrectly stores a pointer to a tracer_type for the
2231-
! rotated registry (e.g. segment%tr_reg%Tr(n)%Tr) from CS%tracer_reg.
2232-
!
2233-
! While incorrect and potentially dangerous, it does not seem that this
2234-
! pointer is used during initialization, so we leave it for now.
2235-
if (CS%rotate_index .and. associated(OBC_in)) &
2236-
call register_temp_salt_segments(GV, OBC_in, CS%tracer_Reg, param_file)
2237-
if (associated(CS%OBC)) &
2238-
call register_temp_salt_segments(GV, CS%OBC, CS%tracer_Reg, param_file)
22392222
endif
2223+
22402224
if (use_frazil) then
22412225
allocate(CS%tv%frazil(isd:ied,jsd:jed)) ; CS%tv%frazil(:,:) = 0.0
22422226
endif
@@ -2329,11 +2313,38 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
23292313
call mixedlayer_restrat_register_restarts(dG%HI, param_file, &
23302314
CS%mixedlayer_restrat_CSp, restart_CSp)
23312315

2332-
if (associated(CS%OBC)) &
2316+
if (CS%rotate_index .and. associated(OBC_in) .and. use_temperature) then
2317+
! NOTE: register_temp_salt_segments includes allocation of tracer fields
2318+
! along segments. Bit reproducibility requires that MOM_initialize_state
2319+
! be called on the input index map, so we must setup both OBC and OBC_in.
2320+
!
2321+
! XXX: This call on OBC_in allocates the tracer fields on the unrotated
2322+
! grid, but also incorrectly stores a pointer to a tracer_type for the
2323+
! rotated registry (e.g. segment%tr_reg%Tr(n)%Tr) from CS%tracer_reg.
2324+
!
2325+
! While incorrect and potentially dangerous, it does not seem that this
2326+
! pointer is used during initialization, so we leave it for now.
2327+
call register_temp_salt_segments(GV, OBC_in, CS%tracer_Reg, param_file)
2328+
endif
2329+
2330+
if (associated(CS%OBC)) then
2331+
! Set up remaining information about open boundary conditions that is needed for OBCs.
2332+
call call_OBC_register(param_file, CS%update_OBC_CSp, US, CS%OBC, CS%tracer_Reg)
2333+
!### Package specific changes to OBCs need to go here?
2334+
2335+
! This is the equivalent to 2 calls to register_segment_tracer (per segment), which
2336+
! could occur with the call to update_OBC_data or after the main initialization.
2337+
if (use_temperature) &
2338+
call register_temp_salt_segments(GV, CS%OBC, CS%tracer_Reg, param_file)
2339+
2340+
! This needs the number of tracers and to have called any code that sets whether
2341+
! reservoirs are used.
23332342
call open_boundary_register_restarts(dg%HI, GV, CS%OBC, CS%tracer_Reg, &
23342343
param_file, restart_CSp, use_temperature)
2344+
endif
23352345

23362346
call callTree_waypoint("restart registration complete (initialize_MOM)")
2347+
call restart_registry_lock(restart_CSp)
23372348

23382349
! Shift from using the temporary dynamic grid type to using the final
23392350
! (potentially static) ocean-specific grid type.
@@ -2431,7 +2442,7 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
24312442
turns, CS%u, CS%v, CS%h, CS%T, CS%S)
24322443

24332444
if (associated(sponge_in_CSp)) then
2434-
! TODO: Implementation and testing of non-ALE spong rotation
2445+
! TODO: Implementation and testing of non-ALE sponge rotation
24352446
call MOM_error(FATAL, "Index rotation of non-ALE sponge is not yet implemented.")
24362447
endif
24372448

@@ -2471,19 +2482,11 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
24712482
endif
24722483

24732484
if (use_ice_shelf .and. CS%debug) &
2474-
call hchksum(CS%frac_shelf_h, "MOM:frac_shelf_h", G%HI, &
2475-
haloshift=0)
2485+
call hchksum(CS%frac_shelf_h, "MOM:frac_shelf_h", G%HI, haloshift=0)
24762486

24772487
call cpu_clock_end(id_clock_MOM_init)
24782488
call callTree_waypoint("returned from MOM_initialize_state() (initialize_MOM)")
24792489

2480-
! ! Need this after MOM_initialize_state for DOME OBC stuff.
2481-
! if (associated(CS%OBC)) &
2482-
! call open_boundary_register_restarts(G%HI, GV, CS%OBC, CS%tracer_Reg, &
2483-
! param_file, restart_CSp, use_temperature)
2484-
2485-
! call callTree_waypoint("restart registration complete (initialize_MOM)")
2486-
24872490
! From this point, there may be pointers being set, so the final grid type
24882491
! that will persist throughout the run has to be used.
24892492

@@ -2838,6 +2841,7 @@ subroutine finish_MOM_initialization(Time, dirs, CS, restart_CSp)
28382841
if (CS%write_IC) then
28392842
allocate(restart_CSp_tmp)
28402843
restart_CSp_tmp = restart_CSp
2844+
call restart_registry_lock(restart_CSp_tmp, unlocked=.true.)
28412845
allocate(z_interface(SZI_(G),SZJ_(G),SZK_(GV)+1))
28422846
call find_eta(CS%h, CS%tv, G, GV, US, z_interface, eta_to_m=1.0)
28432847
call register_restart_field(z_interface, "eta", .true., restart_CSp_tmp, &

src/core/MOM_boundary_update.F90

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module MOM_boundary_update
1717
use MOM_tracer_registry, only : tracer_registry_type
1818
use MOM_variables, only : thermo_var_ptrs
1919
use MOM_verticalGrid, only : verticalGrid_type
20+
use DOME_initialization, only : register_DOME_OBC
2021
use tidal_bay_initialization, only : tidal_bay_set_OBC_data, register_tidal_bay_OBC
2122
use tidal_bay_initialization, only : tidal_bay_OBC_end, tidal_bay_OBC_CS
2223
use Kelvin_initialization, only : Kelvin_set_OBC_data, register_Kelvin_OBC
@@ -58,13 +59,15 @@ module MOM_boundary_update
5859
!> The following subroutines and associated definitions provide the
5960
!! machinery to register and call the subroutines that initialize
6061
!! open boundary conditions.
61-
subroutine call_OBC_register(param_file, CS, US, OBC)
62+
subroutine call_OBC_register(param_file, CS, US, OBC, tr_Reg)
6263
type(param_file_type), intent(in) :: param_file !< Parameter file to parse
6364
type(update_OBC_CS), pointer :: CS !< Control structure for OBCs
6465
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
6566
type(ocean_OBC_type), pointer :: OBC !< Open boundary structure
67+
type(tracer_registry_type), pointer :: tr_Reg !< Tracer registry.
6668

6769
! Local variables
70+
character(len=200) :: config
6871
character(len=40) :: mdl = "MOM_boundary_update" ! This module's name.
6972
! This include declares and sets the variable "version".
7073
# include "version_variable.h"
@@ -91,10 +94,29 @@ subroutine call_OBC_register(param_file, CS, US, OBC)
9194
call get_param(param_file, mdl, "USE_DYED_CHANNEL_OBC", CS%use_dyed_channel, &
9295
"If true, use the dyed channel open boundary.", &
9396
default=.false.)
97+
call get_param(param_file, mdl, "OBC_USER_CONFIG", config, &
98+
"A string that sets how the user code is invoked to set open boundary data: \n"//&
99+
" DOME - specified inflow on northern boundary\n"//&
100+
" dyed_channel - supercritical with dye on the inflow boundary\n"//&
101+
" dyed_obcs - circle_obcs with dyes on the open boundaries\n"//&
102+
" Kelvin - barotropic Kelvin wave forcing on the western boundary\n"//&
103+
" shelfwave - Flather with shelf wave forcing on western boundary\n"//&
104+
" supercritical - now only needed here for the allocations\n"//&
105+
" tidal_bay - Flather with tidal forcing on eastern boundary\n"//&
106+
" USER - user specified", default="none", do_not_log=.true.)
94107

95108
if (CS%use_files) CS%use_files = &
96109
register_file_OBC(param_file, CS%file_OBC_CSp, US, &
97110
OBC%OBC_Reg)
111+
112+
if (trim(config) == "DOME") then
113+
call register_DOME_OBC(param_file, US, OBC, tr_Reg)
114+
! elseif (trim(config) == "tidal_bay") then
115+
! elseif (trim(config) == "Kelvin") then
116+
! elseif (trim(config) == "shelfwave") then
117+
! elseif (trim(config) == "dyed_channel") then
118+
endif
119+
98120
if (CS%use_tidal_bay) CS%use_tidal_bay = &
99121
register_tidal_bay_OBC(param_file, CS%tidal_bay_OBC_CSp, US, &
100122
OBC%OBC_Reg)
@@ -150,7 +172,7 @@ end subroutine OBC_register_end
150172

151173
!> \namespace mom_boundary_update
152174
!! This module updates the open boundary arrays when time-varying.
153-
!! It caused a circular dependency with the tidal_bay setup when
175+
!! It caused a circular dependency with the tidal_bay and other setups when in
154176
!! MOM_open_boundary.
155177
!!
156178
!! A small fragment of the grid is shown below:

src/core/MOM_open_boundary.F90

+15-11
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ module MOM_open_boundary
342342
integer :: id_clock_pass !< A CPU time clock
343343

344344
character(len=40) :: mdl = "MOM_open_boundary" !< This module's name.
345-
! This include declares and sets the variable "version".
346-
#include "version_variable.h"
347345

348346
contains
349347

@@ -359,6 +357,7 @@ subroutine open_boundary_config(G, US, param_file, OBC)
359357
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
360358
type(param_file_type), intent(in) :: param_file !< Parameter file handle
361359
type(ocean_OBC_type), pointer :: OBC !< Open boundary control structure
360+
362361
! Local variables
363362
integer :: l ! For looping over segments
364363
logical :: debug_OBC, debug, mask_outside, reentrant_x, reentrant_y
@@ -370,6 +369,9 @@ subroutine open_boundary_config(G, US, param_file, OBC)
370369
logical :: answers_2018, default_2018_answers
371370
logical :: check_reconstruction, check_remapping, force_bounds_in_subcell
372371
character(len=32) :: remappingScheme
372+
! This include declares and sets the variable "version".
373+
# include "version_variable.h"
374+
373375
allocate(OBC)
374376

375377
call get_param(param_file, mdl, "OBC_NUMBER_OF_SEGMENTS", OBC%number_of_segments, &
@@ -4433,8 +4435,8 @@ subroutine register_OBC(name, param_file, Reg)
44334435
Reg%OB(nobc)%name = name
44344436

44354437
if (Reg%locked) call MOM_error(FATAL, &
4436-
"MOM register_tracer was called for variable "//trim(Reg%OB(nobc)%name)//&
4437-
" with a locked tracer registry.")
4438+
"MOM register_OBC was called for OBC "//trim(Reg%OB(nobc)%name)//&
4439+
" with a locked OBC registry.")
44384440

44394441
end subroutine register_OBC
44404442

@@ -4445,15 +4447,15 @@ subroutine OBC_registry_init(param_file, Reg)
44454447

44464448
integer, save :: init_calls = 0
44474449

4448-
#include "version_variable.h"
4450+
# include "version_variable.h"
44494451
character(len=40) :: mdl = "MOM_open_boundary" ! This module's name.
44504452
character(len=256) :: mesg ! Message for error messages.
44514453

44524454
if (.not.associated(Reg)) then ; allocate(Reg)
44534455
else ; return ; endif
44544456

44554457
! Read all relevant parameters and write them to the model log.
4456-
! call log_version(param_file, mdl,s version, "")
4458+
! call log_version(param_file, mdl, version, "")
44574459

44584460
init_calls = init_calls + 1
44594461
if (init_calls > 1) then
@@ -4503,7 +4505,7 @@ subroutine segment_tracer_registry_init(param_file, segment)
45034505
integer, save :: init_calls = 0
45044506

45054507
! This include declares and sets the variable "version".
4506-
#include "version_variable.h"
4508+
# include "version_variable.h"
45074509
character(len=40) :: mdl = "segment_tracer_registry_init" ! This routine's name.
45084510
character(len=256) :: mesg ! Message for error messages.
45094511

@@ -4527,6 +4529,8 @@ subroutine segment_tracer_registry_init(param_file, segment)
45274529

45284530
end subroutine segment_tracer_registry_init
45294531

4532+
!> Register a tracer array that is active on an OBC segment, potentially also specifing how the
4533+
!! tracer inflow values are specified.
45304534
subroutine register_segment_tracer(tr_ptr, param_file, GV, segment, &
45314535
OBC_scalar, OBC_array)
45324536
type(verticalGrid_type), intent(in) :: GV !< ocean vertical grid structure
@@ -4537,7 +4541,7 @@ subroutine register_segment_tracer(tr_ptr, param_file, GV, segment, &
45374541
!! but it also means that any updates to this
45384542
!! structure in the calling module will be
45394543
!! available subsequently to the tracer registry.
4540-
type(param_file_type), intent(in) :: param_file !< file to parse for model parameter values
4544+
type(param_file_type), intent(in) :: param_file !< file to parse for model parameter values
45414545
type(OBC_segment_type), intent(inout) :: segment !< current segment data structure
45424546
real, optional, intent(in) :: OBC_scalar !< If present, use scalar value for segment tracer
45434547
!! inflow concentration.
@@ -4555,8 +4559,8 @@ subroutine register_segment_tracer(tr_ptr, param_file, GV, segment, &
45554559

45564560
if (segment%tr_Reg%ntseg>=MAX_FIELDS_) then
45574561
write(mesg,'("Increase MAX_FIELDS_ in MOM_memory.h to at least ",I3," to allow for &
4558-
&all the tracers being registered via register_tracer.")') segment%tr_Reg%ntseg+1
4559-
call MOM_error(FATAL,"MOM register_tracer: "//mesg)
4562+
&all the tracers being registered via register_segment_tracer.")') segment%tr_Reg%ntseg+1
4563+
call MOM_error(FATAL,"MOM register_segment_tracer: "//mesg)
45604564
endif
45614565
segment%tr_Reg%ntseg = segment%tr_Reg%ntseg + 1
45624566
ntseg = segment%tr_Reg%ntseg
@@ -4570,7 +4574,7 @@ subroutine register_segment_tracer(tr_ptr, param_file, GV, segment, &
45704574
segment%tr_Reg%Tr(ntseg)%name = tr_ptr%name
45714575

45724576
if (segment%tr_Reg%locked) call MOM_error(FATAL, &
4573-
"MOM register_tracer was called for variable "//trim(segment%tr_Reg%Tr(ntseg)%name)//&
4577+
"MOM register_segment_tracer was called for variable "//trim(segment%tr_Reg%Tr(ntseg)%name)//&
45744578
" with a locked tracer registry.")
45754579

45764580
if (present(OBC_scalar)) segment%tr_Reg%Tr(ntseg)%OBC_inflow_conc = OBC_scalar ! initialize tracer value later

0 commit comments

Comments
 (0)