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

#include <AeroForcesOpImpl.hpp>

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

Classes

struct  BlockBoundary
 The boundary quadrature points on the elements of one block, in the operator's memory space, for a velocity gradient at one interleave width. The points are sorted by the storage offset of their first gradient source at that width, so that neighbouring threads read neighbouring entries of the gradient wherever the boundary allows. Each source is held as its storage offset within a component: that of the gradient at the width the points are sorted for, and that of the pressure at interleave width one (first) and at m_implInterleaveWidth (second), so that the pressure is read at either width. The normals and moment arms are stored point-minor, component d of point p at d * nPoints + p. More...
 
struct  BlockBoundaryHost
 The boundary quadrature points on the elements of one block, as they are gathered at configuration, with the normals and moment arms stored point-major. More...
 
struct  RestrictionHost
 Restriction of boundary quadrature points from the elements of one block, as it is gathered at configuration: point i has the entries from rowOffset[i] up to rowOffset[i + 1], each reading quadrature point sourcePoint of element sourceElement of the block with its weight. A point whose restriction is a gather has one entry of weight one. More...
 
struct  VolumeLocation
 

Public Member Functions

 AeroForcesOpImpl (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
 
- Public Member Functions inherited from Nektar::AeroForcesOp< TData >
void Configure (const std::vector< unsigned int > &velocityComponents, const MultiRegions::ExpListSharedPtr &pressureExpansion, const unsigned int pressureComponent, const std::vector< bool > &selectedBoundaryRegions, const TData rho, const TData mu, const std::array< TData, 3 > &pivot)
 velocityComponents and pressureComponent are the indices of the velocity and pressure in the fields whose gradient and values Apply() receives, which may hold further components.
 
void Apply (LibUtilities::Field< TData, FieldState::Phys > &pressure, LibUtilities::Field< TData, FieldState::Phys > &velocityGradient)
 Collective: every rank must call it.
 
void operator() (LibUtilities::Field< TData, FieldState::Phys > &pressure, 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.
 
std::array< TData, 3 > GetPressureForce ()
 Pressure force from the last Apply().
 
std::array< TData, 3 > GetViscousForce ()
 Viscous force from the last Apply().
 
std::array< TData, 3 > GetPressureMoment ()
 Moment of the pressure traction about the pivot from the last Apply().
 
std::array< TData, 3 > GetViscousMoment ()
 Moment of the viscous traction about the pivot 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::AeroForcesOp< TData >
static std::shared_ptr< AeroForcesOp< TData > > Create (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
 expansionList and components are those of the velocity.
 
- 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::AeroForcesOp< TData >
static const std::string name = "AeroForces"
 

Protected Member Functions

std::map< int, VolumeLocation > BuildVolumeLocations (const MultiRegions::ExpListSharedPtr &expansion)
 
void v_Configure (const std::vector< unsigned int > &velocityComponents, const MultiRegions::ExpListSharedPtr &pressureExpansion, const unsigned int pressureComponent, const std::vector< bool > &selectedBoundaryRegions, const TData rho, const TData mu, const std::array< TData, 3 > &pivot) override
 
void v_Apply (LibUtilities::Field< TData, FieldState::Phys > &pressure, LibUtilities::Field< TData, FieldState::Phys > &velocityGradient) override
 
- Protected Member Functions inherited from Nektar::AeroForcesOp< TData >
 AeroForcesOp (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
 
 ~AeroForcesOp () override=default
 
std::array< TData, 3 > GetResultVector (const unsigned int offset)
 The 3-vector at offset of the reduced result, read on the host.
 

Static Protected Member Functions

static bool CompressRestriction (const std::vector< TData > &restriction, const size_t nSrc, const size_t nDst, std::vector< size_t > &pointMap)
 
static std::vector< TData > BuildRestriction (const LocalRegions::ExpansionSharedPtr &volume, const unsigned int trace, const LocalRegions::ExpansionSharedPtr &boundary)
 
static void AppendRestriction (const std::vector< TData > &restriction, const size_t nSrc, const size_t nDst, const size_t element, RestrictionHost &host)
 Append the rows of the restriction of one boundary face, read from element element of a block, to host: one entry of weight one per point if the restriction is a gather, else the nonzero entries of each row.
 
static size_t StorageOffset (const size_t element, const size_t point, const size_t nPoints, const size_t interleaveWidth)
 Storage offset of quadrature point point of element element within a component of a block of interleave width interleaveWidth whose elements have nPoints quadrature points.
 
static BlockBoundary UploadBlockBoundary (const BlockBoundaryHost &host, const unsigned int nDim, const unsigned int gradientInterleaveWidth)
 Copy the boundary points of one block to the operator's memory space, sorted and laid out for a velocity gradient at interleave width gradientInterleaveWidth.
 

Protected Attributes

MultiRegions::ExpListSharedPtr m_pressureExpansion
 
std::vector< BlockBoundaryHost > m_boundaryHost
 The boundary points of each block, indexed by block, as they are gathered at configuration.
 
std::vector< std::array< BlockBoundary, 2 > > m_boundary
 The boundary points of each block, indexed by block, for a velocity gradient at interleave width one (first) and at m_implInterleaveWidth (second); empty until a gradient is first read at that width.
 
std::array< unsigned int, 3 > m_velocityComponents {}
 
unsigned int m_pressureComponent = 0
 
unsigned int m_dimension = 0
 
unsigned int m_numPlanes = 1
 Number of local planes, or 1 without a homogeneous direction.
 
unsigned int m_gradientDirections = 0
 Number of directions of each velocity component in the gradient.
 
TData m_planeWeight = TData(1)
 Weight of each plane in the average over the planes.
 
TData m_rho = TData(1)
 
TData m_mu = TData(1)
 
- Protected Attributes inherited from Nektar::AeroForcesOp< 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 Configure().
 
- 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::AeroForcesOp< TData >
static constexpr unsigned int pressureForce = 0
 Offsets of the 3-vectors in m_result.
 
static constexpr unsigned int viscousForce = 3
 
static constexpr unsigned int pressureMoment = 6
 
static constexpr unsigned int viscousMoment = 9
 
static constexpr unsigned int resultSize = 12
 Number of entries in m_result.
 

Private Types

using MemSpace = typename ExecSpace::memory_space
 

Detailed Description

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

Definition at line 54 of file AeroForcesOpImpl.hpp.

Member Typedef Documentation

◆ MemSpace

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

Definition at line 56 of file AeroForcesOpImpl.hpp.

Constructor & Destructor Documentation

◆ AeroForcesOpImpl()

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

Definition at line 59 of file AeroForcesOpImpl.hpp.

61 : AeroForcesOp<TData>(expansionList, components)
62 {
63 }

Member Function Documentation

◆ AppendRestriction()

template<typename ExecSpace , typename TData >
static void Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::AppendRestriction ( const std::vector< TData > &  restriction,
const size_t  nSrc,
const size_t  nDst,
const size_t  element,
RestrictionHost &  host 
)
inlinestaticprotected

Append the rows of the restriction of one boundary face, read from element element of a block, to host: one entry of weight one per point if the restriction is a gather, else the nonzero entries of each row.

Definition at line 253 of file AeroForcesOpImpl.hpp.

256 {
257 std::vector<size_t> pointMap;
258 const bool gather =
259 CompressRestriction(restriction, nSrc, nDst, pointMap);
260 for (size_t point = 0; point < nDst; ++point)
261 {
262 if (gather)
263 {
264 host.sourceElement.push_back(element);
265 host.sourcePoint.push_back(pointMap[point]);
266 host.weight.push_back(TData(1));
267 }
268 else
269 {
270 [[maybe_unused]] const size_t rowStart = host.weight.size();
271 for (size_t q = 0; q < nSrc; ++q)
272 {
273 const TData weight = restriction[point * nSrc + q];
274 if (weight != TData(0))
275 {
276 host.sourceElement.push_back(element);
277 host.sourcePoint.push_back(q);
278 host.weight.push_back(weight);
279 }
280 }
281 ASSERTL1(host.weight.size() > rowStart,
282 "AeroForcesOp encountered an empty boundary "
283 "restriction row.");
284 }
285 host.rowOffset.push_back(host.weight.size());
286 }
287 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
static bool CompressRestriction(const std::vector< TData > &restriction, const size_t nSrc, const size_t nDst, std::vector< size_t > &pointMap)

References ASSERTL1, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::CompressRestriction(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::RestrictionHost::rowOffset, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::RestrictionHost::sourceElement, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::RestrictionHost::sourcePoint, and Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::RestrictionHost::weight.

Referenced by Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Configure().

◆ BuildRestriction()

template<typename ExecSpace , typename TData >
static std::vector< TData > Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BuildRestriction ( const LocalRegions::ExpansionSharedPtr &  volume,
const unsigned int  trace,
const LocalRegions::ExpansionSharedPtr &  boundary 
)
inlinestaticprotected

Definition at line 223 of file AeroForcesOpImpl.hpp.

227 {
228 // Probe the exact oriented restriction once during configuration.
229 // Apply only uses the resulting device-resident gather/sparse map.
230 const size_t nSrc = volume->GetTotPoints();
231 const size_t nDst = boundary->GetTotPoints();
232 std::vector<TData> restriction(nDst * nSrc, TData(0));
233 Array<OneD, NekDouble> source(nSrc, 0.0);
234 Array<OneD, NekDouble> destination(nDst, 0.0);
235 for (size_t q = 0; q < nSrc; ++q)
236 {
237 source[q] = 1.0;
238 volume->GetTracePhysVals(trace, boundary, source, destination);
239 for (size_t point = 0; point < nDst; ++point)
240 {
241 restriction[point * nSrc + q] =
242 static_cast<TData>(destination[point]);
243 }
244 source[q] = 0.0;
245 }
246 return restriction;
247 }

Referenced by Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Configure().

◆ BuildVolumeLocations()

template<typename ExecSpace , typename TData >
std::map< int, VolumeLocation > Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BuildVolumeLocations ( const MultiRegions::ExpListSharedPtr &  expansion)
inlineprotected

Definition at line 161 of file AeroForcesOpImpl.hpp.

163 {
164 std::map<int, VolumeLocation> locations;
165 const auto blockAttributes =
166 MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(
167 expansion);
168 for (unsigned int block_idx = 0; block_idx < blockAttributes.size();
169 ++block_idx)
170 {
171 auto collection = MultiRegions::GetCollection(expansion, block_idx);
172 const auto &elements = collection.GetExpVector();
173 for (size_t element = 0; element < elements.size(); ++element)
174 {
175 locations[elements[element]->GetGeom()->GetGlobalID()] = {
176 block_idx, element, elements[element]};
177 }
178 }
179 return locations;
180 }
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)

References Nektar::MultiRegions::GetCollection().

Referenced by Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Configure().

◆ CompressRestriction()

template<typename ExecSpace , typename TData >
static bool Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::CompressRestriction ( const std::vector< TData > &  restriction,
const size_t  nSrc,
const size_t  nDst,
std::vector< size_t > &  pointMap 
)
inlinestaticprotected

Definition at line 182 of file AeroForcesOpImpl.hpp.

185 {
186 const TData tolerance =
187 TData(1000) * std::numeric_limits<TData>::epsilon();
188 pointMap.resize(nDst);
189 for (size_t point = 0; point < nDst; ++point)
190 {
191 size_t source = 0;
192 TData largest = TData(0);
193 for (size_t q = 0; q < nSrc; ++q)
194 {
195 const TData value = std::abs(restriction[point * nSrc + q]);
196 if (value > largest)
197 {
198 largest = value;
199 source = q;
200 }
201 }
202
203 if (std::abs(restriction[point * nSrc + source] - TData(1)) >
204 tolerance)
205 {
206 pointMap.clear();
207 return false;
208 }
209 for (size_t q = 0; q < nSrc; ++q)
210 {
211 if (q != source &&
212 std::abs(restriction[point * nSrc + q]) > tolerance)
213 {
214 pointMap.clear();
215 return false;
216 }
217 }
218 pointMap[point] = source;
219 }
220 return true;
221 }

Referenced by Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::AppendRestriction().

◆ Instantiate()

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

Definition at line 69 of file AeroForcesOpImpl.hpp.

72 {
73 return std::make_unique<AeroForcesOpImpl<ExecSpace, TData>>(
74 expansionList, components);
75 }

◆ StorageOffset()

template<typename ExecSpace , typename TData >
static size_t Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::StorageOffset ( const size_t  element,
const size_t  point,
const size_t  nPoints,
const size_t  interleaveWidth 
)
inlinestaticprotected

Storage offset of quadrature point point of element element within a component of a block of interleave width interleaveWidth whose elements have nPoints quadrature points.

Definition at line 292 of file AeroForcesOpImpl.hpp.

295 {
296 return (element / interleaveWidth) * interleaveWidth * nPoints +
297 point * interleaveWidth + element % interleaveWidth;
298 }

Referenced by Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::UploadBlockBoundary().

◆ UploadBlockBoundary()

template<typename ExecSpace , typename TData >
static BlockBoundary Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::UploadBlockBoundary ( const BlockBoundaryHost &  host,
const unsigned int  nDim,
const unsigned int  gradientInterleaveWidth 
)
inlinestaticprotected

Copy the boundary points of one block to the operator's memory space, sorted and laid out for a velocity gradient at interleave width gradientInterleaveWidth.

Definition at line 303 of file AeroForcesOpImpl.hpp.

306 {
307 BlockBoundary boundary;
308 const size_t nPoints = host.gradient.rowOffset.size() - 1;
309 boundary.nPoints = nPoints;
310
311 const auto &gradient = host.gradient;
312 const auto &pressure = host.pressure;
313 auto gradientOffset = [&](const size_t entry) {
314 return StorageOffset(gradient.sourceElement[entry],
315 gradient.sourcePoint[entry], host.nGradientSrc,
316 gradientInterleaveWidth);
317 };
318
319 std::vector<size_t> order(nPoints);
320 std::iota(order.begin(), order.end(), size_t(0));
321 std::stable_sort(order.begin(), order.end(),
322 [&](const size_t a, const size_t b) {
323 return gradientOffset(gradient.rowOffset[a]) <
324 gradientOffset(gradient.rowOffset[b]);
325 });
326
327 std::vector<size_t> gradientRowOffset{0};
328 std::vector<size_t> gradientSource;
329 std::vector<TData> gradientWeight;
330 std::vector<size_t> pressureRowOffset{0};
331 std::array<std::vector<size_t>, 2> pressureSource;
332 std::vector<TData> pressureWeight;
333 std::vector<TData> weightedNormals(nDim * nPoints);
334 std::vector<TData> momentArms(3 * nPoints);
335 const std::array<unsigned int, 2> interleaveWidths{
337 for (size_t i = 0; i < nPoints; ++i)
338 {
339 const size_t point = order[i];
340 for (size_t entry = gradient.rowOffset[point];
341 entry < gradient.rowOffset[point + 1]; ++entry)
342 {
343 gradientSource.push_back(gradientOffset(entry));
344 gradientWeight.push_back(gradient.weight[entry]);
345 }
346 gradientRowOffset.push_back(gradientSource.size());
347
348 for (size_t entry = pressure.rowOffset[point];
349 entry < pressure.rowOffset[point + 1]; ++entry)
350 {
351 for (unsigned int w = 0; w < interleaveWidths.size(); ++w)
352 {
353 pressureSource[w].push_back(
354 StorageOffset(pressure.sourceElement[entry],
355 pressure.sourcePoint[entry],
356 host.nPressureSrc, interleaveWidths[w]));
357 }
358 pressureWeight.push_back(pressure.weight[entry]);
359 }
360 pressureRowOffset.push_back(pressureWeight.size());
361
362 for (unsigned int d = 0; d < nDim; ++d)
363 {
364 weightedNormals[d * nPoints + i] =
365 host.weightedNormals[point * nDim + d];
366 }
367 for (unsigned int d = 0; d < 3; ++d)
368 {
369 momentArms[d * nPoints + i] = host.momentArms[point * 3 + d];
370 }
371 }
372
373 using SizeRegion = LibUtilities::MemoryRegion<size_t>;
374 using TDataRegion = LibUtilities::MemoryRegion<TData>;
375 boundary.pressureRowOffset = SizeRegion::template FromVector<MemSpace>(
376 "AeroForces pressure rows", pressureRowOffset);
377 for (unsigned int w = 0; w < interleaveWidths.size(); ++w)
378 {
379 boundary.pressureSource[w] =
380 SizeRegion::template FromVector<MemSpace>(
381 "AeroForces pressure sources", pressureSource[w]);
382 }
383 boundary.pressureWeight = TDataRegion::template FromVector<MemSpace>(
384 "AeroForces pressure weights", pressureWeight);
385 boundary.gradientRowOffset = SizeRegion::template FromVector<MemSpace>(
386 "AeroForces gradient rows", gradientRowOffset);
387 boundary.gradientSource = SizeRegion::template FromVector<MemSpace>(
388 "AeroForces gradient sources", gradientSource);
389 boundary.gradientWeight = TDataRegion::template FromVector<MemSpace>(
390 "AeroForces gradient weights", gradientWeight);
391 boundary.weightedNormals = TDataRegion::template FromVector<MemSpace>(
392 "AeroForces weighted normals", weightedNormals);
393 boundary.momentArms = TDataRegion::template FromVector<MemSpace>(
394 "AeroForces moment arms", momentArms);
395 return boundary;
396 }
static size_t StorageOffset(const size_t element, const size_t point, const size_t nPoints, const size_t interleaveWidth)
Storage offset of quadrature point point of element element within a component of a block of interlea...
static constexpr unsigned int m_implInterleaveWidth
Interleave width of the execution space: an input block is read at this width or at width one.
std::vector< double > d(NPUPPER *NPUPPER)

References Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::gradient, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::gradientRowOffset, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::gradientSource, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::gradientWeight, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_implInterleaveWidth, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::momentArms, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::momentArms, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::nGradientSrc, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::nPoints, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::nPressureSrc, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::pressure, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::pressureRowOffset, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::pressureSource, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::pressureWeight, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::RestrictionHost::rowOffset, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::StorageOffset(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundaryHost::weightedNormals, and Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BlockBoundary::weightedNormals.

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

◆ v_Apply()

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

Implements Nektar::AeroForcesOp< TData >.

Definition at line 568 of file AeroForcesOpImpl.hpp.

571 {
572 ASSERTL1(pressure.GetNumHomoModes() == m_numPlanes &&
573 velocityGradient.GetNumHomoModes() == m_numPlanes,
574 "AeroForcesOp pressure or gradient plane count mismatch.");
575 ASSERTL1(m_pressureComponent < pressure.GetNumComponents(),
576 "AeroForcesOp pressure component is out of range.");
577 ASSERTL1(pressure.GetBlocks().size() == m_boundary.size() &&
578 velocityGradient.GetBlocks().size() == m_boundary.size(),
579 "AeroForcesOp block count changed after configuration.");
580
581 // Each block is integrated on its own stream, between the zeroing of
582 // the result and its reduction on the null stream.
583 this->m_result.template Initialize<MemSpace>(TData{0});
584
585 // Each block integrates the boundary points on its elements on its
586 // own stream; a block with no selected boundary launches nothing.
587 for (unsigned int block_idx = 0; block_idx < m_boundary.size();
588 ++block_idx)
589 {
590 auto &pressureBlock = pressure.GetBlocks()[block_idx];
591 auto &gradientBlock = velocityGradient.GetBlocks()[block_idx];
592 const unsigned int pressureInterleaveWidth =
593 pressureBlock.GetInterleaveWidth();
594 const unsigned int gradientInterleaveWidth =
595 gradientBlock.GetInterleaveWidth();
596
597 ASSERTL0((pressureInterleaveWidth == 1 ||
598 pressureInterleaveWidth == m_implInterleaveWidth) &&
599 (gradientInterleaveWidth == 1 ||
600 gradientInterleaveWidth == m_implInterleaveWidth),
601 "AeroForcesOp reads its inputs at interleave width 1 or " +
602 std::to_string(m_implInterleaveWidth) + ".");
603
604 const auto &host = m_boundaryHost[block_idx];
605 if (host.gradient.rowOffset.size() == 1)
606 {
607 continue;
608 }
609
610 auto &boundary =
611 m_boundary[block_idx][gradientInterleaveWidth == 1 ? 0 : 1];
612 if (boundary.nPoints == 0)
613 {
614 boundary = UploadBlockBoundary(host, m_dimension,
615 gradientInterleaveWidth);
616 }
617
618 const unsigned int streamID = block_idx + 1;
619
620 const auto pressurePtr =
621 pressureBlock.template GetPtr<MemSpace, ReadOnly>(streamID) +
622 m_pressureComponent * m_numPlanes * pressureBlock.CompSize();
623 const auto gradientPtr =
624 gradientBlock.template GetPtr<MemSpace, ReadOnly>(streamID);
625 auto result =
626 this->m_result.template GetPtr<MemSpace, ReadWrite>(streamID);
627
628 const auto pressureRowOffset =
629 boundary.pressureRowOffset.template GetPtr<MemSpace, ReadOnly>(
630 streamID);
631 const auto pressureSource =
632 boundary.pressureSource[pressureInterleaveWidth == 1 ? 0 : 1]
633 .template GetPtr<MemSpace, ReadOnly>(streamID);
634 const auto pressureWeight =
635 boundary.pressureWeight.template GetPtr<MemSpace, ReadOnly>(
636 streamID);
637 const auto gradientRowOffset =
638 boundary.gradientRowOffset.template GetPtr<MemSpace, ReadOnly>(
639 streamID);
640 const auto gradientSource =
641 boundary.gradientSource.template GetPtr<MemSpace, ReadOnly>(
642 streamID);
643 const auto gradientWeight =
644 boundary.gradientWeight.template GetPtr<MemSpace, ReadOnly>(
645 streamID);
646 const auto weightedNormals =
647 boundary.weightedNormals.template GetPtr<MemSpace, ReadOnly>(
648 streamID);
649 const auto momentArms =
650 boundary.momentArms.template GetPtr<MemSpace, ReadOnly>(
651 streamID);
652
653 switch (m_dimension)
654 {
655 case 2:
656 AeroForcesKernelLauncher<ExecSpace, 2>(
657 boundary.nPoints, pressureRowOffset, pressureSource,
658 pressureWeight, gradientRowOffset, gradientSource,
659 gradientWeight, weightedNormals, momentArms,
660 pressurePtr, gradientPtr, m_numPlanes,
661 pressureBlock.CompSize(), gradientBlock.CompSize(),
664 m_planeWeight, m_rho, m_mu, result, streamID);
665 break;
666 case 3:
667 AeroForcesKernelLauncher<ExecSpace, 3>(
668 boundary.nPoints, pressureRowOffset, pressureSource,
669 pressureWeight, gradientRowOffset, gradientSource,
670 gradientWeight, weightedNormals, momentArms,
671 pressurePtr, gradientPtr, m_numPlanes,
672 pressureBlock.CompSize(), gradientBlock.CompSize(),
675 m_planeWeight, m_rho, m_mu, result, streamID);
676 break;
677 default:
679 "AeroForcesOp supports only dimensions 2 and 3.");
680 }
681 }
682
683 // Reduce over the spatial ranks, which exclude those of other time
684 // slices, to every one or to rank zero alone.
685 auto comm = this->m_expansionList->GetComm()->GetSpaceComm();
686 if (this->m_rootOnly)
687 {
688 comm->template Reduce<MemSpace>(this->m_result,
690 }
691 else
692 {
693 comm->template AllReduce<MemSpace>(this->m_result,
695 }
696 }
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
LibUtilities::MemoryRegion< TData > m_result
Reduced result of Apply(), of size resultSize, allocated by Configure().
bool m_rootOnly
Whether Apply() reduces the results to rank zero alone.
MultiRegions::ExpListSharedPtr m_expansionList
Expansion list the operator acts on.
Definition Operator.hpp:349
static BlockBoundary UploadBlockBoundary(const BlockBoundaryHost &host, const unsigned int nDim, const unsigned int gradientInterleaveWidth)
Copy the boundary points of one block to the operator's memory space, sorted and laid out for a veloc...
unsigned int m_gradientDirections
Number of directions of each velocity component in the gradient.
unsigned int m_numPlanes
Number of local planes, or 1 without a homogeneous direction.
std::array< unsigned int, 3 > m_velocityComponents
std::vector< BlockBoundaryHost > m_boundaryHost
The boundary points of each block, indexed by block, as they are gathered at configuration.
std::vector< std::array< BlockBoundary, 2 > > m_boundary
The boundary points of each block, indexed by block, for a velocity gradient at interleave width one ...
TData m_planeWeight
Weight of each plane in the average over the planes.

References ASSERTL0, ASSERTL1, Nektar::ErrorUtil::efatal, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundary, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundaryHost, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_dimension, Nektar::MultiRegions::Operator< TData >::m_expansionList, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_gradientDirections, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_implInterleaveWidth, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_mu, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_numPlanes, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_planeWeight, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_pressureComponent, Nektar::AeroForcesOp< TData >::m_result, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_rho, Nektar::AeroForcesOp< TData >::m_rootOnly, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_velocityComponents, NEKERROR, Nektar::LibUtilities::ReduceSum, and Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::UploadBlockBoundary().

◆ v_Configure()

template<typename ExecSpace , typename TData >
void Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Configure ( const std::vector< unsigned int > &  velocityComponents,
const MultiRegions::ExpListSharedPtr &  pressureExpansion,
const unsigned int  pressureComponent,
const std::vector< bool > &  selectedBoundaryRegions,
const TData  rho,
const TData  mu,
const std::array< TData, 3 > &  pivot 
)
inlineoverrideprotectedvirtual

Implements Nektar::AeroForcesOp< TData >.

Definition at line 398 of file AeroForcesOpImpl.hpp.

404 {
405 // A 3DH1 expansion is a 2D mesh extended by the homogeneous
406 // direction: the boundaries are those of its first plane, and each
407 // local plane is integrated as a 2D expansion, the forces per unit
408 // span averaged over the planes. The z velocity is not read.
409 const bool homogeneous =
410 this->m_expansionList->GetExpType() == MultiRegions::e3DH1D;
411 const auto planeExpansion = homogeneous
412 ? this->m_expansionList->GetPlane(0)
413 : this->m_expansionList;
414 m_pressureExpansion = pressureExpansion;
415 m_dimension = planeExpansion->GetCoordim(0);
416 const unsigned int nVelocity = m_dimension + (homogeneous ? 1 : 0);
417 ASSERTL0(m_dimension == 2 || m_dimension == 3,
418 "AeroForcesOp supports only 2D, 3D and 3DH1 expansions.");
419 ASSERTL0(planeExpansion->GetShapeDimension() == m_dimension,
420 "AeroForcesOp does not support embedded-manifold expansions.");
421 ASSERTL0(this->m_components.size() >= nVelocity,
422 "AeroForcesOp requires one velocity component per dimension.");
423 ASSERTL0(velocityComponents.size() == nVelocity,
424 "AeroForcesOp velocity selection has the wrong dimension.");
425 ASSERTL0(pressureExpansion,
426 "AeroForcesOp requires a pressure expansion.");
427 std::copy(velocityComponents.begin(),
428 velocityComponents.begin() + m_dimension,
429 m_velocityComponents.begin());
430 m_numPlanes = homogeneous ? this->m_expansionList->GetZIDs().size() : 1;
431 // A multi-plane 3DH1 gradient also carries the z direction.
433 m_planeWeight = homogeneous ? TData(1) / this->m_expansionList
434 ->GetHomogeneousBasis()
435 ->GetNumPoints()
436 : TData(1);
437 m_pressureComponent = pressureComponent;
438 m_rho = rho;
439 m_mu = mu;
440
441 const auto &boundaryExpansions = planeExpansion->GetBndCondExpansions();
442 ASSERTL0(selectedBoundaryRegions.size() == boundaryExpansions.size(),
443 "AeroForcesOp boundary selection size mismatch.");
444
445 const auto velocityLocations =
447 const auto pressureLocations =
449 Array<OneD, int> boundaryToElement;
450 Array<OneD, int> boundaryToTrace;
451 planeExpansion->GetBoundaryToElmtMap(boundaryToElement,
452 boundaryToTrace);
453
454 const size_t nBlocks =
455 MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(
456 this->m_expansionList)
457 .size();
458 m_boundaryHost.assign(nBlocks, BlockBoundaryHost{});
459 size_t boundaryOffset = 0;
460 for (unsigned int region = 0; region < boundaryExpansions.size();
461 ++region)
462 {
463 auto boundaryList = boundaryExpansions[region];
464 if (!selectedBoundaryRegions[region])
465 {
466 boundaryOffset += boundaryList->GetExpSize();
467 continue;
468 }
469
470 Array<OneD, Array<OneD, NekDouble>> normals;
471 planeExpansion->GetBoundaryNormals(region, normals);
472 for (size_t face = 0; face < boundaryList->GetExpSize(); ++face)
473 {
474 const size_t mapIndex = boundaryOffset + face;
475 const int elementId = boundaryToElement[mapIndex];
476 const int traceId = boundaryToTrace[mapIndex];
477 const auto velocityElement = planeExpansion->GetExp(elementId);
478 const int geometry = velocityElement->GetGeom()->GetGlobalID();
479 const auto velocityLocation = velocityLocations.at(geometry);
480 const auto pressureLocationIt =
481 pressureLocations.find(geometry);
482 ASSERTL0(pressureLocationIt != pressureLocations.end(),
483 "AeroForcesOp could not match a pressure element to a "
484 "selected velocity boundary.");
485 const auto pressureLocation = pressureLocationIt->second;
486 ASSERTL0(pressureLocation.block == velocityLocation.block &&
487 pressureLocation.element ==
488 velocityLocation.element,
489 "AeroForcesOp requires the pressure to share the "
490 "blocks of the velocity.");
491 const int boundaryGeometry =
492 velocityElement->GetGeom()->GetTid(traceId);
493 bool pressureTraceFound = false;
494 unsigned int pressureTraceId = 0;
495 for (unsigned int pressureTrace = 0;
496 pressureTrace < pressureLocation.expansion->GetNtraces();
497 ++pressureTrace)
498 {
499 if (pressureLocation.expansion->GetGeom()->GetTid(
500 pressureTrace) == boundaryGeometry)
501 {
502 pressureTraceFound = true;
503 pressureTraceId = pressureTrace;
504 break;
505 }
506 }
507 ASSERTL0(pressureTraceFound,
508 "AeroForcesOp pressure and velocity boundary topology "
509 "differs.");
510
511 const auto boundary = boundaryList->GetExp(face);
512 const size_t nGradientSrc = velocityElement->GetTotPoints();
513 const size_t nPressureSrc =
514 pressureLocation.expansion->GetTotPoints();
515 const size_t nDst = boundary->GetTotPoints();
516
517 auto &host = m_boundaryHost[velocityLocation.block];
518 host.nGradientSrc = nGradientSrc;
519 host.nPressureSrc = nPressureSrc;
521 BuildRestriction(velocityElement, traceId, boundary),
522 nGradientSrc, nDst, velocityLocation.element,
523 host.gradient);
524 AppendRestriction(BuildRestriction(pressureLocation.expansion,
525 pressureTraceId, boundary),
526 nPressureSrc, nDst, pressureLocation.element,
527 host.pressure);
528
529 Array<OneD, NekDouble> one(nDst, 1.0);
530 Array<OneD, NekDouble> metric(nDst, 0.0);
531 boundary->MultiplyByQuadratureMetric(one, metric);
532 const size_t boundaryPhysOffset =
533 boundaryList->GetPhys_Offset(face);
534 for (size_t point = 0; point < nDst; ++point)
535 {
536 for (unsigned int d = 0; d < m_dimension; ++d)
537 {
538 host.weightedNormals.push_back(static_cast<TData>(
539 metric[point] *
540 normals[d][boundaryPhysOffset + point]));
541 }
542 }
543
544 Array<OneD, NekDouble> x(nDst, 0.0), y(nDst, 0.0), z(nDst, 0.0);
545 boundary->GetCoords(x, y, z);
546 for (size_t point = 0; point < nDst; ++point)
547 {
548 host.momentArms.push_back(static_cast<TData>(x[point]) -
549 pivot[0]);
550 host.momentArms.push_back(static_cast<TData>(y[point]) -
551 pivot[1]);
552 host.momentArms.push_back(static_cast<TData>(z[point]) -
553 pivot[2]);
554 }
555 }
556 boundaryOffset += boundaryList->GetExpSize();
557 }
558
559 // The points of each block are copied to the operator's memory space
560 // when a gradient is first read at each interleave width.
561 m_boundary.clear();
562 m_boundary.resize(nBlocks);
563
564 this->m_result = LibUtilities::MemoryRegion<TData>(
565 "AeroForces result", AeroForcesOp<TData>::resultSize, eHostPinned);
566 }
static constexpr unsigned int resultSize
Number of entries in m_result.
std::vector< std::string > m_components
Names of the field components the operator was built for.
Definition Operator.hpp:351
MultiRegions::ExpListSharedPtr m_pressureExpansion
static std::vector< TData > BuildRestriction(const LocalRegions::ExpansionSharedPtr &volume, const unsigned int trace, const LocalRegions::ExpansionSharedPtr &boundary)
static void AppendRestriction(const std::vector< TData > &restriction, const size_t nSrc, const size_t nDst, const size_t element, RestrictionHost &host)
Append the rows of the restriction of one boundary face, read from element element of a block,...
std::map< int, VolumeLocation > BuildVolumeLocations(const MultiRegions::ExpListSharedPtr &expansion)

References Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::AppendRestriction(), ASSERTL0, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BuildRestriction(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::BuildVolumeLocations(), Nektar::MultiRegions::e3DH1D, Nektar::eHostPinned, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundary, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundaryHost, Nektar::MultiRegions::Operator< TData >::m_components, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_dimension, Nektar::MultiRegions::Operator< TData >::m_expansionList, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_mu, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_numPlanes, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_planeWeight, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_pressureComponent, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_pressureExpansion, Nektar::AeroForcesOp< TData >::m_result, Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_rho, and Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_velocityComponents.

Member Data Documentation

◆ className

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

Definition at line 66 of file AeroForcesOpImpl.hpp.

◆ m_boundary

template<typename ExecSpace , typename TData >
std::vector<std::array<BlockBoundary, 2> > Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundary
protected

The boundary points of each block, indexed by block, for a velocity gradient at interleave width one (first) and at m_implInterleaveWidth (second); empty until a gradient is first read at that width.

Definition at line 148 of file AeroForcesOpImpl.hpp.

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

◆ m_boundaryHost

template<typename ExecSpace , typename TData >
std::vector<BlockBoundaryHost> Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_boundaryHost
protected

The boundary points of each block, indexed by block, as they are gathered at configuration.

Definition at line 144 of file AeroForcesOpImpl.hpp.

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

◆ m_dimension

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

◆ m_gradientDirections

template<typename ExecSpace , typename TData >
unsigned int Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_gradientDirections = 0
protected

Number of directions of each velocity component in the gradient.

Definition at line 155 of file AeroForcesOpImpl.hpp.

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

◆ m_implInterleaveWidth

template<typename ExecSpace , typename TData >
constexpr unsigned int Nektar::detail::AeroForcesOpImpl< 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 138 of file AeroForcesOpImpl.hpp.

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

◆ m_mu

template<typename ExecSpace , typename TData >
TData Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_mu = TData(1)
protected

◆ m_numPlanes

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

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

Definition at line 153 of file AeroForcesOpImpl.hpp.

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

◆ m_planeWeight

template<typename ExecSpace , typename TData >
TData Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_planeWeight = TData(1)
protected

Weight of each plane in the average over the planes.

Definition at line 157 of file AeroForcesOpImpl.hpp.

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

◆ m_pressureComponent

template<typename ExecSpace , typename TData >
unsigned int Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_pressureComponent = 0
protected

◆ m_pressureExpansion

template<typename ExecSpace , typename TData >
MultiRegions::ExpListSharedPtr Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_pressureExpansion
protected

◆ m_rho

template<typename ExecSpace , typename TData >
TData Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::m_rho = TData(1)
protected

◆ m_velocityComponents

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