Loading [MathJax]/extensions/tex2jax.js
MAIA bb96820c
Multiphysics at AIA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
postcartesiancellcollector.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 POSTCELLCOLLECTOR_H_
8#define POSTCELLCOLLECTOR_H_
9
10#include "postcellproperties.h"
11#include "property.h"
12
14namespace maia {
15namespace post {
16namespace collector {
17
20
21// Type traits for invalid values. These values are used to initialize/erase nodes
22template <class T>
23struct Invalid {};
24
25// Invalid value for ids is 'INT_MIN'
26template <>
27struct Invalid<MInt> {
28 static constexpr MInt value() { return std::numeric_limits<MInt>::min(); }
29};
30
31// Invalid value for floats is 'NaN'
32template <>
33struct Invalid<MFloat> {
34 static constexpr MFloat value() {
35#ifdef MAIA_PGI_COMPILER
36 return std::numeric_limits<MFloat>::quiet_NaN();
37#else
38 return std::numeric_limits<MFloat>::signaling_NaN();
39#endif
40 }
41};
42
43// Invalid value for BitsetProperties is '0'
44template <>
46 static constexpr BitsetType value() { return BitsetType(0); }
47};
48
50template <MInt nDim>
51class PostCellCollector : public maia::container::Container<PostCellCollector<nDim>, Invalid> {
52 // Necessary for CRTP
54
55 // Make base class functions known to use without this pointer
58 template <class T>
59 using Storage = typename Base::template Storage<T>;
61
62 public:
63 // Types
64 template <class T>
66
67 // Constructors
69 constexpr PostCellCollector() = default;
70
71 using Base::copyData;
73 using Base::reset;
74
75 MFloat& variable(const MInt id, const MInt dim);
76 MFloat variable(const MInt id, const MInt dim) const;
77
79 constexpr MInt noVariables() const { return m_noVariables; }
80
81 // Property-related accessors
82 BitsetType::reference hasProperty(const MInt id, const PostCell p);
83 MBool hasProperty(const MInt id, const PostCell p) const;
84 void resetProperties(const MInt id);
85 BitsetType& properties(const MInt id);
86
87 // Allow setting number of species and rans variables
88 void setNoVariables(const MInt noVars_);
89
90 private:
93
94 // Data containers
97
98 // Methods required by base class for CRTP
99 void reset();
100 void invalidate(const MInt begin, const MInt end);
101 template <class Functor, class T>
102 void rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end, const MInt destination);
103};
104
105
106template <MInt nDim>
108 m_noVariables = noVars_;
109}
110
112template <MInt nDim>
114 resetStorage(noVariables(), m_Variables);
115 resetStorage(1, m_properties);
116}
117
119template <MInt nDim>
121 return m_Variables[id * noVariables() + varId];
122}
123
125template <MInt nDim>
126MFloat PostCellCollector<nDim>::variable(const MInt id, const MInt varId) const {
127 return m_Variables[id * noVariables() + varId];
128}
129
131template <MInt nDim>
132BitsetType::reference PostCellCollector<nDim>::hasProperty(const MInt id, const PostCell p) {
133 return m_properties[id][maia::post::cell::p(p)];
134}
135
137template <MInt nDim>
139 return m_properties[id][maia::post::cell::p(p)];
140}
141
143template <MInt nDim>
145 m_properties.at(id).reset();
146}
147
149template <MInt nDim>
150void PostCellCollector<nDim>::invalidate(const MInt begin, const MInt end) {
151 // variables
152 fill_invalid(m_Variables, begin, end, noVariables());
153
154 // Properties
155 fill_invalid(m_properties, begin, end);
156}
157
159template <MInt nDim>
161 // ENSURE_VALID_ID_ACCESSOR(id);
162 return m_properties[id];
163}
164
166template <MInt nDim>
167template <class Functor, class T>
168void PostCellCollector<nDim>::rawCopyGeneric(Functor&& c, const T& source, const MInt begin, const MInt end,
169 const MInt destination) {
170 // variables
171 copyData(source.m_Variables, m_Variables, c, begin, end, destination, noVariables());
172 // Properties
173 copyData(source.m_properties, m_properties, c, begin, end, destination);
174}
175
176
177} // namespace collector
178} // namespace post
179} // namespace maia
180
181#endif // ifndef POSTCELLCOLLECTOR_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 Post cell collector.
constexpr PostCellCollector()=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.
void resetProperties(const MInt id)
Reset all properties.
Storage< BitsetType > m_properties
maia::post::cell::BitsetType BitsetType
Storage< MFloat > m_Variables
void setNoVariables(const MInt noVars_)
constexpr MInt noVariables() const
Return number of variables.
BitsetType::reference hasProperty(const MInt id, const PostCell p)
Accessor for properties.
typename maia::post::collector::Invalid< T > Invalid
MInt m_noVariables
Number of variables.
MFloat & variable(const MInt id, const MInt dim)
Accessor for variables.
typename Base::template Storage< T > Storage
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
BitsetType & properties(const MInt id)
Accessor for properties.
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< PostCell >::type p(const PostCell property)
Converts property name to underlying integer value.
std::bitset< p(PostCell::NumProperties)> BitsetType
maia::post::cell::BitsetType BitsetType
Underlying bitset type for property storage.
Namespace for auxiliary functions/classes.
PostCell
POST cell Property Labels.