ensightOutputCase.H
Go to the documentation of this file.
1 // write time values to case file
2 
3 scalar timeCorrection = 0;
4 if (timeDirs[0].value() < 0)
5 {
6  timeCorrection = - timeDirs[0].value();
7  Info<< "Correcting time values. Adding " << timeCorrection << endl;
8 }
9 
10 // the case file is always ASCII
11 Info << "write case: " << caseFileName.c_str() << endl;
12 
13 OFstream caseFile(ensightDir/caseFileName, IOstream::ASCII);
14 caseFile.setf(ios_base::left);
15 
16 caseFile.setf(ios_base::scientific, ios_base::floatfield);
17 caseFile.precision(5);
18 
19 caseFile
20  << "FORMAT" << nl
21  << setw(16) << "type:" << "ensight gold" << nl << nl;
22 
23 if (hasMovingMesh)
24 {
25  caseFile
26  << "GEOMETRY" << nl
27  << setw(16) << "model: 1" << (dataMask/geometryName).c_str() << nl;
28 }
29 else
30 {
31  caseFile
32  << "GEOMETRY" << nl
33  << setw(16) << "model:" << geometryName << nl;
34 }
35 
36 
37 // add information for clouds
38 // multiple clouds currently require the same time index
39 forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
40 {
41  const word& cloudName = cloudIter.key();
42 
43  caseFile
44  << setw(16) << "measured: 2"
45  << fileName
46  (
47  dataMask/lagrangian::cloud::prefix/cloudName/"positions"
48  ).c_str()
49  << nl;
50 }
51 caseFile
52  << nl << "VARIABLE" << nl;
53 
54 forAllConstIter(HashTable<word>, volumeFields, fieldIter)
55 {
56  const word& fieldName = fieldIter.key();
57  const word& fieldType = fieldIter();
58  string ensightType;
59 
60  if (fieldType == volScalarField::typeName)
61  {
62  ensightType = "scalar";
63  }
64  else if (fieldType == volVectorField::typeName)
65  {
66  ensightType = "vector";
67  }
68  else if (fieldType == volSphericalTensorField::typeName)
69  {
70  ensightType = "tensor symm";
71  }
72  else if (fieldType == volSymmTensorField::typeName)
73  {
74  ensightType = "tensor symm";
75  }
76  else if (fieldType == volTensorField::typeName)
77  {
78  ensightType = "tensor asym";
79  }
80 
81  if (ensightType.size())
82  {
84  (
85  caseFile,
86  ensightType,
87  fieldName,
88  dataMask
89  );
90  }
91 }
92 
93 // TODO: allow similar/different time-steps for each cloud
94 
95 
96 label cloudNo = 0;
97 forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
98 {
99  const word& cloudName = cloudIter.key();
100 
101  forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
102  {
103  const word& fieldName = fieldIter.key();
104  const word& fieldType = fieldIter();
105  string ensightType;
106 
107  if (fieldType == scalarIOField::typeName)
108  {
109  ensightType = "scalar";
110  }
111  else if (fieldType == vectorIOField::typeName)
112  {
113  ensightType = "vector";
114  }
115  else if (fieldType == tensorIOField::typeName)
116  {
117  ensightType = "tensor";
118  }
119 
120  if (ensightType.size())
121  {
123  (
124  caseFile,
125  ensightType,
126  fieldName,
127  dataMask,
128  lagrangian::cloud::prefix/cloudName,
129  cloudNo,
130  2
131  );
132  }
133  }
134  cloudNo++;
135 }
136 
137 
138 // add time values
139 caseFile << nl << "TIME" << nl;
140 
141 // time set 1 - geometry and volume fields
142 if (fieldTimesUsed.size())
143 {
144  caseFile
145  << "time set: " << 1 << nl
146  << "number of steps: " << fieldTimesUsed.size() << nl
147  << "filename numbers:" << nl;
148 
149  label count = 0;
150  forAll(fieldTimesUsed, i)
151  {
152  caseFile
153  << " " << setw(12) << fieldTimesUsed[i];
154 
155  if (++count % 6 == 0)
156  {
157  caseFile << nl;
158  }
159  }
160 
161  caseFile
162  << nl << "time values:" << nl;
163 
164  count = 0;
165  forAll(fieldTimesUsed, i)
166  {
167  caseFile
168  << " " << setw(12)
169  << timeIndices[fieldTimesUsed[i]] + timeCorrection;
170 
171  if (++count % 6 == 0)
172  {
173  caseFile << nl;
174  }
175  }
176  caseFile << nl << nl;
177 }
178 
179 // TODO: allow similar/different time-steps for each cloud
180 cloudNo = 0;
181 forAllConstIter(HashTable<DynamicList<label>>, cloudTimesUsed, cloudIter)
182 {
183  // const word& cloudName = cloudIter.key();
184  const DynamicList<label>& timesUsed = cloudIter();
185 
186  if (timesUsed.size() && cloudNo == 0)
187  {
188  caseFile
189  << "time set: " << 2 << nl
190  << "number of steps: " << timesUsed.size() << nl
191  << "filename numbers:" << nl;
192 
193  label count = 0;
194  forAll(timesUsed, i)
195  {
196  caseFile
197  << " " << setw(12) << timesUsed[i];
198 
199  if (++count % 6 == 0)
200  {
201  caseFile << nl;
202  }
203  }
204 
205  caseFile
206  << nl << "time values:" << nl;
207 
208  count = 0;
209  forAll(timesUsed, i)
210  {
211  caseFile
212  << " " << setw(12)
213  << timeIndices[timesUsed[i]] + timeCorrection;
214 
215  if (++count % 6 == 0)
216  {
217  caseFile << nl;
218  }
219  }
220  caseFile << nl << nl;
221 
222  cloudNo++;
223  }
224 }
225 
226 caseFile << "# end" << nl;
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
bool hasMovingMesh
Info<< "write case: "<< caseFileName.c_str()<< endl;OFstream caseFile(ensightDir/caseFileName, IOstream::ASCII);caseFile.setf(ios_base::left);caseFile.setf(ios_base::scientific, ios_base::floatfield);caseFile.precision(5);caseFile<< "FORMAT"<< nl<< setw(16)<< "type:"<< "ensight gold"<< nl<< nl;if(hasMovingMesh){ caseFile<< "GEOMETRY"<< nl<< setw(16)<< "model: 1"<<(dataMask/geometryName).c_str()<< nl;}else{ caseFile<< "GEOMETRY"<< nl<< setw(16)<< "model:"<< geometryName<< nl;}forAllConstIter(HashTable< HashTable< word >>, cloudFields, cloudIter){ const word &cloudName=cloudIter.key();caseFile<< setw(16)<< "measured: 2"<< fileName(dataMask/lagrangian::cloud::prefix/cloudName/"positions").c_str()<< nl;}caseFile<< nl<< "VARIABLE"<< nl;forAllConstIter(HashTable< word >, volumeFields, fieldIter){ const word &fieldName=fieldIter.key();const word &fieldType=fieldIter();string ensightType;if(fieldType==volScalarField::typeName) { ensightType="scalar";} else if(fieldType==volVectorField::typeName) { ensightType="vector";} else if(fieldType==volSphericalTensorField::typeName) { ensightType="tensor symm";} else if(fieldType==volSymmTensorField::typeName) { ensightType="tensor symm";} else if(fieldType==volTensorField::typeName) { ensightType="tensor asym";} if(ensightType.size()) { ensightCaseEntry(caseFile, ensightType, fieldName, dataMask);}}label cloudNo=0;forAllConstIter(HashTable< HashTable< word >>, cloudFields, cloudIter){ const word &cloudName=cloudIter.key();forAllConstIter(HashTable< word >, cloudIter(), fieldIter) { const word &fieldName=fieldIter.key();const word &fieldType=fieldIter();string ensightType;if(fieldType==scalarIOField::typeName) { ensightType="scalar";} else if(fieldType==vectorIOField::typeName) { ensightType="vector";} else if(fieldType==tensorIOField::typeName) { ensightType="tensor";} if(ensightType.size()) { ensightCaseEntry(caseFile, ensightType, fieldName, dataMask, lagrangian::cloud::prefix/cloudName, cloudNo, 2);} } cloudNo++;}caseFile<< nl<< "TIME"<< nl;if(fieldTimesUsed.size()){ caseFile<< "time set: "<< 1<< nl<< "number of steps: "<< fieldTimesUsed.size()<< nl<< "filename numbers:"<< nl;label count=0;forAll(fieldTimesUsed, i) { caseFile<< " "<< setw(12)<< fieldTimesUsed[i];if(++count % 6==0) { caseFile<< nl;} } caseFile<< nl<< "time values:"<< nl;count=0;forAll(fieldTimesUsed, i) { caseFile<< " "<< setw(12)<< timeIndices[fieldTimesUsed[i]]+timeCorrection;if(++count % 6==0) { caseFile<< nl;} } caseFile<< nl<< nl;}cloudNo=0;forAllConstIter(HashTable< DynamicList< label >>, cloudTimesUsed, cloudIter){ const DynamicList< label > & timesUsed
scalar timeCorrection
HashTable< HashTable< word > > cloudFields
Definition: findFields.H:7
HashTable< word > volumeFields
Definition: findFields.H:4
static instantList timeDirs
Definition: globalFoam.H:44
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
messageStream Info
void ensightCaseEntry(OFstream &caseFile, const string &ensightType, const word &fieldName, const fileName &dataMask, const fileName &local=fileName::null, const label cloudNo=-1, const label timeSet=1)
IOstream & scientific(IOstream &io)
Definition: IOstream.H:594
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
static const char nl
Definition: Ostream.H:267
const word cloudName(propsDict.lookup("cloudName"))