-
Notifications
You must be signed in to change notification settings - Fork 19
A polynya test case #797
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
Open
einola
wants to merge
48
commits into
develop
Choose a base branch
from
issue375_polynya_test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
A polynya test case #797
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
9199211
Polynya test case
einola db69db8
Minor updates to the config file
einola 805e1c0
Create init file with CMake
einola e510c07
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola 327de33
Merge branch 'develop' into issue375_polynya_test
einola b99de51
Add open (Neumann zero) boundary conditions
einola 60f876b
Revert "Add open (Neumann zero) boundary conditions"
einola 0584cbf
Merge branch '793landmask_cg' into issue375_polynya_test
einola 0077c28
New boundary handling.
winzerle 02720e1
- Removed old Dirichlet-Info from the mesh.
winzerle f4b5ebd
Merge branch 'develop' into issue375_polynya_test
einola eef5a16
Merge branch 'develop' into issue375_polynya_test
einola 1a3c692
Remove VTK output from VPCGDynamicsKernel
einola be756c3
Add u and v wind direction to ConfiguredAtmosphere
einola 150b21f
Initialise damage to one
einola 21cf14e
Fix open-water flux in FluxConfiguredAtmosphere
einola 4c6a41a
Update config_polynya.cfg
einola 768c4d4
Minor tweaks and fixes
einola d515e03
Merge branch 'develop' into issue375_polynya_test
einola e10ccbf
Clang-format fixes
einola 2e06954
Increase the domain size
einola 6bcb88d
Update PrognosticData_test.cpp
einola 437d6d1
Remove commented-out code
einola cbd56d8
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola 5781dbf
Minor fixes to get the model to compile and polynya simulation to start
einola 94e2b63
Merge branch 'develop' into issue375_polynya_test
einola 0ad9d32
Revert "Minor tweaks and fixes"
einola 53116d9
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola be0823c
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola 95c2a86
Change back dates on several files
einola fad93a1
Fix the date fixing
einola 5356fd1
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola 4c3a1dc
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola a783559
Fix polynya initialisation
einola 7d4da1f
Make an integration test out of the polynya case
einola dd519cd
Additional python path for the CI
einola 54919ec
Fix wrong python command on macOS
einola 58d8277
Reduce accuracy of polynya integration test
einola ee55629
Reduce the accuracy even further
einola d4be55e
Remove redundant f-string from make_init_polynya.py
einola 17f55a7
Use integer division, instead of type conversion
einola 00270c8
Use the class variable for init_file in PolynyaIntegration_test.py
einola 11ffd45
Document the PolynyaIntegration_test.py with a docstring
einola ef78f73
Merge remote-tracking branch 'origin/develop' into issue375_polynya_test
einola e4cec19
Merge branch 'develop' into issue375_polynya_test
einola 8c5962b
Update PolynyaIntegration_test.py "known good values"
einola 040f675
Merge branch 'develop' into issue375_polynya_test
einola f76e2cf
Update the polynya integration test script
einola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[model] | ||
init_file = init_polynya.nc | ||
start = 2023-01-01T00:00:00Z | ||
stop = 2023-01-05T00:00:00Z | ||
time_step = P0-0T00:01:00 | ||
missing_value = 1e20 | ||
|
||
[Modules] | ||
DiagnosticOutputModule = Nextsim::ConfigOutput | ||
DynamicsModule = Nextsim::MEVPDynamics | ||
AtmosphereBoundaryModule = Nextsim::FluxConfiguredAtmosphere | ||
OceanBoundaryModule = Nextsim::FluxConfiguredOcean | ||
IceThermodynamicsModule = Nextsim::ThermoWinton | ||
|
||
[ConfigOutput] | ||
period = P0-0T04:00:00 | ||
field_names = hice,cice,u,v | ||
filename = polynya.diagnostic.nc | ||
|
||
[FluxConfiguredOcean] | ||
qio = 2.30 | ||
sss = 28 | ||
sst = -1.54 | ||
mld = 10. | ||
current_u = 0. | ||
current_v = 0. | ||
|
||
[FluxConfiguredAtmosphere] | ||
Q_ia = 30 | ||
Q_ow = 300 | ||
dQia_dT = 0 | ||
wind_u = 16 | ||
wind_v = 12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from make_init_base import initMaker | ||
|
||
# Creates initial conditions for the Bjornsson et al. (2001) polynya case | ||
|
||
# Domain size [km] | ||
x = 100 | ||
y = 50 | ||
res = 2 | ||
|
||
nfirst = y // res | ||
nsecond = x // res | ||
nLayers = 3 | ||
|
||
fname = "init_polynya.nc" | ||
|
||
# The model expects everything in metres | ||
initializer = initMaker(fname, nfirst, nsecond, res*1e3, isWinton=True, checkZeros=False) | ||
|
||
# Ice everywhere and all boundaries closed, except the x = 100 km end | ||
initializer.mask[:, :] = 1. | ||
initializer.mask[0, :] = 0. | ||
initializer.mask[-1, :] = 0. | ||
initializer.mask[:, 0] = 0. | ||
#initializer.mask[:, -1] = 0. ## right | ||
|
||
# Uniform concentration of 90% | ||
initializer.cice[:, :] = 0.9 | ||
|
||
# Uniform thickness of 20 cm | ||
initializer.hice[:, :] = 0.2 | ||
|
||
# Undamaged ice | ||
initializer.damage[:, :] = 1. | ||
|
||
# Ice and ocean temperature and salinity at the freezing point | ||
ice_salinity = 5 # should match Ice::s in constants.hpp | ||
mu: float = -0.055 # should match Water::mu in constants.hpp | ||
ocean_temperature = -1.54 | ||
ocean_salinity = ocean_temperature / mu | ||
|
||
initializer.sss[:, :] = ocean_salinity | ||
initializer.sst[:, :] = ocean_temperature | ||
initializer.tsurf[:, :] = ice_salinity * mu | ||
initializer.tbott = initializer.tsurf | ||
initializer.tintr = initializer.tsurf | ||
|
||
# All other variables are zero or not needed | ||
|
||
# The file is written when initializer goes out of scope |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import unittest | ||
|
||
import netCDF4 | ||
import numpy as np | ||
|
||
|
||
class Polynya(unittest.TestCase): | ||
jwallwork23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
A test class based on the Bjornsson et al. (2001) polynya case. We run the model for 5 days and check the output | ||
against known values. The main purpose of this test is to check that the model is running and that the output is | ||
reasonable. | ||
|
||
NB! This test is very sensitive to small perturbations in the model. If the test fails, run the full-resolution | ||
version, cited below, and compare the results. You may need to adjust the "known good values" of the test | ||
accordingly. | ||
|
||
See Bjornsson et al. (2001) doi:10.3402/tellusa.v53i2.12184 for details. | ||
""" | ||
|
||
# A few useful global variables for the class | ||
executable = "../nextsim" | ||
|
||
init_file = "init_polynya.nc" | ||
config_file = "PolynyaIntegration.cfg" | ||
diagnostics_file = "polynya.diagnostic.nc" | ||
|
||
# Load the data once and re-use for all tests | ||
hice = np.array([]) | ||
cice = np.array([]) | ||
uice = np.array([]) | ||
vice = np.array([]) | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
""" | ||
A set-up class which, | ||
- Creates the initialisation file, using make_init_column.py | ||
- Runs the model | ||
- Loads the neccesary variables from the output file | ||
""" | ||
|
||
# Make the init column | ||
cls.__make_init_column() | ||
|
||
# Create the config file | ||
cls.__make_cfg_file() | ||
|
||
# Run the model | ||
subprocess.run(cls.executable + " --config-file " + cls.config_file, shell=True, check=True) | ||
|
||
# Load the basic variables | ||
root = netCDF4.Dataset(cls.diagnostics_file, "r", format="NETCDF4") | ||
cls.cice = np.squeeze(np.array(root.variables["cice"][:].data)) | ||
cls.hice = np.squeeze(np.array(root.variables["hice"][:].data)) | ||
cls.uice = np.array(root.variables["u"][:].data) | ||
cls.vice = np.array(root.variables["v"][:].data) | ||
|
||
@classmethod | ||
def __make_cfg_file(cls): | ||
cfg = open(cls.config_file, "w") | ||
cfg.write(""" | ||
[model] | ||
init_file = init_polynya.nc | ||
start = 2023-01-01T00:00:00Z | ||
stop = 2023-01-05T00:00:00Z | ||
time_step = P0-0T00:30:00 | ||
missing_value = 1e20 | ||
|
||
[Modules] | ||
DiagnosticOutputModule = Nextsim::ConfigOutput | ||
DynamicsModule = Nextsim::BBMDynamics | ||
AtmosphereBoundaryModule = Nextsim::FluxConfiguredAtmosphere | ||
OceanBoundaryModule = Nextsim::FluxConfiguredOcean | ||
IceThermodynamicsModule = Nextsim::ThermoWinton | ||
|
||
[ConfigOutput] | ||
period = P0-0T00:01:00 | ||
field_names = hice,cice,u,v | ||
filename = polynya.diagnostic.nc | ||
|
||
[FluxConfiguredOcean] | ||
qio = 2.30 | ||
sss = 28 | ||
sst = -1.54 | ||
mld = 10. | ||
current_u = 0. | ||
current_v = 0. | ||
|
||
[FluxConfiguredAtmosphere] | ||
Q_ia = 30 | ||
Q_ow = 300 | ||
dQia_dT = 0 | ||
wind_u = 16 | ||
wind_v = 12 | ||
""") | ||
cfg.close() | ||
|
||
@classmethod | ||
def __make_init_column(cls): | ||
sys.path.append('../run') | ||
sys.path.append('../../run') | ||
from make_init_base import initMaker | ||
|
||
# Creates initial conditions for the Bjornsson et al. (2001) polynya case | ||
|
||
# Domain size [km] | ||
x = 100 | ||
y = 50 | ||
res = 4 | ||
|
||
nfirst = y // res | ||
nsecond = x // res | ||
|
||
fname = cls.init_file | ||
|
||
# The model expects everything in metres | ||
initializer = initMaker(fname, nfirst, nsecond, res*1e3, checkZeros=False) | ||
|
||
# Ice everywhere and all boundaries closed, except the x = 100 km end | ||
initializer.mask[:, :] = 1. | ||
initializer.mask[0, :] = 0. | ||
initializer.mask[-1, :] = 0. | ||
initializer.mask[:, 0] = 0. | ||
#initializer.mask[:, -1] = 0. ## right | ||
|
||
# Uniform concentration of 90% | ||
initializer.cice[:, :] = 0.9 | ||
|
||
# Uniform thickness of 20 cm | ||
initializer.hice[:, :] = 0.2 | ||
|
||
# Undamaged ice | ||
initializer.damage[:, :] = 1. | ||
|
||
# Ice and ocean temperature and salinity at the freezing point | ||
ice_salinity = 5 # should match Ice::s in constants.hpp | ||
mu: float = -0.055 # should match Water::mu in constants.hpp | ||
ocean_temperature = -1.54 | ||
ocean_salinity = ocean_temperature / mu | ||
|
||
initializer.sss[:, :] = ocean_salinity | ||
initializer.sst[:, :] = ocean_temperature | ||
|
||
# All other variables are zero or not needed | ||
|
||
# The file is written when initializer goes out of scope | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
""" | ||
A tear-down class that deletes the netCDF output and temporary files | ||
""" | ||
|
||
if os.path.isfile(cls.diagnostics_file): | ||
os.remove(cls.diagnostics_file) | ||
|
||
if os.path.isfile(cls.init_file): | ||
os.remove(cls.init_file) | ||
|
||
if os.path.isfile(cls.config_file): | ||
os.remove(cls.config_file) | ||
|
||
def test_iceThickness(self): | ||
""" | ||
Test the ice thickness against standard max, min, and mean values | ||
The maximum varies by (at least) 3 cm between platforms, making a test of it useless | ||
""" | ||
|
||
mean = 0.1323 | ||
min = 0.0000 | ||
hice = self.hice[:,:,:,0] | ||
self.assertAlmostEqual(min, hice.min(), 4, "Min ice thickness not ~= " + str(min) + " m") | ||
self.assertAlmostEqual(mean, hice.mean(), 4, "Mean ice thickness not ~= " + str(mean) + " m") | ||
|
||
def test_concentration(self): | ||
""" | ||
Test the ice concentration against standard max, min, and mean values | ||
The min and max are easy, but the mean is sensitive | ||
""" | ||
|
||
mean = 0.4402 | ||
max = 1.0000 | ||
min = 0.0000 | ||
cice = self.cice[:,:,:,0] | ||
self.assertAlmostEqual(max, cice.max(), 4, "Max conentration not ~= " + str(max)) | ||
self.assertAlmostEqual(min, cice.min(), 4, "Min concentration not ~= " + str(min)) | ||
self.assertAlmostEqual(mean, cice.mean(), 2, "Mean concentration not ~= " + str(mean)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this any more!