MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbcellcollector.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 LBCOLLECTOR_H_
8#define LBCOLLECTOR_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 "lbcellproperties.h"
20
21// The following macro enables the "Structure-of-Arrays" memory layout for multi-dimensional node
22// variables. This might be beneficial for GPU computations. Default is "Array-of-Structures".
23// Examples (for nodes nN with four children cM each)
24// Array-of-Structures (AOS): n0c0, n0c1, n0c2, n0c3, n1c0, n1c1, n1c2, n1c3, n2c0, n2c1, ...
25// Structure-of-Arrays (SOA): n0c0, n1c0, n2c0, n3c0, ..., n0c1, n1c1, n2c1, n3c1, ..., n0c2, ...
26#ifdef WAR_NVHPC_PSTL
27#define LBCOLLECTOR_SOA_MEMORY_LAYOUT
28#endif
29
30// The macro 'LBCOLLECTOR_SANITY_CHECKS_ACCESSORS' enables (potentially very expensive) sanity
31// checks for all accessors. It is enabled for build type "extra_debug".
32#ifdef MAIA_EXTRA_DEBUG
33#define LBCOLLECTOR_SANITY_CHECKS_ACCESSORS
34#endif
35
36// Sanity-checking macros for accessors
37#if defined(LBCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
38#define ENSURE_VALID_ID_ACCESSOR(id) \
39 do { \
40 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
41 } while(false)
42#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
43 do { \
44 MAIA_CONTAINER_ENSURE( \
45 id >= 0 && id < noVariables(), \
46 "variable id = " + std::to_string(id) + " is out-of-bounds [0, " + std::to_string(noVariables()) + ")", AT_); \
47 } while(false)
48#define ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(id) \
49 do { \
50 MAIA_CONTAINER_ENSURE(id >= 0 && id < noDistributions(), \
51 "distribution id = " + std::to_string(id) + " is out-of-bounds [0, " \
52 + std::to_string(noDistributions()), \
53 AT_); \
54 } while(false)
55
56#define ENSURE_VALID_PROPERTY_ACCESSOR(p) \
57 do { \
58 MAIA_CONTAINER_ENSURE(p != LbCell::NumProperties, "Invalid property", AT_); \
59 } while(false)
60#else
61#define ENSURE_VALID_ID_ACCESSOR(id) \
62 do { \
63 } while(false)
64#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
65 do { \
66 } while(false)
67#define ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(id) \
68 do { \
69 } while(false)
70#define ENSURE_VALID_PROPERTY_ACCESSOR(dir) \
71 do { \
72 } while(false)
73#endif
74
75
76// Namespace for auxiliary functions/classes
77namespace maia {
78namespace lb {
79namespace collector {
80
83
84// Type traits for invalid values. These values are used to initialize/erase nodes
85template <class T>
86struct Invalid {};
87
88// Invalid value for ids is 'INT_MIN'
89template <>
90struct Invalid<MInt> {
91 static constexpr MInt value() { return std::numeric_limits<MInt>::min(); }
92};
93
94// Invalid value for floats is 'NaN'
95template <>
96struct Invalid<MFloat> {
97 static constexpr MFloat value() {
98#ifdef MAIA_PGI_COMPILER
99 return std::numeric_limits<MFloat>::quiet_NaN();
100#else
101 return std::numeric_limits<MFloat>::signaling_NaN();
102#endif
103 }
104};
105
106// Invalid value for BitsetProperties is '0'
107template <>
109 static constexpr BitsetType value() { return BitsetType(0); }
110};
111
113template <MInt nDim>
114class LbCellCollector : public maia::container::Container<LbCellCollector<nDim>, Invalid> {
115 // Necessary for CRTP
117
118 // Make base class functions known to use without this pointer
120 using Base::resetStorage;
121 template <class T>
122 using Storage = typename Base::template Storage<T>;
124
125
126 public:
127 // Types
128 template <class T>
130
131 // Constructors
133 constexpr LbCellCollector() = default;
134
135 // Ensure that base class method is found when called from outside
136 using Base::copyData;
137 using Base::fill_invalid;
138 using Base::reset;
139
140 // Accessors
141 MFloat& nu(const MInt id);
142 MFloat nu(const MInt id) const;
143 MFloat& nuT(const MInt id);
144 MFloat nuT(const MInt id) const;
145 MFloat& oldNu(const MInt id);
146 MFloat oldNu(const MInt id) const;
147 MFloat& oldNuT(const MInt id);
148 MFloat oldNuT(const MInt id) const;
149 MInt& bndId(const MInt id);
150 MInt bndId(const MInt id) const;
151 MInt& level(const MInt id);
152 MInt level(const MInt id) const;
153 MFloat& kappa(const MInt id);
154 MFloat kappa(const MInt id) const;
155 MFloat& diffusivity(const MInt id);
156 MFloat diffusivity(const MInt id) const;
157 MFloat& spongeFactor(const MInt id);
158 MFloat spongeFactor(const MInt id) const;
159 MFloat& variables(const MInt id, const MInt eid);
160 MFloat variables(const MInt id, const MInt eid) const;
162 MFloat& oldVariables(const MInt id, const MInt eid);
163 MFloat oldVariables(const MInt id, const MInt eid) const;
165 MFloat& distributions(const MInt id, const MInt eid);
166 MFloat distributions(const MInt id, const MInt eid) const;
167 MFloat& oldDistributions(const MInt id, const MInt eid);
168 MFloat oldDistributions(const MInt id, const MInt eid) const;
169 MFloat& distributionsThermal(const MInt id, const MInt eid);
170 MFloat distributionsThermal(const MInt id, const MInt eid) const;
171 MFloat& oldDistributionsThermal(const MInt id, const MInt eid);
172 MFloat oldDistributionsThermal(const MInt id, const MInt eid) const;
173 MFloat& distributionsTransport(const MInt id, const MInt eid);
174 MFloat distributionsTransport(const MInt id, const MInt eid) const;
175 MFloat& oldDistributionsTransport(const MInt id, const MInt eid);
176 MFloat oldDistributionsTransport(const MInt id, const MInt eid) const;
177 MFloat& externalForces(const MInt id, const MInt eid);
178 MFloat externalForces(const MInt id, const MInt eid) const;
179 MFloat& previousDistribution(const MInt id, const MInt eid);
180 MFloat previousDistribution(const MInt id, const MInt eid) const;
181 MFloat& previousVariable(const MInt id, const MInt eid);
182 MFloat previousVariable(const MInt id, const MInt eid) const;
183 MFloat& uOtherPhase(const MInt id, const MInt dir);
184 MFloat uOtherPhase(const MInt id, const MInt dir) const;
185 MFloat& invVolumeFraction(const MInt id);
186 MFloat invVolumeFraction(const MInt id) const;
187
188 // Property-related accessors
189 BitsetType::reference hasProperty(const MInt id, const LbCell p);
190 MBool hasProperty(const MInt id, const LbCell p) const;
191 void resetProperties(const MInt id);
192 BitsetType& allProperties(const MInt id);
193
195 void setThermal(const MBool isThermal_);
196
198 void setTransport(const MBool useTransport_);
199
201 void setNoVariables();
202
204 void setNoDistributions(const MInt noDistributions_);
205
207 constexpr MInt isThermal() const { return m_isThermal; }
208
210 constexpr MInt useTransport() const { return m_useTransport; }
211
212 void setSaveUOtherPhase(const MBool saveUOtherPhase_);
213 void setSaveVolumeFraction(const MBool saveVolumeFraction_);
214 void setSavePrevVars(const MBool savePrevVars_);
215 constexpr MInt saveUOtherPhase() const { return m_saveUOtherPhase; }
216 constexpr MInt saveVolumeFraction() const { return m_saveVolumeFraction; }
217 constexpr MInt savePrevVars() const { return m_savePrevVars; }
218 void setSaveNuT(const MBool saveNuT_);
219 void setSaveOldNu(const MBool saveOldNu_);
220 constexpr MInt saveNuT() const { return m_saveNuT; }
221 constexpr MInt saveOldNu() const { return m_saveOldNu; }
222
224 constexpr MInt noVariables() const { return m_noVariables; }
225
227 constexpr MInt noCells() const { return this->size(); }
228
230 constexpr MInt noDistributions() const { return m_noDistributions; }
231
233 static constexpr MInt noProperties() { return maia::lb::cell::p(LbCell::NumProperties); }
234
235 private:
236 // Methods required by base class for CRTP
237 void reset();
238 void invalidate(const MInt begin, const MInt end);
239 template <class Functor, class T>
240 void rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end, const MInt destination);
241
243 MInt m_noVariables = 1 + nDim;
244
246
248
251
254
260
261 // Data containers
285};
286
288template <MInt nDim>
290 resetStorage(1, m_nu);
291 if(saveOldNu()) {
292 resetStorage(1, m_oldNu);
293 }
294 resetStorage(1, m_kappa);
295 resetStorage(1, m_diffusivity);
296 resetStorage(1, m_spongeFactor);
297 resetStorage(1, m_bndId);
298 resetStorage(1, m_level);
299 resetStorage(noVariables(), m_variables);
300 resetStorage(noVariables(), m_oldVariables);
301 resetStorage(noDistributions(), m_distributions);
302 resetStorage(noDistributions(), m_oldDistributions);
303 resetStorage(nDim, m_externalForces);
304 if(isThermal()) {
305 resetStorage(noDistributions(), m_distributionsThermal);
306 resetStorage(noDistributions(), m_oldDistributionsThermal);
307 }
308 if(useTransport()) {
309 resetStorage(noDistributions(), m_distributionsTransport);
310 resetStorage(noDistributions(), m_oldDistributionsTransport);
311 }
312 if(savePrevVars()) {
313 resetStorage(noDistributions(), m_previousDistribution);
314 resetStorage(noVariables(), m_previousVariable);
315 }
316 if(saveNuT()) {
317 resetStorage(1, m_nuT);
318 if(saveOldNu()) {
319 resetStorage(1, m_oldNuT);
320 }
321 }
322 if(saveUOtherPhase()) {
323 resetStorage(nDim, m_uOtherPhase);
324 }
325 if(saveVolumeFraction()) {
326 resetStorage(1, m_invVolumeFraction);
327 }
328 resetStorage(1, m_properties);
329}
330
331
333template <MInt nDim>
335 ENSURE_VALID_ID_ACCESSOR(id);
336 return m_nu[id];
337}
339template <MInt nDim>
341 ENSURE_VALID_ID_ACCESSOR(id);
342 return m_nu[id];
343}
344
345template <MInt nDim>
347 ENSURE_VALID_ID_ACCESSOR(id);
348 return m_oldNu[id];
349}
350template <MInt nDim>
352 ENSURE_VALID_ID_ACCESSOR(id);
353 return m_oldNu[id];
354}
355
357template <MInt nDim>
359 ENSURE_VALID_ID_ACCESSOR(id);
360 return m_kappa[id];
361}
362
364template <MInt nDim>
366 ENSURE_VALID_ID_ACCESSOR(id);
367 return m_kappa[id];
368}
369
371template <MInt nDim>
373 // Prevent accidental compilation without support for SoA layout
374 ENSURE_VALID_ID_ACCESSOR(id);
375 return m_diffusivity[id];
376}
377
379template <MInt nDim>
381 // Prevent accidental compilation without support for SoA layout
382 ENSURE_VALID_ID_ACCESSOR(id);
383 return m_diffusivity[id];
384}
385
387template <MInt nDim>
389 ENSURE_VALID_ID_ACCESSOR(id);
390 return m_spongeFactor[id];
391}
393template <MInt nDim>
395 ENSURE_VALID_ID_ACCESSOR(id);
396 return m_spongeFactor[id];
397}
398
400template <MInt nDim>
402 ENSURE_VALID_ID_ACCESSOR(id);
403 return m_bndId[id];
404}
406template <MInt nDim>
408 ENSURE_VALID_ID_ACCESSOR(id);
409 return m_bndId[id];
410}
411
413template <MInt nDim>
415 ENSURE_VALID_ID_ACCESSOR(id);
416 return m_level[id];
417}
419template <MInt nDim>
421 ENSURE_VALID_ID_ACCESSOR(id);
422 return m_level[id];
423}
424
425template <MInt nDim>
427#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
428 return m_variables[eid * noCells() + id];
429#else
430 ENSURE_VALID_ID_ACCESSOR(id);
431 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
432 return m_variables[id * noVariables() + eid];
433#endif
434}
435
436template <MInt nDim>
438#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
439 return m_variables[eid * noCells() + id];
440#else
441 ENSURE_VALID_ID_ACCESSOR(id);
442 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
443 return m_variables[id * noVariables() + eid];
444#endif
445}
446
447template <MInt nDim>
449 return m_variables.data();
450}
451
452template <MInt nDim>
454#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
455 return m_oldVariables[eid * noCells() + id];
456#else
457 ENSURE_VALID_ID_ACCESSOR(id);
458 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
459 return m_oldVariables[id * noVariables() + eid];
460#endif
461}
462
463template <MInt nDim>
465#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
466 return m_oldVariables[eid * noCells() + id];
467#else
468 ENSURE_VALID_ID_ACCESSOR(id);
469 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
470 return m_oldVariables[id * noVariables() + eid];
471#endif
472}
473
474template <MInt nDim>
476 return m_oldVariables.data();
477}
478
479template <MInt nDim>
481#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
482 return m_distributions[eid * noCells() + id];
483#else
484 ENSURE_VALID_ID_ACCESSOR(id);
485 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
486 return m_distributions[id * noDistributions() + eid];
487#endif
488}
489
490template <MInt nDim>
492#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
493 return m_distributions[eid * noCells() + id];
494#else
495 ENSURE_VALID_ID_ACCESSOR(id);
496 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
497 return m_distributions[id * noDistributions() + eid];
498#endif
499}
500
501template <MInt nDim>
503#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
504 return m_oldDistributions[eid * noCells() + id];
505#else
506 ENSURE_VALID_ID_ACCESSOR(id);
507 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
508 return m_oldDistributions[id * noDistributions() + eid];
509#endif
510}
511
512template <MInt nDim>
514#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
515 return m_oldDistributions[eid * noCells() + id];
516#else
517 ENSURE_VALID_ID_ACCESSOR(id);
518 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
519 return m_oldDistributions[id * noDistributions() + eid];
520#endif
521}
522
523template <MInt nDim>
525 ENSURE_VALID_ID_ACCESSOR(id);
526 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
527 return m_previousDistribution[id * noDistributions() + eid];
528}
529
530template <MInt nDim>
532 ENSURE_VALID_ID_ACCESSOR(id);
533 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
534 return m_previousDistribution[id * noDistributions() + eid];
535}
536
537template <MInt nDim>
539 ENSURE_VALID_ID_ACCESSOR(id);
540 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
541 return m_previousVariable[id * noVariables() + eid];
542}
543
544template <MInt nDim>
546 ENSURE_VALID_ID_ACCESSOR(id);
547 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
548 return m_previousVariable[id * noVariables() + eid];
549}
550
551template <MInt nDim>
553 ENSURE_VALID_ID_ACCESSOR(id);
554 return m_nuT[id];
555}
556
557template <MInt nDim>
559 ENSURE_VALID_ID_ACCESSOR(id);
560 return m_nuT[id];
561}
562
563template <MInt nDim>
565 ENSURE_VALID_ID_ACCESSOR(id);
566 return m_uOtherPhase[id * nDim + dir];
567}
568
569template <MInt nDim>
571 ENSURE_VALID_ID_ACCESSOR(id);
572 return m_uOtherPhase[id * nDim + dir];
573}
574
575template <MInt nDim>
577 ENSURE_VALID_ID_ACCESSOR(id);
578 return m_invVolumeFraction[id];
579}
580
581template <MInt nDim>
583 ENSURE_VALID_ID_ACCESSOR(id);
584 return m_invVolumeFraction[id];
585}
586
587template <MInt nDim>
589 ENSURE_VALID_ID_ACCESSOR(id);
590 return m_oldNuT[id];
591}
592
593template <MInt nDim>
595 ENSURE_VALID_ID_ACCESSOR(id);
596 return m_oldNuT[id];
597}
598
599template <MInt nDim>
601#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
602 return m_distributionsThermal[eid * noCells() + id];
603#else
604 ENSURE_VALID_ID_ACCESSOR(id);
605 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
606 return m_distributionsThermal[id * noDistributions() + eid];
607#endif
608}
609
610template <MInt nDim>
612#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
613 return m_distributionsThermal[eid * noCells() + id];
614#else
615 ENSURE_VALID_ID_ACCESSOR(id);
616 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
617 return m_distributionsThermal[id * noDistributions() + eid];
618#endif
619}
620
621template <MInt nDim>
623#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
624 return m_oldDistributionsThermal[eid * noCells() + id];
625#else
626 ENSURE_VALID_ID_ACCESSOR(id);
627 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
628 return m_oldDistributionsThermal[id * noDistributions() + eid];
629#endif
630}
631
632template <MInt nDim>
634#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
635 return m_oldDistributionsThermal[eid * noCells() + id];
636#else
637 ENSURE_VALID_ID_ACCESSOR(id);
638 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
639 return m_oldDistributionsThermal[id * noDistributions() + eid];
640#endif
641}
642
643template <MInt nDim>
645#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
646 return m_distributionsTransport[eid * noCells() + id];
647#endif
648 ENSURE_VALID_ID_ACCESSOR(id);
649 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
650 return m_distributionsTransport[id * noDistributions() + eid];
651}
652
653template <MInt nDim>
655#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
656 return m_distributionsTransport[eid * noCells() + id];
657#endif
658 ENSURE_VALID_ID_ACCESSOR(id);
659 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
660 return m_distributionsTransport[id * noDistributions() + eid];
661}
662
663template <MInt nDim>
665 ENSURE_VALID_ID_ACCESSOR(id);
666 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
667 return m_externalForces[id * nDim + eid];
668}
669
670template <MInt nDim>
672 ENSURE_VALID_ID_ACCESSOR(id);
673 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
674 return m_externalForces[id * nDim + eid];
675}
676
677template <MInt nDim>
679#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
680 return m_oldDistributionsTransport[eid * noCells() + id];
681#endif
682 ENSURE_VALID_ID_ACCESSOR(id);
683 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
684 return m_oldDistributionsTransport[id * noDistributions() + eid];
685}
686
687template <MInt nDim>
689#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
690 return m_oldDistributionsTransport[eid * noCells() + id];
691#endif
692 ENSURE_VALID_ID_ACCESSOR(id);
693 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
694 return m_oldDistributionsTransport[id * noDistributions() + eid];
695}
696
698template <MInt nDim>
700 ENSURE_VALID_ID_ACCESSOR(id);
701 ENSURE_VALID_PROPERTY_ACCESSOR(p);
702 return m_properties[id][maia::lb::cell::p(p)];
703}
705template <MInt nDim>
707 ENSURE_VALID_ID_ACCESSOR(id);
708 ENSURE_VALID_PROPERTY_ACCESSOR(p);
709 return m_properties[id][maia::lb::cell::p(p)];
710}
712template <MInt nDim>
714 ENSURE_VALID_ID_ACCESSOR(id);
715 m_properties[id].reset();
716}
717
719template <MInt nDim>
721 ENSURE_VALID_ID_ACCESSOR(id);
722 return m_properties[id];
723}
724
726template <MInt nDim>
728 m_isThermal = isThermal_;
729}
730
732template <MInt nDim>
734 m_useTransport = useTransport_;
735}
736
738template <MInt nDim>
740 if(isThermal() && !useTransport()) {
741 // only thermal
742 m_noVariables = 1 + nDim + 1;
743 } else if(!isThermal() && useTransport()) {
744 // only transport
745 // TODO: So far both variables must be stored, but this will change
746 // when the sysEq formulation is used in the LB
747 m_noVariables = 1 + nDim + 2;
748 } else if(isThermal() && useTransport()) {
749 // coupled thermal and transport
750 m_noVariables = 1 + nDim + 2;
751 } else {
752 // standard model
753 m_noVariables = 1 + nDim;
754 }
755}
756
757template <MInt nDim>
759 m_saveUOtherPhase = saveUOtherPhase_;
760}
761
762template <MInt nDim>
764 m_saveVolumeFraction = saveVolumeFraction_;
765}
766
767template <MInt nDim>
769 m_savePrevVars = savePrevVars_;
770}
771
772template <MInt nDim>
774 m_saveNuT = saveNuT_;
775}
776
777template <MInt nDim>
779 m_saveOldNu = saveOldNu_;
780}
781
783template <MInt nDim>
785 m_noDistributions = noDistributions_;
786}
787
789template <MInt nDim>
790void LbCellCollector<nDim>::invalidate(const MInt begin, const MInt end) {
791
792 fill_invalid(m_nu, begin, end);
793 if(saveOldNu()) {
794 fill_invalid(m_oldNu, begin, end);
795 }
796 fill_invalid(m_kappa, begin, end);
797 fill_invalid(m_diffusivity, begin, end);
798 fill_invalid(m_spongeFactor, begin, end);
799 fill_invalid(m_bndId, begin, end, 1, -1 /* TODO labels:LB Invalid<MInt>::value() */);
800 fill_invalid(m_level, begin, end);
801 fill_invalid(m_variables, begin, end, noVariables(), 0.);
802 fill_invalid(m_oldVariables, begin, end, noVariables(), 0.);
803 fill_invalid(m_distributions, begin, end, noDistributions());
804 fill_invalid(m_oldDistributions, begin, end, noDistributions());
805 fill_invalid(m_externalForces, begin, end, nDim, 0.0);
806 if(isThermal()) {
807 fill_invalid(m_distributionsThermal, begin, end, noDistributions());
808 fill_invalid(m_oldDistributionsThermal, begin, end, noDistributions());
809 }
810 if(useTransport()) {
811 fill_invalid(m_distributionsTransport, begin, end, noDistributions());
812 fill_invalid(m_oldDistributionsTransport, begin, end, noDistributions());
813 }
814 if(savePrevVars()) {
815 fill_invalid(m_previousDistribution, begin, end, noDistributions());
816 fill_invalid(m_previousVariable, begin, end, noVariables());
817 }
818 if(saveNuT()) {
819 fill_invalid(m_nuT, begin, end);
820 if(saveOldNu()) {
821 fill_invalid(m_oldNuT, begin, end);
822 }
823 }
824 if(saveUOtherPhase()) {
825 fill_invalid(m_uOtherPhase, begin, end, nDim);
826 }
827 if(saveVolumeFraction()) {
828 fill_invalid(m_invVolumeFraction, begin, end);
829 }
830
831 // Properties
832 fill_invalid(m_properties, begin, end);
833}
834
835
837template <MInt nDim>
838template <class Functor, class T>
839void LbCellCollector<nDim>::rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end,
840 const MInt destination) {
841
842 copyData(source.m_nu, m_nu, c, begin, end, destination);
843 if(saveOldNu()) {
844 copyData(source.m_oldNu, m_oldNu, c, begin, end, destination);
845 }
846 copyData(source.m_kappa, m_kappa, c, begin, end, destination);
847 copyData(source.m_diffusivity, m_diffusivity, c, begin, end, destination);
848 copyData(source.m_spongeFactor, m_spongeFactor, c, begin, end, destination);
849 copyData(source.m_bndId, m_bndId, c, begin, end, destination);
850 copyData(source.m_level, m_level, c, begin, end, destination);
851 copyData(source.m_variables, m_variables, c, begin, end, destination, noVariables());
852 copyData(source.m_oldVariables, m_oldVariables, c, begin, end, destination, noVariables());
853 copyData(source.m_distributions, m_distributions, c, begin, end, destination, noDistributions());
854 copyData(source.m_oldDistributions, m_oldDistributions, c, begin, end, destination, noDistributions());
855 copyData(source.m_externalForces, m_externalForces, c, begin, end, destination, nDim);
856 if(isThermal()) {
857 copyData(source.m_distributionsThermal, m_distributionsThermal, c, begin, end, destination, noDistributions());
858 copyData(source.m_oldDistributionsThermal, m_oldDistributionsThermal, c, begin, end, destination,
859 noDistributions());
860 }
861 if(useTransport()) {
862 copyData(source.m_distributionsTransport, m_distributionsTransport, c, begin, end, destination, noDistributions());
863 copyData(source.m_oldDistributionsTransport, m_oldDistributionsTransport, c, begin, end, destination,
864 noDistributions());
865 }
866 if(savePrevVars()) {
867 copyData(source.m_previousDistribution, m_previousDistribution, c, begin, end, destination, noDistributions());
868 copyData(source.m_previousVariable, m_previousVariable, c, begin, end, destination, noVariables());
869 }
870 if(saveNuT()) {
871 copyData(source.m_nuT, m_nuT, c, begin, end, destination);
872 if(saveOldNu()) {
873 copyData(source.m_oldNuT, m_oldNuT, c, begin, end, destination);
874 }
875 }
876 if(saveUOtherPhase()) {
877 copyData(source.m_uOtherPhase, m_uOtherPhase, c, begin, end, destination, nDim);
878 }
879 if(saveVolumeFraction()) {
880 copyData(source.m_invVolumeFraction, m_invVolumeFraction, c, begin, end, destination);
881 }
882
883 // Properties
884 copyData(source.m_properties, m_properties, c, begin, end, destination);
885}
886
887} // namespace collector
888} // namespace lb
889} // namespace maia
890
891
892// Undefine macros that should not be used outside this file
893#undef LBCOLLECTOR_SANITY_CHECKS_ACCESSORS
894#undef ENSURE_VALID_ID_ACCESSOR
895#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
896#undef ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR
897#undef ENSURE_VALID_PROPERTY_ACCESSOR
898
899#endif // ifndef LBCOLLECTOR_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
constexpr MInt size() const
Return size (i.e., currently used number of nodes)
Definition: container.h:89
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 LB cell collector.
maia::lb::cell::BitsetType BitsetType
void setThermal(const MBool isThermal_)
Allow setting whether to support thermal computations.
MFloat & distributionsTransport(const MInt id, const MInt eid)
MFloat & diffusivity(const MInt id)
Accessor for the diffusivity.
void setSaveVolumeFraction(const MBool saveVolumeFraction_)
void setTransport(const MBool useTransport_)
Allow setting whether to support transport computations.
constexpr MInt noCells() const
Return number of cells.
constexpr MInt saveUOtherPhase() const
void setSaveUOtherPhase(const MBool saveUOtherPhase_)
void setSaveOldNu(const MBool saveOldNu_)
MFloat & previousVariable(const MInt id, const MInt eid)
constexpr MInt saveVolumeFraction() const
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.
MFloat & externalForces(const MInt id, const MInt eid)
MFloat & variables(const MInt id, const MInt eid)
void resetProperties(const MInt id)
Reset all properties.
MInt m_noVariables
Number of variables.
BitsetType & allProperties(const MInt id)
Accessor for properties.
typename maia::lb::collector::Invalid< T > Invalid
MBool m_useTransport
Use transport model.
MFloat & invVolumeFraction(const MInt id)
MBool m_isThermal
Use thermal model.
constexpr MInt useTransport() const
Return number of species.
typename Base::template Storage< T > Storage
MInt & level(const MInt id)
Accessor for level.
void setNoVariables()
Update number of variables according to used model.
void setSaveNuT(const MBool saveNuT_)
MFloat & nu(const MInt id)
Accessor for nu.
MInt & bndId(const MInt id)
Accessor for bndId.
MFloat & oldDistributionsTransport(const MInt id, const MInt eid)
static constexpr MInt noProperties()
Return number of properties defined for each node.
constexpr LbCellCollector()=default
Default c'tor does nothing.
void reset()
Reset tree, re-create data structures with given capacity, and set size to zero.
BitsetType::reference hasProperty(const MInt id, const LbCell p)
Accessor for properties.
MFloat & oldVariables(const MInt id, const MInt eid)
constexpr MInt isThermal() const
Return number of species.
constexpr MInt noVariables() const
Return number of variables.
constexpr MInt noDistributions() const
Return number of distributions.
MFloat & kappa(const MInt id)
Accessor for kappa.
MFloat & spongeFactor(const MInt id)
Accessor for spongeFactor.
void setSavePrevVars(const MBool savePrevVars_)
MFloat & previousDistribution(const MInt id, const MInt eid)
MFloat & distributionsThermal(const MInt id, const MInt eid)
MFloat & oldDistributionsThermal(const MInt id, const MInt eid)
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
MFloat & uOtherPhase(const MInt id, const MInt dir)
void setNoDistributions(const MInt noDistributions_)
Sets the number of distributions.
MFloat & distributions(const MInt id, const MInt eid)
MFloat & oldDistributions(const MInt id, const MInt eid)
LbCell
LB 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
std::bitset< p(LbCell::NumProperties)> BitsetType
constexpr std::underlying_type< LbCell >::type p(const LbCell property)
Converts property name to underlying integer value.
maia::lb::cell::BitsetType BitsetType
Underlying bitset type for property storage.
Namespace for auxiliary functions/classes.