Skip to content

Commit 9cb0e39

Browse files
andrewwinters5000patrickersingranocha
authored
Well-balanced mortars (#45)
* first attempt to restructure mortar calculation to preserve well-balancedness * adjust cfl in new elixir * partially working version. straight-sided elements okay * working version of the mortar approximation well-balancedness. Still allocates * rename file for consistency * add new experimental elixir for wet/dry well balancedness * fix dumb spelling mistakes * reduce allocations * add comments * wet-dry well balancedness works but perturbation test on wet-drt still crashes * add velocity desingularization on the mortars * remove redundant call to summary callback * update comments * update call signature for prolong2mortars routine * change to a better source file name * remove TODO * change to better file name for source code * add yml for better github interface * add special mortar container for the shallow water solver * rename file * remove allocations * typo fixes * working module AMR conservation, needs cleanup and tests * remove TreeMesh file; save for later PR * update codecov.yml to resolve merge conflict * cleanup well-balanced wet-dry elixir * update docstring * cleanup well balanced elixirs and update ODE library * cleanup wet perturbation elixir * cleanup wet dry perturbation elixir * add tests * cleanup the new projection and mortar calculation routines * remove debugging statements * apply formatter for examples and test * apply formatter to new mortar routines * fix formatting in test files and extend test to fire resize call * adjust call signature to increase converage * remove debugging comment * improve readibility * add comment about test values that may change * Add NEWS.md with a first item * Apply suggestions from code review Co-authored-by: Patrick Ersing <114223904+patrickersing@users.noreply.github.com> Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com> * rename new elixirs to be more descriptive * unify names of AMR indicator functions * forgot to rename gravity_constant to gravity * convert docstring for new mortar type to a comment * add upstream test for fully wet AMR * fix broken link to development section of the docs * remove unnecessary using Download * put changelog creation into docs/make.jl * typo fix in NEWS.md * adjust name of module block in test_p4est_2d * add DocPreviewCleanup.yml so previewing the docs works * add command in Documenter.yml to build and deploy * remove unneeded uses from Documenter.yml * reduce amount of output to screen for fully wet tests * adjust nonconforming, well balanced, and wet/dry test * update perturbation test with wet/dry and AMR * apply formatter * up maxiters in coverage override for amr + wet/dry test * adjust docstring as in code review * add changelog.md to ignored files --------- Co-authored-by: Patrick Ersing <114223904+patrickersing@users.noreply.github.com> Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
1 parent 2267af4 commit 9cb0e39

26 files changed

+1558
-37
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Doc Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
doc-preview-cleanup:
9+
# Do not run on forks to avoid authorization errors
10+
# Source: https://github.community/t/have-github-action-only-run-on-master-repo-and-not-on-forks/140840/18
11+
if: github.repository_owner == 'trixi-framework'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout gh-pages branch
15+
uses: actions/checkout@v4
16+
with:
17+
ref: gh-pages
18+
19+
- name: Delete preview and history
20+
shell: bash
21+
run: |
22+
git config user.name "Documenter.jl"
23+
git config user.email "documenter@juliadocs.github.io"
24+
git rm -rf --ignore-unmatch "previews/PR$PRNUM"
25+
git commit -m "delete preview" --allow-empty
26+
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
27+
env:
28+
PRNUM: ${{ github.event.number }}
29+
30+
- name: Push changes
31+
run: |
32+
git push --force origin gh-pages-new:gh-pages

.github/workflows/Documenter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040
- name: Install dependencies
4141
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
4242
- name: Build and deploy
43-
uses: julia-actions/julia-docdeploy@v1
4443
env:
4544
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4645
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
4746
GKSwstype: 100 # To make GitHub Action work, disable showing a plot window with the GR backend of the Plots package
47+
run: julia --project=docs --color=yes docs/make.jl
4848
- name: Run doctests
4949
run: |
5050
julia --project=docs --color=yes -e '

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
- tree_2d
5252
- structured_2d
5353
- unstructured_2d
54+
- p4est_2d
5455
- unit
5556
- upstream
5657
include:
@@ -97,6 +98,7 @@ jobs:
9798
- tree_2d
9899
- structured_2d
99100
- unstructured_2d
101+
- p4est_2d
100102
- unit
101103
steps:
102104
- uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ out*/
1515
docs/build
1616
docs/src/authors.md
1717
docs/src/home.md
18+
docs/src/changelog.md
1819
docs/src/code_of_conduct.md
1920
docs/src/contributing.md
2021
docs/out/

NEWS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
TrixiShallowWater.jl follows the interpretation of
4+
[semantic versioning (semver)](https://julialang.github.io/Pkg.jl/dev/compatibility/#Version-specifier-format-1)
5+
used in the Julia ecosystem. Notable changes will be documented in this file
6+
for human readability.
7+
8+
9+
## Changes in the v0.1 lifecycle
10+
11+
#### Added
12+
13+
- Experimental support for well-balanced mortars together with AMR [#45]
14+
15+
#### Changed
16+
17+
#### Deprecated
18+
19+
#### Removed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ julia --project=.
8181
```
8282
if already inside the `run` directory.
8383
Further details, of how to develop TrixiShallowWater.jl together with a local
84-
clone Trixi.jl, can be found in the Development section of the [documentation](#documentation).
84+
clone Trixi.jl, can be found in the
85+
[Development section](https://trixi-framework.github.io/TrixiShallowWater.jl/stable/development/)
86+
of the documentation.
8587

8688
## Authors
8789
TrixiShallowWater.jl is maintained by the

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
2-
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
32
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
4+
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
45
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
56
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
67
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
@@ -15,6 +16,7 @@ TrixiShallowWater = "804cb1fc-5b08-4398-a671-a789bfe091b3"
1516

1617
[compat]
1718
CairoMakie = "0.13"
19+
Changelog = "1.1"
1820
CSV = "0.10"
1921
DataFrames = "1.7"
2022
Documenter = "1.3"

docs/make.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using TrixiShallowWater
22
using Documenter
33
using DocumenterInterLinks
44
using Literate
5+
using Changelog: Changelog
56

67
# Provide external links to the Trixi.jl docs (project root and inventory file)
78
links = InterLinks("Trixi" => ("https://trixi-framework.github.io/Trixi.jl/stable/",
@@ -61,7 +62,23 @@ write(joinpath(@__DIR__, "src", "home.md"), readme_text)
6162
DocMeta.setdocmeta!(TrixiShallowWater, :DocTestSetup, :(using TrixiShallowWater);
6263
recursive = true)
6364

64-
# TODO: create changelog
65+
# Create changelog
66+
Changelog.generate(Changelog.Documenter(), # output type
67+
joinpath(@__DIR__, "..", "NEWS.md"), # input file
68+
joinpath(@__DIR__, "src", "changelog_tmp.md"); # output file
69+
repo = "trixi-framework/TrixiShallowWater.jl", # default repository for links
70+
branch = "main",)
71+
# Fix edit URL of changelog
72+
open(joinpath(@__DIR__, "src", "changelog.md"), "w") do io
73+
for line in eachline(joinpath(@__DIR__, "src", "changelog_tmp.md"))
74+
if startswith(line, "EditURL")
75+
line = "EditURL = \"https://github.com/trixi-framework/TrixiShallowWater.jl/blob/main/NEWS.md\""
76+
end
77+
println(io, line)
78+
end
79+
end
80+
# Remove temporary file
81+
rm(joinpath(@__DIR__, "src", "changelog_tmp.md"))
6582

6683
# Make documentation
6784
makedocs(;
@@ -83,6 +100,7 @@ makedocs(;
83100
"Advanced topics & developers" => ["Development" => "development.md",
84101
"Style guide" => "styleguide.md",
85102
"Testing" => "testing.md"],
103+
"Changelog" => "changelog.md",
86104
"Authors" => "authors.md",
87105
"Contributing" => "contributing.md",
88106
"Code of Conduct" => "code_of_conduct.md",
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK
3+
using Trixi
4+
using TrixiShallowWater
5+
6+
###############################################################################
7+
# semidiscretization of the shallow water equations with a continuous
8+
# bottom topography function and a perturbation in the water height
9+
10+
equations = ShallowWaterEquationsWetDry2D(gravity = 9.812, H0 = 2.1)
11+
12+
function initial_condition_perturbation(x, t, equations::ShallowWaterEquationsWetDry2D)
13+
# Calculate primitive variables
14+
H = equations.H0
15+
v1 = 0.0
16+
v2 = 0.0
17+
18+
x1, x2 = x
19+
b = (1.75 / exp(0.5 * ((x1 - 1.0)^2 + (x2 + 1.0)^2))
20+
+
21+
0.8 / exp(0.5 * ((x1 + 1.0)^2 + (x2 - 1.0)^2))
22+
-
23+
0.5 / exp(3.5 * ((x1 - 0.4)^2 + (x2 - 0.325)^2)))
24+
25+
# Waterheight perturbation
26+
H = H + 0.5 * exp(-40.0 * ((x[1])^2 + (x[2])^2))
27+
28+
return prim2cons(SVector(H, v1, v2, b), equations)
29+
end
30+
31+
initial_condition = initial_condition_perturbation
32+
33+
boundary_condition = Dict(:x_neg => boundary_condition_slip_wall,
34+
:y_neg => boundary_condition_slip_wall,
35+
:x_pos => boundary_condition_slip_wall,
36+
:y_pos => boundary_condition_slip_wall)
37+
38+
###############################################################################
39+
# Get the DG approximation space
40+
41+
volume_flux = (flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal)
42+
43+
surface_flux = (FluxHydrostaticReconstruction(flux_hll_chen_noelle,
44+
hydrostatic_reconstruction_chen_noelle),
45+
flux_nonconservative_chen_noelle)
46+
47+
# Create the solver
48+
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
49+
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
50+
51+
###############################################################################
52+
# This setup is for the curved, split form well-balancedness testing
53+
54+
# Affine type mapping to take the [-1,1]^2 domain from the mesh file
55+
# and warp it as described in https://arxiv.org/abs/2012.12040
56+
function mapping_twist(xi, eta)
57+
y = eta + 0.2 * cos(1.5 * pi * xi) * cos(0.5 * pi * eta)
58+
x = xi + 0.2 * cos(0.5 * pi * xi) * cos(2.0 * pi * y)
59+
return SVector(x, y)
60+
end
61+
62+
# The mesh below can be made periodic if desired
63+
64+
# Create P4estMesh with 4 x 4 trees
65+
trees_per_dimension = (4, 4)
66+
mesh = P4estMesh(trees_per_dimension, polydeg = 3,
67+
mapping = mapping_twist,
68+
initial_refinement_level = 0,
69+
periodicity = false)
70+
71+
# Refine bottom left quadrant of each tree to level 3
72+
function refine_fn(p4est, which_tree, quadrant)
73+
quadrant_obj = unsafe_load(quadrant)
74+
if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 3
75+
# return true (refine)
76+
return Cint(1)
77+
else
78+
# return false (don't refine)
79+
return Cint(0)
80+
end
81+
end
82+
83+
# Refine recursively until each bottom left quadrant of a tree has level 3
84+
# The mesh will be rebalanced before the simulation starts
85+
refine_fn_c = @cfunction(refine_fn, Cint,
86+
(Ptr{Trixi.p4est_t}, Ptr{Trixi.p4est_topidx_t},
87+
Ptr{Trixi.p4est_quadrant_t}))
88+
Trixi.refine_p4est!(mesh.p4est, true, refine_fn_c, C_NULL)
89+
90+
# Create the semi discretization object
91+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
92+
boundary_conditions = boundary_condition)
93+
###############################################################################
94+
# ODE solvers, callbacks, etc.
95+
96+
tspan = (0.0, 3.0)
97+
ode = semidiscretize(semi, tspan)
98+
99+
###############################################################################
100+
101+
summary_callback = SummaryCallback()
102+
103+
analysis_interval = 1000
104+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
105+
extra_analysis_errors = (:conservation_error,))
106+
107+
alive_callback = AliveCallback(analysis_interval = analysis_interval)
108+
109+
save_solution = SaveSolutionCallback(dt = 0.04,
110+
save_initial_solution = true,
111+
save_final_solution = true)
112+
113+
# Define the perturbation of water height as a variable to use in the AMR indicator
114+
@inline function waterheight_total(u, equations::ShallowWaterEquationsWetDry2D)
115+
return u[1] + u[4]
116+
end
117+
118+
amr_controller = ControllerThreeLevel(semi,
119+
IndicatorMax(semi, variable = waterheight_total),
120+
base_level = 1,
121+
med_level = 2, med_threshold = 2.01,
122+
max_level = 4, max_threshold = 2.15)
123+
124+
amr_callback = AMRCallback(semi, amr_controller,
125+
interval = 1,
126+
adapt_initial_condition = false,
127+
adapt_initial_condition_only_refine = false)
128+
129+
stepsize_callback = StepsizeCallback(cfl = 1.0)
130+
131+
callbacks = CallbackSet(summary_callback,
132+
analysis_callback,
133+
alive_callback,
134+
save_solution,
135+
amr_callback,
136+
stepsize_callback)
137+
138+
###############################################################################
139+
# run the simulation
140+
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
141+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
142+
adaptive = false,
143+
save_everystep = false, callback = callbacks);

0 commit comments

Comments
 (0)