-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOVTimeStepImage.cxx
237 lines (211 loc) · 8.04 KB
/
BOVTimeStepImage.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
____ _ __ ____ __ ____
/ __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
_\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
/___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
Copyright 2012 SciberQuest Inc.
*/
#include "BOVTimeStepImage.h"
#include "BOVScalarImage.h"
#include "BOVVectorImage.h"
#include "BOVMetaData.h"
#include "SQMacros.h"
#include <sstream>
using std::ostringstream;
#ifdef WIN32
#define PATH_SEP "\\"
#else
#define PATH_SEP "/"
#endif
//-----------------------------------------------------------------------------
BOVTimeStepImage::BOVTimeStepImage(
MPI_Comm comm,
MPI_Info hints,
int stepIdx,
BOVMetaData *metaData)
{
#ifdef SQTK_WITHOUT_MPI
sqErrorMacro(
cerr,
<< "This class requires MPI but it was built without MPI.");
#else
int mpiMode=0;
if (metaData->ReadMode())
{
mpiMode=MPI_MODE_RDONLY;
}
else
if (metaData->WriteMode())
{
mpiMode=MPI_MODE_WRONLY|MPI_MODE_CREATE;
}
else
{
sqErrorMacro(cerr,"Invalid mode " << metaData->GetMode());
}
ostringstream seriesExt;
seriesExt << "_" << stepIdx << "." << metaData->GetBrickFileExtension();
// Open each array.
size_t nArrays=metaData->GetNumberOfArrays();
for (size_t i=0; i<nArrays; ++i)
{
const char *arrayName=metaData->GetArrayName(i);
// skip inactive arrays
if (!metaData->IsArrayActive(arrayName))
{
continue;
}
// scalar
if (metaData->IsArrayScalar(arrayName))
{
// deduce the file name from the following convention:
// arrayname_step.ext
ostringstream fileName;
fileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << seriesExt.str();
// open
BOVScalarImage *scalar
= new BOVScalarImage(comm,hints,fileName.str().c_str(),arrayName,mpiMode);
this->Scalars.push_back(scalar);
}
// vector
else
if (metaData->IsArrayVector(arrayName))
{
// deduce the file name from the following convention:
// arrayname{x,y,z}_step.ext
ostringstream xFileName,yFileName,zFileName;
xFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "x" << seriesExt.str();
yFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "y" << seriesExt.str();
zFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "z" << seriesExt.str();
// open
BOVVectorImage *vector = new BOVVectorImage;
vector->SetName(arrayName);
vector->SetNumberOfComponents(3);
vector->SetComponentFile(0,comm,hints,xFileName.str().c_str(),mpiMode);
vector->SetComponentFile(1,comm,hints,yFileName.str().c_str(),mpiMode);
vector->SetComponentFile(2,comm,hints,zFileName.str().c_str(),mpiMode);
this->Vectors.push_back(vector);
}
// tensor
else
if (metaData->IsArrayTensor(arrayName))
{
// deduce the file name from the following convention:
// arrayname{xx,xy, ... ,zz}_step.ext
ostringstream
xxFileName,xyFileName,xzFileName,
yxFileName,yyFileName,yzFileName,
zxFileName,zyFileName,zzFileName;
xxFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xx" << seriesExt.str();
xyFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xy" << seriesExt.str();
xzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xz" << seriesExt.str();
yxFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-yx" << seriesExt.str();
yyFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-yy" << seriesExt.str();
yzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-yz" << seriesExt.str();
zxFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-zx" << seriesExt.str();
zyFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-zy" << seriesExt.str();
zzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-zz" << seriesExt.str();
// open
BOVVectorImage *tensor = new BOVVectorImage;
tensor->SetName(arrayName);
tensor->SetNumberOfComponents(9);
tensor->SetComponentFile(0,comm,hints,xxFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(1,comm,hints,xyFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(2,comm,hints,xzFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(3,comm,hints,yxFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(4,comm,hints,yyFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(5,comm,hints,yzFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(6,comm,hints,zxFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(7,comm,hints,zyFileName.str().c_str(),mpiMode);
tensor->SetComponentFile(8,comm,hints,zzFileName.str().c_str(),mpiMode);
this->Tensors.push_back(tensor);
}
// symetric tensor
else
if (metaData->IsArraySymetricTensor(arrayName))
{
// deduce the file name from the following convention:
// arrayname{xx,xy, ... ,zz}_step.ext
ostringstream
xxFileName,xyFileName,xzFileName,
yyFileName,yzFileName,
zzFileName;
xxFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xx" << seriesExt.str();
xyFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xy" << seriesExt.str();
xzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-xz" << seriesExt.str();
yyFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-yy" << seriesExt.str();
yzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-yz" << seriesExt.str();
zzFileName << metaData->GetPathToBricks() << PATH_SEP << arrayName << "-zz" << seriesExt.str();
// open
BOVVectorImage *symTensor = new BOVVectorImage;
symTensor->SetName(arrayName);
symTensor->SetNumberOfComponents(6);
symTensor->SetComponentFile(0,comm,hints,xxFileName.str().c_str(),mpiMode);
symTensor->SetComponentFile(1,comm,hints,xyFileName.str().c_str(),mpiMode);
symTensor->SetComponentFile(2,comm,hints,xzFileName.str().c_str(),mpiMode);
symTensor->SetComponentFile(3,comm,hints,yyFileName.str().c_str(),mpiMode);
symTensor->SetComponentFile(4,comm,hints,yzFileName.str().c_str(),mpiMode);
symTensor->SetComponentFile(5,comm,hints,zzFileName.str().c_str(),mpiMode);
this->SymetricTensors.push_back(symTensor);
}
// other ?
else
{
sqErrorMacro(cerr,"Bad array type for array " << arrayName << ".");
}
}
#endif
}
//-----------------------------------------------------------------------------
BOVTimeStepImage::~BOVTimeStepImage()
{
int nScalars=this->Scalars.size();
for (int i=0; i<nScalars; ++i)
{
delete this->Scalars[i];
}
int nVectors=this->Vectors.size();
for (int i=0; i<nVectors; ++i)
{
delete this->Vectors[i];
}
int nTensors=this->Tensors.size();
for (int i=0; i<nTensors; ++i)
{
delete this->Tensors[i];
}
int nSymetricTensors=this->SymetricTensors.size();
for (int i=0; i<nSymetricTensors; ++i)
{
delete this->SymetricTensors[i];
}
}
//-----------------------------------------------------------------------------
ostream &operator<<(ostream &os, const BOVTimeStepImage &si)
{
os << "Scalars:" << endl;
int nScalars=si.Scalars.size();
for (int i=0; i<nScalars; ++i)
{
os << *si.Scalars[i] << endl;
}
os << "Vectors:" << endl;
int nVectors=si.Vectors.size();
for (int i=0; i<nVectors; ++i)
{
os << *si.Vectors[i] << endl;
}
os << "Tensors:" << endl;
int nTensors=si.Tensors.size();
for (int i=0; i<nTensors; ++i)
{
os << *si.Tensors[i] << endl;
}
os << "SymetricTensors:" << endl;
int nSymetricTensors=si.SymetricTensors.size();
for (int i=0; i<nSymetricTensors; ++i)
{
os << *si.SymetricTensors[i] << endl;
}
return os;
}