23 const int IntOrderOffset,
27 fluxFunction(numFlux.GetFluxFunction()),
28 IntOrderOffset(IntOrderOffset),
30 num_equations(fluxFunction.num_equations)
32#ifndef MFEM_THREAD_SAFE
51 const int dof = el.
GetDof();
53#ifdef MFEM_THREAD_SAFE
83 const int order = el.
GetOrder()*2 + IntOrderOffset;
101 max_char_speed = std::max(mcs, max_char_speed);
113 const int dof = el.
GetDof();
115#ifdef MFEM_THREAD_SAFE
146 const int order = el.
GetOrder()*2 + IntOrderOffset;
168 for (
int i = 0; i < dof; i++)
169 for (
int j = 0; j < dof; j++)
170 for (
int d = 0; d < fluxFunction.
dim; d++)
172 grad(di*dof+i, dj*dof+j) += w * dshape(i,d) * shape(j) * J(di,dj,d);
183 const int dof1 = el1.
GetDof();
184 const int dof2 = el2.
GetDof();
186#ifdef MFEM_THREAD_SAFE
222 const int order = 2*std::max(el1.
GetOrder(), el2.
GetOrder()) + IntOrderOffset;
253 const real_t speed = numFlux.
Eval(state1, state2, nor, Tr, fluxN);
256 max_char_speed = std::max(speed, max_char_speed);
270 const int dof1 = el1.
GetDof();
271 const int dof2 = el2.
GetDof();
273#ifdef MFEM_THREAD_SAFE
305 const int order = 2*std::max(el1.
GetOrder(), el2.
GetOrder()) + IntOrderOffset;
338 numFlux.
Grad(1, state1, state2, nor, Tr, JDotN);
347 for (
int j = 0; j < dof1; j++)
350 for (
int i = 0; i < dof1; i++)
352 elmat(i+dof1*di, j+dof1*dj) += w * shape1(i) * shape1(j);
356 for (
int i = 0; i < dof2; i++)
358 elmat(ioff+i+dof2*di, j+dof1*dj) -= w * shape2(i) * shape1(j);
366 numFlux.
Grad(2, state1, state2, nor, Tr, JDotN);
368 const int joff = ioff;
375 for (
int j = 0; j < dof2; j++)
378 for (
int i = 0; i < dof1; i++)
380 elmat(i+dof1*di, joff+j+dof2*dj) += w * shape1(i) * shape2(j);
384 for (
int i = 0; i < dof2; i++)
386 elmat(ioff+i+dof2*di, joff+j+dof2*dj) -= w * shape2(i) * shape2(j);
398#ifdef MFEM_THREAD_SAFE
404 flux.
Mult(normal, FUdotN);
413#ifdef MFEM_THREAD_SAFE
419 flux.
Mult(normal, fluxDotN);
428#ifdef MFEM_THREAD_SAFE
434 JDotN.
Set(normal(0), J(0));
435 for (
int d = 1; d <
dim; d++)
444#ifndef MFEM_THREAD_SAFE
454#ifdef MFEM_THREAD_SAFE
460 const real_t maxE = std::max(speed1, speed2);
465 flux(i) = 0.5*(scaledMaxE*(state1(i) - state2(i)) + (
fluxN1(i) +
fluxN2(i)));
474#ifdef MFEM_THREAD_SAFE
482 const real_t maxE = std::max(speed1, speed2);
492 grad(i,i) += 0.5 * scaledMaxE;
501 grad(i,i) -= 0.5 * scaledMaxE;
510#ifdef MFEM_THREAD_SAFE
517 const real_t maxE = std::max(speed1, speed2);
522 flux(i) = 0.5*(scaledMaxE*(state1(i) - state2(i)) + (
fluxN1(i) +
fluxN2(i)));
532#ifdef MFEM_THREAD_SAFE
536#if defined(MFEM_USE_DOUBLE)
537 constexpr real_t tol = 1e-12;
538#elif defined(MFEM_USE_SINGLE)
539 constexpr real_t tol = 4e-6;
541#error "Only single and double precision are supported!"
542 constexpr real_t tol = 1.;
545 auto equal_check = [=](
real_t a,
real_t b) ->
bool {
return std::abs(
a -
b) <= tol * std::abs(
a +
b); };
549#ifdef MFEM_THREAD_SAFE
560 const real_t maxE = std::max(speed1, speed2);
570 if (equal_check(state1(i), state2(i))) {
continue; }
571 grad(i,i) = 0.5 * ((
fluxN2(i) -
fluxN1(i)) / (state2(i) - state1(i))
572 -
JDotN(i,i) + scaledMaxE);
582 const real_t maxE = std::max(speed1, speed2);
591 if (equal_check(state1(i), state2(i))) {
continue; }
592 grad(i,i) = 0.5 * ((
fluxN2(i) -
fluxN1(i)) / (state2(i) - state1(i))
602#ifndef MFEM_THREAD_SAFE
607 MFEM_WARNING(
"Upwinded flux is implemented only component-wise.")
614#ifdef MFEM_THREAD_SAFE
622 if (state1(i) <= state2(i))
632 return std::max(speed1, speed2);
640#ifdef MFEM_THREAD_SAFE
655 grad(i,i) = std::max(
JDotN(i,i), 0_r);
665 grad(i,i) = std::min(
JDotN(i,i), 0_r);
675#ifdef MFEM_THREAD_SAFE
684 if (state1(i) <= state2(i))
694 return std::max(speed1, speed2);
702#ifdef MFEM_THREAD_SAFE
706#if defined(MFEM_USE_DOUBLE)
707 constexpr real_t tol = 1e-12;
708#elif defined(MFEM_USE_SINGLE)
709 constexpr real_t tol = 4e-6;
711#error "Only single and double precision are supported!"
712 constexpr real_t tol = 1.;
715 auto equal_check = [=](
real_t a,
real_t b) ->
bool {
return std::abs(
a -
b) <= tol * std::abs(
a +
b); };
719#ifdef MFEM_THREAD_SAFE
734 const real_t gr12 = (!equal_check(state1(i), state2(i)))?
737 grad(i,i) = (gr12 >= 0.)?(
JDotN(i,i)):(gr12);
742#ifdef MFEM_THREAD_SAFE
749 bool J_needed =
false;
751 if (equal_check(state1(i), state2(i)))
769 const real_t gr12 = (!equal_check(state1(i), state2(i)))?
772 grad(i,i) = std::min(gr12, 0_r);
781#ifdef MFEM_THREAD_SAFE
794#ifdef MFEM_THREAD_SAFE
798 FDotN(0) = U(0) * (bval * normal);
806#ifdef MFEM_THREAD_SAFE
811 Uavg(0) = (U1(0) + U2(0)) * 0.5;
821#ifdef MFEM_THREAD_SAFE
825 FDotN(0) = (U1(0) + U2(0)) * 0.5 * (bval * normal);
833#ifdef MFEM_THREAD_SAFE
838 for (
int d = 0; d <
dim; d++)
849#ifdef MFEM_THREAD_SAFE
853 JDotN(0,0) = bval * normal;
860 FU = U(0) * U(0) * 0.5;
861 return std::fabs(U(0));
869 FDotN(0) = U(0) * U(0) * 0.5 * normal.
Sum();
870 return std::fabs(U(0));
878 FU = (U1(0)*U1(0) + U1(0)*U2(0) + U2(0)*U2(0)) / 6.;
879 return std::max(std::fabs(U1(0)), std::fabs(U2(0)));
888 FDotN(0) = (U1(0)*U1(0) + U1(0)*U2(0) + U2(0)*U2(0)) / 6. * normal.
Sum();
889 return std::max(std::fabs(U1(0)), std::fabs(U2(0)));
897 for (
int d = 0; d <
dim; d++)
908 JDotN(0,0) = U(0) * normal.
Sum();
915 const real_t height = U(0);
918 const real_t energy = 0.5 * g * (height * height);
920 MFEM_ASSERT(height >= 0,
"Negative Height");
922 for (
int d = 0; d <
dim; d++)
925 for (
int i = 0; i <
dim; i++)
927 FU(1 + i, d) = h_vel(i) * h_vel(d) / height;
929 FU(1 + d, d) += energy;
932 const real_t sound = std::sqrt(g * height);
933 const real_t vel = std::sqrt(h_vel * h_vel) / height;
944 const real_t height = U(0);
947 const real_t energy = 0.5 * g * (height * height);
949 MFEM_ASSERT(height >= 0,
"Negative Height");
950 FUdotN(0) = h_vel * normal;
951 const real_t normal_vel = FUdotN(0) / height;
952 for (
int i = 0; i <
dim; i++)
954 FUdotN(1 + i) = normal_vel * h_vel(i) + energy * normal(i);
957 const real_t sound = std::sqrt(g * height);
958 const real_t vel = std::fabs(normal_vel) / std::sqrt(normal*normal);
969 const real_t density = U(0);
972 const real_t kinetic_energy = 0.5 * (momentum*momentum) / density;
974 const real_t pressure = (specific_heat_ratio - 1.0) *
975 (energy - kinetic_energy);
978 MFEM_ASSERT(density >= 0,
"Negative Density");
979 MFEM_ASSERT(pressure >= 0,
"Negative Pressure");
980 MFEM_ASSERT(energy >= 0,
"Negative Energy");
983 for (
int d = 0; d <
dim; d++)
985 FU(0, d) = momentum(d);
986 for (
int i = 0; i <
dim; i++)
989 FU(1 + i, d) = momentum(i) * momentum(d) / density;
992 FU(1 + d, d) += pressure;
995 const real_t H = (energy + pressure) / density;
996 for (
int d = 0; d <
dim; d++)
999 FU(1 +
dim, d) = momentum(d) * H;
1005 const real_t sound = std::sqrt(specific_heat_ratio * pressure / density);
1007 const real_t speed = std::sqrt(2.0 * kinetic_energy / density);
1009 return speed + sound;
1019 const real_t density = x(0);
1022 const real_t kinetic_energy = 0.5 * (momentum*momentum) / density;
1024 const real_t pressure = (specific_heat_ratio - 1.0) *
1025 (energy - kinetic_energy);
1028 MFEM_ASSERT(density >= 0,
"Negative Density");
1029 MFEM_ASSERT(pressure >= 0,
"Negative Pressure");
1030 MFEM_ASSERT(energy >= 0,
"Negative Energy");
1034 FUdotN(0) = momentum * normal;
1036 const real_t normal_velocity = FUdotN(0) / density;
1037 for (
int d = 0; d <
dim; d++)
1040 FUdotN(1 + d) = normal_velocity * momentum(d) + pressure * normal(d);
1043 FUdotN(1 +
dim) = normal_velocity * (energy + pressure);
1048 const real_t sound = std::sqrt(specific_heat_ratio * pressure / density);
1050 const real_t speed = std::fabs(normal_velocity) / std::sqrt(normal*normal);
1052 return speed + sound;
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.
real_t ComputeAvgFluxDotN(const Vector &state1, const Vector &state2, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxDotN) const override
Compute average flux F̄(u) n.
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)
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.
void Mult(const real_t *x, real_t *y) const
Matrix vector multiplication.
void Set(real_t alpha, const real_t *A)
Set the matrix to alpha * A, assuming that A has the same dimensions as the matrix and uses column-ma...
void MultTranspose(const real_t *x, real_t *y) const
Multiply a vector with the transpose matrix.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
void AddMatrix(DenseMatrix &A, int ro, int co)
Perform (ro+i,co+j)+=A(i,j) for 0<=i.
Rank 3 tensor (array of matrices)
void SetSize(int i, int j, int k, MemoryType mt_=MemoryType::PRESERVE)
real_t ComputeFlux(const Vector &state, ElementTransformation &Tr, DenseMatrix &flux) const override
Compute F(ρ, ρu, E)
real_t ComputeFluxDotN(const Vector &x, const Vector &normal, FaceElementTransformations &Tr, Vector &fluxN) const override
Compute normal flux, F(ρ, ρu, E)n.
Abstract class for all finite elements.
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
void CalcPhysDShape(ElementTransformation &Trans, DenseMatrix &dshape) const
Evaluate the gradients of all shape functions of a scalar finite element in physical space at the poi...
int GetDim() const
Returns the reference space dimension for the finite element.
virtual void CalcShape(const IntegrationPoint &ip, Vector &shape) const =0
Evaluate the values of all shape functions of a scalar finite element in reference space at the given...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
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...
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 ...
Class for integration point with weight.
Class for an integration rule - an Array of IntegrationPoint.
int GetNPoints() const
Returns the number of the points in the integration rule.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
const IntegrationRule * IntRule
Abstract class for numerical flux for a system of hyperbolic conservation laws on a face with states,...
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...
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...
RusanovFlux(const FluxFunction &fluxFunction)
Constructor for a flux function.
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.
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)
int GetVDim()
Returns dimension of the vector.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
real_t Norml2() const
Returns the l2 norm of the vector.
int Size() const
Returns the size of the vector.
real_t Sum() const
Return the sum of the vector entries.
void SetSize(int s)
Resize the vector to size s.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
void CalcOrtho(const DenseMatrix &J, Vector &n)
void AddMult_a_ABt(real_t a, const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &ABt)
ABt += a * A * B^t.
void MultVWt(const Vector &v, const Vector &w, DenseMatrix &VWt)
void AddMult_a_VWt(const real_t a, const Vector &v, const Vector &w, DenseMatrix &VWt)
VWt += a * v w^t.
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
void vel(const Vector &x, real_t t, Vector &u)