Skip to content

Commit

Permalink
add gradient variable type parameter to AbstractEquationsParabolic (#…
Browse files Browse the repository at this point in the history
…1409)

* add gradient variable type parameter

* fix parabolic literate test

* remove trailing comment

* remove unnecessary abstract type

* move gradient variable structs

* formatting

* fix dropped changes

* try to fix doc tests

* fixing navier stokes 1D

* formatting

* remove duplicate GradientVariablesPrimitive/Entropy definition

* update news
  • Loading branch information
jlchan authored and ranocha committed Nov 10, 2023
1 parent 49d3cd2 commit 443858f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ for human readability.
- Implementation of the quasi-1D shallow water equations
- Subcell positivity limiting support for conservative variables in 2D for `TreeMesh`
- AMR for hyperbolic-parabolic equations on 2D/3D `TreeMesh`
- Added `GradientVariables` type parameter to `AbstractEquationsParabolic`

#### Changed

Expand Down
11 changes: 9 additions & 2 deletions docs/literate/src/files/adding_new_parabolic_terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ equations_hyperbolic = LinearScalarAdvectionEquation2D(advection_velocity);
# `ConstantAnisotropicDiffusion2D` has a field for `equations_hyperbolic`. It is useful to have
# information about the hyperbolic system available to the parabolic part so that we can reuse
# functions defined for hyperbolic equations (such as `varnames`).

struct ConstantAnisotropicDiffusion2D{E, T} <: Trixi.AbstractEquationsParabolic{2, 1}
#
# The abstract type `Trixi.AbstractEquationsParabolic` has three parameters: `NDIMS` (the spatial dimension,
# e.g., 1D, 2D, or 3D), `NVARS` (the number of variables), and `GradientVariable`, which we set as
# `GradientVariablesConservative`. This indicates that the gradient should be taken with respect to the
# conservative variables (e.g., the same variables used in `equations_hyperbolic`). Users can also take
# the gradient with respect to a different set of variables; see, for example, the implementation of
# [`CompressibleNavierStokesDiffusion2D`](@ref), which can utilize either "primitive" or "entropy" variables.

struct ConstantAnisotropicDiffusion2D{E, T} <: Trixi.AbstractEquationsParabolic{2, 1, GradientVariablesConservative}
diffusivity::T
equations_hyperbolic::E
end
Expand Down
2 changes: 1 addition & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export LaplaceDiffusion1D, LaplaceDiffusion2D, LaplaceDiffusion3D,
CompressibleNavierStokesDiffusion1D, CompressibleNavierStokesDiffusion2D,
CompressibleNavierStokesDiffusion3D

export GradientVariablesPrimitive, GradientVariablesEntropy
export GradientVariablesConservative, GradientVariablesPrimitive, GradientVariablesEntropy

export flux, flux_central, flux_lax_friedrichs, flux_hll, flux_hllc, flux_hlle,
flux_godunov,
Expand Down
2 changes: 1 addition & 1 deletion src/equations/compressible_navier_stokes_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ w_2 = \frac{\rho v1}{p},\, w_3 = -\frac{\rho}{p}
struct CompressibleNavierStokesDiffusion1D{GradientVariables, RealT <: Real,
E <: AbstractCompressibleEulerEquations{1}
} <:
AbstractCompressibleNavierStokesDiffusion{1, 3}
AbstractCompressibleNavierStokesDiffusion{1, 3, GradientVariables}
# TODO: parabolic
# 1) For now save gamma and inv(gamma-1) again, but could potentially reuse them from the Euler equations
# 2) Add NGRADS as a type parameter here and in AbstractEquationsParabolic, add `ngradients(...)` accessor function
Expand Down
2 changes: 1 addition & 1 deletion src/equations/compressible_navier_stokes_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ w_2 = \frac{\rho v_1}{p},\, w_3 = \frac{\rho v_2}{p},\, w_4 = -\frac{\rho}{p}
struct CompressibleNavierStokesDiffusion2D{GradientVariables, RealT <: Real,
E <: AbstractCompressibleEulerEquations{2}
} <:
AbstractCompressibleNavierStokesDiffusion{2, 4}
AbstractCompressibleNavierStokesDiffusion{2, 4, GradientVariables}
# TODO: parabolic
# 1) For now save gamma and inv(gamma-1) again, but could potentially reuse them from the Euler equations
# 2) Add NGRADS as a type parameter here and in AbstractEquationsParabolic, add `ngradients(...)` accessor function
Expand Down
2 changes: 1 addition & 1 deletion src/equations/compressible_navier_stokes_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ w_2 = \frac{\rho v_1}{p},\, w_3 = \frac{\rho v_2}{p},\, w_4 = \frac{\rho v_3}{p}
struct CompressibleNavierStokesDiffusion3D{GradientVariables, RealT <: Real,
E <: AbstractCompressibleEulerEquations{3}
} <:
AbstractCompressibleNavierStokesDiffusion{3, 5}
AbstractCompressibleNavierStokesDiffusion{3, 5, GradientVariables}
# TODO: parabolic
# 1) For now save gamma and inv(gamma-1) again, but could potentially reuse them from the Euler equations
# 2) Add NGRADS as a type parameter here and in AbstractEquationsParabolic, add `ngradients(...)` accessor function
Expand Down
2 changes: 1 addition & 1 deletion src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,6 @@ abstract type AbstractLinearizedEulerEquations{NDIMS, NVARS} <:
AbstractEquations{NDIMS, NVARS} end
include("linearized_euler_2d.jl")

abstract type AbstractEquationsParabolic{NDIMS, NVARS} <:
abstract type AbstractEquationsParabolic{NDIMS, NVARS, GradientVariables} <:
AbstractEquations{NDIMS, NVARS} end
end # @muladd
11 changes: 8 additions & 3 deletions src/equations/equations_parabolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
# specialize this function to compute gradients e.g., of primitive variables instead of conservative
gradient_variable_transformation(::AbstractEquationsParabolic) = cons2cons

# By default, the gradients are taken with respect to the conservative variables.
# this is reflected by the type parameter `GradientVariablesConservative` in the abstract
# type `AbstractEquationsParabolic{NDIMS, NVARS, GradientVariablesConservative}`.
struct GradientVariablesConservative end

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

# Compressible Navier-Stokes equations
abstract type AbstractCompressibleNavierStokesDiffusion{NDIMS, NVARS} <:
AbstractEquationsParabolic{NDIMS, NVARS} end
abstract type AbstractCompressibleNavierStokesDiffusion{NDIMS, NVARS, GradientVariables} <:
AbstractEquationsParabolic{NDIMS, NVARS, GradientVariables} end
include("compressible_navier_stokes.jl")
include("compressible_navier_stokes_1d.jl")
include("compressible_navier_stokes_2d.jl")
Expand Down

0 comments on commit 443858f

Please sign in to comment.