7#ifndef DGELEMENTCOLLECTOR_H_
8#define DGELEMENTCOLLECTOR_H_
30#ifdef MAIA_EXTRA_DEBUG
31#define DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
35#if defined(DGCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
36#define ENSURE_VALID_ID_ACCESSOR(id) \
38 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
40#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
42 MAIA_CONTAINER_ENSURE( \
43 id >= 0 && id < noVars(), \
44 "variable id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noVars()) + ")", AT_); \
46#define ENSURE_VALID_NODE_VARIABLE_ID_ACCESSOR(id) \
48 MAIA_CONTAINER_ENSURE( \
49 id >= 0 && id < noNodeVars(), \
50 "node variable id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noNodeVars()) + ")", AT_); \
52#define ENSURE_VALID_SURFACE_ID_ACCESSOR(id) \
54 MAIA_CONTAINER_ENSURE(id >= 0 && id < noSurfaces(), \
55 "surface id " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noSurfaces()), \
58#define ENSURE_CONDITION(condition, message) \
60 MAIA_CONTAINER_ENSURE(condition, message, AT_); \
63#define ENSURE_VALID_ID_ACCESSOR(id) \
66#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
69#define ENSURE_VALID_NODE_VARIABLE_ID_ACCESSOR(id) \
72#define ENSURE_VALID_SURFACE_ID_ACCESSOR(id) \
75#define ENSURE_CONDITION(condition, message) \
93 static constexpr MInt value() {
return std::numeric_limits<MInt>::min(); }
99 static constexpr MLong value() {
return std::numeric_limits<MLong>::min(); }
106#ifdef MAIA_PGI_COMPILER
107 return std::numeric_limits<MFloat>::quiet_NaN();
109 return std::numeric_limits<MFloat>::signaling_NaN();
116template <MInt nDim,
class SysEqn>
206 template <
class Functor,
class T>
237template <MInt nDim,
class SysEqn>
239 resetStorage(1, m_cellId);
240 resetStorage(1, m_polyDeg);
241 resetStorage(1, m_noNodes1D);
242 resetStorage(noSurfaces(), m_surfaceIds);
243 resetStorage(maxNoNodesXD() * nDim, m_nodeCoordinates);
244 resetStorage(maxNoNodesXD() * noVars(), m_variables);
245 resetStorage(maxNoNodesXD() * noVars(), m_timeIntStorage);
246 resetStorage(maxNoNodesXD() * noNodeVars(), m_nodeVariables);
247 resetStorage(maxNoNodesXD() * noVars(), m_rightHandSide);
248 resetStorage(maxNoNodesXD() * noVars(), m_externalSource);
249 resetStorage(1, m_invJacobian);
254template <MInt nDim,
class SysEqn>
257#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
258#error Missing implementation for structure-of-arrays memory layout.
260 ENSURE_VALID_ID_ACCESSOR(
id);
264template <MInt nDim,
class SysEqn>
267#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
268#error Missing implementation for structure-of-arrays memory layout.
270 ENSURE_VALID_ID_ACCESSOR(
id);
276template <MInt nDim,
class SysEqn>
279#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
280#error Missing implementation for structure-of-arrays memory layout.
282 ENSURE_VALID_ID_ACCESSOR(
id);
283 return m_polyDeg[
id];
286template <MInt nDim,
class SysEqn>
289#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
290#error Missing implementation for structure-of-arrays memory layout.
292 ENSURE_VALID_ID_ACCESSOR(
id);
293 return m_polyDeg[
id];
297template <MInt nDim,
class SysEqn>
300#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
301#error Missing implementation for structure-of-arrays memory layout.
303 ENSURE_VALID_ID_ACCESSOR(
id);
304 return m_noNodes1D[
id];
308template <MInt nDim,
class SysEqn>
311#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
312#error Missing implementation for structure-of-arrays memory layout.
314 ENSURE_VALID_ID_ACCESSOR(
id);
315 return m_noNodes1D[
id];
319template <MInt nDim,
class SysEqn>
322#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
323#error Missing implementation for structure-of-arrays memory layout.
325 ENSURE_VALID_ID_ACCESSOR(
id);
326 return ipow(m_noNodes1D[
id], nDim);
330template <MInt nDim,
class SysEqn>
333#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
334#error Missing implementation for structure-of-arrays memory layout.
336 ENSURE_VALID_ID_ACCESSOR(
id);
337 ENSURE_VALID_SURFACE_ID_ACCESSOR(dir);
338 return m_surfaceIds[
id * noSurfaces() + dir];
341template <MInt nDim,
class SysEqn>
344#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
345#error Missing implementation for structure-of-arrays memory layout.
347 ENSURE_VALID_ID_ACCESSOR(
id);
348 ENSURE_VALID_SURFACE_ID_ACCESSOR(dir);
349 return m_surfaceIds[
id * noSurfaces() + dir];
354template <MInt nDim,
class SysEqn>
357#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
358#error Missing implementation for structure-of-arrays memory layout.
360 ENSURE_VALID_ID_ACCESSOR(
id);
361 return m_nodeCoordinates[
id * nDim * maxNoNodesXD()];
364template <MInt nDim,
class SysEqn>
367#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
368#error Missing implementation for structure-of-arrays memory layout.
370 ENSURE_VALID_ID_ACCESSOR(
id);
371 return m_nodeCoordinates[
id * nDim * maxNoNodesXD()];
376template <MInt nDim,
class SysEqn>
379#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
380#error Missing implementation for structure-of-arrays memory layout.
382 ENSURE_VALID_ID_ACCESSOR(
id);
383 ENSURE_CONDITION(pos >= 0 && pos < noVars() * maxNoNodesXD(),
"Invalid position.");
384 return m_variables[
id * noVars() * maxNoNodesXD() + pos];
387template <MInt nDim,
class SysEqn>
390#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
391#error Missing implementation for structure-of-arrays memory layout.
393 ENSURE_VALID_ID_ACCESSOR(
id);
394 ENSURE_CONDITION(pos >= 0 && pos < noVars() * maxNoNodesXD(),
"Invalid position.");
395 return m_variables[
id * noVars() * maxNoNodesXD() + pos];
400template <MInt nDim,
class SysEqn>
403#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
404#error Missing implementation for structure-of-arrays memory layout.
406 ENSURE_VALID_ID_ACCESSOR(
id);
407 return m_timeIntStorage[
id * noVars() * maxNoNodesXD()];
410template <MInt nDim,
class SysEqn>
413#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
414#error Missing implementation for structure-of-arrays memory layout.
416 ENSURE_VALID_ID_ACCESSOR(
id);
417 return m_timeIntStorage[
id * noVars() * maxNoNodesXD()];
422template <MInt nDim,
class SysEqn>
425#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
426#error Missing implementation for structure-of-arrays memory layout.
428 ENSURE_VALID_ID_ACCESSOR(
id);
429 return m_nodeVariables[
id * noNodeVars() * maxNoNodesXD()];
432template <MInt nDim,
class SysEqn>
435#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
436#error Missing implementation for structure-of-arrays memory layout.
438 ENSURE_VALID_ID_ACCESSOR(
id);
439 return m_nodeVariables[
id * noNodeVars() * maxNoNodesXD()];
444template <MInt nDim,
class SysEqn>
447#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
448#error Missing implementation for structure-of-arrays memory layout.
450 ENSURE_VALID_ID_ACCESSOR(
id);
451 return m_rightHandSide[
id * noVars() * maxNoNodesXD()];
454template <MInt nDim,
class SysEqn>
457#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
458#error Missing implementation for structure-of-arrays memory layout.
460 ENSURE_VALID_ID_ACCESSOR(
id);
461 return m_rightHandSide[
id * noVars() * maxNoNodesXD()];
466template <MInt nDim,
class SysEqn>
469#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
470#error Missing implementation for structure-of-arrays memory layout.
472 ENSURE_VALID_ID_ACCESSOR(
id);
473 return m_externalSource[
id * noVars() * maxNoNodesXD()];
476template <MInt nDim,
class SysEqn>
479#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
480#error Missing implementation for structure-of-arrays memory layout.
482 ENSURE_VALID_ID_ACCESSOR(
id);
483 return m_externalSource[
id * noVars() * maxNoNodesXD()];
488template <MInt nDim,
class SysEqn>
491#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
492#error Missing implementation for structure-of-arrays memory layout.
494 ENSURE_VALID_ID_ACCESSOR(
id);
495 return m_invJacobian[
id];
498template <MInt nDim,
class SysEqn>
501#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
502#error Missing implementation for structure-of-arrays memory layout.
504 ENSURE_VALID_ID_ACCESSOR(
id);
505 return m_invJacobian[
id];
510template <MInt nDim,
class SysEqn>
513#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
514#error Missing implementation for structure-of-arrays memory layout.
517 const MInt coordSize = nDim * maxNoNodesXD();
518 const MInt varSize = maxNoNodesXD() * noVars();
519 const MInt nodeVarSize = maxNoNodesXD() * noNodeVars();
522 fill_invalid(m_cellId, begin, end);
525 fill_invalid(m_polyDeg, begin, end);
528 fill_invalid(m_noNodes1D, begin, end);
531 fill_invalid(m_surfaceIds, begin, end, noSurfaces());
534 fill_invalid(m_nodeCoordinates, begin, end, coordSize);
537 fill_invalid(m_variables, begin, end, varSize);
540 fill_invalid(m_timeIntStorage, begin, end, varSize);
543 fill_invalid(m_nodeVariables, begin, end, nodeVarSize);
546 fill_invalid(m_rightHandSide, begin, end, varSize);
549 fill_invalid(m_externalSource, begin, end, varSize);
552 fill_invalid(m_invJacobian, begin, end);
557template <MInt nDim,
class SysEqn>
558template <
class Functor,
class T>
560 const MInt destination) {
562#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
563#error Missing implementation for structure-of-arrays memory layout.
566 const MInt varSize = maxNoNodesXD() * noVars();
569 copyData(source.m_cellId, m_cellId, c, begin, end, destination);
572 copyData(source.m_polyDeg, m_polyDeg, c, begin, end, destination);
575 copyData(source.m_noNodes1D, m_noNodes1D, c, begin, end, destination);
578 copyData(source.m_surfaceIds, m_surfaceIds, c, begin, end, destination, noSurfaces());
581 copyData(source.m_nodeCoordinates, m_nodeCoordinates, c, begin, end, destination, nDim * maxNoNodesXD());
584 copyData(source.m_variables, m_variables, c, begin, end, destination, varSize);
587 copyData(source.m_timeIntStorage, m_timeIntStorage, c, begin, end, destination, varSize);
590 copyData(source.m_nodeVariables, m_nodeVariables, c, begin, end, destination, maxNoNodesXD() * noNodeVars());
593 copyData(source.m_rightHandSide, m_rightHandSide, c, begin, end, destination, varSize);
596 copyData(source.m_externalSource, m_externalSource, c, begin, end, destination, varSize);
599 copyData(source.m_invJacobian, m_invJacobian, c, begin, end, destination);
604template <MInt nDim,
class SysEqn>
606 const MInt oldMaxPolyDeg = m_maxPolyDeg;
607 m_maxPolyDeg = maxPolyDeg_;
608 return oldMaxPolyDeg;
612template <MInt nDim,
class SysEqn>
614 m_maxNoNodes1D = maxNoNodes1D_;
615 m_maxNoNodesXD =
ipow(m_maxNoNodes1D, nDim);
627template <MInt nDim,
class SysEqn>
629 return getElementByCellId(0, this->size(), cellId);
643template <MInt nDim,
class SysEqn>
645 const MInt*
const begin = &m_cellId[0];
646 const MInt*
const end = begin + (last - first);
647 const MInt*
const low = std::lower_bound(begin, end, cellId);
650 if(low == begin && *low != cellId) {
666 return first + std::distance(begin, low);
675#undef DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
676#undef ENSURE_VALID_ID_ACCESSOR
677#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
678#undef ENSURE_VALID_NODE_VARIABLE_ID_ACCESSOR
679#undef ENSURE_VALID_SURFACE_ID_ACCESSOR
680#undef ENSURE_CONDITION
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.
Class that represents DG element collector.
MFloat & externalSource(const MInt id)
Accessor for external source terms.
static constexpr MInt noVars()
Return number of nodes in 1D.
MInt & polyDeg(const MInt id)
Accessor for polynomial degree.
typename maia::dg::collector::Invalid< T > Invalid
Storage< MInt > m_surfaceIds
typename Base::template Storage< T > Storage
MInt noNodesXD(const MInt id) const
Accessor for number of nodes XD (const version).
constexpr MInt noNodeVars() const
Return number of node variables.
MFloat & nodeCoordinates(const MInt id)
Accessor for node coordinates.
MFloat & invJacobian(const MInt id)
Accessor for inverse jacobian.
MInt m_maxPolyDeg
Maximum polynomial degree.
MInt & cellId(const MInt id)
Accessor for cell id.
Storage< MFloat > m_externalSource
MInt maxNoNodesXD() const
Return maximum number of nodes XD.
Storage< MFloat > m_timeIntStorage
Storage< MFloat > m_nodeVariables
MFloat variables(const MInt id) const
MInt m_maxNoNodes1D
Maximum number of nodes 1D.
MInt & surfaceIds(const MInt id, const MInt dir)
Accessor for surface ids.
MInt m_maxNoNodesXD
Maximum number if nodes XD.
MInt maxNoNodes1D() const
Return maximum number of nodes 1D.
Storage< MInt > m_polyDeg
Storage< MFloat > m_nodeCoordinates
void noNodeVars(const MInt noNodeVars_)
MFloat & nodeVars(const MInt id)
Accessor for node variables.
MFloat & variables(const MInt id, const MInt pos)
Accessor for variables.
Storage< MInt > m_noNodes1D
Storage< MFloat > m_invJacobian
MInt getElementByCellId(const MInt cellId) const
Return element id for a given cell id (or -1 if not found).
MFloat & timeIntStorage(const MInt id)
Accessor for storage variables.
MFloat & variables(const MInt id)
MFloat & rightHandSide(const MInt id)
Accessor for right hand side.
Storage< MFloat > m_rightHandSide
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
MInt maxPolyDeg() const
Return maximum polynomial degree.
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.
static constexpr MInt noSurfaces()
Return number of surfaces per element.
void reset()
Reset tree, re-create data structures with given capacity, and set size to zero.
MInt noNodes1D(const MInt id) const
Accessor for number of nodes 1D (const version).
constexpr ElementCollector()=default
Default c'tor does nothing.
Storage< MFloat > m_variables
MInt ipow(MInt base, MInt exp)
Integer exponent function for non-negative exponents.
Namespace for auxiliary functions/classes.
static constexpr MInt value()
static constexpr MLong value()