48 void Foam::ensightCase::initialize()
58 if (
isDir(ensightDir_))
60 if (options_->overwrite())
67 <<
"Warning: re-using existing directory" <<
nl
68 <<
" " << ensightDir_ <<
endl;
79 os_->setf(ios_base::left);
88 Foam::label Foam::ensightCase::checkTimeset(
const labelHashSet& lookup)
const
102 else if (tsTimes.size() == timesUsed_.size())
106 tsTimes.erase(iter.key());
122 void Foam::ensightCase::writeHeader()
const
129 <<
"type: ensight gold" <<
nl;
134 Foam::scalar Foam::ensightCase::writeTimeset()
const
138 const labelList indices(timesUsed_.sortedToc());
139 label
count = indices.size();
142 scalar timeCorrection = timesUsed_[indices[0]];
143 if (timeCorrection < 0)
145 timeCorrection = -timeCorrection;
146 Info<<
"Correcting time values. Adding " << timeCorrection <<
endl;
155 <<
"time set: " << ts <<
nl
156 <<
"number of steps: " <<
count <<
nl;
158 if (indices[0] == 0 && indices[
count-1] ==
count-1)
162 <<
"filename start number: " << 0 <<
nl
163 <<
"filename increment: " << 1 <<
nl;
168 <<
"filename numbers:" <<
nl;
171 for (
const label idx : indices)
173 *os_ <<
' ' <<
setw(12) << idx;
175 if (++
count % 6 == 0)
188 *os_ <<
"time values:" <<
nl;
191 for (
const label idx : indices)
193 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
195 if (++
count % 6 == 0)
205 return timeCorrection;
209 void Foam::ensightCase::writeTimeset
213 const scalar timeCorrection
220 const labelList indices(hashed.sortedToc());
221 label
count = indices.size();
224 <<
"time set: " << ts <<
nl
225 <<
"number of steps: " <<
count <<
nl
226 <<
"filename numbers:" <<
nl;
229 for (
const label idx : indices)
231 *os_ <<
' ' <<
setw(12) << idx;
233 if (++
count % 6 == 0)
244 *os_ <<
"time values:" <<
nl;
247 for (
const label idx : indices)
249 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
251 if (++
count % 6 == 0)
263 void Foam::ensightCase::noteGeometry(
const bool moving)
const
267 geomTimes_.insert(timeIndex_);
271 geomTimes_.insert(-1);
278 void Foam::ensightCase::noteCloud(
const word&
cloudName)
const
285 cloudTimes_.insert(timeIndex_);
291 void Foam::ensightCase::noteCloud
295 const char* ensightType
308 <<
"Tried to add a cloud variable for writing"
309 <<
" - without having added a cloud"
315 void Foam::ensightCase::noteVariable
318 const char* ensightType
321 if (variables_.insert(varName, ensightType))
329 Foam::ensightCase::createDataFile
338 const fileName outdir = dataDir()/padded(timeIndex_);
349 Foam::ensightCase::createCloudFile
361 const fileName outdir =
379 Foam::ensightCase::ensightCase
382 const word& caseName,
386 options_(new options(opts)),
388 ensightDir_(ensightDir),
389 caseName_(caseName +
".case"),
404 Foam::ensightCase::ensightCase
407 const word& caseName,
411 options_(new options(
format)),
413 ensightDir_(ensightDir),
414 caseName_(caseName +
".case"),
434 setTime(value, timesUsed_.size());
454 const fileName outdir = dataDir()/padded(timeIndex_);
460 <<
"# index time" <<
nl
461 << outdir.
name() <<
' ' << timeValue_ <<
nl;
465 timesUsed_.set(index, value);
480 const bool staticGeom = (geomTimes_.size() == 1 && geomTimes_.found(-1));
481 label tsGeom = staticGeom ? 0 : checkTimeset(geomTimes_);
484 label meshIndex = -1;
487 label tsCloud = checkTimeset(cloudTimes_);
495 if (geomTimes_.size() == 1)
498 meshIndex = *(geomTimes_.begin());
503 tsCloud = 1 +
std::max(label(1), tsGeom);
510 const fileName dataMask = (dataDirName/mask());
515 if (!geomTimes_.empty() || !cloudTimes_.empty())
527 <<
setw(16) <<
"model:"
528 << (dataDirName/word(
"constant")/geometryName).c_str()
531 else if (meshIndex >= 0)
535 <<
setw(16) <<
"model:"
536 << (dataDirName/padded(meshIndex)/geometryName).c_str()
539 else if (!geomTimes_.empty())
544 << (dataMask/geometryName).c_str()
549 const wordList cloudNames(cloudVars_.sortedToc());
553 const fileName masked =
562 << (masked/
"positions").c_str()
570 if (variables_.size() || cloudVars_.size())
580 const wordList varNames(variables_.sortedToc());
582 for (
const word& varName : varNames)
584 const string& ensType = variables_[varName];
590 (nodeVariables_.found(varName) || nodeValues())
594 <<
setw(15) << varName <<
' '
595 << (dataMask/varName).c_str() <<
nl;
607 const fileName masked =
614 const HashTable<string>& vars = cloudVars_[
cloudName];
616 for (
const word& varName : vars.sortedToc())
618 const string& ensType = vars[varName];
622 << ensType.c_str() <<
" per "
625 << (
"c" +
Foam::name(cloudNo) + varName).c_str() <<
' '
626 << (masked/varName).c_str()
638 if (!timesUsed_.empty())
641 <<
nl <<
"TIME" <<
nl;
644 const scalar timeCorrection = writeTimeset();
649 writeTimeset(tsGeom, geomTimes_, timeCorrection);
655 writeTimeset(tsCloud, cloudTimes_, timeCorrection);
683 path = dataDir()/padded(timeIndex_);
692 noteGeometry(moving);
714 output().writeBinaryHeader();
731 os_->stdStream().seekp(0, std::ios_base::beg);
738 os <<
"Ensight case:" <<
nl
739 <<
" path: " << ensightDir_ <<
nl
740 <<
" name: " << caseName_ <<
nl
745 os <<
" values per node" <<
nl;