7#ifndef ACAOBSERVERDATACOLLECTOR_H_
8#define ACAOBSERVERDATACOLLECTOR_H_
34#define ACACOLLECTOR_SANITY_CHECKS_ACCESSORS
38#if defined(ACACOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
39#define ENSURE_VALID_ID_ACCESSOR(id) \
41 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
43#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
45 MAIA_CONTAINER_ENSURE( \
46 id >= 0 && id < noVars(), \
47 "variable id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noVars()) + ")", AT_); \
49#define ENSURE_VALID_SAMPLE_ID_ACCESSOR(id) \
51 MAIA_CONTAINER_ENSURE( \
52 id >= 0 && id < noSamples(), \
53 "sample id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noSamples()) + ")", AT_); \
55#define ENSURE_CONDITION(condition, message) \
57 MAIA_CONTAINER_ENSURE(condition, message, AT_); \
60#define ENSURE_VALID_ID_ACCESSOR(id) \
63#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
66#define ENSURE_VALID_SAMPLE_ID_ACCESSOR(id) \
69#define ENSURE_CONDITION(condition, message) \
77namespace acoustic_analogy {
78namespace observer_collector {
87 static constexpr MInt value() {
return std::numeric_limits<MInt>::min(); }
93 static constexpr MLong value() {
return std::numeric_limits<MLong>::min(); }
100#ifdef MAIA_PGI_COMPILER
101 return std::numeric_limits<MFloat>::quiet_NaN();
103 return std::numeric_limits<MFloat>::signaling_NaN();
158 ENSURE_CONDITION(noVars_ > 0 && noVars_ <=
s_maxNoVars,
"Invalid number of variables.");
167 "Invalid number of complex variables.");
175 ENSURE_CONDITION(noSamples_ > 0 && noSamples_ <=
s_maxNoSamples,
"Invalid number of samples.");
183 template <
class Functor,
class T>
218 const MInt varSize = noVars() * noSamples();
219 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
221 resetStorage(nDim, m_observerCoordinates);
222 resetStorage(varSize, m_variables);
223 resetStorage(complexVarSize, m_complexVariables);
231#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
232#error Missing implementation for structure-of-arrays memory layout.
234 ENSURE_VALID_ID_ACCESSOR(
id);
235 return m_observerCoordinates[
id * nDim];
241#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
242#error Missing implementation for structure-of-arrays memory layout.
244 ENSURE_VALID_ID_ACCESSOR(
id);
245 return m_observerCoordinates[
id * nDim];
251#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
252#error Missing implementation for structure-of-arrays memory layout.
254 ENSURE_VALID_ID_ACCESSOR(
id);
255 return m_observerCoordinates[
id * nDim + component];
263#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
264#error Missing implementation for structure-of-arrays memory layout.
266 ENSURE_VALID_ID_ACCESSOR(
id);
267 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
268 return m_variables[
id * noVars() * noSamples() + var * noSamples()];
278#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
279#error Missing implementation for structure-of-arrays memory layout.
281 ENSURE_VALID_ID_ACCESSOR(
id);
282 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
283 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
284 return m_variables[
id * noVars() * noSamples() + var * noSamples() + sample];
290#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
291#error Missing implementation for structure-of-arrays memory layout.
293 ENSURE_VALID_ID_ACCESSOR(
id);
294 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
295 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
296 return m_variables[
id * noVars() * noSamples() + var * noSamples() + sample];
304#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
305#error Missing implementation for structure-of-arrays memory layout.
307 ENSURE_VALID_ID_ACCESSOR(
id);
308 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
309 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples()];
318 const MInt component) {
320#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
321#error Missing implementation for structure-of-arrays memory layout.
323 ENSURE_VALID_ID_ACCESSOR(
id);
324 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
325 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
326 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples() + 2 * sample + component];
331 const MInt component)
const {
333#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
334#error Missing implementation for structure-of-arrays memory layout.
336 ENSURE_VALID_ID_ACCESSOR(
id);
337 ENSURE_VALID_VARIABLE_ID_ACCESSOR(var);
338 ENSURE_VALID_SAMPLE_ID_ACCESSOR(sample);
339 return m_complexVariables[
id * 2 * noComplexVars() * noSamples() + var * 2 * noSamples() + 2 * sample + component];
347#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
348#error Missing implementation for structure-of-arrays memory layout.
351 const MInt varSize = noVars() * noSamples();
352 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
355 fill_invalid(m_observerCoordinates, begin, end, nDim);
358 fill_invalid(m_variables, begin, end, varSize);
361 fill_invalid(m_complexVariables, begin, end, complexVarSize);
367template <
class Functor,
class T>
369 const MInt destination) {
371#ifdef ACACOLLECTOR_SOA_MEMORY_LAYOUT
372#error Missing implementation for structure-of-arrays memory layout.
375 const MInt varSize = noVars() * noSamples();
376 const MInt complexVarSize = 2 * noComplexVars() * noSamples();
379 copyData(source.m_observerCoordinates, m_observerCoordinates, c, begin, end, destination, nDim);
382 copyData(source.m_variables, m_variables, c, begin, end, destination, varSize);
385 copyData(source.m_complexVariables, m_complexVariables, c, begin, end, destination, complexVarSize);
395#undef ACACOLLECTOR_SANITY_CHECKS_ACCESSORS
396#undef ENSURE_VALID_ID_ACCESSOR
397#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
398#undef ENSURE_VALID_SAMPLE_ID_ACCESSOR
399#undef ENSURE_CONDITION
Class that represents DG element collector.
Storage< MFloat > m_complexVariables
Storage< MFloat > m_observerCoordinates
MInt noVars()
Return number of variables.
static constexpr MInt s_maxNoVars
Maximum number of variables (in the time domain)
MFloat & complexVariables(const MInt id, const MInt var)
Accessor for complex variables.
static constexpr MInt s_maxNoSamples
Maximum number of samples.
MInt noComplexVars()
Return number of complex variables.
typename maia::acoustic_analogy::observer_collector::Invalid< T > Invalid
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.
void setNoComplexVars(const MInt noComplexVars_)
Set number of complex variables.
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
Storage< MFloat > m_variables
void setNoVars(const MInt noVars_)
Set number of variables.
MInt noSamples()
Return number of samples (i.e. number of time steps)
MFloat & variables(const MInt id, const MInt var)
Accessor for variables (return a reference to the start of the given variable in memory).
MFloat & variables(const MInt id)
constexpr ObserverDataCollector()=default
Default c'tor does nothing.
void reset()
Reset, re-create data structures with given capacity, and set size to zero.
typename Base::template Storage< T > Storage
static constexpr MInt s_maxNoComplexVars
Maximum number of complex variables (in the frequency domain)
MFloat & complexVariables(const MInt id)
void setNoSamples(const MInt noSamples_)
Set number of samples.
MFloat & observerCoordinates(const MInt id)
Accessor for surface element coordinates.
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 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()