Nektar++
Loading...
Searching...
No Matches
BndCondWallCFEOpImpl.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: BndCondWallCFEOpImpl.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
41
42using namespace Nektar;
43
44namespace Nektar::detail
45{
46
47/// Tags this operator claims. Anything else is another operator's business.
48inline bool IsViscousWallTag(const std::string &tag)
49{
50 return tag == "WallViscous" || tag == "WallAdiabatic";
51}
52
53/// An adiabatic wall additionally insulates: no heat flux through it.
54inline bool IsAdiabaticWallTag(const std::string &tag)
55{
56 return tag == "WallAdiabatic";
57}
58
59/// A plain viscous wall is held at the session temperature Twall. This is the
60/// complement of IsAdiabaticWallTag() within IsViscousWallTag(): every viscous
61/// wall carries exactly one of the two thermal conditions.
62inline bool IsIsothermalWallTag(const std::string &tag)
63{
64 return tag == "WallViscous";
65}
66
67template <typename ExecSpace, typename EoSParamType, typename TData>
69{
70 using MemSpace = typename ExecSpace::memory_space;
71
72public:
74 const std::vector<std::string> &components)
75 : BndCondWallCFEOp<TData>(expansionList, components)
76 {
77 m_numComp = components.size();
78 m_coordDim = MultiRegions::GetCollection(expansionList, 0)
79 .GetExpVector()[0]
80 ->GetCoordim();
81
83 "A compressible wall needs density, one momentum component "
84 "per direction and energy.");
85
86 SetUpEquationOfState(expansionList->GetSession(), m_EoS);
87
88 m_session = expansionList->GetSession();
89 }
90
91 // className - for OperatorFactory
92 static std::string className;
93
94 // instantiation function for CreatorFunction in OperatorFactory
95 static std::unique_ptr<MultiRegions::Operator<TData>> Instantiate(
96 const MultiRegions::ExpListSharedPtr &expansionList,
97 const std::vector<std::string> &components)
98 {
99 return std::make_unique<
101 components);
102 }
103
104protected:
105 unsigned int m_numComp = 0;
106 unsigned int m_coordDim = 0;
107 EoSParamType m_EoS;
108
110
111 /// Wall temperature each isothermal region is held at, one per storage
112 /// block. See v_SetBndCondPhysOp() for where each value comes from.
113 std::vector<TData> m_Twall;
114
115 /// A wall mirrors the interior rather than imposing a target, so what
116 /// v_Apply() leaves in the storage is already the exterior state and the
117 /// diffusion must not reflect it again.
118 bool v_GhostIsReflected() const override
119 {
120 return true;
121 }
122
123 /**
124 * @brief An adiabatic wall carries no heat flux.
125 *
126 * With u = 0 at the wall the viscous work u.tau vanishes, so the energy
127 * component of the viscous boundary flux is exactly q.n = k dT/dn, and
128 * suppressing it is the whole of the condition. Every other component, and
129 * an isothermal wall's energy - which is a condition on the state, imposed
130 * on the diffusion's exterior energy instead - keeps its flux.
131 */
132 TData v_BndFluxWeight(const unsigned blk,
133 const unsigned comp) const override
134 {
135 ASSERTL1(this->m_bndCondPhysOp,
136 "No boundary storage attached: call SetBndCondPhysOp().");
137
138 const bool isEnergy = (comp + 1 == m_numComp);
139
140 return (isEnergy &&
142 this->m_bndCondPhysOp->GetBndUserDefined(blk, 0)))
143 ? TData(0.0)
144 : TData(1.0);
145 }
146
147 /// An isothermal wall acts on the diffusion's exterior state.
148 bool v_HasDiffusionExteriorState() const override
149 {
150 return true;
151 }
152
153 /**
154 * @brief Resolve the wall temperature of each region.
155 *
156 * Three places, least specific first, so that adding the mechanism breaks
157 * nothing that already works:
158 *
159 * 1. the built-in default of 300.15;
160 * 2. a session `Twall`, which is how every session written before this
161 * existed says it, and which applies to every wall at once;
162 * 3. the region's own tag, `USERDEFINEDTYPE="WallViscous:twall=300.15"`.
163 *
164 * The third is the reason for the mechanism: a session parameter cannot
165 * give two walls different temperatures, and a channel heated on one side
166 * needs exactly that.
167 *
168 * Read here rather than in the constructor because the tags arrive with
169 * the storage.
170 */
171 void v_SetBndCondPhysOp() override
172 {
173 const auto numBlocks = this->m_bndCondPhysOp->GetNumBlocks();
174
175 double sessionTwall = 300.15;
176 m_session->LoadParameter("Twall", sessionTwall, sessionTwall);
177
178 m_Twall.assign(numBlocks, TData(sessionTwall));
179
180 for (unsigned blk = 0; blk < numBlocks; ++blk)
181 {
182 this->m_bndCondPhysOp->GetBndUserDefinedParam(blk, 0, "twall",
183 m_Twall[blk]);
184
185 // The isothermal energy is the last component, so extra
186 // transported components are not supported.
188 this->m_bndCondPhysOp->GetBndUserDefined(blk, 0)) ||
189 m_numComp == m_coordDim + 2,
190 "An isothermal wall needs exactly density, one momentum "
191 "component per direction and energy.");
192 }
193 }
194
195 /**
196 * @brief Hold an isothermal wall at Twall, in the diffusion's exterior
197 * state only.
198 *
199 * The wall temperature is a condition on the state the diffusion sees,
200 * not on the inviscid flux: writing it into the boundary storage would
201 * reach the Riemann solver too. This hook supplies the diffusion's
202 * exterior state alone.
203 *
204 * The trace average is not linear in the total energy: it averages the
205 * *internal* energy and adds back the kinetic energy of the averaged
206 * momentum, so the target has to be expressed in those terms. Solving
207 *
208 * {e_int} = 1/2 (eL + eR) = rho_ave * e(rho_ave, Twall)
209 * eL = E+ - |m+|^2 / (2 rho+)
210 * eR = E- - |m-|^2 / (2 rho-)
211 *
212 * for the exterior energy gives
213 *
214 * E- = 2 rho_ave e(rho_ave, Twall) - eL + |m-|^2 / (2 rho-)
215 *
216 * and the kernel supplies the kinetic term of the average on top.
217 * Treating the average as linear instead leaves the wall short by a
218 * kinetic energy term - an error of order Mach number squared, small at
219 * low speed and not zero.
220 *
221 * An adiabatic wall does nothing here. Its condition is on the heat flux,
222 * which is v_BndFluxWeight().
223 */
224 void v_ApplyDiffusionExteriorState(const unsigned blk, TData *ext,
225 const TData *interior, const size_t nPts,
226 const size_t compStride) const override
227 {
228 ASSERTL1(this->m_bndCondPhysOp,
229 "No boundary storage attached: call SetBndCondPhysOp().");
230
232 this->m_bndCondPhysOp->GetBndUserDefined(blk, 0)))
233 {
234 return;
235 }
236
237 ImposeIsothermalWallEnergyBlock<ExecSpace>(
238 nPts, compStride, m_coordDim, m_numComp - 1, m_EoS, m_Twall[blk],
239 interior, ext, this->m_opStreamID);
240 }
241
242 /// The blocks this operator owns, i.e. the regions tagged as viscous or
243 /// adiabatic walls. Only these are seeded with the interior state.
244 std::vector<bool> v_GetOwnedBlocks() const override
245 {
246 ASSERTL1(this->m_bndCondPhysOp,
247 "No boundary storage attached: call SetBndCondPhysOp().");
248
249 const auto numBlocks = this->m_bndCondPhysOp->GetNumBlocks();
250 std::vector<bool> owned(numBlocks, false);
251
252 for (unsigned blk = 0; blk < numBlocks; ++blk)
253 {
254 // A region carries one condition for all of its components, so the
255 // first settles whether this is a wall.
256 owned[blk] = IsViscousWallTag(
257 this->m_bndCondPhysOp->GetBndUserDefined(blk, 0));
258 }
259
260 return owned;
261 }
262
263 /**
264 * @brief Turn the seeded interior state into a no-slip wall state.
265 *
266 * The caller has already put the interior trace into the boundary storage,
267 * so this is the whole of the state side of the physics: density stays as
268 * it is, momentum reverses, and the average across the trace therefore has
269 * zero velocity.
270 *
271 * Neither thermal condition is imposed here, for two different reasons.
272 * An adiabatic wall constrains the heat flux rather than the state, so
273 * AdvDiffTraceFluxCFEOpImpl suppresses the energy component of the viscous
274 * boundary flux instead. An isothermal wall does constrain the state - but
275 * only the state the *diffusion* sees, inside the viscous flux. Writing
276 * it into the boundary storage here would reach the inviscid flux as
277 * well; it goes into m_gloT1Diff instead.
278 *
279 * What does belong here is any condition the advection should see too - a
280 * moving wall's velocity, for instance.
281 *
282 * Regions that are not walls are left untouched and are never seeded, so
283 * their session-evaluated values stand.
284 */
285 void v_Apply() override
286 {
287 ASSERTL1(this->m_bndCondPhysOp,
288 "No boundary storage attached: call SetBndCondPhysOp().");
289
290 const auto owned = v_GetOwnedBlocks();
291
292 for (unsigned blk = 0; blk < owned.size(); ++blk)
293 {
294 if (!owned[blk])
295 {
296 continue;
297 }
298
299 const auto stride = this->m_bndCondPhysOp->GetBlockCompStride(blk);
300 auto bndPtr =
301 this->m_bndCondPhysOp->UpdateBlockPtr(blk, this->m_opStreamID);
302
303 ReverseMomentumBlock<ExecSpace>(stride, m_coordDim, bndPtr,
304 this->m_opStreamID);
305 }
306 }
307};
308
309} // 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....
Viscous wall states for the compressible flow solver.
std::vector< LocalRegions::ExpansionSharedPtr > & GetExpVector()
Definition Collection.h:102
void v_SetBndCondPhysOp() override
Resolve the wall temperature of each region.
void v_ApplyDiffusionExteriorState(const unsigned blk, TData *ext, const TData *interior, const size_t nPts, const size_t compStride) const override
Hold an isothermal wall at Twall, in the diffusion's exterior state only.
void v_Apply() override
Turn the seeded interior state into a no-slip wall state.
BndCondWallCFEOpImpl(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
std::vector< bool > v_GetOwnedBlocks() const override
The blocks this operator owns, i.e. the regions tagged as viscous or adiabatic walls....
bool v_GhostIsReflected() const override
A wall mirrors the interior rather than imposing a target, so what v_Apply() leaves in the storage is...
static std::unique_ptr< MultiRegions::Operator< TData > > Instantiate(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
LibUtilities::SessionReaderSharedPtr m_session
typename ExecSpace::memory_space MemSpace
std::vector< TData > m_Twall
Wall temperature each isothermal region is held at, one per storage block. See v_SetBndCondPhysOp() f...
TData v_BndFluxWeight(const unsigned blk, const unsigned comp) const override
An adiabatic wall carries no heat flux.
bool v_HasDiffusionExteriorState() const override
An isothermal wall acts on the diffusion's exterior state.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
bool IsViscousWallTag(const std::string &tag)
Tags this operator claims. Anything else is another operator's business.
void SetUpEquationOfState(LibUtilities::SessionReaderSharedPtr session, IdealGasEoS< TData > &EoS)
bool IsIsothermalWallTag(const std::string &tag)
A plain viscous wall is held at the session temperature Twall. This is the complement of IsAdiabaticW...
bool IsAdiabaticWallTag(const std::string &tag)
An adiabatic wall additionally insulates: no heat flux through it.