MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
hyperbolic.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12
13#ifndef MFEM_HYPERBOLIC
14#define MFEM_HYPERBOLIC
15
16#include "nonlinearform.hpp"
17
18namespace mfem
19{
20
21// This file contains general hyperbolic conservation element/face form
22// integrators. HyperbolicFormIntegrator and RiemannSolver are defined.
23//
24// HyperbolicFormIntegrator is a NonlinearFormIntegrator that implements
25// element weak divergence and interface flux
26//
27// ∫_T F(u):∇v, -∫_e F̂(u)⋅[[v]]
28//
29// Here, T is an element, e is an edge, and [[⋅]] is jump. This form integrator
30// is coupled with RiemannSolver that implements the numerical flux F̂. For
31// RiemannSolver, the Rusanov flux, also known as local Lax-Friedrichs flux, is
32// provided.
33//
34// To implement a specific hyperbolic conservation laws, users can create
35// derived classes from FluxFunction with overloaded ComputeFlux. One can
36// optionally overload ComputeFluxDotN to avoid creating dense matrix when
37// computing normal flux. Several example equations are also defined including:
38// advection, Burgers', shallow water, and Euler equations. Users can control
39// the quadrature rule by either providing the integration rule, or integration
40// order offset. Integration will use 2*p + IntOrderOffset order quadrature
41// rule.
42//
43// At each call of HyperbolicFormIntegrator::AssembleElementVector
44// HyperbolicFormIntegrator::AssembleFaceVector, the maximum characteristic
45// speed will be updated. This will not be reinitialized automatically. To
46// reinitialize, use HyperbolicFormIntegrator::ResetMaxCharSpeed. See, ex18.hpp.
47//
48// Note: To avoid communication overhead, we update the maximum characteristic
49// speed within each MPI process only. Use the appropriate MPI routine to gather
50// the information.
51
52/**
53 * @brief Abstract class for hyperbolic flux for a system of hyperbolic
54 * conservation laws
55 *
56 */
58{
59public:
60 const int num_equations;
61 const int dim;
62
63 FluxFunction(const int num_equations, const int dim)
65 {
66#ifndef MFEM_THREAD_SAFE
68#endif
69 }
70
71 /**
72 * @brief Compute flux F(u, x) for given state u and physical point x
73 *
74 * @param[in] state value of state at the current integration point
75 * @param[in] Tr element information
76 * @param[out] flux F(u, x)
77 * @return real_t maximum characteristic speed
78 *
79 * @note One can put assertion in here to detect non-physical solution
80 */
82 DenseMatrix &flux) const = 0;
83 /**
84 * @brief Compute normal flux. Optionally overloaded in the
85 * derived class to avoid creating full dense matrix for flux.
86 *
87 * @param[in] state state at the current integration point
88 * @param[in] normal normal vector, @see CalcOrtho
89 * @param[in] Tr face information
90 * @param[out] fluxDotN normal flux from the given element at the current
91 * integration point
92 * @return real_t maximum (normal) characteristic velocity
93 */
94 virtual real_t ComputeFluxDotN(const Vector &state, const Vector &normal,
96 Vector &fluxDotN) const;
97
98 /**
99 * @brief Compute flux Jacobian. Optionally overloaded in the derived class
100 * when Jacobian is necessary (e.g. Newton iteration, flux limiter)
101 *
102 * @param state state at the current integration point
103 * @param Tr element information
104 * @param J flux Jacobian, J(i,j,d) = dF_{id} / u_j
105 */
106 virtual void ComputeFluxJacobian(const Vector &state,
108 DenseTensor &J) const
109 {
110 MFEM_ABORT("Not Implemented.");
111 }
112
113private:
114#ifndef MFEM_THREAD_SAFE
115 mutable DenseMatrix flux;
116#endif
117};
118
119
120/**
121 * @brief Abstract class for numerical flux for a system of hyperbolic
122 * conservation laws on a face with states, fluxes and characteristic speed
123 *
124 */
126{
127public:
130
131 /**
132 * @brief Evaluates numerical flux for given states and fluxes. Must be
133 * overloaded in a derived class
134 *
135 * @param[in] state1 state value at a point from the first element
136 * (num_equations)
137 * @param[in] state2 state value at a point from the second element
138 * (num_equations)
139 * @param[in] nor scaled normal vector, see mfem::CalcOrtho() (dim)
140 * @param[in] Tr face information
141 * @param[out] flux numerical flux (num_equations)
142 */
143 virtual real_t Eval(const Vector &state1, const Vector &state2,
144 const Vector &nor, FaceElementTransformations &Tr,
145 Vector &flux) const = 0;
146
147 virtual ~RiemannSolver() = default;
148
149 /// @brief Get flux function F
150 /// @return constant reference to the flux function.
151 const FluxFunction &GetFluxFunction() const { return fluxFunction; }
152
153protected:
155};
156
157/**
158 * @brief Abstract hyperbolic form integrator, (F(u, x), ∇v) and (F̂(u±, x, n))
159 *
160 */
162{
163private:
164 // The maximum characteristic speed, updated during element/face vector assembly
165 real_t max_char_speed;
166 const RiemannSolver &rsolver; // Numerical flux that maps F(u±,x) to hat(F)
167 const FluxFunction &fluxFunction;
168 const int IntOrderOffset; // integration order offset, 2*p + IntOrderOffset.
169#ifndef MFEM_THREAD_SAFE
170 // Local storage for element integration
171 Vector shape; // shape function value at an integration point
172 Vector state; // state value at an integration point
173 DenseMatrix flux; // flux value at an integration point
174 DenseMatrix dshape; // derivative of shape function at an integration point
175
176 Vector shape1; // shape function value at an integration point - first elem
177 Vector shape2; // shape function value at an integration point - second elem
178 Vector state1; // state value at an integration point - first elem
179 Vector state2; // state value at an integration point - second elem
180 Vector nor; // normal vector, @see CalcOrtho
181 Vector fluxN; // hat(F)(u,x)
182#endif
183
184public:
185 const int num_equations; // the number of equations
186 /**
187 * @brief Construct a new Hyperbolic Form Integrator object
188 *
189 * @param[in] rsolver numerical flux
190 * @param[in] IntOrderOffset integration order offset
191 */
193 const RiemannSolver &rsolver,
194 const int IntOrderOffset=0);
195
196 /**
197 * @brief Reset the Max Char Speed 0
198 *
199 */
201 {
202 max_char_speed = 0.0;
203 }
204
206 {
207 return max_char_speed;
208 }
209
210 const FluxFunction &GetFluxFunction() { return fluxFunction; }
211
212 /**
213 * @brief implement (F(u), grad v) with abstract F computed by ComputeFlux
214 *
215 * @param[in] el local finite element
216 * @param[in] Tr element transformation
217 * @param[in] elfun local coefficient of basis
218 * @param[out] elvect evaluated dual vector
219 */
222 const Vector &elfun, Vector &elvect) override;
223
224 /**
225 * @brief implement <-hat(F)(u,x) n, [[v]]> with abstract hat(F) computed by
226 * ComputeFluxDotN and numerical flux object
227 *
228 * @param[in] el1 finite element of the first element
229 * @param[in] el2 finite element of the second element
230 * @param[in] Tr face element transformations
231 * @param[in] elfun local coefficient of basis from both elements
232 * @param[out] elvect evaluated dual vector <-hat(F)(u,x) n, [[v]]>
233 */
234 void AssembleFaceVector(const FiniteElement &el1,
235 const FiniteElement &el2,
237 const Vector &elfun, Vector &elvect) override;
238
239};
240
241
242/**
243 * @brief Rusanov flux, also known as local Lax-Friedrichs,
244 * F̂ n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
245 * where λ is the maximum characteristic velocity
246 *
247 */
249{
250public:
259
260 /**
261 * @brief hat(F)n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
262 *
263 * @param[in] state1 state value at a point from the first element
264 * (num_equations)
265 * @param[in] state2 state value at a point from the second element
266 * (num_equations)
267 * @param[in] nor normal vector (not a unit vector) (dim)
268 * @param[in] Tr face element transformation
269 * @param[out] flux ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
270 */
271 real_t Eval(const Vector &state1, const Vector &state2,
272 const Vector &nor, FaceElementTransformations &Tr,
273 Vector &flux) const override;
274
275protected:
276#ifndef MFEM_THREAD_SAFE
278#endif
279};
280
282{
283private:
284 VectorCoefficient &b; // velocity coefficient
285#ifndef MFEM_THREAD_SAFE
286 mutable Vector bval; // velocity value storage
287#endif
288
289public:
290
291 /**
292 * @brief Construct a new Advection Flux Function with given
293 * spatial dimension
294 *
295 * @param b velocity coefficient, possibly depends on space
296 */
298 : FluxFunction(1, b.GetVDim()), b(b)
299 {
300#ifndef MFEM_THREAD_SAFE
301 bval.SetSize(b.GetVDim());
302#endif
303 }
304
305 /**
306 * @brief Compute F(u)
307 *
308 * @param state state (u) at current integration point
309 * @param Tr current element transformation with integration point
310 * @param flux F(u) = ubᵀ
311 * @return real_t maximum characteristic speed, |b|
312 */
314 DenseMatrix &flux) const override;
315};
316
318{
319public:
320 /**
321 * @brief Construct a new Burgers Flux Function with given
322 * spatial dimension
323 *
324 * @param dim spatial dimension
325 */
326 BurgersFlux(const int dim)
327 : FluxFunction(1, dim) {}
328
329 /**
330 * @brief Compute F(u)
331 *
332 * @param state state (u) at current integration point
333 * @param Tr current element transformation with integration point
334 * @param flux F(u) = ½u²*1ᵀ where 1 is (dim) vector
335 * @return real_t maximum characteristic speed, |u|
336 */
338 DenseMatrix &flux) const override;
339};
340
342{
343private:
344 const real_t g; // gravity constant
345
346public:
347 /**
348 * @brief Construct a new Shallow Water Flux Function with
349 * given spatial dimension
350 *
351 * @param dim spatial dimension
352 * @param g gravity constant
353 */
354 ShallowWaterFlux(const int dim, const real_t g=9.8)
355 : FluxFunction(dim + 1, dim), g(g) {}
356
357 /**
358 * @brief Compute F(h, hu)
359 *
360 * @param state state (h, hu) at current integration point
361 * @param Tr current element transformation with integration point
362 * @param flux F(h, hu) = [huᵀ; huuᵀ + ½gh²I]
363 * @return real_t maximum characteristic speed, |u| + √(gh)
364 */
366 DenseMatrix &flux) const override;
367
368 /**
369 * @brief Compute normal flux, F(h, hu)
370 *
371 * @param state state (h, hu) at current integration point
372 * @param normal normal vector, usually not a unit vector
373 * @param Tr current element transformation with integration point
374 * @param fluxN F(ρ, ρu, E)n = [ρu⋅n; ρu(u⋅n) + pn; (u⋅n)(E + p)]
375 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
376 */
377 real_t ComputeFluxDotN(const Vector &state, const Vector &normal,
379 Vector &fluxN) const override;
380};
381
383{
384private:
385 const real_t specific_heat_ratio; // specific heat ratio, γ
386 // const real_t gas_constant; // gas constant
387
388public:
389 /**
390 * @brief Construct a new Euler Flux Function with given
391 * spatial dimension
392 *
393 * @param dim spatial dimension
394 * @param specific_heat_ratio specific heat ratio, γ
395 */
396 EulerFlux(const int dim, const real_t specific_heat_ratio)
397 : FluxFunction(dim + 2, dim),
398 specific_heat_ratio(specific_heat_ratio) {}
399
400 /**
401 * @brief Compute F(ρ, ρu, E)
402 *
403 * @param state state (ρ, ρu, E) at current integration point
404 * @param Tr current element transformation with integration point
405 * @param flux F(ρ, ρu, E) = [ρuᵀ; ρuuᵀ + pI; uᵀ(E + p)]
406 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
407 */
409 DenseMatrix &flux) const override;
410
411 /**
412 * @brief Compute normal flux, F(ρ, ρu, E)n
413 *
414 * @param x x (ρ, ρu, E) at current integration point
415 * @param normal normal vector, usually not a unit vector
416 * @param Tr current element transformation with integration point
417 * @param fluxN F(ρ, ρu, E)n = [ρu⋅n; ρu(u⋅n) + pn; (u⋅n)(E + p)]
418 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
419 */
420 real_t ComputeFluxDotN(const Vector &x, const Vector &normal,
422 Vector &fluxN) const override;
423};
424
425} // namespace mfem
426
427#endif // MFEM_HYPERBOLIC
AdvectionFlux(VectorCoefficient &b)
Construct a new Advection Flux Function with given spatial dimension.
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(u)
BurgersFlux(const int dim)
Construct a new Burgers Flux Function with given spatial dimension.
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(u)
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition densemat.hpp:105
Rank 3 tensor (array of matrices)
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(ρ, ρu, E)
EulerFlux(const int dim, const real_t specific_heat_ratio)
Construct a new Euler Flux Function with given spatial dimension.
real_t ComputeFluxDotN(const Vector &x, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxN) const override
Compute normal flux, F(ρ, ρu, E)n.
A specialized ElementTransformation class representing a face and its two neighboring elements.
Definition eltrans.hpp:484
Abstract class for all finite elements.
Definition fe_base.hpp:239
Abstract class for hyperbolic flux for a system of hyperbolic conservation laws.
FluxFunction(const int num_equations, const int dim)
const int num_equations
virtual void ComputeFluxJacobian(const Vector &state, ElementTransformation &Tr, DenseTensor &J) const
Compute flux Jacobian. Optionally overloaded in the derived class when Jacobian is necessary (e....
virtual real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const =0
Compute flux F(u, x) for given state u and physical point x.
virtual real_t ComputeFluxDotN(const Vector &state, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const
Compute normal flux. Optionally overloaded in the derived class to avoid creating full dense matrix f...
Abstract hyperbolic form integrator, (F(u, x), ∇v) and (F̂(u±, x, n))
HyperbolicFormIntegrator(const RiemannSolver &rsolver, const int IntOrderOffset=0)
Construct a new Hyperbolic Form Integrator object.
const FluxFunction & GetFluxFunction()
void AssembleFaceVector(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr, const Vector &elfun, Vector &elvect) override
implement <-hat(F)(u,x) n, [[v]]> with abstract hat(F) computed by ComputeFluxDotN and numerical flux...
void ResetMaxCharSpeed()
Reset the Max Char Speed 0.
void AssembleElementVector(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun, Vector &elvect) override
implement (F(u), grad v) with abstract F computed by ComputeFlux
This class is used to express the local action of a general nonlinear finite element operator....
Abstract class for numerical flux for a system of hyperbolic conservation laws on a face with states,...
RiemannSolver(const FluxFunction &fluxFunction)
virtual ~RiemannSolver()=default
const FluxFunction & GetFluxFunction() const
Get flux function F.
virtual real_t Eval(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const =0
Evaluates numerical flux for given states and fluxes. Must be overloaded in a derived class.
const FluxFunction & fluxFunction
Rusanov flux, also known as local Lax-Friedrichs, F̂ n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻) where λ...
RusanovFlux(const FluxFunction &fluxFunction)
real_t Eval(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const override
hat(F)n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
ShallowWaterFlux(const int dim, const real_t g=9.8)
Construct a new Shallow Water Flux Function with given spatial dimension.
real_t ComputeFluxDotN(const Vector &state, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxN) const override
Compute normal flux, F(h, hu)
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(h, hu)
Base class for vector Coefficients that optionally depend on time and space.
Vector data type.
Definition vector.hpp:80
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:538
real_t b
Definition lissajous.cpp:42
float real_t
Definition config.hpp:43