Theseus
Compressible flow solver
Loading...
Searching...
No Matches
RHSOperator.hpp
Go to the documentation of this file.
1// Copyright (c) 2025-2026 Board of Trustees of the University of Illinois
2//
3// This file is part of Theseus.
4//
5// SPDX-License-Identifier: BSD-3-Clause
6#pragma once
7
8#include "DGSEMIntegrator.hpp"
10#include "ModalBasis.hpp"
12#include "GasModel.hpp"
13#include "StabilityEstimate.hpp"
16
17namespace Theseus
18{
19 class RHSOperatorBase : public mfem::TimeDependentOperator,
20 public mfem::ParNonlinearForm
21 {
22 protected:
23 std::shared_ptr<mfem::ParFiniteElementSpace> vfes;
24 std::shared_ptr<mfem::ParFiniteElementSpace> fes0;
25 std::shared_ptr<mfem::ParMesh> pmesh;
26 std::shared_ptr<mfem::ParGridFunction> eta;
27 std::shared_ptr<Prandtl::PerssonPeraireIndicator> indicator;
28
30 const int num_dofs_scalar;
31 const int Ndofs;
32
33 const mfem::real_t sharpness_fac = 9.21024;
34 const mfem::real_t modalThreshold;
35 const mfem::real_t alpha_min;
36 const mfem::real_t alpha_max;
37
38 std::vector<mfem::Array<int>> bdr_marker;
39 mfem::Array<Theseus::BCDescriptor> bc_descriptors;
40 mfem::Vector bc_vector_data;
41 mfem::Vector bc_scalar_data;
42
43 mutable mfem::real_t alpha_dof;
45 public:
46 RHSOperatorBase(std::shared_ptr<mfem::ParFiniteElementSpace> vfes_,
47 std::shared_ptr<mfem::ParFiniteElementSpace> fes0_,
48 std::shared_ptr<mfem::ParMesh> pmesh_,
49 std::shared_ptr<mfem::ParGridFunction> eta_,
50 std::shared_ptr<mfem::ParGridFunction> alpha_,
51 std::shared_ptr<Prandtl::PerssonPeraireIndicator> indicator_,
52 const mfem::real_t alpha_max = 0.5, const mfem::real_t alpha_min = 0.001)
53 : mfem::TimeDependentOperator(vfes_->GetTrueVSize()),
54 mfem::ParNonlinearForm(vfes_.get()),
55 vfes(vfes_), fes0(fes0_), pmesh(pmesh_),
56 eta(eta_), indicator(indicator_),
57 num_equations(vfes->GetVDim()),
58 dim(pmesh->SpaceDimension()),
59 order(vfes->GetElementOrder(0)),
60 num_elements(pmesh->GetNE()),
61 num_dofs_scalar(vfes_->GetTrueVSize()/vfes_->GetVDim()),
62 Ndofs(vfes->GetFE(0)->GetDof()),
63 modalThreshold(0.5 * std::pow(10.0, -1.8 * std::pow(order, 0.25))),
65 {
66 diag0.mass = 0.0;
67 diag0.ke = 0.0;
68 diag0.en = 0.0;
69 }
70 virtual ~RHSOperatorBase() = default;
71 void SetBCDescriptorData(const mfem::Array<Theseus::BCDescriptor> &bc_descr, const mfem::Vector &bc_scalar_dat,
72 const mfem::Vector &bc_vector_dat)
73 {
74 bc_descriptors = bc_descr;
75 bc_scalar_data = bc_scalar_dat;
76 bc_vector_data = bc_vector_dat;
77 }
78
79 void AddBdrFaceMarker(mfem::Array<int> &bdr_marker_)
80 {
81 bdr_marker.push_back(bdr_marker_);
82 }
83
84 virtual void Finalize(mfem::real_t time=0)
85 {
86 SetTime(time);
87 }
88
90
91 inline mfem::real_t& GetTimeRef()
92 {
93 return t;
94 }
95 virtual void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const
96 { std::cout << "RHSOperatorBase::ComputeIntegralMeasures empty." << std::endl; }
97 virtual void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
98 { std::cout << "RHSOperatorBase::Mult empty." << std::endl; }
99 virtual StabilityEstimate EstimateStability(const mfem::Vector &u) const
100 { MFEM_ABORT("RHSOperatorBase::EstimateStability called on base class."); }
101 virtual std::string GasModelName() const {
102 return std::string("RHSOperatorBase::GasModel: NONE");
103 }
104 virtual std::string NumFluxName() const {
105 return std::string("RHSOperatorBase::NumFlux: NONE");
106 }
107 virtual std::string FlowModelName() const {
108 return std::string("RHSOperatorBase::FlowModel: NONE");
109 }
111 {
112 MFEM_ABORT("RHSOperatorBase::GetGasModelInterface() called on base class.");
113 }
114 };
115
116 template<typename PhysicsT>
118 {
119 public:
120 using Physics = PhysicsT;
123 using Gas = typename Physics::GasModel;
124 using InviscidFlux = typename Physics::InviscidFlux;
125 protected:
128 const std::string gasModelName;
129 const std::string numFluxName;
130 const std::string flowModelName;
132 std::shared_ptr<const Gas> gas;
133 std::shared_ptr<const GasModelInterface> gas_interface;
134 public:
135 RHSOperator(std::shared_ptr<mfem::ParFiniteElementSpace> vfes_,
136 std::shared_ptr<mfem::ParFiniteElementSpace> fes0_,
137 std::shared_ptr<mfem::ParMesh> pmesh_,
138 std::shared_ptr<mfem::ParGridFunction> eta_,
139 std::shared_ptr<mfem::ParGridFunction> alpha_,
140 std::shared_ptr<Prandtl::PerssonPeraireIndicator> indicator_,
141 std::shared_ptr<const Gas> gas_,
142 const std::string &gasModelName_,
143 const std::string &numFluxName_,
144 const std::string &flowModelName_,
145 const mfem::real_t alpha_max = 0.5, const mfem::real_t alpha_min = 0.001)
146 : RHSOperatorBase(vfes_, fes0_, pmesh_, eta_, alpha_,
147 indicator_, alpha_max, alpha_min),
148 gasModelName(gasModelName_), numFluxName(numFluxName_),
149 flowModelName(flowModelName_),
150 viscousFlowModel(flowModelName_ == "NavierStokes"),
151 gas(std::move(gas_)),
153 {
155 operator_cache.alpha = alpha_;
156 }
157
159
160 virtual ~RHSOperator() = default;
161 void Finalize(mfem::real_t time = 0) override;
162
163#ifdef SUBCELL_FV_BLENDING
164 void ComputeBlendingCoefficient() const;
165 void CheckIndicatorSmoothness() const;
166 void ComputeIndicatorField(const mfem::Vector &u) const;
167#endif
168
169 void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override;
170 StabilityEstimate EstimateStability(const mfem::Vector &u) const override;
171 void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const override;
172 virtual void FlowMult(const mfem::Vector &pu, mfem::Vector &pdudt) const = 0;
173
174 std::string GasModelName() const override { return gasModelName; }
175 std::string NumFluxName() const override { return numFluxName; }
176 std::string FlowModelName() const override { return flowModelName; }
177
178 const Gas &GetGasModel() const { return *gas; };
180 {
181 return *gas_interface;
182 }
183 void FetchRestrictions(const mfem::Vector &pu, mfem::Vector &uVol,
184 mfem::Vector &uInt, mfem::Vector &uBnd) const;
185 };
186
187}
188
189#include "RHSOperator_impl.hpp"
Definition GasModel.hpp:262
Definition GasModel.hpp:235
Definition RHSOperator.hpp:21
mfem::real_t alpha_dof
Definition RHSOperator.hpp:43
void AddBdrFaceMarker(mfem::Array< int > &bdr_marker_)
Definition RHSOperator.hpp:79
virtual std::string FlowModelName() const
Definition RHSOperator.hpp:107
const int dim
Definition RHSOperator.hpp:29
virtual StabilityEstimate EstimateStability(const mfem::Vector &u) const
Definition RHSOperator.hpp:99
const mfem::real_t sharpness_fac
Definition RHSOperator.hpp:33
virtual std::string NumFluxName() const
Definition RHSOperator.hpp:104
Theseus::IntegralMeasures diag0
Definition RHSOperator.hpp:44
std::vector< mfem::Array< int > > bdr_marker
Definition RHSOperator.hpp:38
const mfem::real_t alpha_min
Definition RHSOperator.hpp:35
virtual const GasModelInterface & GetGasModelInterface() const
Definition RHSOperator.hpp:110
std::shared_ptr< mfem::ParMesh > pmesh
Definition RHSOperator.hpp:25
mfem::Array< Theseus::BCDescriptor > bc_descriptors
Definition RHSOperator.hpp:39
const int num_dofs_scalar
Definition RHSOperator.hpp:30
std::shared_ptr< mfem::ParFiniteElementSpace > fes0
Definition RHSOperator.hpp:24
virtual void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
Definition RHSOperator.hpp:97
mfem::Vector bc_scalar_data
Definition RHSOperator.hpp:41
mfem::Vector bc_vector_data
Definition RHSOperator.hpp:40
mfem::real_t & GetTimeRef()
Definition RHSOperator.hpp:91
RHSOperatorBase(std::shared_ptr< mfem::ParFiniteElementSpace > vfes_, std::shared_ptr< mfem::ParFiniteElementSpace > fes0_, std::shared_ptr< mfem::ParMesh > pmesh_, std::shared_ptr< mfem::ParGridFunction > eta_, std::shared_ptr< mfem::ParGridFunction > alpha_, std::shared_ptr< Prandtl::PerssonPeraireIndicator > indicator_, const mfem::real_t alpha_max=0.5, const mfem::real_t alpha_min=0.001)
Definition RHSOperator.hpp:46
virtual void Finalize(mfem::real_t time=0)
Definition RHSOperator.hpp:84
const mfem::real_t modalThreshold
Definition RHSOperator.hpp:34
virtual std::string GasModelName() const
Definition RHSOperator.hpp:101
std::shared_ptr< Prandtl::PerssonPeraireIndicator > indicator
Definition RHSOperator.hpp:27
virtual void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const
Definition RHSOperator.hpp:95
virtual ~RHSOperatorBase()=default
IntegralMeasures GetIntegralMeasuresBaseline() const
Definition RHSOperator.hpp:89
std::shared_ptr< mfem::ParFiniteElementSpace > vfes
Definition RHSOperator.hpp:23
std::shared_ptr< mfem::ParGridFunction > eta
Definition RHSOperator.hpp:26
const int Ndofs
Definition RHSOperator.hpp:31
const int num_elements
Definition RHSOperator.hpp:29
const int order
Definition RHSOperator.hpp:29
const int num_equations
Definition RHSOperator.hpp:29
void SetBCDescriptorData(const mfem::Array< Theseus::BCDescriptor > &bc_descr, const mfem::Vector &bc_scalar_dat, const mfem::Vector &bc_vector_dat)
Definition RHSOperator.hpp:71
const mfem::real_t alpha_max
Definition RHSOperator.hpp:36
Definition RHSOperator.hpp:118
PhysicsT Physics
Definition RHSOperator.hpp:120
const std::string flowModelName
Definition RHSOperator.hpp:130
const std::string numFluxName
Definition RHSOperator.hpp:129
DeviceCache device_cache
Definition RHSOperator.hpp:127
std::shared_ptr< const Gas > gas
Definition RHSOperator.hpp:132
const GasModelInterface & GetGasModelInterface() const override
Definition RHSOperator.hpp:179
OperatorCache & GetOperatorCacheReference()
Definition RHSOperator.hpp:158
void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
Definition RHSOperator_impl.hpp:697
std::string NumFluxName() const override
Definition RHSOperator.hpp:175
std::shared_ptr< const GasModelInterface > gas_interface
Definition RHSOperator.hpp:133
void FetchRestrictions(const mfem::Vector &pu, mfem::Vector &uVol, mfem::Vector &uInt, mfem::Vector &uBnd) const
Definition RHSOperator_impl.hpp:295
StabilityEstimate EstimateStability(const mfem::Vector &u) const override
Definition RHSOperator_impl.hpp:10
void Finalize(mfem::real_t time=0) override
Definition RHSOperator_impl.hpp:267
OperatorCache operator_cache
Definition RHSOperator.hpp:126
virtual void FlowMult(const mfem::Vector &pu, mfem::Vector &pdudt) const =0
RHSOperator(std::shared_ptr< mfem::ParFiniteElementSpace > vfes_, std::shared_ptr< mfem::ParFiniteElementSpace > fes0_, std::shared_ptr< mfem::ParMesh > pmesh_, std::shared_ptr< mfem::ParGridFunction > eta_, std::shared_ptr< mfem::ParGridFunction > alpha_, std::shared_ptr< Prandtl::PerssonPeraireIndicator > indicator_, std::shared_ptr< const Gas > gas_, const std::string &gasModelName_, const std::string &numFluxName_, const std::string &flowModelName_, const mfem::real_t alpha_max=0.5, const mfem::real_t alpha_min=0.001)
Definition RHSOperator.hpp:135
virtual ~RHSOperator()=default
std::string FlowModelName() const override
Definition RHSOperator.hpp:176
typename Physics::GasModel Gas
Definition RHSOperator.hpp:123
typename Physics::InviscidFlux InviscidFlux
Definition RHSOperator.hpp:124
void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const override
Definition RHSOperator_impl.hpp:508
const Gas & GetGasModel() const
Definition RHSOperator.hpp:178
const bool viscousFlowModel
Definition RHSOperator.hpp:131
std::string GasModelName() const override
Definition RHSOperator.hpp:174
const std::string gasModelName
Definition RHSOperator.hpp:128
Definition AxisymmetricGeometry.hpp:15
Definition json.hpp:5363
std::shared_ptr< mfem::ParGridFunction > alpha
Definition dgsem_cache.hpp:154
OperatorGasModel gas
Definition dgsem_cache.hpp:129
Definition dgsem_cache.hpp:16
mfem::real_t en
Definition dgsem_cache.hpp:19
mfem::real_t mass
Definition dgsem_cache.hpp:17
mfem::real_t ke
Definition dgsem_cache.hpp:18
Definition StabilityEstimate.hpp:24