Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | List of all members
Nektar::detail::EnergyOpImpl< ExecSpace, TData > Class Template Reference

#include <EnergyOpImpl.hpp>

Inheritance diagram for Nektar::detail::EnergyOpImpl< ExecSpace, TData >:
[legend]

Public Member Functions

 EnergyOpImpl (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
 
- Public Member Functions inherited from Nektar::EnergyOp< TData >
void Configure (const std::vector< unsigned int > &velocityComponents)
 velocityComponents are the indices of the velocity components in the velocity field, which may hold further components.
 
void Apply (LibUtilities::Field< TData, FieldState::Phys > &velocity, LibUtilities::Field< TData, FieldState::Phys > &velocityGradient)
 Collective: every rank must call it.
 
void operator() (LibUtilities::Field< TData, FieldState::Phys > &velocity, LibUtilities::Field< TData, FieldState::Phys > &velocityGradient)
 Collective: as Apply().
 
void SetRootOnly (const bool rootOnly)
 Reduce the results of the next Apply() to rank zero alone if rootOnly, else to every rank.
 
TData GetKineticEnergy ()
 Integral of the squared velocity magnitude from the last Apply().
 
TData GetEnstrophy ()
 Integral of the squared vorticity magnitude from the last Apply().
 
TData GetVolume ()
 Domain volume from the last Apply().
 
- Public Member Functions inherited from Nektar::MultiRegions::Operator< TData >
virtual ~Operator ()=default
 
 Operator (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > components)
 Construct the interface part of a concrete operator; called by the factory-registered creator functions.
 

Static Public Member Functions

static std::unique_ptr< MultiRegions::Operator< TData > > Instantiate (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
 
- Static Public Member Functions inherited from Nektar::EnergyOp< TData >
static std::shared_ptr< EnergyOp< TData > > Create (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
 
- Static Public Member Functions inherited from Nektar::MultiRegions::Operator< TData >
template<template< typename > typename TOperator>
static std::shared_ptr< TOperator< TData > > Create (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > components, const std::string &execStr)
 Create a concrete operator instance through the operator factory.
 
static std::string GetOpExecSpace (std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
 Return the execution space name ("opExecSpace") for an operator.
 
static const DefaultOpImplRule * GetDefaultOpImplRule (const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
 Return the row of the default implementation table (DefaultOpImplTable.hpp) that a block of elements takes, or null if none does.
 
static std::string GetDefaultOpImpl (const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
 Return the implementation a block of elements takes when neither the command line nor the session names one for its operator.
 
static std::vector< unsigned int > GetDefaultInterleaveWidths (const MultiRegions::ExpListSharedPtr &expansionList)
 Return the default interleave widths, one per block of expansionList, that persistent Fields (e.g. solution storage, time-integration and linear-solver workspace) built on it should be constructed with.
 
static bool IsDiscontinuousProjection (std::shared_ptr< LibUtilities::SessionReader > session)
 Return true if the session uses a Discontinuous (DG) projection.
 

Static Public Attributes

static std::string className
 
- Static Public Attributes inherited from Nektar::EnergyOp< TData >
static const std::string name = "Energy"
 

Protected Member Functions

void v_Configure (const std::vector< unsigned int > &velocityComponents) override
 
void v_Apply (LibUtilities::Field< TData, FieldState::Phys > &velocity, LibUtilities::Field< TData, FieldState::Phys > &velocityGradient) override
 
- Protected Member Functions inherited from Nektar::EnergyOp< TData >
 EnergyOp (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
 
 ~EnergyOp () override=default
 
TData GetResult (const unsigned int index)
 Entry index of the reduced result, read on the host.
 

Protected Attributes

std::array< std::vector< const TData * >, 2 > m_metric
 Quadrature metric of every point of each block, indexed by block, at interleave width one (first) and at m_implInterleaveWidth (second); null until a velocity is first read at that width.
 
LibUtilities::MemoryRegion< TData > m_planeWeights
 Quadrature weight of each local homogeneous plane, of size m_numPlanes.
 
std::array< unsigned int, 3 > m_velocityComponents {}
 
unsigned int m_dimension = 0
 
unsigned int m_numPlanes = 1
 Number of local planes, or 1 without a homogeneous direction.
 
- Protected Attributes inherited from Nektar::EnergyOp< TData >
bool m_rootOnly = false
 Whether Apply() reduces the results to rank zero alone.
 
LibUtilities::MemoryRegion< TData > m_result
 Reduced result of Apply(), of size resultSize, allocated by the implementation's constructor.
 
- Protected Attributes inherited from Nektar::MultiRegions::Operator< TData >
MultiRegions::ExpListSharedPtr m_expansionList
 Expansion list the operator acts on.
 
std::vector< std::string > m_components
 Names of the field components the operator was built for.
 
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
 Data warehouse shared with the other operators on the expansion list, used to build and cache shared tables (basis matrices, mode indices, geometric factors) once.
 

Static Protected Attributes

static constexpr unsigned int m_implInterleaveWidth
 Interleave width of the execution space: an input block is read at this width or at width one.
 
- Static Protected Attributes inherited from Nektar::EnergyOp< TData >
static constexpr unsigned int kineticEnergy = 0
 Indices of the integrals in m_result.
 
static constexpr unsigned int enstrophy = 1
 
static constexpr unsigned int volume = 2
 
static constexpr unsigned int resultSize = 3
 Number of entries in m_result.
 

Private Types

using MemSpace = typename ExecSpace::memory_space
 

Detailed Description

template<typename ExecSpace, typename TData>
class Nektar::detail::EnergyOpImpl< ExecSpace, TData >

Definition at line 50 of file EnergyOpImpl.hpp.

Member Typedef Documentation

◆ MemSpace

template<typename ExecSpace , typename TData >
using Nektar::detail::EnergyOpImpl< ExecSpace, TData >::MemSpace = typename ExecSpace::memory_space
private

Definition at line 52 of file EnergyOpImpl.hpp.

Constructor & Destructor Documentation

◆ EnergyOpImpl()

template<typename ExecSpace , typename TData >
Nektar::detail::EnergyOpImpl< ExecSpace, TData >::EnergyOpImpl ( const MultiRegions::ExpListSharedPtr &  expansionList,
const std::vector< std::string > &  components 
)
inline

Definition at line 55 of file EnergyOpImpl.hpp.

57 : EnergyOp<TData>(expansionList, components)
58 {
59 // A 3DH1 expansion is a 2D mesh extended by the homogeneous direction.
60 const bool homogeneous =
61 expansionList->GetExpType() == MultiRegions::e3DH1D;
62 const unsigned int shapeDimension = expansionList->GetShapeDimension();
63 m_dimension = shapeDimension + (homogeneous ? 1 : 0);
64 ASSERTL0(m_dimension == 2 || m_dimension == 3,
65 "EnergyOp supports only 2D, 3D and 3DH1 expansions.");
66 ASSERTL0(expansionList->GetCoordim(0) == shapeDimension,
67 "EnergyOp does not support embedded-manifold expansions.");
68 ASSERTL0(components.size() >= m_dimension,
69 "EnergyOp requires one velocity component per dimension.");
70
71 // The quadrature metric of each block is fetched from the data
72 // warehouse at the interleave width of the first velocity read at it.
73 const size_t nBlocks =
74 MultiRegions::GetCollections(expansionList).size();
75 for (auto &metric : m_metric)
76 {
77 metric.assign(nBlocks, nullptr);
78 }
79
80 // z quadrature weight of each local plane, times Lhom / 2, with which
81 // the kernel sums the planes; a single unit weight without a
82 // homogeneous direction.
83 std::vector<TData> planeWeights{TData{1}};
84 if (homogeneous)
85 {
86 const auto w = expansionList->GetHomogeneousBasis()->GetW();
87 const auto zIDs = expansionList->GetZIDs();
88 const auto homoLen = expansionList->GetHomoLen();
90 zIDs.size() > 1,
91 "EnergyOp requires the homogeneous derivative, which needs "
92 "more than one homogeneous plane on each rank.");
93 planeWeights.resize(zIDs.size());
94 for (unsigned int n = 0; n < zIDs.size(); ++n)
95 {
96 planeWeights[n] = w[zIDs[n]] * homoLen * 0.5;
97 }
98 }
99 m_numPlanes = planeWeights.size();
101 LibUtilities::MemoryRegion<TData>::template FromVector<MemSpace>(
102 "Energy plane weights", planeWeights);
103
104 this->m_result = LibUtilities::MemoryRegion<TData>(
105 "Energy result", EnergyOp<TData>::resultSize, eHostPinned);
106 }
#define ASSERTL0(condition, msg)
static constexpr unsigned int resultSize
Number of entries in m_result.
Definition EnergyOp.hpp:142
LibUtilities::MemoryRegion< TData > m_result
Reduced result of Apply(), of size resultSize, allocated by the implementation's constructor.
Definition EnergyOp.hpp:148
unsigned int m_numPlanes
Number of local planes, or 1 without a homogeneous direction.
LibUtilities::MemoryRegion< TData > m_planeWeights
Quadrature weight of each local homogeneous plane, of size m_numPlanes.
std::array< std::vector< const TData * >, 2 > m_metric
Quadrature metric of every point of each block, indexed by block, at interleave width one (first) and...
Collections::CollectionVector GetCollections(MultiRegions::ExpListSharedPtr expansionList)

References ASSERTL0, Nektar::MultiRegions::e3DH1D, Nektar::eHostPinned, Nektar::MultiRegions::GetCollections(), Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_dimension, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_metric, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_numPlanes, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_planeWeights, and Nektar::EnergyOp< TData >::m_result.

Member Function Documentation

◆ Instantiate()

template<typename ExecSpace , typename TData >
static std::unique_ptr< MultiRegions::Operator< TData > > Nektar::detail::EnergyOpImpl< ExecSpace, TData >::Instantiate ( const MultiRegions::ExpListSharedPtr &  expansionList,
const std::vector< std::string > &  components 
)
inlinestatic

Definition at line 112 of file EnergyOpImpl.hpp.

115 {
116 return std::make_unique<EnergyOpImpl<ExecSpace, TData>>(expansionList,
117 components);
118 }

◆ v_Apply()

template<typename ExecSpace , typename TData >
void Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply ( LibUtilities::Field< TData, FieldState::Phys > &  velocity,
LibUtilities::Field< TData, FieldState::Phys > &  velocityGradient 
)
inlineoverrideprotectedvirtual

Implements Nektar::EnergyOp< TData >.

Definition at line 147 of file EnergyOpImpl.hpp.

150 {
151 ASSERTL1(velocity.GetNumHomoModes() == m_numPlanes &&
152 velocityGradient.GetNumHomoModes() == m_numPlanes,
153 "EnergyOp velocity plane count mismatch.");
154 ASSERTL1(velocity.GetNumComponents() >= m_dimension,
155 "EnergyOp velocity component count mismatch.");
156 ASSERTL1(velocity.GetBlocks().size() == m_metric[0].size() &&
157 velocityGradient.GetBlocks().size() == m_metric[0].size(),
158 "EnergyOp velocity block count changed after configuration.");
159
160 // Each block is integrated on its own stream, between the zeroing of
161 // the result and its reduction on the null stream.
162 this->m_result.template Initialize<MemSpace>(TData{0});
163
164 for (unsigned int block_idx = 0;
165 block_idx < velocity.GetBlocks().size(); ++block_idx)
166 {
167 const unsigned int streamID = block_idx + 1;
168
169 auto &velocityBlock = velocity.GetBlocks()[block_idx];
170 auto &gradientBlock = velocityGradient.GetBlocks()[block_idx];
171 const unsigned int interleaveWidth =
172 velocityBlock.GetInterleaveWidth();
173
174 ASSERTL0(interleaveWidth == 1 ||
175 interleaveWidth == m_implInterleaveWidth,
176 "EnergyOp reads a velocity at interleave width 1 or " +
177 std::to_string(m_implInterleaveWidth) + ", not " +
178 std::to_string(interleaveWidth) + ".");
179 ASSERTL1(velocityBlock.CompSize() == gradientBlock.CompSize() &&
180 gradientBlock.GetInterleaveWidth() == interleaveWidth,
181 "EnergyOp velocity-gradient block layout mismatch.");
182
183 // The metric is laid out like the velocity, so one storage index
184 // addresses the same point in both.
185 const TData *&metric =
186 m_metric[interleaveWidth == 1 ? 0 : 1][block_idx];
187 if (metric == nullptr)
188 {
189 metric = this->m_dataWarehouse->template GetData<MemSpace>(
190 LocalRegions::QuadratureMetricKey<TData>(block_idx,
191 interleaveWidth));
192 }
193
194 const auto velocityPtr =
195 velocityBlock.template GetPtr<MemSpace, ReadOnly>(streamID);
196 const auto gradientPtr =
197 gradientBlock.template GetPtr<MemSpace, ReadOnly>(streamID);
198 const auto planeWeights =
199 m_planeWeights.template GetPtr<MemSpace, ReadOnly>(streamID);
200 auto result =
201 this->m_result.template GetPtr<MemSpace, ReadWrite>(streamID);
202
203 switch (m_dimension)
204 {
205 case 2:
206 EnergyKernelLauncher<ExecSpace, 2>(
207 velocityBlock.CompSize(), m_numPlanes,
209 m_velocityComponents[2], metric, planeWeights,
210 velocityPtr, gradientPtr, result, streamID);
211 break;
212 case 3:
213 EnergyKernelLauncher<ExecSpace, 3>(
214 velocityBlock.CompSize(), m_numPlanes,
216 m_velocityComponents[2], metric, planeWeights,
217 velocityPtr, gradientPtr, result, streamID);
218 break;
219 default:
221 "EnergyOp supports only dimensions 2 and 3.");
222 }
223 }
224
225 // Reduce over the spatial ranks, which exclude those of other time
226 // slices, to every one or to rank zero alone.
227 auto comm = this->m_expansionList->GetComm()->GetSpaceComm();
228 if (this->m_rootOnly)
229 {
230 comm->template Reduce<MemSpace>(this->m_result,
232 }
233 else
234 {
235 comm->template AllReduce<MemSpace>(this->m_result,
237 }
238 }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
bool m_rootOnly
Whether Apply() reduces the results to rank zero alone.
Definition EnergyOp.hpp:145
MultiRegions::ExpListSharedPtr m_expansionList
Expansion list the operator acts on.
Definition Operator.hpp:349
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
Data warehouse shared with the other operators on the expansion list, used to build and cache shared ...
Definition Operator.hpp:355
std::array< unsigned int, 3 > m_velocityComponents
static constexpr unsigned int m_implInterleaveWidth
Interleave width of the execution space: an input block is read at this width or at width one.

References ASSERTL0, ASSERTL1, Nektar::ErrorUtil::efatal, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), Nektar::MultiRegions::Operator< TData >::m_dataWarehouse, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_dimension, Nektar::MultiRegions::Operator< TData >::m_expansionList, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_implInterleaveWidth, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_metric, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_numPlanes, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_planeWeights, Nektar::EnergyOp< TData >::m_result, Nektar::EnergyOp< TData >::m_rootOnly, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_velocityComponents, NEKERROR, and Nektar::LibUtilities::ReduceSum.

◆ v_Configure()

template<typename ExecSpace , typename TData >
void Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Configure ( const std::vector< unsigned int > &  velocityComponents)
inlineoverrideprotectedvirtual

Implements Nektar::EnergyOp< TData >.

Definition at line 138 of file EnergyOpImpl.hpp.

140 {
141 ASSERTL0(velocityComponents.size() == m_dimension,
142 "EnergyOp velocity selection must match the dimension.");
143 std::copy(velocityComponents.begin(), velocityComponents.end(),
144 m_velocityComponents.begin());
145 }

References ASSERTL0, Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_dimension, and Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_velocityComponents.

Member Data Documentation

◆ className

template<typename ExecSpace , typename TData >
std::string Nektar::detail::EnergyOpImpl< ExecSpace, TData >::className
static

Definition at line 109 of file EnergyOpImpl.hpp.

◆ m_dimension

template<typename ExecSpace , typename TData >
unsigned int Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_dimension = 0
protected

◆ m_implInterleaveWidth

template<typename ExecSpace , typename TData >
constexpr unsigned int Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_implInterleaveWidth
staticconstexprprotected
Initial value:
=
NektarSpaces::vector_width<ExecSpace, TData>::value

Interleave width of the execution space: an input block is read at this width or at width one.

Definition at line 123 of file EnergyOpImpl.hpp.

Referenced by Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply().

◆ m_metric

template<typename ExecSpace , typename TData >
std::array<std::vector<const TData *>, 2> Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_metric
protected

Quadrature metric of every point of each block, indexed by block, at interleave width one (first) and at m_implInterleaveWidth (second); null until a velocity is first read at that width.

Definition at line 129 of file EnergyOpImpl.hpp.

Referenced by Nektar::detail::EnergyOpImpl< ExecSpace, TData >::EnergyOpImpl(), and Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply().

◆ m_numPlanes

template<typename ExecSpace , typename TData >
unsigned int Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_numPlanes = 1
protected

Number of local planes, or 1 without a homogeneous direction.

Definition at line 136 of file EnergyOpImpl.hpp.

Referenced by Nektar::detail::EnergyOpImpl< ExecSpace, TData >::EnergyOpImpl(), and Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply().

◆ m_planeWeights

template<typename ExecSpace , typename TData >
LibUtilities::MemoryRegion<TData> Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_planeWeights
protected

Quadrature weight of each local homogeneous plane, of size m_numPlanes.

Definition at line 132 of file EnergyOpImpl.hpp.

Referenced by Nektar::detail::EnergyOpImpl< ExecSpace, TData >::EnergyOpImpl(), and Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply().

◆ m_velocityComponents

template<typename ExecSpace , typename TData >
std::array<unsigned int, 3> Nektar::detail::EnergyOpImpl< ExecSpace, TData >::m_velocityComponents {}
protected