Nektar++
Loading...
Searching...
No Matches
MassOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MassOp.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 mass element operator.
32///////////////////////////////////////////////////////////////////////////////
33
34/**
35 * @file MassOp.hpp
36 * @brief Whole-field interface of the Mass element operator, which applies
37 * every element's mass matrix to a coefficient-space field.
38 *
39 * @details
40 * For every element the operator integrates the expansion against each of
41 * that element's own basis functions,
42 * \f[ I_n = \int_{\Omega^e} \phi_n\,u \,\mathrm{d}x
43 * = \sum_m \hat{u}_m \int_{\Omega^e} \phi_n\,\phi_m \,\mathrm{d}x
44 * \approx \sum_i w_i\,J_i\,\phi_n(\xi_i)
45 * \sum_m \hat{u}_m\,\phi_m(\xi_i), \f]
46 * that is, it applies the element mass matrix to the input coefficients.
47 * Written that way the operator is the composition of the two families it
48 * is built from: BwdTrans evaluates
49 * \f$u(\xi_i) = \sum_m \hat{u}_m \phi_m(\xi_i)\f$ at the quadrature points,
50 * and IProductWRTBase integrates that result against the basis, supplying
51 * the quadrature metric -- the tensor product of the expansion's
52 * per-direction weight tables \f$w_i\f$ times the element Jacobian
53 * \f$J_i\f$ (one value per element for a regular geometry, one per
54 * quadrature point for a deformed one). Every implementation in this
55 * family reuses those two families' kernels or standard-region matrices
56 * for the two stages; they differ in where the quadrature metric is
57 * applied, set out below, and in that the regular-geometry StdMat path
58 * collapses the pair into the single precomputed standard-region mass
59 * matrix.
60 *
61 * Where the metric enters depends on the implementation:
62 * - the SumFac paths hand the expansion's per-direction weight tables and
63 * the block's Jacobian table to the inner-product kernel, which applies
64 * them inside its contraction;
65 * - the SumFacTOP path multiplies the staged physical values by the metric
66 * between the two stages and then calls the inner-product shape kernels
67 * in their metric-free form;
68 * - the StdMat paths inherit the weights from the standard-region matrices
69 * they fetch from the data warehouse (which are built by applying the
70 * corresponding StdExpansion operation to unit vectors) and apply the
71 * Jacobian separately -- to the intermediate physical values for a
72 * deformed block, and, since the Jacobian is then one constant per
73 * element, to the coefficient-space result for a regular one.
74 *
75 * MassOp is the whole-field interface class of the family (see ElmtOp.hpp
76 * for the two-level element-operator structure); the per-block interface
77 * is MassBlockOp (MassBlockOp.hpp) and the factory shell
78 * detail::MassOpImpl (MassOpImpl.hpp). The numerical work lives in the
79 * detail::MassBlockOpImpl definitions -- MassBlockOpSerialAVXStdMat.hpp and
80 * MassBlockOpSerialAVXSumFac.hpp for the Serial and AVX execution spaces,
81 * MassBlockOpDeviceStdMat.hpp for the Device StdMat implementation and
82 * MassBlockOpDeviceSumFac.hpp for both Device sum-factorisation strategies
83 * (SumFac and SumFacTOP) -- registered with the block-operator factory by
84 * CMake-generated translation units, one per execution space,
85 * implementation and data type. The sum-factorised kernel launchers are in
86 * MassBlockOpSerialAVXSumFacKernels.hpp, MassBlockOpDeviceSumFacKernels.hpp and
87 * MassBlockOpDeviceSumFacTOPKernels.hpp.
88 *
89 * @see BwdTransOp.hpp and IProductWRTBaseOp.hpp for the two operators
90 * composed here, in particular the note in the latter on the weight tables
91 * of the collapsed shapes.
92 */
93
94#pragma once
95
97
99
100namespace Nektar::MultiRegions
101{
102
103/**
104 * @brief Whole-field interface of the mass operator: applies each
105 * element's mass matrix to a coefficient-space field.
106 *
107 * @details
108 * As with the other element-operator families, this class sets the
109 * Apply() field states at compile time -- coefficient space in and out,
110 * BwdTransOp's input state composed with IProductWRTBaseOp's output state
111 * -- and drives one MassBlockOp per element block; the per-execution-space
112 * behaviour lives in the block operators, not here (the factory shell
113 * detail::MassOpImpl adds nothing beyond registration). See ElmtOp for the
114 * block decomposition and factory scheme.
115 *
116 * Two settings modify what the block operators compute, both forwarded to
117 * every block operator: SetScale(s) multiplies the result by the scalar s,
118 * and after SetAppend(true) Apply() accumulates the scaled result onto the
119 * output's existing values instead of overwriting them. The underlying
120 * BwdTrans kernels run with APPEND false; the scale and the append flag
121 * enter in the IProductWRTBase stage, or in the GEMM and Jacobian step of
122 * the StdMat paths.
123 *
124 * @tparam TData Floating-point type of the field data.
125 *
126 * @see MassBlockOp for the per-block interface.
127 */
128template <typename TData>
129class MassOp : public ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>
130{
131 friend class ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>;
132
133public:
134 /**
135 * @brief Build a complete Mass operator through the operator and
136 * block-operator factories.
137 *
138 * The operator-factory key is #name + @p execStr and the block-operator
139 * key MassBlockOp::name + @p execStr + @p implStr; see ElmtOp::Create
140 * for the two-stage construction and the execution-space and
141 * implementation lookup rules.
142 *
143 * @param expansionList Expansion list the operator acts on.
144 * @param components Names of the field components the operator
145 * is set up for.
146 * @param execStr Execution space ("Serial", "AVX" or
147 * "Device"); the session's setting is used
148 * if empty.
149 * @param implStr Implementation ("StdMat", "SumFac" or, on
150 * Device, "SumFacTOP"); the session's
151 * setting is used if empty.
152 *
153 * @return The fully assembled operator, ready to Apply().
154 */
155 static std::shared_ptr<MassOp<TData>> Create(
156 const MultiRegions::ExpListSharedPtr &expansionList,
157 const std::vector<std::string> &components,
158 const std::string &execStr = "", const std::string &implStr = "")
159 {
161 template Create<MassOp, MassBlockOp>(expansionList, components,
162 execStr, implStr);
163 }
164
165 /// Operator base name; Create() appends the execution space to it to
166 /// form the operator-factory key.
167 static inline const std::string name = "Mass";
168
169 /**
170 * @brief Switch all block operators between overwrite and
171 * accumulate mode.
172 *
173 * With @p append set, subsequent Apply() calls add the scaled result
174 * onto the output field's existing contents instead of overwriting
175 * them. The default is overwrite.
176 *
177 * @param append Accumulate into the output when true.
178 */
179 void SetAppend(const bool &append)
180 {
181 // Loop over the blocks.
182 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
183 {
184 this->m_blockOp[blk]->SetAppend(append);
185 }
186 }
187
188 /**
189 * @brief Set the factor every block operator multiplies its result by.
190 * The initial value is 1.
191 *
192 * @param scale Factor applied to the result of subsequent Apply()
193 * calls.
194 */
195 void SetScale(const TData &scale)
196 {
197 // Loop over the blocks.
198 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
199 {
200 this->m_blockOp[blk]->SetScale(scale);
201 }
202 }
203
204protected:
205 /// One block operator per element block, filled by Create().
206 std::vector<std::shared_ptr<MassBlockOp<TData>>> m_blockOp;
207
208 /**
209 * @brief Construct the interface part of a concrete operator; called by
210 * the factory-registered creator functions.
211 *
212 * @param expansionList Expansion list the operator acts on.
213 * @param components Field component names the operator is set
214 * up for.
215 */
217 const std::vector<std::string> &components)
218 : ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>(expansionList,
219 components)
220 {
221 }
222
223 ~MassOp() override = default;
224
225 /**
226 * @brief Apply the operator block by block.
227 *
228 * Checks that the two fields agree in their component and
229 * homogeneous-mode counts, then hands each input/output block pair to
230 * the corresponding entry of #m_blockOp. Input and output are both in
231 * coefficient space, so the two fields carry the same number of data
232 * values per element.
233 *
234 * @param in Coefficient-space input field.
235 * @param out Coefficient-space output field; overwritten, or
236 * accumulated into when append mode is set.
237 */
240 {
241 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
242 "Number of input and output components differ");
243
244 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
245 "Number of input and output homogeneous modes differ");
246
247 // Loop over the blocks.
248 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
249 {
250 // Block dependent.
251 auto &inblock = in.GetBlocks()[blk];
252 auto &outblock = out.GetBlocks()[blk];
253
254 this->m_blockOp[blk]->Apply(inblock, outblock);
255 }
256 }
257};
258
259} // 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 Mass 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 mass operator: applies each element's mass matrix to a coefficient-space...
Definition MassOp.hpp:130
void v_Apply(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Coeff > &out) override
Apply the operator block by block.
Definition MassOp.hpp:238
static const std::string name
Operator base name; Create() appends the execution space to it to form the operator-factory key.
Definition MassOp.hpp:167
MassOp(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...
Definition MassOp.hpp:216
static std::shared_ptr< MassOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete Mass operator through the operator and block-operator factories.
Definition MassOp.hpp:155
void SetAppend(const bool &append)
Switch all block operators between overwrite and accumulate mode.
Definition MassOp.hpp:179
~MassOp() override=default
void SetScale(const TData &scale)
Set the factor every block operator multiplies its result by. The initial value is 1.
Definition MassOp.hpp:195
std::vector< std::shared_ptr< MassBlockOp< TData > > > m_blockOp
One block operator per element block, filled by Create().
Definition MassOp.hpp:206
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.