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

AMR for 2D Parabolic P4est #1691

Merged
merged 153 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
b33cbc2
Clean branch
DanielDoehring Aug 14, 2023
7e32e24
Un-Comment
DanielDoehring Aug 14, 2023
5e1997b
un-comment
DanielDoehring Aug 14, 2023
54e328e
test coarsen
DanielDoehring Aug 14, 2023
a9e4cb7
remove redundancy
DanielDoehring Aug 14, 2023
ebb5865
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 15, 2023
4f72a09
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 15, 2023
70568f5
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 16, 2023
ebc9cc8
Remove support for passive terms
DanielDoehring Aug 18, 2023
9c766b9
expand resize
DanielDoehring Aug 18, 2023
c63e8b7
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 18, 2023
82894d7
comments
DanielDoehring Aug 18, 2023
6ef88ca
format
DanielDoehring Aug 18, 2023
7e4a450
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 19, 2023
53f5991
Avoid code duplication
DanielDoehring Aug 20, 2023
daf6fc4
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 20, 2023
cdfe93b
Update src/callbacks_step/amr_dg1d.jl
DanielDoehring Aug 22, 2023
0f2b779
comment
DanielDoehring Aug 22, 2023
376f99e
comment & format
DanielDoehring Aug 22, 2023
1dcfed4
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
baec78f
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
8526d16
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 22, 2023
826553f
Try to increase coverage
DanielDoehring Aug 28, 2023
9363b52
Merge branch 'Parabolic_AMR_1D' of github.com:DanielDoehring/Trixi.jl…
DanielDoehring Aug 28, 2023
d209629
Slightly more expressive names
DanielDoehring Aug 29, 2023
abce5ae
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Aug 31, 2023
a7d56a1
Apply suggestions from code review
sloede Sep 1, 2023
133c6a6
Merge branch 'main' into Parabolic_AMR_1D
sloede Sep 1, 2023
d348b82
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 6, 2023
f87046d
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 6, 2023
0c7dcb0
Merge branch 'main' into Parabolic_AMR_1D
DanielDoehring Sep 7, 2023
abb6dfb
add specifier for 1d
DanielDoehring Sep 11, 2023
bfa3a24
Structs for resizing parabolic helpers
DanielDoehring Sep 11, 2023
40ad266
check if mortars are present
DanielDoehring Sep 11, 2023
4d1914b
reuse `reinitialize_containers!`
DanielDoehring Sep 11, 2023
70c8e66
resize calls for parabolic helpers
DanielDoehring Sep 11, 2023
a5db7d0
update analysis callbacks
DanielDoehring Sep 11, 2023
c9d98a2
Velocities for compr euler
DanielDoehring Sep 11, 2023
694e6bc
Init container
DanielDoehring Sep 11, 2023
07655a4
correct copy-paste error
DanielDoehring Sep 11, 2023
edd82ce
resize each dim
DanielDoehring Sep 11, 2023
ba1ef1b
add dispatch
DanielDoehring Sep 11, 2023
7d351e5
Add AMR for shear layer
DanielDoehring Sep 11, 2023
e608174
USe only amr shear layer
DanielDoehring Sep 11, 2023
6574bf5
first steps towards p4est parabolic amr
DanielDoehring Sep 11, 2023
4c35430
Add tests
DanielDoehring Sep 11, 2023
21d29f8
remove plots
DanielDoehring Sep 11, 2023
29bd213
Format
DanielDoehring Sep 11, 2023
cb3eac8
remove redundant line
DanielDoehring Sep 11, 2023
1bb2982
look into p4est amr parabolic
DanielDoehring Sep 11, 2023
7e68d94
platform independent tests
DanielDoehring Sep 11, 2023
108bf05
Working on mortars for parabolic p4est
DanielDoehring Sep 12, 2023
0517687
print analysis every step
DanielDoehring Sep 12, 2023
0eadf49
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 12, 2023
5c20c4f
No need for different flux_viscous comps after adding container_visco…
DanielDoehring Sep 12, 2023
a0b6e3a
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Sep 12, 2023
21ccff4
Laplace 3d
DanielDoehring Sep 12, 2023
06a7811
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 15, 2023
591132b
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 18, 2023
d3b3e85
coarsen also for p4est mesh
DanielDoehring Sep 18, 2023
e868184
Eliminate unused stuff
DanielDoehring Sep 19, 2023
d1b8316
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
07cf0ba
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
8df117b
Longer times to allow converage to hit coarsen!
DanielDoehring Sep 20, 2023
ff77769
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Sep 20, 2023
cdaa865
Increase testing of Laplace 3D
DanielDoehring Sep 20, 2023
4699a10
Add tests for velocities
DanielDoehring Sep 20, 2023
306c9b0
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 20, 2023
0129b5e
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 22, 2023
ac1c1ca
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Sep 22, 2023
59800cf
Continue working on AMR p4est 2d
DanielDoehring Oct 2, 2023
5f0051c
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 4, 2023
bb4b778
Note possible remedy for paraboic p4est mortars
DanielDoehring Oct 5, 2023
389d89c
remove comment
DanielDoehring Oct 5, 2023
03be339
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 5, 2023
6b6d5e3
remove some comments
DanielDoehring Oct 5, 2023
1d4486a
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 5, 2023
5fe10b0
clean up attempts
DanielDoehring Oct 6, 2023
e6ac2d4
Merge remote-tracking branch 'DanielDoehring/AMR_Parabolic_2D3D_Tree'…
jlchan Oct 6, 2023
f86121f
add elixir for amr testing
jlchan Oct 6, 2023
27afc2d
adding commented out mortar routines in 2D
jlchan Oct 6, 2023
7943167
Adding Mortar to 2d dg parabolic term
apey236 Oct 6, 2023
a8173c7
remove testing snippet
jlchan Oct 7, 2023
5f4e8f3
fix comments
jlchan Oct 7, 2023
113bce5
add more arguments for dispatch
jlchan Oct 7, 2023
53c5c68
add some temporary todo notes
jlchan Oct 7, 2023
4c2ed6c
some updates for AP and KS
jlchan Oct 7, 2023
39cc7b8
specialize mortar_fluxes_to_elements
jlchan Oct 7, 2023
e33bcfa
BUGFIX: apply_jacobian_parabolic! was incorrect for P4estMesh
jlchan Oct 7, 2023
0ee3d3e
fixed rhs_parabolic! for mortars
jlchan Oct 7, 2023
2e23b36
more changes to elixir
jlchan Oct 7, 2023
e089803
indexing bug
jlchan Oct 7, 2023
5b4c4da
comments
jlchan Oct 7, 2023
3b58ee5
Merge branch 'main' into jc/amr_parabolic_p4est
jlchan Oct 9, 2023
41770d7
Adding the example for nonperiodic BCs with amr
apey236 Oct 9, 2023
00a460a
hopefully this fixes AMR boundaries for parabolic terms
jlchan Oct 9, 2023
6f46507
add elixir
jlchan Oct 9, 2023
2c7fdd8
Example with non periodic bopundary conditions
apey236 Oct 9, 2023
d0afe4a
remove cruft
jlchan Oct 9, 2023
333b136
Merge remote-tracking branch 'jlchan/jc/amr_parabolic_p4est' into jc/…
jlchan Oct 9, 2023
7e1dc7d
Merge branch 'main' into jc/amr_parabolic_p4est
jlchan Oct 12, 2023
c9bd910
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Oct 25, 2023
26dd055
Merge remote-tracking branch 'TrixiJesse/jc/amr_parabolic_p4est' into…
DanielDoehring Oct 25, 2023
355178a
clean up merge nonsense
DanielDoehring Oct 25, 2023
984e72e
restore examples
DanielDoehring Oct 25, 2023
666e9ed
restore project
DanielDoehring Oct 25, 2023
d4dc22c
restore
DanielDoehring Oct 25, 2023
ba0335e
more similar
DanielDoehring Oct 25, 2023
343ff7c
more similar to standard case
DanielDoehring Oct 25, 2023
5f550ef
correct amr file
DanielDoehring Oct 25, 2023
fe7d7cd
delete doubled tests
DanielDoehring Oct 25, 2023
bdebd64
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Oct 25, 2023
345391c
remove unused
DanielDoehring Oct 25, 2023
6a60d41
Merge branch 'AMR_Parabolic_P4est' of github.com:DanielDoehring/Trixi…
DanielDoehring Oct 25, 2023
d683ffe
remove duplicate test
DanielDoehring Oct 25, 2023
f74153b
format
DanielDoehring Oct 25, 2023
69916db
BCs are not periodic
DanielDoehring Oct 25, 2023
b94a38c
Merge branch 'main' into AMR_Parabolic_P4est
jlchan Oct 31, 2023
b9d0c4a
Merge branch 'main' into AMR_Parabolic_P4est
jlchan Oct 31, 2023
dc0aa9a
straighten examples, provide tests
DanielDoehring Nov 2, 2023
5d8d7bc
format
DanielDoehring Nov 2, 2023
0ddebfb
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 2, 2023
5b2d224
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 3, 2023
b7e61db
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 3, 2023
2c1f309
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 10, 2023
03c117c
fmt
DanielDoehring Nov 10, 2023
40214a6
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 11, 2023
b10775d
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 12, 2023
be878f9
reduce test time intervals
DanielDoehring Nov 12, 2023
519b878
Merge branch 'AMR_Parabolic_P4est' of github.com:DanielDoehring/Trixi…
DanielDoehring Nov 12, 2023
d27f401
shorten test
DanielDoehring Nov 12, 2023
3ac9f6d
test vals updated ode
DanielDoehring Nov 12, 2023
4f41ae6
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 13, 2023
2f95483
Merge branch 'main' into AMR_Parabolic_P4est
jlchan Nov 13, 2023
4c4d6a3
cache_parabolic does not require mortars
DanielDoehring Nov 16, 2023
cf606ff
Merge branch 'AMR_Parabolic_P4est' of github.com:DanielDoehring/Trixi…
DanielDoehring Nov 16, 2023
3d405ac
add couple comments
DanielDoehring Nov 16, 2023
69f3e6c
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 16, 2023
c7c55d8
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 16, 2023
76d0cf5
Update src/callbacks_step/amr.jl
DanielDoehring Nov 16, 2023
65c2aff
Update src/callbacks_step/amr.jl
DanielDoehring Nov 16, 2023
530e65e
Update src/solvers/dgsem_p4est/dg_2d_parabolic.jl
DanielDoehring Nov 16, 2023
f1ccb1b
Update src/solvers/dgsem_p4est/dg_2d_parabolic.jl
DanielDoehring Nov 16, 2023
b5b62f6
Update src/solvers/dgsem_p4est/dg_2d_parabolic.jl
DanielDoehring Nov 16, 2023
6ea1f10
Update src/solvers/dgsem_p4est/dg_2d_parabolic.jl
DanielDoehring Nov 16, 2023
4fc3468
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 17, 2023
fe05645
fmt
DanielDoehring Nov 17, 2023
88246cc
add news entry
DanielDoehring Nov 17, 2023
c9f8ea0
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 17, 2023
5df7755
Update src/callbacks_step/amr.jl
jlchan Nov 17, 2023
4f9c269
Merge branch 'main' into AMR_Parabolic_P4est
DanielDoehring Nov 18, 2023
f40412a
typo
DanielDoehring Nov 20, 2023
7327cc5
Merge branch 'main' into AMR_Parabolic_P4est
ranocha Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the linear advection-diffusion equation

diffusivity() = 5.0e-2
advection_velocity = (1.0, 0.0)
equations = LinearScalarAdvectionEquation2D(advection_velocity)
equations_parabolic = LaplaceDiffusion2D(diffusivity(), equations)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -0.5) # minimum coordinates (min(x), min(y))
coordinates_max = (0.0, 0.5) # maximum coordinates (max(x), max(y))

trees_per_dimension = (4, 4)
mesh = P4estMesh(trees_per_dimension,
polydeg = 3, initial_refinement_level = 2,
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
periodicity = false)

# Example setup taken from
# - Truman Ellis, Jesse Chan, and Leszek Demkowicz (2016).
# Robust DPG methods for transient convection-diffusion.
# In: Building bridges: connections and challenges in modern approaches
# to numerical partial differential equations.
# [DOI](https://doi.org/10.1007/978-3-319-41640-3_6).
function initial_condition_eriksson_johnson(x, t, equations)
l = 4
epsilon = diffusivity() # TODO: this requires epsilon < .6 due to sqrt
lambda_1 = (-1 + sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
lambda_2 = (-1 - sqrt(1 - 4 * epsilon * l)) / (-2 * epsilon)
r1 = (1 + sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
s1 = (1 - sqrt(1 + 4 * pi^2 * epsilon^2)) / (2 * epsilon)
u = exp(-l * t) * (exp(lambda_1 * x[1]) - exp(lambda_2 * x[1])) +
cos(pi * x[2]) * (exp(s1 * x[1]) - exp(r1 * x[1])) / (exp(-s1) - exp(-r1))
return SVector{1}(u)
end
initial_condition = initial_condition_eriksson_johnson

boundary_conditions = Dict(:x_neg => BoundaryConditionDirichlet(initial_condition),
:y_neg => BoundaryConditionDirichlet(initial_condition),
:y_pos => BoundaryConditionDirichlet(initial_condition),
:x_pos => boundary_condition_do_nothing)

boundary_conditions_parabolic = Dict(:x_neg => BoundaryConditionDirichlet(initial_condition),
:x_pos => BoundaryConditionDirichlet(initial_condition),
:y_neg => BoundaryConditionDirichlet(initial_condition),
:y_pos => BoundaryConditionDirichlet(initial_condition))

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolicParabolic(mesh,
(equations, equations_parabolic),
initial_condition, solver;
boundary_conditions = (boundary_conditions,
boundary_conditions_parabolic))

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span `tspan`
tspan = (0.0, 0.5)
ode = semidiscretize(semi, tspan)

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_interval = 1000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

# The AliveCallback prints short status information in regular intervals
alive_callback = AliveCallback(analysis_interval = analysis_interval)

amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
base_level = 1,
med_level = 2, med_threshold = 0.9,
max_level = 3, max_threshold = 1.0)

amr_callback = AMRCallback(semi, amr_controller,
interval = 50)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, amr_callback)

###############################################################################
# run the simulation

# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
time_int_tol = 1.0e-11
sol = solve(ode, dt = 1e-7, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
ode_default_options()..., callback = callbacks)

# Print the timer summary
summary_callback()
83 changes: 83 additions & 0 deletions examples/p4est_2d_dgsem/elixir_advection_diffusion_periodic_amr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the linear advection-diffusion equation

advection_velocity = (1.5, 1.0)
equations = LinearScalarAdvectionEquation2D(advection_velocity)
diffusivity() = 5.0e-2
equations_parabolic = LaplaceDiffusion2D(diffusivity(), equations)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))

trees_per_dimension = (4, 4)
mesh = P4estMesh(trees_per_dimension,
polydeg = 3, initial_refinement_level = 1,
coordinates_min = coordinates_min, coordinates_max = coordinates_max)

# Define initial condition
function initial_condition_diffusive_convergence_test(x, t,
equation::LinearScalarAdvectionEquation2D)
# Store translated coordinate for easy use of exact solution
x_trans = x - equation.advection_velocity * t

nu = diffusivity()
c = 1.0
A = 0.5
L = 2
f = 1 / L
omega = 2 * pi * f
scalar = c + A * sin(omega * sum(x_trans)) * exp(-2 * nu * omega^2 * t)
return SVector(scalar)
end
initial_condition = initial_condition_diffusive_convergence_test

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolicParabolic(mesh,
(equations, equations_parabolic),
initial_condition, solver)

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span `tspan`
tspan = (0.0, 0.5)
ode = semidiscretize(semi, tspan);

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

# The AliveCallback prints short status information in regular intervals
alive_callback = AliveCallback(analysis_interval = analysis_interval)

amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
base_level = 1,
med_level = 2, med_threshold = 1.25,
max_level = 3, max_threshold = 1.45)

amr_callback = AMRCallback(semi, amr_controller,
interval = 20)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, amr_callback)

###############################################################################
# run the simulation

# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
time_int_tol = 1.0e-11
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
ode_default_options()..., callback = callbacks)

# Print the timer summary
summary_callback()
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ heat_bc = Adiabatic((x, t, equations) -> 0.0)
boundary_condition_lid = BoundaryConditionNavierStokesWall(velocity_bc_lid, heat_bc)
boundary_condition_cavity = BoundaryConditionNavierStokesWall(velocity_bc_cavity, heat_bc)

# define periodic boundary conditions everywhere
boundary_conditions = Dict(:x_neg => boundary_condition_slip_wall,
:y_neg => boundary_condition_slip_wall,
:y_pos => boundary_condition_slip_wall,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the ideal compressible Navier-Stokes equations

# TODO: parabolic; unify names of these accessor functions
prandtl_number() = 0.72
mu() = 0.001

equations = CompressibleEulerEquations2D(1.4)
equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu = mu(),
Prandtl = prandtl_number())

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))

# Create a uniformly refined mesh
trees_per_dimension = (6, 6)
mesh = P4estMesh(trees_per_dimension,
polydeg = 3, initial_refinement_level = 2,
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
periodicity = (false, false))

function initial_condition_cavity(x, t, equations::CompressibleEulerEquations2D)
Ma = 0.1
rho = 1.0
u, v = 0.0, 0.0
p = 1.0 / (Ma^2 * equations.gamma)
return prim2cons(SVector(rho, u, v, p), equations)
end
initial_condition = initial_condition_cavity

# BC types
velocity_bc_lid = NoSlip((x, t, equations) -> SVector(1.0, 0.0))
velocity_bc_cavity = NoSlip((x, t, equations) -> SVector(0.0, 0.0))
heat_bc = Adiabatic((x, t, equations) -> 0.0)
boundary_condition_lid = BoundaryConditionNavierStokesWall(velocity_bc_lid, heat_bc)
boundary_condition_cavity = BoundaryConditionNavierStokesWall(velocity_bc_cavity, heat_bc)

boundary_conditions = Dict(:x_neg => boundary_condition_slip_wall,
:y_neg => boundary_condition_slip_wall,
:y_pos => boundary_condition_slip_wall,
:x_pos => boundary_condition_slip_wall)

boundary_conditions_parabolic = Dict(:x_neg => boundary_condition_cavity,
:y_neg => boundary_condition_cavity,
:y_pos => boundary_condition_lid,
:x_pos => boundary_condition_cavity)

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
initial_condition, solver;
boundary_conditions = (boundary_conditions,
boundary_conditions_parabolic))

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span `tspan`
tspan = (0.0, 25.0)
ode = semidiscretize(semi, tspan);

summary_callback = SummaryCallback()
alive_callback = AliveCallback(alive_interval = 2000)
analysis_interval = 2000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

amr_indicator = IndicatorLöhner(semi, variable = Trixi.density)

amr_controller = ControllerThreeLevel(semi, amr_indicator,
base_level = 0,
med_level = 1, med_threshold = 0.005,
max_level = 2, max_threshold = 0.01)

amr_callback = AMRCallback(semi, amr_controller,
interval = 50,
adapt_initial_condition = true,
adapt_initial_condition_only_refine = true)

callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback, amr_callback)
# callbacks = CallbackSet(summary_callback, alive_callback)

###############################################################################
# run the simulation

time_int_tol = 1e-8
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
ode_default_options()..., callback = callbacks)

summary_callback() # print the timer summary
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ heat_bc = Adiabatic((x, t, equations) -> 0.0)
boundary_condition_lid = BoundaryConditionNavierStokesWall(velocity_bc_lid, heat_bc)
boundary_condition_cavity = BoundaryConditionNavierStokesWall(velocity_bc_cavity, heat_bc)

# define periodic boundary conditions everywhere
boundary_conditions = boundary_condition_slip_wall

boundary_conditions_parabolic = (; x_neg = boundary_condition_cavity,
Expand Down
97 changes: 97 additions & 0 deletions src/callbacks_step/amr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,103 @@ function copy_to_quad_iter_volume(info, user_data)
return nothing
end

# specialized callback which includes the `cache_parabolic` argument
function (amr_callback::AMRCallback)(u_ode::AbstractVector, mesh::P4estMesh,
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
equations, dg::DG, cache, cache_parabolic,
semi,
t, iter;
only_refine = false, only_coarsen = false,
passive_args = ())
@unpack controller, adaptor = amr_callback

u = wrap_array(u_ode, mesh, equations, dg, cache)
lambda = @trixi_timeit timer() "indicator" controller(u, mesh, equations, dg, cache,
t = t, iter = iter)

@boundscheck begin
@assert axes(lambda)==(Base.OneTo(ncells(mesh)),) ("Indicator array (axes = $(axes(lambda))) and mesh cells (axes = $(Base.OneTo(ncells(mesh)))) have different axes")
end

# Copy controller value of each quad to the quad's user data storage
iter_volume_c = cfunction(copy_to_quad_iter_volume, Val(ndims(mesh)))

# The pointer to lambda will be interpreted as Ptr{Int} above
jlchan marked this conversation as resolved.
Show resolved Hide resolved
@assert lambda isa Vector{Int}
iterate_p4est(mesh.p4est, lambda; iter_volume_c = iter_volume_c)

@trixi_timeit timer() "refine" if !only_coarsen
# Refine mesh
refined_original_cells = @trixi_timeit timer() "mesh" refine!(mesh)

# Refine solver
@trixi_timeit timer() "solver" refine!(u_ode, adaptor, mesh, equations, dg,
cache, cache_parabolic,
refined_original_cells)
for (p_u_ode, p_mesh, p_equations, p_dg, p_cache) in passive_args
@trixi_timeit timer() "passive solver" refine!(p_u_ode, adaptor, p_mesh,
p_equations,
p_dg, p_cache,
refined_original_cells)
end
else
# If there is nothing to refine, create empty array for later use
refined_original_cells = Int[]
end

@trixi_timeit timer() "coarsen" if !only_refine
# Coarsen mesh
coarsened_original_cells = @trixi_timeit timer() "mesh" coarsen!(mesh)

# coarsen solver
@trixi_timeit timer() "solver" coarsen!(u_ode, adaptor, mesh, equations, dg,
cache, cache_parabolic,
coarsened_original_cells)
for (p_u_ode, p_mesh, p_equations, p_dg, p_cache) in passive_args
@trixi_timeit timer() "passive solver" coarsen!(p_u_ode, adaptor, p_mesh,
p_equations,
p_dg, p_cache,
coarsened_original_cells)
end
else
# If there is nothing to coarsen, create empty array for later use
coarsened_original_cells = Int[]
end
jlchan marked this conversation as resolved.
Show resolved Hide resolved

# Store whether there were any cells coarsened or refined and perform load balancing
has_changed = !isempty(refined_original_cells) || !isempty(coarsened_original_cells)
# Check if mesh changed on other processes
if mpi_isparallel()
has_changed = MPI.Allreduce!(Ref(has_changed), |, mpi_comm())[]
end

if has_changed # TODO: Taal decide, where shall we set this?
# don't set it to has_changed since there can be changes from earlier calls
mesh.unsaved_changes = true

if mpi_isparallel() && amr_callback.dynamic_load_balancing
@trixi_timeit timer() "dynamic load balancing" begin
global_first_quadrant = unsafe_wrap(Array,
unsafe_load(mesh.p4est).global_first_quadrant,
mpi_nranks() + 1)
old_global_first_quadrant = copy(global_first_quadrant)
partition!(mesh)
rebalance_solver!(u_ode, mesh, equations, dg, cache,
old_global_first_quadrant)
end
end

reinitialize_boundaries!(semi.boundary_conditions, cache)
# if the semidiscretization also stores parabolic boundary conditions,
# reinitialize them after each refinement step as well.
if hasproperty(semi, :boundary_conditions_parabolic)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
reinitialize_boundaries!(semi.boundary_conditions_parabolic, cache)
end
end

# Return true if there were any cells coarsened or refined, otherwise false
return has_changed
end

# 2D
function cfunction(::typeof(copy_to_quad_iter_volume), ::Val{2})
@cfunction(copy_to_quad_iter_volume, Cvoid,
Expand Down
Loading