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

Add 3D Cartesian Shallow Water Equations #36

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

amrueda
Copy link
Collaborator

@amrueda amrueda commented Sep 16, 2024

This PR adds the 3D Shallow Water Equations (SWE) in Cartesian form, which can be solved on a 2D manifold embedded in 3D. We add two strategies to obtain entropy (total energy) conservation based on two-point fluxes: (i) using an entropy correction term, and (ii) using an entropy-consistent projection of the momentum. Both strategies require divergence-free metric terms on the 2D manifold. In this PR, we implement the curl-invariant form of Kopriva (2006). We also add the possibility to discretize the equations with the weak-form kernel.

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 92.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 83.93%. Comparing base (223fefe) to head (111fa45).

Files with missing lines Patch % Lines
src/equations/shallow_water_3d.jl 87.41% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   81.78%   83.93%   +2.15%     
==========================================
  Files           8       11       +3     
  Lines         829     1052     +223     
==========================================
+ Hits          678      883     +205     
- Misses        151      169      +18     

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

@amrueda amrueda changed the title WIP: Add ES discretization for Cartesian Shallow Water Equations Add Cartesian Shallow Water Equations Sep 17, 2024
@amrueda amrueda changed the title Add Cartesian Shallow Water Equations Add 3D Cartesian Shallow Water Equations Sep 17, 2024
@amrueda amrueda marked this pull request as ready for review September 17, 2024 16:28
struct MetricTermsCrossProduct end

"""
MetricTermsCurlInvariant()
Copy link
Member

Choose a reason for hiding this comment

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

Just a small thing regarding terminology - In his 2006 paper, David Kopriva originally called this the "invariant curl form" rather than the "curl-invariant form". Some more recent papers (not by Kopriva) have indeed called it the "curl-invariant form", but I don't see why the terminology should be changed. It also may be worth adding references to the following papers:

  • Kopriva, D. A. (2006). Metric identities and the discontinuous spectral element method on curvilinear meshes. Journal of Scientific Computing 26, 301-327. https://doi.org/10.1007/s10915-005-9070-8
  • Vinokur, M. and Yee, H. C. (2001). Extension of efficient low dissipation high order schemes for 3-D curvilinear moving grids. In Caughey, D. A., and Hafez, M. M. (eds.), Frontiers of Computational Fluid Dynamics 2002, World Scientific, Singapore, pp. 129–164. https://doi.org/10.1142/9789812810793_0008

Shallow water equations (SWE) in three space dimensions in conservation form (with constant bottom topography).
The equations are given by
```math
\begin{aligned}
Copy link
Member

@tristanmontoya tristanmontoya Sep 23, 2024

Choose a reason for hiding this comment

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

My understanding is that the 3D Cartesian form of the shallow water equations first appeared in the following paper, which we should reference here:

J. Coté (1988). A Lagrange multiplier approach for the metric terms of semi-Lagrangian models on the sphere. Quarterly Journal of the Royal Meteorological Society 114, 1347-1352. https://doi.org/10.1002/qj.49711448310

I also think it would also make sense to mention the Lagrange multiplier source term and perhaps link to where that is implemented.

end

# Custom RHS that applies a source term that depends on du (used to convert apply Lagrange multiplier)
function rhs_semi_custom!(du_ode, u_ode, semi, t)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to have the custom RHS and Lagrange multiplier source terms defined in dg_2d_manifold_in_3d_cartesian.jl and called by dispatch on the ShallowWaterEquations3D equation type rather than specified in the elixir? This is how I do it for the covariant form, for example:

function Trixi.rhs!(du, u, t, mesh::P4estMesh{2},
equations::AbstractCovariantEquations{2},
initial_condition, boundary_conditions, source_terms::Source,
dg::DG, cache) where {Source}
# Reset du
Trixi.@trixi_timeit Trixi.timer() "reset ∂u/∂t" Trixi.reset_du!(du, dg, cache)
# Calculate volume integral
Trixi.@trixi_timeit Trixi.timer() "volume integral" begin
Trixi.calc_volume_integral!(du, u, mesh,
Trixi.have_nonconservative_terms(equations),
equations,
dg.volume_integral, dg, cache)
end
# Prolong solution to interfaces
Trixi.@trixi_timeit Trixi.timer() "prolong2interfaces" begin
Trixi.prolong2interfaces!(cache, u, mesh, equations,
dg.surface_integral, dg)
end
# Calculate interface fluxes
Trixi.@trixi_timeit Trixi.timer() "interface flux" begin
Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations),
equations,
dg.surface_integral, dg, cache)
end
# Prolong solution to boundaries
Trixi.@trixi_timeit Trixi.timer() "prolong2boundaries" begin
Trixi.prolong2boundaries!(cache, u, mesh, equations,
dg.surface_integral, dg)
end
# Calculate boundary fluxes
Trixi.@trixi_timeit Trixi.timer() "boundary flux" begin
Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations,
dg.surface_integral, dg)
end
# Calculate surface integrals
Trixi.@trixi_timeit Trixi.timer() "surface integral" begin
Trixi.calc_surface_integral!(du, u, mesh, equations,
dg.surface_integral, dg, cache)
end
# Apply Jacobian from mapping to reference element
Trixi.@trixi_timeit Trixi.timer() "Jacobian" Trixi.apply_jacobian!(du, mesh,
equations, dg,
cache)
# Calculate source terms
Trixi.@trixi_timeit Trixi.timer() "source terms" begin
Trixi.calc_sources!(du, u, t, source_terms, equations, dg, cache)
end
return nothing
end

# for performance reasons.

# First summand 0.5 * (Xₘ Xₗ_ζ - Xₗ Xₘ_ζ)_η
@turbo for j in eachnode(basis), i in eachnode(basis)
Copy link
Member

@tristanmontoya tristanmontoya Sep 23, 2024

Choose a reason for hiding this comment

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

The LoopVectorization.jl @turbo macro is used here to compute the metrics, but it is not used anywhere else (e.g. in the volume integral). With the future support for LoopVectorization.jl uncertain, I am hesitant to use it in new code unless it's really critical for performance.

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.

2 participants