27#define LBCOLLECTOR_SOA_MEMORY_LAYOUT
32#ifdef MAIA_EXTRA_DEBUG
33#define LBCOLLECTOR_SANITY_CHECKS_ACCESSORS
37#if defined(LBCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
38#define ENSURE_VALID_ID_ACCESSOR(id) \
40 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
42#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
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_); \
48#define ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(id) \
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()), \
56#define ENSURE_VALID_PROPERTY_ACCESSOR(p) \
58 MAIA_CONTAINER_ENSURE(p != LbCell::NumProperties, "Invalid property", AT_); \
61#define ENSURE_VALID_ID_ACCESSOR(id) \
64#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
67#define ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(id) \
70#define ENSURE_VALID_PROPERTY_ACCESSOR(dir) \
91 static constexpr MInt value() {
return std::numeric_limits<MInt>::min(); }
98#ifdef MAIA_PGI_COMPILER
99 return std::numeric_limits<MFloat>::quiet_NaN();
101 return std::numeric_limits<MFloat>::signaling_NaN();
239 template <
class Functor,
class T>
290 resetStorage(1, m_nu);
292 resetStorage(1, m_oldNu);
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);
305 resetStorage(noDistributions(), m_distributionsThermal);
306 resetStorage(noDistributions(), m_oldDistributionsThermal);
309 resetStorage(noDistributions(), m_distributionsTransport);
310 resetStorage(noDistributions(), m_oldDistributionsTransport);
313 resetStorage(noDistributions(), m_previousDistribution);
314 resetStorage(noVariables(), m_previousVariable);
317 resetStorage(1, m_nuT);
319 resetStorage(1, m_oldNuT);
322 if(saveUOtherPhase()) {
323 resetStorage(nDim, m_uOtherPhase);
325 if(saveVolumeFraction()) {
326 resetStorage(1, m_invVolumeFraction);
328 resetStorage(1, m_properties);
335 ENSURE_VALID_ID_ACCESSOR(
id);
341 ENSURE_VALID_ID_ACCESSOR(
id);
347 ENSURE_VALID_ID_ACCESSOR(
id);
352 ENSURE_VALID_ID_ACCESSOR(
id);
359 ENSURE_VALID_ID_ACCESSOR(
id);
366 ENSURE_VALID_ID_ACCESSOR(
id);
374 ENSURE_VALID_ID_ACCESSOR(
id);
375 return m_diffusivity[
id];
382 ENSURE_VALID_ID_ACCESSOR(
id);
383 return m_diffusivity[
id];
389 ENSURE_VALID_ID_ACCESSOR(
id);
390 return m_spongeFactor[
id];
395 ENSURE_VALID_ID_ACCESSOR(
id);
396 return m_spongeFactor[
id];
402 ENSURE_VALID_ID_ACCESSOR(
id);
408 ENSURE_VALID_ID_ACCESSOR(
id);
415 ENSURE_VALID_ID_ACCESSOR(
id);
421 ENSURE_VALID_ID_ACCESSOR(
id);
427#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
428 return m_variables[eid * noCells() +
id];
430 ENSURE_VALID_ID_ACCESSOR(
id);
431 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
432 return m_variables[
id * noVariables() + eid];
438#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
439 return m_variables[eid * noCells() +
id];
441 ENSURE_VALID_ID_ACCESSOR(
id);
442 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
443 return m_variables[
id * noVariables() + eid];
449 return m_variables.data();
454#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
455 return m_oldVariables[eid * noCells() +
id];
457 ENSURE_VALID_ID_ACCESSOR(
id);
458 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
459 return m_oldVariables[
id * noVariables() + eid];
465#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
466 return m_oldVariables[eid * noCells() +
id];
468 ENSURE_VALID_ID_ACCESSOR(
id);
469 ENSURE_VALID_VARIABLE_ID_ACCESSOR(eid);
470 return m_oldVariables[
id * noVariables() + eid];
476 return m_oldVariables.data();
481#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
482 return m_distributions[eid * noCells() +
id];
484 ENSURE_VALID_ID_ACCESSOR(
id);
485 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
486 return m_distributions[
id * noDistributions() + eid];
492#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
493 return m_distributions[eid * noCells() +
id];
495 ENSURE_VALID_ID_ACCESSOR(
id);
496 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
497 return m_distributions[
id * noDistributions() + eid];
503#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
504 return m_oldDistributions[eid * noCells() +
id];
506 ENSURE_VALID_ID_ACCESSOR(
id);
507 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
508 return m_oldDistributions[
id * noDistributions() + eid];
514#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
515 return m_oldDistributions[eid * noCells() +
id];
517 ENSURE_VALID_ID_ACCESSOR(
id);
518 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
519 return m_oldDistributions[
id * noDistributions() + eid];
525 ENSURE_VALID_ID_ACCESSOR(
id);
526 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
527 return m_previousDistribution[
id * noDistributions() + eid];
532 ENSURE_VALID_ID_ACCESSOR(
id);
533 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
534 return m_previousDistribution[
id * noDistributions() + eid];
539 ENSURE_VALID_ID_ACCESSOR(
id);
540 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
541 return m_previousVariable[
id * noVariables() + eid];
546 ENSURE_VALID_ID_ACCESSOR(
id);
547 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
548 return m_previousVariable[
id * noVariables() + eid];
553 ENSURE_VALID_ID_ACCESSOR(
id);
559 ENSURE_VALID_ID_ACCESSOR(
id);
565 ENSURE_VALID_ID_ACCESSOR(
id);
566 return m_uOtherPhase[
id * nDim + dir];
571 ENSURE_VALID_ID_ACCESSOR(
id);
572 return m_uOtherPhase[
id * nDim + dir];
577 ENSURE_VALID_ID_ACCESSOR(
id);
578 return m_invVolumeFraction[
id];
583 ENSURE_VALID_ID_ACCESSOR(
id);
584 return m_invVolumeFraction[
id];
589 ENSURE_VALID_ID_ACCESSOR(
id);
595 ENSURE_VALID_ID_ACCESSOR(
id);
601#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
602 return m_distributionsThermal[eid * noCells() +
id];
604 ENSURE_VALID_ID_ACCESSOR(
id);
605 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
606 return m_distributionsThermal[
id * noDistributions() + eid];
612#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
613 return m_distributionsThermal[eid * noCells() +
id];
615 ENSURE_VALID_ID_ACCESSOR(
id);
616 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
617 return m_distributionsThermal[
id * noDistributions() + eid];
623#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
624 return m_oldDistributionsThermal[eid * noCells() +
id];
626 ENSURE_VALID_ID_ACCESSOR(
id);
627 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
628 return m_oldDistributionsThermal[
id * noDistributions() + eid];
634#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
635 return m_oldDistributionsThermal[eid * noCells() +
id];
637 ENSURE_VALID_ID_ACCESSOR(
id);
638 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
639 return m_oldDistributionsThermal[
id * noDistributions() + eid];
645#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
646 return m_distributionsTransport[eid * noCells() +
id];
648 ENSURE_VALID_ID_ACCESSOR(
id);
649 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
650 return m_distributionsTransport[
id * noDistributions() + eid];
655#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
656 return m_distributionsTransport[eid * noCells() +
id];
658 ENSURE_VALID_ID_ACCESSOR(
id);
659 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
660 return m_distributionsTransport[
id * noDistributions() + eid];
665 ENSURE_VALID_ID_ACCESSOR(
id);
666 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
667 return m_externalForces[
id * nDim + eid];
672 ENSURE_VALID_ID_ACCESSOR(
id);
673 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
674 return m_externalForces[
id * nDim + eid];
679#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
680 return m_oldDistributionsTransport[eid * noCells() +
id];
682 ENSURE_VALID_ID_ACCESSOR(
id);
683 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
684 return m_oldDistributionsTransport[
id * noDistributions() + eid];
689#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
690 return m_oldDistributionsTransport[eid * noCells() +
id];
692 ENSURE_VALID_ID_ACCESSOR(
id);
693 ENSURE_VALID_DISTRIBUTION_ID_ACCESSOR(eid);
694 return m_oldDistributionsTransport[
id * noDistributions() + eid];
700 ENSURE_VALID_ID_ACCESSOR(
id);
701 ENSURE_VALID_PROPERTY_ACCESSOR(p);
707 ENSURE_VALID_ID_ACCESSOR(
id);
708 ENSURE_VALID_PROPERTY_ACCESSOR(p);
714 ENSURE_VALID_ID_ACCESSOR(
id);
715 m_properties[
id].reset();
721 ENSURE_VALID_ID_ACCESSOR(
id);
722 return m_properties[
id];
728 m_isThermal = isThermal_;
734 m_useTransport = useTransport_;
740 if(isThermal() && !useTransport()) {
742 m_noVariables = 1 + nDim + 1;
743 }
else if(!isThermal() && useTransport()) {
747 m_noVariables = 1 + nDim + 2;
748 }
else if(isThermal() && useTransport()) {
750 m_noVariables = 1 + nDim + 2;
753 m_noVariables = 1 + nDim;
759 m_saveUOtherPhase = saveUOtherPhase_;
764 m_saveVolumeFraction = saveVolumeFraction_;
769 m_savePrevVars = savePrevVars_;
774 m_saveNuT = saveNuT_;
779 m_saveOldNu = saveOldNu_;
785 m_noDistributions = noDistributions_;
792 fill_invalid(m_nu, begin, end);
794 fill_invalid(m_oldNu, begin, end);
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 );
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);
807 fill_invalid(m_distributionsThermal, begin, end, noDistributions());
808 fill_invalid(m_oldDistributionsThermal, begin, end, noDistributions());
811 fill_invalid(m_distributionsTransport, begin, end, noDistributions());
812 fill_invalid(m_oldDistributionsTransport, begin, end, noDistributions());
815 fill_invalid(m_previousDistribution, begin, end, noDistributions());
816 fill_invalid(m_previousVariable, begin, end, noVariables());
819 fill_invalid(m_nuT, begin, end);
821 fill_invalid(m_oldNuT, begin, end);
824 if(saveUOtherPhase()) {
825 fill_invalid(m_uOtherPhase, begin, end, nDim);
827 if(saveVolumeFraction()) {
828 fill_invalid(m_invVolumeFraction, begin, end);
832 fill_invalid(m_properties, begin, end);
838template <
class Functor,
class T>
840 const MInt destination) {
842 copyData(source.m_nu, m_nu, c, begin, end, destination);
844 copyData(source.m_oldNu, m_oldNu, c, begin, end, destination);
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);
857 copyData(source.m_distributionsThermal, m_distributionsThermal, c, begin, end, destination, noDistributions());
858 copyData(source.m_oldDistributionsThermal, m_oldDistributionsThermal, c, begin, end, destination,
862 copyData(source.m_distributionsTransport, m_distributionsTransport, c, begin, end, destination, noDistributions());
863 copyData(source.m_oldDistributionsTransport, m_oldDistributionsTransport, c, begin, end, destination,
867 copyData(source.m_previousDistribution, m_previousDistribution, c, begin, end, destination, noDistributions());
868 copyData(source.m_previousVariable, m_previousVariable, c, begin, end, destination, noVariables());
871 copyData(source.m_nuT, m_nuT, c, begin, end, destination);
873 copyData(source.m_oldNuT, m_oldNuT, c, begin, end, destination);
876 if(saveUOtherPhase()) {
877 copyData(source.m_uOtherPhase, m_uOtherPhase, c, begin, end, destination, nDim);
879 if(saveVolumeFraction()) {
880 copyData(source.m_invVolumeFraction, m_invVolumeFraction, c, begin, end, destination);
884 copyData(source.m_properties, m_properties, c, begin, end, destination);
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
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.
constexpr MInt size() const
Return size (i.e., currently used number of nodes)
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 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_)
MFloat & oldNu(const MInt id)
MFloat & nuT(const MInt id)
void setTransport(const MBool useTransport_)
Allow setting whether to support transport computations.
constexpr MInt noCells() const
Return number of cells.
constexpr MInt saveUOtherPhase() const
constexpr MInt savePrevVars() const
void setSaveUOtherPhase(const MBool saveUOtherPhase_)
void setSaveOldNu(const MBool saveOldNu_)
Storage< MFloat > m_variables
MFloat & previousVariable(const MInt id, const MInt eid)
Storage< MFloat > m_invVolumeFraction
Storage< MFloat > m_distributions
constexpr MInt saveOldNu() const
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)
MBool m_saveVolumeFraction
void resetProperties(const MInt id)
Reset all properties.
MInt m_noVariables
Number of variables.
BitsetType & allProperties(const MInt id)
Accessor for properties.
Storage< MFloat > m_diffusivity
Storage< MFloat > m_oldNuT
typename maia::lb::collector::Invalid< T > Invalid
MBool m_useTransport
Use transport model.
Storage< MFloat > m_externalForces
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_)
Storage< MFloat > m_kappa
MFloat & nu(const MInt id)
Accessor for nu.
MInt & bndId(const MInt id)
Accessor for bndId.
Storage< MFloat > m_oldVariables
MFloat & oldDistributionsTransport(const MInt id, const MInt eid)
constexpr MInt saveNuT() const
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.
Storage< MFloat > m_distributionsTransport
BitsetType::reference hasProperty(const MInt id, const LbCell p)
Accessor for properties.
Storage< MFloat > m_oldDistributionsTransport
Storage< MFloat > m_oldDistributions
MFloat & oldVariables(const MInt id, const MInt eid)
constexpr MInt isThermal() const
Return number of species.
Storage< MFloat > m_uOtherPhase
Storage< MFloat > m_distributionsThermal
constexpr MInt noVariables() const
Return number of variables.
Storage< BitsetType > m_properties
constexpr MInt noDistributions() const
Return number of distributions.
MFloat * oldVariables_ptr()
MFloat & kappa(const MInt id)
Accessor for kappa.
Storage< MFloat > m_spongeFactor
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.
Storage< MFloat > m_previousDistribution
MFloat & oldNuT(const MInt id)
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)
Storage< MFloat > m_oldDistributionsThermal
Storage< MFloat > m_previousVariable
Storage< MFloat > m_oldNu
MFloat & oldDistributions(const MInt id, const MInt eid)
LbCell
LB cell Property Labels.
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.
static constexpr MFloat value()
static constexpr MInt value()