Nektar++
Loading...
Searching...
No Matches
edesign/EquationSystems/NavierStokesCFE.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NavierStokesCFE.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Navier-Stokes equations in conservative variables without
32// artificial diffusion
33//
34///////////////////////////////////////////////////////////////////////////////
35
37
56#include <SolverCore/AdvDiffusion/AdvWeakDGDiffusionIP/AdvWeakDGDiffusionIPOp.hpp>
57#include <SolverCore/TimeOps/TimeOp.hpp>
58
59namespace Nektar
60{
61using namespace MultiRegions;
62
65 "NavierStokesCFE", NavierStokesCFE::create,
66 "Navier-Stokes equations in conservative variables.");
67
71 : UnsteadySystem(pSession, pGraph)
72{
73 ASSERTL0(m_projectionType == MultiRegions::eDiscontinuous,
74 "The NavierStokesCFE is only implemented for projectionType "
75 "Discontinuous");
76}
77
78/**
79 * @brief Initialisation object for the Navier-Stokes equations in conservative
80 * variables.
81 */
82void NavierStokesCFE::v_InitObject(bool declareExpansionLists)
83{
84 // Call to the initialisation object of EquationSystem
85 UnsteadySystem::v_InitObject(declareExpansionLists);
86
87 ASSERTL0(m_session->DefinesSolverInfo("UPWINDTYPE"),
88 "No UPWINDTYPE defined in session.");
89
90 /// Create Fields for solution m_phys, m_coeff and others
91 v_InitialiseFields();
92
93 // Create and initialise all operators
94 v_InitialiseOperators();
95}
96
97void NavierStokesCFE::v_GenerateSummary(SummaryList &s)
98{
99 UnsteadySystem::v_GenerateSummary(s);
100
101 AddSummaryItem(s, "Equations", "Compressible Navier-Stokes");
102 AddSummaryItem(s, "Formulation", "Explicit");
103
104 std::stringstream ss;
105 ss << R"(
106 _ _ _ _
107| \ | | | | | | _ _
108| \| | ___| | _| |_ __ _ _ __ _| |_ _| |_
109| . ` |/ _ \ |/ / __/ _` | '__|_ _|_ _|
110| |\ | __/ <| || (_| | | |_| |_|
111\_| \_/\___|_|\_\\__\__,_|_|
112 _ _ _
113 | | (_) | |
114 _ __ ___ __| | ___ ___ _ __ _ _ __ ___ __| |
115| '__/ _ \/ _` |/ _ \/ __| |/ _` | '_ \ / _ \/ _` |
116| | | __/ (_| | __/\__ \ | (_| | | | | __/ (_| |
117|_| \___|\__,_|\___||___/_|\__, |_| |_|\___|\__,_|
118 __/ |
119 |___/
120)";
121 AddSummaryItem(s, "Redesign disclaimer", ss.str());
122}
123
124/**
125 * @brief Assemble the explicit Navier-Stokes increment.
126 *
127 * The field-based TimeOp stores stage increments, so this routine returns
128 * dt * RHS rather than the unscaled RHS. The explicit conservative
129 * Navier-Stokes RHS is
130 *
131 * RHS = -advection + diffusion.
132 *
133 * The diffusion operator is applied in append mode so its final backward
134 * transform accumulates directly into the advective contribution.
135 */
136void NavierStokesCFE::DoOdeRhs(
138 LibUtilities::Field<double, FieldState::Phys> &out, const double &time,
139 const double &dt)
140{
141 // out = dt * (-advection + diffusion)
142 m_advDiffusionOp->UpdateBndPhys(time);
143 m_advDiffusionOp->SetScale(dt);
144 m_advDiffusionOp->Apply(in, out);
145}
146
147/**
148 * @brief Project onto the solution space, which for DG is a copy.
149 */
150void NavierStokesCFE::DoProjection(
153 [[maybe_unused]] const double &time)
154{
155 if (&in != &out)
156 {
157 m_math.copy(in, out);
158 }
159}
160
161/*
162 * Create and initialise all operators for this solver
163 */
164void NavierStokesCFE::v_InitialiseOperators()
165{
166 // Element-local projection of the solution to coefficients for output.
167 m_iProductWRTBaseOp =
168 IProductWRTBaseOp<double>::Create(m_expansionLists[0], m_variables[0]);
169 m_multiplyByElmtInvMassOp = MultiplyByElmtInvMassOp<double>::Create(
170 m_expansionLists[0], m_variables[0]);
171
172 std::string execName =
174
175 // Create advection operators
177 m_expansionLists[0], m_variables[0]);
178
179 std::string riemannMethod = m_session->GetSolverInfo("UpwindType");
180
181 std::string EqnOfState =
182 StringUtils::ToUpperCopy(m_session->GetEquationOfState().type);
183
184 std::string AdvDiffMethod = "AdvDiffTraceFluxCFE" + riemannMethod +
185 EqnOfState; // add prefix for local version
186 auto advDiffusionTraceFluxOp = SolverCore::TraceFluxOp<double>::Create(
187 m_expansionLists[0], m_variables[0], AdvDiffMethod);
188 advDiffusionTraceFluxOp->SetViscousTraceForm(ReadViscousTraceForm());
189 m_advDiffusionOp->SetAdvDiffTraceFlux(advDiffusionTraceFluxOp);
190
191 auto eulerVolFluxOp =
192 EulerVolumeFluxOp<double>::Create(m_expansionLists[0], m_variables[0]);
193 m_advDiffusionOp->SetAdvVolFlux(eulerVolFluxOp);
194
195 auto diffusionVolFluxOp = DiffusionCFEVolFluxOp<double>::Create(
196 m_expansionLists[0], m_variables[0]);
197 m_advDiffusionOp->SetDiffVolFlux(diffusionVolFluxOp);
198
199 // The average-of-normal-fluxes form needs the viscous flux on its own as
200 // well as the total; the CFE operator forms both in one pass.
201 const bool avgNormalFlux =
202 advDiffusionTraceFluxOp->GetViscousTraceForm() ==
204 double>::ViscousTraceForm::AverageOfNormalFluxes;
205 if (avgNormalFlux)
206 {
207 m_advDiffusionOp->SetAdvDiffVolFlux(AdvDiffCFEVolFluxOp<double>::Create(
208 m_expansionLists[0], m_variables[0]));
209 }
210
211 // The element-local part of the right-hand side in one pass, as
212 // SOLVERINFO FusedElmt selects; it needs the average-of-normal-
213 // fluxes form.
214 m_advDiffusionOp->SetFusedElmtOp(
215 CreateAdvDiffFusedElmtCFEOp<SolverCore::AdvDiffFusedElmtOp>(
216 m_expansionLists[0], m_variables[0], avgNormalFlux,
217 "needs ViscousTraceFlux=AverageOfNormalFluxes."));
218
219 // Configure Time-integration
220 m_timeOp = TimeOp<double>::Create(m_expansionLists[0], m_variables[0]);
221 m_timeOp->DefineProjection(&NavierStokesCFE::DoProjection, this);
222 m_timeOp->DefineExplicitRhs(&NavierStokesCFE::DoOdeRhs, this);
223
224 SetUpBoundaryConditions();
225}
226
227/**
228 * @brief The viscous trace form SOLVERINFO ViscousTraceFlux selects.
229 *
230 * FluxOfAverages (default) evaluates the viscous trace flux from the
231 * averaged state and gradient; AverageOfNormalFluxes averages the two
232 * elements' own normal viscous fluxes. Both add the same interior-penalty
233 * term, and boundary traces keep the first form in either case.
234 */
236 ReadViscousTraceForm()
237{
239 std::string form;
240 m_session->LoadSolverInfo("ViscousTraceFlux", form, "FluxOfAverages");
241 if (StringUtils::IEquals(form, "AverageOfNormalFluxes"))
242 {
243 return Form::AverageOfNormalFluxes;
244 }
245 ASSERTL0(StringUtils::IEquals(form, "FluxOfAverages"),
246 "Unknown ViscousTraceFlux '" + form +
247 "'; expected FluxOfAverages or AverageOfNormalFluxes.");
248 return Form::FluxOfAverages;
249}
250
251CoefficientFieldViews NavierStokesCFE::v_GetOutputFieldViews()
252{
253 // The solution is advanced in physical space, so project back to
254 // coefficients before exposing it to output filters, through the
255 // element-local L2 projection required by the restart path.
256 m_iProductWRTBaseOp->Apply(m_phys[0], m_wsp_coeff[0]);
257 m_multiplyByElmtInvMassOp->Apply(m_wsp_coeff[0], m_coeff[0]);
258
259 return UnsteadySystem::v_GetOutputFieldViews();
260}
261
262/**
263 * @brief Attach the boundary conditions this system supports.
264 *
265 * Each operator claims only the regions carrying its tag and costs nothing
266 * when there are none, so all of them are attached unconditionally.
267 */
268void NavierStokesCFE::SetUpBoundaryConditions()
269{
270 // Viscous wall states are functions of the interior trace rather than of
271 // the session, so they are recomputed each apply and written into the same
272 // boundary storage the trace flux gathers from. Attached unconditionally:
273 // the operator claims only the regions tagged as walls and costs nothing
274 // when there are none.
275 auto bndCondWallOp =
276 BndCondWallCFEOp<double>::Create(m_expansionLists[0], m_variables[0]);
277 m_advDiffusionOp->AddBndCondUpdateOp(bndCondWallOp);
278
279 // Likewise for a pressure outflow, which extrapolates the interior state
280 // and imposes only the static pressure. Each of these claims its own
281 // regions by USERDEFINEDTYPE, so attaching both is not a conflict.
282 auto bndCondPressureOutflowOp = BndCondPressureOutflowCFEOp<double>::Create(
283 m_expansionLists[0], m_variables[0]);
284 m_advDiffusionOp->AddBndCondUpdateOp(bndCondPressureOutflowOp);
285
286 // And for the entropy inflow, which is a condition on the inviscid state
287 // and so belongs on both this path and the Euler one.
288 auto bndCondEntropyVelocityOp =
290 m_variables[0]);
291 m_advDiffusionOp->AddBndCondUpdateOp(bndCondEntropyVelocityOp);
292
293 // Its two siblings, which fill the same degree of freedom with the
294 // pressure or the total enthalpy instead.
295 auto bndCondEntropyPressureOp =
297 m_variables[0]);
298 m_advDiffusionOp->AddBndCondUpdateOp(bndCondEntropyPressureOp);
299
300 auto bndCondEntropyTotalEnthalpyOp =
302 m_expansionLists[0], m_variables[0]);
303 m_advDiffusionOp->AddBndCondUpdateOp(bndCondEntropyTotalEnthalpyOp);
304
305 // An inviscid wall and a symmetry plane, which mirror the momentum, and a
306 // zeroth order extrapolation, which claims its regions so they are seeded
307 // with the interior state and then leaves them alone.
308 auto bndCondSlipWallOp = BndCondSlipWallCFEOp<double>::Create(
309 m_expansionLists[0], m_variables[0]);
310 m_advDiffusionOp->AddBndCondUpdateOp(bndCondSlipWallOp);
311
312 auto bndCondExtrapOrder0Op = BndCondExtrapOrder0CFEOp<double>::Create(
313 m_expansionLists[0], m_variables[0]);
314 m_advDiffusionOp->AddBndCondUpdateOp(bndCondExtrapOrder0Op);
315
316 // The characteristic farfield, which takes its freestream from the session
317 // parameters rather than from the region's boundary values.
318 auto bndCondRiemannInvariantOp =
320 m_variables[0]);
321 m_advDiffusionOp->AddBndCondUpdateOp(bndCondRiemannInvariantOp);
322
323 // And the reservoir inflow, whose session values are a stagnation state
324 // and a flow direction rather than a conserved state.
325 auto bndCondStagnationInflowOp =
327 m_variables[0]);
328 m_advDiffusionOp->AddBndCondUpdateOp(bndCondStagnationInflowOp);
329}
330
331/**
332 * @brief Supply the Courant estimate with the compressible wave speed.
333 *
334 * The conserved state is converted to velocity and sound speed on demand,
335 * so a run that asks for no Courant estimate builds neither the operator
336 * nor the field it writes into. The estimate this feeds is advective; the
337 * diffusive time scale of the viscous terms does not enter it.
338 */
339UnsteadySystem::CFLVelocity NavierStokesCFE::v_GetCFLVelocity()
340{
341 std::vector<std::string> components;
342 for (unsigned int i = 0; i < m_coordim; ++i)
343 {
344 components.push_back("u" + std::to_string(i));
345 }
346 components.push_back("c");
347
348 if (!m_cflVelocityOp)
349 {
350 // The kernel works in the shape dimension while the reduction reads
351 // the coordinate dimension; they part company only on a manifold,
352 // which the compressible solver does not support.
353 ASSERTL0(m_expansionLists[0]->GetExp(0)->GetShapeDimension() ==
354 m_coordim,
355 "The Courant estimate expects the shape and coordinate "
356 "dimensions to agree.");
357
358 m_cflVelocityOp =
359 CFLVelocityCFEOp<double>::Create(m_expansionLists[0], components);
360
361 auto bAtr_phys =
362 MultiRegions::GetBlockAttributes<double, FieldState::Phys>(
363 m_expansionLists[0]);
364
365 m_cflVelocity = LibUtilities::Field<double, FieldState::Phys>(
366 "cflVelocity", bAtr_phys, m_coordim + 1, m_npointsZ);
367 }
368
369 m_cflVelocityOp->Apply(m_phys[0], m_cflVelocity);
370
371 // The last component is a sound speed, so it counts in full.
372 return {&m_cflVelocity, 0, components, 1.0};
373}
374
375} // namespace Nektar
#define ASSERTL0(condition, msg)
Whole-field interface of the IProductWRTBase element operator, which takes a physical-space field to ...
Whole-field interface of the MultiplyByElmtInvMass element operator, which multiplies a coefficient-s...
The Navier-Stokes volume flux with the viscous flux on its own (see SolverCore::AdvDiffVolumeFluxOp):...
Subsonic Riemann boundary holding the entropy and the pressure.
Subsonic Riemann boundary holding the entropy and the total enthalpy.
Subsonic Riemann inflow holding the entropy and the velocity.
Zeroth order extrapolation: the exterior state is the interior one.
Subsonic pressure outflow, as a boundary state.
Characteristic farfield boundary from the Riemann invariants.
Inviscid slip wall and symmetry plane.
Subsonic inflow from a stagnation state and a flow direction.
Viscous wall states for the compressible flow solver.
A Field represents expansion data to be operated on.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Whole-field interface of the inner product with the basis: integrates a physical-space field against ...
Whole-field interface of the element-wise inverse mass operator: replaces every element's coefficient...
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100
static std::string className
Name of class.
NavierStokesCFE(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
static SolverUtils::EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::vector< std::pair< std::string, std::string > > SummaryList
Definition Misc.h:46
EquationSystemFactory & GetEquationSystemFactory()
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition Misc.cpp:46
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:287