Nektar++
Loading...
Searching...
No Matches
AvgAssmbScatrOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: AvgAssmbScatrOp.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: Public interface of the averaging assemble-scatter operator,
32// which replaces every local copy of each global degree of freedom of a
33// coefficient field by the signed average of all its copies.
34//
35///////////////////////////////////////////////////////////////////////////////
36
37#pragma once
38
39#include <memory>
40#include <string>
41#include <vector>
42
44
46{
47
48/**
49 * @brief Base class for the averaging assemble-scatter operator: replaces
50 * every local copy of each global degree of freedom by the signed average
51 * of all its copies.
52 *
53 * @details
54 * Each local coefficient becomes
55 * \f$x_i \leftarrow s_i \sum_j s_j x_j / m\f$, where \f$s\f$ are the
56 * orientation signs of the local-to-global assembly map and \f$m\f$ is the
57 * number of copies of the degree of freedom with a nonzero sign, counted
58 * over every rank and every periodic partner. A coefficient of sign zero,
59 * as an unused mode of an edge or face shared with an element of lower
60 * order is in a variable-order expansion, is set to zero. The result is
61 * continuous, and a continuous field is left unchanged. For a ContField
62 * this is AssemblyMap::AvgAssemble() followed by
63 * AssemblyMap::GlobalToLocal().
64 *
65 * The averaging is the sum formed by AssmbScatrOp, weighted by the inverse
66 * multiplicity, which the implementation (detail::AvgAssmbScatrOpImpl)
67 * builds once, when the operator is created, and reuses on every Apply().
68 * Construction and Apply() both communicate in parallel runs, so every rank
69 * must construct the operator and call Apply() together.
70 *
71 * @tparam TData Floating-point type of the coefficient data.
72 */
73template <typename TData> class AvgAssmbScatrOp : public Operator<TData>
74{
75public:
76 /**
77 * @brief Create an averaging assemble-scatter operator through the
78 * operator factory.
79 *
80 * @param expansionList Expansion list the operator acts on; in
81 * parallel runs a MultiRegions::ContField.
82 * @param components Session variable names of the field
83 * components the operator is built for.
84 * @param execStr Execution-space suffix, e.g. "Serial",
85 * "AVX" or "Device". If empty, it is taken
86 * from the "opExecSpace" command-line
87 * argument; without it the operator takes the
88 * space the build provides and warns.
89 *
90 * @return The operator implementation for the requested execution
91 * space. Creation raises a fatal error if none is registered.
92 */
93 static std::shared_ptr<AvgAssmbScatrOp<TData>> Create(
94 const MultiRegions::ExpListSharedPtr &expansionList,
95 const std::vector<std::string> &components,
96 const std::string &execStr = "")
97 {
98 return Operator<TData>::template Create<AvgAssmbScatrOp>(
99 expansionList, components, execStr);
100 }
101
102 /// Operator base name; Create() appends the execution space to it to
103 /// form the factory key.
104 static inline const std::string name = "AvgAssmbScatr";
105
106 /**
107 * @brief Average the local copies of @p inout in place.
108 *
109 * @param inout Coefficient-space field with the components the
110 * operator was created for; averaged in place, at the
111 * interleave width it has on entry.
112 */
114 {
115 v_Apply(inout);
116 }
117
118 /**
119 * @brief Average the local copies of @p in, writing the result to
120 * @p out.
121 *
122 * @param in Coefficient-space input field with the components
123 * the operator was created for; left unmodified unless
124 * it is the same object as @p out.
125 * @param out Coefficient-space output field of the same size as
126 * @p in; on return it holds the average at the
127 * interleave width of @p in.
128 */
134
135 /// @brief Call operator; equivalent to the in-place Apply().
140
141 /// @brief Call operator; equivalent to the two-field Apply().
147
148protected:
149 /// @brief Construct the interface part of a concrete implementation;
150 /// called by the factory-registered creator functions.
152 const std::vector<std::string> &components)
153 : Operator<TData>(expansionList, components)
154 {
155 }
156
157 ~AvgAssmbScatrOp() override = default;
158
159 /// @brief Implementation hook for the in-place Apply().
160 virtual void v_Apply(
162
163 /// @brief Implementation hook for the two-field Apply().
164 virtual void v_Apply(
167};
168
169} // namespace Nektar::MultiRegions
Whole-field operator base class and factory machinery shared by every operator family in the MultiReg...
A Field represents expansion data to be operated on.
Base class for the averaging assemble-scatter operator: replaces every local copy of each global degr...
void operator()(LibUtilities::Field< TData, FieldState::Coeff > &inout)
Call operator; equivalent to the in-place Apply().
virtual void v_Apply(LibUtilities::Field< TData, FieldState::Coeff > &inout)=0
Implementation hook for the in-place Apply().
virtual void v_Apply(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Coeff > &out)=0
Implementation hook for the two-field Apply().
void operator()(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Coeff > &out)
Call operator; equivalent to the two-field Apply().
static std::shared_ptr< AvgAssmbScatrOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
Create an averaging assemble-scatter operator through the operator factory.
AvgAssmbScatrOp(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...
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
void Apply(LibUtilities::Field< TData, FieldState::Coeff > &inout)
Average the local copies of inout in place.
void Apply(LibUtilities::Field< TData, FieldState::Coeff > &in, LibUtilities::Field< TData, FieldState::Coeff > &out)
Average the local copies of in, writing the result to out.
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.