MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lptcellcollector.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 LPTCOLLECTOR_H_
8#define LPTCOLLECTOR_H_
9
10#include <algorithm>
11#include <bitset>
12#include <type_traits>
13#include <vector>
14#include "INCLUDE/maiamacro.h"
15#include "INCLUDE/maiatypes.h"
16#include "MEMORY/container.h"
17#include "UTIL/functions.h"
18#include "compiler_config.h"
19#include "lptcellproperties.h"
20
21
22// The macro 'LPTCOLLECTOR_SANITY_CHECKS_ACCESSORS' enables (potentially very expensive) sanity checks
23// for all accessors. It is enabled for build type "extra_debug".
24#ifdef MAIA_EXTRA_DEBUG
25#define LPTCOLLECTOR_SANITY_CHECKS_ACCESSORS
26#endif
27
28#ifdef LPTCOLLECTOR_SOA_MEMORY_LAYOUT
29#error Missing implementation for structure-of-arrays memory layout.
30#endif
31
32// Sanity-checking macros for accessors
33#if defined(MAIA_ASSERT_ACCESSORS) || defined(LPTCOLLECTOR_SANITY_CHECKS_ACCESSORS)
34#define ENSURE_VALID_ID_ACCESSOR(id) \
35 do { \
36 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
37 } while(false)
38#define ENSURE_VALID_SET_ID_ACCESSOR(id) \
39 do { \
40 MAIA_CONTAINER_ENSURE( \
41 (id) >= 0 && (id) < maxNoSets(), \
42 "set id = " + std::to_string(id) + "is out-of-bounds [0, " + std::to_string(maxNoSets()) + ")", AT_); \
43 } while(false)
44#define ENSURE_VALID_DIM_ID_ACCESSOR(dim) \
45 do { \
46 MAIA_CONTAINER_ENSURE(dim >= 0 && dim < nDim, \
47 "dim = " + std::to_string(dim) + " is out-of-bounds [0, " + std::to_string(nDim) + ")", \
48 AT_); \
49 } while(false)
50#define ENSURE_VALID_PROPERTY_ACCESSOR(p) \
51 do { \
52 MAIA_CONTAINER_ENSURE(p != LptCell::NumProperties, "Invalid property", AT_); \
53 } while(false)
54#else
55#define ENSURE_VALID_ID_ACCESSOR(id) \
56 do { \
57 } while(false)
58#define ENSURE_VALID_SET_ID_ACCESSOR(id) \
59 do { \
60 } while(false)
61#define ENSURE_VALID_DIM_ID_ACCESSOR(id) \
62 do { \
63 } while(false)
64#define ENSURE_VALID_PROPERTY_ACCESSOR(dim) \
65 do { \
66 } while(false)
67#endif
68
69
70// Namespace for auxiliary functions/classes
71namespace maia {
72namespace lpt {
73namespace collector {
74
77
78// Type traits for invalid values. These values are used to initialize/erase nodes
79template <class T>
80struct Invalid {};
81
82// Invalid value for ids is 'INT_MIN'
83template <>
84struct Invalid<MInt> {
85 static constexpr MInt value() { return std::numeric_limits<MInt>::min(); }
86};
87
88// Invalid value for floats is 'NaN'
89template <>
90struct Invalid<MFloat> {
91 static constexpr MFloat value() {
92#ifdef MAIA_PGI_COMPILER
93 return std::numeric_limits<MFloat>::quiet_NaN();
94#else
95 return std::numeric_limits<MFloat>::signaling_NaN();
96#endif
97 }
98};
99
100// Invalid value for BitsetProperties is '0'
101template <>
103 static constexpr BitsetType value() { return {0}; }
104};
105
106
108template <MInt nDim>
109class LptCells : public maia::container::Container<LptCells<nDim>, Invalid> {
110 // Necessary for CRTP
111 friend class maia::container::Container<LptCells<nDim>, Invalid>;
112
113 // Make base class functions known to use without this pointer
115 using Base::resetStorage;
117 template <class T>
118 using Storage = typename Base::template Storage<T>;
119
120 public:
122
123 // Types
124 template <class T>
126
127 // Constructors
129 constexpr LptCells() = default;
130
131 // Ensure that base class method is found when called from outside
132 using Base::copyData;
133 using Base::fill_invalid;
134 using Base::reset;
135
136 // Property-related accessors
137 BitsetType::reference hasProperty(const MInt id, const LptCell p);
138 MBool hasProperty(const MInt id, const LptCell p) const;
139 void resetProperties(const MInt id);
140 BitsetType& properties(const MInt id);
141
142 MFloat volumeFraction(const MInt id) const;
143 MFloat& volumeFraction(const MInt id);
144
145 MInt noParticles(const MInt id) const;
146 MInt& noParticles(const MInt id);
147
148 MInt noEllipsoids(const MInt id) const;
149 MInt& noEllipsoids(const MInt id);
150
151 MInt bndryCellId(const MInt id) const;
152 MInt& bndryCellId(const MInt id);
153
154 MFloat fluidVariable(const MInt id, const MInt var) const;
155 MFloat& fluidVariable(const MInt id, const MInt var);
156
157 MFloat fluidSpecies(const MInt id) const;
158 MFloat& fluidSpecies(const MInt id);
159
160 MFloat& massFlux(const MInt id);
161 MFloat massFlux(const MInt id) const;
162
163 MFloat& heatFlux(const MInt id);
164 MFloat heatFlux(const MInt id) const;
165
166 MFloat& momentumFlux(const MInt id, const MInt dim);
167 MFloat momentumFlux(const MInt id, const MInt dim) const;
168
169 MFloat& workFlux(const MInt id);
170 MFloat workFlux(const MInt id) const;
171
172 MFloat& velocitySlope(const MInt id, const MInt varId, const MInt dim);
173 MFloat velocitySlope(const MInt id, const MInt varId, const MInt dim) const;
174
176
177 void setLptCollectorCoupling(const MBool mass, const MBool momentum, const MBool heat);
178
180
181 private:
182 // Methods required by base class for CRTP
183 void reset();
184 void invalidate(const MInt begin, const MInt end);
185 template <class Functor, class T>
186 void rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end, const MInt destination);
187
191 static constexpr MInt m_noVariables = nDim + 3;
194
195 constexpr MBool hasMassCoupling() const { return m_massCoupling; }
196 constexpr MBool hasMomentumCoupling() const { return m_momentumCoupling; }
197 constexpr MBool hasHeatCoupling() const { return m_heatCoupling; }
198 constexpr MInt noVars() const { return m_noVariables; };
199 constexpr MInt noSpecies() const { return m_noSpecies; };
200 constexpr MBool hasSlopes() const { return m_storeSlopes; }
201
203
208
210
212
217
219};
220
222template <MInt nDim>
223void LptCells<nDim>::setLptCollectorCoupling(const MBool mass, const MBool momentum, const MBool heat) {
224 m_massCoupling = mass;
225 m_momentumCoupling = momentum;
226 m_heatCoupling = heat;
227}
229template <MInt nDim>
231 // resetStorage(#of items per cell, Storage<> name);
232
233 resetStorage(1, m_properties);
234 resetStorage(1, m_noParticles);
235 resetStorage(1, m_noEllipsoids);
236 resetStorage(1, m_volumeFraction);
237 resetStorage(1, m_bndryCellId);
238
239 resetStorage(noVars(), m_variables);
240
241 resetStorage(noSpecies(), m_species);
242
243 if(hasMassCoupling()) {
244 resetStorage(1, m_massFlux);
245 }
246 if(hasHeatCoupling()) resetStorage(1, m_heatFlux);
247 if(hasMomentumCoupling()) {
248 resetStorage(nDim, m_momentumFlux);
249 resetStorage(1, m_workFlux);
250 }
251 if(hasSlopes()) {
252 resetStorage(nDim * nDim, m_velocitySlopes);
253 }
254}
255
257template <MInt nDim>
259 ENSURE_VALID_ID_ACCESSOR(id);
260 ENSURE_VALID_PROPERTY_ACCESSOR(p);
261 return m_properties.at(id)[maia::lpt::cell::p(p)];
262}
264template <MInt nDim>
266 ENSURE_VALID_ID_ACCESSOR(id);
267 ENSURE_VALID_PROPERTY_ACCESSOR(p);
268 return m_properties.at(id)[maia::lpt::cell::p(p)];
269}
271template <MInt nDim>
273 ENSURE_VALID_ID_ACCESSOR(id);
274 m_properties.at(id).reset();
275}
277template <MInt nDim>
279 ENSURE_VALID_ID_ACCESSOR(id);
280 return m_properties[id];
281}
282
284template <MInt nDim>
286 ENSURE_VALID_ID_ACCESSOR(id);
287 return m_volumeFraction[id];
288}
289template <MInt nDim>
291 ENSURE_VALID_ID_ACCESSOR(id);
292 return m_volumeFraction[id];
293}
295template <MInt nDim>
297 ENSURE_VALID_ID_ACCESSOR(id);
298 return m_noParticles[id];
299}
300template <MInt nDim>
302 ENSURE_VALID_ID_ACCESSOR(id);
303 return m_noParticles[id];
304}
305
307template <MInt nDim>
309 ENSURE_VALID_ID_ACCESSOR(id);
310 return m_noEllipsoids[id];
311}
312template <MInt nDim>
314 ENSURE_VALID_ID_ACCESSOR(id);
315 return m_noEllipsoids[id];
316}
317
319template <MInt nDim>
321 ENSURE_VALID_ID_ACCESSOR(id);
322 return m_bndryCellId[id];
323}
324template <MInt nDim>
326 ENSURE_VALID_ID_ACCESSOR(id);
327 return m_bndryCellId[id];
328}
329
331template <MInt nDim>
333 ENSURE_VALID_ID_ACCESSOR(id);
334 return m_variables[id * noVars() + var];
335}
336template <MInt nDim>
337MFloat LptCells<nDim>::fluidVariable(const MInt id, const MInt var) const {
338 ENSURE_VALID_ID_ACCESSOR(id);
339 return m_variables[id * noVars() + var];
340}
341
343template <MInt nDim>
345 ENSURE_VALID_ID_ACCESSOR(id);
346 return m_species[id];
347}
348template <MInt nDim>
350 ENSURE_VALID_ID_ACCESSOR(id);
351 return m_species[id];
352}
353
355template <MInt nDim>
357 ENSURE_VALID_ID_ACCESSOR(id);
358 return m_massFlux[id];
359}
360template <MInt nDim>
362 ENSURE_VALID_ID_ACCESSOR(id);
363 return m_massFlux[id];
364}
366template <MInt nDim>
368 ENSURE_VALID_ID_ACCESSOR(id);
369 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
370 return m_momentumFlux[id * nDim + dim];
371}
372template <MInt nDim>
373MFloat LptCells<nDim>::momentumFlux(const MInt id, const MInt dim) const {
374 ENSURE_VALID_ID_ACCESSOR(id);
375 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
376 return m_momentumFlux[id * nDim + dim];
377}
379template <MInt nDim>
381 ENSURE_VALID_ID_ACCESSOR(id);
382 return m_workFlux[id];
383}
384template <MInt nDim>
386 ENSURE_VALID_ID_ACCESSOR(id);
387 return m_workFlux[id];
388}
389
391template <MInt nDim>
393 ENSURE_VALID_ID_ACCESSOR(id);
394 return m_heatFlux[id];
395}
396template <MInt nDim>
398 ENSURE_VALID_ID_ACCESSOR(id);
399 return m_heatFlux[id];
400}
401
402template <MInt nDim>
403MFloat& LptCells<nDim>::velocitySlope(const MInt id, const MInt varId, const MInt dir) {
404 ENSURE_VALID_ID_ACCESSOR(id);
405 ENSURE_VALID_DIM_ID_ACCESSOR(dir);
406 return m_velocitySlopes[id * nDim * nDim + varId * nDim + dir];
407}
408
409template <MInt nDim>
410MFloat LptCells<nDim>::velocitySlope(const MInt id, const MInt varId, const MInt dir) const {
411 ENSURE_VALID_ID_ACCESSOR(id);
412 ENSURE_VALID_DIM_ID_ACCESSOR(dir);
413 return m_velocitySlopes[id * nDim * nDim + varId * nDim + dir];
414}
415
416
418template <MInt nDim>
419void LptCells<nDim>::invalidate(const MInt begin, const MInt end) {
420 fill_invalid(m_properties, begin, end, 1, false);
421 fill_invalid(m_volumeFraction, begin, end);
422 fill_invalid(m_noParticles, begin, end);
423 fill_invalid(m_noEllipsoids, begin, end);
424 fill_invalid(m_bndryCellId, begin, end);
425
426 fill_invalid(m_variables, begin, end, noVars());
427 fill_invalid(m_species, begin, end, noSpecies());
428
429 if(hasMassCoupling()) {
430 fill_invalid(m_massFlux, begin, end);
431 }
432 if(hasHeatCoupling()) fill_invalid(m_heatFlux, begin, end);
433 if(hasMomentumCoupling()) {
434 fill_invalid(m_workFlux, begin, end);
435 fill_invalid(m_momentumFlux, begin, end, nDim);
436 }
437 if(hasSlopes()) {
438 fill_invalid(m_velocitySlopes, begin, end, nDim * nDim);
439 }
440}
441
443template <MInt nDim>
444template <class Functor, class T>
445void LptCells<nDim>::rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end,
446 const MInt destination) {
447 copyData(source.m_properties, m_properties, c, begin, end, destination);
448 copyData(source.m_volumeFraction, m_volumeFraction, c, begin, end, destination);
449 copyData(source.m_noParticles, m_noParticles, c, begin, end, destination);
450 copyData(source.m_noEllipsoids, m_noEllipsoids, c, begin, end, destination);
451 copyData(source.m_bndryCellId, m_bndryCellId, c, begin, end, destination);
452
453 copyData(source.m_variables, m_variables, c, begin, end, destination, noVars());
454 copyData(source.m_species, m_species, c, begin, end, destination, noSpecies());
455
456 if(hasMassCoupling()) {
457 copyData(source.m_massFlux, m_massFlux, c, begin, end, destination);
458 }
459 if(hasHeatCoupling()) copyData(source.m_heatFlux, m_heatFlux, c, begin, end, destination);
460 if(hasMomentumCoupling()) {
461 copyData(source.m_workFlux, m_workFlux, c, begin, end, destination);
462 copyData(source.m_momentumFlux, m_momentumFlux, c, begin, end, destination, nDim);
463 }
464 if(hasSlopes()) {
465 copyData(source.m_velocitySlopes, m_velocitySlopes, c, begin, end, destination, nDim * nDim);
466 }
467}
468
469} // namespace collector
470} // namespace lpt
471} // namespace maia
472
473
474// Undefine macros that should not be used outside this file
475#undef LPTCOLLECTOR_SANITY_CHECKS_ACCESSORS
476#undef ENSURE_VALID_ID_ACCESSOR
477#undef ENSURE_VALID_ID_ACCESSOR
478#undef ENSURE_VALID_SET_ID_ACCESSOR
479#undef ENSURE_VALID_PROPERTY_ACCESSOR
480
481#endif // ifndef LPTCOLLECTOR_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 LPT cell collector.
MFloat & momentumFlux(const MInt id, const MInt dim)
Accessor for momentumFlux.
MInt noEllipsoids(const MInt id) const
Storage< BitsetType > m_properties
constexpr MBool hasHeatCoupling() const
static constexpr MInt m_noVariables
MFloat & velocitySlope(const MInt id, const MInt varId, const MInt dim)
BitsetType & properties(const MInt id)
Accessor for properties.
constexpr MBool hasMassCoupling() const
MInt bndryCellId(const MInt id) const
constexpr LptCells()=default
Default c'tor does nothing.
void reset()
Reset tree, re-create data structures with given capacity, and set size to zero.
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.
constexpr MBool hasMomentumCoupling() const
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
MFloat fluidSpecies(const MInt id) const
MFloat volumeFraction(const MInt id) const
MFloat & heatFlux(const MInt id)
Accessor for heatFlux.
constexpr MInt noVars() const
MInt noParticles(const MInt id) const
MFloat & massFlux(const MInt id)
Accessor for massFlux.
typename Base::template Storage< T > Storage
constexpr MBool hasSlopes() const
BitsetType::reference hasProperty(const MInt id, const LptCell p)
Accessor for properties.
maia::lpt::cell::BitsetType BitsetType
typename maia::lpt::collector::Invalid< T > Invalid
MFloat & workFlux(const MInt id)
Accessor for workFlux.
MFloat fluidVariable(const MInt id, const MInt var) const
void setLptCollectorCoupling(const MBool mass, const MBool momentum, const MBool heat)
Set the lpt-collector type.
void resetProperties(const MInt id)
Reset all properties.
void setLptCollectorNoSpecies(const MInt noSpecies)
constexpr MInt noSpecies() const
LptCell
Lpt cell Property Labels.
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
MInt id
Definition: maiatypes.h:71
constexpr std::underlying_type< LptCell >::type p(const LptCell property)
Converts property name to underlying integer value.
std::bitset< p(LptCell::NumProperties)> BitsetType
maia::lpt::cell::BitsetType BitsetType
Underlying bitset type for property storage.
Namespace for auxiliary functions/classes.