Nektar++
Loading...
Searching...
No Matches
PhysInterp1DScaledOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysInterp1DScaledOp.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 PhysInterp1DScaledOp.hpp
37 * @brief Whole-field interface of the PhysInterp1DScaled element operator,
38 * which re-evaluates a physical-space field on a rescaled quadrature grid
39 * of the same elements.
40 *
41 * @details
42 * ### What the operator computes
43 * Each element of a block holds its values on a tensor-product grid of
44 * quadrature points, \f$nm_d\f$ points in reference direction \f$d\f$.
45 * The operator interpolates those values onto a grid of \f$nq_d\f$ points
46 * of the same points distribution, so input and output are both in
47 * FieldState::Phys and only the number of points changes. In one
48 * direction that is
49 * \f[ u(\xi^{new}_i) = \sum_{p} h_p(\xi^{new}_i)\, u(\xi_p), \f]
50 * where \f$h_p\f$ is the Lagrange interpolant through the element's own
51 * quadrature points, \f$h_p(\xi_r) = \delta_{pr}\f$; in two and three
52 * directions it is the tensor product of one such sum per direction,
53 * \f[ u(\xi^{new}_{i}, \eta^{new}_{j}) =
54 * \sum_{p,q} h_p(\xi^{new}_{i})\, h_q(\eta^{new}_{j})\,
55 * u(\xi_p, \eta_q). \f]
56 * The element's geometry never enters -- no Jacobians or metric terms --
57 * and neither do the expansion's modes: the operator maps point values to
58 * point values. It is the block-operator counterpart of
59 * ExpList::PhysInterp1DScaled, the over-integration step
60 * the solvers use to dealias nonlinear terms; PhysGalerkinProject1DScaledOp
61 * maps the finer grid back. AdvectionDealiasOp performs the same
62 * interpolation as a stage of its own kernels, fetching the same
63 * warehouse data, rather than applying this operator.
64 *
65 * ### The scale factor
66 * The output point counts come from the single scale factor \f$\sigma\f$
67 * set through SetScaleFactor(), applied per direction to the *number of
68 * quadrature points* (it is not a geometric scaling):
69 * \f[ nq_0 = \lfloor \sigma\, nm_0 \rfloor, \qquad
70 * nq_d = \begin{cases}
71 * \lfloor \sigma\, nm_0 \rfloor - 1, & nm_0 - nm_d = 1 \\
72 * \lfloor \sigma\, nm_d \rfloor, & \text{otherwise}
73 * \end{cases} \quad (d = 1, 2). \f]
74 * The special case keeps a one-point offset between direction 0 and a
75 * direction one point shorter -- the standard point relation of the
76 * collapsed shapes -- intact in the output. It is the rule of
77 * MultiRegions::ExpList::Get1DScaledTotPoints, which writes the offset
78 * case as \f$\lfloor \sigma\, nm_0 - 1 \rfloor\f$, the same number for
79 * \f$\sigma\, nm_0 \ge 1\f$; so the operator's output sizes match those
80 * of a field the caller sized with it. Because the point counts differ
81 * between input and output, the two fields do not share block
82 * attributes: the output field must be built with per-element data
83 * counts computed from the same \f$\sigma\f$ by this rule.
84 *
85 * @note These are the counts the operator interpolates onto, but not the
86 * ones the sum-factorised implementations' size switch is driven by: that
87 * switch recomputes per-direction output counts as
88 * \f$\lfloor \sigma\, nm_d \rfloor\f$ from the scale factor and the input
89 * counts, without the offset case, and reads the counts derived here only
90 * for its runtime-sized fall-back (see
91 * LibUtilities/BasicUtils/Switch/BlockOpSwitchPhysInterp1D.h.in).
92 *
93 * ### Interpolation matrices
94 * The per-direction matrices are the interpolation operators from the
95 * direction's own points distribution to \f$nq_d\f$ points of that same
96 * distribution, taken from the data warehouse under
97 * LibUtilities::BasisDataKey with LibUtilities::eInterp and \f$nq_d\f$ as
98 * the target count, and laid out exactly like a 1D basis table:
99 * `I[p * nq_d + i]` is \f$h_p(\xi^{new}_i)\f$. That is why the
100 * sum-factorised implementations can drive the backward transform's
101 * tensor-product kernels unchanged, with the input points of a direction
102 * playing the role of its modes. The StdMat implementations instead fetch
103 * the assembled dense matrix over all directions (StdRegions::StdMatKey
104 * with StdRegions::ePhysInterpStdMat or its transpose, the output counts
105 * being part of the key). Either way the target point counts enter the
106 * warehouse key, so one cached entry is built per basis and target
107 * point count and shared between blocks and operators.
108 *
109 * The collapsed shapes need no special treatment: the physical points of
110 * a triangle, tetrahedron, prism or pyramid form a tensor-product grid in
111 * the collapsed coordinates, so the tensor-product kernels of the
112 * segment, quadrilateral and hexahedron serve every shape of the matching
113 * dimension.
114 *
115 * The family follows the standard element-operator layout (see
116 * ElmtOp.hpp):
117 * - PhysInterp1DScaledOp (this file): whole-field interface fixing the
118 * Apply() field states and carrying the scale factor to the blocks;
119 * - detail::PhysInterp1DScaledOpImpl (PhysInterp1DScaledOpImpl.hpp): the
120 * factory-registered whole-field implementation, one entry per
121 * execution space;
122 * - PhysInterp1DScaledBlockOp (PhysInterp1DScaledBlockOp.hpp): per-block
123 * interface, holding the scale factor;
124 * - detail::PhysInterp1DScaledBlockOpImpl: the per-block implementations.
125 * PhysInterp1DScaledBlockOpSerialAVXStdMat.hpp and
126 * PhysInterp1DScaledBlockOpSerialAVXSumFac.hpp each serve both the Serial and
127 * the AVX space, PhysInterp1DScaledBlockOpDeviceStdMat.hpp serves
128 * Device/StdMat, and PhysInterp1DScaledBlockOpDeviceSumFac.hpp serves both
129 * device sum-factorisation strategies (SumFac and SumFacTOP);
130 * - the kernel headers PhysInterp1DScaledBlockOpDeviceSumFacKernels.hpp and
131 * PhysInterp1DScaledBlockOpDeviceSumFacTOPKernels.hpp, which only include the
132 * backward transform's device kernels.
133 */
134
135#pragma once
136
138
140
141namespace Nektar::MultiRegions
142{
143
144/**
145 * @brief Whole-field interface of the scaled physical-space
146 * interpolation: re-evaluates a physical-space field on the rescaled
147 * quadrature grid of every element.
148 *
149 * As with the other element-operator families, this class exists to fix
150 * the Apply() parameter types at compile time -- physical space in,
151 * physical space out -- and to drive the per-block operators: it holds
152 * one PhysInterp1DScaledBlockOp per element block, and v_Apply() hands
153 * each block of the input/output fields to the matching entry. All
154 * numerical work happens in the block operators.
155 *
156 * SetScaleFactor() must be called before the first Apply(): it is what
157 * sets the output point counts and builds or fetches the interpolation
158 * data of every block operator (see the file notes for the scale-factor
159 * rule). The output field must have been sized with the same factor.
160 *
161 * Unlike BwdTransOp this family has no append mode; Apply() always
162 * overwrites the output.
163 *
164 * @tparam TData Floating-point type of the field data.
165 *
166 * @see PhysInterp1DScaledBlockOp for the per-block interface and the
167 * implementation strategies available per execution space.
168 */
169template <typename TData>
171 : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
172{
173 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
174
175public:
176 /**
177 * @brief Create a scaled-interpolation operator through the operator
178 * and block-operator factories.
179 *
180 * Builds the interface object under the factory key #name + @p execStr
181 * and one block operator per element block under
182 * PhysInterp1DScaledBlockOp::name + @p execStr + @p implStr (see
183 * ElmtOp::Create for the two-stage construction and for the session
184 * settings used when @p execStr or @p implStr is empty). The returned
185 * operator still needs SetScaleFactor() before it can be applied.
186 *
187 * @param expansionList Expansion list the operator acts on.
188 * @param components Names of the field components the
189 * operator is set up for.
190 * @param execStr Execution space ("Serial", "AVX" or
191 * "Device"); the session's setting if empty.
192 * @param implStr Block implementation ("StdMat", "SumFac"
193 * or, on the Device space, "SumFacTOP"); the
194 * session's setting if empty.
195 *
196 * @return The assembled operator, ready to Apply() once its scale
197 * factor is set.
198 */
199 static std::shared_ptr<PhysInterp1DScaledOp<TData>> Create(
200 const MultiRegions::ExpListSharedPtr &expansionList,
201 const std::vector<std::string> &components,
202 const std::string &execStr = "", const std::string &implStr = "")
203 {
205 template Create<PhysInterp1DScaledOp, PhysInterp1DScaledBlockOp>(
206 expansionList, components, execStr, implStr);
207 }
208
209 /// Operator base name; Create() appends the execution space to it to
210 /// form the operator-factory key.
211 static inline const std::string name = "PhysInterp1DScaled";
212
213 /**
214 * @brief Set the scale factor of every block operator, fixing the
215 * number of output points per direction.
216 *
217 * Forwarded to PhysInterp1DScaledBlockOp::SetScaleFactor on each
218 * block, where it also triggers the lookup of the interpolation data
219 * for the resulting point counts. Must be called before Apply().
220 * Calling it again with a different factor re-targets the operator:
221 * every implementation recomputes its point counts from the stored
222 * input counts and fetches the matching data afresh.
223 *
224 * @param scale Multiplier applied to the per-direction
225 * quadrature-point counts; see the file notes for
226 * the exact rule.
227 */
228 void SetScaleFactor(TData scale)
229 {
230 // Loop over the blocks.
231 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
232 {
233 this->m_blockOp[blk]->SetScaleFactor(scale);
234 }
235 }
236
237protected:
238 /// One block operator per element block of the expansion list;
239 /// populated by ElmtOp::Create().
240 std::vector<std::shared_ptr<PhysInterp1DScaledBlockOp<TData>>> m_blockOp;
241
242 /**
243 * @brief Construct the interface part of a concrete implementation;
244 * called by the factory-registered creator functions.
245 *
246 * @param expansionList Expansion list the operator acts on.
247 * @param components Component names the operator is set up
248 * for.
249 */
251 const std::vector<std::string> &components)
252 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
253 components)
254 {
255 }
256
257 ~PhysInterp1DScaledOp() override = default;
258
259 /**
260 * @brief Interpolate block by block.
261 *
262 * Checks that @p in and @p out agree in component and
263 * homogeneous-mode count -- their per-element data counts
264 * deliberately differ, being the unscaled and the scaled point counts
265 * -- then hands each pair of blocks to the corresponding entry of
266 * #m_blockOp.
267 *
268 * @param in Physical-space input field on the elements' own
269 * quadrature grids.
270 * @param out Physical-space output field on the scaled grids;
271 * overwritten.
272 */
275 {
276 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
277 "Number of input and output components differ");
278
279 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
280 "Number of input and output homogeneous modes differ");
281
282 // Loop over the blocks.
283 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
284 {
285 // Block dependent.
286 auto &inblock = in.GetBlocks()[blk];
287 auto &outblock = out.GetBlocks()[blk];
288
289 this->m_blockOp[blk]->Apply(inblock, outblock);
290 }
291 }
292};
293
294} // namespace Nektar::MultiRegions
Whole-field base class and factory machinery shared by every element-operator family in the MultiRegi...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Per-block interface class of the scaled physical-space interpolation operator.
A Field represents expansion data to be operated on.
Common base class of the element-operator interfaces: an operator applied independently to every elem...
Definition ElmtOp.hpp:111
Whole-field interface of the scaled physical-space interpolation: re-evaluates a physical-space field...
static const std::string name
Operator base name; Create() appends the execution space to it to form the operator-factory key.
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Interpolate block by block.
void SetScaleFactor(TData scale)
Set the scale factor of every block operator, fixing the number of output points per direction.
PhysInterp1DScaledOp(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...
std::vector< std::shared_ptr< PhysInterp1DScaledBlockOp< TData > > > m_blockOp
One block operator per element block of the expansion list; populated by ElmtOp::Create().
static std::shared_ptr< PhysInterp1DScaledOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a scaled-interpolation operator through the operator and block-operator factories.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.