MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
hyperbolic.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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 NumericalFlux are defined.
23//
24// HyperbolicFormIntegrator is a NonlinearFormIntegrator that implements
25// element weak divergence and interface flux
26//
27// ∫_K F(u):∇v, -∫_f F̂(u)⋅n[v]
28//
29// Here, K is an element, f is a face, n normal and [⋅] is jump. This form
30// integrator is coupled with NumericalFlux that implements the numerical flux
31// F̂. For NumericalFlux, the Rusanov flux, also known as local Lax-Friedrichs
32// flux, or component-wise upwinded flux are 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 virtual ~FluxFunction() {}
67
68 /**
69 * @brief Compute flux F(u, x). Must be implemented in a derived class.
70 *
71 * Used in HyperbolicFormIntegrator::AssembleElementVector() for evaluation
72 * of (F(u), ∇v) and in the default implementation of ComputeFluxDotN()
73 * for evaluation of F(u)⋅n.
74 * @param[in] state state at the current integration point (num_equations)
75 * @param[in] Tr element transformation
76 * @param[out] flux flux from the given element at the current
77 * integration point (num_equations, dim)
78 * @return real_t maximum characteristic speed |dF(u,x)/du|
79 *
80 * @note One can put assertion in here to detect non-physical solution
81 */
83 DenseMatrix &flux) const = 0;
84 /**
85 * @brief Compute normal flux F(u, x)⋅n. Optionally overloaded in a derived
86 * class to avoid creating a full dense matrix for flux.
87 *
88 * Used in NumericalFlux for evaluation of the normal flux on a face.
89 * @param[in] state state at the current integration point (num_equations)
90 * @param[in] normal normal vector, see mfem::CalcOrtho() (dim)
91 * @param[in] Tr face transformation
92 * @param[out] fluxDotN normal flux from the given element at the current
93 * integration point (num_equations)
94 * @return real_t maximum (normal) characteristic speed |dF(u,x)/du⋅n|
95 */
96 virtual real_t ComputeFluxDotN(const Vector &state, const Vector &normal,
98 Vector &fluxDotN) const;
99
100 /**
101 * @brief Compute average flux over the given interval of states.
102 * Optionally overloaded in a derived class.
103 *
104 * The average flux is defined as F̄(u1,u2) = ∫ F(u) du / (u2 - u1) for
105 * u ∈ [u1,u2], where u1 is the first state (@a state1) and the u2 the
106 * second state (@a state2), while F(u) is the flux as defined in
107 * ComputeFlux().
108 *
109 * Used in the default implementation of ComputeAvgFluxDotN().
110 * @param[in] state1 state of the beginning of the interval (num_equations)
111 * @param[in] state2 state of the end of the interval (num_equations)
112 * @param[in] Tr element transformation
113 * @param[out] flux_ average flux from the given element at the current
114 * integration point (num_equations, dim)
115 * @return real_t maximum characteristic speed |dF(u,x)/du| over
116 * the interval [u1,u2]
117 */
118 virtual real_t ComputeAvgFlux(const Vector &state1, const Vector &state2,
120 DenseMatrix &flux_) const
121 { MFEM_ABORT("Not Implemented."); }
122
123 /**
124 * @brief Compute average normal flux over the given interval of states.
125 * Optionally overloaded in a derived class.
126 *
127 * The average normal flux is defined as F̄(u1,u2)n = ∫ F(u)n du / (u2 - u1)
128 * for u ∈ [u1,u2], where u1 is the first state (@a state1) and the u2 the
129 * second state (@a state2), while n is the normal and F(u) is the flux as
130 * defined in ComputeFlux().
131 *
132 * Used in NumericalFlux::Average() and NumericalFlux::AverageGrad() for
133 * evaluation of the average normal flux on a face.
134 * @param[in] state1 state of the beginning of the interval (num_equations)
135 * @param[in] state2 state of the end of the interval (num_equations)
136 * @param[in] normal normal vector, see mfem::CalcOrtho() (dim)
137 * @param[in] Tr face transformation
138 * @param[out] fluxDotN average normal flux from the given element at the
139 * current integration point (num_equations)
140 * @return real_t maximum (normal) characteristic speed |dF(u,x)/du⋅n|
141 * over the interval [u1,u2]
142 */
143 virtual real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2,
144 const Vector &normal,
146 Vector &fluxDotN) const;
147
148 /**
149 * @brief Compute flux Jacobian J(u, x). Optionally overloaded in a derived
150 * class when Jacobian is necessary (e.g. Newton iteration, flux limiter)
151 *
152 * Used in HyperbolicFormIntegrator::AssembleElementGrad() for evaluation of
153 * Jacobian of the flux in an element and in the default implementation of
154 * ComputeFluxJacobianDotN().
155 * @param[in] state state at the current integration point (num_equations)
156 * @param[in] Tr element transformation
157 * @param[out] J_ flux Jacobian, $ J(i,j,d) = dF_{id} / du_j $
158 */
159 virtual void ComputeFluxJacobian(const Vector &state,
161 DenseTensor &J_) const
162 { MFEM_ABORT("Not Implemented."); }
163
164 /**
165 * @brief Compute normal flux Jacobian J(u, x)⋅n. Optionally overloaded in
166 * a derived class to avoid creating a full dense tensor for Jacobian.
167 *
168 * Used in NumericalFlux for evaluation of Jacobian of the normal flux on
169 * a face.
170 * @param[in] state state at the current integration point (num_equations)
171 * @param[in] normal normal vector, see mfem::CalcOrtho() (dim)
172 * @param[in] Tr element transformation
173 * @param[out] JDotN normal flux Jacobian, $ JDotN(i,j) = d(F_{id} n_d) / du_j $
174 */
175 virtual void ComputeFluxJacobianDotN(const Vector &state,
176 const Vector &normal,
178 DenseMatrix &JDotN) const;
179
180private:
181#ifndef MFEM_THREAD_SAFE
182 mutable DenseMatrix flux;
183 mutable DenseTensor J;
184#endif
185};
186
187
188/**
189 * @brief Abstract class for numerical flux for a system of hyperbolic
190 * conservation laws on a face with states, fluxes and characteristic speed
191 *
192 */
194{
195public:
196 /**
197 * @brief Constructor for a flux function
198 * @param fluxFunction flux function F(u,x)
199 */
202
203 /**
204 * @brief Evaluates normal numerical flux for the given states and normal.
205 * Must be implemented in a derived class.
206 *
207 * Used in HyperbolicFormIntegrator::AssembleFaceVector() for evaluation of
208 * <F̂(u⁻,u⁺,x) n, [v]> term at the face.
209 * @param[in] state1 state value at a point from the first element
210 * (num_equations)
211 * @param[in] state2 state value at a point from the second element
212 * (num_equations)
213 * @param[in] nor scaled normal vector, see mfem::CalcOrtho() (dim)
214 * @param[in] Tr face transformation
215 * @param[out] flux numerical flux (num_equations)
216 * @return real_t maximum characteristic speed |dF(u,x)/du⋅n|
217 */
218 virtual real_t Eval(const Vector &state1, const Vector &state2,
219 const Vector &nor, FaceElementTransformations &Tr,
220 Vector &flux) const = 0;
221
222 /**
223 * @brief Evaluates Jacobian of the normal numerical flux for the given
224 * states and normal. Optionally overloaded in a derived class.
225 *
226 * Used in HyperbolicFormIntegrator::AssembleFaceGrad() for Jacobian
227 * of the term <F̂(u⁻,u⁺,x) n, [v]> at the face.
228 * @param[in] side indicates gradient w.r.t. the first (side = 1)
229 * or second (side = 2) state
230 * @param[in] state1 state value of the beginning of the interval
231 * (num_equations)
232 * @param[in] state2 state value of the end of the interval
233 * (num_equations)
234 * @param[in] nor scaled normal vector, see mfem::CalcOrtho() (dim)
235 * @param[in] Tr face transformation
236 * @param[out] grad Jacobian of normal numerical flux (num_equations, dim)
237 */
238 virtual void Grad(int side, const Vector &state1, const Vector &state2,
239 const Vector &nor, FaceElementTransformations &Tr,
240 DenseMatrix &grad) const
241 { MFEM_ABORT("Not implemented."); }
242
243 /**
244 * @brief Evaluates average normal numerical flux over the interval between
245 * the given end states in the second argument and for the given normal.
246 * Optionally overloaded in a derived class.
247 *
248 * Presently, not used. Reserved for future use.
249 * @param[in] state1 state value of the beginning of the interval
250 * (num_equations)
251 * @param[in] state2 state value of the end of the interval
252 * (num_equations)
253 * @param[in] nor scaled normal vector, see mfem::CalcOrtho() (dim)
254 * @param[in] Tr face transformation
255 * @param[out] flux numerical flux (num_equations)
256 * @return real_t maximum characteristic speed |dF(u,x)/du⋅n|
257 */
258 virtual real_t Average(const Vector &state1, const Vector &state2,
259 const Vector &nor, FaceElementTransformations &Tr,
260 Vector &flux) const
261 { MFEM_ABORT("Not implemented."); }
262
263 /**
264 * @brief Evaluates Jacobian of the average normal numerical flux over the
265 * interval between the given end states in the second argument and for the
266 * given normal. Optionally overloaded in a derived class.
267 *
268 * Presently, not used. Reserved for future use.
269 * @param[in] side indicates gradient w.r.t. the first (side = 1)
270 * or second (side = 2) state
271 * @param[in] state1 state value of the beginning of the interval
272 * (num_equations)
273 * @param[in] state2 state value of the end of the interval
274 * (num_equations)
275 * @param[in] nor scaled normal vector, see mfem::CalcOrtho() (dim)
276 * @param[in] Tr face transformation
277 * @param[out] grad Jacobian of the average normal numerical flux
278 * (num_equations, dim)
279 */
280 virtual void AverageGrad(int side, const Vector &state1, const Vector &state2,
281 const Vector &nor, FaceElementTransformations &Tr,
282 DenseMatrix &grad) const
283 { MFEM_ABORT("Not implemented."); }
284
285 virtual ~NumericalFlux() = default;
286
287 /// @brief Get flux function F
288 /// @return constant reference to the flux function.
289 const FluxFunction &GetFluxFunction() const { return fluxFunction; }
290
291protected:
293};
294
295/// @deprecated Use NumericalFlux instead.
296MFEM_DEPRECATED typedef NumericalFlux RiemannSolver;
297
298/**
299 * @brief Abstract hyperbolic form integrator, assembling (F(u, x), ∇v) and
300 * <F̂(u⁻,u⁺,x) n, [v]> terms for scalar finite elements.
301 *
302 * This form integrator is coupled with a NumericalFlux that implements the
303 * numerical flux F̂ at the faces. The flux F is obtained from the FluxFunction
304 * assigned to the aforementioned NumericalFlux.
305 */
307{
308private:
309 // The maximum characteristic speed, updated during element/face vector assembly
310 real_t max_char_speed;
311 const NumericalFlux &numFlux; // Numerical flux that maps F(u±,x) to F̂
312 const FluxFunction &fluxFunction;
313 const int IntOrderOffset; // integration order offset, 2*p + IntOrderOffset.
314 const real_t sign;
315#ifndef MFEM_THREAD_SAFE
316 // Local storage for element integration
317 Vector shape; // shape function value at an integration point
318 Vector state; // state value at an integration point
319 DenseMatrix flux; // flux value at an integration point
320 DenseTensor J; // Jacobian matrix at an integration point
321 DenseMatrix dshape; // derivative of shape function at an integration point
322
323 Vector shape1; // shape function value at an integration point - first elem
324 Vector shape2; // shape function value at an integration point - second elem
325 Vector state1; // state value at an integration point - first elem
326 Vector state2; // state value at an integration point - second elem
327 Vector nor; // normal vector, see mfem::CalcOrtho()
328 Vector fluxN; // F̂(u±,x) n
329 DenseMatrix JDotN; // Ĵ(u±,x) n
330#endif
331
332public:
333 const int num_equations; // the number of equations
334 /**
335 * @brief Construct a new Hyperbolic Form Integrator object
336 *
337 * @param[in] numFlux numerical flux
338 * @param[in] IntOrderOffset integration order offset
339 * @param[in] sign sign of the convection term
340 */
342 const NumericalFlux &numFlux,
343 const int IntOrderOffset = 0,
344 const real_t sign = 1.);
345
346 /**
347 * @brief Reset the Max Char Speed 0
348 *
349 */
351 {
352 max_char_speed = 0.0;
353 }
354
356 {
357 return max_char_speed;
358 }
359
360 const FluxFunction &GetFluxFunction() { return fluxFunction; }
361
362 /**
363 * @brief Implements (F(u), ∇v) with abstract F computed by
364 * FluxFunction::ComputeFlux()
365 *
366 * @param[in] el local finite element
367 * @param[in] Tr element transformation
368 * @param[in] elfun local coefficient of basis
369 * @param[out] elvect evaluated dual vector
370 */
373 const Vector &elfun, Vector &elvect) override;
374
375 /**
376 * @brief Implements (J(u), ∇v) with abstract J computed by
377 * FluxFunction::ComputeFluxJacobian()
378 *
379 * @param[in] el local finite element
380 * @param[in] Tr element transformation
381 * @param[in] elfun local coefficient of basis
382 * @param[out] grad evaluated Jacobian
383 */
384 void AssembleElementGrad(const FiniteElement &el,
386 const Vector &elfun, DenseMatrix &grad) override;
387
388 /**
389 * @brief Implements <-F̂(u⁻,u⁺,x) n, [v]> with abstract F̂ computed by
390 * NumericalFlux::Eval() of the numerical flux object
391 *
392 * @param[in] el1 finite element of the first element
393 * @param[in] el2 finite element of the second element
394 * @param[in] Tr face element transformations
395 * @param[in] elfun local coefficient of basis from both elements
396 * @param[out] elvect evaluated dual vector <-F̂(u⁻,u⁺,x) n, [v]>
397 */
398 void AssembleFaceVector(const FiniteElement &el1,
399 const FiniteElement &el2,
401 const Vector &elfun, Vector &elvect) override;
402
403 /**
404 * @brief Implements <-Ĵ(u⁻,u⁺,x) n, [v]> with abstract Ĵ computed by
405 * NumericalFlux::Grad() of the numerical flux object
406 *
407 * @param[in] el1 finite element of the first element
408 * @param[in] el2 finite element of the second element
409 * @param[in] Tr face element transformations
410 * @param[in] elfun local coefficient of basis from both elements
411 * @param[out] elmat evaluated Jacobian matrix <-Ĵ(u⁻,u⁺,x) n, [v]>
412 */
413 void AssembleFaceGrad(const FiniteElement &el1,
414 const FiniteElement &el2,
416 const Vector &elfun, DenseMatrix &elmat) override;
417};
418
419
420/**
421 * @brief Rusanov flux, also known as local Lax-Friedrichs,
422 * F̂ n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
423 * where λ is the maximum characteristic speed.
424 * @note The implementation assumes monotonous |dF(u,x)/du⋅n| in u, so the
425 * maximum characteristic speed λ for any interval [u⁻, u⁺] is given by
426 * max(|dF(u⁺,x)/du⁺⋅n|, |dF(u⁻,x)/du⁻⋅n|).
427 */
429{
430public:
431 /**
432 * @brief Constructor for a flux function
433 * @param fluxFunction flux function F(u,x)
434 */
436
437 /**
438 * @brief Normal numerical flux F̂(u⁻,u⁺,x) n
439 * @note Systems of equations are treated component-wise
440 *
441 * @param[in] state1 state value (u⁻) at a point from the first element
442 * (num_equations)
443 * @param[in] state2 state value (u⁺) at a point from the second element
444 * (num_equations)
445 * @param[in] nor normal vector (not a unit vector) (dim)
446 * @param[in] Tr face element transformation
447 * @param[out] flux F̂ n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻)
448 * @return max(|dF(u⁺,x)/du⁺⋅n|, |dF(u⁻,x)/du⁻⋅n|)
449 */
450 real_t Eval(const Vector &state1, const Vector &state2,
451 const Vector &nor, FaceElementTransformations &Tr,
452 Vector &flux) const override;
453
454 /**
455 * @brief Jacobian of normal numerical flux F̂(u⁻,u⁺,x) n
456 * @note The Jacobian of flux J n is required to be implemented in
457 * FluxFunction::ComputeFluxJacobianDotN()
458 *
459 * @param[in] side gradient w.r.t the first (u⁻) or second argument (u⁺)
460 * @param[in] state1 state value (u⁻) of the beginning of the interval
461 * (num_equations)
462 * @param[in] state2 state value (u⁺) of the end of the interval
463 * (num_equations)
464 * @param[in] nor normal vector (not a unit vector) (dim)
465 * @param[in] Tr face element transformation
466 * @param[out] grad Jacobian of F(u⁻,u⁺,x) n
467 * side = 1:
468 * ½J(u⁻,x)n + ½λ
469 * side = 2:
470 * ½J(u⁺,x)n - ½λ
471 */
472 void Grad(int side, const Vector &state1, const Vector &state2,
473 const Vector &nor, FaceElementTransformations &Tr,
474 DenseMatrix &grad) const override;
475
476 /**
477 * @brief Average normal numerical flux over the interval [u⁻, u⁺] in the
478 * second argument of the flux F̂(u⁻,u,x) n
479 * @note The average normal flux F̄ n is required to be implemented in
480 * FluxFunction::ComputeAvgFluxDotN()
481 * @note Systems of equations are treated component-wise
482 *
483 * @param[in] state1 state value (u⁻) of the beginning of the interval
484 * (num_equations)
485 * @param[in] state2 state value (u⁺) of the end of the interval
486 * (num_equations)
487 * @param[in] nor normal vector (not a unit vector) (dim)
488 * @param[in] Tr face element transformation
489 * @param[out] flux ½(F̄(u⁻,u⁺,x)n + F(u⁻,x)n) - ¼λ(u⁺ - u⁻)
490 * @return max(|dF(u⁺,x)/du⁺⋅n|, |dF(u⁻,x)/du⁻⋅n|)
491 */
492 real_t Average(const Vector &state1, const Vector &state2,
493 const Vector &nor, FaceElementTransformations &Tr,
494 Vector &flux) const override;
495
496 /**
497 * @brief Jacobian of average normal numerical flux over the interval
498 * [u⁻, u⁺] in the second argument of the flux F̂(u⁻,u,x) n
499 * @note The average normal flux F̄ n is required to be implemented in
500 * FluxFunction::ComputeAvgFluxDotN() and the Jacobian of flux J n in
501 * FluxFunction::ComputeFluxJacobianDotN()
502 * @note Only the diagonal terms of the J n are considered, i.e., systems
503 * are treated as a set of independent equations
504 *
505 * @param[in] side gradient w.r.t the first (u⁻) or second argument (u⁺)
506 * @param[in] state1 state value (u⁻) of the beginning of the interval
507 * (num_equations)
508 * @param[in] state2 state value (u⁺) of the end of the interval
509 * (num_equations)
510 * @param[in] nor normal vector (not a unit vector) (dim)
511 * @param[in] Tr face element transformation
512 * @param[out] grad Jacobian of F̄(u⁻,u⁺,x) n
513 * side = 1:
514 * ½(F̄(u⁻,u⁺,x)n - F(u⁻,x)n) / (u⁺ - u⁻) - ½J(u⁻,x)n + ¼λ
515 * side = 2:
516 * ½(F(u⁺,x)n - F̄(u⁻,u⁺,x)n) / (u⁺ - u⁻) - ¼λ
517 */
518 void AverageGrad(int side, const Vector &state1, const Vector &state2,
519 const Vector &nor, FaceElementTransformations &Tr,
520 DenseMatrix &grad) const override;
521
522protected:
523#ifndef MFEM_THREAD_SAFE
526#endif
527};
528
529/**
530 * @brief Component-wise upwinded flux
531 *
532 * Upwinded flux for scalar equations, a special case of Godunov or
533 * Engquist-Osher flux, is defined as follows:
534 * F̂ n = F(u⁺)n for dF(u)/du < 0 on [u⁻,u⁺]
535 * F̂ n = F(u⁻)n for dF(u)/du > 0 on [u⁻,u⁺]
536 * @note This construction assumes monotonous F(u,x) in u
537 * @note Systems of equations are treated component-wise
538 */
540{
541public:
542 /**
543 * @brief Constructor for a flux function
544 * @param fluxFunction flux function F(u,x)
545 */
547
548 /**
549 * @brief Normal numerical flux F̂(u⁻,u⁺,x) n
550 *
551 * @param[in] state1 state value (u⁻) at a point from the first element
552 * (num_equations)
553 * @param[in] state2 state value (u⁺) at a point from the second element
554 * (num_equations)
555 * @param[in] nor normal vector (not a unit vector) (dim)
556 * @param[in] Tr face element transformation
557 * @param[out] flux F̂ n = min(F(u⁻,x)n, F(u⁺,x)n) for u⁻ ≤ u⁺
558 * or F̂ n = max(F(u⁻,x)n, F(u⁺,x)n) for u⁻ > u⁺
559 * @return max(|dF(u⁺,x)/du⁺⋅n|, |dF(u⁻,x)/du⁻⋅n|)
560 */
561 real_t Eval(const Vector &state1, const Vector &state2,
562 const Vector &nor, FaceElementTransformations &Tr,
563 Vector &flux) const override;
564
565 /**
566 * @brief Jacobian of normal numerical flux F̂(u⁻,u⁺,x) n
567 * @note The Jacobian of flux J n is required to be implemented in
568 * FluxFunction::ComputeFluxJacobianDotN()
569 *
570 * @param[in] side gradient w.r.t the first (u⁻) or second argument (u⁺)
571 * @param[in] state1 state value (u⁻) of the beginning of the interval
572 * (num_equations)
573 * @param[in] state2 state value (u⁺) of the end of the interval
574 * (num_equations)
575 * @param[in] nor normal vector (not a unit vector) (dim)
576 * @param[in] Tr face element transformation
577 * @param[out] grad Jacobian of F(u⁻,u⁺,x) n
578 * side = 1:
579 * max(J(u⁻,x)n, 0)
580 * side = 2:
581 * min(J(u⁺,x)n, 0)
582 */
583 void Grad(int side, const Vector &state1, const Vector &state2,
584 const Vector &nor, FaceElementTransformations &Tr,
585 DenseMatrix &grad) const override;
586
587 /**
588 * @brief Average normal numerical flux over the interval [u⁻, u⁺] in the
589 * second argument of the flux F̂(u⁻,u,x) n
590 * @note The average normal flux F̄ n is required to be implemented in
591 * FluxFunction::ComputeAvgFluxDotN()
592 *
593 * @param[in] state1 state value (u⁻) of the beginning of the interval
594 * (num_equations)
595 * @param[in] state2 state value (u⁺) of the end of the interval
596 * (num_equations)
597 * @param[in] nor normal vector (not a unit vector) (dim)
598 * @param[in] Tr face element transformation
599 * @param[out] flux F̂ n = min(F(u⁻)n, F̄(u⁺,x)n) for u⁻ ≤ u⁺
600 * or F̂ n = max(F(u⁻)n, F̄(u⁺,x)n) for u⁻ > u⁺
601 * @return max(|dF(u⁺,x)/du⁺⋅n|, |dF(u⁻,x)/du⁻⋅n|)
602 */
603 real_t Average(const Vector &state1, const Vector &state2,
604 const Vector &nor, FaceElementTransformations &Tr,
605 Vector &flux) const override;
606
607 /**
608 * @brief Jacobian of average normal numerical flux over the interval
609 * [u⁻, u⁺] in the second argument of the flux F̂(u⁻,u,x) n
610 * @note The average normal flux F̄ n is required to be implemented in
611 * FluxFunction::ComputeAvgFluxDotN() and the Jacobian of flux J n in
612 * FluxFunction::ComputeFluxJacobianDotN()
613 *
614 * @param[in] side gradient w.r.t the first (u⁻) or second argument (u⁺)
615 * @param[in] state1 state value (u⁻) of the beginning of the interval
616 * (num_equations)
617 * @param[in] state2 state value (u⁺) of the end of the interval
618 * (num_equations)
619 * @param[in] nor normal vector (not a unit vector) (dim)
620 * @param[in] Tr face element transformation
621 * @param[out] grad Jacobian of F̄(u⁻,u⁺,x) n
622 * side = 1:
623 * (F(u⁺) - F̄(u⁻,u⁺))n / (u⁺ - u⁻) when negative
624 * J(u⁻,x) n otherwise
625 * side = 2:
626 * min((F(u⁺) - F̄(u⁻,u⁺))n / (u⁺ - u⁻), 0)
627 */
628 void AverageGrad(int side, const Vector &state1, const Vector &state2,
629 const Vector &nor, FaceElementTransformations &Tr,
630 DenseMatrix &grad) const override;
631
632protected:
633#ifndef MFEM_THREAD_SAFE
636#endif
637};
638
639/// Advection flux
641{
642private:
643 VectorCoefficient &b; // velocity coefficient
644#ifndef MFEM_THREAD_SAFE
645 mutable Vector bval; // velocity value storage
646#endif
647
648public:
649
650 /**
651 * @brief Construct AdvectionFlux FluxFunction with given velocity
652 *
653 * @param b velocity coefficient, possibly depends on space
654 */
656 : FluxFunction(1, b.GetVDim()), b(b)
657 {
658#ifndef MFEM_THREAD_SAFE
659 bval.SetSize(b.GetVDim());
660#endif
661 }
662
663 /**
664 * @brief Compute F(u)
665 *
666 * @param state state (u) at current integration point
667 * @param Tr current element transformation with the integration point
668 * @param flux F(u) = ubᵀ
669 * @return real_t maximum characteristic speed, |b|
670 */
672 DenseMatrix &flux) const override;
673
674 /**
675 * @brief Compute F(u) n
676 *
677 * @param state state (u) at current integration point
678 * @param normal normal vector, usually not a unit vector
679 * @param Tr current element transformation with the integration point
680 * @param fluxDotN F(u) n = u (bᵀn)
681 * @return real_t maximum characteristic speed, |b|
682 */
683 real_t ComputeFluxDotN(const Vector &state,
684 const Vector &normal, FaceElementTransformations &Tr,
685 Vector &fluxDotN) const override;
686
687 /**
688 * @brief Compute average flux F̄(u)
689 *
690 * @param state1 state value (u⁻) of the beginning of the interval
691 * @param state2 state value (u⁺) of the end of the interval
692 * @param Tr current element transformation with the integration point
693 * @param flux F̄(u) = (u⁻+u⁺)/2*bᵀ
694 * @return real_t maximum characteristic speed, |b|
695 */
696 real_t ComputeAvgFlux(const Vector &state1, const Vector &state2,
697 ElementTransformation &Tr, DenseMatrix &flux) const override;
698
699 /**
700 * @brief Compute average flux F̄(u) n
701 *
702 * @param state1 state value (u⁻) of the beginning of the interval
703 * @param state2 state value (u⁺) of the end of the interval
704 * @param normal normal vector, usually not a unit vector
705 * @param Tr current element transformation with the integration point
706 * @param fluxDotN F̄(u) n = (u⁻+u⁺)/2*(bᵀn)
707 * @return real_t maximum characteristic speed, |b|
708 */
709 real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2,
710 const Vector &normal, FaceElementTransformations &Tr,
711 Vector &fluxDotN) const override;
712
713 /**
714 * @brief Compute J(u)
715 *
716 * @param state state (u) at current integration point
717 * @param Tr current element transformation with the integration point
718 * @param J J(u) = diag(b)
719 */
720 void ComputeFluxJacobian(const Vector &state,
722 DenseTensor &J) const override;
723
724 /**
725 * @brief Compute J(u) n
726 *
727 * @param state state (u) at current integration point
728 * @param normal normal vector, usually not a unit vector
729 * @param Tr current element transformation with the integration point
730 * @param JDotN J(u) n = bᵀn
731 */
732 void ComputeFluxJacobianDotN(const Vector &state,
733 const Vector &normal,
735 DenseMatrix &JDotN) const override;
736};
737
738/// Burgers flux
740{
741public:
742 /**
743 * @brief Construct BurgersFlux FluxFunction with given spatial dimension
744 *
745 * @param dim spatial dimension
746 */
747 BurgersFlux(const int dim)
748 : FluxFunction(1, dim) {}
749
750 /**
751 * @brief Compute F(u)
752 *
753 * @param state state (u) at current integration point
754 * @param Tr current element transformation with the integration point
755 * @param flux F(u) = ½u²*1ᵀ where 1 is (dim) vector
756 * @return real_t maximum characteristic speed, |u|
757 */
759 DenseMatrix &flux) const override;
760
761 /**
762 * @brief Compute F(u) n
763 *
764 * @param state state (u) at current integration point
765 * @param normal normal vector, usually not a unit vector
766 * @param Tr current element transformation with the integration point
767 * @param fluxDotN F(u) n = ½u²*(1ᵀn) where 1 is (dim) vector
768 * @return real_t maximum characteristic speed, |u|
769 */
770 real_t ComputeFluxDotN(const Vector &state,
771 const Vector &normal,
773 Vector &fluxDotN) const override;
774
775 /**
776 * @brief Compute average flux F̄(u)
777 *
778 * @param state1 state value (u⁻) of the beginning of the interval
779 * @param state2 state value (u⁺) of the end of the interval
780 * @param Tr current element transformation with the integration point
781 * @param flux F̄(u) = (u⁻²+u⁻*u⁺+u⁺²)/6*1ᵀ where 1 is (dim) vector
782 * @return real_t maximum characteristic speed, |u|
783 */
784 real_t ComputeAvgFlux(const Vector &state1,
785 const Vector &state2,
787 DenseMatrix &flux) const override;
788
789 /**
790 * @brief Compute average flux F̄(u) n
791 *
792 * @param state1 state value (u⁻) of the beginning of the interval
793 * @param state2 state value (u⁺) of the end of the interval
794 * @param normal normal vector, usually not a unit vector
795 * @param Tr current element transformation with the integration point
796 * @param fluxDotN F̄(u) n = (u⁻²+u⁻*u⁺+u⁺²)/6*(1ᵀn) where 1 is (dim) vector
797 * @return real_t maximum characteristic speed, |u|
798 */
799 real_t ComputeAvgFluxDotN(const Vector &state1,
800 const Vector &state2,
801 const Vector &normal,
803 Vector &fluxDotN) const override;
804
805 /**
806 * @brief Compute J(u)
807 *
808 * @param state state (u) at current integration point
809 * @param Tr current element transformation with the integration point
810 * @param J J(u) = diag(u*1) where 1 is (dim) vector
811 */
812 void ComputeFluxJacobian(const Vector &state,
814 DenseTensor &J) const override;
815
816 /**
817 * @brief Compute J(u) n
818 *
819 * @param state state (u) at current integration point
820 * @param normal normal vector, usually not a unit vector
821 * @param Tr current element transformation with the integration point
822 * @param JDotN J(u) n = u*(1ᵀn) where 1 is (dim) vector
823 */
824 void ComputeFluxJacobianDotN(const Vector &state,
825 const Vector &normal,
827 DenseMatrix &JDotN) const override;
828};
829
830/// Shallow water flux
832{
833private:
834 const real_t g; // gravity constant
835
836public:
837 /**
838 * @brief Construct a new ShallowWaterFlux FluxFunction with given spatial
839 * dimension and gravity constant
840 *
841 * @param dim spatial dimension
842 * @param g gravity constant
843 */
844 ShallowWaterFlux(const int dim, const real_t g=9.8)
845 : FluxFunction(dim + 1, dim), g(g) {}
846
847 /**
848 * @brief Compute F(h, hu)
849 *
850 * @param state state (h, hu) at current integration point
851 * @param Tr current element transformation with the integration point
852 * @param flux F(h, hu) = [huᵀ; huuᵀ + ½gh²I]
853 * @return real_t maximum characteristic speed, |u| + √(gh)
854 */
856 DenseMatrix &flux) const override;
857
858 /**
859 * @brief Compute normal flux, F(h, hu)
860 *
861 * @param state state (h, hu) at current integration point
862 * @param normal normal vector, usually not a unit vector
863 * @param Tr current element transformation with the integration point
864 * @param fluxN F(ρ, ρu, E)n = [ρu⋅n; ρu(u⋅n) + pn; (u⋅n)(E + p)]
865 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
866 */
867 real_t ComputeFluxDotN(const Vector &state, const Vector &normal,
869 Vector &fluxN) const override;
870};
871
872/// Euler flux
874{
875private:
876 const real_t specific_heat_ratio; // specific heat ratio, γ
877 // const real_t gas_constant; // gas constant
878
879public:
880 /**
881 * @brief Construct a new EulerFlux FluxFunction with given spatial
882 * dimension and specific heat ratio
883 *
884 * @param dim spatial dimension
885 * @param specific_heat_ratio specific heat ratio, γ
886 */
887 EulerFlux(const int dim, const real_t specific_heat_ratio)
888 : FluxFunction(dim + 2, dim),
889 specific_heat_ratio(specific_heat_ratio) {}
890
891 /**
892 * @brief Compute F(ρ, ρu, E)
893 *
894 * @param state state (ρ, ρu, E) at current integration point
895 * @param Tr current element transformation with the integration point
896 * @param flux F(ρ, ρu, E) = [ρuᵀ; ρuuᵀ + pI; uᵀ(E + p)]
897 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
898 */
900 DenseMatrix &flux) const override;
901
902 /**
903 * @brief Compute normal flux, F(ρ, ρu, E)n
904 *
905 * @param x x (ρ, ρu, E) at current integration point
906 * @param normal normal vector, usually not a unit vector
907 * @param Tr current element transformation with the integration point
908 * @param fluxN F(ρ, ρu, E)n = [ρu⋅n; ρu(u⋅n) + pn; (u⋅n)(E + p)]
909 * @return real_t maximum characteristic speed, |u| + √(γp/ρ)
910 */
911 real_t ComputeFluxDotN(const Vector &x, const Vector &normal,
913 Vector &fluxN) const override;
914};
915
916} // namespace mfem
917
918#endif // MFEM_HYPERBOLIC
Advection flux.
AdvectionFlux(VectorCoefficient &b)
Construct AdvectionFlux FluxFunction with given velocity.
void ComputeFluxJacobian(const Vector &state, ElementTransformation &Tr, DenseTensor &J) const override
Compute J(u)
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(u)
void ComputeFluxJacobianDotN(const Vector &state, const Vector &normal, ElementTransformation &Tr, DenseMatrix &JDotN) const override
Compute J(u) n.
real_t ComputeFluxDotN(const Vector &state, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const override
Compute F(u) n.
real_t ComputeAvgFlux(const Vector &state1, const Vector &state2, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute average flux F̄(u)
real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const override
Compute average flux F̄(u) n.
Burgers flux.
real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const override
Compute average flux F̄(u) n.
BurgersFlux(const int dim)
Construct BurgersFlux FluxFunction with given spatial dimension.
void ComputeFluxJacobianDotN(const Vector &state, const Vector &normal, ElementTransformation &Tr, DenseMatrix &JDotN) const override
Compute J(u) n.
real_t ComputeAvgFlux(const Vector &state1, const Vector &state2, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute average flux F̄(u)
real_t ComputeFluxDotN(const Vector &state, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const override
Compute F(u) n.
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(u)
void ComputeFluxJacobian(const Vector &state, ElementTransformation &Tr, DenseTensor &J) const override
Compute J(u)
Component-wise upwinded flux.
ComponentwiseUpwindFlux(const FluxFunction &fluxFunction)
Constructor for a flux function.
void AverageGrad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const override
Jacobian of average normal numerical flux over the interval [u⁻, u⁺] in the second argument of the fl...
real_t Average(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const override
Average normal numerical flux over the interval [u⁻, u⁺] in the second argument of the flux F̂(u⁻,...
void Grad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const override
Jacobian of normal numerical flux F̂(u⁻,u⁺,x) n.
real_t Eval(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const override
Normal numerical flux F̂(u⁻,u⁺,x) n.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
Rank 3 tensor (array of matrices)
Euler flux.
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 EulerFlux FluxFunction with given spatial dimension and specific heat ratio.
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:750
Abstract class for all finite elements.
Definition fe_base.hpp:244
Abstract class for hyperbolic flux for a system of hyperbolic conservation laws.
virtual real_t ComputeAvgFlux(const Vector &state1, const Vector &state2, ElementTransformation &Tr, DenseMatrix &flux_) const
Compute average flux over the given interval of states. Optionally overloaded in a derived class.
virtual real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const
Compute average normal flux over the given interval of states. Optionally overloaded in a derived cla...
FluxFunction(const int num_equations, const int dim)
const int num_equations
virtual ~FluxFunction()
virtual real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const =0
Compute flux F(u, x). Must be implemented in a derived class.
virtual void ComputeFluxJacobian(const Vector &state, ElementTransformation &Tr, DenseTensor &J_) const
Compute flux Jacobian J(u, x). Optionally overloaded in a derived class when Jacobian is necessary (e...
virtual real_t ComputeFluxDotN(const Vector &state, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const
Compute normal flux F(u, x)⋅n. Optionally overloaded in a derived class to avoid creating a full dens...
virtual void ComputeFluxJacobianDotN(const Vector &state, const Vector &normal, ElementTransformation &Tr, DenseMatrix &JDotN) const
Compute normal flux Jacobian J(u, x)⋅n. Optionally overloaded in a derived class to avoid creating a ...
Abstract hyperbolic form integrator, assembling (F(u, x), ∇v) and <F̂(u⁻,u⁺,x) n, [v]> terms for scal...
HyperbolicFormIntegrator(const NumericalFlux &numFlux, const int IntOrderOffset=0, const real_t sign=1.)
Construct a new Hyperbolic Form Integrator object.
const FluxFunction & GetFluxFunction()
void AssembleFaceGrad(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr, const Vector &elfun, DenseMatrix &elmat) override
Implements <-Ĵ(u⁻,u⁺,x) n, [v]> with abstract Ĵ computed by NumericalFlux::Grad() of the numerical ...
void AssembleFaceVector(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr, const Vector &elfun, Vector &elvect) override
Implements <-F̂(u⁻,u⁺,x) n, [v]> with abstract F̂ computed by NumericalFlux::Eval() of the numerical ...
void ResetMaxCharSpeed()
Reset the Max Char Speed 0.
void AssembleElementGrad(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun, DenseMatrix &grad) override
Implements (J(u), ∇v) with abstract J computed by FluxFunction::ComputeFluxJacobian()
void AssembleElementVector(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun, Vector &elvect) override
Implements (F(u), ∇v) with abstract F computed by FluxFunction::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,...
NumericalFlux(const FluxFunction &fluxFunction)
Constructor for a flux function.
virtual ~NumericalFlux()=default
const FluxFunction & fluxFunction
virtual real_t Eval(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const =0
Evaluates normal numerical flux for the given states and normal. Must be implemented in a derived cla...
const FluxFunction & GetFluxFunction() const
Get flux function F.
virtual real_t Average(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const
Evaluates average normal numerical flux over the interval between the given end states in the second ...
virtual void AverageGrad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const
Evaluates Jacobian of the average normal numerical flux over the interval between the given end state...
virtual void Grad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const
Evaluates Jacobian of the normal numerical flux for the given states and normal. Optionally overloade...
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)
Constructor for a flux function.
DenseMatrix JDotN
real_t Average(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const override
Average normal numerical flux over the interval [u⁻, u⁺] in the second argument of the flux F̂(u⁻,...
void Grad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const override
Jacobian of normal numerical flux F̂(u⁻,u⁺,x) n.
void AverageGrad(int side, const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, DenseMatrix &grad) const override
Jacobian of average normal numerical flux over the interval [u⁻, u⁺] in the second argument of the fl...
real_t Eval(const Vector &state1, const Vector &state2, const Vector &nor, FaceElementTransformations &Tr, Vector &flux) const override
Normal numerical flux F̂(u⁻,u⁺,x) n.
Shallow water flux.
ShallowWaterFlux(const int dim, const real_t g=9.8)
Construct a new ShallowWaterFlux FluxFunction with given spatial dimension and gravity constant.
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:82
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:558
real_t b
Definition lissajous.cpp:42
MFEM_DEPRECATED typedef NumericalFlux RiemannSolver
float real_t
Definition config.hpp:43