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"
15
16namespace Theseus
17{
18 class RHSOperatorBase : public mfem::TimeDependentOperator,
19 public mfem::ParNonlinearForm
20 {
21 protected:
22 mutable mfem::real_t max_char_speed;
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 GetMaxCharSpeed() const
92 {
93 return max_char_speed;
94 }
95
96 inline mfem::real_t& GetTimeRef()
97 {
98 return t;
99 }
100 virtual void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const
101 { std::cout << "RHSOperatorBase::ComputeIntegralMeasures empty." << std::endl; }
102 virtual void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
103 { std::cout << "RHSOperatorBase::Mult empty." << std::endl; }
104 virtual std::string GasModelName() const {
105 return std::string("RHSOperatorBase::GasModel: NONE");
106 }
107 virtual std::string NumFluxName() const {
108 return std::string("RHSOperatorBase::NumFlux: NONE");
109 }
110 virtual std::string FlowModelName() const {
111 return std::string("RHSOperatorBase::FlowModel: NONE");
112 }
114 {
115 MFEM_ABORT("RHSOperatorBase::GetGasModelInterface() called on base class.");
116 }
117 };
118
119 template<typename PhysicsT>
121 {
122 public:
123 using Physics = PhysicsT;
126 using Gas = typename Physics::GasModel;
127 using InviscidFlux = typename Physics::InviscidFlux;
128 protected:
131 const std::string gasModelName;
132 const std::string numFluxName;
133 const std::string flowModelName;
134 std::shared_ptr<const Gas> gas;
135 std::shared_ptr<const GasModelInterface> gas_interface;
136 public:
137 RHSOperator(std::shared_ptr<mfem::ParFiniteElementSpace> vfes_,
138 std::shared_ptr<mfem::ParFiniteElementSpace> fes0_,
139 std::shared_ptr<mfem::ParMesh> pmesh_,
140 std::shared_ptr<mfem::ParGridFunction> eta_,
141 std::shared_ptr<mfem::ParGridFunction> alpha_,
142 std::shared_ptr<Prandtl::PerssonPeraireIndicator> indicator_,
143 std::shared_ptr<const Gas> gas_,
144 const std::string &gasModelName_,
145 const std::string &numFluxName_,
146 const std::string &flowModelName_,
147 const mfem::real_t alpha_max = 0.5, const mfem::real_t alpha_min = 0.001)
148 : RHSOperatorBase(vfes_, fes0_, pmesh_, eta_, alpha_,
149 indicator_, alpha_max, alpha_min),
150 gasModelName(gasModelName_), numFluxName(numFluxName_),
151 flowModelName(flowModelName_), 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 void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const override;
171 virtual mfem::real_t FlowMult(const mfem::Vector &pu, mfem::Vector &pdudt) const = 0;
172
173 std::string GasModelName() const override { return gasModelName; }
174 std::string NumFluxName() const override { return numFluxName; }
175 std::string FlowModelName() const override { return flowModelName; }
176
177 const Gas &GetGasModel() const { return *gas; };
179 {
180 return *gas_interface;
181 }
182 void FetchRestrictions(const mfem::Vector &pu, mfem::Vector &uVol,
183 mfem::Vector &uInt, mfem::Vector &uBnd) const;
184 };
185
186}
187
188#include "RHSOperator_impl.hpp"
Definition GasModel.hpp:262
Definition GasModel.hpp:235
Definition RHSOperator.hpp:20
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:110
const int dim
Definition RHSOperator.hpp:29
const mfem::real_t sharpness_fac
Definition RHSOperator.hpp:33
virtual std::string NumFluxName() const
Definition RHSOperator.hpp:107
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:113
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
mfem::real_t max_char_speed
Definition RHSOperator.hpp:22
virtual void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
Definition RHSOperator.hpp:102
mfem::Vector bc_scalar_data
Definition RHSOperator.hpp:41
mfem::real_t GetMaxCharSpeed() const
Definition RHSOperator.hpp:91
mfem::Vector bc_vector_data
Definition RHSOperator.hpp:40
mfem::real_t & GetTimeRef()
Definition RHSOperator.hpp:96
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:104
std::shared_ptr< Prandtl::PerssonPeraireIndicator > indicator
Definition RHSOperator.hpp:27
virtual void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const
Definition RHSOperator.hpp:100
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:121
PhysicsT Physics
Definition RHSOperator.hpp:123
const std::string flowModelName
Definition RHSOperator.hpp:133
const std::string numFluxName
Definition RHSOperator.hpp:132
DeviceCache device_cache
Definition RHSOperator.hpp:130
std::shared_ptr< const Gas > gas
Definition RHSOperator.hpp:134
const GasModelInterface & GetGasModelInterface() const override
Definition RHSOperator.hpp:178
OperatorCache & GetOperatorCacheReference()
Definition RHSOperator.hpp:158
void Mult(const mfem::Vector &u, mfem::Vector &dudt) const override
Definition RHSOperator_impl.hpp:397
std::string NumFluxName() const override
Definition RHSOperator.hpp:174
std::shared_ptr< const GasModelInterface > gas_interface
Definition RHSOperator.hpp:135
void FetchRestrictions(const mfem::Vector &pu, mfem::Vector &uVol, mfem::Vector &uInt, mfem::Vector &uBnd) const
Definition RHSOperator_impl.hpp:39
void Finalize(mfem::real_t time=0) override
Definition RHSOperator_impl.hpp:11
OperatorCache operator_cache
Definition RHSOperator.hpp:129
virtual mfem::real_t 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:137
virtual ~RHSOperator()=default
std::string FlowModelName() const override
Definition RHSOperator.hpp:175
typename Physics::GasModel Gas
Definition RHSOperator.hpp:126
typename Physics::InviscidFlux InviscidFlux
Definition RHSOperator.hpp:127
void ComputeIntegralMeasures(const mfem::Vector &u, Theseus::IntegralMeasures &diag) const override
Definition RHSOperator_impl.hpp:208
const Gas & GetGasModel() const
Definition RHSOperator.hpp:177
std::string GasModelName() const override
Definition RHSOperator.hpp:173
const std::string gasModelName
Definition RHSOperator.hpp:131
Definition AxisymmetricGeometry.hpp:15
Definition json.hpp:5363
std::shared_ptr< mfem::ParGridFunction > alpha
Definition dgsem_cache.hpp:151
OperatorGasModel gas
Definition dgsem_cache.hpp:126
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