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

Implement namelist reading and early initialization of MPAS dynamical core #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d985991
Add XML namelist definition file for MPAS dynamical core
gdicker1 Jan 22, 2024
3b42c4f
Wire up XML namelist definition file in CAM config
kuanchihwang Jan 22, 2024
ef48506
Manually backport necessary subroutines to time manager for MPAS
kuanchihwang Feb 13, 2024
a217fdf
Start implementing MPAS subdriver
kuanchihwang Feb 13, 2024
3b27365
Implement `dyn_readnl`
kuanchihwang Feb 13, 2024
f9c6a1b
Build MPAS subdriver with upstream
kuanchihwang Feb 14, 2024
c348ea5
Build MPAS subdriver with upstream
kuanchihwang Feb 14, 2024
9494b82
Fix wrong prefix in XML namelist definition file
kuanchihwang Feb 15, 2024
363d782
Adjust indentation level
kuanchihwang Feb 15, 2024
5b90e51
Reword a comment
kuanchihwang Feb 21, 2024
7b4633b
Whitespace around construct
kuanchihwang Feb 21, 2024
5ef859f
Adjust indentation level
kuanchihwang Feb 21, 2024
ce9bc5f
Disable debug prints in release builds
kuanchihwang Feb 21, 2024
3eaeeb8
Default to MPI master rank for debug prints
kuanchihwang Feb 21, 2024
c4fda96
Move instantiation of MPAS dynamical core to `dyn_comp` module
kuanchihwang Feb 22, 2024
361d187
Use `DEBUG` macro instead
kuanchihwang Feb 27, 2024
8669b0e
Prefix `mpas_` to MPAS namelist groups to avoid naming collisions
kuanchihwang Feb 27, 2024
c58059b
Prefix `mpas_` to MPAS namelist groups to avoid naming collisions
kuanchihwang Feb 27, 2024
0e62d59
Change wording
kuanchihwang Feb 27, 2024
4a34799
Add more comments for `stringify` pure function
kuanchihwang Feb 27, 2024
c8e09ca
Add `stringify` pure function to `string_utils` module
kuanchihwang Feb 27, 2024
176e00b
Make debug output run-time configurable
kuanchihwang Feb 27, 2024
6e5d6ab
Add more comments for `dyn_readnl` subroutine
kuanchihwang Feb 28, 2024
4c0f612
Add more comments for XML namelist definition file
kuanchihwang Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ def _setup_mpas(case: Case) -> None:

shutil.copytree(mpas_dycore_src_root, mpas_dycore_bld_root, copy_function=_copy2_as_needed, dirs_exist_ok=True)
shutil.move(os.path.join(mpas_dycore_bld_root, "Makefile"), os.path.join(mpas_dycore_bld_root, "Makefile.CESM"))
_copy2_as_needed(os.path.normpath(os.path.join(mpas_dycore_src_root, os.pardir, os.pardir, "Makefile")), os.path.join(mpas_dycore_bld_root, "Makefile"))
_copy2_as_needed(os.path.normpath(os.path.join(mpas_dycore_src_root, os.pardir, os.pardir, "Makefile.in.CESM")), os.path.join(mpas_dycore_bld_root, "Makefile.in.CESM"))
_copy2_as_needed(os.path.normpath(os.path.join(mpas_dycore_src_root, os.pardir, os.pardir, "driver", "dyn_mpas_subdriver.F90")), os.path.join(mpas_dycore_bld_root, "driver"))
_copy2_as_needed(os.path.normpath(os.path.join(mpas_dycore_src_root, os.pardir, os.pardir, "Makefile")), mpas_dycore_bld_root)
_copy2_as_needed(os.path.normpath(os.path.join(mpas_dycore_src_root, os.pardir, os.pardir, "Makefile.in.CESM")), mpas_dycore_bld_root)

def _copy2_as_needed(src: str, dst: str) -> None:
"""
Expand All @@ -199,6 +200,9 @@ def _copy2_as_needed(src: str, dst: str) -> None:
# `src` and `dst` are both files but their modification time or size differ.
# Example scenario: User modified some existing source code files.
shutil.copy2(src, dst)
elif os.path.isdir(dst) and os.path.isfile(os.path.join(dst, os.path.basename(src))):
dst = os.path.join(dst, os.path.basename(src))
_copy2_as_needed(src, dst)
else:
if os.path.isdir(dst) or os.path.isdir(os.path.dirname(dst)):
# `src` is a new file that does not exist at `dst`.
Expand Down
4 changes: 4 additions & 0 deletions cime_config/cam_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ def __init__(self, case, case_log):
# MPAS dynamical core relies on its upstream build infrastructure for compilation instead of CIME to take advantage of future upstream changes automatically.
self.create_config("dyn_src_dirs", dyn_dirs_desc, ["mpas"],
valid_list_type="str")

# Add XML namelist definition file for MPAS dynamical core.
mpas_dyn_nml_path = os.path.normpath(os.path.join(cime_conf_path, os.pardir, "src", "dynamics", "mpas"))
self._add_xml_nml_file(mpas_dyn_nml_path, "namelist_definition_mpas_dycore.xml")
elif dycore == "none":
# Source code directories
self.create_config("dyn_src_dirs", dyn_dirs_desc, ["none"],
Expand Down
34 changes: 25 additions & 9 deletions src/dynamics/mpas/Makefile.in.CESM
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif
#

export CP = cp -afv
export LN = ln -fsv
export MKDIR = mkdir -pv
export RM = rm -frv

Expand Down Expand Up @@ -61,22 +62,29 @@ all:
@echo ' `make libmpas-clean ESM="CESM" LIBROOT="..."`'

.PHONY: libmpas-prepare
libmpas-prepare: libmpas-archiver-script.txt libmpas-no-physics libmpas-preview
libmpas-prepare: libmpas-archiver-script.txt libmpas-no-physics libmpas-prefix-namelist-groups libmpas-preview

# Combine multiple static libraries into `libmpas.a` via archiver/MRI script. This requires GNU or GNU-like archiver (`ar`) program.
libmpas-archiver-script.txt:
@echo "create libmpas.a" > $(@)
@echo "addlib libdycore.a" >> $(@)
@echo "addlib libframework.a" >> $(@)
@echo "addlib libops.a" >> $(@)
@echo "save" >> $(@)
@echo "end" >> $(@)
@echo "create libmpas.a" > $(@)
@echo "addlib libdycore.a" >> $(@)
@echo "addlib libframework.a" >> $(@)
@echo "addlib libops.a" >> $(@)
@echo "addmod dyn_mpas_subdriver.o" >> $(@)
@echo "save" >> $(@)
@echo "end" >> $(@)

# Do not use built-in MPAS/WRF physics.
.PHONY: libmpas-no-physics
libmpas-no-physics:
@sed -E -i -e "s/^ *PHYSICS=.+$$/PHYSICS=/g" core_atmosphere/Makefile

# Prefix `mpas_` to MPAS namelist groups to avoid naming collisions.
.PHONY: libmpas-prefix-namelist-groups
libmpas-prefix-namelist-groups:
@sed -E -i -e "s/(^ *< *nml_record.+name=)\"(mpas_)?(\w+)\"/\1\"mpas_\3\"/g" core_atmosphere/Registry.xml
@sed -E -i -e "s/(^ *< *nml_record.+name=)\"(mpas_)?(\w+)\"/\1\"mpas_\3\"/g" core_atmosphere/diagnostics/Registry_*.xml

.PHONY: libmpas-preview
libmpas-preview:
@echo "Previewing build options for $(LIBROOT)/libmpas.a:"
Expand Down Expand Up @@ -106,13 +114,21 @@ $(LIBROOT)/libmpas.a: libmpas.a
$(MKDIR) $(LIBROOT)
$(CP) $(<) $(@)

libmpas.a: $(AUTOCLEAN_DEPS) dycore externals frame ops
libmpas.a: $(AUTOCLEAN_DEPS) dycore externals frame ops subdrv
$(AR) $(ARFLAGS) < libmpas-archiver-script.txt
@find -P . -name "*.mod" -type f -exec $(LN) "{}" . ";"

.PHONY: libmpas-clean
libmpas-clean: clean
$(RM) $(LIBROOT)/libmpas.a libmpas.a
$(RM) $(LIBROOT)/libmpas.a libmpas.a *.mod *.o

.PHONY: externals
externals: $(AUTOCLEAN_DEPS)
( cd external; $(MAKE) FC="$(FC)" SFC="$(SFC)" CC="$(CC)" SCC="$(SCC)" FFLAGS="$(FFLAGS)" CFLAGS="$(CFLAGS)" CPP="$(CPP)" NETCDF="$(NETCDF)" CORE="$(CORE)" ezxml-lib )

.PHONY: subdrv
subdrv: driver/dyn_mpas_subdriver.o

%.o: %.F90 dycore frame ops
( cd $(<D); $(FC) $(CPPFLAGS) $(FFLAGS) -c $(<F) $(CPPINCLUDES) $(FCINCLUDES) -I../framework -I../operators -I../core_$(CORE) )
$(LN) $(@) .
Loading
Loading