Nektar++
Loading...
Searching...
No Matches
PhysLiftProjectOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysLiftProjectOp.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 lift-and-project element operator,
32// from physical-space inner products and element-local trace values to the
33// physical-space projection onto the polynomial space.
34//
35///////////////////////////////////////////////////////////////////////////////
36
37/**
38 * @file PhysLiftProjectOp.hpp
39 * @brief Public interface of the PhysLiftProject element operator: the
40 * trace lift followed by the projection through coefficient space, the tail
41 * of a weak discontinuous Galerkin right-hand side.
42 *
43 * @details
44 * For every element the operator computes
45 * \f[ u \mathrel{(+)=} s\, B M^{-1} B^{\mathsf T} (f + L g), \f]
46 * where
47 * - @c f holds the element's physical-space inner products, the arrays
48 * IProductWRTDerivBase (physical-space output) and IProductWRTPhysTrace
49 * write, which carry the quadrature metric already;
50 * - @c g holds values on the element's own traces, laid out by
51 * GetLocTraceBlockAttributes(), and @c L is the trace lift of
52 * IProductWRTPhysTrace, \f$\sum_F \int_F g\, h_{\boldsymbol p} J_F\f$;
53 * - \f$B^{\mathsf T}\f$ is the basis transpose without the metric
54 * (IProductWRTBase with SetIntegration(false)), \f$M\f$ the element mass
55 * matrix on the same quadrature and \f$B\f$ the backward transform;
56 * - @c s is the SetScale() factor, and SetAppend() accumulates onto @c u.
57 *
58 * It is therefore the four-operator chain IProductWRTPhysTrace (appending),
59 * IProductWRTBase without integration, MultiplyByElmtInvMass and BwdTrans,
60 * up to rounding. Each block takes one of three forms, decided at
61 * construction by detail::PhysLiftProjectFormOf():
62 * - **Pointwise**, where the element has as many modes as quadrature points:
63 * B is square, \f$M = B^{\mathsf T} W J B\f$, so
64 * \f$B M^{-1} B^{\mathsf T} = (W J)^{-1}\f$, a scale by the quadrature
65 * weight and the Jacobian at each point, on affine and deformed elements
66 * alike;
67 * - **StdInvMass**, on affine elements otherwise: the sum-factorised basis
68 * transpose, the standard inverse mass over the Jacobian (a scale per
69 * mode where the standard mass is diagonal) and the backward transform;
70 * - **ElmtInvMass**, on deformed elements otherwise: the four operators in
71 * sequence, as their block operators, MultiplyByElmtInvMass with each
72 * element's own inverse mass from the data warehouse
73 * (LocalRegions::ElmtInvMassKey).
74 *
75 * Apply(in, trace, out) lifts @c trace, each block through its block
76 * operator's ApplyLift(); the two-argument Apply(in, out) projects @c in
77 * alone. @c in and @c out are distinct fields; @c out leaves
78 * at the interleave width of @c in.
79 *
80 * The family follows the standard element-operator layout (see ElmtOp.hpp):
81 * this interface, detail::PhysLiftProjectOpImpl for the factory, the
82 * per-block interface PhysLiftProjectBlockOp, and two block implementations
83 * in each execution space, chosen as for the other element operators
84 * (`--opImpl` or the session's per-operator setting):
85 * - SumFac: PhysLiftProjectBlockOpSerialAVXSumFac.hpp (Serial and AVX, one
86 * element group at a time) and PhysLiftProjectBlockOpDeviceSumFac.hpp
87 * (Device, through the Device kernels of the four operators, SumFac or
88 * SumFacTOP), the Pointwise and StdInvMass forms;
89 * - StdMat: PhysLiftProjectBlockOpSerialAVXStdMat.hpp and
90 * PhysLiftProjectBlockOpDeviceStdMat.hpp, the StdInvMass form as one
91 * dense product with \f$P = B M_{\mathrm{std}}^{-1} B^{\mathsf T}\f$
92 * (nqTot x nqTot, from the data warehouse) scaled by `scale / J`, and the
93 * Pointwise form through the kernels it shares with SumFac;
94 * and in both the ElmtInvMass form through PhysLiftProjectBlockOp's
95 * CreateChain() and ApplyElmtInvMass().
96 */
97
98#pragma once
99
101
103
104namespace Nektar::MultiRegions
105{
106
107/**
108 * @brief Whole-field interface of the lift-and-project operator: holds one
109 * PhysLiftProjectBlockOp per element block and hands each block of the
110 * fields to it.
111 *
112 * @tparam TData Floating-point type of the field data.
113 */
114template <typename TData>
116 : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
117{
118 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
119
120public:
121 using ElmtOp<FieldState::Phys, FieldState::Phys, TData>::Apply;
122
123 /**
124 * @brief Create the operator through the operator and block-operator
125 * factories (see ElmtOp::Create()).
126 */
127 static std::shared_ptr<PhysLiftProjectOp<TData>> Create(
128 const MultiRegions::ExpListSharedPtr &expansionList,
129 const std::vector<std::string> &components,
130 const std::string &execStr = "", const std::string &implStr = "")
131 {
133 template Create<PhysLiftProjectOp, PhysLiftProjectBlockOp>(
134 expansionList, components, execStr, implStr);
135 }
136
137 /// Operator base name; Create() appends the execution space to it to
138 /// form the factory key.
139 static inline const std::string name = "PhysLiftProject";
140
141 /**
142 * @brief `out (+)= scale * B M^{-1} B^T (in + L trace)`.
143 *
144 * @param in Volume inner products, laid out by
145 * GetBlockAttributes().
146 * @param trace Values on the elements' own traces, laid out by
147 * GetLocTraceBlockAttributes(), with the components of
148 * @p in.
149 * @param out Volume field, written or accumulated onto.
150 */
157
158 /// The factor the result is scaled by, on every block.
159 void SetScale(const TData &scale)
160 {
161 for (unsigned int blk = 0; blk < m_blockOp.size(); ++blk)
162 {
163 m_blockOp[blk]->SetScale(scale);
164 }
165 }
166
167 /// Accumulate onto the output instead of overwriting it, on every
168 /// block.
169 void SetAppend(const bool &append)
170 {
171 for (unsigned int blk = 0; blk < m_blockOp.size(); ++blk)
172 {
173 m_blockOp[blk]->SetAppend(append);
174 }
175 }
176
177protected:
178 std::vector<std::shared_ptr<PhysLiftProjectBlockOp<TData>>> m_blockOp;
179
181 const std::vector<std::string> &components)
182 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
183 components)
184 {
185 }
186
187 ~PhysLiftProjectOp() override = default;
188
189 /// The projection of @p in alone.
192 {
193 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
194 "Number of input and output components differ");
195 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
196 "Number of input and output homogeneous modes differ");
197
198 for (unsigned int blk = 0; blk < m_blockOp.size(); ++blk)
199 {
200 m_blockOp[blk]->Apply(in.GetBlocks()[blk], out.GetBlocks()[blk]);
201 }
202 }
203
204 /// Implementation hook for the three-argument Apply().
205 virtual void v_ApplyLift(
209 {
210 ASSERTL1(in.GetNumComponents() == out.GetNumComponents() &&
211 trace.GetNumComponents() == in.GetNumComponents(),
212 "Number of input, trace and output components differ");
213 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes() &&
214 trace.GetNumHomoModes() == in.GetNumHomoModes(),
215 "Number of input, trace and output homogeneous modes differ");
216
217 for (unsigned int blk = 0; blk < m_blockOp.size(); ++blk)
218 {
219 m_blockOp[blk]->ApplyLift(in.GetBlocks()[blk],
220 trace.GetBlocks()[blk],
221 out.GetBlocks()[blk]);
222 }
223 }
224};
225
226} // 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 PhysLiftProject element operator, and the choice of its form for a block.
A Field represents expansion data to be operated on.
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
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
Whole-field interface of the lift-and-project operator: holds one PhysLiftProjectBlockOp per element ...
void SetScale(const TData &scale)
The factor the result is scaled by, on every block.
void SetAppend(const bool &append)
Accumulate onto the output instead of overwriting it, on every block.
void Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &trace, LibUtilities::Field< TData, FieldState::Phys > &out)
out (+)= scale * B M^{-1} B^T (in + L trace).
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
static std::shared_ptr< PhysLiftProjectOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create the operator through the operator and block-operator factories (see ElmtOp::Create()).
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
The projection of in alone.
virtual void v_ApplyLift(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &trace, LibUtilities::Field< TData, FieldState::Phys > &out)
Implementation hook for the three-argument Apply().
PhysLiftProjectOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
std::vector< std::shared_ptr< PhysLiftProjectBlockOp< TData > > > m_blockOp
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.