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 73 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
55 changes: 55 additions & 0 deletions examples/dgmulti_2d/elixir_advection_diffusion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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)
equations_parabolic = LaplaceDiffusion2D(5e-2)

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
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 + 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 => boundary_condition_do_nothing,
:right => boundary_condition_do_nothing)

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

semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic), initial_condition, dg;
boundary_conditions=(boundary_conditions, parabolic_boundary_conditions))
jlchan marked this conversation as resolved.
Show resolved Hide resolved

tspan = (0.0, 1.5)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()
alive_callback = AliveCallback(alive_interval=10)
callbacks = CallbackSet(summary_callback, alive_callback)

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

time_int_tol = 1e-6
saveat = LinRange(tspan..., 10)
sol = solve(ode, RDPK3SpFSAL49(), abstol=time_int_tol, reltol=time_int_tol, save_everystep=false,
saveat=saveat, callback=callbacks)
summary_callback() # print the timer summary
34 changes: 34 additions & 0 deletions examples/dgmulti_2d/elixir_advection_diffusion_periodic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

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.0, 1.0)
equations_parabolic = LaplaceDiffusion2D(1e-2)

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, equations_parabolic),
initial_condition, dg)

tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()
alive_callback = AliveCallback(alive_interval=10)
analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval, uEltype=real(dg))
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)
summary_callback() # print the timer summary
11 changes: 9 additions & 2 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ using SparseArrays: AbstractSparseMatrix, AbstractSparseMatrixCSC, sparse, dropt
using Reexport: @reexport

using SciMLBase: CallbackSet, DiscreteCallback,
ODEProblem, ODESolution, ODEFunction
ODEProblem, ODESolution, ODEFunction,
SplitODEProblem
import SciMLBase: get_du, get_tmp_cache, u_modified!,
AbstractODEIntegrator, init, step!, check_error,
get_proposed_dt, set_proposed_dt!,
Expand Down Expand Up @@ -106,6 +107,7 @@ include("meshes/meshes.jl")
include("solvers/solvers.jl")
include("semidiscretization/semidiscretization.jl")
include("semidiscretization/semidiscretization_hyperbolic.jl")
include("semidiscretization/semidiscretization_hyperbolic_parabolic.jl")
include("semidiscretization/semidiscretization_euler_acoustics.jl")
include("callbacks_step/callbacks_step.jl")
include("callbacks_stage/callbacks_stage.jl")
Expand All @@ -128,6 +130,7 @@ export AcousticPerturbationEquations2D,
HyperbolicDiffusionEquations1D, HyperbolicDiffusionEquations2D, HyperbolicDiffusionEquations3D,
LinearScalarAdvectionEquation1D, LinearScalarAdvectionEquation2D, LinearScalarAdvectionEquation3D,
InviscidBurgersEquation1D,
LaplaceDiffusion2D,
LatticeBoltzmannEquations2D, LatticeBoltzmannEquations3D,
ShallowWaterEquations1D, ShallowWaterEquations2D

Expand All @@ -151,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 Expand Up @@ -185,6 +190,8 @@ export nelements, nnodes, nvariables,

export SemidiscretizationHyperbolic, semidiscretize, compute_coefficients, integrate

export SemidiscretizationHyperbolicParabolic

export SemidiscretizationEulerAcoustics

export SemidiscretizationEulerGravity, ParametersEulerGravity,
Expand Down
28 changes: 28 additions & 0 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ end
return flux
end

"""
BoundaryConditionNeumann(boundary_value_function)

Similar to `BoundaryConditionDirichlet`, but creates a Neumann boundary condition for parabolic
equations that uses the function `boundary_value_function` to specify the values 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_value_function(x, t, equations)
```
where `x` specifies the coordinates, `t` is the current time, and `equation` is the corresponding system of equations.
jlchan marked this conversation as resolved.
Show resolved Hide resolved
"""
struct BoundaryConditionNeumann{B}
boundary_value_function::B
end

# Imposing no boundary condition just evaluates the flux at the inner state.
@inline function boundary_condition_do_nothing(flux, other_args...)
return flux
end
jlchan marked this conversation as resolved.
Show resolved Hide resolved

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

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

# operator types used for dispatch on parabolic boundary fluxes
struct Gradient end
struct Divergence end
jlchan marked this conversation as resolved.
Show resolved Hide resolved

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

end # @muladd
53 changes: 53 additions & 0 deletions src/equations/laplace_diffusion_2d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@doc raw"""
LaplaceDiffusion2D(diffusivity, equations)

`LaplaceDiffusion2D` represents a scalar diffusion term ``\nabla \cdot (\kappa\nabla u))``
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{E, N, T} <: AbstractLaplaceDiffusionEquations{2, N}
diffusivity::T
equations::E
end

function LaplaceDiffusion2D(diffusivity, equations=nothing)
jlchan marked this conversation as resolved.
Show resolved Hide resolved
if equations isa AbstractEquations
nvars = nvariables(equations)
else # assume scalar diffusion if no equations are specified
nvars = 1
end
return LaplaceDiffusion2D{typeof(equations), nvars, typeof(diffusivity)}(diffusivity, equations)
end

# 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 SVector(equations.diffusivity * dudx, equations.diffusivity * dudy)
end

# Dirichlet-type boundary condition for use with a parabolic solver in weak form
@inline function (boundary_condition::BoundaryConditionDirichlet)(u_inner, normal::AbstractVector,
x, t, operator_type::Gradient,
equations::LaplaceDiffusion2D)
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


@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)
end
Loading