Nektar++
Loading...
Searching...
No Matches
PhysInterp1DScaledBlockOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysInterp1DScaledBlockOp.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 PhysInterp1DScaledBlockOp.hpp
37 * @brief Per-block interface class of the scaled physical-space
38 * interpolation operator.
39 */
40
41#pragma once
42
43#include <vector>
44
46
48{
49
50/**
51 * @brief Per-block interface of the scaled interpolation: interpolates
52 * every element of one block onto its rescaled quadrature grid.
53 *
54 * Sets the BlockAccessor states accepted by Apply() -- physical space in
55 * and out -- and carries the scale factor shared by all implementations,
56 * together with the hook through which setting it lets an implementation
57 * prepare its interpolation data. The concrete implementations are the
58 * detail::PhysInterp1DScaledBlockOpImpl definitions in the headers listed
59 * in PhysInterp1DScaledOp.hpp; CMake includes exactly one of them per
60 * generated registration translation unit, matching the
61 * execution-space/implementation pair that unit registers with the
62 * block-operator factory.
63 *
64 * @tparam TData Floating-point type of the field data.
65 *
66 * @see ElmtBlockOp for the Apply()/v_Apply() contract;
67 * PhysInterp1DScaledOp for the whole-field interface driving this class
68 * and for the meaning of the scale factor.
69 */
70template <typename TData>
72 : public ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>
73{
74public:
75 /**
76 * @brief Create one scaled-interpolation block operator through the
77 * block-operator factory, under the key #name + @p execStr +
78 * @p implStr.
79 *
80 * @param block_idx Index of the block within the expansion
81 * list's Collections.
82 * @param exp Representative expansion of the block
83 * (its first element).
84 * @param dataWarehouse Data warehouse shared with the other
85 * operators on the expansion list.
86 * @param execStr Execution-space part of the factory key.
87 * @param implStr Implementation part of the factory key.
88 *
89 * @return The newly created block operator.
90 */
91 static std::shared_ptr<PhysInterp1DScaledBlockOp<TData>> Create(
92 const unsigned int block_idx,
95 const std::string &execStr, const std::string &implStr)
96 {
98 template Create<PhysInterp1DScaledBlockOp>(
99 block_idx, exp, dataWarehouse, execStr, implStr);
100 }
101
102 /// Block-operator base name; Create() appends the execution space
103 /// and implementation to it to form the factory key.
104 static inline const std::string name = "BlockPhysInterp1DScaled";
105
106 /**
107 * @brief Set this block's scale factor, and with it the number of
108 * output points per direction.
109 *
110 * Must be called before Apply(): the implementations derive their
111 * output point counts, workspaces and interpolation data from it (see
112 * v_SetScaleFactor), none of which is known at construction. The
113 * sum-factorised implementations assert on an unset factor; the
114 * StdMat ones do not.
115 *
116 * @param scale Multiplier applied to the per-direction
117 * quadrature-point counts; see the file notes of
118 * PhysInterp1DScaledOp.hpp for the exact rule.
119 */
120 void SetScaleFactor(const TData &scale)
121 {
122 v_SetScaleFactor(scale);
123 }
124
125protected:
126 /// Scale factor most recently set, or -1 while unset -- the value the
127 /// sum-factorised implementations assert against.
128 TData m_scale = -1.0; // scaling factor
129
130 /**
131 * @brief Construct the interface part of a concrete block operator;
132 * called by the factory-registered creator functions.
133 *
134 * @param block_idx Index of the block within the expansion
135 * list's Collections.
136 * @param exp Representative expansion of the block.
137 * @param dataWarehouse Data warehouse shared with the other
138 * operators on the expansion list.
139 */
141 const unsigned int block_idx,
144 : ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>(block_idx, exp,
145 dataWarehouse)
146 {
147 }
148
149 ~PhysInterp1DScaledBlockOp() override = default;
150
151 /// \brief The per-direction point counts of the @p scale over-integrated
152 /// grid this operator's interpolation and projection matrices are built
153 /// for.
154 ///
155 /// Direction 0 scales outright, and a direction carrying one point fewer
156 /// than direction 0 keeps that offset, which is what lets the switch
157 /// templating see the same relationship on the over-integrated grid as on
158 /// the native one.
159 static std::vector<unsigned int> GetScaledNumPoints(
160 const std::vector<unsigned int> &nq, const NekDouble scale)
161 {
162 std::vector<unsigned int> nqScaled;
163 nqScaled.reserve(nq.size());
164
165 for (size_t d = 0; d < nq.size(); ++d)
166 {
167 nqScaled.push_back((d != 0 && nq[0] - nq[d] == 1)
168 ? static_cast<unsigned int>(scale * nq[0]) -
169 1
170 : static_cast<unsigned int>(scale * nq[d]));
171 }
172
173 return nqScaled;
174 }
175
176 /**
177 * @brief Implementation hook for SetScaleFactor().
178 *
179 * Overrides must record @p scale in #m_scale and put the block
180 * operator into a state where Apply() interpolates onto the point
181 * counts that factor implies: fix the per-direction output sizes,
182 * fetch the matching interpolation data from the data warehouse and
183 * size any workspace, replacing whatever an earlier call set up.
184 *
185 * @param scale Multiplier applied to the per-direction
186 * quadrature-point counts.
187 */
188 virtual void v_SetScaleFactor(const TData &scale) = 0;
189};
190
191} // namespace Nektar::MultiRegions
Block-level base class, implementation-strategy tags and device launch helpers shared by every elemen...
Base class of the per-family block operators: applies one element operation to every element of one b...
Per-block interface of the scaled interpolation: interpolates every element of one block onto its res...
void SetScaleFactor(const TData &scale)
Set this block's scale factor, and with it the number of output points per direction.
static const std::string name
Block-operator base name; Create() appends the execution space and implementation to it to form the f...
PhysInterp1DScaledBlockOp(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
Construct the interface part of a concrete block operator; called by the factory-registered creator f...
static std::shared_ptr< PhysInterp1DScaledBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one scaled-interpolation block operator through the block-operator factory,...
TData m_scale
Scale factor most recently set, or -1 while unset – the value the sum-factorised implementations asse...
static std::vector< unsigned int > GetScaledNumPoints(const std::vector< unsigned int > &nq, const NekDouble scale)
The per-direction point counts of the scale over-integrated grid this operator's interpolation and pr...
virtual void v_SetScaleFactor(const TData &scale)=0
Implementation hook for SetScaleFactor().
std::shared_ptr< NekDataWarehouse > NekDataWarehouseSharedPtr
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition Expansion.h:66
FieldState
Possible states for Field data.