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

Parabolic mortars for P4estMesh #1662

Draft
wants to merge 92 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
92 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
7e68d94
platform independent tests
DanielDoehring Sep 11, 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
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
5f0051c
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
jlchan Oct 4, 2023
389d89c
remove comment
DanielDoehring Oct 5, 2023
03be339
Merge branch 'AMR_Parabolic_2D3D_Tree' of github.com:DanielDoehring/T…
DanielDoehring Oct 5, 2023
1d4486a
Merge branch 'main' into AMR_Parabolic_2D3D_Tree
DanielDoehring Oct 5, 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
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
117 changes: 117 additions & 0 deletions examples/p4est_2d_dgsem/elixir_advection_diffusion_nonperiodic_amr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using OrdinaryDiffEq, Plots
using Trixi

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

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

# Define initial condition (copied from "examples/tree_1d_dgsem/elixir_advection_diffusion.jl")
function initial_condition_bubble(x, t, equation)
return SVector((x[1]-pi) * (x[2]-pi) * (x[1]+pi) * (x[2]+pi))
end

initial_condition = initial_condition_bubble

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))

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

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

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

# 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, .5)
ode = semidiscretize(semi, tspan)

# u = sol.u[end]

# du = similar(u)
# Trixi.rhs_parabolic!(du, u, semi, 0.0)

# x, y = [semi.cache.elements.node_coordinates[i, :, :, :] for i in 1:2]
# for i in eachindex(x)
# u[i] = initial_condition_bubble((x[i], y[i]), 0.0, equations)[1]
# end
# u = Trixi.wrap_array(u, semi)
# fill!(cache_parabolic.elements.surface_flux_values, NaN);
# dg = solver
# parabolic_scheme = semi.solver_parabolic
# t = 0.0
# (; cache, cache_parabolic, boundary_conditions_parabolic) = semi
# @unpack viscous_container = cache_parabolic
# @unpack u_transformed, gradients, flux_viscous = viscous_container

# Trixi.transform_variables!(u_transformed, u, mesh, equations_parabolic,
# dg, parabolic_scheme, cache, cache_parabolic)

# Trixi.calc_gradient!(gradients, u_transformed, t, mesh, equations_parabolic,
# boundary_conditions_parabolic, dg, cache, cache_parabolic)

# grad_x, grad_y = gradients
# @show any(isnan.(grad_x))
# @show any(isnan.(grad_y))

# 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=0.5,
max_level=3, max_threshold=0.75)

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

# 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()
plot(sol)
# pd = PlotData2D(sol)
# plot!(getmesh(pd))

101 changes: 101 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,101 @@
using OrdinaryDiffEq, Plots
using Trixi

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

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

function x_trans_periodic(x, domain_length=SVector(2 * pi), center=SVector(0.0))
x_normalized = x .- center
x_shifted = x_normalized .% domain_length
x_offset = ((x_shifted .< -0.5 * domain_length) - (x_shifted .> 0.5 * domain_length)) .* domain_length
return center + x_shifted + x_offset
end

# Define initial condition (copied from "examples/tree_1d_dgsem/elixir_advection_diffusion.jl")
function initial_condition_diffusive_convergence_test(x, t, equation::LinearScalarAdvectionEquation2D)
# Store translated coordinate for easy use of exact solution
# Assumes that advection_velocity[2] = 0 (effectively that we are solving a 1D equation)
x_trans = x_trans_periodic(x[2] - equation.advection_velocity[2] * t)
# y_trans = x_trans_periodic(x[1] - equation.advection_velocity[1] * t)

nu = diffusivity()
c = 0.0
A = 1.0
omega = 1.0
scalar = c + A * sin(omega * (sum(x_trans))) * exp(-nu * omega^2 * t)
return SVector(scalar)
end

# Define initial condition (copied from "examples/tree_1d_dgsem/elixir_advection_diffusion.jl")
function initial_condition_new_test(x, t, equation::LinearScalarAdvectionEquation2D)
return SVector(2 * x[1] + x[2] > 0)
end
# initial_condition = initial_condition_diffusive_convergence_test
initial_condition = initial_condition_new_test

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

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

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

# 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, 1.0)
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=2,
med_level=3, med_threshold=0.5,
max_level=4, max_threshold=0.75)

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

# 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)
# sol = solve(ode, ROCK4(eigen_est=eigen_est); abstol=time_int_tol, reltol=time_int_tol,
# ode_default_options()..., callback=callbacks)
# Print the timer summary
summary_callback()
plot(sol)
pd = PlotData2D(sol)
plot!(getmesh(pd))

102 changes: 102 additions & 0 deletions examples/p4est_2d_dgsem/elixir_navierstokes_lid_driven_cavity_amr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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.5
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)

# 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,
: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))

# semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
# initial_condition, solver;)

###############################################################################
# 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=100)
analysis_interval = 100
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.02,
max_level=3, max_threshold=0.05)

amr_callback = AMRCallback(semi, amr_controller,
interval=5,
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


pd = PlotData2D(sol)
plot(pd["rho"])
plot!(getmesh(pd))
Loading
Loading