VTK  9.2.6
vtkAMReXGridReaderInternal.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkAMReXGridReaderInternal.hpp
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
23#ifndef vtkAMReXGridReaderInternal_h
24#define vtkAMReXGridReaderInternal_h
25
26#include <map>
27#include <string>
28#include <vector>
29
30#include "vtkDataSet.h"
32
33class vtkIndent;
34
35//==============================================================================
36// I N T E R N A L A M R e X R E A D E R
37//==============================================================================
38
39// ----------------------------------------------------------------------------
40// Class RealDecriptor (begin)
41// ----------------------------------------------------------------------------
42
43/*
44 floating point format specification (fmt):
45 - fmt[0] = # of bits per number
46 - fmt[1] = # of bits in exponent
47 - fmt[2] = # of bits in mantissa
48 - fmt[3] = start bit of sign
49 - fmt[4] = start bit of exponent
50 - fmt[5] = start bit of mantissa
51 - fmt[6] = high order mantissa bit (CRAY needs this)
52 - fmt[7] = bias of exponent
53
54 64 11 52 0 1 12 0 1023 - IEEE Double
55
56 byte order (ord) handles endianness (and defines size such as float or double)
57 - ord[0] = byte in 1st byte
58 - ord[1] = byte in 2nd byte
59 - ord[2] = byte in 3rd byte
60 - ord[3] = byte in 4th byte
61 - ...
62*/
63
65{
66public:
68 RealDescriptor(const long* format, const int* order, int order_length);
69 const long* format() const&;
70 const std::vector<long>& formatarray() const&;
71 const int* order() const&;
72 const std::vector<int>& orderarray() const&;
73 int numBytes() const;
74 bool operator==(const RealDescriptor& rd) const;
75
76private:
77 std::vector<long> fr;
78 std::vector<int> ord;
79};
80
81// ----------------------------------------------------------------------------
82// Class RealDecriptor ( end )
83// ----------------------------------------------------------------------------
84
85// ----------------------------------------------------------------------------
86// Class vtkAMReXGridHeader (begin)
87// ----------------------------------------------------------------------------
88
90{
91public:
92 std::string versionName;
94 std::vector<std::string> variableNames;
95
96 // prefix string indicating a variable is a vector component
97 // Note: this prefix will be removed from any variable name
98 // whether or not the variable name is a properly formed
99 // vector variable name (contains a proper postfix)
100 std::string vectorNamePrefix = "amrexvec";
101
102 // delimeter must be the same after prefix and before postfix
103 char nameDelim = '_';
104
105 // variableNames map to (potentially a collection of) variableNames indices
106 std::map<std::string, std::vector<int>> parsedVariableNames;
107 std::map<std::string, std::vector<int>> extraMultiFabParsedVarNames;
108 std::map<std::string, int> extraMultiFabParsedVarMap;
109
110 int dim;
111 double time;
113 std::vector<double> problemDomainLoEnd;
114 std::vector<double> problemDomainHiEnd;
115 std::vector<int> refinementRatio;
116 std::vector<std::vector<std::vector<int>>> levelDomains;
117 std::vector<int> levelSteps;
118 std::vector<std::vector<double>> cellSize;
121 std::vector<int> levelSize;
122 std::vector<std::vector<std::vector<std::vector<double>>>> levelCells;
123 std::vector<std::string> levelPrefix;
124 std::vector<std::string> multiFabPrefix;
125
126 // use this to store the prefixes for extra multifabs appended to the end of the main header
128 // only allow one topology per multifab. 0 == vertex data, 3 == cell data
129 // edge and face data not supported
130 std::vector<int> extraMultiFabVarTopology;
131 // prefix for each multifab on each level [fab][level]
132 std::vector<std::vector<std::string>> extraMultiFabPrefixes;
133 // vector of variables stored on each fab [fab][variable]
134 std::vector<std::vector<std::string>> extraMultiFabVariables;
135
137
139
140 void PrintSelf(std::ostream& os, vtkIndent indent);
141 void PrintSelfGenericHeader(std::ostream& os, vtkIndent indent);
142 bool Parse(const std::string& headerData);
143 bool ParseGenericHeader(const std::string& headerData);
144
145 void SetVectorNamePrefix(const std::string& prefix);
146 void SetNameDelimiter(const char delim);
147
148private:
149 // if the vectorNamePrefix is detected at the beginning of the name,
150 // remove it along with the expected x/y/z postfix. Otherwise, return
151 // the original string
152 std::string GetBaseVariableName(const std::string& name);
153
154 // returns 0 if postfix is x, 1 for y and 2 for z. returns -1 otherwise
155 int CheckComponent(const std::string& name);
156
157 // check if name has the vectorNamePrefix
158 bool HasVectorPrefix(const std::string& name);
159};
160
161// ----------------------------------------------------------------------------
162// Class vtkAMReXGridHeader ( end )
163// ----------------------------------------------------------------------------
164
165// ----------------------------------------------------------------------------
166// Class vtkAMReXGridLevelHeader (begin)
167// ----------------------------------------------------------------------------
168
170{
171 enum Version
172 {
173 Undefined_v1 = 0, // ---- undefined
174 Version_v1 = 1, // ---- auto converting version with headers
175 // ---- for each fab in the data files and
176 // ---- min and max values for each fab in the header
177 NoFabHeader_v1 = 2, // ---- no fab headers, no fab mins or maxes
178 NoFabHeaderMinMax_v1 = 3, // ---- no fab headers,
179 // ---- min and max values for each fab in the header
180 NoFabHeaderFAMinMax_v1 = 4 // ---- no fab headers, no fab mins or maxes,
181 // ---- min and max values for each FabArray in the header
182 };
183 enum Ordering
184 {
185 NormalOrder = 1,
186 ReverseOrder = 2
187 };
188
189public:
190 int level;
191 int dim;
198 std::vector<std::vector<std::vector<int>>> levelBoxArrays;
201 std::vector<std::string> levelFABFile;
202 std::vector<long> levelFileOffset;
203 std::vector<std::vector<double>> levelMinimumsFAB;
204 std::vector<std::vector<double>> levelMaximumsFAB;
205 std::vector<double> levelFABArrayMinimum;
206 std::vector<double> levelFABArrayMaximum;
210
212 void PrintSelf(std::ostream& os, vtkIndent indent);
213 void PrintSelfLevelHeader(std::ostream& os, vtkIndent indent);
214 bool Parse(int _level, int _dim, const std::string& headerData);
215 bool ParseLevelHeader(int _level, int _dim, const std::string& headerData);
216};
217
218// ----------------------------------------------------------------------------
219// Class vtkAMReXGridLevelHeader ( end )
220// ----------------------------------------------------------------------------
221
222// ----------------------------------------------------------------------------
223// Class vtkAMReXGridReaderInternal (begin)
224// ----------------------------------------------------------------------------
225
227{
228public:
233 void PrintSelf(std::ostream& os, vtkIndent indent);
234 void SetFileName(char* fName);
235
241 int GetBlockLevel(const int blockIdx);
243 int GetBlockIndexWithinLevel(int blockIdx, int level);
244 void GetBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
245 void GetExtraMultiFabBlockAttribute(const char* attribute, int blockIdx, vtkDataSet* pDataSet);
246 int GetOffsetOfAttribute(const char* attribute);
247 int GetAttributeOffsetExtraMultiFab(const char* attribute, const int fabIndex);
248 int GetExtraMultiFabIndex(const char* attribute);
249 void ReadFAB(std::istream& is);
250 int ReadVersion(std::istream& is);
251 void ReadOrder(std::istream& is, std::vector<int>& ar);
252 void PrintOrder(std::vector<int>& ar);
253 void ReadFormat(std::istream& is, std::vector<long>& ar);
254 void PrintFormat(std::vector<long>& ar);
256 int ReadBoxArray(std::istream& is, int* boxArray, int* boxArrayDim);
257 void PrintBoxArray(int* boxArray);
258 int ReadNumberOfAttributes(std::istream& is);
259 void ReadBlockAttribute(std::istream& is, int numberOfPoints, int size, char* buffer);
261 void* out, const void* in, long nitems, const RealDescriptor& ord, const RealDescriptor& ird);
263 void* out, const void* in, long nitems, const int* outord, const int* inord, int REALSIZE);
264
265 template <typename T>
266 void CreateVTKAttributeArray(vtkAOSDataArrayTemplate<T>* dataArray, const RealDescriptor* ord,
267 const RealDescriptor* ird, const std::vector<std::vector<char>>& buffers,
268 const int numberOfPoints, const std::string& attribute);
269
273 std::string FileName;
275 friend class vtkAMReXGridHeader;
276 std::vector<vtkAMReXGridLevelHeader*> LevelHeader;
277 std::vector<std::vector<vtkAMReXGridLevelHeader*>> ExtraMultiFabHeader;
278 friend class vtkAMReXGridLeveHeader;
279};
280
281template <typename T>
283 const RealDescriptor* ord, const RealDescriptor* ird,
284 const std::vector<std::vector<char>>& buffers, const int numberOfPoints,
285 const std::string& attribute)
286{
287 int nComps = static_cast<int>(this->Header->parsedVariableNames[attribute].size());
288 if (nComps == 0) // check if the variable is in an extra fab
289 {
290 nComps = static_cast<int>(this->Header->extraMultiFabParsedVarNames[attribute].size());
291 }
292 if (nComps == 0)
293 {
294 return;
295 }
296 dataArray->SetName(attribute.c_str());
297 dataArray->SetNumberOfComponents(nComps);
298 dataArray->SetNumberOfTuples(numberOfPoints);
299 T* arrayPtr = new T[numberOfPoints];
300 for (int j = 0; j < nComps; ++j)
301 {
302 this->Convert(arrayPtr, buffers[j].data(), numberOfPoints, *ord, *ird);
303
304 // Copy to data array component
305 for (int i = 0; i < numberOfPoints; ++i)
306 {
307 dataArray->SetTypedComponent(i, j, arrayPtr[i]);
308 }
309 }
310 delete[] arrayPtr;
311}
312
313// ----------------------------------------------------------------------------
314// Class vtkAMReXGridReaderInternal ( end )
315// ----------------------------------------------------------------------------
316#endif /* vtkAMReXGridReaderInternal_h */
317// VTK-HeaderTest-Exclude: vtkAMReXGridReaderInternal.h
const int * order() const &
const std::vector< long > & formatarray() const &
const std::vector< int > & orderarray() const &
int numBytes() const
const long * format() const &
RealDescriptor(const long *format, const int *order, int order_length)
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
void SetNameDelimiter(const char delim)
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< double > levelFABArrayMinimum
bool Parse(int _level, int _dim, const std::string &headerData)
Consists of the low-level AMReX Reader used by the vtkAMReXGridReader.
void ReadFAB(std::istream &is)
void ReadFormat(std::istream &is, std::vector< long > &ar)
void Convert(void *out, const void *in, long nitems, const RealDescriptor &ord, const RealDescriptor &ird)
int GetOffsetOfAttribute(const char *attribute)
int GetBlockLevel(const int blockIdx)
std::vector< vtkAMReXGridLevelHeader * > LevelHeader
void GetBlockAttribute(const char *attribute, int blockIdx, vtkDataSet *pDataSet)
void PrintSelf(std::ostream &os, vtkIndent indent)
void ReadBlockAttribute(std::istream &is, int numberOfPoints, int size, char *buffer)
RealDescriptor * ReadRealDescriptor(std::istream &is)
int ReadBoxArray(std::istream &is, int *boxArray, int *boxArrayDim)
void PermuteOrder(void *out, const void *in, long nitems, const int *outord, const int *inord, int REALSIZE)
void PrintBoxArray(int *boxArray)
int GetBlockIndexWithinLevel(int blockIdx, int level)
int ReadNumberOfAttributes(std::istream &is)
void PrintOrder(std::vector< int > &ar)
int GetAttributeOffsetExtraMultiFab(const char *attribute, const int fabIndex)
int GetExtraMultiFabIndex(const char *attribute)
void PrintFormat(std::vector< long > &ar)
int ReadVersion(std::istream &is)
std::vector< std::vector< vtkAMReXGridLevelHeader * > > ExtraMultiFabHeader
void SetFileName(char *fName)
void GetExtraMultiFabBlockAttribute(const char *attribute, int blockIdx, vtkDataSet *pDataSet)
void CreateVTKAttributeArray(vtkAOSDataArrayTemplate< T > *dataArray, const RealDescriptor *ord, const RealDescriptor *ird, const std::vector< std::vector< char > > &buffers, const int numberOfPoints, const std::string &attribute)
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 SetName(const char *)
Set/get array's name.
abstract class to specify dataset behavior
Definition vtkDataSet.h:63
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
a simple class to control print indentation
Definition vtkIndent.h:40