7#ifndef MAIA_DGSURFACECOLLECTOR_H
8#define MAIA_DGSURFACECOLLECTOR_H
20#ifdef MAIA_EXTRA_DEBUG
21#define DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
25#if defined(DGCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
26#define ENSURE_VALID_ID_ACCESSOR(id) \
28 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
30#define ENSURE_VALID_SIDE_ACCESSOR(side) \
32 MAIA_CONTAINER_ENSURE(side >= 0 && side < 2, "side " + std::to_string(side) + " out-of-bounds [0, 2)", AT_); \
34#define ENSURE_VALID_DIR_ACCESSOR(orientation) \
36 MAIA_CONTAINER_ENSURE( \
37 orientation >= 0 && orientation < nDim, \
38 "orientation " + std::to_string(orientation) + " out-of-bounds [0, " + std::to_string(nDim) + ")", AT_); \
41#define ENSURE_VALID_ID_ACCESSOR(id) \
44#define ENSURE_VALID_SIDE_ACCESSOR(side) \
47#define ENSURE_VALID_DIR_ACCESSOR(orientation) \
58template <MInt nDim,
class SysEqn>
146 template <
class Functor,
class T>
189template <MInt nDim,
class SysEqn>
192#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
193#error Missing implementation for structure-of-arrays memory layout.
195 ENSURE_VALID_ID_ACCESSOR(srfcId);
196 return m_orientation[srfcId];
199template <MInt nDim,
class SysEqn>
202#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
203#error Missing implementation for structure-of-arrays memory layout.
205 ENSURE_VALID_ID_ACCESSOR(srfcId);
206 return m_orientation[srfcId];
211template <MInt nDim,
class SysEqn>
214#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
215#error Missing implementation for structure-of-arrays memory layout.
217 ENSURE_VALID_ID_ACCESSOR(srfcId);
218 return m_fineCellId[srfcId];
221template <MInt nDim,
class SysEqn>
224#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
225#error Missing implementation for structure-of-arrays memory layout.
227 ENSURE_VALID_ID_ACCESSOR(srfcId);
228 return m_fineCellId[srfcId];
233template <MInt nDim,
class SysEqn>
236#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
237#error Missing implementation for structure-of-arrays memory layout.
239 ENSURE_VALID_ID_ACCESSOR(srfcId);
240 return m_internalSideId[srfcId];
243template <MInt nDim,
class SysEqn>
246#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
247#error Missing implementation for structure-of-arrays memory layout.
249 ENSURE_VALID_ID_ACCESSOR(srfcId);
250 return m_internalSideId[srfcId];
255template <MInt nDim,
class SysEqn>
258#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
259#error Missing implementation for structure-of-arrays memory layout.
261 ENSURE_VALID_ID_ACCESSOR(srfcId);
262 return m_polyDeg[srfcId];
265template <MInt nDim,
class SysEqn>
268#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
269#error Missing implementation for structure-of-arrays memory layout.
271 ENSURE_VALID_ID_ACCESSOR(srfcId);
272 return m_polyDeg[srfcId];
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(srfcId);
283 return m_noNodes1D[srfcId];
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(srfcId);
293 return m_noNodes1D[srfcId];
296template <MInt nDim,
class SysEqn>
299#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
300#error Missing implementation for structure-of-arrays memory layout.
302 ENSURE_VALID_ID_ACCESSOR(srfcId);
303 return ipow(m_noNodes1D[srfcId], nDim - 1);
307template <MInt nDim,
class SysEqn>
310#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
311#error Missing implementation for structure-of-arrays memory layout.
313 ENSURE_VALID_ID_ACCESSOR(srfcId);
314 return m_globalId[srfcId];
317template <MInt nDim,
class SysEqn>
320#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
321#error Missing implementation for structure-of-arrays memory layout.
323 ENSURE_VALID_ID_ACCESSOR(srfcId);
324 return m_globalId[srfcId];
329template <MInt nDim,
class SysEqn>
332#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
333#error Missing implementation for structure-of-arrays memory layout.
335 ENSURE_VALID_ID_ACCESSOR(srfcId);
336 ENSURE_VALID_DIR_ACCESSOR(dir);
337 return m_coordinates[srfcId * nDim + dir];
340template <MInt nDim,
class SysEqn>
343#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
344#error Missing implementation for structure-of-arrays memory layout.
346 ENSURE_VALID_ID_ACCESSOR(srfcId);
347 ENSURE_VALID_DIR_ACCESSOR(dir);
348 return m_coordinates[srfcId * nDim + dir];
353template <MInt nDim,
class SysEqn>
356#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
357#error Missing implementation for structure-of-arrays memory layout.
359 ENSURE_VALID_ID_ACCESSOR(srfcId);
360 return m_nodeCoordinates[srfcId * noValuesNodeCoordinates()];
363template <MInt nDim,
class SysEqn>
366#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
367#error Missing implementation for structure-of-arrays memory layout.
369 ENSURE_VALID_ID_ACCESSOR(srfcId);
370 return m_nodeCoordinates[srfcId * noValuesNodeCoordinates()];
375template <MInt nDim,
class SysEqn>
378#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
379#error Missing implementation for structure-of-arrays memory layout.
381 ENSURE_VALID_ID_ACCESSOR(srfcId);
382 return m_flux[srfcId * noValuesFlux()];
385template <MInt nDim,
class SysEqn>
388#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
389#error Missing implementation for structure-of-arrays memory layout.
391 ENSURE_VALID_ID_ACCESSOR(srfcId);
392 return m_flux[srfcId * noValuesFlux()];
397template <MInt nDim,
class SysEqn>
400#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
401#error Missing implementation for structure-of-arrays memory layout.
403 ENSURE_VALID_ID_ACCESSOR(srfcId);
404 ENSURE_VALID_SIDE_ACCESSOR(side);
405 return m_nghbrElementIds[2 * srfcId + side];
408template <MInt nDim,
class SysEqn>
411#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
412#error Missing implementation for structure-of-arrays memory layout.
414 ENSURE_VALID_ID_ACCESSOR(srfcId);
415 ENSURE_VALID_SIDE_ACCESSOR(side);
416 return m_nghbrElementIds[2 * srfcId + side];
421template <MInt nDim,
class SysEqn>
424#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
425#error Missing implementation for structure-of-arrays memory layout.
427 ENSURE_VALID_ID_ACCESSOR(srfcId);
428 ENSURE_VALID_SIDE_ACCESSOR(side);
429 return m_variables[2 * noValuesVariables() * srfcId + side * noValuesVariables()];
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(srfcId);
439 ENSURE_VALID_SIDE_ACCESSOR(side);
440 return m_variables[2 * noValuesVariables() * srfcId + side * noValuesVariables()];
445template <MInt nDim,
class SysEqn>
448#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
449#error Missing implementation for structure-of-arrays memory layout.
451 ENSURE_VALID_ID_ACCESSOR(srfcId);
452 ENSURE_VALID_SIDE_ACCESSOR(side);
453 return m_nodeVars[2 * noValuesNodeVars() * srfcId + side * noValuesNodeVars()];
456template <MInt nDim,
class SysEqn>
459#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
460#error Missing implementation for structure-of-arrays memory layout.
462 ENSURE_VALID_ID_ACCESSOR(srfcId);
463 ENSURE_VALID_SIDE_ACCESSOR(side);
464 return m_nodeVars[2 * noValuesNodeVars() * srfcId + side * noValuesNodeVars()];
469template <MInt nDim,
class SysEqn>
471 resetStorage(1, m_orientation);
472 resetStorage(2, m_nghbrElementIds);
473 resetStorage(1, m_fineCellId);
474 resetStorage(1, m_internalSideId);
475 resetStorage(1, m_polyDeg);
476 resetStorage(1, m_noNodes1D);
477 resetStorage(1, m_globalId);
478 resetStorage(2 * noValuesVariables(), m_variables);
479 resetStorage(2 * noValuesNodeVars(), m_nodeVars);
480 resetStorage(nDim, m_coordinates);
481 resetStorage(noValuesNodeCoordinates(), m_nodeCoordinates);
482 resetStorage(noValuesFlux(), m_flux);
487template <MInt nDim,
class SysEqn>
490#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
491#error Missing implementation for structure-of-arrays memory layout.
494 fill_invalid(m_orientation, begin, end);
496 fill_invalid(m_nghbrElementIds, begin, end, 2);
498 fill_invalid(m_fineCellId, begin, end);
500 fill_invalid(m_internalSideId, begin, end);
502 fill_invalid(m_polyDeg, begin, end);
504 fill_invalid(m_noNodes1D, begin, end);
506 fill_invalid(m_globalId, begin, end);
508 fill_invalid(m_variables, begin, end, 2 * noValuesVariables());
510 fill_invalid(m_nodeVars, begin, end, 2 * noValuesNodeVars());
512 fill_invalid(m_coordinates, begin, end, nDim);
514 fill_invalid(m_nodeCoordinates, begin, end, noValuesNodeCoordinates());
516 fill_invalid(m_flux, begin, end, noValuesFlux());
521template <MInt nDim,
class SysEqn>
522template <
class Functor,
class T>
524 const MInt destination) {
526#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
527#error Missing implementation for structure-of-arrays memory layout.
530 copyData(source.m_orientation, m_orientation, c, begin, end, destination);
532 copyData(source.m_nghbrElementIds, m_nghbrElementIds, c, begin, end, destination, 2);
534 copyData(source.m_fineCellId, m_fineCellId, c, begin, end, destination);
536 copyData(source.m_internalSideId, m_internalSideId, c, begin, end, destination);
538 copyData(source.m_polyDeg, m_polyDeg, c, begin, end, destination);
540 copyData(source.m_noNodes1D, m_noNodes1D, c, begin, end, destination);
542 copyData(source.m_globalId, m_globalId, c, begin, end, destination);
544 copyData(source.m_variables, m_variables, c, begin, end, destination, 2 * noValuesVariables());
546 copyData(source.m_nodeVars, m_nodeVars, c, begin, end, destination, 2 * noValuesNodeVars());
548 copyData(source.m_coordinates, m_coordinates, c, begin, end, destination, nDim);
550 copyData(source.m_nodeCoordinates, m_nodeCoordinates, c, begin, end, destination, noValuesNodeCoordinates());
552 copyData(source.m_flux, m_flux, c, begin, end, destination, noValuesFlux());
561#undef DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
562#undef ENSURE_VALID_ID_ACCESSOR
563#undef ENSURE_VALID_SIDE_ACCESSOR
564#undef ENSURE_VALID_DIR_ACCESSOR
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.
Storage< MFloat > m_nodeCoordinates
Integration node coordinates.
MInt & internalSideId(const MInt srfcId)
Accessor for internal side id.
MInt maxNoNodes1D() const
Return maximum number of nodes 1D.
Storage< MFloat > m_nodeVars
Additional variables at each node.
constexpr MInt noValuesNodeCoordinates() const
Storage< MFloat > m_coordinates
Coordinates of the surface center.
typename maia::dg::collector::Invalid< T > Invalid
MInt maxPolyDeg() const
Return maximum polynomial degree.
void maxPolyDeg(const MInt maxPolyDeg_)
void noNodeVars(const MInt noNodeVars_)
Storage< MInt > m_fineCellId
H-refinement fine element id.
Storage< MInt > m_nghbrElementIds
Nghbr. element ids (or -1 of no neighbor)
MInt & noNodes1D(const MInt srfcId)
Accessor for number of nodes 1D.
Storage< MFloat > m_flux
Store the numerical (Riemann) flux.
Storage< MInt > m_noNodes1D
Number of nodes 1D of the neighbors.
constexpr SurfaceCollector()=default
Default c'tor does nothing.
Storage< MInt > m_internalSideId
Side id of the internal element.
MFloat & nodeVars(const MInt srfcId, const MInt side)
Accessor for node variables.
Storage< MInt > m_polyDeg
Polynomial degrees of the neighbors.
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.
MInt & nghbrElementIds(const MInt srfcId, const MInt side)
Accessor for neighbor element ids.
typename Base::template Storage< T > Storage
MInt maxNoNodesXD() const
Return maximum number if nodes XD.
void maxNoNodes1D(const MInt maxNoNodes1D_)
MFloat & flux(const MInt srfcId)
Accessor for flux.
constexpr MInt noNodeVars() const
Return number of node variables.
constexpr MInt noValuesFlux() const
constexpr MInt noValuesVariables() const
MLong & globalId(const MInt srfcId)
Accessor for global id.
MInt & fineCellId(const MInt srfcId)
Accessor for fine cell id.
MInt noNodesXD(const MInt srfcId) const
Accessor for number of nodes XD (const version).
constexpr MInt noValuesNodeVars() const
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
MFloat & nodeCoords(const MInt srfcId)
Accessor for node coordinates.
Storage< MLong > m_globalId
MInt & polyDeg(const MInt srfcId)
Accessor for polynomial degree.
Storage< MInt > m_orientation
Orientiation of face normal vector.
void reset()
Reset SurfaceCollector, re-create data structures.
MFloat & variables(const MInt srfcId, const MInt side)
Accessor for variables.
MInt & orientation(const MInt srfcId)
Accessor for orientation.
Storage< MFloat > m_variables
Surface variables.
MFloat & coords(const MInt srfcId, const MInt dir)
Accessor for coordinates.
MInt ipow(MInt base, MInt exp)
Integer exponent function for non-negative exponents.
Namespace for auxiliary functions/classes.