Nektar++
Loading...
Searching...
No Matches
DivergenceOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: DivergenceOp.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 DivergenceOp.hpp
37 * @brief Public interface of the Divergence element operator, which
38 * evaluates the divergence of a physical-space vector field at the
39 * quadrature points of every element.
40 *
41 * @details
42 * The operator forms
43 * \f[ \nabla\cdot\mathbf{u}
44 * = \sum_{d} \frac{\partial u_d}{\partial x_d}, \f]
45 * where the sum runs over the shape dimension of the expansion and
46 * \f$u_d\f$ is the d-th component of the input field. Each physical
47 * derivative is obtained element by element, by differentiating in the
48 * element's reference directions and contracting with that element's
49 * derivative factors (the metric terms
50 * \f$\partial\xi_j/\partial x_d\f$), so unlike BwdTrans the geometry
51 * enters through the derivative-factor tables cached in the data
52 * warehouse. On a multi-plane 3DH1 expansion this is done plane by
53 * plane and \f$\partial w/\partial z\f$, w being input component 2,
54 * is added afterwards by the homogeneous z-derivative.
55 *
56 * The family follows the standard element-operator layout (see
57 * ElmtOp.hpp):
58 * - DivergenceOp (this file): whole-field interface setting the
59 * Apply() field states and running the per-block operators, then the
60 * v_ApplyFFT() hook;
61 * - detail::DivergenceOpImpl (DivergenceOpImpl.hpp): the
62 * factory-registered whole-field implementation, one entry per
63 * execution space, which builds the homogeneous z-derivative and
64 * runs it in v_ApplyFFT();
65 * - DivergenceBlockOp (DivergenceBlockOp.hpp): per-block interface;
66 * - detail::DivergenceBlockOpImpl: the per-block implementations, one
67 * header per implementation family --
68 * DivergenceBlockOpSerialAVXStdMat.hpp and
69 * DivergenceBlockOpSerialAVXSumFac.hpp each serve both the Serial and the AVX
70 * space, DivergenceBlockOpDeviceStdMat.hpp serves Device/StdMat, and
71 * DivergenceBlockOpDeviceSumFac.hpp serves both device sum-factorisation
72 * strategies (SumFac and SumFacTOP);
73 * - the kernel launchers in DivergenceBlockOpSerialAVXSumFacKernels.hpp,
74 * DivergenceBlockOpDeviceSumFacKernels.hpp and
75 * DivergenceBlockOpDeviceSumFacTOPKernels.hpp, which chain the PhysDeriv
76 * kernels of their execution space component by component. The
77 * StdMat paths have no kernels of their own: they call the PhysDeriv
78 * StdMat kernels directly;
79 * - detail::DerivZOpImpl (DerivZOpImpl.hpp, shared with the other
80 * operator families): the homogeneous z-derivative used for
81 * multi-plane 3DH1 fields, invoked through v_ApplyFFT() after the
82 * per-block operators above.
83 */
84
85#pragma once
86
88
90
92{
93
94/**
95 * @brief Whole-field interface of the divergence operator: sums the
96 * physical derivatives \f$\partial u_d / \partial x_d\f$ of the first
97 * shape-dimension components of a physical-space field.
98 *
99 * As with the other element-operator families, this class exists to
100 * set the Apply() parameter types at compile time -- both input and
101 * output in FieldState::Phys -- and to drive the per-block operators:
102 * it holds one DivergenceBlockOp per element block, and v_Apply()
103 * hands each block of the input/output fields to the matching entry.
104 * The block operators form the divergence over the shape dimension; on
105 * a multi-plane 3DH1 expansion v_ApplyFFT(), implemented by
106 * detail::DivergenceOpImpl, then adds \f$\partial w/\partial z\f$.
107 *
108 * The input field must carry at least as many components as the
109 * expansion's shape dimension; the first shape-dimension components
110 * are interpreted as the Cartesian components of the vector field.
111 * Every block operator reads only those components and accumulates
112 * their derivatives into output component 0, one homogeneous plane at
113 * a time; in one dimension that is
114 * \f$\mathrm{d}u_0/\mathrm{d}x\f$. A 3DH1 input carries the z
115 * velocity as component 2.
116 *
117 * @tparam TData Floating-point type of the field data.
118 *
119 * @see DivergenceBlockOp for the per-block interface and the
120 * implementation strategies available per execution space.
121 */
122template <typename TData>
123class DivergenceOp : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
124{
125 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
126
127public:
128 /**
129 * @brief Create a divergence operator through the operator and
130 * block-operator factories.
131 *
132 * Builds the interface object under the factory key
133 * `"Divergence" + execStr` and one block operator per element
134 * block under `"BlockDivergence" + execStr + implStr` (see
135 * ElmtOp::Create for the two-stage construction and for the
136 * session defaults used when @p execStr / @p implStr are empty).
137 *
138 * @param expansionList Expansion list the operator acts on.
139 * @param components Names of the field components the
140 * operator is set up for.
141 * @param execStr Execution space ("Serial", "AVX" or
142 * "Device"); session default if empty.
143 * @param implStr Implementation strategy ("StdMat",
144 * "SumFac" or, on the Device space,
145 * "SumFacTOP"); session default if
146 * empty.
147 *
148 * @return The fully assembled operator, ready to Apply.
149 */
150 static std::shared_ptr<DivergenceOp<TData>> Create(
151 const MultiRegions::ExpListSharedPtr &expansionList,
152 const std::vector<std::string> &components,
153 const std::string &execStr = "", const std::string &implStr = "")
154 {
156 template Create<DivergenceOp, DivergenceBlockOp>(
157 expansionList, components, execStr, implStr);
158 }
159
160 /// Operator base name; Create() appends the execution space to it
161 /// to form the factory key.
162 static inline const std::string name = "Divergence";
163
164protected:
165 /// One block operator per element block, filled by ElmtOp::Create
166 /// and driven in order by v_Apply().
167 std::vector<std::shared_ptr<DivergenceBlockOp<TData>>> m_blockOp;
168
169 /**
170 * @brief Construct the interface part of a concrete operator;
171 * called by the factory-registered creator functions.
172 *
173 * @param expansionList Expansion list the operator acts on.
174 * @param components Component names the operator is set up
175 * for.
176 */
178 const std::vector<std::string> &components)
179 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
180 components)
181 {
182 }
183
184 ~DivergenceOp() override = default;
185
186 /**
187 * @brief Apply the divergence block by block.
188 *
189 * Checks that the homogeneous-mode counts of @p in and @p out
190 * agree, hands each block pair to the corresponding block
191 * operator, then calls v_ApplyFFT() to add the z derivative.
192 *
193 * @param in Physical-space vector field; its first
194 * shape-dimension components are differentiated,
195 * and component 2 in z on a 3DH1 expansion.
196 * @param out Physical-space field receiving the divergence.
197 */
200 {
201 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
202 "Number of input and output homogeneous modes differ");
203
204 // Loop over the blocks.
205 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
206 {
207 // Block dependent.
208 auto &inblock = in.GetBlocks()[blk];
209 auto &outblock = out.GetBlocks()[blk];
210
211 this->m_blockOp[blk]->Apply(inblock, outblock);
212 }
213
214 // Apply FFT.
215 v_ApplyFFT(in, out);
216 }
217
218 /// Add \f$\partial w/\partial z\f$ to @p out; called by v_Apply()
219 /// after the block loop.
220 virtual void v_ApplyFFT(
223};
224
225} // namespace Nektar::MultiRegions
Per-block interface of the Divergence element operator.
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....
A Field represents expansion data to be operated on.
Whole-field interface of the divergence operator: sums the physical derivatives of the first shape-d...
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Apply the divergence block by block.
std::vector< std::shared_ptr< DivergenceBlockOp< TData > > > m_blockOp
One block operator per element block, filled by ElmtOp::Create and driven in order by v_Apply().
DivergenceOp(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...
static std::shared_ptr< DivergenceOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a divergence operator through the operator and block-operator factories.
virtual void v_ApplyFFT(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out)=0
Add to out; called by v_Apply() after the block loop.
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
Common base class of the element-operator interfaces: an operator applied independently to every elem...
Definition ElmtOp.hpp:111
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.