Nektar++
Loading...
Searching...
No Matches
PhysDerivOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysDerivOp.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 PhysDerivOp.hpp
37 * @brief Public interface of the physical-space derivative (PhysDeriv)
38 * element operator, which maps a field at the quadrature points to its
39 * gradient at the same points.
40 *
41 * @details
42 * PhysDeriv takes \f$u\f$ sampled at an element's quadrature points and
43 * returns the Cartesian derivatives
44 * \f[ \frac{\partial u}{\partial x_k}(\xi_i)
45 * = \sum_{d} \frac{\partial \xi_d}{\partial x_k}(\xi_i)
46 * \frac{\partial u}{\partial \xi_d}(\xi_i), \qquad
47 * k = 0,\dots,\mathrm{coordDim}-1, \f]
48 * at those same points: a tensorial derivative on the standard element
49 * followed by the chain rule with the element's derivative factors
50 * \f$\partial \xi_d / \partial x_k\f$ (see the notes on PhysDerivOp).
51 * Both input and output are therefore in FieldState::Phys. For an
52 * ordinary (non-homogeneous) field the output carries `coordDim`
53 * components per input component; for a 3D-homogeneous-1D (3DH1) field
54 * with more than one homogeneous plane it always carries exactly three,
55 * regardless of `coordDim` -- x and y from the per-block operators, z
56 * from an FFT-based homogeneous derivative (see DerivZOpImpl.hpp).
57 *
58 * The family follows the standard element-operator layout (see
59 * ElmtOp.hpp):
60 * - PhysDerivOp (this file): whole-field interface setting the Apply()
61 * field states and running the per-block operators, then the
62 * v_ApplyFFT() hook;
63 * - detail::PhysDerivOpImpl (PhysDerivOpImpl.hpp): the factory-registered
64 * whole-field implementation, one entry per execution space, which
65 * builds the homogeneous z-derivative and runs it in v_ApplyFFT();
66 * - PhysDerivBlockOp (PhysDerivBlockOp.hpp): per-block interface;
67 * - detail::PhysDerivBlockOpImpl: the per-block implementations, one
68 * header per implementation family --
69 * PhysDerivBlockOpSerialAVXStdMat.hpp and PhysDerivBlockOpSerialAVXSumFac.hpp
70 * each serve both the Serial and the AVX space,
71 * PhysDerivBlockOpDeviceStdMat.hpp serves Device/StdMat, and
72 * PhysDerivBlockOpDeviceSumFac.hpp serves both device sum-factorisation
73 * strategies (SumFac and SumFacTOP);
74 * - the kernels in PhysDerivBlockOpSerialAVXStdMatKernels.hpp,
75 * PhysDerivBlockOpSerialAVXSumFacKernels.hpp,
76 * PhysDerivBlockOpDeviceStdMatKernels.hpp,
77 * PhysDerivBlockOpDeviceSumFacKernels.hpp and
78 * PhysDerivBlockOpDeviceSumFacTOPKernels.hpp;
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 * The kernel headers also define per-direction ("Dir") kernels, which
85 * produce a single Cartesian derivative component and can accumulate
86 * onto it. PhysDeriv itself never calls them: the sum-factorised ones
87 * are the building blocks of the Divergence kernels (and, in one
88 * dimension, of the CurlCurl kernels), the host StdMat one,
89 * MultiplyByDerivDirFactorKernel, of the Serial/AVX Divergence StdMat
90 * implementation. Conversely the all-component kernels PhysDeriv uses
91 * are shared with other families: MultiplyByDerivFactorKernel with the
92 * AdvectionDealias StdMat implementations, and the device
93 * PhysDeriv{1,2,3}DSumFacKernel / PhysDeriv{1,2,3}DSumFacTOPKernel with
94 * the AdvectionDealias, Helmholtz, Laplacian and LinAdvDiffReaction
95 * device kernels.
96 */
97
98#pragma once
99
101
103
104namespace Nektar::MultiRegions
105{
106
107/// \brief Element-block operator that computes the physical-space derivative
108/// \f$\nabla u\f$ over a collection of elements.
109template <typename TData>
110class PhysDerivOp : public ElmtOp<FieldState::Phys, FieldState::Phys, TData>
111{
112 friend class ElmtOp<FieldState::Phys, FieldState::Phys, TData>;
113
114public:
115 /**
116 * @brief Create a physical-derivative operator, its per-block
117 * operators and, for a multi-plane 3DH1 expansion, its homogeneous
118 * z-derivative.
119 *
120 * Builds the interface object under the factory key
121 * `"PhysDeriv" + execStr` and one block operator per element block
122 * under `"BlockPhysDeriv" + execStr + implStr`; see ElmtOp::Create
123 * for the two-stage construction and for the session defaults used
124 * when @p execStr or @p implStr are empty. If @p expansionList is a
125 * 3D-homogeneous-1D expansion holding more than one homogeneous
126 * plane on this rank, the constructor of detail::PhysDerivOpImpl
127 * additionally builds its z-derivative, detail::PhysDerivOpImpl::m_zOp;
128 * for every other expansion that is left null.
129 *
130 * @param expansionList Expansion list the operator acts on.
131 * @param components Names of the field components the
132 * operator is set up for; these name the
133 * input components, the output field
134 * carrying coordDim (or, for multi-plane
135 * 3DH1, three) of them each.
136 * @param execStr Execution space ("Serial", "AVX" or
137 * "Device"); session default if empty.
138 * @param implStr Block implementation ("StdMat",
139 * "SumFac" or, on the Device space,
140 * "SumFacTOP"); session default if empty.
141 *
142 * @return The fully assembled operator, ready to Apply.
143 */
144 static std::shared_ptr<PhysDerivOp<TData>> Create(
145 const MultiRegions::ExpListSharedPtr &expansionList,
146 const std::vector<std::string> &components,
147 const std::string &execStr = "", const std::string &implStr = "")
148 {
150 template Create<PhysDerivOp, PhysDerivBlockOp>(
151 expansionList, components, execStr, implStr);
152 }
153
154 /// Operator base name; ElmtOp::Create() appends the execution space
155 /// to it to form the factory key, and uses it to look up the
156 /// session's default block implementation.
157 static inline const std::string name = "PhysDeriv";
158
159protected:
160 /// One block operator per element block of the expansion list;
161 /// populated by ElmtOp::Create().
162 std::vector<std::shared_ptr<PhysDerivBlockOp<TData>>> m_blockOp;
163
164 /**
165 * @brief Construct the interface part of a concrete implementation;
166 * called by the factory-registered creator functions.
167 *
168 * @param expansionList Expansion list the operator acts on.
169 * @param components Component names the operator is set up
170 * for.
171 */
173 const std::vector<std::string> &components)
174 : ElmtOp<FieldState::Phys, FieldState::Phys, TData>(expansionList,
175 components)
176 {
177 }
178
179 ~PhysDerivOp() override = default;
180
181 /**
182 * @brief Apply the physical derivative block by block, adding the
183 * homogeneous z-derivative for a multi-plane 3DH1 field.
184 *
185 * Requires that the fields conform -- @p out must have exactly
186 * `coordDim` times as many components as @p in for a field with a
187 * single homogeneous mode and exactly three times as many for one
188 * with several, and the same number of homogeneous modes -- then
189 * hands each pair of blocks to the corresponding entry of
190 * #m_blockOp. It then calls v_ApplyFFT(), which for a field with
191 * more than one homogeneous mode writes the z component of every
192 * output block.
193 *
194 * @param in Physical-space input field.
195 * @param out Physical-space output field, overwritten; see
196 * the file notes for its component count.
197 */
200 {
201 ASSERTL1(in.GetNumComponents() ==
202 out.GetNumComponents() /
203 (in.GetNumHomoModes() == 1
204 ? static_cast<unsigned int>(
205 this->m_expansionList->GetCoordim(0))
206 : 3u),
207 "Number of input and output components differ");
208
209 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
210 "Number of input and output homogeneous modes differ");
211
212 // Loop over the blocks.
213 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
214 {
215 // Block dependent.
216 auto &inblock = in.GetBlocks()[blk];
217 auto &outblock = out.GetBlocks()[blk];
218
219 this->m_blockOp[blk]->Apply(inblock, outblock);
220 }
221
222 // Apply FFT.
223 v_ApplyFFT(in, out);
224 }
225
226 /// Homogeneous z-derivative, called by v_Apply() after the block
227 /// loop; writes the z component of every output block of a
228 /// multi-plane 3DH1 field and leaves any other field untouched.
229 virtual void v_ApplyFFT(
232};
233
234} // 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 class of the physical-derivative 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
Element-block operator that computes the physical-space derivative over a collection of elements.
virtual void v_ApplyFFT(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out)=0
Homogeneous z-derivative, called by v_Apply() after the block loop; writes the z component of every o...
static std::shared_ptr< PhysDerivOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a physical-derivative operator, its per-block operators and, for a multi-plane 3DH1 expansion,...
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Apply the physical derivative block by block, adding the homogeneous z-derivative for a multi-plane 3...
PhysDerivOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
Construct the interface part of a concrete implementation; called by the factory-registered creator f...
std::vector< std::shared_ptr< PhysDerivBlockOp< TData > > > m_blockOp
One block operator per element block of the expansion list; populated by ElmtOp::Create().
static const std::string name
Operator base name; ElmtOp::Create() appends the execution space to it to form the factory key,...
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
FieldState
Possible states for Field data.