Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Couple the HBModel and SWModel for use in the Split-Explicit Stepper #1268

Merged
merged 3 commits into from
Jul 23, 2020

Conversation

blallen
Copy link
Contributor

@blallen blallen commented Jun 22, 2020

Description

A continuation of #1257, adding the necessary communication between the two models needed to have a true split-explicit stepper. The work in this PR enables us to run with up to a 90-minute timestep for the hydrostatic spindown test case.

The broadcasts of reshaped MPIStateArrays depends on #1071 to run on the GPU. I'll pull over the commits from that PR for running bors, but we need to merge that before we merge this one.

There's quite a bit of partial work in this PR that was necessary to get things running, but that either isn't fully implemented everywhere it should be or isn't implemented super elegantly (mainly regarding collecting all the Ocean models into a single module and how multiple dispatch is used for the couple). I'll revisit that once we have the full timestepping machinery running.

I have

  • Written and run all necessary tests with CLIMA by including tests/runtests.jl
  • Followed all necessary style guidelines and run julia .dev/climaformat.jl .
  • Updated the documentation to reflect changes from this PR.

For review by CLIMA developers

  • There are no open pull requests for this already
  • CLIMA developers with relevant expertise have been assigned to review this submission
  • The code conforms to the style guidelines and has consistent naming conventions. julia .dev/format.jl has been run in a separate commit.
  • This code does what it is technically intended to do (all numerics make sense physically and/or computationally)

@blallen blallen added Ocean 🌊 "How inappropriate to call this planet Earth when it is quite clearly Ocean" Timestepping labels Jun 22, 2020
@blallen blallen self-assigned this Jun 22, 2020
@blallen blallen force-pushed the bla/coupled_ocean branch 4 times, most recently from 7b73bf3 to 6c6b594 Compare June 25, 2020 18:00
@blallen blallen marked this pull request as ready for review June 26, 2020 20:45
@blallen
Copy link
Contributor Author

blallen commented Jun 26, 2020

So there's a nasty bug hidden somewhere in the code I used to couple the timesteppers: when using the Statecheck module, the velocity fields can differ after approximately the 4th decimal place after each run. I've tried comparing runs within the same REPL session and across different ones and it happens either way. The weird thing is that the solutions are still within 0.2% of the analytical solution and the VTK output looks reasonable.

As far as I can tell, I've made sure to properly initialize all the variables we are using. I'd appreciate someone taking another look at this before I merge everything in.

@christophernhill
Copy link
Member

christophernhill commented Jun 27, 2020

@blallen there is a lot in this PR that is all lumped together. Is it too late to do over and try and do this in stages? That would be my general instinct (I know thats logistically painful given current CI and monorepo foo, but it is still probably the right approach).

One funky thing I did notice is

boxy_ΔGᵘ = reshape(ΔGᵘ, Nq^2, Nqk, 2, nelemv, nelemh)
         boxy_ΔGᵘ .=
             -reshape(flat_∫du, Nq^2, 1, 2, 1, nelemh) / baroclinic.problem.H

but I think thats probably just left over debugging? or possibly it should be

         boxy_ΔGᵘ .-=
             reshape(flat_∫du, Nq^2, 1, 2, 1, nelemh) / baroclinic.problem.H

in which case spelling it out properly might be better. My general take is Unary ops are an easy way to blow yourself up and don't add anything except potential to make really dumb subtle errors.

  • separate (but related)
    @leios does .= broadcast work all the time and in all ways for all things GPU, or are we better off using copy!() ? I tried some .= with the MPI_wrapper PR and got various Dat error messages.

@blallen
Copy link
Contributor Author

blallen commented Jun 27, 2020

@blallen there is a lot in this PR that is all lumped together. Is it too late to do over and try and do this in stages? That would be my general instinct (I know thats logistically painful given current CI and monorepo foo, but it is still probably the right approach).

I can spin-off 22cb1ff (and related changes) into a separate PR. I was originally planning on doing this afterwards in order to reuse the SimpleBoxProblem setup between both SWModel and HBModel, but realized that having a Base module would also be useful for the coupling traits.

c25791f can also be split into a separate PR, but it will depend on #1071 being merged. I just put it here since all the other broadcast reshapes also depend on #1071 so this PR is CPU only for now.

The rest of the stuff in the PR is pretty hard to disentangle. Basically everything in the src/Ocean/SplitExplicit directory is needed before coupling the models makes sense. This includes the TendencyIntegralModel, the FlowIntegralModel, the FullyCoupled dispatch functions in HydrostaticBoussinesqCoupling.jl and ShallowWaterCoupling.jl, and finally the actual communication between the models in Communication.jl.

We might be able to add some unit tests for the two *IntegralModel where we just provide an input flow/tendency and check that the resulting integrals make sense. Then we could also split those off into a separate PR. I'm not sure if there's anything we could do to split the *Coupling.jl and Communication.jl files into smaller chunks.

One funky thing I did notice is

boxy_ΔGᵘ = reshape(ΔGᵘ, Nq^2, Nqk, 2, nelemv, nelemh)
         boxy_ΔGᵘ .=
             -reshape(flat_∫du, Nq^2, 1, 2, 1, nelemh) / baroclinic.problem.H

but I think thats probably just left over debugging? or possibly it should be

         boxy_ΔGᵘ .-=
             reshape(flat_∫du, Nq^2, 1, 2, 1, nelemh) / baroclinic.problem.H

in which case spelling it out properly might be better. My general take is Unary ops are an easy way to blow yourself up and don't add anything except potential to make really dumb subtle errors.

Ah yeah, that's probably a better way to write it. I copied this straight from @jm-c's branch, but I think your way of writing it is functionally the same (and definitely clearer).

  • separate (but related)
    @leios does .= broadcast work all the time and in all ways for all things GPU, or are we better off using copy!() ? I tried some .= with the MPI_wrapper PR and got various Dat error messages.

@leios is going to squash #1071 soon, and then I can cherry-pick that commit and test all of this on the GPU.

@christophernhill
Copy link
Member

@blallen doing some splitting would be great. Some is better than none.

Just to check regarding

boxy_ΔGᵘ = reshape(ΔGᵘ, Nq^2, Nqk, 2, nelemv, nelemh)
         boxy_ΔGᵘ .=
             -reshape(flat_∫du, Nq^2, 1, 2, 1, nelemh) / baroclinic.problem.H

As this is written I think the second line is completely overwriting the first assignment (i.e. it is NOT subtracting the integral). The second line is setting every level to minus of the integral. If you meant to be subtracting the integral then I think the operator needs to be

.-=

NOT

.=-

If you are simply assigning then I am not sure why the

boxy_ΔGᵘ = reshape(ΔGᵘ, Nq^2, Nqk, 2, nelemv, nelemh)

is there.

Adding some all-caps just to make sure you didn't miss what I was saying!!!

@blallen
Copy link
Contributor Author

blallen commented Jun 27, 2020

The function below zeros out the contents of ΔGᵘ at the beginning of each RK stage, so I don't think there is any accumulation anyways. The .-= syntax is definitely clearer than the .=- syntax, but I think the function makes them equivalent in this case. I will change to .-= after rebasing and splitting things off into separate PRs.

@inline function initialize_states!(
    baroclinic::HydrostaticBoussinesqModel,
    barotropic::ShallowWaterModel,
    model_bc,
    model_bt,
    state_bc,
    state_bt,
)
    model_bc.state_auxiliary.ΔGᵘ .= -0

    return nothing
end

@blallen blallen force-pushed the bla/coupled_ocean branch 3 times, most recently from fed9fa6 to 46b958c Compare June 29, 2020 15:50
@blallen
Copy link
Contributor Author

blallen commented Jun 29, 2020

Okay, just rebased and rewrote history. Plan of attack is:

59959e6 - gets it own PR #1302 , no new tests needed
3795358 - gets it own PR, need to think up some simple tests for the integrations
46b958c - gets it own PR #1301, depends on #1071
070e655 and e887683 probably squashed to a single commit in the future and remain in this PR, depends on #1071

bors bot added a commit that referenced this pull request Jun 29, 2020
1302: Add supermodule `Ocean` around SWModel and HBModel r=blallen a=blallen

# Description

Split out from #1268. Necessary step towards coupling the SWModel and HBModel. Questionable if a supermodule is better than a base package to inherit from, but we will discuss that in the future. A further improvement with this is to move `SimpleBoxProblem.jl` up one level to be in `Ocean.SimpleBoxProblem` instead of `Ocean.HydrostaticBoussinesq`, but that will probably come in a separate PR (for clarity and because it is of lower importance right now)



Co-authored-by: Brandon Allen <ballen@mit.edu>
@blallen blallen force-pushed the bla/coupled_ocean branch 2 times, most recently from da75340 to d16d820 Compare June 30, 2020 01:10
@blallen
Copy link
Contributor Author

blallen commented Jun 30, 2020

Rebased on top of #1302, dropped the commit that got sent to #1301 and did some more history rewriting as I realized we could replace the FlowIntegralModel and TendencyIntegralModel with a single VerticalIntegralModel.jl with some minor modifications. This way we only need one test for the integrals instead of one for the flow and one for the tendency.

I'll split off 55d879b into its own PR tomorrow and add some basic tests based on the hydrostatic spindown initial state (and we can add more complicated tests as we get them).

Just to note here, #1301 is a bit more complicated than expected. We'll need to make the corresponding changes here once everything is figured out there.

@blallen
Copy link
Contributor Author

blallen commented Jul 21, 2020

bors r+

@blallen
Copy link
Contributor Author

blallen commented Jul 21, 2020

bors r+

bors bot added a commit that referenced this pull request Jul 21, 2020
1268: Couple the HBModel and SWModel for use in the Split-Explicit Stepper r=blallen a=blallen

# Description

A continuation of #1257, adding the necessary communication between the two models needed to have a true split-explicit stepper. The work in this PR enables us to run with up to a 90-minute timestep for the hydrostatic spindown test case. 

The broadcasts of reshaped MPIStateArrays depends on #1071 to run on the GPU. I'll pull over the commits from that PR for running bors, but we need to merge that before we merge this one.

There's quite a bit of partial work in this PR that was necessary to get things running, but that either isn't fully implemented everywhere it should be or isn't implemented super elegantly (mainly regarding collecting all the Ocean models into a single module and how multiple dispatch is used for the couple). I'll revisit that once we have the full timestepping machinery running.



Co-authored-by: Brandon Allen <ballen@mit.edu>
@bors
Copy link
Contributor

bors bot commented Jul 21, 2020

Build failed:

@blallen
Copy link
Contributor Author

blallen commented Jul 21, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 22, 2020

Merge conflict.

@blallen blallen force-pushed the bla/coupled_ocean branch 4 times, most recently from e64ff1e to 5e92e79 Compare July 23, 2020 00:55
blallen and others added 2 commits July 22, 2020 20:58
fill out communication functions and add necessary aux variables

don't statecheck aux while adding new aux variables

turn off restart values for now

remove time averaging over fast mode and add flag for reconciliation

add zero initializations

replace .=- with .-=

rebase fix for `test_vertical_integral_model.jl`

convert `tendency_from_slow_to_fast!` to new reshape&broadcast setup

Update `reconcile_from_fast_to_slow!` with new reshape&broadcast method

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
drive shallow water model by HB model

add coupling traits, use to replace forcing traits in shallow water
model

move coupling for SWModel to file in SplitExplicit

add coupling to HBModel, get fully coupled model to converge to analytic
solution

Add hydrostatic spindown tests with actual multi-rate happening

remove old integral models

get flow deviation working with new reshape&broadcast setup (on cpu).

Remove stub functions for partial coupling

use Coupling trait for dispatch instead of boolean in
SplitExplicitMethod.

use abbreviated model names

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
@blallen
Copy link
Contributor Author

blallen commented Jul 23, 2020

bors r+

@blallen
Copy link
Contributor Author

blallen commented Jul 23, 2020

bors try

bors bot added a commit that referenced this pull request Jul 23, 2020
This matches up numerical fluxes for the continuity equation in the
baroclinic and barotropic models

Fix `shallow_boundary_state!` numerical flux signatures.

update reference values for tests
@blallen
Copy link
Contributor Author

blallen commented Jul 23, 2020

bors try-

@blallen
Copy link
Contributor Author

blallen commented Jul 23, 2020

bors try

bors bot added a commit that referenced this pull request Jul 23, 2020
@bors
Copy link
Contributor

bors bot commented Jul 23, 2020

try

Build failed:

@blallen
Copy link
Contributor Author

blallen commented Jul 23, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 23, 2020

@bors bors bot merged commit 0c70054 into CliMA:master Jul 23, 2020
@blallen blallen deleted the bla/coupled_ocean branch July 23, 2020 13:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ocean 🌊 "How inappropriate to call this planet Earth when it is quite clearly Ocean" Timestepping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants