Nektar++
Loading...
Searching...
No Matches
IProductWRTBaseOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: IProductWRTBaseOp.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: Whole-field interface of the inner product with the
32// basis
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file IProductWRTBaseOp.hpp
37 * @brief Whole-field interface of the IProductWRTBase element operator,
38 * which takes a physical-space field to its inner product with every basis
39 * function of every element.
40 *
41 * @details
42 * For every element the operator evaluates
43 * \f[ I_n = \int_{\Omega^e} u\,\phi_n \,\mathrm{d}x
44 * \approx \sum_i w_i\,J_i\,\phi_n(\xi_i)\,u(\xi_i), \f]
45 * that is, it applies the transpose of the element's backward-transform
46 * matrix to the input after weighting the input by the quadrature metric:
47 * the tensor product of the expansion's per-direction weight tables
48 * \f$w_i\f$ times the element Jacobian \f$J_i\f$ (one value per element
49 * for a regular geometry, one per quadrature point for a deformed one).
50 * Through that Jacobian, and unlike BwdTrans, whose matrix it transposes,
51 * the operator does depend on the element geometry.
52 *
53 * The per-direction weight tables are the expansion's own
54 * (LibUtilities::BasisDataKey with eWeights): for the collapsed shapes --
55 * triangle, tetrahedron, prism and pyramid -- they are not the raw
56 * one-dimensional quadrature weights but already carry the factors of the
57 * collapsed coordinate map, which is why \f$w_i\f$ above is their tensor
58 * product rather than the tensor product of the Gaussian weights. The
59 * standard-region matrices of the StdMat implementations carry the same
60 * factors, being built by applying StdExpansion::IProductWRTBase to the
61 * physical unit vectors.
62 *
63 * Three settings modify that default behaviour, all forwarded to every
64 * block operator of the family:
65 * - SetIntegration(false) drops the quadrature metric, leaving the plain
66 * basis transpose \f$\sum_i \phi_n(\xi_i)\,u(\xi_i)\f$ for input that
67 * already carries \f$w J\f$. That is how the physical-output
68 * instantiation of IProductWRTDerivBase is completed into coefficients
69 * (see IProductWRTDerivBaseOp.hpp).
70 * - SetScale(s) multiplies the result by the scalar s.
71 * - SetAppend(true) adds the result onto the output instead of
72 * overwriting it.
73 *
74 * IProductWRTBaseOp is the whole-field interface class of the family (see
75 * ElmtOp.hpp for the two-level element-operator structure); the per-block
76 * interface is IProductWRTBaseBlockOp (IProductWRTBaseBlockOp.hpp). The
77 * numerical work lives in the detail::IProductWRTBaseBlockOpImpl
78 * definitions -- IProductWRTBaseBlockOpSerialAVXStdMat.hpp and
79 * IProductWRTBaseBlockOpSerialAVXSumFac.hpp for the Serial and AVX execution
80 * spaces, IProductWRTBaseBlockOpDeviceStdMat.hpp for the Device StdMat
81 * implementation and IProductWRTBaseBlockOpDeviceSumFac.hpp for both Device
82 * sum-factorisation strategies (SumFac and SumFacTOP) -- registered with
83 * the block-operator factory by CMake-generated translation units, one per
84 * execution space, implementation and data type. The sum-factorised
85 * kernels are in IProductWRTBaseBlockOpSerialAVXSumFacKernels.hpp,
86 * IProductWRTBaseBlockOpDeviceSumFacKernels.hpp and
87 * IProductWRTBaseBlockOpDeviceSumFacTOPKernels.hpp.
88 *
89 * @see BwdTransOp.hpp for the operator this one transposes.
90 */
91
92#pragma once
93
95
97
99{
100
101/**
102 * @brief Whole-field interface of the inner product with the basis:
103 * integrates a physical-space field against every basis function of every
104 * element.
105 *
106 * @details
107 * As with the other element-operator families, this class sets the
108 * Apply() field states at compile time -- input in FieldState::Phys,
109 * output in FieldState::Coeff, the reverse of BwdTransOp -- and drives one
110 * IProductWRTBaseBlockOp per element block; the per-execution-space
111 * behaviour lives in the block operators, not here (the factory shell
112 * detail::IProductWRTBaseOpImpl adds nothing beyond registration). See
113 * ElmtOp for the block decomposition and factory scheme.
114 *
115 * By default Apply() overwrites the output field; after SetAppend(true)
116 * it instead accumulates the scaled inner product onto the output's
117 * existing values.
118 *
119 * Three settings modify what the block operators compute: the scale factor
120 * applied to the result, the append flag and the quadrature-metric switch,
121 * all forwarded to every block operator by SetScale(), SetAppend() and
122 * SetIntegration().
123 *
124 * @tparam TData Floating-point type of the field data.
125 */
126template <typename TData>
128 : public ElmtOp<FieldState::Phys, FieldState::Coeff, TData>
129{
130 friend class ElmtOp<FieldState::Phys, FieldState::Coeff, TData>;
131
132public:
133 /**
134 * @brief Build a complete IProductWRTBase operator through the operator
135 * and block-operator factories.
136 *
137 * The operator-factory key is #name + @p execStr and the block-operator
138 * key IProductWRTBaseBlockOp::name + @p execStr + @p implStr; see
139 * ElmtOp::Create for the two-stage construction and the execution-space
140 * and implementation lookup rules.
141 *
142 * @param expansionList Expansion list the operator acts on.
143 * @param components Names of the field components the operator
144 * is set up for.
145 * @param execStr Execution space ("Serial", "AVX" or
146 * "Device"); the session's setting is used
147 * if empty.
148 * @param implStr Implementation ("StdMat", "SumFac" or, on
149 * Device, "SumFacTOP"); the session's
150 * setting is used if empty.
151 *
152 * @return The fully assembled operator, ready to Apply().
153 */
154 static std::shared_ptr<IProductWRTBaseOp<TData>> Create(
155 const MultiRegions::ExpListSharedPtr &expansionList,
156 const std::vector<std::string> &components,
157 const std::string &execStr = "", const std::string &implStr = "")
158 {
160 template Create<IProductWRTBaseOp, IProductWRTBaseBlockOp>(
161 expansionList, components, execStr, implStr);
162 }
163
164 /// Operator base name; Create() appends the execution space to it to
165 /// form the operator-factory key.
166 static inline const std::string name = "IProductWRTBase";
167
168 /**
169 * @brief Switch all block operators between overwrite and
170 * accumulate mode.
171 *
172 * With @p append set, subsequent Apply() calls add the scaled inner
173 * product onto the output field's existing contents instead of
174 * overwriting them. The default is overwrite.
175 *
176 * @param append Accumulate into the output when true.
177 */
178 void SetAppend(const bool &append)
179 {
180 // Loop over the blocks.
181 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
182 {
183 this->m_blockOp[blk]->SetAppend(append);
184 }
185 }
186
187 /**
188 * @brief Switch the quadrature metric on (the initial state) or off for
189 * every block operator.
190 *
191 * With @p value false the operator applies the basis transpose alone,
192 * without the quadrature weights and the Jacobian, which is what an
193 * input already carrying \f$wJ\f$ needs (see the file notes). With
194 * @p value true it performs the full inner product.
195 *
196 * @param value Apply the quadrature metric when true.
197 */
198 void SetIntegration(bool value)
199 {
200 // Loop over the blocks.
201 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
202 {
203 this->m_blockOp[blk]->SetIntegration(value);
204 }
205 }
206
207 /**
208 * @brief Set the factor every block operator multiplies its result by.
209 *
210 * The factor applies to the coefficient-space result whether or not
211 * the quadrature metric is in use. The initial value is 1.
212 *
213 * @param scale Factor applied to the result of subsequent Apply()
214 * calls.
215 */
216 void SetScale(const TData &scale)
217 {
218 // Loop over the blocks.
219 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
220 {
221 this->m_blockOp[blk]->SetScale(scale);
222 }
223 }
224
225protected:
226 /// One block operator per element block, filled by Create().
227 std::vector<std::shared_ptr<IProductWRTBaseBlockOp<TData>>> m_blockOp;
228
229 /**
230 * @brief Construct the interface part of a concrete operator; called by
231 * the factory-registered creator functions.
232 *
233 * @param expansionList Expansion list the operator acts on.
234 * @param components Field component names the operator is set
235 * up for.
236 */
238 const std::vector<std::string> &components)
239 : ElmtOp<FieldState::Phys, FieldState::Coeff, TData>(expansionList,
240 components)
241 {
242 }
243
244 ~IProductWRTBaseOp() override = default;
245
246 /**
247 * @brief Apply the operator block by block.
248 *
249 * Checks that the two fields agree in their component and
250 * homogeneous-mode counts, then hands each input/output block pair to
251 * the corresponding entry of #m_blockOp.
252 *
253 * @param in Physical-space input field.
254 * @param out Coefficient-space output field; overwritten, or
255 * accumulated into when append mode is set.
256 */
259 {
260 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
261 "Number of input and output components differ");
262
263 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
264 "Number of input and output homogeneous modes differ");
265
266 // Loop over the blocks.
267 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
268 {
269 // Block dependent.
270 auto &inblock = in.GetBlocks()[blk];
271 auto &outblock = out.GetBlocks()[blk];
272
273 this->m_blockOp[blk]->Apply(inblock, outblock);
274 }
275 }
276};
277
278} // 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 of the IProductWRTBase element 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 inner product with the basis: integrates a physical-space field against ...
std::vector< std::shared_ptr< IProductWRTBaseBlockOp< TData > > > m_blockOp
One block operator per element block, filled by Create().
void SetIntegration(bool value)
Switch the quadrature metric on (the initial state) or off for every block operator.
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Coeff > &out) override
Apply the operator block by block.
static std::shared_ptr< IProductWRTBaseOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete IProductWRTBase operator through the operator and block-operator factories.
IProductWRTBaseOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
Construct the interface part of a concrete operator; called by the factory-registered creator functio...
void SetScale(const TData &scale)
Set the factor every block operator multiplies its result by.
void SetAppend(const bool &append)
Switch all block operators between overwrite and accumulate mode.
static const std::string name
Operator base name; Create() appends the execution space to it to form the operator-factory key.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.