Nektar++
Loading...
Searching...
No Matches
BndCondPressureOutflowCFEOpImpl.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: BndCondPressureOutflowCFEOpImpl.hpp
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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
40
43
44using namespace Nektar;
45
46namespace Nektar::detail
47{
48
49/// Tag this operator claims.
50inline bool IsPressureOutflowTag(const std::string &tag)
51{
52 return tag == "PressureOutflow";
53}
54
55/**
56 * @brief Subsonic pressure outflow.
57 *
58 * Prescribes the static pressure at an outflow and extrapolates everything
59 * else, which is the well posed choice while the flow leaves the domain
60 * subsonically: one characteristic enters, so exactly one quantity may be
61 * imposed. Once the outflow goes supersonic no characteristic enters and
62 * nothing may be imposed, so the whole state is extrapolated.
63 *
64 * The caller seeds the storage with the interior trace, which is already the
65 * extrapolated state, so the supersonic branch has nothing to do and the
66 * subsonic branch has only the energy left to write:
67 *
68 * E = rho+ e(rho+, p_out) + |m+|^2 / (2 rho+)
69 *
70 * the internal energy that goes with the prescribed pressure at the
71 * extrapolated density, plus the extrapolated kinetic energy.
72 *
73 * ### Where the pressure comes from
74 *
75 * From the session's boundary value for the *energy* variable, so
76 *
77 * <D VAR="E" USERDEFINEDTYPE="PressureOutflow" VALUE="pInf" />
78 *
79 * holds a pressure and not an energy. Existing sessions are written that
80 * way, and there is no other slot for the number to arrive in:
81 * BndCondPhysOp evaluates every component from the session alike. It remains a
82 * trap - the variable is named for a quantity it does not hold on this one
83 * boundary type.
84 *
85 * The value is taken once, in v_SetBndCondPhysOp(), and not re-read. A
86 * time-dependent outflow pressure
87 * is therefore *not* supported: a session may declare one and it is silently
88 * ignored. The copy is needed either way, because every owned block is
89 * overwritten with the interior state before v_Apply() runs.
90 *
91 * ### Why the diffusion side needs nothing
92 *
93 * This is an imposed region rather than a reflective one, so the trace flux
94 * operator reflects it to 2g - Q+ for the diffusion, so the trace average
95 * lands on the imposed value.
96 *
97 * That the reflection lands on the target exactly is a *precondition of this
98 * condition*, not a general property. The compressible kernel averages the
99 * internal energy and adds back the kinetic energy of the averaged momentum
100 * rather than averaging E linearly. Here rho and momentum are extrapolated, so
101 * the ghost has rho- = rho+ and m- = m+, the kinetic term added back is exactly
102 * the one subtracted, and {E} collapses to the linear (E+ + E-)/2 = E_b. A
103 * condition that perturbs rho or m as well - PressureOutflowNonReflective, say
104 * - loses that cancellation and has to solve for the exterior energy on the
105 * internal energy instead, as the isothermal wall does. The convention is
106 * documented on SolverCore::BndCondUpdateOp::GhostIsReflected().
107 */
108template <typename ExecSpace, typename EoSParamType, typename TData>
110 : public BndCondPressureOutflowCFEOp<TData>
111{
112 using MemSpace = typename ExecSpace::memory_space;
113
114public:
116 const MultiRegions::ExpListSharedPtr &expansionList,
117 const std::vector<std::string> &components)
118 : BndCondPressureOutflowCFEOp<TData>(expansionList, components)
119 {
120 m_numComp = components.size();
121 m_coordDim = MultiRegions::GetCollection(expansionList, 0)
122 .GetExpVector()[0]
123 ->GetCoordim();
124
126 "A compressible pressure outflow needs density, one momentum "
127 "component per direction and energy.");
128
129 SetUpEquationOfState(expansionList->GetSession(), m_EoS);
130 }
131
132 // className - for OperatorFactory
133 static std::string className;
134
135 // instantiation function for CreatorFunction in OperatorFactory
136 static std::unique_ptr<MultiRegions::Operator<TData>> Instantiate(
137 const MultiRegions::ExpListSharedPtr &expansionList,
138 const std::vector<std::string> &components)
139 {
140 return std::make_unique<
142 expansionList, components);
143 }
144
145protected:
146 unsigned int m_numComp = 0;
147 unsigned int m_coordDim = 0;
148 EoSParamType m_EoS;
149
150 /// Prescribed static pressure per owned block, taken from the session
151 /// before the storage is overwritten. Empty for unowned blocks. Held in
152 /// the execution space's memory: the boundary storage lives there, so
153 /// both the copy at setup and the reads in the apply kernel stay
154 /// on-space.
155 std::vector<LibUtilities::MemoryRegion<TData>> m_pressure;
156
157 std::vector<bool> v_GetOwnedBlocks() const override
158 {
159 ASSERTL1(this->m_bndCondPhysOp,
160 "No boundary storage attached: call SetBndCondPhysOp().");
161
162 const auto numBlocks = this->m_bndCondPhysOp->GetNumBlocks();
163 std::vector<bool> owned(numBlocks, false);
164
165 for (unsigned blk = 0; blk < numBlocks; ++blk)
166 {
167 owned[blk] = IsPressureOutflowTag(
168 this->m_bndCondPhysOp->GetBndUserDefined(blk, 0));
169 }
170
171 return owned;
172 }
173
174 /// Copy the prescribed pressure out of the session-evaluated storage,
175 /// while it is still there.
176 void v_SetBndCondPhysOp() override
177 {
178 const auto owned = v_GetOwnedBlocks();
179 m_pressure.clear();
180 m_pressure.resize(owned.size());
181
182 for (unsigned blk = 0; blk < owned.size(); ++blk)
183 {
184 if (!owned[blk])
185 {
186 continue;
187 }
188
189 const auto stride = this->m_bndCondPhysOp->GetBlockCompStride(blk);
190 const auto *bndPtr =
191 this->m_bndCondPhysOp->GetBlockPtr(blk, this->m_opStreamID);
192
193 // The boundary storage lives in the execution space's memory, so
194 // the copy runs there as a kernel - a host-side assign from this
195 // pointer is a host dereference of device memory on a real
196 // device.
198 m_pressure[blk].template Initialize<MemSpace>(0);
199 TData *pOut = m_pressure[blk].template GetPtr<MemSpace, ReadWrite>(
200 this->m_opStreamID);
201
202 CopyPrescribedPressureBlock<ExecSpace>(
203 stride, m_numComp - 1, bndPtr, pOut, this->m_opStreamID);
204 }
205 }
206
207 void v_Apply() override
208 {
209 ASSERTL1(this->m_bndCondPhysOp,
210 "No boundary storage attached: call SetBndCondPhysOp().");
211
212 const auto owned = v_GetOwnedBlocks();
213
214 for (unsigned blk = 0; blk < owned.size(); ++blk)
215 {
216 if (!owned[blk])
217 {
218 continue;
219 }
220
221 const auto stride = this->m_bndCondPhysOp->GetBlockCompStride(blk);
222 auto bndPtr =
223 this->m_bndCondPhysOp->UpdateBlockPtr(blk, this->m_opStreamID);
224 const TData *pOut =
225 m_pressure[blk].template GetPtr<MemSpace, ReadOnly>(
226 this->m_opStreamID);
227 const TData *norms = this->m_bndCondPhysOp->GetBlockNormals(blk);
228
229 ASSERTL1(m_pressure[blk].size() == stride,
230 "Prescribed outflow pressure was taken for a different "
231 "block size than the storage now reports.");
232
233 ApplyPressureOutflowBlock<ExecSpace>(
234 stride, m_coordDim, m_numComp - 1, m_EoS, pOut, norms, bndPtr,
235 this->m_opStreamID);
236 }
237 }
238};
239
240} // namespace Nektar::detail
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Subsonic pressure outflow, as a boundary state.
std::vector< LocalRegions::ExpansionSharedPtr > & GetExpVector()
Definition Collection.h:102
A MemoryRegion represents a memory region.
std::vector< LibUtilities::MemoryRegion< TData > > m_pressure
Prescribed static pressure per owned block, taken from the session before the storage is overwritten....
BndCondPressureOutflowCFEOpImpl(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
void v_SetBndCondPhysOp() override
Copy the prescribed pressure out of the session-evaluated storage, while it is still there.
static std::unique_ptr< MultiRegions::Operator< TData > > Instantiate(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
void SetUpEquationOfState(LibUtilities::SessionReaderSharedPtr session, IdealGasEoS< TData > &EoS)
bool IsPressureOutflowTag(const std::string &tag)
Tag this operator claims.