-
Notifications
You must be signed in to change notification settings - Fork 20
Add ocean model conservation checks #437
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
Merged
cbegeman
merged 17 commits into
E3SM-Project:main
from
cbegeman:add-conservation-checks
Dec 19, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b9bbdb1
Add verify_properties to step and ocean_model_step
cbegeman eb95bc7
Add conservation-related utilities
cbegeman 9ba4df2
Test mass conservation for btrgyre
cbegeman 625d404
Add other property tests to ocean_model_step
cbegeman 0d096ea
Set conservation tolerances in ocean cfg section
cbegeman 335e69b
Check that properties have been verified before running
cbegeman 68e3001
Consistently use 'check' properties instead of 'verify'
cbegeman 4ac8032
Update the docs and doc strings
cbegeman cf845c2
Placeholder non-boussinesq mass conservation check for omega
cbegeman 34b123b
Fixup unrelated docs
cbegeman 1898d84
Generalize salt conservation check to all tracers
cbegeman b7b19b4
Support conservation checks for convergence tests
cbegeman b688c76
Check mass conservation for manufactured_solution test
cbegeman 275728d
Add more information to property check logs
cbegeman bb4547a
Make tolerances less permissive
cbegeman 48e72c8
Clean-up ocean conservation
cbegeman 3fbdd8c
Clean-up ocean model step
cbegeman 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
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
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,72 @@ | ||
| from mpas_tools.cime.constants import constants | ||
|
|
||
| # Should match config_density0 | ||
| rho_sw = 1026.0 | ||
|
|
||
| cp_sw = constants['SHR_CONST_CPSW'] | ||
|
|
||
|
|
||
| def compute_total_mass(ds_mesh, ds): | ||
| """ | ||
| Compute the total mass in an ocean model output file using a constant | ||
| density | ||
| """ | ||
| ds = _reduce_dataset_time_dim(ds) | ||
| area_cell = ds_mesh.areaCell | ||
| layer_thickness = ds.layerThickness | ||
| total_mass = rho_sw * ( | ||
| area_cell * layer_thickness.sum(dim='nVertLevels') | ||
| ).sum(dim='nCells') | ||
| return total_mass | ||
|
|
||
|
|
||
| def compute_total_energy(ds_mesh, ds): | ||
| """ | ||
| Compute the total heat content an ocean model output file | ||
| """ | ||
| ds = _reduce_dataset_time_dim(ds) | ||
| area_cell = ds_mesh.areaCell | ||
| layer_thickness = ds.layerThickness | ||
| temperature = ds.temperature | ||
| total_energy = ( | ||
| rho_sw | ||
| * cp_sw | ||
| * ( | ||
| area_cell * (layer_thickness * temperature).sum(dim='nVertLevels') | ||
| ).sum(dim='nCells') | ||
| ) | ||
| return total_energy | ||
|
|
||
|
|
||
| def compute_total_tracer(ds_mesh, ds, tracer_name='tracer1'): | ||
| """ | ||
| Compute the total salt in an ocean model output file | ||
| """ | ||
| ds = _reduce_dataset_time_dim(ds) | ||
| area_cell = ds_mesh.areaCell | ||
| layer_thickness = ds.layerThickness | ||
| tracer = ds[tracer_name] | ||
| total_tracer = ( | ||
| area_cell * (layer_thickness * tracer).sum(dim='nVertLevels') | ||
| ).sum(dim='nCells') | ||
| return total_tracer | ||
|
|
||
|
|
||
| def compute_total_salt(ds_mesh, ds): | ||
| """ | ||
| Compute the total salt in an ocean model output file | ||
| """ | ||
| return compute_total_tracer(ds_mesh, ds, tracer_name='salinity') | ||
|
|
||
|
|
||
| def _reduce_dataset_time_dim(ds): | ||
| for time_dim in ['time', 'Time']: | ||
| if time_dim in ds.dims: | ||
| if ds.sizes[time_dim] > 1: | ||
| raise ValueError( | ||
| 'compute_total_energy is designed to work on a dataset ' | ||
| 'with one time slice' | ||
| ) | ||
| else: | ||
| ds = ds.isel(time_dim=0) | ||
| return ds |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.