Nektar++
Loading...
Searching...
No Matches
PhysTraceExtractOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysTraceExtractOp.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/**
36 * @file PhysTraceExtractOp.hpp
37 * @brief Public interface of the PhysTraceExtract element operator, which
38 * interpolates a volume physical-space field onto the quadrature points
39 * of the element's traces.
40 *
41 * @details
42 * Given a field at the volume quadrature points of an element, this
43 * operator evaluates it at the trace quadrature points,
44 * \f[ u(\boldsymbol\xi^{tr}) = \sum_{\boldsymbol p} u_{\boldsymbol p}\,
45 * h_{\boldsymbol p}(\boldsymbol\xi^{tr}) , \f]
46 * where \f$h_{\boldsymbol p}(\boldsymbol\xi) = \prod_a h_{p_a}(\xi_a)\f$
47 * is the tensor product of the cardinal (hat) functions of the @em volume
48 * quadrature grid, \f$h_p(\xi_q) = \delta_{pq}\f$, the \f$u_{\boldsymbol
49 * p}\f$ are the field values at the volume quadrature points, and the
50 * traces of an element are its endpoint vertices in one dimension, its
51 * edges in two and its faces in three.
52 *
53 * On a direction-\f$a\f$ trace at \f$\xi_a = \pm 1\f$ the tensor product
54 * factorises as
55 * \f[ h_{\boldsymbol p}\big|_{\xi_a = \pm 1} = h_{p_a}(\pm 1)
56 * \prod_{b \neq a} h_{p_b}(\xi_b) , \f]
57 * so the evaluation splits into a normal-direction interpolation with
58 * \f$h_{p_a}(\pm 1)\f$, which collapses the volume array onto the trace's
59 * plane, followed by a tangential interpolation of that plane onto the
60 * trace quadrature points with \f$h_{p_b}(\xi_b^{tr})\f$. That is the
61 * structure the kernels exploit.
62 *
63 * Both stages use `eInterp` tables taken from the data warehouse at
64 * setup: the normal-direction table \f$h_p(\pm 1)\f$ (called `ntbasis` in
65 * this operator's kernels, `nbasis` in IProductWRTPhysTrace's) and the
66 * trace table \f$h_p(\xi^{tr})\f$ (`tbasis`). Neither is an expansion
67 * basis evaluated anywhere, and `nm` throughout this family holds
68 * `GetNumPoints`, that is volume quadrature counts and not modes. The
69 * operator is a pure interpolation: no quadrature weights and no
70 * Jacobian enter it.
71 *
72 * It is the adjoint of IProductWRTPhysTrace in the hat basis. Both build
73 * their `eInterp` BasisDataKeys from the same basis key, point count and
74 * points type. This operator applies the tables untransposed where
75 * IProductWRTPhysTrace applies them transposed and additionally weights
76 * them with the trace quadrature weights and the trace Jacobian.
77 *
78 * The operator only ever interpolates point values. Nothing in this
79 * repository calls it outside its unit tests.
80 *
81 * The family follows the standard element-operator layout (see
82 * ElmtOp.hpp):
83 * - PhysTraceExtractOp (this file): whole-field interface setting the
84 * Apply() field states, plus the per-trace entry point;
85 * - detail::PhysTraceExtractOpImpl (PhysTraceExtractOpImpl.hpp): the
86 * factory-registered whole-field implementation, one entry per
87 * execution space;
88 * - PhysTraceExtractBlockOp (PhysTraceExtractBlockOp.hpp): per-block
89 * interface;
90 * - detail::PhysTraceExtractBlockOpImpl: the per-block implementations,
91 * in PhysTraceExtractBlockOpSerialAVXSumFac.hpp (serving both the Serial and
92 * the AVX space) and PhysTraceExtractBlockOpDeviceSumFac.hpp (Device);
93 * - the kernels in PhysTraceExtractBlockOpSerialAVXSumFacKernels.hpp and
94 * PhysTraceExtractBlockOpDeviceSumFacKernels.hpp.
95 *
96 * The per-shape entry points are generated from
97 * LibUtilities/BasicUtils/Switch/BlockOpShapeBlock.cpp.in, one
98 * translation unit per shape, execution space and data type, so the
99 * size-templated OperatorND instantiations of the SumFac families are
100 * kept. Those units include the switch template
101 * LibUtilities/BasicUtils/Switch/BlockOpSwitchPhysTraceExtract.h.in,
102 * which is named after this operator: its per-shape template arguments
103 * carry trace point counts per normal direction.
104 *
105 * @note There is one trace-extraction algorithm, registered under
106 * MultiRegions::SumFac and, where an execution space provides it,
107 * MultiRegions::SumFacTOP. A StdMat request is mapped to SumFac on the
108 * host and SumFacTOP on the device by PhysTraceExtractBlockOp::Create(),
109 * so a whole-field
110 * selection of StdMat, SumFac or SumFacTOP can include this operator.
111 *
112 * @warning For three-dimensional shapes the general normal-direction
113 * interpolation, the arm taken when the volume rule of the normal
114 * direction contains no domain endpoints (Gauss-type rules), produces
115 * wrong values on the bulk path. Its location has not been established:
116 * the `ntbasis` row strides the per-trace path dispatches are correct,
117 * that path taking its stride as an explicit `tstride` argument rather
118 * than from the face-loop bound. No three-dimensional Gauss fixture
119 * exists, so the unit-test suites stay green regardless.
120 *
121 * @see IProductWRTPhysTraceOp.hpp for the adjoint operator, the
122 * discontinuous Galerkin lifting term, which maps trace data back into a
123 * volume-shaped array.
124 */
125
126#pragma once
127
129
131
132namespace Nektar::MultiRegions
133{
134
135// PhysTraceExtract base class
136// Defines the apply operator to enforce apply parameter types
137/**
138 * @brief Whole-field interface of the trace extraction: interpolates the
139 * volume field of every element onto that element's trace quadrature
140 * points.
141 *
142 * @details
143 * As with the other element-operator families, this class exists to set
144 * the Apply() parameter types at compile time and to drive the per-block
145 * operators: it holds one PhysTraceExtractBlockOp per element block, and
146 * v_Apply() hands each block of the input/output fields to the matching
147 * entry. All numerical work happens in the block operators.
148 *
149 * ### Field layouts
150 * Both fields are in FieldState::Phys, but they are not the same shape
151 * and the type system does not tell them apart:
152 * - @em in is a volume field, laid out by GetBlockAttributes(), with one
153 * entry per volume quadrature point;
154 * - @em out is a packed trace field, laid out by
155 * GetLocTraceBlockAttributes(). Within an element the traces come in
156 * pair order, the \f$N_0\f$ pair first, then the \f$N_1\f$ pair or
157 * single, then \f$N_2\f$, face-major within a pair.
158 *
159 * This is the mirror image of IProductWRTPhysTrace, which reads the
160 * packed trace layout and writes the volume one. The conformance checks
161 * in v_Apply() and ExtractTrace() compare only component counts and
162 * homogeneous-mode counts, so passing the two layouts the wrong way round
163 * is not caught here.
164 *
165 * ### Entry points
166 * - Apply() (inherited from ElmtOp) extracts the whole element boundary
167 * in one call, filling every trace of the packed record.
168 * - ExtractTrace() extracts one trace of every element into a
169 * caller-chosen offset of the packed record, of every block of a Field
170 * or of one given block.
171 *
172 * This operator has no append flag: both paths write the entries they
173 * are responsible for.
174 *
175 * @tparam TData Floating-point type of the field data.
176 *
177 * @see PhysTraceExtractBlockOp for the per-block interface and the
178 * implementations available per execution space.
179 */
180template <typename TData>
182 : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
183{
184 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
185
186public:
187 /**
188 * @brief Create a trace extraction operator through the operator and
189 * block-operator factories.
190 *
191 * Builds the interface object under the factory key
192 * `"PhysTraceExtract" + execStr` and one block operator per element
193 * block under `"BlockPhysTraceExtract" + execStr + implStr` (see
194 * ElmtOp::Create for the two-stage construction and for the session
195 * defaults used when @p execStr / @p implStr are empty).
196 *
197 * @param expansionList Expansion list the operator acts on.
198 * @param components Names of the field components the
199 * operator is set up for.
200 * @param execStr Execution space ("Serial", "AVX" or
201 * "Device"); session default if empty.
202 * @param implStr Block implementation; StdMat resolves to
203 * SumFac on the host and SumFacTOP on the
204 * device, see the file notes.
205 *
206 * @return The fully assembled operator, ready to Apply.
207 */
208 static std::shared_ptr<PhysTraceExtractOp<TData>> Create(
209 const MultiRegions::ExpListSharedPtr &expansionList,
210 const std::vector<std::string> &components,
211 const std::string &execStr = "", const std::string &implStr = "")
212 {
214 template Create<PhysTraceExtractOp, PhysTraceExtractBlockOp>(
215 expansionList, components, execStr, implStr);
216 }
217
218 /// Operator base name; Create() appends the execution space to it
219 /// to form the factory key.
220 static inline const std::string name = "PhysTraceExtract";
221
222 /**
223 * @brief Extract a single trace of every element into @p out at
224 * @p outOffset.
225 *
226 * @details
227 * The per-trace counterpart of Apply(): rather than filling the whole
228 * packed record it interpolates onto trace @p traceid alone and
229 * writes that trace's entries, leaving the rest of the record
230 * untouched by this call. A caller assembling the whole boundary
231 * therefore issues one call per trace, advancing @p outOffset in the
232 * packed order of the traces rather than in trace-id order; that is
233 * how the operator-level unit tests drive it, for instance
234 * `3, 1, 0, 2` on a quadrilateral and `4, 2, 1, 3, 0, 5` on a
235 * hexahedron.
236 *
237 * @param traceid Local trace index within the element's shape,
238 * in the Nektar edge/face numbering; the
239 * implementations map it to a (normal
240 * direction, position) pair.
241 * @param in Volume-shaped input field; see the class notes
242 * for its layout.
243 * @param out Packed trace field, written at @p outOffset.
244 * @param outOffset Offset of this trace's data within one
245 * element's packed trace entries, counted in
246 * entries per element.
247 *
248 * @note Not every implementation serves every shape. An unserved
249 * shape either raises a fatal error or is reported on standard
250 * output with @p out left unwritten.
251 *
252 * @note In three dimensions the general arm of the normal-direction
253 * interpolation this reaches takes the `ntbasis` row stride as an
254 * explicit `tstride` argument rather than from the face-loop bound,
255 * which is one on this path; the defect the file notes describe is
256 * on the bulk path.
257 */
258 void ExtractTrace(const unsigned traceid,
261 const unsigned outOffset)
262 {
263 // Loop over the blocks.
264 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
265 {
266 ExtractTrace(traceid, in.GetBlocks()[blk], out.GetBlocks()[blk],
267 outOffset, blk);
268 }
269 }
270
271 /**
272 * @brief Extract a single trace of every element of block @p blk into
273 * @p outblock at @p outOffset.
274 *
275 * @details
276 * The block-level counterpart of the Field overload above, for a
277 * caller holding single blocks rather than Fields.
278 *
279 * @param traceid Local trace index within the element's shape.
280 * @param inblock Volume-shaped input block, laid out as block
281 * @p blk of GetBlockAttributes().
282 * @param outblock Packed trace block, laid out as block @p blk
283 * of GetLocTraceBlockAttributes(), written at
284 * @p outOffset.
285 * @param outOffset Offset of this trace's data within one
286 * element's packed trace entries, counted in
287 * entries per element.
288 * @param blk Index of the block of the operator's expansion
289 * list whose block operator is applied.
290 */
292 const unsigned traceid,
295 const unsigned outOffset, const unsigned blk)
296 {
297 ASSERTL1(blk < this->m_blockOp.size(),
298 "Block index exceeds the number of blocks");
299
300 ASSERTL1(inblock.GetNumComponents() == outblock.GetNumComponents(),
301 "Number of input and output components differ");
302
303 ASSERTL1(inblock.GetNumHomoModes() == outblock.GetNumHomoModes(),
304 "Number of input and output homogeneous modes differ");
305
306 this->m_blockOp[blk]->ExtractTrace(traceid, inblock, outblock,
307 outOffset);
308 }
309
310 /**
311 * @brief Set the tangential collocation flags of every block
312 * operator, passing false to force the fast path off.
313 *
314 * @details
315 * The implementations record one collocation flag per (normal
316 * direction, tangential direction) at setup, six of them in three
317 * dimensions, set when the trace quadrature points of that direction
318 * coincide with the volume quadrature points of the corresponding
319 * direction. Where the flag is set the tangential interpolation
320 * collapses to a straight copy of the plane. Clearing the flags
321 * selects the general contraction instead, which is how the unit
322 * tests reach that code path on meshes whose points do coincide; it
323 * is a different route to the same mathematical operation.
324 *
325 * @param isCollocated Value written to every flag of every
326 * block.
327 *
328 * @note The flags live on PhysTraceExtractBlockOp itself, so this
329 * reaches every implementation without a virtual hook. The setter
330 * is wholesale, so passing true does not restore the flags a block
331 * started with; it asserts collocation the constructor may not have
332 * found.
333 */
334 void SetIsCollocated(const bool isCollocated)
335 {
336 // Loop over the blocks.
337 for (unsigned blk = 0; blk < this->m_blockOp.size(); ++blk)
338 {
339 this->m_blockOp[blk]->SetIsCollocated(isCollocated);
340 }
341 }
342
343 /**
344 * @brief The outward normal component of a vector-valued field on the
345 * element-local traces; see PhysTraceExtractBlockOp::
346 * ApplyNormalComponent(). @p in has `nvar * ndim` components, ndim
347 * being the coordinate dimension, and @p out has `nvar`. The normals
348 * are each element's own (MultiRegions::LocalTraceNormalKey), on the
349 * element's trace points, so the Gauss-Lobatto trace points are not
350 * supported. A scratch trace field is built on first use, for the
351 * block implementations that extract every component first.
352 */
355 {
357 "The normal component is formed on the elements' own trace "
358 "points, not the Gauss-Lobatto ones.");
359 ASSERTL1(in.GetNumComponents() ==
360 out.GetNumComponents() *
361 this->m_expansionList->GetCoordim(0),
362 "The input needs one component per output component and "
363 "coordinate direction");
364 bool needsScratch = false;
365 for (const auto &blockOp : this->m_blockOp)
366 {
367 needsScratch |= blockOp->NormalComponentNeedsScratch();
368 }
369 if (needsScratch &&
370 (!m_normalScratch ||
371 m_normalScratch.GetNumComponents() != in.GetNumComponents()))
372 {
374 "PhysTraceExtract normal component",
375 GetLocTraceBlockAttributes<TData, FieldState::Phys>(
377 in.GetNumComponents(), 1);
378 }
379 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
380 {
381 this->m_blockOp[blk]->ApplyNormalComponent(
382 in.GetBlocks()[blk],
383 needsScratch ? &m_normalScratch.GetBlocks()[blk] : nullptr,
384 out.GetBlocks()[blk]);
385 }
386 }
387
388 /**
389 * @brief Extract onto the Gauss-Lobatto trace points rather than the
390 * element's own.
391 *
392 * @details
393 * The operator evaluates the volume field at whichever trace points
394 * the expansion reports, so the choice is a choice of table, not an
395 * extra stage: passing true builds the interpolation against the
396 * Gauss-Lobatto variant and the values land directly on it.
397 *
398 * It matters on the collapsed direction of a face of a tetrahedron,
399 * prism or pyramid, where the element's own trace quadrature is
400 * Gauss-Radau and has no point at the collapsed end, while the trace
401 * and boundary expansions of a continuous field carry Gauss-Lobatto
402 * with one point more. Extracting onto a continuous field's boundary
403 * needs that variant; a discontinuous field's trace keeps the
404 * element's own, and passing true there would interpolate onto points
405 * the destination does not have.
406 *
407 * The output storage must be sized the same way; see
408 * MultiRegions::GetLocTraceBlockAttributes(), whose last argument
409 * carries the same choice. The collocation flags are worked out again
410 * for the new points, replacing any set by SetIsCollocated(), so call
411 * this first.
412 *
413 * @param useGLLTracePoints True for the Gauss-Lobatto variant.
414 */
415 void SetUseGLLTracePoints(const bool useGLLTracePoints)
416 {
417 m_useGLLTracePoints = useGLLTracePoints;
418 // Loop over the blocks.
419 for (unsigned blk = 0; blk < this->m_blockOp.size(); ++blk)
420 {
421 this->m_blockOp[blk]->SetUseGLLTracePoints(useGLLTracePoints);
422 }
423 }
424
425protected:
426 /// One block operator per element block of the expansion list;
427 /// populated by ElmtOp::Create().
428 std::vector<std::shared_ptr<PhysTraceExtractBlockOp<TData>>> m_blockOp;
429 /// The trace quadrature the blocks interpolate onto; see
430 /// SetUseGLLTracePoints().
432 /// Every component's trace for ApplyNormalComponent(), for the block
433 /// implementations that extract them before contracting.
435
436 /**
437 * @brief Construct the interface part of a concrete implementation;
438 * called by the factory-registered creator functions.
439 *
440 * @param expansionList Expansion list the operator acts on.
441 * @param components Component names the operator is set up
442 * for.
443 */
445 const std::vector<std::string> &components)
446 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
447 components)
448 {
449 }
450
451 ~PhysTraceExtractOp() override = default;
452
453 /**
454 * @brief Extract every trace of every element, block by block.
455 *
456 * Checks that the fields agree in component count and in number of
457 * homogeneous modes -- not that their block layouts are the volume
458 * and trace ones described in the class notes -- then hands each pair
459 * of blocks to the corresponding entry of #m_blockOp, which fills the
460 * whole packed trace record of each element.
461 *
462 * @param in Volume-shaped input field.
463 * @param out Packed trace output field.
464 *
465 * @note This is the path the nodal-shape guard note in the file
466 * documentation applies to.
467 */
470 {
471 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
472 "Number of input and output components differ");
473
474 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
475 "Number of input and output homogeneous modes differ");
476
477 // Loop over the blocks.
478 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
479 {
480 // Block dependent.
481 auto &inblock = in.GetBlocks()[blk];
482 auto &outblock = out.GetBlocks()[blk];
483
484 this->m_blockOp[blk]->Apply(inblock, outblock);
485 }
486 }
487};
488
489} // namespace Nektar::MultiRegions
Whole-field base class and factory machinery shared by every element-operator family in the MultiRegi...
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Per-block interface class of the trace extraction operator PhysTraceExtract.
Get the BlockAttributes for a given field state from an ExpList. This method basically captures ident...
Definition Block.hpp:144
unsigned int GetNumComponents() const
Gets the number of components.
Definition Block.hpp:249
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
Definition Block.hpp:259
A Field represents expansion data to be operated on.
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
Common base class of the element-operator interfaces: an operator applied independently to every elem...
Definition ElmtOp.hpp:111
MultiRegions::ExpListSharedPtr m_expansionList
Expansion list the operator acts on.
Definition Operator.hpp:349
Whole-field interface of the trace extraction: interpolates the volume field of every element onto th...
void ApplyNormalComponent(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out)
The outward normal component of a vector-valued field on the element-local traces; see PhysTraceExtra...
void SetUseGLLTracePoints(const bool useGLLTracePoints)
Extract onto the Gauss-Lobatto trace points rather than the element's own.
void ExtractTrace(const unsigned traceid, LibUtilities::BlockAccessor< TData, FieldState::Phys > &inblock, LibUtilities::BlockAccessor< TData, FieldState::Phys > &outblock, const unsigned outOffset, const unsigned blk)
Extract a single trace of every element of block blk into outblock at outOffset.
PhysTraceExtractOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
Construct the interface part of a concrete implementation; called by the factory-registered creator f...
void ExtractTrace(const unsigned traceid, LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out, const unsigned outOffset)
Extract a single trace of every element into out at outOffset.
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
bool m_useGLLTracePoints
The trace quadrature the blocks interpolate onto; see SetUseGLLTracePoints().
void SetIsCollocated(const bool isCollocated)
Set the tangential collocation flags of every block operator, passing false to force the fast path of...
LibUtilities::Field< TData, FieldState::Phys > m_normalScratch
Every component's trace for ApplyNormalComponent(), for the block implementations that extract them b...
static std::shared_ptr< PhysTraceExtractOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a trace extraction operator through the operator and block-operator factories.
std::vector< std::shared_ptr< PhysTraceExtractBlockOp< TData > > > m_blockOp
One block operator per element block of the expansion list; populated by ElmtOp::Create().
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Extract every trace of every element, block by block.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.