Skip to content

Commit

Permalink
Fix bug in mom6 driver introduced in payu-org#373 and added another t…
Browse files Browse the repository at this point in the history
…est for mom6 setup
  • Loading branch information
Jo Basevi committed Nov 8, 2023
1 parent bb84f66 commit f0cdbb2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
9 changes: 5 additions & 4 deletions payu/models/mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

# Standard library
import os
import shutil

# Extensions
import f90nml
Expand Down Expand Up @@ -67,12 +66,14 @@ def setup(self):
# FMS initialisation
super(Mom6, self).setup()

self.init_config()

# Add parameter files to config files and copy files over to work path
# Add parameter files to config files
mom6_add_parameter_files(self)

# Copy configuration files over to work path
self.setup_configuration_files()

self.init_config()

def init_config(self):
"""Patch input.nml as a new or restart run."""

Expand Down
58 changes: 52 additions & 6 deletions test/models/test_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@

from test.common import cd
from test.common import tmpdir, ctrldir, labdir, expt_workdir
from test.common import config as config_orig
from test.common import write_config
from test.common import make_random_file, make_inputs
from test.common import make_random_file, make_inputs, make_exe

verbose = True

# Global config
config = copy.deepcopy(config_orig)
config["model"] = "mom6"


def setup_module(module):
"""
Expand All @@ -42,7 +37,14 @@ def setup_module(module):
except Exception as e:
print(e)

config = {
'laboratory': 'lab',
'jobname': 'testrun',
'model': 'mom6',
'exe': 'test.exe'
}
write_config(config)
make_exe()


def teardown_module(module):
Expand Down Expand Up @@ -118,3 +120,47 @@ def test_mom6_add_parameter_files(input_nml,

# Tidy up input.nml
os.remove(input_nml_fp)


def test_setup():
input_nml = {
"MOM_input_nml": {
"input_filename": 'F',
"parameter_filename": ["MOM_input", "MOM_override"]
},
"SIS_input_nml": {
"parameter_filename": "SIS_input"
}
}

expected_files_added = {'input.nml', 'diag_table',
'MOM_input', 'MOM_override', 'SIS_input'}

# Create config files in control directory
for file in expected_files_added:
if file != 'input.nml':
filename = os.path.join(ctrldir, file)
make_random_file(filename, 8)

# Create config.nml
input_nml_fp = os.path.join(ctrldir, 'input.nml')
f90nml.write(input_nml, input_nml_fp)

with cd(ctrldir):
lab = payu.laboratory.Laboratory(lab_path=str(labdir))
expt = payu.experiment.Experiment(lab, reproduce=False)
model = expt.models[0]

# Function to test
model.setup()

# Check config files are moved to model's work path
work_path_files = os.listdir(model.work_path)
for file in expected_files_added:
assert file in work_path_files

# Check input.nml was patched as new run
work_input_fpath = os.path.join(model.work_path, 'input.nml')
input_nml = f90nml.read(work_input_fpath)
assert input_nml['MOM_input_nml']['input_filename'] == 'n'
assert input_nml['SIS_input_nml']['input_filename'] == 'n'

0 comments on commit f0cdbb2

Please sign in to comment.