MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
dgcartesianspongeelementcollector.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef DGSPONGELEMENTCOLLECTOR_H_
8#define DGSPONGELEMENTCOLLECTOR_H_
9
10
11// The following macro enables the "Structure-of-Arrays" memory layout for multi-dimensional node
12// variables. This might be beneficial for GPU computations. Default is "Array-of-Structures".
13// Examples (for nodes nN with four children cM each)
14// Array-of-Structures (AOS): n0c0, n0c1, n0c2, n0c3, n1c0, n1c1, n1c2, n1c3, n2c0, n2c1, ...
15// Structure-of-Arrays (SOA): n0c0, n1c0, n2c0, n3c0, ..., n0c1, n1c1, n2c1, n3c1, ..., n0c2, ...
16// #define DGCOLLECTOR_SOA_MEMORY_LAYOUT
17
18// The macro 'DGCOLLECTOR_SANITY_CHECKS_ACCESSORS' enables (potentially very expensive) sanity
19// checks
20// for all accessors. It is enabled for build type "extra_debug".
21#ifdef MAIA_EXTRA_DEBUG
22#define DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
23#endif
24
25// Sanity-checking macros for accessors
26#if defined(DGCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
27#define ENSURE_VALID_ID_ACCESSOR(id) \
28 do { \
29 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
30 } while(false)
31#define ENSURE_VALID_NODE_ID_ACCESSOR(pos) \
32 do { \
33 MAIA_CONTAINER_ENSURE(pos >= 0 && pos < noNodesXD(), \
34 "node id " + std::to_string(pos) + " out-of-bounds [0, " + std::to_string(noNodesXD()), \
35 AT_); \
36 } while(false)
37#else
38#define ENSURE_VALID_ID_ACCESSOR(id) \
39 do { \
40 } while(false)
41#define ENSURE_VALID_NODE_ID_ACCESSOR(pos) \
42 do { \
43 } while(false)
44#endif
45
46
48namespace maia {
49namespace dg {
50namespace collector {
51
53template <MInt nDim, class SysEqn>
54class SpongeElementCollector : public maia::container::Container<SpongeElementCollector<nDim, SysEqn>, Invalid> {
55 // Necessary for CRTP
57
58 // Make base class functions known to use without this pointer
61 template <class T>
62 using Storage = typename Base::template Storage<T>;
63
65 constexpr MInt noNodesXD() const { return m_noNodesXD; }
66
67 public:
68 // Types
69 template <class T>
71
72 // Constructor
74 constexpr SpongeElementCollector() = default;
75
76 // Ensure that base class method is found when called from outside
77 using Base::copyData;
79 using Base::reset;
80
81 // Accessors
82 MInt& elementId(const MInt id);
83 MInt elementId(const MInt id) const;
84 MFloat& spongeEta(const MInt id);
85 MFloat spongeEta(const MInt id, const MInt pos) const;
86 MFloat spongeEta(const MInt id) const { return spongeEta(id, 0); };
87
89 MInt maxPolyDeg() const { return m_maxPolyDeg; }
90 // Set maximum polynomial degree
91 MInt maxPolyDeg(const MInt maxPolyDeg_);
92
93 private:
94 // Methods required by base class for CRTP
95 void reset();
96 void invalidate(const MInt begin, const MInt end);
97 template <class Functor, class T>
98 void rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end, const MInt destination);
99
102
105
106 // Data containers
109};
110
111
113template <MInt nDim, class SysEqn>
115 resetStorage(1, m_elementId);
116 resetStorage(noNodesXD(), m_spongeEta);
117}
118
119
121template <MInt nDim, class SysEqn>
123// Prevent accidental compilation without support for SoA layout
124#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
125#error Missing implementation for structure-of-arrays memory layout.
126#endif
127 ENSURE_VALID_ID_ACCESSOR(id);
128 return m_elementId[id];
129}
131template <MInt nDim, class SysEqn>
133// Prevent accidental compilation without support for SoA layout
134#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
135#error Missing implementation for structure-of-arrays memory layout.
136#endif
137 ENSURE_VALID_ID_ACCESSOR(id);
138 return m_elementId[id];
139}
140
141
143template <MInt nDim, class SysEqn>
145// Prevent accidental compilation without support for SoA layout
146#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
147#error Missing implementation for structure-of-arrays memory layout.
148#endif
149 ENSURE_VALID_ID_ACCESSOR(id);
150 return m_spongeEta[id * noNodesXD()];
151}
153template <MInt nDim, class SysEqn>
155// Prevent accidental compilation without support for SoA layout
156#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
157#error Missing implementation for structure-of-arrays memory layout.
158#endif
159 ENSURE_VALID_ID_ACCESSOR(id);
160 ENSURE_VALID_NODE_ID_ACCESSOR(pos);
161 return m_spongeEta[id * noNodesXD() + pos];
162}
163
164
166template <MInt nDim, class SysEqn>
168// Prevent accidental compilation without support for SoA layout
169#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
170#error Missing implementation for structure-of-arrays memory layout.
171#endif
172
173 // Element id
174 fill_invalid(m_elementId, begin, end);
175
176 // Sponge eta
177 fill_invalid(m_spongeEta, begin, end, noNodesXD());
178}
179
180
182template <MInt nDim, class SysEqn>
183template <class Functor, class T>
184void SpongeElementCollector<nDim, SysEqn>::rawCopyGeneric(Functor&& c, const T& source, const MInt begin,
185 const MInt end, const MInt destination) {
186// Prevent accidental compilation without support for SoA layout
187#ifdef DGCOLLECTOR_SOA_MEMORY_LAYOUT
188#error Missing implementation for structure-of-arrays memory layout.
189#endif
190
191 // Element id
192 copyData(source.m_elementId, m_elementId, c, begin, end, destination);
193
194 // Sponge eta
195 copyData(source.m_spongeEta, m_spongeEta, c, begin, end, destination, noNodesXD());
196}
197
198
200template <MInt nDim, class SysEqn>
202 const MInt oldMaxPolyDeg = m_maxPolyDeg;
203 m_maxPolyDeg = maxPolyDeg_;
204 m_noNodesXD = ipow(m_maxPolyDeg + 1, nDim);
205 return oldMaxPolyDeg;
206}
207
208} // namespace collector
209} // namespace dg
210} // namespace maia
211
212
213// Undefine macros that should not be used outside this file
214#undef DGCOLLECTOR_SANITY_CHECKS_ACCESSORS
215#undef ENSURE_VALID_ID_ACCESSOR
216#undef ENSURE_VALID_NODE_ID_ACCESSOR
217
218#endif // ifndef DGSPONGELEMENTCOLLECTOR_H_
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.
Definition: container.h:138
void fill_invalid(Container_ &c, const MInt begin, const MInt end, const MInt solverSize=1, const T value=Invalid< T >::value())
Definition: container.h:131
void resetStorage(const MInt n, Storage< T > &c)
Create new container with given size and replace original one.
Definition: container.h:420
void reset(const MInt capacity)
Reset tree, re-create data structures with given capacity, and set size to zero.
Definition: container.h:187
Class that represents DG element collector.
MFloat & spongeEta(const MInt id)
Accessor for sponge eta.
MInt & elementId(const MInt id)
Accessor for element id.
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
typename maia::dg::collector::Invalid< T > Invalid
void reset()
Reset SpongeElementCollector, re-create data structures.
constexpr MInt noNodesXD() const
Return number of nodes in 2D/3D.
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 maxPolyDeg() const
Return maximum polynomial degree.
constexpr SpongeElementCollector()=default
Default c'tor does nothing.
MInt ipow(MInt base, MInt exp)
Integer exponent function for non-negative exponents.
Definition: functions.h:317
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
MInt id
Definition: maiatypes.h:71
Namespace for auxiliary functions/classes.