Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@scalandr
Copy link
Collaborator

Here is a new test group with two test cases to validate the new nonhydrostatic capabilites of MPAS-O. The tests consist of i) an internal solitary wave, and ii) an internal stratified seiche. For both tests, after building mesh and initial conditions, a hydrostatic and a nonhydrostatic simulation are run, and plots are made to show the differences between the two models.

@scalandr
Copy link
Collaborator Author

scalandr commented Apr 24, 2022

For the solitary wave test case, the plot looks like this
solitary
It shows the temperature profiles obtained after 16h and 30 min for the nonhydrostatic (top) and hydrostatic (bottom) simulations.

@xylar xylar added enhancement New feature or request ocean labels Apr 24, 2022
@xylar xylar self-assigned this Apr 24, 2022
@xylar
Copy link
Collaborator

xylar commented Apr 24, 2022

@scalandr, could you give me instructions on which E3SM branch is needed to go with this test case and how to compile it? I think you mentioned that PETSC is required.

@scalandr scalandr requested review from dengwirda and vanroekel April 25, 2022 17:29
@scalandr
Copy link
Collaborator Author

@xylar, the E3SM branch is this one:
https://github.com/scalandr/E3SM/tree/v2_nonhydro
To compile it go to components/mpas-ocean, and then do

source /lcrc/soft/climate/e3sm-unified/load_latest_e3sm_unified_anvil.sh
source home/ac.vanroekel/load_MPAS
make ifort CORE=ocean USE_PETSC=true USE_LAPACK=true DEGUB=true USE_PIO2=true

@xylar
Copy link
Collaborator

xylar commented Apr 26, 2022

@scalandr, thanks very much for the instructions. When I try to build on Anvil, I'm seeing:

mpas_ocn_vel_hadv_coriolis.F(262): error #6404: This name does not have a type, and must have an explicit type.   [WAV]
!$omp private(cell1, cell2, wav)
----------------------------^
mpas_ocn_vel_hadv_coriolis.F(262): error #7656: Subobjects are not allowed in this OpenMP* clause; a named variable must be specified.   [WAV]
!$omp private(cell1, cell2, wav)
----------------------------^
compilation aborted for mpas_ocn_vel_hadv_coriolis.F (code 1)
make[3]: *** [mpas_ocn_vel_hadv_coriolis.o] Error 1

I presume your testing has been without OpenMP so far but it seems like you will want to test with OPENMP=true as well to catch problems.

@xylar xylar self-requested a review April 26, 2022 09:51
Copy link
Collaborator

@xylar xylar left a comment

Choose a reason for hiding this comment

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

@scalandr, this is really amazing work!

My overall feeling is that there is some room to reduce the redundancy between the two test cases. That would be worth discussing together. But it seems like a lot of the InitialState and Forward classes are copies of one another so there should be a way to simplify things a bit. At least it seems worth considering.

Another major thing is that it would be nice to use the existing infrastructure for creating vertical coordinates rather than doing everything in each InitialState class. This might require adding your z coordinate in which only the top layer moves but I see that that coordinate doesn't get used by default in the current setup.

And finally I think each InitialState class would benefit a lot from taking advantage of xarray to avoid loops wherever possible.

Comment on lines +2 to +3
config_run_duration = '0001_16:30:00'
config_dt = '00:01:00'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a pretty long simulation (which is obviously fine). For regression testing to make sure the nonhydro code is working as expected, it would be great to also have a shorter (say 3 time step) version of the test cases that includes validation of several fields against a baseline simulation (if provided). This would be something to consider as a follow-up PR.

Comment on lines 177 to 121
for k in range(0, nVertLevels):
activeCells = k <= maxLevelCell
salinity[0, activeCells, k] = S0
density[0, activeCells, k] = rho0 + (10.0/2)*(1.0 - \
np.tanh((2/1)*np.arctanh(0.99)*(zMid[0, :, k] + \
0.5*maxDepth - 0.1*np.cos((np.pi/10)*xCell[:]))))
# T = Tref - (rho - rhoRef)/alpha
temperature[0, activeCells, k] = config_eos_linear_Tref \
- (density[0, activeCells, k] - config_eos_linear_densityref) / \
config_eos_linear_alpha
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to avoid looping over k if we don't need to. This would have at least advantages:

  1. you would not need to pre-initialized the 3D variables above
  2. looping is nearly always slow in python

The computation of the vertical coordinate that I suggested above will add a ds.cellMask variable that I demonstrate here (equivalent to your activeCells). But in this test case, you have hard-coded that there is no bathymetry so this might be needlessly complicated. You might want to leave out the masking (all .where(ds.cellMask) calls).

Suggested change
for k in range(0, nVertLevels):
activeCells = k <= maxLevelCell
salinity[0, activeCells, k] = S0
density[0, activeCells, k] = rho0 + (10.0/2)*(1.0 - \
np.tanh((2/1)*np.arctanh(0.99)*(zMid[0, :, k] + \
0.5*maxDepth - 0.1*np.cos((np.pi/10)*xCell[:]))))
# T = Tref - (rho - rhoRef)/alpha
temperature[0, activeCells, k] = config_eos_linear_Tref \
- (density[0, activeCells, k] - config_eos_linear_densityref) / \
config_eos_linear_alpha
ds['salinity'] = (S0*xarray.ones_like(ds.zMid)).where(ds.cellMask)
ds['density'] =rho0 + (10.0/2)*(1.0 - \
np.tanh((2/1)*np.arctanh(0.99)*(ds.zMid + \
0.5*maxDepth - 0.1*np.cos((np.pi/10)*ds.xCell))))
# T = Tref - (rho - rhoRef)/alpha
ds['temperature'] = config_eos_linear_Tref \
- (ds.density - config_eos_linear_densityref) / \
config_eos_linear_alpha

The density calculations seems to be really tricky to format in a reasonable way so maybe compute some intermediate variable to make it more readable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed it as suggested, but I have not put intermediate variables. If you think they are necessary for the code to be readable I'll create them.

Comment on lines 188 to 128
# initial velocity on edges
ds['normalVelocity'] = (('Time', 'nEdges', 'nVertLevels',),
np.zeros([1, nEdges, nVertLevels]))
normalVelocity = ds['normalVelocity']
for iEdge in range(0, nEdges):
normalVelocity[0, iEdge, :] = u[0, iEdge, :] * math.cos(angleEdge[iEdge])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems complicated, given that u is just all zeros (unless I missed something). I think the following would do it:

Suggested change
# initial velocity on edges
ds['normalVelocity'] = (('Time', 'nEdges', 'nVertLevels',),
np.zeros([1, nEdges, nVertLevels]))
normalVelocity = ds['normalVelocity']
for iEdge in range(0, nEdges):
normalVelocity[0, iEdge, :] = u[0, iEdge, :] * math.cos(angleEdge[iEdge])
# initial velocity on edges
ds['normalVelocity'] = (('Time', 'nEdges', 'nVertLevels',),
np.zeros([1, nEdges, nVertLevels]))

Do you have in mind to support non-zero u in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The lines

        normalVelocity = ds['normalVelocity']
        for iEdge in range(0, nEdges):
            normalVelocity[0, iEdge, :] = u[0, iEdge, :] * math.cos(angleEdge[iEdge])

are indeed there for the more general case of a non-zero initial velocity. So, in that case, all you have to do is changing u.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, that sounds reasonable.

@xylar
Copy link
Collaborator

xylar commented Apr 26, 2022

A few more things I forgot to include above.

I am still running the tests. 1 hour on an Anvil interactive node was not enough. Update: the tests ran successfully with a longer allocation and took about 84 minutes together.

I would like to add PETSC to the Spack build for compass and try running with that instead of @vanroekel's build. I think it would be important to make a PR to add PETSC before this goes in because otherwise no one can use it without special instructions.

Finally, I think it will be necessary to get the v2_nonhydro branch merged into E3SM before this PR gets merged because, again, without that no on can run these tests without special instructions.

compass/ocean/tests/nonhydro/solitary_wave/visualize.py Outdated Show resolved Hide resolved
compass/ocean/tests/nonhydro/solitary_wave/visualize.py Outdated Show resolved Hide resolved
@xylar
Copy link
Collaborator

xylar commented May 14, 2022

@scalandr, thanks for starting on addressing my comments! That's great! Let me know if you have questions on the ones that remain. Also, let me know when you are ready for me to re-review and then fix up the PEP8 stuff (as we agreed).

It would be great to meet in person whenever we are allowed to go back to the Lab. Please get in touch when that happens so we can arrange something.

@scalandr
Copy link
Collaborator Author

Hi Xylar, I was able to compile my nonhydro code with openMP and PETSc both on, so
OPENMP=true PETSC=true
and the tests also ran just fine. Basically there are openMP loop everywhere except in the PETSc submodule, since PETSc was not really built for openMP. Let me know if you have any issue with this. I believe I am pretty close to open a PR request for the nonhydro code.

@xylar
Copy link
Collaborator

xylar commented May 15, 2022

@scalandr, that sounds good. What we need to test is that code unrelated to nonhydro still compiles fine with OPENMP=true. I don't believe that's currently the case. I think it would be good to open a "discussion" PR on E3SM-Ocean-Discussion before we move over to E3SM. We should be able to do so "no-harm" testing to make sure everything works as before when someone isn't using the nonhydro capabilities.

@scalandr
Copy link
Collaborator Author

@xylar, what do you mean by the "code unrelated to nonhydro"? What I mean when I say nonhydro code is the standard v2 MPAS-O code, plus a few more modules in the shared folder and a few if statements in the time-steppers. So the nonhydro code already includes the standard hydrostatic version.
About testing that we didn't do any harm to the standard hydro, these two test cases are already a proof of that. A hydro simulation is run for both test cases, and we get the expected hydrostatic results. But a more thorough testing can of course be done.

@xylar
Copy link
Collaborator

xylar commented May 15, 2022

@xylar, what do you mean by the "code unrelated to nonhydro"? What I mean when I say nonhydro code is the standard v2 MPAS-O code, plus a few more modules in the shared folder and a few if statements in the time-steppers. So the nonhydro code already includes the standard hydrostatic version.

Right, I understand that.

About testing that we didn't do any harm to the standard hydro, these two test cases are already a proof of that. A hydro simulation is run for both test cases, and we get the expected hydrostatic results. But a more thorough testing can of course be done.

That's not quite the same as what I mean. We need to run several standard E3SM and compass test cases with the current E3SM master branch and with v2_nonhydro merged into E3SM master to make sure the results are bit-for-bit identical. When I tried to compile v2_nonhydro with OPENMP=true (which is a requirement for many these tests), I got errors. See my earlier comment #374 (comment). These will need to be fixed before v2_nonhydro is safe to merge into E3SM.

If you make a PR for v2_nonhydro, we can discuss more there.

@xylar
Copy link
Collaborator

xylar commented May 15, 2022

One more thing, E3SM will require a branch that is named something like ocn/nonhydro. It must start with the component that is affected, then a /, then a description of the feature that is all lowercase and has only - and no other punctuation. It might be worth making a branch from v2_nonhydro with the expected naming convention and then using that for the PR to E3SM-Ocean-Discussion, too. That will be a little less confusing than changing branch names before the E3SM PR.

@scalandr
Copy link
Collaborator Author

In the name, what should the spelling be, ocn or ocean?
Do I have to add my github name in front, so scalandr/ocean/nonhydro?

@xylar
Copy link
Collaborator

xylar commented May 16, 2022

In the name, what should the spelling be, ocn or ocean?

Either is fine.

Do I have to add my github name in front, so scalandr/ocean/nonhydro?

No, that is only necessary if you aren't using your own fork of E3SM. If you're using your own fork, including your username is redundant.

@scalandr
Copy link
Collaborator Author

About openMP, if I use the most updated version of v2_nonhydro and do

source /lcrc/soft/climate/e3sm-unified/load_latest_e3sm_unified_anvil.sh
source home/ac.vanroekel/load_MPAS
make ifort CORE=ocean USE_PETSC=true USE_LAPACK=true DEGUB=true USE_PIO2=true OPENMP=true

I get
MPAS was built with OpenMP enabled.
Could you try with the most recent version of v2_nonhydro and let me know if you still have errors?

@xylar
Copy link
Collaborator

xylar commented May 16, 2022

@scalandr, I think I see. We are using different compilers and MPI libraries, and yours aren't detecting the error that I'm seeing. Sorry about not being more specific.

I just tried a few hours ago and I don't think any changes were made to the v2_nonhydro branch since then. So I don't think it is the version of v2_nonhydro. I thin it is that I used a newer version of Intel, the same one used by E3SM. To reproduce what I'm seeing, please try:

git clone git@github.com:MPAS-Dev/compass.git
./conda/configure_compass_env.py --conda ~/miniconda3/ --env_name compass_nonhydro -c intel -i mvapich
source load_compass_nonhydro_anvil_intel_mvapich.sh
cd </path/to/>v2_nonhydro/components/mpas-ocean
make clean
make OPENMP=true ifort

You can look at the contents of load_compass_nonhydro_anvil_intel_mvapich.sh to see what modules are being loaded in this case.

@xylar
Copy link
Collaborator

xylar commented May 16, 2022

I am very close to having PETSC and Netlib-LAPACK supported in compass. This should allow you to stop using @vanroekel's script and also let you test with any of the 13 configurations supported in compass: https://mpas-dev.github.io/compass/latest/developers_guide/machines/index.html#supported-machines

@xylar
Copy link
Collaborator

xylar commented May 16, 2022

@scalandr, I ran into a small problem with the test above. If you try it tomorrow, it should demonstrate the issue but I need to fix something first. Related to #391

@xylar
Copy link
Collaborator

xylar commented May 16, 2022

@scalandr, okay the compass issue is fixed. You should be able to try #374 (comment)

@scalandr
Copy link
Collaborator Author

@xylar, I tried #374 and I have fixed the issues with openMP. Just pushed the changes.

@xylar
Copy link
Collaborator

xylar commented May 18, 2022

@scalandr, that's perfect, that worked for me, too. If you want to make a PR to E3SM-Ocean-Discussion, I'm happy to do some more rigorous testing in the next week or 2 and post the results. You should also get someone who is familiar with the nonhydro work itself to review. Hopefully, the discussion will go quickly and you can make a PR to E3SM once everyone is happy.

@scalandr scalandr force-pushed the add_nonhydro_test_group branch from 96a6c84 to 1410863 Compare February 1, 2023 22:29
@xylar xylar removed request for dengwirda and xylar February 1, 2023 23:54
@MPAS-Dev MPAS-Dev deleted a comment from pep8speaks Feb 1, 2023
Copy link
Collaborator

@xylar xylar left a comment

Choose a reason for hiding this comment

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

@scalandr, one more small thing to fix -- there are 4 docstrings that still refer to the baroclinic channel instead of Nonhydro. Please fetch the remote branch to get my commit that fixed the formatting of the code, hard reset, and then fix the 4 docstring, commit and push.

compass/ocean/tests/nonhydro/solitary_wave/__init__.py Outdated Show resolved Hide resolved
compass/ocean/tests/nonhydro/solitary_wave/forward.py Outdated Show resolved Hide resolved
compass/ocean/tests/nonhydro/stratified_seiche/__init__.py Outdated Show resolved Hide resolved
compass/ocean/tests/nonhydro/stratified_seiche/forward.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@xylar xylar left a comment

Choose a reason for hiding this comment

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

Thanks @scalandr! That looks great. I'll run the tests again tomorrow using your E3SM branch. Assuming they still run successfully, I'll approve.

As we agreed, we're going to make the unusual step of merging this before the associated changes are in E3SM so this can be the basis for testing PETSc configurations and so that other nonhydro test cases can be added to this test group in follow-up PRs.

@xylar xylar requested review from cbegeman and xylar February 2, 2023 03:21
@xylar
Copy link
Collaborator

xylar commented Feb 2, 2023

@scalandr, can you let me know which is the best E3SM branch to test with? I was testing with https://github.com/scalandr/E3SM/tree/v2_nonhydro but it looks like https://github.com/scalandr/E3SM/tree/ocean/nonhydro was updated more recently. I'm going to try the second one for now.

@scalandr
Copy link
Collaborator Author

scalandr commented Feb 2, 2023

Use the second one please, i.e.
https://github.com/scalandr/E3SM/tree/ocean/nonhydro

Copy link
Collaborator

@xylar xylar left a comment

Choose a reason for hiding this comment

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

Both test cases passed on Chrysalis with Intel and OpenMPI. I'm very pleased to add this capability!

@xylar
Copy link
Collaborator

xylar commented Feb 2, 2023

@cbegeman, could you give this another look when you have a chance?

@vanroekel, do you want to review as well?

Copy link
Collaborator

@vanroekel vanroekel left a comment

Choose a reason for hiding this comment

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

I took a look through the conversation and all the code and this looks great to me. Very happy to see this go in.

Approving on visual inspection and Xylar's testing.

Copy link
Collaborator

@cbegeman cbegeman left a comment

Choose a reason for hiding this comment

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

@scalandr Great work on this! I just made some minor edits to the documentation. If you like, you can add the suggestions to a batch commit and then commit them directly from github.

I'm approving now based on your and Xylar's testing and successful tests of mine before the latest clean-up.

docs/users_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/users_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/users_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
docs/developers_guide/ocean/test_groups/nonhydro.rst Outdated Show resolved Hide resolved
Thanks Carolyn!

Co-authored-by: Carolyn Begeman <cbegeman@lanl.gov>
@scalandr
Copy link
Collaborator Author

scalandr commented Feb 2, 2023

Hi Carolyn, I followed your suggestion, so I added your comments to a batch commit and then committed them directly from github. Thanks!

@xylar xylar merged commit 99db33c into MPAS-Dev:main Feb 2, 2023
@xylar
Copy link
Collaborator

xylar commented Feb 2, 2023

Great, thanks everyone!

@xylar xylar mentioned this pull request Feb 8, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ocean

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.