diff --git a/NEWS.md b/NEWS.md index bc213fcea55..b6f569f3544 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ for human readability. - Implementation of the polytropic Euler equations in 2D - 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 diff --git a/docs/literate/src/files/adding_new_parabolic_terms.jl b/docs/literate/src/files/adding_new_parabolic_terms.jl index f5c2b815f33..209ef62c988 100644 --- a/docs/literate/src/files/adding_new_parabolic_terms.jl +++ b/docs/literate/src/files/adding_new_parabolic_terms.jl @@ -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 diff --git a/src/Trixi.jl b/src/Trixi.jl index 97d518d5b78..8894d30bc9d 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -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, diff --git a/src/equations/compressible_navier_stokes_1d.jl b/src/equations/compressible_navier_stokes_1d.jl index 74d672ce7ae..0814fdc1765 100644 --- a/src/equations/compressible_navier_stokes_1d.jl +++ b/src/equations/compressible_navier_stokes_1d.jl @@ -86,7 +86,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 diff --git a/src/equations/compressible_navier_stokes_2d.jl b/src/equations/compressible_navier_stokes_2d.jl index 80857999017..e85053d68a7 100644 --- a/src/equations/compressible_navier_stokes_2d.jl +++ b/src/equations/compressible_navier_stokes_2d.jl @@ -86,7 +86,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 diff --git a/src/equations/compressible_navier_stokes_3d.jl b/src/equations/compressible_navier_stokes_3d.jl index de2cad99ea8..2fcecd2b8c0 100644 --- a/src/equations/compressible_navier_stokes_3d.jl +++ b/src/equations/compressible_navier_stokes_3d.jl @@ -86,7 +86,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 diff --git a/src/equations/equations.jl b/src/equations/equations.jl index 0e77b92e045..78b1b829b06 100644 --- a/src/equations/equations.jl +++ b/src/equations/equations.jl @@ -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 diff --git a/src/equations/equations_parabolic.jl b/src/equations/equations_parabolic.jl index 47a76174cb1..a063e9f2758 100644 --- a/src/equations/equations_parabolic.jl +++ b/src/equations/equations_parabolic.jl @@ -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")