VTK  9.6.20260315
vtkAMReXGridReaderInternal.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
10
11#ifndef vtkAMReXGridReaderInternal_h
12#define vtkAMReXGridReaderInternal_h
13
14#include <map>
15#include <string>
16#include <vector>
17
18#include "vtkDataSet.h"
20
21VTK_ABI_NAMESPACE_BEGIN
22class vtkIndent;
23
24//==============================================================================
25// I N T E R N A L A M R e X R E A D E R
26//==============================================================================
27
28// ----------------------------------------------------------------------------
29// Class RealDecriptor (begin)
30// ----------------------------------------------------------------------------
31
32/*
33 floating point format specification (fmt):
34 - fmt[0] = # of bits per number
35 - fmt[1] = # of bits in exponent
36 - fmt[2] = # of bits in mantissa
37 - fmt[3] = start bit of sign
38 - fmt[4] = start bit of exponent
39 - fmt[5] = start bit of mantissa
40 - fmt[6] = high order mantissa bit (CRAY needs this)
41 - fmt[7] = bias of exponent
42
43 64 11 52 0 1 12 0 1023 - IEEE Double
44
45 byte order (ord) handles endianness (and defines size such as float or double)
46 - ord[0] = byte in 1st byte
47 - ord[1] = byte in 2nd byte
48 - ord[2] = byte in 3rd byte
49 - ord[3] = byte in 4th byte
50 - ...
51*/
52
54{
55public:
57 RealDescriptor(const long* format, const int* order, int order_length);
58 const long* format() const&;
59 const std::vector<long>& formatarray() const&;
60 const int* order() const&;
61 const std::vector<int>& orderarray() const&;
62 std::size_t numBytes() const;
63 bool operator==(const RealDescriptor& rd) const;
64
65private:
66 std::vector<long> fr;
67 std::vector<int> ord;
68};
69
70// ----------------------------------------------------------------------------
71// Class RealDescriptor ( end )
72// ----------------------------------------------------------------------------
73
74// ----------------------------------------------------------------------------
75// Class vtkAMReXGridHeader (begin)
76// ----------------------------------------------------------------------------
77
79{
80public:
81 std::string versionName;
83 std::vector<std::string> variableNames;
84
85 // prefix string indicating a variable is a vector component
86 // Note: this prefix will be removed from any variable name
87 // whether or not the variable name is a properly formed
88 // vector variable name (contains a proper postfix)
89 std::string vectorNamePrefix = "amrexvec";
90
91 // delimiter must be the same after prefix and before postfix
92 char nameDelim = '_';
93
94 // variableNames map to (potentially a collection of) variableNames indices
95 std::map<std::string, std::vector<int>> parsedVariableNames;
96 std::map<std::string, std::vector<int>> extraMultiFabParsedVarNames;
97 std::map<std::string, int> extraMultiFabParsedVarMap;
98
99 int dim;
100 double time;
102 std::vector<double> problemDomainLoEnd;
103 std::vector<double> problemDomainHiEnd;
104 std::vector<int> refinementRatio;
105 std::vector<std::vector<std::vector<int>>> levelDomains;
106 std::vector<int> levelSteps;
107 std::vector<std::vector<double>> cellSize;
110 std::vector<int> levelSize;
111 std::vector<std::vector<std::vector<std::vector<double>>>> levelCells;
112 std::vector<std::string> levelPrefix;
113 std::vector<std::string> multiFabPrefix;
114
115 // use this to store the prefixes for extra multifabs appended to the end of the main header
117 // only allow one topology per multifab. 0 == vertex data, 3 == cell data
118 // edge and face data not supported
119 std::vector<int> extraMultiFabVarTopology;
120 // prefix for each multifab on each level [fab][level]
121 std::vector<std::vector<std::string>> extraMultiFabPrefixes;
122 // vector of variables stored on each fab [fab][variable]
123 std::vector<std::vector<std::string>> extraMultiFabVariables;
124
126
128
129 void PrintSelf(std::ostream& os, vtkIndent indent);
130 void PrintSelfGenericHeader(std::ostream& os, vtkIndent indent);
131 bool Parse(const std::string& headerData);
132 bool ParseGenericHeader(const std::string& headerData);
133
134 void SetVectorNamePrefix(const std::string& prefix);
135 void SetNameDelimiter(char delim);
136
137private:
138 // if the vectorNamePrefix is detected at the beginning of the name,
139 // remove it along with the expected x/y/z postfix. Otherwise, return
140 // the original string
141 std::string GetBaseVariableName(const std::string& name);
142
143 // returns 0 if postfix is x, 1 for y and 2 for z. returns -1 otherwise
144 int CheckComponent(const std::string& name);
145
146 // check if name has the vectorNamePrefix
147 bool HasVectorPrefix(const std::string& name);
148};
149
150// ----------------------------------------------------------------------------
151// Class vtkAMReXGridHeader ( end )
152// ----------------------------------------------------------------------------
153
154// ----------------------------------------------------------------------------
155// Class vtkAMReXGridLevelHeader (begin)
156// ----------------------------------------------------------------------------
157
159{
160 enum Version
161 {
162 Undefined_v1 = 0, // ---- undefined
163 Version_v1 = 1, // ---- auto converting version with headers
164 // ---- for each fab in the data files and
165 // ---- min and max values for each fab in the header
166 NoFabHeader_v1 = 2, // ---- no fab headers, no fab mins or maxes
167 NoFabHeaderMinMax_v1 = 3, // ---- no fab headers,
168 // ---- min and max values for each fab in the header
169 NoFabHeaderFAMinMax_v1 = 4 // ---- no fab headers, no fab mins or maxes,
170 // ---- min and max values for each FabArray in the header
171 };
172 enum Ordering
173 {
174 NormalOrder = 1,
175 ReverseOrder = 2
176 };
177
178public:
179 int level;
180 int dim;
187 std::vector<std::vector<std::vector<int>>> levelBoxArrays;
190 std::vector<std::string> levelFABFile;
191 std::vector<std::size_t> levelFileOffset;
192 std::vector<std::vector<double>> levelMinimumsFAB;
193 std::vector<std::vector<double>> levelMaximumsFAB;
194 std::vector<double> levelFABArrayMinimum;
195 std::vector<double> levelFABArrayMaximum;
199
201 void PrintSelf(std::ostream& os, vtkIndent indent);
202 void PrintSelfLevelHeader(std::ostream& os, vtkIndent indent);
203 bool Parse(int _level, int _dim, const std::string& headerData);
204 bool ParseLevelHeader(int _level, int _dim, const std::string& headerData);
205};
206
207// ----------------------------------------------------------------------------
208// Class vtkAMReXGridLevelHeader ( end )
209// ----------------------------------------------------------------------------
210
211// ----------------------------------------------------------------------------
212// Class vtkAMReXGridReaderInternal (begin)
213// ----------------------------------------------------------------------------
214
216{
217public:
222 void PrintSelf(std::ostream& os, vtkIndent indent);
223 void SetFileName(char* fName);
224
230 int GetBlockLevel(int blockIdx);
232 int GetBlockIndexWithinLevel(int blockIdx, int level);
233 void GetBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
234 void GetExtraMultiFabBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
235 vtkIdType GetOffsetOfAttribute(const char* attribute);
236 vtkIdType GetAttributeOffsetExtraMultiFab(const char* attribute, int fabIndex);
237 int GetExtraMultiFabIndex(const char* attribute);
238 void ReadFAB(std::istream& is);
239 int ReadVersion(std::istream& is);
240 void ReadOrder(std::istream& is, std::vector<int>& ar);
241 void PrintOrder(std::vector<int>& ar);
242 void ReadFormat(std::istream& is, std::vector<long>& ar);
243 void PrintFormat(std::vector<long>& ar);
245 std::size_t ReadBoxArray(std::istream& is, int* boxArray, int* boxArrayDim);
246 void PrintBoxArray(int* boxArray);
247 int ReadNumberOfAttributes(std::istream& is);
249 std::istream& is, std::size_t numberOfPoints, std::size_t size, char* buffer);
250 void Convert(void* out, const void* in, std::size_t nitems, const RealDescriptor& ord,
251 const RealDescriptor& ird);
252 void PermuteOrder(void* out, const void* in, std::size_t nitems, const int* outord,
253 const int* inord, std::size_t REALSIZE);
254
255 template <typename T>
257 const RealDescriptor* ird, const std::vector<std::vector<char>>& buffers,
258 std::size_t numberOfPoints, const std::string& attribute);
259
263 std::string FileName;
265 friend class vtkAMReXGridHeader;
266 std::vector<vtkAMReXGridLevelHeader*> LevelHeader;
267 std::vector<std::vector<vtkAMReXGridLevelHeader*>> ExtraMultiFabHeader;
269};
270
271template <typename T>
273 const RealDescriptor* ord, const RealDescriptor* ird,
274 const std::vector<std::vector<char>>& buffers, std::size_t numberOfPoints,
275 const std::string& attribute)
276{
277 int nComps = static_cast<int>(this->Header->parsedVariableNames[attribute].size());
278 if (nComps == 0) // check if the variable is in an extra fab
279 {
280 nComps = static_cast<int>(this->Header->extraMultiFabParsedVarNames[attribute].size());
281 }
282 if (nComps == 0)
283 {
284 return;
285 }
286 dataArray->SetName(attribute.c_str());
287 dataArray->SetNumberOfComponents(nComps);
288 dataArray->SetNumberOfTuples(numberOfPoints);
289 T* arrayPtr = new T[numberOfPoints];
290 for (int j = 0; j < nComps; ++j)
291 {
292 this->Convert(arrayPtr, buffers[j].data(), numberOfPoints, *ord, *ird);
293
294 // Copy to data array component
295 for (std::size_t i = 0; i < numberOfPoints; ++i)
296 {
297 dataArray->SetTypedComponent(i, j, arrayPtr[i]);
298 }
299 }
300 delete[] arrayPtr;
301}
302
303// ----------------------------------------------------------------------------
304// Class vtkAMReXGridReaderInternal ( end )
305// ----------------------------------------------------------------------------
306VTK_ABI_NAMESPACE_END
307#endif /* vtkAMReXGridReaderInternal_h */
308// VTK-HeaderTest-Exclude: vtkAMReXGridReaderInternal.h
const int * order() const &
const std::vector< long > & formatarray() const &
const std::vector< int > & orderarray() const &
std::size_t numBytes() const
const long * format() const &
RealDescriptor(const long *format, const int *order, int order_length)
void SetNameDelimiter(char delim)
std::vector< std::vector< double > > cellSize
std::vector< int > extraMultiFabVarTopology
std::vector< std::vector< std::string > > extraMultiFabVariables
std::vector< std::vector< std::vector< int > > > levelDomains
std::vector< double > problemDomainLoEnd
bool ParseGenericHeader(const std::string &headerData)
void PrintSelf(std::ostream &os, vtkIndent indent)
std::vector< std::vector< std::string > > extraMultiFabPrefixes
std::vector< double > problemDomainHiEnd
bool Parse(const std::string &headerData)
std::vector< std::string > multiFabPrefix
std::vector< std::string > levelPrefix
std::map< std::string, int > extraMultiFabParsedVarMap
std::vector< int > refinementRatio
std::vector< std::string > variableNames
std::map< std::string, std::vector< int > > parsedVariableNames
std::vector< std::vector< std::vector< std::vector< double > > > > levelCells
void PrintSelfGenericHeader(std::ostream &os, vtkIndent indent)
std::map< std::string, std::vector< int > > extraMultiFabParsedVarNames
void SetVectorNamePrefix(const std::string &prefix)
std::vector< double > levelFABArrayMaximum
std::vector< std::vector< std::vector< int > > > levelBoxArrays
std::vector< std::vector< double > > levelMaximumsFAB
std::vector< std::vector< double > > levelMinimumsFAB
void PrintSelf(std::ostream &os, vtkIndent indent)
void PrintSelfLevelHeader(std::ostream &os, vtkIndent indent)
std::vector< std::string > levelFABFile
bool ParseLevelHeader(int _level, int _dim, const std::string &headerData)
std::vector< std::size_t > levelFileOffset
std::vector< double > levelFABArrayMinimum
bool Parse(int _level, int _dim, const std::string &headerData)
void ReadFAB(std::istream &is)
void ReadFormat(std::istream &is, std::vector< long > &ar)
std::vector< vtkAMReXGridLevelHeader * > LevelHeader
void GetBlockAttribute(const char *attribute, int blockIdx, vtkDataSet *pDataSet)
void PrintSelf(std::ostream &os, vtkIndent indent)
vtkIdType GetAttributeOffsetExtraMultiFab(const char *attribute, int fabIndex)
RealDescriptor * ReadRealDescriptor(std::istream &is)
int GetBlockLevel(int blockIdx)
vtkIdType GetOffsetOfAttribute(const char *attribute)
void PrintBoxArray(int *boxArray)
int GetBlockIndexWithinLevel(int blockIdx, int level)
void Convert(void *out, const void *in, std::size_t nitems, const RealDescriptor &ord, const RealDescriptor &ird)
int ReadNumberOfAttributes(std::istream &is)
void PrintOrder(std::vector< int > &ar)
void CreateVTKAttributeArray(vtkAOSDataArrayTemplate< T > *dataArray, const RealDescriptor *ord, const RealDescriptor *ird, const std::vector< std::vector< char > > &buffers, std::size_t numberOfPoints, const std::string &attribute)
void PermuteOrder(void *out, const void *in, std::size_t nitems, const int *outord, const int *inord, std::size_t REALSIZE)
int GetExtraMultiFabIndex(const char *attribute)
void PrintFormat(std::vector< long > &ar)
void ReadBlockAttribute(std::istream &is, std::size_t numberOfPoints, std::size_t size, char *buffer)
int ReadVersion(std::istream &is)
std::vector< std::vector< vtkAMReXGridLevelHeader * > > ExtraMultiFabHeader
void SetFileName(char *fName)
void GetExtraMultiFabBlockAttribute(const char *attribute, int blockIdx, vtkDataSet *pDataSet)
std::size_t ReadBoxArray(std::istream &is, int *boxArray, int *boxArrayDim)
void ReadOrder(std::istream &is, std::vector< int > &ar)
Array-Of-Structs implementation of vtkGenericDataArray.
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
virtual void SetNumberOfTuples(vtkIdType numTuples)
Set the number of tuples (a component group) in the array.
virtual void SetName(const char *)
Set/get array's name.
abstract class to specify dataset behavior
Definition vtkDataSet.h:166
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
a simple class to control print indentation
Definition vtkIndent.h:108
int vtkIdType
Definition vtkType.h:363