Nektar++
Loading...
Searching...
No Matches
BndCondPhysOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: BndCondPhysOp.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
42{
43
44// Boundary condition phys-value operator base class.
45// Holds the evaluated values of every non-periodic boundary region - Dirichlet,
46// Neumann or Robin - one storage block per region. Periodic boundaries are not
47// held here: the interior trace strategy pairs them with their partner.
48template <typename TData> class BndCondPhysOp : public Operator<TData>
49{
50
51public:
52 static std::shared_ptr<BndCondPhysOp<TData>> Create(
53 const MultiRegions::ExpListSharedPtr &expansionList,
54 const std::vector<std::string> &components,
55 const std::string &execStr = "")
56 {
57 return Operator<TData>::template Create<BndCondPhysOp>(
58 expansionList, components, execStr);
59 }
60
61 static inline const std::string name = "BndCondPhys";
62
63 /// Refill the storage on stream @p streamID, the default stream unless
64 /// set. The trace flux operator sets the one it reads the storage on.
65 void SetStreamID(const unsigned int streamID)
66 {
67 m_opStreamID = streamID;
68 }
69
70 /// Refill on the default stream again, undoing SetStreamID().
75
76 /// Number of blocks the boundary data is stored in.
77 size_t GetNumBlocks() const
78 {
79 return v_GetNumBlocks();
80 }
81
82 /// Components held per block, i.e. the range valid for GetBndCondType().
83 size_t GetNumComponents() const
84 {
85 return this->m_components.size();
86 }
87
88 /**
89 * @brief Bring the stored values up to date for time @p time.
90 *
91 * The constructor evaluates every region once, so this is only needed
92 * where a condition actually depends on time; it returns immediately
93 * otherwise. Callers on the DG path should invoke it once per step, as
94 * LinearSystemOp does with the corresponding CG operators - without it a
95 * time-dependent condition stays pinned at the value it had when the
96 * operator was built.
97 *
98 * Consumers need do nothing to see the new values: they reach the data
99 * through GetBlockPtr(), which is refetched per apply.
100 */
101 void UpdateBndPhys(const TData &time = 0.0)
102 {
104 {
105 return;
106 }
107 v_UpdateBndPhys(time);
109 }
110
111 /**
112 * @brief Where the data for global trace @p tid lives.
113 *
114 * The mapping is fixed once the operator is constructed, so a caller that
115 * gathers many traces can resolve it up front and keep only the integers,
116 * rather than paying a virtual call and two map lookups per trace. The
117 * base pointer is deliberately not returned: it must come from
118 * GetBlockPtr() at the point of use, so that the memory manager still sees
119 * every access.
120 */
121 void GetTraceLocation(const size_t tid, unsigned &blk, size_t &offset,
122 size_t &compOffset)
123 {
124 v_GetTraceLocation(tid, blk, offset, compOffset);
125 }
126
127 /**
128 * @brief Does this operator hold boundary data for global trace @p tid?
129 *
130 * GetTraceLocation() assumes it does and asserts otherwise, which only
131 * reports in a debug build. This is the question asked before that, by a
132 * caller holding a trace it cannot pair locally: a trace on no boundary
133 * region of this rank is one whose neighbour lives on another, and it is
134 * the answer here rather than an out-of-range read that must decide
135 * which.
136 */
137 bool HasTrace(const size_t tid) const
138 {
139 return v_HasTrace(tid);
140 }
141
142 /// Base pointer for block @p blk, fetched through the memory manager on
143 /// stream @p streamID.
144 const TData *GetBlockPtr(const unsigned blk,
145 const unsigned int streamID = 0)
146 {
147 return v_GetBlockPtr(blk, streamID);
148 }
149
150 /**
151 * @brief Writable base pointer for block @p blk.
152 *
153 * For an operator that *computes* boundary values rather than evaluating
154 * them from the session - a wall state derived from the interior trace,
155 * say. Writing here rather than intercepting the gather keeps the flux
156 * path unchanged: consumers refetch through GetBlockPtr() on every apply
157 * and so pick the new values up without knowing where they came from.
158 *
159 * The layout is the region's own component-major phys layout, the same one
160 * GetTraceLocation() resolves into.
161 */
162 TData *UpdateBlockPtr(const unsigned blk, const unsigned int streamID = 0)
163 {
164 return v_UpdateBlockPtr(blk, streamID);
165 }
166
167 /// Phys points in block @p blk, i.e. the stride between its components and
168 /// equally the number of points to walk when transforming the whole block.
169 size_t GetBlockCompStride(const unsigned blk) const
170 {
171 return v_GetBlockCompStride(blk);
172 }
173
174 /**
175 * @brief Outward normals of block @p blk, in the same layout as its
176 * values: component major, #GetBlockCompStride() apart, one component per
177 * coordinate direction.
178 *
179 * Cached in the data warehouse, so repeated calls are free and every
180 * boundary condition that needs a normal direction - a symmetry plane, a
181 * characteristic inflow, an outflow deciding whether it is subsonic -
182 * draws on one copy.
183 */
184 const TData *GetBlockNormals(const unsigned blk)
185 {
186 return v_GetBlockNormals(blk);
187 }
188
189 /**
190 * @brief Condition type component @p comp of block @p blk carries.
191 *
192 * Values of every type are stored identically; what differs is how they
193 * must be interpreted, so a consumer that treats a Neumann or Robin
194 * boundary differently from a Dirichlet one asks here. Never
195 * SpatialDomains::ePeriodic - those regions hold no values and are not
196 * given a block.
197 */
199 const unsigned blk, const unsigned comp) const
200 {
201 return v_GetBndCondType(blk, comp);
202 }
203
204 /**
205 * @brief USERDEFINEDTYPE of component @p comp of block @p blk.
206 *
207 * Empty when the session gives none. The tags are solver specific, so this
208 * hands back the session's own string rather than a code: a compressible
209 * flow solver knows what "WallAdiabatic" means and this operator does not.
210 * A condition so tagged is still an ordinary condition of its
211 * GetBndCondType() as far as the storage here goes.
212 *
213 * Host side only - the string is not something a kernel can read. A caller
214 * that needs the distinction on device should resolve these once into its
215 * own per-block table of codes, as it must do for its own enum anyway.
216 */
217 const std::string &GetBndUserDefined(const unsigned blk,
218 const unsigned comp) const
219 {
220 return v_GetBndUserDefined(blk, comp);
221 }
222
223 /**
224 * @brief A named parameter carried on the boundary tag.
225 *
226 * A USERDEFINEDTYPE may carry parameters after the condition itself,
227 *
228 * USERDEFINEDTYPE="WallViscous:twall=300.15"
229 * USERDEFINEDTYPE="WallViscous:twall=TInf"
230 *
231 * so that a quantity belonging to one region is written on that region
232 * rather than as a session-wide parameter. Two regions may then hold
233 * different values, which a session parameter cannot express.
234 *
235 * The value is evaluated as an expression against the session, as the
236 * `Rotated:` periodic tag does, so it may name session parameters and use
237 * arithmetic rather than having to be a literal.
238 *
239 * GetBndUserDefined() returns the condition with any such parameters
240 * stripped, so a condition that takes none - and the check that every tag
241 * is claimed by some operator - are unaffected by their presence.
242 *
243 * @param blk - Storage block.
244 * @param comp - Component; a region carries one tag for all of them.
245 * @param name - Parameter name, matched without regard to case.
246 * @param value - Set only when the parameter is present, so a caller may
247 * seed it with a default and ignore the return.
248 *
249 * @return Whether the parameter was present.
250 */
251 bool GetBndUserDefinedParam(const unsigned blk, const unsigned comp,
252 const std::string &name, TData &value) const
253 {
254 return v_GetBndUserDefinedParam(blk, comp, name, value);
255 }
256
257protected:
258 /// Stream the storage is refilled on unless SetStreamID() says otherwise.
259 static constexpr unsigned int m_defaultStreamID = 0;
260 /// Stream the storage is refilled on. See SetStreamID().
262
263 /// Set once the constructor's initial evaluation has happened, so that
264 /// UpdateBndPhys() can skip regions that will never change.
267
269 const std::vector<std::string> &components)
270 : Operator<TData>(expansionList, components)
271 {
272 }
273
274 ~BndCondPhysOp() override = default;
275
276 virtual size_t v_GetNumBlocks() const = 0;
277
278 virtual void v_GetTraceLocation(const size_t tid, unsigned &blk,
279 size_t &offset, size_t &compOffset) = 0;
280
281 virtual bool v_HasTrace(const size_t tid) const = 0;
282
283 virtual const TData *v_GetBlockPtr(const unsigned blk,
284 const unsigned int streamID) = 0;
285
286 virtual TData *v_UpdateBlockPtr(const unsigned blk,
287 const unsigned int streamID) = 0;
288
289 virtual size_t v_GetBlockCompStride(const unsigned blk) const = 0;
290
291 virtual const TData *v_GetBlockNormals(const unsigned blk) = 0;
292
294 const unsigned blk, const unsigned comp) const = 0;
295
296 virtual bool v_GetBndUserDefinedParam(const unsigned blk,
297 const unsigned comp,
298 const std::string &name,
299 TData &value) const = 0;
300
301 virtual const std::string &v_GetBndUserDefined(
302 const unsigned blk, const unsigned comp) const = 0;
303
304 virtual void v_UpdateBndPhys(const TData &time) = 0;
305};
306
307} // namespace Nektar::MultiRegions
Whole-field operator base class and factory machinery shared by every operator family in the MultiReg...
static constexpr unsigned int m_defaultStreamID
Stream the storage is refilled on unless SetStreamID() says otherwise.
size_t GetNumComponents() const
Components held per block, i.e. the range valid for GetBndCondType().
virtual bool v_HasTrace(const size_t tid) const =0
static std::shared_ptr< BndCondPhysOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
void GetTraceLocation(const size_t tid, unsigned &blk, size_t &offset, size_t &compOffset)
Where the data for global trace tid lives.
void SetStreamID(const unsigned int streamID)
Refill the storage on stream streamID, the default stream unless set. The trace flux operator sets th...
void UpdateBndPhys(const TData &time=0.0)
Bring the stored values up to date for time time.
BndCondPhysOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
virtual const TData * v_GetBlockNormals(const unsigned blk)=0
virtual TData * v_UpdateBlockPtr(const unsigned blk, const unsigned int streamID)=0
SpatialDomains::BoundaryConditionType GetBndCondType(const unsigned blk, const unsigned comp) const
Condition type component comp of block blk carries.
const TData * GetBlockPtr(const unsigned blk, const unsigned int streamID=0)
Base pointer for block blk, fetched through the memory manager on stream streamID.
virtual size_t v_GetNumBlocks() const =0
virtual const TData * v_GetBlockPtr(const unsigned blk, const unsigned int streamID)=0
void ResetStreamID()
Refill on the default stream again, undoing SetStreamID().
bool GetBndUserDefinedParam(const unsigned blk, const unsigned comp, const std::string &name, TData &value) const
A named parameter carried on the boundary tag.
bool HasTrace(const size_t tid) const
Does this operator hold boundary data for global trace tid?
const TData * GetBlockNormals(const unsigned blk)
Outward normals of block blk, in the same layout as its values: component major, GetBlockCompStride()...
virtual void v_UpdateBndPhys(const TData &time)=0
bool m_bndPhysInitialised
Set once the constructor's initial evaluation has happened, so that UpdateBndPhys() can skip regions ...
unsigned int m_opStreamID
Stream the storage is refilled on. See SetStreamID().
size_t GetNumBlocks() const
Number of blocks the boundary data is stored in.
const std::string & GetBndUserDefined(const unsigned blk, const unsigned comp) const
USERDEFINEDTYPE of component comp of block blk.
virtual SpatialDomains::BoundaryConditionType v_GetBndCondType(const unsigned blk, const unsigned comp) const =0
virtual void v_GetTraceLocation(const size_t tid, unsigned &blk, size_t &offset, size_t &compOffset)=0
size_t GetBlockCompStride(const unsigned blk) const
Phys points in block blk, i.e. the stride between its components and equally the number of points to ...
virtual const std::string & v_GetBndUserDefined(const unsigned blk, const unsigned comp) const =0
virtual bool v_GetBndUserDefinedParam(const unsigned blk, const unsigned comp, const std::string &name, TData &value) const =0
TData * UpdateBlockPtr(const unsigned blk, const unsigned int streamID=0)
Writable base pointer for block blk.
virtual size_t v_GetBlockCompStride(const unsigned blk) const =0
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100
std::vector< std::string > m_components
Names of the field components the operator was built for.
Definition Operator.hpp:351
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.