Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use FMS 2023.04 #1043

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ find_package( vader 1.7.0 REQUIRED)
find_package( saber 1.10.0 REQUIRED)
find_package( ioda 2.9.0 REQUIRED)
find_package( ufo 1.10.0 REQUIRED)
find_package( fms 2020.4.0 REQUIRED) # NOTE: remove this when we update to latest MOM6
find_package( mom6 2020.4.0 REQUIRED) # NOTE: remove this when we update to latest MOM6
find_package( fms 2023.3.0 REQUIRED COMPONENTS R4 R8)
add_library( fms ALIAS FMS::fms_r8)
find_package( OpenMP COMPONENTS C Fortran REQUIRED)

# Optionally look for Torch and daml
find_package(Torch QUIET)
Expand All @@ -47,10 +48,7 @@ include_directories( ${NETCDF_INCLUDE_DIRS} )
# Model
# TODO update to allow switching between mom6solo (here) and UFS (external)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self, or anyone else that cares, this is fine for now but I'm assuming we're building MOM6 twice when soca is built as part of the ufs-bundle. No real harm, but wasteful. At some point special logic should be added to use a prebuilt mom6 lib if it exists.

################################################################################
# # NOTE enable these when we're ready to update to latest MOM6
# find_package( fms 2023.3.0 REQUIRED COMPONENTS R4 R8)
# add_library( fms ALIAS FMS::fms_r8)
# add_subdirectory(mom6)
add_subdirectory(mom6)

################################################################################
# Sources
Expand Down
1 change: 0 additions & 1 deletion bundle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ecbuild_bundle( PROJECT vader GIT "https://github.com/jcsda-internal/v
ecbuild_bundle( PROJECT saber GIT "https://github.com/jcsda-internal/saber.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT ioda GIT "https://github.com/jcsda-internal/ioda.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT ufo GIT "https://github.com/jcsda-internal/ufo.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT mom6 GIT "https://github.com/jcsda-internal/MOM6.git" UPDATE BRANCH main-ecbuild RECURSIVE )
ecbuild_bundle( PROJECT soca SOURCE "../" )

#===================================================================================================
Expand Down
7 changes: 5 additions & 2 deletions mom6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ target_include_directories(mom6 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/MOM6/config_src/memory/dynamic_nonsymmetric>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/MOM6/src/framework>)
# TODO use symmetric memory above if doing regional MOM6
target_link_libraries(mom6 PUBLIC NetCDF::NetCDF_C NetCDF::NetCDF_Fortran fms )
# Note that the explicit dependency on OpenMP is only because FMS is not declaring its OpenMP dependency correctly
# This will be fixed with fms version 2024.01
target_link_libraries(mom6 PUBLIC NetCDF::NetCDF_C NetCDF::NetCDF_Fortran fms OpenMP::OpenMP_Fortran OpenMP::OpenMP_C)

####################################################
### Create standalone MOM6 executable
Expand Down Expand Up @@ -71,4 +73,5 @@ install (
COMPONENT Library)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod DESTINATION ${CMAKE_INSTALL_PREFIX}/MOM6)
install(EXPORT mom6-config
DESTINATION lib/cmake)
DESTINATION lib/cmake)

2 changes: 2 additions & 0 deletions src/soca/Geometry/Geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,6 @@ namespace soca {
}
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------

} // namespace soca
4 changes: 1 addition & 3 deletions src/soca/Geometry/soca_geom_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ subroutine soca_geom_init(self, f_conf, f_comm, gen)
type(time_type) :: Start_time
type(ocean_grid_type), pointer :: grid !< Grid metrics
type(MOM_control_struct) :: CSp
type(MOM_restart_CS), pointer :: restart_CSp !< NOTE remove this when updating MOM6

! variables needed for reading gridspec file
integer :: r
Expand Down Expand Up @@ -205,8 +204,7 @@ subroutine soca_geom_init(self, f_conf, f_comm, gen)
call io_infra_init()
call set_calendar_type(JULIAN)
call time_interp_external_init
restart_CSp => NULL()
call initialize_MOM( Start_time, Start_time, param_file, dirs, CSp, restart_CSp )
call initialize_MOM( Start_time, Start_time, param_file, dirs, CSp )
call get_MOM_state_elements(CSp, G=grid)

! grab the grid properties that we need
Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ function(soca_add_test)
DEPENDS ${ARG_EXE}
TEST_DEPENDS ${ARG_TEST_DEPENDS})
elseif ( ARG_SCRIPT )
# running a test specific script, right now this is only for the mom6.x forecast
# running a test specific script, right now this is only for the mom6solo forecast
ecbuild_add_test( TARGET test_soca_${ARG_NAME}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SCRIPT}
WORKING_DIRECTORY ${WORKDIR}
ARGS ${CONFIG_FILE}
DEPENDS mom6.x
DEPENDS mom6solo
ENVIRONMENT "BIN_DIR=${CMAKE_BINARY_DIR}/bin"
"MPIEXE=${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPI}"
TEST_DEPENDS ${ARG_TEST_DEPENDS}
Expand Down
20 changes: 9 additions & 11 deletions test/mom6solo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import pandas as pd
from datetime import datetime, timedelta

# TODO put this back when updating MOM6
MOM6EXE = 'mom6.x'
#MOM6EXE = 'mom6solo'
MOM6EXE = 'mom6solo'

# get input parameters
binDir = os.environ['BIN_DIR']
Expand Down Expand Up @@ -44,7 +42,7 @@ def replace_config_content(content, replacements):
for key, value in changes.items():
def replacement_function(match):
start, end = match.group(1), match.group(3)
return f"{start}{value}{end}"
return f"{start}{value}{end}"
key_pattern = rf"(\b{key}\s*=\s*)([^,\n]*)(,|/|\n)"
section_content = re.sub(key_pattern, replacement_function, section_content, flags=re.MULTILINE)
# Replace the old section content with the new one
Expand Down Expand Up @@ -73,10 +71,10 @@ def replacement_function(match):
# link input restart files
#----------------------------------------------------------------------------------------
if os.path.exists ('RESTART'):
shutil.rmtree('RESTART')
shutil.rmtree('RESTART')
os.makedirs('RESTART')
if os.path.exists ('RESTART_IN'):
shutil.rmtree('RESTART_IN')
shutil.rmtree('RESTART_IN')
os.makedirs('RESTART_IN')
os.symlink("../"+config['initial condition']['ocn_filename'], 'RESTART_IN/MOM.res.nc')

Expand All @@ -89,7 +87,7 @@ def replacement_function(match):
file.write(" 4 (Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)\n")
file.write(f" {init_date.year:4d} {init_date.month:2d} {init_date.day:2d} {init_date.hour:2d} {init_date.minute:2d} {init_date.second:2d} Model start time: year, month, day, hour, minute, second\n")
file.write(f" {init_date.year:4d} {init_date.month:2d} {init_date.day:2d} {init_date.hour:2d} {init_date.minute:2d} {init_date.second:2d} Current model time: year, month, day, hour, minute, second\n")


#----------------------------------------------------------------------------------------
# run executable
Expand All @@ -111,15 +109,15 @@ def replacement_function(match):
#----------------------------------------------------------------------------------------
for fcstHr in range(restartFrequency, fcst_len+1, restartFrequency):
rstDate = init_date + timedelta(hours=fcstHr)

# get rstDate in format such as MOM.res_Y2018_D105_S03600.nc
rst_day = rstDate.timetuple().tm_yday
rst_day = rstDate.timetuple().tm_yday
rst_seconds = rstDate.hour * 3600
rst_src = f"MOM.res_Y{rstDate.year}_D{rst_day:03}_S{rst_seconds:05}.nc"

# get init_date / fcstHr in a format such as ocn.forecast_mom6.fc.2018-04-15T00:00:00Z.PT1H.nc
forecast_date = init_date + timedelta(hours=fcstHr)
forecast_date_str = init_date.strftime("%Y-%m-%dT%H:%M:%SZ")
rst_dst = f"ocn.{config['output']['exp']}.fc.{forecast_date_str}.PT{fcstHr}H.nc"

shutil.move('RESTART/'+rst_src, config['output']['datadir']+'/'+rst_dst)