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(dataMask/cloud::prefix/cloudName/"positions").c_str()
46  << nl;
47 }
48 caseFile
49  << nl << "VARIABLE" << nl;
50 
51 forAllConstIter(HashTable<word>, volumeFields, fieldIter)
52 {
53  const word& fieldName = fieldIter.key();
54  const word& fieldType = fieldIter();
55  string ensightType;
56 
57  if (fieldType == volScalarField::typeName)
58  {
59  ensightType = "scalar";
60  }
61  else if (fieldType == volVectorField::typeName)
62  {
63  ensightType = "vector";
64  }
65  else if (fieldType == volSphericalTensorField::typeName)
66  {
67  ensightType = "tensor symm";
68  }
69  else if (fieldType == volSymmTensorField::typeName)
70  {
71  ensightType = "tensor symm";
72  }
73  else if (fieldType == volTensorField::typeName)
74  {
75  ensightType = "tensor asym";
76  }
77 
78  if (ensightType.size())
79  {
81  (
82  caseFile,
83  ensightType,
84  fieldName,
85  dataMask
86  );
87  }
88 }
89 
90 // TODO: allow similar/different time-steps for each cloud
91 
92 
93 label cloudNo = 0;
94 forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
95 {
96  const word& cloudName = cloudIter.key();
97 
98  forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
99  {
100  const word& fieldName = fieldIter.key();
101  const word& fieldType = fieldIter();
102  string ensightType;
103 
104  if (fieldType == scalarIOField::typeName)
105  {
106  ensightType = "scalar";
107  }
108  else if (fieldType == vectorIOField::typeName)
109  {
110  ensightType = "vector";
111  }
112  else if (fieldType == tensorIOField::typeName)
113  {
114  ensightType = "tensor";
115  }
116 
117  if (ensightType.size())
118  {
120  (
121  caseFile,
122  ensightType,
123  fieldName,
124  dataMask,
125  cloud::prefix/cloudName,
126  cloudNo,
127  2
128  );
129  }
130  }
131  cloudNo++;
132 }
133 
134 
135 // add time values
136 caseFile << nl << "TIME" << nl;
137 
138 // time set 1 - geometry and volume fields
139 if (fieldTimesUsed.size())
140 {
141  caseFile
142  << "time set: " << 1 << nl
143  << "number of steps: " << fieldTimesUsed.size() << nl
144  << "filename numbers:" << nl;
145 
146  label count = 0;
147  forAll(fieldTimesUsed, i)
148  {
149  caseFile
150  << " " << setw(12) << fieldTimesUsed[i];
151 
152  if (++count % 6 == 0)
153  {
154  caseFile << nl;
155  }
156  }
157 
158  caseFile
159  << nl << "time values:" << nl;
160 
161  count = 0;
162  forAll(fieldTimesUsed, i)
163  {
164  caseFile
165  << " " << setw(12)
166  << timeIndices[fieldTimesUsed[i]] + timeCorrection;
167 
168  if (++count % 6 == 0)
169  {
170  caseFile << nl;
171  }
172  }
173  caseFile << nl << nl;
174 }
175 
176 // TODO: allow similar/different time-steps for each cloud
177 cloudNo = 0;
178 forAllConstIter(HashTable<DynamicList<label>>, cloudTimesUsed, cloudIter)
179 {
180  // const word& cloudName = cloudIter.key();
181  const DynamicList<label>& timesUsed = cloudIter();
182 
183  if (timesUsed.size() && cloudNo == 0)
184  {
185  caseFile
186  << "time set: " << 2 << nl
187  << "number of steps: " << timesUsed.size() << nl
188  << "filename numbers:" << nl;
189 
190  label count = 0;
191  forAll(timesUsed, i)
192  {
193  caseFile
194  << " " << setw(12) << timesUsed[i];
195 
196  if (++count % 6 == 0)
197  {
198  caseFile << nl;
199  }
200  }
201 
202  caseFile
203  << nl << "time values:" << nl;
204 
205  count = 0;
206  forAll(timesUsed, i)
207  {
208  caseFile
209  << " " << setw(12)
210  << timeIndices[timesUsed[i]] + timeCorrection;
211 
212  if (++count % 6 == 0)
213  {
214  caseFile << nl;
215  }
216  }
217  caseFile << nl << nl;
218 
219  cloudNo++;
220  }
221 }
222 
223 caseFile << "# end" << nl;
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:251
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)
HashTable< word > volumeFields
Definition: findFields.H:4
HashTable< HashTable< word > > cloudFields
Definition: findFields.H:7
static instantList timeDirs
Definition: globalFoam.H:44
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
static const char nl
Definition: Ostream.H:260
messageStream Info
const word cloudName(propsDict.lookup("cloudName"))
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
bool hasMovingMesh
scalar timeCorrection
IOstream & scientific(IOstream &io)
Definition: IOstream.H:582