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

Adding quasi 1d shallow water equations #1619

Merged
merged 30 commits into from
Sep 14, 2023

Conversation

KrisshChawla
Copy link
Contributor

@KrisshChawla KrisshChawla commented Aug 29, 2023

Added an equation type and entropy conservative fluxes for the quasi 1d shallow water equations based on https://doi.org/10.48550/arXiv.2307.12089. We also added a manufactured solution elixir which also serves as a CI test.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 29, 2023

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

@jlchan jlchan changed the title adding quasi 1d shallow water equations Adding quasi 1d shallow water equations Aug 29, 2023
@jlchan jlchan self-requested a review August 29, 2023 22:24
@jlchan jlchan marked this pull request as draft August 29, 2023 22:28
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
@jlchan jlchan marked this pull request as ready for review August 29, 2023 22:52
@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Patch coverage: 86.84% and project coverage change: +3.17% 🎉

Comparison is base (547556d) 92.94% compared to head (cd3f4c1) 96.11%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1619      +/-   ##
==========================================
+ Coverage   92.94%   96.11%   +3.17%     
==========================================
  Files         416      418       +2     
  Lines       34070    34223     +153     
==========================================
+ Hits        31666    32892    +1226     
+ Misses       2404     1331    -1073     
Flag Coverage Δ
unittests 96.11% <86.84%> (+3.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/Trixi.jl 43.48% <ø> (ø)
src/equations/equations.jl 98.04% <ø> (ø)
src/equations/shallow_water_quasi_1d.jl 86.11% <86.11%> (ø)
...gsem/elixir_shallowwater_quasi_1d_well_balanced.jl 100.00% <100.00%> (ø)

... and 39 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jlchan
Copy link
Contributor

jlchan commented Aug 30, 2023

The test failures appear to be from #1617.

src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
@jlchan
Copy link
Contributor

jlchan commented Aug 30, 2023

@KrisshChawla when you're ready, please re-request a review from us

@KrisshChawla KrisshChawla requested review from jlchan and ranocha August 30, 2023 13:40
Copy link
Member

@andrewwinters5000 andrewwinters5000 left a comment

Choose a reason for hiding this comment

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

Overall this looks quite good so far! I left a few suggestions for clean-up. My main two questions are

  1. Is entropy conservation and/or stability ever tested? Such that you verify that the newly implemented fluxes are working properly. For the most strenuous test it would good to test against initial conditions with discontinuities in all variables including b and a. Even though a discontinuous channel width might be "unphysical" or meaningless, this is only an academic test to make sure everything is working.
  2. Was well-balancedness ever tested to make sure the fluxes are implemented correctly? This is related to one of my suggestions that noted a function to compute the well-balancedness error is missing. This set of equations would need a specialized version of this function because one needs to divide off the channel width from the water height in the conservative variables. Similar to the question above, a well-balancedness test with a discontinuous bottom topography is always more strenuous to make sure the implementation is behaving as expected.

using Trixi

###############################################################################
# Semidiscretization of the shallow water equations
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Semidiscretization of the shallow water equations
# Semidiscretization of the quasi 1d shallow water equations
# See Chan et al. https://doi.org/10.48550/arXiv.2307.12089 for details

Maybe adding a link to the paper here is overkill but I was not sure how well-known these equations are.

@@ -0,0 +1,59 @@
using OrdinaryDiffEq
Copy link
Member

Choose a reason for hiding this comment

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

The name of this elixir does not follow the normal convention. Typically, the convergence test elixirs would be something like elixir_shallow_water_quasi_1d_source_terms.jl. Also, we prefer to avoid capital letters in the files names.

Comment on lines 115 to 116
@trixi_testset "elixir_shallow_water_quasi_1D_manufactured.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_shallow_water_quasi_1D_manufactured.jl"),
Copy link
Member

Choose a reason for hiding this comment

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

If the filename of the elixir changes, this will need updated.

src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Show resolved Hide resolved
src/equations/shallow_water_quasi_1d.jl Outdated Show resolved Hide resolved
e = (a_h_v^2) / (2 * a * a_h) + 0.5 * equations.gravity * (a_h^2 / a) +
equations.gravity * a_h * b
return e
end
Copy link
Member

Choose a reason for hiding this comment

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

Is well-balancedness ever computed? As far as I can tell there is a missing function to compute this error, like the following (modulo a bunch of the comments therein. I was lazy and just copied over and slightly modified the code from the shallow_water_1d.jl file.

# Calculate the error for the "lake-at-rest" test case where H = h+b should
# be a constant value over time. Note, assumes there is a single reference
# water height `H0` with which to compare.
#
# TODO: TrixiShallowWater: where should `threshold_limiter` live? May need
# to modify or have different versions of the `lake_at_rest_error` function
@inline function lake_at_rest_error(u, equations::ShallowWaterEquationsQuasi1D)
    _, _, b, _ = u
    h = waterheight(u, equations)

    # For well-balancedness testing with possible wet/dry regions the reference
    # water height `H0` accounts for the possibility that the bottom topography
    # can emerge out of the water as well as for the threshold offset to avoid
    # division by a "hard" zero water heights as well.
    H0_wet_dry = max(equations.H0, b + equations.threshold_limiter)

    return abs(H0_wet_dry - (h + b))
end

Copy link
Contributor

Choose a reason for hiding this comment

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

We can check this - I originally removed this from this PR to make it shorter, but it'd be great to demonstrate this property.

jlchan
jlchan previously approved these changes Sep 8, 2023
Copy link
Contributor

@jlchan jlchan left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@andrewwinters5000, for the entropy conservation check, do we usually add that as a test or do we just comment with the result we get from running an EC elixir?

Copy link
Contributor

Choose a reason for hiding this comment

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

can you change the name to examples/tree_1d_dgsem/elixir_shallowwater_quasi_1d_well_balanced.jl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will rename it.

@ranocha
Copy link
Member

ranocha commented Sep 8, 2023

@andrewwinters5000, for the entropy conservation check, do we usually add that as a test or do we just comment with the result we get from running an EC elixir?

We typically report results of a local run. Right now, we do not have an automated way of checking EC in CI.

@sloede
Copy link
Member

sloede commented Sep 8, 2023

@andrewwinters5000, for the entropy conservation check, do we usually add that as a test or do we just comment with the result we get from running an EC elixir?

We typically report results of a local run. Right now, we do not have an automated way of checking EC in CI.

A slightly less convenient method could be to write out entropy conservation information in the analysis callback to a file, and then read that file back during test verification. It would probably require some additional coding but nothing extremely difficult.

@KrisshChawla
Copy link
Contributor Author

The entropy conservation test results in an error of '∑∂S/∂U ⋅ Uₜ : 1.58068003e-14' when using the entropy conservative flux ‘(flux_chan_etal, flux_nonconservative_chan_etal)’ for surface and volume fluxes along with the adjusted non-periodic initial condition for total water height ‘H = 3 + 0.5 * x[1]’ in the well balancedness test case.

@jlchan
Copy link
Contributor

jlchan commented Sep 8, 2023

The entropy conservation test results in an error of '∑∂S/∂U ⋅ Uₜ : 1.58068003e-14' when using the entropy conservative flux ‘(flux_chan_etal, flux_nonconservative_chan_etal)’ for surface and volume fluxes along with the adjusted non-periodic initial condition for total water height ‘H = 3 + 0.5 * x[1]’ in the well balancedness test case.

I should clarify that this is using the setup from the well-balanced test case, which involved spatially varying and discontinuous a and b, but it is not the constant well-balanced solution

Copy link
Contributor

@jlchan jlchan left a comment

Choose a reason for hiding this comment

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

Let's wait for @andrewwinters5000 to take a look but it looks good to me

Copy link
Member

@andrewwinters5000 andrewwinters5000 left a comment

Choose a reason for hiding this comment

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

This looks good from my end of things. The entropy conservation test results look good and the new well-balancedness test is a nice addition.

@jlchan jlchan merged commit b942775 into trixi-framework:main Sep 14, 2023
30 of 31 checks passed
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.

5 participants