Nektar++
Loading...
Searching...
No Matches
BwdTransOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: BwdTransOp.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 backward transform, from
32// coefficient space to physical space
33//
34///////////////////////////////////////////////////////////////////////////////
35
36/**
37 * @file BwdTransOp.hpp
38 * @brief Public interface of the backward-transform (BwdTrans) element
39 * operator, which maps a field from coefficient space to physical space.
40 *
41 * The backward transform evaluates each element's expansion at the
42 * quadrature points of its basis,
43 * \f[ u(\xi_i) = \sum_n \hat{u}_n \phi_n(\xi_i), \f]
44 * where \f$\hat{u}_n\f$ are the element's coefficients and \f$\phi_n\f$
45 * its basis functions. It is purely element-local and independent of the
46 * element geometry -- no Jacobians or metric terms enter -- and is the
47 * block-operator equivalent of ExpList::BwdTrans, which
48 * the BwdTrans unit tests use as the reference solution.
49 *
50 * The family follows the standard element-operator layout (see
51 * ElmtOp.hpp):
52 * - BwdTransOp (this file): whole-field interface fixing the Apply()
53 * field states;
54 * - detail::BwdTransOpImpl (BwdTransOpImpl.hpp): the factory-registered
55 * whole-field implementation, one entry per execution space;
56 * - BwdTransBlockOp (BwdTransBlockOp.hpp): per-block interface;
57 * - detail::BwdTransBlockOpImpl: the per-block implementations, one
58 * header per implementation family rather than one per registered
59 * execution-space/strategy pairing -- BwdTransBlockOpSerialAVXStdMat.hpp and
60 * BwdTransBlockOpSerialAVXSumFac.hpp each serve both the Serial and the AVX
61 * space, BwdTransBlockOpDeviceStdMat.hpp serves Device/StdMat, and
62 * BwdTransBlockOpDeviceSumFac.hpp serves both device sum-factorisation
63 * strategies (SumFac and SumFacTOP);
64 * - the sum-factorised kernels in BwdTransBlockOpSerialAVXSumFacKernels.hpp,
65 * BwdTransBlockOpDeviceSumFacKernels.hpp and
66 * BwdTransBlockOpDeviceSumFacTOPKernels.hpp.
67 */
68
69#pragma once
70
72
74
76{
77
78/**
79 * @brief Whole-field interface of the backward transform: evaluates a
80 * coefficient-space field at the quadrature points of every element.
81 *
82 * As with the other element-operator families, this class exists to fix
83 * the Apply() parameter types at compile time -- input in
84 * FieldState::Coeff, output in FieldState::Phys -- and to drive the
85 * per-block operators: it holds one BwdTransBlockOp per element block,
86 * and v_Apply() hands each block of the input and output fields to the
87 * matching entry. All numerical work happens in the block operators.
88 *
89 * By default Apply() overwrites the output field; after SetAppend(true)
90 * it instead accumulates the transform onto the output's existing
91 * values.
92 *
93 * @tparam TData Floating-point type of the field data.
94 *
95 * @see BwdTransBlockOp for the per-block interface and the
96 * implementation strategies available per execution space.
97 */
98template <typename TData>
99class BwdTransOp : public ElmtOp<FieldState::Coeff, FieldState::Phys, TData>
100{
101 friend class ElmtOp<FieldState::Coeff, FieldState::Phys, TData>;
102
103public:
104 /**
105 * @brief Create a backward-transform operator through the operator
106 * and block-operator factories.
107 *
108 * Builds the interface object under the factory key
109 * `"BwdTrans" + execStr` and one block operator per element block
110 * under `"BlockBwdTrans" + execStr + implStr`; see ElmtOp::Create
111 * for the two-stage construction and for the session defaults used
112 * when @p execStr or @p implStr are empty.
113 *
114 * @param expansionList Expansion list the operator acts on.
115 * @param components Names of the field components the
116 * operator is set up for.
117 * @param execStr Execution space ("Serial", "AVX" or
118 * "Device"); session default if empty.
119 * @param implStr Block implementation ("StdMat",
120 * "SumFac", "SumFacTOP" (Device only));
121 * session default if empty.
122 *
123 * @return The fully assembled operator, ready to Apply().
124 */
125 static std::shared_ptr<BwdTransOp<TData>> Create(
126 const MultiRegions::ExpListSharedPtr &expansionList,
127 const std::vector<std::string> &components,
128 const std::string &execStr = "", const std::string &implStr = "")
129 {
131 template Create<BwdTransOp, BwdTransBlockOp>(
132 expansionList, components, execStr, implStr);
133 }
134
135 /// Operator base name; Create() appends the execution space to it
136 /// to form the factory key.
137 static inline const std::string name = "BwdTrans";
138
139 /**
140 * @brief Switch all block operators between overwrite and
141 * accumulate mode.
142 *
143 * With @p append set, subsequent Apply() calls add the backward
144 * transform onto the output field's existing contents instead of
145 * overwriting them. The default is overwrite.
146 *
147 * @param append Accumulate into the output when true.
148 */
149 void SetAppend(const bool &append)
150 {
151 // Loop over the blocks.
152 for (unsigned int blk = 0; blk < m_blockOp.size(); ++blk)
153 {
154 this->m_blockOp[blk]->SetAppend(append);
155 }
156 }
157
158protected:
159 /// One block operator per element block of the expansion list;
160 /// populated by ElmtOp::Create().
161 std::vector<std::shared_ptr<BwdTransBlockOp<TData>>> m_blockOp;
162
163 /**
164 * @brief Construct the interface part of a concrete implementation;
165 * called by the factory-registered creator functions.
166 *
167 * @param expansionList Expansion list the operator acts on.
168 * @param components Component names the operator is set up
169 * for.
170 */
172 const std::vector<std::string> &components)
173 : ElmtOp<FieldState::Coeff, FieldState::Phys, TData>(expansionList,
174 components)
175 {
176 }
177
178 ~BwdTransOp() override = default;
179
180 /**
181 * @brief Apply the backward transform block by block.
182 *
183 * Checks that @p in and @p out conform -- equal component and
184 * homogeneous-mode counts -- then hands each pair of blocks to the
185 * corresponding entry of #m_blockOp.
186 *
187 * @param in Coefficient-space input field.
188 * @param out Physical-space output field; overwritten, or
189 * accumulated into when append mode is set.
190 */
193 {
194 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
195 "Number of input and output components differ");
196
197 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
198 "Number of input and output homogeneous modes differ");
199
200 // Loop over the blocks.
201 for (unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
202 {
203 // Block dependent.
204 auto &inblock = in.GetBlocks()[blk];
205 auto &outblock = out.GetBlocks()[blk];
206
207 this->m_blockOp[blk]->Apply(inblock, outblock);
208 }
209 }
210};
211
212} // namespace Nektar::MultiRegions
Per-block interface class of the backward-transform 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 backward transform: evaluates a coefficient-space field at the quadratur...
BwdTransOp(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...
~BwdTransOp() override=default
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
std::vector< std::shared_ptr< BwdTransBlockOp< TData > > > m_blockOp
One block operator per element block of the expansion list; populated by ElmtOp::Create().
static std::shared_ptr< BwdTransOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a backward-transform operator through the operator and block-operator factories.
void v_Apply(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Apply the backward transform block by block.
void SetAppend(const bool &append)
Switch all block operators between overwrite and accumulate mode.
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.