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

added nonhydrostatic capabilities to MPAS-O #21

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

scalandr
Copy link
Collaborator

This is a nonhydrostatic version of MPAS-O. This nonhydrostatic model enables new physics, allowing the correct representation of, for example, high-resolution internal waves dynamics, which are not well represented by the hydrostatic approximation. New vertical momentum and pressure terms are added in the formulation, and a coupled elliptic system is formed for the solution of the nonhydrostatic pressure correction. At every time step, this system is solved with the PETSc library using preconditioned iterative Krylov solvers. The flag config_enable_nonhydrostatic_mode can be used to turn on and off the nonhydrostatic capabilities.

@scalandr scalandr requested review from xylar, dengwirda and vanroekel May 20, 2022 21:18
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, thank you for this amazing work! This will be such an great new capability for us to have.

I have noticed several things that need a little work. I still have a lot of code to go through but this is all I have time for for a little while so wanted to give you a chance to address it first.

The major one is that most if not all of the variables you added should be in the nonhydrostaticPKG package (I suggest this name change). In the code, it will be important to only access these fields if the package is active. Typically, you can check if the field pointers are associated. See many examples of this throughout the code. If you don't make use of packages, your changes here will add substantially to the memory usage of the model even in hydrostatic mode.

The other, which is preventing the code from compiling and therefore preventing me from verifying that the results in hydrostatic mode are bit-for-bit is the incorrect indentation in src/shared/Makefile. It needs to be with tabs, not spaces.

Please verify that the code compiles for you and then ping me to try testing again.

Comment on lines 929 to 948
($(FC) pio2.f90 $(FCINCLUDES) $(FFLAGS) $(LDFLAGS) $(LIBS) -o pio2.out &> /dev/null && echo "=> PIO 2 detected") || \
($(FC) pio2.f90 $(FCINCLUDES) $(FFLAGS) $(LDFLAGS) $(LIBS) -o pio2.out && echo "=> PIO 2 detected") || \
Copy link
Collaborator

Choose a reason for hiding this comment

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

@scalandr, this line needs to go back to what it used to be. I presume this was just to help you debug.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@xylar, done.

Comment on lines 2997 to 3008
<var name="dynamicViscosity" type="real" dimensions="nVertLevelsP1 nCells Time" units="Ns/m^2"
description="dynamic viscosity of water as a function of temperature and salinity"
packages="forwardMode;analysisMode"
/>
<var name="uStar" type="real" dimensions="nVertLevels nCells Time" units="m s^{-1}"
description="stress velocity for wall bounded flows"
packages="forwardMode;analysisMode"
/>
<var name="yPlus" type="real" dimensions="nVertLevels nCells Time" units="m"
description="boundary normal coordinate"
packages="forwardMode;analysisMode"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add to nonhydrostaticPKG

Comment on lines 3070 to 3090
<var name="ugrad" type="real" dimensions="R3 nVertLevels nCells Time" units="s^{-1}"
description="three-dimensional gradient of zonal velocity"
/>
<var name="vgrad" type="real" dimensions="R3 nVertLevels nCells Time" units="s^{-1}"
description="three-dimensional gradient of meridional velocity"
/>
<var name="wgrad" type="real" dimensions="R3 nVertLevels nCells Time" units="s^{-1}"
description="three-dimensional gradient of vertical velocity"
/>
<var name="tgrad" type="real" dimensions="R3 nVertLevels nCells Time" units="s^{-1}"
description="three-dimensional gradient of temperature"
/>
<var name="sgrad" type="real" dimensions="R3 nVertLevels nCells Time" units="s^{-1}"
description="three-dimensional gradient of salinity"
/>
<var name="Sh" type="real" dimensions="nVertLevels nCells Time" units="unitless"
description="Structure function for heat and salt -- may want to consider separating at some point"
/>
<var name="Sm" type="real" dimensions="nVertLevels nCells Time" units="unitless"
description="Structure function for momentum"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add to nonhydrostaticPKG

Comment on lines 3085 to 3090
<var name="Sh" type="real" dimensions="nVertLevels nCells Time" units="unitless"
description="Structure function for heat and salt -- may want to consider separating at some point"
/>
<var name="Sm" type="real" dimensions="nVertLevels nCells Time" units="unitless"
description="Structure function for momentum"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried that the names Sh and Sm are not sufficiently descriptive or unique.

Comment on lines 30 to 36
mpas_ocn_vvel_vert_advection.o \
mpas_ocn_vvel_horiz_advection.o \
mpas_ocn_vvel_coriolis.o \
mpas_ocn_vvel_hmix_del2.o \
mpas_ocn_vvel_advection.o \
mpas_ocn_vvel_pgf.o \
mpas_ocn_nonhydrostatic_pressure_solve.o \
Copy link
Collaborator

Choose a reason for hiding this comment

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

The indentation here seems to be incorrect.

Comment on lines 84 to 91
mpas_ocn_two_equation_model_driver.o \
mpas_ocn_two_equation_structure_functions.o \
mpas_ocn_two_equation_model_driver.o \
mpas_ocn_tke_glsPsi_transport.o \
mpas_ocn_tke_advection_mono.o \
mpas_ocn_glsPsi_advection_mono.o \
mpas_ocn_shear_production.o \
mpas_ocn_buoyancy_production.o
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation here needs to be with tabs, not spaces. As a result, I am not able to build the code on Anvil.

@scalandr
Copy link
Collaborator Author

scalandr commented Jul 1, 2022

Hi @xylar, I am ready to ask for a re-review of the PR. Before I click on the "re-request review" button I wanted to ask you about the two conflicting files. If I click on "Resolve conflicts" and fix them there, then my local branch will not see the changes, correct? What is your recommendation on how to proceed? Thanks!

@xylar
Copy link
Collaborator

xylar commented Jul 1, 2022

@scalandr, my recommendation for resolving conflicts like this is always to rebase onto E3SM-Project/E3SM/master.

If you use "Resolve conflicts" here, it will do a merge of E3SM-Ocean-Discussion/E3SM/master to this branch, but that's not very helpful since that isn't the same thing as E3SM-Project/E3SM/master and some merge conflicts might remain. Also, I am a strong advocate of avoiding merging at nearly all cost expect for merging pull requests. If you merge E3SM-Project/E3SM/master into your branch instead of rebasing, things can become very messy to untangle later. (Of course, if mistakes happen during a rebase, that can also be tricky to untangle later, but I still very much think it's worth it.)

I will update E3SM-Ocean-Discussion/E3SM/master to match E3SM-Project/E3SM/master right now. That way, if you rebase onto E3SM-Project/E3SM/master, you won't see any extra commits that aren't yours.

@xylar
Copy link
Collaborator

xylar commented Jul 1, 2022

Okay, I just updated E3SM-Ocean-Discussion/E3SM/master. This shows why it's important to use E3SM-Project/E3SM/master as the base branch instead: there are now 4 conflicting files, not jut 2.

@scalandr
Copy link
Collaborator Author

scalandr commented Jul 1, 2022

@xylar, when we did the rebase together last time we did

git remote add E3SM-Project/E3SM [email protected]:E3SM-Project/E3SM.git
git fetch --all -p
git rebase -i E3SM-Project/E3SM/master

Shall i just do git fetch --all -p before the git rebase command this time?

@xylar
Copy link
Collaborator

xylar commented Jul 1, 2022

@scalandr, yes, that's right. You don't need to add E3SM-Porject/E3SM as a remote since it's already been added.

@scalandr scalandr requested a review from xylar July 2, 2022 01:58
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.

I see a few basically cosmetic things that I'd like to see fixed. After that, I'm ready for this to move to E3SM.

I'd like to have @dengwirda and @mark-petersen both approve here first, though.

Comment on lines 247 to 248
<nml_option name="config_use_vertMom_del2" type="logical" default_value=".false." units="unitless"
description="If true, Laplacian horizontal mixing is used on the vertical momentum equation."
Copy link
Collaborator

Choose a reason for hiding this comment

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

The registry needs to be indented with tabs, not spaces everywhere.

Comment on lines 1119 to 1131
<nml_record name="nonhydrostatic_pressure">
<nml_option name="config_enable_nonhydrostatic_mode" type="logical" default_value=".false." units="unitless"
description="Flag to enable the nonhydrostatic pressure calculation"
possible_values=".true. or .false."
/>
<nml_option name="config_nonhydrostatic_solve_surface_boundary_condition" type="character" default_value="noGradient" units="unitless"
description="setting for surface boundary condition for the pressure correction solve"
possible_values="noGradient or no pressure"
/>
<nml_option name="config_enable_vertMomentum_disable_nonHydro" type="logical" default_value=".false." units="unitless"
description="flag to enable hydrostatic pressure with vertical momentum tendencies"
possible_values=".true. or .false."
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the process of replacing spaces with tabs for indentation, please make the indentation consistent

Comment on lines 2188 to 2195
<var name="vertVelocityNonhydro" type="real" dimensions="nVertLevelsP1 nCells Time" units="m s^{-1}"
description="prognostic vertical velocity, only used when config_enable_nonhydrostatic_mode = .true."
/>
<var name="nonhydrostaticPressure" type="real" dimensions="nVertLevels nCells Time" units="N m^{-2}"
description="nonhydrostatic pressure, set to zero if config_enable_nonhydrostatic_mode = .false."
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can these variables be put in the nonhydrostaticPKG package? If they aren't used at all when the nonhydrostaticPKG is disabled, this should be possible. If not, this will add to the memory used in hydrostatic mode.

Comment on lines 2542 to 2547
<var name="tendVertVelocityNonhydro" type="real" dimensions="nVertLevelsP1 nCells Time" units="m s^{-2}" name_in_code="vertVelocityNonhydroTend"
description="time tendency of the vertical velocity (Only active for non hydrostatic mode)"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, can this be in the nonhydrostaticPKG package?

Comment on lines 2626 to 2611
<var name="velocityHmixTend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocitydue to horizontal mixing"
/>
<var name="velocityVmixTend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocity due to vertical mixing"
/>
<var name="velocityCoriolisTend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocity due to Coriolis"
/>
<var name="velocityPGFtend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocity due to PGF"
/>
<var name="velocityVadvTend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocity due to vertical advection"
/>
<var name="velocityForcingTend" dimensions="nVertLevels nEdges Time" units="m/s^2" type="real"
description="tendency of normal velocity due to top and bottom forcing"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this still needs to happen.

Comment on lines 268 to 269
print*, dt

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please take this out. I assume it's for debugging.

Comment on lines 506 to 537

call ocn_time_integrator_rk4_compute_thick_tends( block, dt, rk_substep_weights(rk_step), err )
block => block % next
end do

call mpas_timer_stop("RK4 vel/thick tendency computations")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe put back these blank lines?

call mpas_timer_stop("RK4 vel/thick tendency computations")

! Update halos for prognostic variables.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe put back this comment (below the if)

Comment on lines 710 to 713
call ocn_nonhydrostatic_pressure_update_velocity(normalVelocityNew, vertVelocityNonhydroNew, &
layerThicknessNew, layerThickEdgeMean, nonhydrostaticPressure, nonhydrostaticPressureOld, &
nhPressureCorrection, dt)
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 indented 3 spaces too many

@@ -658,7 +658,7 @@ subroutine ocn_meshCreate(domain) !{{{
!$acc edgeNormalVectors, &
!$acc localVerticalUnitVectors, &
!$acc cellTangentPlane, &
!$acc coeffs_reconstruct)
!$acc coeffs_reconstruct)
Copy link
Collaborator

Choose a reason for hiding this comment

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

trailing space should be removed.

@xylar
Copy link
Collaborator

xylar commented Jul 5, 2022

It looks like one more conflicting commit came in in the last few days. @scalandr, you'll need to rebase one more time.

I ran the nightly test suite from compass with and without PETSc (and NetLib LAPACK). The first one was fine. The second was fine except for tests with different thread decompositions, as we have already discussed. I didn't try rerunning @scalandr's new nonhydro test case yet but will do that as part of an E3SM review.

@scalandr
Copy link
Collaborator Author

Hi @vanroekel, I took care of all your comments, so

  • I got rid of unused flags like config_use_constant_forced_pgf, config_disable_ALE, and config_enable_vertMomentum_disable_nonHydro,
    I renamed nonhydrostaticPressure and nonhydrostaticPressureOld to nonhydrostaticPressureNew and nonhydrostaticPressureCur, respectively, in all time-steppers,
  • I removed viscosity from hmix tend,
  • I cleaned other files you mentioned.
    About the vertical mixing in the vertical momentum, I believe I should inline the tri-diagonal solver. It’s something that we’ll have to do eventually, so let’s just do it now. Beside the tri-diagonal solver, the only thing left is the rebase.

@scalandr
Copy link
Collaborator Author

scalandr commented Jul 13, 2022

@xylar, If I do the rebase I see

rebase

So should I erase the first 7 lines, i.e. commits 88fb to 7355?

@xylar
Copy link
Collaborator

xylar commented Jul 13, 2022

@scalandr, no, sorry for the confusion. Here's what we're seeing on GitHub:
image
Those are the commits that we would want to get rid of. But I now think it's just GitHub glitching and not noticing that those commits aren't part of this branch. We've seen that before. I think if I change the target branch to something else and then change it back to E3SM-Ocean-Discussion:master, it should be fine. I'll try that.

@xylar xylar changed the base branch from master to alternate July 13, 2022 05:13
@xylar xylar changed the base branch from alternate to master July 13, 2022 05:13
@xylar
Copy link
Collaborator

xylar commented Jul 13, 2022

Indeed, that seems to have taken care of it:
image
@vanroekel, make sure you agree that the commits that shouldn't have been here are gone.

@vanroekel
Copy link
Collaborator

@scalandr the new version is looking great! I think there is just one more question about the tridiagonal solve in my mind. It looks like you inlined that code. If that is true, can you remove the code for the solver itself? it shouldn't be needed anymore

@scalandr
Copy link
Collaborator Author

Hi @vanroekel, I finished inlining the tridiagonal solve in ocn_vertVel_vmix_tend_implicit and got rid of the subroutine tridiagonal_solve. I also corrected the module description in the horizontal mixing module for the vertical momentum, that is ocn_vvel_hmix_del2.

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.

This is looking great! I'm ready for this to move on to e3sm.

xylar pushed a commit that referenced this pull request Jan 18, 2023
This commit resolves reveiew comments for PR #21 ('Add a regional
sea-level projection capability to MALI')

- Set up MPI variables outside of routine 'interpolation_init'.
- Move reformatting command of 1D SL array to 2D array inside of
  routine 'interpolation'
- Include #ifdef USE_SEALEVELMODEL inside of the check for config_uplift_method
- other small fixes
@xylar
Copy link
Collaborator

xylar commented Mar 10, 2023

@scalandr, I noticed when building this today that the make targets are out of date compared to master. Could you do a rebase to bring those changes in when you have time? Not super urgent but it would be a good idea.

@scalandr
Copy link
Collaborator Author

Hi @xylar, as far as I know @jonbob already rebased this nonhydro branch locally. What would be the best way to proceed? For him to push the rebased version? Thanks!

@xylar
Copy link
Collaborator

xylar commented Mar 13, 2023

@scalandr and @jonbob, that's something for the 2 of you to coordinate but I think that sounds like the easiest solution. In general, it is very important that no one but the developer force-pushes to a branch on a fork without careful coordination.

xylar pushed a commit that referenced this pull request Sep 12, 2024
…Dev/develop

Previously, when the regional sea-level prediction capability was added
to MALI (#21), the restart config option for the sea-level model was not
added. This led the sea-level model to get initialized to Timestep zero
when coupled MALI-SLM simulations are being restarted, forgetting about
the ice loading changes and associated viscoelastic solid earth deformation
that happened in the timesteps prior to current model time. This PR
fixes the problem by allowing the sea-level model to resume where it
was left off. Note in parallel to this PR, the version of the SLM needs
to incorporate the changes made in the following accompanying
PR (MALI-Dev/1DSeaLevelModel_FWTW#9)

* hollyhan/add_restart_functionality_slm:
  Don't call SLM on init of a restart
  Add addl info on restart about the calculated time since last SLM call
  Allow restarts at any interval when using SLM
  Add missing error flag so model actually dies when error occurs
  Add missing arguments to log write statement
  Update restart check to also use time interval division
  Adjust check if adaptive dt is on or not
  Update checks using interval division
  Improve error handling, correct other usage of config_uplift_method
  Improve synchronization of timesteps between MALI and SLM
  Add restart option when the SLM is coupled to MALI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants