Nektar++
Loading...
Searching...
No Matches
MultiplyByElmtInvMassOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MultiplyByElmtInvMassOp.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 MultiplyByElmtInvMassOp.hpp
37 * @brief Whole-field interface of the MultiplyByElmtInvMass element
38 * operator, which multiplies a coefficient-space field by the inverse of
39 * each element's own mass matrix.
40 *
41 * @details
42 * For every element the operator applies the inverse of that element's
43 * mass matrix
44 * \f[ M^e_{mn} = \int_{\Omega^e} \phi_m \phi_n \,\mathrm{d}\boldsymbol{x} \f]
45 * to that element's coefficients. It maps coefficient space to coefficient
46 * space and couples no degrees of freedom between elements; it is the
47 * block-operator counterpart of ExpList::MultiplyByElmtInvMass. Applied to
48 * the output of IProductWRTBaseOp it gives the element-local
49 * (discontinuous Galerkin) forward transform. The weak-DG
50 * advection and diffusion operators invert the element mass matrix of the
51 * semi-discrete system through PhysLiftProjectOp instead, which applies the
52 * same inverse mass (or, where B is square, its pointwise equivalent) to
53 * their assembled residual together with the trace lift and the backward
54 * transform.
55 *
56 * Unlike the transform-type families there is no StdMat/SumFac split: a
57 * single implementation is registered per execution space under the
58 * Generic tag (see ElmtBlockOp.hpp), and the only case distinction it makes
59 * is between blocks of regular and of deformed geometry (see
60 * MultiplyByElmtInvMassBlockOp.hpp). The family is laid out as
61 * - MultiplyByElmtInvMassOp (this file): whole-field interface;
62 * - detail::MultiplyByElmtInvMassOpImpl (MultiplyByElmtInvMassOpImpl.hpp):
63 * the factory-registered whole-field shell, one entry per execution
64 * space;
65 * - MultiplyByElmtInvMassBlockOp (MultiplyByElmtInvMassBlockOp.hpp):
66 * per-block interface;
67 * - detail::MultiplyByElmtInvMassBlockOpImpl, defined for the Serial and
68 * AVX execution spaces in MultiplyByElmtInvMassBlockOpSerialAVXGeneric.hpp
69 * and for the Device execution space in
70 * MultiplyByElmtInvMassBlockOpDeviceGeneric.hpp.
71 */
72
73#pragma once
74
76
78
80{
81
82/**
83 * @brief Whole-field interface of the element-wise inverse mass operator:
84 * replaces every element's coefficients by the solution of that element's
85 * mass system.
86 *
87 * @details
88 * As with the other element-operator families this class sets the Apply()
89 * field states at compile time -- coefficient space in, coefficient space
90 * out -- and drives one MultiplyByElmtInvMassBlockOp per element block:
91 * v_Apply() hands each block of the input and output fields to the matching
92 * entry of #m_blockOp, and all numerical work happens in the block
93 * operators (the factory shell detail::MultiplyByElmtInvMassOpImpl adds
94 * nothing beyond registration).
95 *
96 * @tparam TData Floating-point type of the field data.
97 *
98 * @see MultiplyByElmtInvMassBlockOp for the per-block interface and the
99 * regular/deformed case distinction the implementations make.
100 */
101template <typename TData>
103 : public ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>
104{
105 friend class ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>;
106
107public:
108 /**
109 * @brief Build a complete element-wise inverse mass operator through
110 * the operator and block-operator factories.
111 *
112 * The interface object and one block operator per element block are
113 * built by ElmtOp::Create under the keys #name + @p execStr and
114 * MultiplyByElmtInvMassBlockOp::name + @p execStr + @p implStr. Only
115 * the "Generic" implementation is registered for this family, so
116 * ElmtBlockOp::Create falls back to it whatever @p implStr asks for.
117 * A block of deformed elements fetches its per-element inverse mass
118 * matrices from the data warehouse (LocalRegions::ElmtInvMassKey), so
119 * every operator on the expansion list shares one copy.
120 *
121 * @param expansionList Expansion list the operator acts on.
122 * @param components Names of the field components the operator
123 * is set up for.
124 * @param execStr Execution space ("Serial", "AVX" or
125 * "Device"); the session's setting is used
126 * if empty.
127 * @param implStr Implementation; the session's setting is
128 * used if empty, and either way the lookup
129 * resolves to "Generic" as described above.
130 *
131 * @return The fully assembled operator, ready to Apply().
132 */
133 static std::shared_ptr<MultiplyByElmtInvMassOp<TData>> Create(
134 const MultiRegions::ExpListSharedPtr &expansionList,
135 const std::vector<std::string> &components,
136 const std::string &execStr = "", const std::string &implStr = "")
137 {
139 TData>::template Create<MultiplyByElmtInvMassOp,
141 expansionList, components, execStr, implStr);
142 }
143
144 /// Operator base name; Create() appends the execution space to it to
145 /// form the operator-factory key.
146 static inline const std::string name = "MultiplyByElmtInvMass";
147
148protected:
149 /// One block operator per element block, filled by Create().
150 std::vector<std::shared_ptr<MultiplyByElmtInvMassBlockOp<TData>>> m_blockOp;
151
152 /**
153 * @brief Construct the interface part of a concrete operator; called by
154 * the factory-registered creator functions.
155 *
156 * @param expansionList Expansion list the operator acts on.
157 * @param components Field component names the operator is set
158 * up for.
159 */
161 const std::vector<std::string> &components)
162 : ElmtOp<FieldState::Coeff, FieldState::Coeff, TData>(expansionList,
163 components)
164 {
165 }
166
167 ~MultiplyByElmtInvMassOp() override = default;
168
169 /**
170 * @brief Apply the operator block by block.
171 *
172 * Checks that the two fields agree in their component and
173 * homogeneous-mode counts, then hands each input/output block pair to
174 * the corresponding entry of #m_blockOp.
175 *
176 * @param in Coefficient-space input field.
177 * @param out Coefficient-space output field; overwritten.
178 */
181 {
182 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
183 "Number of input and output components differ");
184
185 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
186 "Number of input and output homogeneous modes differ");
187
188 // Loop over the blocks.
189 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
190 {
191 // Block dependent.
192 auto &inblock = in.GetBlocks()[blk];
193 auto &outblock = out.GetBlocks()[blk];
194
195 this->m_blockOp[blk]->Apply(inblock, outblock);
196 }
197 }
198};
199
200} // 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 MultiplyByElmtInvMass 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
static std::shared_ptr< TOperator< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete element operator: the whole-field interface object plus one block operator per eleme...
Definition ElmtOp.hpp:166
Base class of the per-block inverse mass operators: applies each element's inverse mass matrix to tha...
Whole-field interface of the element-wise inverse mass operator: replaces every element's coefficient...
static const std::string name
Operator base name; Create() appends the execution space to it to form the operator-factory key.
static std::shared_ptr< MultiplyByElmtInvMassOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete element-wise inverse mass operator through the operator and block-operator factories...
std::vector< std::shared_ptr< MultiplyByElmtInvMassBlockOp< TData > > > m_blockOp
One block operator per element block, filled by Create().
void v_Apply(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Coeff > &out) override
Apply the operator block by block.
MultiplyByElmtInvMassOp(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...
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.