7#ifndef ACASURFACEDATACOLLECTOR_H_
8#define ACASURFACEDATACOLLECTOR_H_
33#define ACACOLLECTOR_SANITY_CHECKS_ACCESSORS
37#if defined(ACACOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
38#define ENSURE_VALID_ID_ACCESSOR(id) \
40 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
42#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
44 MAIA_CONTAINER_ENSURE( \
45 id >= 0 && id < noVars(), \
46 "variable id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noVars()) + ")", AT_); \
48#define ENSURE_VALID_SAMPLE_ID_ACCESSOR(id) \
50 MAIA_CONTAINER_ENSURE( \
51 id >= 0 && id < noSamples(), \
52 "sample id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noSamples()) + ")", AT_); \
54#define ENSURE_VALID_DIR_ID_ACCESSOR(id) \
56 MAIA_CONTAINER_ENSURE(id >= 0 && id < nDim, \
57 "direction id = " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(nDim) + ")", \
60#define ENSURE_CONDITION(condition, message) \
62 MAIA_CONTAINER_ENSURE(condition, message, AT_); \
65#define ENSURE_VALID_ID_ACCESSOR(id) \
68#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
71#define ENSURE_VALID_SAMPLE_ID_ACCESSOR(id) \
74#define ENSURE_VALID_DIR_ID_ACCESSOR(id) \
77#define ENSURE_CONDITION(condition, message) \
85namespace acoustic_analogy {
95 static constexpr MInt value() {
return std::numeric_limits<MInt>::min(); }
101 static constexpr MLong value() {
return std::numeric_limits<MLong>::min(); }
108#ifdef MAIA_PGI_COMPILER
109 return std::numeric_limits<MFloat>::quiet_NaN();
111 return std::numeric_limits<MFloat>::signaling_NaN();
173 ENSURE_CONDITION(noVars_ > 0 && noVars_ <=
s_maxNoVars,
"Invalid number of variables.");
182 "Invalid number of complex variables.");
190 ENSURE_CONDITION(noSamples_ > 0 && noSamples_ <=
s_maxNoSamples,
"Invalid number of samples.");
199 template <
class Functor,
class T>
233 const MInt varSize = noVars() * noSamples();
234 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
236 resetStorage(nDim, m_surfaceCoordinates);
237 resetStorage(1, m_surfaceArea);
238 resetStorage(nDim, m_surfaceNormal);
239 resetStorage(varSize, m_variables);
240 resetStorage(complexVarSize, m_complexVariables);
246 const MInt varSize = noVars() * noSamples();
247 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
249 resizeStorage(nDim, m_surfaceCoordinates);
250 resizeStorage(1, m_surfaceArea);
251 resizeStorage(nDim, m_surfaceNormal);
252 resizeStorage(varSize, m_variables);
253 resizeStorage(complexVarSize, m_complexVariables);
261#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
262#error Missing implementation for structure-of-arrays memory layout.
264 ENSURE_VALID_ID_ACCESSOR(
id);
265 return m_surfaceCoordinates[
id * nDim];
271#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
272#error Missing implementation for structure-of-arrays memory layout.
274 ENSURE_VALID_ID_ACCESSOR(
id);
275 return m_surfaceCoordinates[
id * nDim];
283#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
284#error Missing implementation for structure-of-arrays memory layout.
286 ENSURE_VALID_ID_ACCESSOR(
id);
287 return m_surfaceArea[
id];
293#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
294#error Missing implementation for structure-of-arrays memory layout.
296 ENSURE_VALID_ID_ACCESSOR(
id);
297 return m_surfaceCoordinates[
id];
305#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
306#error Missing implementation for structure-of-arrays memory layout.
308 ENSURE_VALID_ID_ACCESSOR(
id);
309 return m_surfaceNormal[
id * nDim];
315#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
316#error Missing implementation for structure-of-arrays memory layout.
318 ENSURE_VALID_ID_ACCESSOR(
id);
319 return m_surfaceNormal[
id * nDim];
327#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
328#error Missing implementation for structure-of-arrays memory layout.
330 ENSURE_VALID_ID_ACCESSOR(
id);
331 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
332 return m_variables[
id * noVars() * noSamples() + var * noSamples()];
342#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
343#error Missing implementation for structure-of-arrays memory layout.
345 ENSURE_VALID_ID_ACCESSOR(
id);
346 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
347 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
348 return m_variables[
id * noVars() * noSamples() + var * noSamples() + sample];
354#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
355#error Missing implementation for structure-of-arrays memory layout.
357 ENSURE_VALID_ID_ACCESSOR(
id);
358 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
359 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
360 return m_variables[
id * noVars() * noSamples() + var * noSamples() + sample];
368#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
369#error Missing implementation for structure-of-arrays memory layout.
371 ENSURE_VALID_ID_ACCESSOR(
id);
372 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
373 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples()];
382 const MInt component) {
384#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
385#error Missing implementation for structure-of-arrays memory layout.
387 ENSURE_VALID_ID_ACCESSOR(
id);
388 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
389 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
390 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples() + 2 * sample + component];
395 const MInt component)
const {
397#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
398#error Missing implementation for structure-of-arrays memory layout.
400 ENSURE_VALID_ID_ACCESSOR(
id);
401 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
402 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
403 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples() + 2 * sample + component];
411#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
412#error Missing implementation for structure-of-arrays memory layout.
415 const MInt varSize = noVars() * noSamples();
416 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
419 fill_invalid(m_surfaceCoordinates, begin, end, nDim);
422 fill_invalid(m_surfaceArea, begin, end);
425 fill_invalid(m_surfaceNormal, begin, end, nDim);
428 fill_invalid(m_variables, begin, end, varSize);
431 fill_invalid(m_complexVariables, begin, end, complexVarSize);
437template <
class Functor,
class T>
439 const MInt destination) {
441#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
442#error Missing implementation for structure-of-arrays memory layout.
445 const MInt varSize = noVars() * noSamples();
446 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
449 copyData(source.m_surfaceCoordinates, m_surfaceCoordinates, c, begin, end, destination, nDim);
452 copyData(source.m_surfaceArea, m_surfaceArea, c, begin, end, destination);
455 copyData(source.m_surfaceNormal, m_surfaceNormal, c, begin, end, destination, nDim);
458 copyData(source.m_variables, m_variables, c, begin, end, destination, varSize);
461 copyData(source.m_complexVariables, m_complexVariables, c, begin, end, destination, complexVarSize);
471#undef ACACOLLECTOR_SANITY_CHECKS_ACCESSORS
472#undef ENSURE_VALID_ID_ACCESSOR
473#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
474#undef ENSURE_VALID_SAMPLE_ID_ACCESSOR
475#undef ENSURE_VALID_DIR_ID_ACCESSOR
476#undef ENSURE_CONDITION
Class that represents DG element collector.
MFloat & variables(const MInt id, const MInt var)
Accessor for variables.
MFloat & complexVariables(const MInt id)
Storage< MFloat > m_surfaceNormal
typename Base::template Storage< T > Storage
Storage< MFloat > m_surfaceArea
MInt noVars()
Return number of variables.
void rawCopyGeneric(Functor &&c, const T &source, const MInt begin, const MInt end, const MInt destination)
Helper function for rawCopy(). Destination may refer to beginning or end of target range.
MFloat & surfaceArea(const MInt id)
Accessor for surface area (or segment length in 2D).
MFloat & complexVariables(const MInt id, const MInt var)
Accessor for complex variables.
MFloat & surfaceCoordinates(const MInt id)
Accessor for surface element coordinates.
void setNoVars(const MInt noVars_)
Set number of variables.
void reset()
Reset, re-create data structures with given capacity, and set size to zero.
MInt noSamples()
Return number of samples (i.e. number of time steps)
Storage< MFloat > m_complexVariables
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
void setNoComplexVars(const MInt noComplexVars_)
Set number of complex variables.
constexpr SurfaceDataCollector()=default
Default c'tor does nothing.
void resize() override
Resize data strucutres reusing values from previous state.
static constexpr MInt s_maxNoSamples
Maximum number of samples.
Storage< MFloat > m_variables
MFloat & variables(const MInt id)
Storage< MFloat > m_surfaceCoordinates
void setNoSamples(const MInt noSamples_)
Set number of samples.
MFloat & surfaceNormal(const MInt id)
Accessor for surface normal.
static constexpr MInt s_maxNoComplexVars
Maximum number of complex variables (in the frequency domain)
MInt noComplexVars()
Return number of complex variables.
static constexpr MInt s_maxNoVars
Maximum number of variables (in the time domain)
typename maia::acoustic_analogy::collector::Invalid< T > Invalid
void copyData(const Container_ &source, Container_ &target, Functor &&f, const MInt begin, const MInt end, const MInt dest, const MInt solverSize=1)
Copy [begin, end) range with given solver size from source to dest position of target.
void fill_invalid(Container_ &c, const MInt begin, const MInt end, const MInt solverSize=1, const T value=Invalid< T >::value())
void resetStorage(const MInt n, Storage< T > &c)
Create new container with given size and replace original one.
void resizeStorage(const MInt n, Storage< T > &c)
Resize container with given size.
void reset(const MInt capacity)
Reset tree, re-create data structures with given capacity, and set size to zero.
Namespace for auxiliary functions/classes.
static constexpr MInt value()
static constexpr MLong value()