VTK  9.6.20260516
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 // Topology of the main multifab, detected from level-header box type vectors.
116 // Encoded with the same convention as extraMultiFabVarTopology:
117 // 3 == cell data (default), 0 == vertex/nodal data, -1 == unsupported (face/edge).
119
120 // use this to store the prefixes for extra multifabs appended to the end of the main header
122 // only allow one topology per multifab. 0 == vertex data, 3 == cell data
123 // edge and face data not supported
124 std::vector<int> extraMultiFabVarTopology;
125 // prefix for each multifab on each level [fab][level]
126 std::vector<std::vector<std::string>> extraMultiFabPrefixes;
127 // vector of variables stored on each fab [fab][variable]
128 std::vector<std::vector<std::string>> extraMultiFabVariables;
129
131
133
134 void PrintSelf(std::ostream& os, vtkIndent indent);
135 void PrintSelfGenericHeader(std::ostream& os, vtkIndent indent);
136 bool Parse(const std::string& headerData);
137 bool ParseGenericHeader(const std::string& headerData);
138
139 void SetVectorNamePrefix(const std::string& prefix);
140 void SetNameDelimiter(char delim);
141
142private:
143 // if the vectorNamePrefix is detected at the beginning of the name,
144 // remove it along with the expected x/y/z postfix. Otherwise, return
145 // the original string
146 std::string GetBaseVariableName(const std::string& name);
147
148 // returns 0 if postfix is x, 1 for y and 2 for z. returns -1 otherwise
149 int CheckComponent(const std::string& name);
150
151 // check if name has the vectorNamePrefix
152 bool HasVectorPrefix(const std::string& name);
153};
154
155// ----------------------------------------------------------------------------
156// Class vtkAMReXGridHeader ( end )
157// ----------------------------------------------------------------------------
158
159// ----------------------------------------------------------------------------
160// Class vtkAMReXGridLevelHeader (begin)
161// ----------------------------------------------------------------------------
162
164{
165 enum Version
166 {
167 Undefined_v1 = 0, // ---- undefined
168 Version_v1 = 1, // ---- auto converting version with headers
169 // ---- for each fab in the data files and
170 // ---- min and max values for each fab in the header
171 NoFabHeader_v1 = 2, // ---- no fab headers, no fab mins or maxes
172 NoFabHeaderMinMax_v1 = 3, // ---- no fab headers,
173 // ---- min and max values for each fab in the header
174 NoFabHeaderFAMinMax_v1 = 4 // ---- no fab headers, no fab mins or maxes,
175 // ---- min and max values for each FabArray in the header
176 };
177 enum Ordering
178 {
179 NormalOrder = 1,
180 ReverseOrder = 2
181 };
182
183public:
184 int level;
185 int dim;
192 std::vector<std::vector<std::vector<int>>> levelBoxArrays;
195 std::vector<std::string> levelFABFile;
196 std::vector<std::size_t> levelFileOffset;
197 std::vector<std::vector<double>> levelMinimumsFAB;
198 std::vector<std::vector<double>> levelMaximumsFAB;
199 std::vector<double> levelFABArrayMinimum;
200 std::vector<double> levelFABArrayMaximum;
204
206 void PrintSelf(std::ostream& os, vtkIndent indent);
207 void PrintSelfLevelHeader(std::ostream& os, vtkIndent indent);
208 bool Parse(int _level, int _dim, const std::string& headerData);
209 bool ParseLevelHeader(int _level, int _dim, const std::string& headerData);
210};
211
212// ----------------------------------------------------------------------------
213// Class vtkAMReXGridLevelHeader ( end )
214// ----------------------------------------------------------------------------
215
216// ----------------------------------------------------------------------------
217// Class vtkAMReXGridReaderInternal (begin)
218// ----------------------------------------------------------------------------
219
221{
222public:
227 void PrintSelf(std::ostream& os, vtkIndent indent);
228 void SetFileName(char* fName);
229
235 int GetBlockLevel(int blockIdx);
237 int GetBlockIndexWithinLevel(int blockIdx, int level);
238 void GetBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
239 void GetExtraMultiFabBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
240 vtkIdType GetOffsetOfAttribute(const char* attribute);
241 vtkIdType GetAttributeOffsetExtraMultiFab(const char* attribute, int fabIndex);
242 int GetExtraMultiFabIndex(const char* attribute);
243 void ReadFAB(std::istream& is);
244 int ReadVersion(std::istream& is);
245 void ReadOrder(std::istream& is, std::vector<int>& ar);
246 void PrintOrder(std::vector<int>& ar);
247 void ReadFormat(std::istream& is, std::vector<long>& ar);
248 void PrintFormat(std::vector<long>& ar);
250 std::size_t ReadBoxArray(std::istream& is, int* boxArray, int* boxArrayDim);
251 void PrintBoxArray(int* boxArray);
252 int ReadNumberOfAttributes(std::istream& is);
254 std::istream& is, std::size_t numberOfPoints, std::size_t size, char* buffer);
255 void Convert(void* out, const void* in, std::size_t nitems, const RealDescriptor& ord,
256 const RealDescriptor& ird);
257 void PermuteOrder(void* out, const void* in, std::size_t nitems, const int* outord,
258 const int* inord, std::size_t REALSIZE);
259
260 template <typename T>
262 const RealDescriptor* ird, const std::vector<std::vector<char>>& buffers,
263 std::size_t numberOfPoints, const std::string& attribute);
264
268 std::string FileName;
270 friend class vtkAMReXGridHeader;
271 std::vector<vtkAMReXGridLevelHeader*> LevelHeader;
272 std::vector<std::vector<vtkAMReXGridLevelHeader*>> ExtraMultiFabHeader;
274};
275
276template <typename T>
278 const RealDescriptor* ord, const RealDescriptor* ird,
279 const std::vector<std::vector<char>>& buffers, std::size_t numberOfPoints,
280 const std::string& attribute)
281{
282 int nComps = static_cast<int>(this->Header->parsedVariableNames[attribute].size());
283 if (nComps == 0) // check if the variable is in an extra fab
284 {
285 nComps = static_cast<int>(this->Header->extraMultiFabParsedVarNames[attribute].size());
286 }
287 if (nComps == 0)
288 {
289 return;
290 }
291 dataArray->SetName(attribute.c_str());
292 dataArray->SetNumberOfComponents(nComps);
293 dataArray->SetNumberOfTuples(numberOfPoints);
294 T* arrayPtr = new T[numberOfPoints];
295 for (int j = 0; j < nComps; ++j)
296 {
297 this->Convert(arrayPtr, buffers[j].data(), numberOfPoints, *ord, *ird);
298
299 // Copy to data array component
300 for (std::size_t i = 0; i < numberOfPoints; ++i)
301 {
302 dataArray->SetTypedComponent(i, j, arrayPtr[i]);
303 }
304 }
305 delete[] arrayPtr;
306}
307
308// ----------------------------------------------------------------------------
309// Class vtkAMReXGridReaderInternal ( end )
310// ----------------------------------------------------------------------------
311VTK_ABI_NAMESPACE_END
312#endif /* vtkAMReXGridReaderInternal_h */
313// 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