Nektar++
Loading...
Searching...
No Matches
AdvectionOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: AdvectionOp.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: Strong-form (non-conservative) advection: advVel \dot \grad(u)
32//
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file AdvectionOp.hpp
37 * @brief Whole-field interface of the advection element operator, which
38 * evaluates the convective term V . grad(u) at the quadrature points.
39 *
40 * @details
41 * Advection is a physical-space to physical-space element operator: for
42 * each component u of the input field it computes scale * (V . grad u) at
43 * every quadrature point, where V is a user-supplied advection velocity
44 * field with one component per coordinate dimension (three on a 3DH1
45 * expansion). This is the non-conservative (convective) form of the
46 * advection term.
47 *
48 * AdvectionOp is the whole-field interface class of the family (see
49 * ElmtOp.hpp for the two-level element-operator structure); the per-block
50 * interface is AdvectionBlockOp (AdvectionBlockOp.hpp). The plane-local
51 * numerical work lives in the detail::AdvectionBlockOpImpl definitions --
52 * AdvectionBlockOpSerialAVXStdMat.hpp and AdvectionBlockOpSerialAVXSumFac.hpp
53 * for the Serial and AVX execution spaces, AdvectionBlockOpDeviceStdMat.hpp and
54 * AdvectionBlockOpDeviceSumFac.hpp for the Device execution space -- registered
55 * with the block-operator factory by CMake-generated translation units. On
56 * a multi-plane 3DH1 expansion the homogeneous term w du/dz is added by
57 * the z-operator detail::AdvectionZOpImpl (AdvectionZOpImpl.hpp), owned by
58 * detail::AdvectionOpImpl (AdvectionOpImpl.hpp).
59 */
60
61#pragma once
62
64
66
68{
69
70/**
71 * @brief Whole-field interface of the advection element operator: writes
72 * scale * (V . grad u) at every quadrature point of every component u of
73 * the input field.
74 *
75 * @details
76 * The operator maps physical space to physical space. Before the first
77 * Apply() the advection velocity V must be supplied through SetAdvVel();
78 * Apply() then evaluates, element by element,
79 * \f$ s \sum_k V_k \, \partial u / \partial x_k \f$ at each quadrature
80 * point -- overwriting the output, or accumulating onto it when
81 * SetAppend(true) is set -- with s the factor given by SetScale()
82 * (default 1). The same velocity is applied to every component of the
83 * input field. On a multi-plane 3DH1 expansion the sum includes the
84 * homogeneous term w du/dz, added after the block loop through the
85 * v_SetScaleFFT(), v_SetAdvVelFFT() and v_ApplyFFT() hooks.
86 *
87 * As with the other element-operator families, this class sets the
88 * Apply() field states at compile time and drives one AdvectionBlockOp per
89 * element block; the per-execution-space behaviour lives in the block
90 * operators and, for the homogeneous term, in the z-operator owned by
91 * detail::AdvectionOpImpl, which implements the hooks. See ElmtOp for the
92 * block decomposition and factory scheme.
93 *
94 * @tparam TData Floating-point type of the field data.
95 */
96template <typename TData>
97class AdvectionOp : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
98{
99 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
100
101public:
102 /**
103 * @brief Build a complete advection operator through the operator and
104 * block-operator factories.
105 *
106 * See ElmtOp::Create for the two-stage construction and the
107 * execution-space/implementation lookup rules.
108 *
109 * @param expansionList Expansion list the operator acts on.
110 * @param components Names of the field components.
111 * @param execStr Execution space ("Serial", "AVX" or
112 * "Device"); the session's setting is used
113 * if empty.
114 * @param implStr Implementation ("StdMat", "SumFac" or, on
115 * Device, "SumFacTOP"); the session's
116 * setting is used if empty.
117 *
118 * @return The fully assembled operator. SetAdvVel() must still be
119 * called before the first Apply().
120 */
121 static std::shared_ptr<AdvectionOp<TData>> Create(
122 const MultiRegions::ExpListSharedPtr &expansionList,
123 const std::vector<std::string> &components,
124 const std::string &execStr = "", const std::string &implStr = "")
125 {
127 template Create<AdvectionOp, AdvectionBlockOp>(
128 expansionList, components, execStr, implStr);
129 }
130
131 /// Operator base name; Create() appends the execution space to it
132 /// to form the operator-factory key.
133 static inline const std::string name = "Advection";
134
135 /**
136 * @brief Set the scalar factor applied to the advection term on every
137 * block and on the homogeneous term, so that Apply() produces
138 * scale * (V . grad u).
139 *
140 * @param scale New scale factor (initially 1).
141 */
142 void SetScale(const TData &scale)
143 {
144 // Loop over the blocks.
145 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
146 {
147 this->m_blockOp[blk]->SetScale(scale);
148 }
149 v_SetScaleFFT(scale);
150 }
151
152 /**
153 * @brief Choose between overwriting and accumulating output.
154 *
155 * With append set, Apply() adds scale * (V . grad u) onto the existing
156 * contents of the output field instead of overwriting it -- useful
157 * when the advection term is one of several contributions to a
158 * right-hand side.
159 *
160 * @param append True to accumulate, false (the initial state) to
161 * overwrite.
162 */
163 void SetAppend(const bool &append)
164 {
165 // Loop over the blocks.
166 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
167 {
168 this->m_blockOp[blk]->SetAppend(append);
169 }
170 }
171
172 /**
173 * @brief Supply the advection velocity field V; must be called before
174 * the first Apply().
175 *
176 * @p advVel must be built on the operator's expansion list and hold
177 * one component per coordinate dimension of the mesh, or three on a
178 * 3DH1 expansion, each a physical-space scalar field; the component
179 * count is checked with a level-1 assertion. Each block accessor is
180 * handed to the corresponding block operator, which keeps a
181 * non-owning pointer to it, and the whole field to v_SetAdvVelFFT(),
182 * so the field must outlive the operator's use. The block
183 * implementations reshape the velocity storage in place to their own
184 * interleave width the first time Apply() finds it at another width,
185 * updating the accessor's recorded width: the field's interleave
186 * width is modified as a side effect.
187 *
188 * @param advVel Advection velocity field, one component per
189 * coordinate dimension (three on 3DH1).
190 */
192 {
193 // A 3DH1 expansion carries a third velocity component along the
194 // homogeneous direction, which the planes themselves do not count.
195 ASSERTL1(advVel.GetNumComponents() ==
196 ((advVel.GetNumHomoModes() == 1)
197 ? static_cast<unsigned int>(
198 this->m_expansionList->GetCoordim(0))
199 : 3u),
200 "Advection velocity must have coordDim components, or three "
201 "on a 3DH1 expansion");
202
203 // Loop over the blocks.
204 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
205 {
206 this->m_blockOp[blk]->SetAdvVel(advVel.GetBlocks()[blk]);
207 }
208 v_SetAdvVelFFT(advVel);
209 m_isSetAdvVel = true;
210 }
211
212protected:
213 /// Whether SetAdvVel() has been called; checked by v_Apply().
214 bool m_isSetAdvVel = false;
215 /// One block operator per element block, filled by Create().
216 std::vector<std::shared_ptr<AdvectionBlockOp<TData>>> m_blockOp;
217
218 /**
219 * @brief Construct the interface part of a concrete operator; called
220 * by the factory-registered creator functions.
221 *
222 * @param expansionList Expansion list the operator acts on.
223 * @param components Component names the operator is set up
224 * for.
225 */
227 const std::vector<std::string> &components)
228 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
229 components)
230 {
231 }
232
233 ~AdvectionOp() override = default;
234
235 /**
236 * @brief Apply the advection operator block by block.
237 *
238 * Checks that the fields conform (component and homogeneous-mode
239 * counts) and that the advection velocity has been set, then hands
240 * each input/output block pair to the corresponding entry of
241 * #m_blockOp, and finally calls v_ApplyFFT() to add the homogeneous
242 * term.
243 *
244 * @param in Physical-space input field.
245 * @param out Physical-space output field; overwritten, or
246 * accumulated onto when append is set.
247 */
250 {
251 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
252 "Number of input and output components differ");
253
254 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
255 "Number of input and output homogeneous modes differ");
256
258 "Advection velocity has not been set."
259 "Set the value with SetAdvVel() before calling Apply().");
260
261 // Loop over the blocks.
262 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
263 {
264 // Block dependent.
265 auto &inblock = in.GetBlocks()[blk];
266 auto &outblock = out.GetBlocks()[blk];
267
268 this->m_blockOp[blk]->Apply(inblock, outblock);
269 }
270
271 // Apply FFT.
272 v_ApplyFFT(in, out);
273 }
274
275 /// Pass the scale factor on to the homogeneous term; called by
276 /// SetScale().
277 virtual void v_SetScaleFFT(const TData &scale) = 0;
278
279 /// Pass the advection velocity on to the homogeneous term; called by
280 /// SetAdvVel().
281 virtual void v_SetAdvVelFFT(
283
284 /// Add the homogeneous term to @p out; called by v_Apply() after the
285 /// block loop.
286 virtual void v_ApplyFFT(
289};
290
291} // namespace Nektar::MultiRegions
Per-block interface of the advection 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.
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.
Whole-field interface of the advection element operator: writes scale * (V . grad u) at every quadrat...
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Apply the advection operator block by block.
virtual void v_SetAdvVelFFT(LibUtilities::Field< TData, FieldState::Phys > &advVel)=0
Pass the advection velocity on to the homogeneous term; called by SetAdvVel().
virtual void v_SetScaleFFT(const TData &scale)=0
Pass the scale factor on to the homogeneous term; called by SetScale().
virtual void v_ApplyFFT(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out)=0
Add the homogeneous term to out; called by v_Apply() after the block loop.
bool m_isSetAdvVel
Whether SetAdvVel() has been called; checked by v_Apply().
void SetAdvVel(LibUtilities::Field< TData, FieldState::Phys > &advVel)
Supply the advection velocity field V; must be called before the first Apply().
static std::shared_ptr< AdvectionOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete advection operator through the operator and block-operator factories.
AdvectionOp(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 SetAppend(const bool &append)
Choose between overwriting and accumulating output.
std::vector< std::shared_ptr< AdvectionBlockOp< TData > > > m_blockOp
One block operator per element block, filled by Create().
void SetScale(const TData &scale)
Set the scalar factor applied to the advection term on every block and on the homogeneous term,...
static const std::string name
Operator base name; Create() appends the execution space to it to form the operator-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.