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 terms for DGMulti #1136

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
7d3925b
minor formatting
jlchan May 17, 2022
96e16ed
adding multi-term semidiscretization
jlchan May 19, 2022
d320529
fixing bug and adding test
jlchan May 19, 2022
84006ba
changing name
jlchan May 20, 2022
93c718e
changing name, importing SplitODEFunction
jlchan May 20, 2022
c4feca7
Merge branch 'main' into jc/semidiscretization_hyperbolic_parabolic
jlchan May 20, 2022
7dc7b2d
fixing test by adding norm
jlchan May 20, 2022
1772269
trying another test fix
jlchan May 21, 2022
fae867b
adding norm back
jlchan May 21, 2022
cd16b36
adjusting tol
jlchan May 21, 2022
d6690ba
try to fix test again
jlchan May 21, 2022
fe0203a
syntax error
jlchan May 21, 2022
64e6ebf
removing norm frm test
jlchan May 21, 2022
dd60ebf
adding cache to parabolic terms (enable reuse of inviscid cache)
jlchan May 22, 2022
c141fc1
generalize dgmulti iterators
jlchan May 22, 2022
943450f
fix typo
jlchan May 22, 2022
093f27f
generalizing reset_du! for dgmulti
jlchan May 22, 2022
ace2ce1
WIP gradient and divergence computations
jlchan May 22, 2022
9133d84
fix name
jlchan May 22, 2022
ade76e3
more generalization
jlchan May 22, 2022
54a4b7e
divergence + remove repeated code
jlchan May 22, 2022
681c818
adding cache
jlchan May 22, 2022
421a317
remove test
jlchan May 22, 2022
d0d7083
update diffusion test
jlchan May 22, 2022
a9fde8a
update diffusion rhs
jlchan May 22, 2022
827defb
moving routines around
jlchan May 22, 2022
a0a4b8b
fix multiple includes
jlchan May 22, 2022
f4f181e
removing time dependence for now from viscous rhs
jlchan May 23, 2022
333bed3
export ScalarDiffusion2D
jlchan May 23, 2022
2a1a6b4
fix test
jlchan May 23, 2022
a909b54
working periodic advection RHS
jlchan May 23, 2022
3316fab
cleanup and comments
jlchan May 23, 2022
3fe88d7
making periodic advection-diffusion example
jlchan May 23, 2022
341de95
trim whitespace
jlchan May 23, 2022
fbf27c3
adding t back in to parabolic rhs
jlchan May 23, 2022
b4bf34a
refactoring boundary condition code
jlchan May 23, 2022
5f35752
update elixir with BCs
jlchan May 23, 2022
00cdd2b
change default DGMulti interface flux behavior
jlchan May 23, 2022
2083bb2
cleanup
jlchan May 23, 2022
695e779
renaming variables
jlchan May 23, 2022
e556cde
BC prepping
jlchan May 23, 2022
3edb18c
cleanup of elixir
jlchan May 23, 2022
455974a
more name fixing
jlchan May 23, 2022
fd2489e
Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl
jlchan May 23, 2022
1d9e71b
Merge branch 'main' into jc/semidiscretization_hyperbolic_parabolic
jlchan May 23, 2022
4ef7835
adding Neumann BCs
jlchan May 23, 2022
48a715a
switching to weak form
jlchan May 23, 2022
45d2141
fixing cache variable names
jlchan May 23, 2022
bbba3ba
simplified parabolic boundary flux treatement
jlchan May 23, 2022
8a11d57
updated elixir with different types of BCs
jlchan May 23, 2022
478e831
Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl
jlchan May 24, 2022
cffc139
Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl
jlchan May 24, 2022
924a5b9
Update src/equations/equations.jl
jlchan May 24, 2022
0a0d7c1
Merge remote-tracking branch 'Trixi_fork/jc/semidiscretization_hyperb…
jlchan May 24, 2022
f7a0284
rhs! -> rhs_parabolic!
jlchan May 25, 2022
3a799f5
move Gradient/Divergence types
jlchan May 25, 2022
a957094
add "no boundary condition" BC
jlchan May 25, 2022
2e5146c
rename ScalarDiffusion -> LaplaceDiffusion
jlchan May 25, 2022
2c45293
rhs -> rhs_parabolic! again
jlchan May 25, 2022
7159af3
comments
jlchan May 25, 2022
d2cccd0
moving tests around
jlchan May 25, 2022
b73eb74
scalarDiffusion -> LaplaceDiffusion
jlchan May 25, 2022
363f805
tuple-based constructor
jlchan May 25, 2022
3d30e54
updating examples
jlchan May 25, 2022
29f81e5
add ScalarPlotData2D docstring (#1145)
jlchan May 26, 2022
ff0c954
Merge remote-tracking branch 'origin/main' into jc/semidiscretization…
jlchan May 27, 2022
19910cb
Apply suggestions from code review
jlchan May 27, 2022
e8c9afb
Merge remote-tracking branch 'Trixi_fork/jc/semidiscretization_hyperb…
jlchan May 27, 2022
3ab3162
renaming for consistency
jlchan May 27, 2022
a61648e
move Neumann BCs into equations.jl
jlchan May 27, 2022
b4d7f60
renaming, e.g., ParabolicEquations -> EquationsParabolic, etc
jlchan May 27, 2022
a49635e
rename test module
jlchan May 27, 2022
3573cae
generalize LaplaceDiffusion2D to any number of variables
jlchan May 27, 2022
8bb3a73
removing saveat times and standardizing `tol` names
jlchan May 27, 2022
26bbaba
parabolic_cache -> cache_parabolic
jlchan May 27, 2022
24eb1b3
renaming `create_cache` -> `create_cache_parabolic`
jlchan May 27, 2022
05c8b0c
Update examples/dgmulti_2d/elixir_advection_diffusion.jl
jlchan May 27, 2022
4f1d3e0
Update src/equations/equations.jl
jlchan May 27, 2022
d5e032c
Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl
jlchan May 27, 2022
270f7ce
parabolic_boundary_conditions -> boundary_conditions_parabolic
jlchan May 27, 2022
822425a
Update src/semidiscretization/semidiscretization_hyperbolic_parabolic.jl
jlchan May 27, 2022
bd14aa6
Merge remote-tracking branch 'Trixi_fork/jc/semidiscretization_hyperb…
jlchan May 27, 2022
8986d5c
add equations as field to LaplaceDiffusion2D
jlchan May 27, 2022
4c3a7ed
moving Neumann BCs into equations.jl and adding default BC behavior
jlchan May 27, 2022
a4a4b44
running parabolic tests, adding integration test
jlchan May 27, 2022
41b3480
adding parabolic tests to ci
jlchan May 27, 2022
f0beee8
missing comma
jlchan May 27, 2022
696ebc4
Update src/equations/laplace_diffusion_2d.jl
jlchan May 27, 2022
5bfa918
fix test
jlchan May 27, 2022
e5b9533
Merge remote-tracking branch 'Trixi_fork/jc/semidiscretization_hyperb…
jlchan May 27, 2022
3bf4357
fix test typo
jlchan May 27, 2022
2267954
fix tests (for real this time)
jlchan May 27, 2022
63d67d7
improve test coverage
jlchan May 27, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
- p4est_part1
- p4est_part2
- unstructured_dgmulti
- parabolic
- paper_self_gravitating_gas_dynamics
- misc_part1
- misc_part2
Expand Down
30 changes: 14 additions & 16 deletions examples/dgmulti_2d/elixir_advection_diffusion.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@

using Trixi, OrdinaryDiffEq

dg = DGMulti(polydeg = 3, element_type = Tri(), approximation_type = Polynomial(),
surface_integral = SurfaceIntegralWeakForm(flux_lax_friedrichs),
volume_integral = VolumeIntegralWeakForm())

equations = LinearScalarAdvectionEquation2D(1.5, 1.0)
parabolic_equations = LaplaceDiffusion2D(5e-2)
equations_parabolic = LaplaceDiffusion2D(5e-2, equations)

initial_condition_zero(x, t, equations::LinearScalarAdvectionEquation2D) = SVector(0.0)
initial_condition = initial_condition_zero

# tag different boundary segments
left(x, tol=50*eps()) = abs(x[1]+1)<tol
right(x, tol=50*eps()) = abs(x[1]-1)<tol
bottom(x, tol=50*eps()) = abs(x[2]+1)<tol
top(x, tol=50*eps()) = abs(x[2]-1)<tol
left(x, tol=50*eps()) = abs(x[1] + 1) < tol
right(x, tol=50*eps()) = abs(x[1] - 1) < tol
bottom(x, tol=50*eps()) = abs(x[2] + 1) < tol
top(x, tol=50*eps()) = abs(x[2] - 1) < tol
is_on_boundary = Dict(:left => left, :right => right, :top => top, :bottom => bottom)
mesh = DGMultiMesh(dg, cells_per_dimension=(16, 16); is_on_boundary)

# BC types
boundary_condition_left = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 + .1 * x[2]))
boundary_condition_left = BoundaryConditionDirichlet((x, t, equations) -> SVector(1 + 0.1 * x[2]))
boundary_condition_zero = BoundaryConditionDirichlet((x, t, equations) -> SVector(0.0))
boundary_condition_neumann_zero = BoundaryConditionNeumann((x, t, equations) -> SVector(0.0))

# define inviscid boundary conditions
boundary_conditions = (; :left => boundary_condition_left,
:bottom => boundary_condition_zero,
:top => no_boundary_condition,
:right => no_boundary_condition)
:top => boundary_condition_do_nothing,
:right => boundary_condition_do_nothing)

# define viscous boundary conditions
parabolic_boundary_conditions = (; :left => boundary_condition_left,
boundary_conditions_parabolic = (; :left => boundary_condition_left,
:bottom => boundary_condition_zero,
:top => boundary_condition_zero,
:right => boundary_condition_neumann_zero)

semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, parabolic_equations), initial_condition, dg;
boundary_conditions=(boundary_conditions, parabolic_boundary_conditions))
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic), initial_condition, dg;
boundary_conditions=(boundary_conditions, boundary_conditions_parabolic))

tspan = (0.0, 1.5)
ode = semidiscretize(semi, tspan)
Expand All @@ -49,8 +48,7 @@ callbacks = CallbackSet(summary_callback, alive_callback)
###############################################################################
# run the simulation

tol = 1e-6
tsave = LinRange(tspan..., 10)
sol = solve(ode, RDPK3SpFSAL49(), abstol=tol, reltol=tol, save_everystep=false,
saveat=tsave, callback=callbacks)
time_int_tol = 1e-6
sol = solve(ode, RDPK3SpFSAL49(), abstol=time_int_tol, reltol=time_int_tol,
save_everystep=false, callback=callbacks)
summary_callback() # print the timer summary
10 changes: 6 additions & 4 deletions examples/dgmulti_2d/elixir_advection_diffusion_periodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ dg = DGMulti(polydeg = 3, element_type = Tri(), approximation_type = Polynomial(
volume_integral = VolumeIntegralWeakForm())

equations = LinearScalarAdvectionEquation2D(1.0, 1.0)
parabolic_equations = LaplaceDiffusion2D(1e-2)
equations_parabolic = LaplaceDiffusion2D(1e-2, equations)

function initial_condition_sharp_gaussian(x, t, equations::LinearScalarAdvectionEquation2D)
return SVector(exp(-100 * (x[1]^2 + x[2]^2)))
end
initial_condition = initial_condition_sharp_gaussian

mesh = DGMultiMesh(dg, cells_per_dimension = (16, 16), periodicity=true)
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, parabolic_equations),
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
initial_condition, dg)

tspan = (0.0, 2.0)
Expand All @@ -29,6 +29,8 @@ callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback)
###############################################################################
# run the simulation

tol = 1e-6
sol = solve(ode, RDPK3SpFSAL49(), abstol=tol, reltol=tol, save_everystep=false, callback=callbacks)
time_int_tol = 1e-6
sol = solve(ode, RDPK3SpFSAL49(), abstol=time_int_tol, reltol=time_int_tol,
save_everystep=false, callback=callbacks)

summary_callback() # print the timer summary
9 changes: 4 additions & 5 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,10 @@ export AcousticPerturbationEquations2D,
HyperbolicDiffusionEquations1D, HyperbolicDiffusionEquations2D, HyperbolicDiffusionEquations3D,
LinearScalarAdvectionEquation1D, LinearScalarAdvectionEquation2D, LinearScalarAdvectionEquation3D,
InviscidBurgersEquation1D,
LaplaceDiffusion2D,
LatticeBoltzmannEquations2D, LatticeBoltzmannEquations3D,
ShallowWaterEquations1D, ShallowWaterEquations2D

export no_boundary_condition

export LaplaceDiffusion2D, BoundaryConditionNeumann

export flux, flux_central, flux_lax_friedrichs, flux_hll, flux_hllc, flux_hlle, flux_godunov,
flux_chandrashekar, flux_ranocha, flux_derigs_etal, flux_hindenlang_gassner,
flux_nonconservative_powell,
Expand All @@ -157,8 +154,10 @@ export initial_condition_constant,
initial_condition_density_wave,
initial_condition_weak_blast_wave

export boundary_condition_periodic,
export boundary_condition_do_nothing,
boundary_condition_periodic,
BoundaryConditionDirichlet,
BoundaryConditionNeumann,
boundary_condition_noslip_wall,
boundary_condition_slip_wall,
boundary_condition_wall
Expand Down
47 changes: 39 additions & 8 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,44 @@ end
return flux
end

# operator types used for dispatch on parabolic boundary fluxes
struct Gradient end
struct Divergence end

# Dirichlet-type boundary condition for use with parabolic equations.
@inline function (boundary_condition::BoundaryConditionDirichlet)(u_inner, normal::AbstractVector,
x, t, operator_type::Divergence,
equations)
return u_inner
end


"""
BoundaryConditionNeumann(boundary_normal_flux_function)

Similar to `BoundaryConditionDirichlet`, but creates a Neumann boundary condition for parabolic
equations that uses the function `boundary_normal_flux_function` to specify the values of the normal
flux at the boundary.
The passed boundary value function will be called with the same arguments as an initial condition function is called, i.e., as
```julia
boundary_normal_flux_function(x, t, equations)
```
where `x` specifies the coordinates, `t` is the current time, and `equation` is the corresponding system of equations.
"""
struct BoundaryConditionNeumann{B}
boundary_normal_flux_function::B
end

# specify default behavior for a Neumann BC is to evaluate the flux at the inner state
@inline function (boundary_condition::BoundaryConditionNeumann)(flux_inner, normal::AbstractVector,
x, t, operator_type::Gradient,
equations)
return flux_inner
end

# Imposing no boundary condition just evaluates the flux at the inner state.
@inline function no_boundary_condition(flux, other_args...)
return flux
@inline function boundary_condition_do_nothing(inner_flux_or_state, other_args...)
return inner_flux_or_state
end

# set sensible default values that may be overwritten by specific equations
Expand Down Expand Up @@ -333,14 +368,10 @@ include("lattice_boltzmann_3d.jl")
abstract type AbstractAcousticPerturbationEquations{NDIMS, NVARS} <: AbstractEquations{NDIMS, NVARS} end
include("acoustic_perturbation_2d.jl")

abstract type AbstractParabolicEquations{NDIMS, NVARS} <: AbstractEquations{NDIMS, NVARS} end

# operator types used for dispatch on parabolic boundary fluxes
struct Gradient end
struct Divergence end
abstract type AbstractEquationsParabolic{NDIMS, NVARS} <: AbstractEquations{NDIMS, NVARS} end

# Linear scalar diffusion for use in linear scalar advection-diffusion problems
abstract type AbstractLaplaceDiffusionEquations{NDIMS, NVARS} <: AbstractParabolicEquations{NDIMS, NVARS} end
abstract type AbstractLaplaceDiffusionEquations{NDIMS, NVARS} <: AbstractEquationsParabolic{NDIMS, NVARS} end
include("laplace_diffusion_2d.jl")

end # @muladd
34 changes: 11 additions & 23 deletions src/equations/laplace_diffusion_2d.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
@doc raw"""
LaplaceDiffusion2D{T} <: AbstractParabolicEquations{2, 1}
LaplaceDiffusion2D(diffusivity, equations)

`LaplaceDiffusion2D` represents a scalar diffusion term ``\nabla \cdot (\kappa\nabla u))``
applied to each solution component.
with diffusivity ``\kappa`` applied to each solution component defined by `equations`.

If `equations` is not specified, a scalar `LaplaceDiffusion2D` is returned.
jlchan marked this conversation as resolved.
Show resolved Hide resolved
"""
struct LaplaceDiffusion2D{T} <: AbstractLaplaceDiffusionEquations{2, 1}
struct LaplaceDiffusion2D{E, N, T} <: AbstractLaplaceDiffusionEquations{2, N}
diffusivity::T
equations::E
end

LaplaceDiffusion2D(diffusivity, equations) =
LaplaceDiffusion2D{typeof(equations), nvariables(equations), typeof(diffusivity)}(diffusivity, equations)

# no orientation specified since the flux is vector-valued
function flux(u, grad_u, equations::LaplaceDiffusion2D)
jlchan marked this conversation as resolved.
Show resolved Hide resolved
dudx, dudy = grad_u
return equations.diffusivity * dudx, equations.diffusivity * dudy
return SVector(equations.diffusivity * dudx, equations.diffusivity * dudy)
end

# Dirichlet-type boundary condition for use with a parabolic solver in weak form
Expand All @@ -21,26 +27,8 @@ end
return boundary_condition.boundary_value_function(x, t, equations)
end

@inline function (boundary_condition::BoundaryConditionDirichlet)(flux_inner, normal::AbstractVector,
x, t, operator_type::Divergence,
equations::LaplaceDiffusion2D)
return flux_inner
end

# `boundary_value_function` should have signature `boundary_value_function(x, t, equations)`
# For Neumann BCs, this corresponds to kappa * (∇u ⋅ n)
struct BoundaryConditionNeumann{B}
boundary_value_function::B
end

@inline function (boundary_condition::BoundaryConditionNeumann)(u_inner, normal::AbstractVector,
x, t, operator_type::Gradient,
equations::LaplaceDiffusion2D)
return u_inner
end

@inline function (boundary_condition::BoundaryConditionNeumann)(flux_inner, normal::AbstractVector,
x, t, operator_type::Divergence,
equations::LaplaceDiffusion2D)
return boundary_condition.boundary_value_function(x, t, equations)
return boundary_condition.boundary_normal_flux_function(x, t, equations)
end
Loading