52 std::ostringstream oss;
55 return word(oss.str(),
false);
66 os.
setf(std::ios_base::left);
69 std::ios_base::fmtflags(timeFmt),
70 std::ios_base::floatfield
83 const ensightCase::options& opts
86 os.
setf(std::ios_base::left);
89 std::ios_base::fmtflags(opts.timeFormat()),
90 std::ios_base::floatfield
101 const scalar timeValue
105 <<
"time set: " << ts <<
nl 106 <<
"number of steps: " << 1 <<
nl;
109 os <<
"filename start number: 0" <<
nl 110 <<
"filename increment: 1" <<
nl 111 <<
"time values:" <<
nl;
113 os <<
" " << timeValue
128 <<
"time set: " << ts <<
nl 129 <<
"number of steps: " <<
values.size() <<
nl;
132 os <<
"filename start number: 0" <<
nl 133 <<
"filename increment: 1" <<
nl;
136 os <<
"time values:" <<
nl;
138 for (
const scalar val :
values)
157 const UList<scalar>&
values,
158 const bitSet& indices
167 || (indices.size() ==
values.size() && indices.all())
178 <<
"time set: " << ts <<
nl 179 <<
"number of steps: " << indices.count() <<
nl;
182 os <<
"filename numbers:" <<
nl;
184 for (
const label idx : indices)
193 os <<
' ' <<
setf(ios_base::right) <<
setw(8) << idx;
198 os <<
"time values:" <<
nl;
200 for (
const label idx : indices)
219 return ensightDir_/dataDirName;
223 void Foam::ensightCase::initialize()
233 if (
isDir(ensightDir_))
235 if (options_->overwrite())
242 <<
"Warning: re-using existing directory" <<
nl 243 <<
" " << ensightDir_ <<
endl;
259 Foam::label Foam::ensightCase::checkTimeset(
const labelHashSet& lookup)
const 273 else if (tsTimes.size() == timesUsed_.size())
277 tsTimes.erase(iter.key());
293 void Foam::ensightCase::writeHeader()
const 300 <<
"type: ensight gold" <<
nl;
305 Foam::scalar Foam::ensightCase::writeTimeset()
const 309 const labelList indices(timesUsed_.sortedToc());
310 label
count = indices.size();
313 scalar timeCorrection = timesUsed_[indices[0]];
314 if (timeCorrection < 0)
316 timeCorrection = -timeCorrection;
317 Info<<
"Correcting time values. Adding " << timeCorrection <<
endl;
326 <<
"time set: " << ts <<
nl 327 <<
"number of steps: " <<
count <<
nl;
329 if (indices[0] == 0 && indices[
count-1] ==
count-1)
333 <<
"filename start number: " << 0 <<
nl 334 <<
"filename increment: " << 1 <<
nl;
339 <<
"filename numbers:" <<
nl;
342 for (
const label idx : indices)
344 *os_ <<
' ' <<
setw(12) << idx;
346 if (++
count % 6 == 0)
359 *os_ <<
"time values:" <<
nl;
362 for (
const label idx : indices)
364 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
366 if (++
count % 6 == 0)
376 return timeCorrection;
380 void Foam::ensightCase::writeTimeset
384 const scalar timeCorrection
391 const labelList indices(hashed.sortedToc());
392 label
count = indices.size();
395 <<
"time set: " << ts <<
nl 396 <<
"number of steps: " <<
count <<
nl 397 <<
"filename numbers:" <<
nl;
400 for (
const label idx : indices)
402 *os_ <<
' ' <<
setw(12) << idx;
404 if (++
count % 6 == 0)
415 *os_ <<
"time values:" <<
nl;
418 for (
const label idx : indices)
420 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
422 if (++
count % 6 == 0)
434 void Foam::ensightCase::noteGeometry(
const bool moving)
const 438 geomTimes_.insert(timeIndex_);
442 geomTimes_.insert(-1);
449 void Foam::ensightCase::noteCloud(
const word&
cloudName)
const 456 cloudTimes_.insert(timeIndex_);
462 void Foam::ensightCase::noteCloud
466 const char* ensightType
479 <<
"Tried to add a cloud variable for writing" 480 <<
" - without having added a cloud" 486 void Foam::ensightCase::noteVariable
489 const char* ensightType
492 if (variables_.insert(varName, ensightType))
500 Foam::ensightCase::createDataFile
510 const fileName outdir = dataDir()/padded(timeIndex_);
521 Foam::ensightCase::createCloudFile
533 const fileName outdir =
551 Foam::ensightCase::ensightCase
554 const word& caseName,
558 options_(new options(opts)),
560 ensightDir_(ensightDir),
561 caseName_(caseName +
".case"),
576 Foam::ensightCase::ensightCase
579 const word& caseName,
583 options_(new options(fmt)),
585 ensightDir_(ensightDir),
586 caseName_(caseName +
".case"),
606 setTime(value, timesUsed_.size());
626 const fileName outdir = dataDir()/padded(timeIndex_);
632 <<
"# index time" <<
nl 633 << outdir.
name() <<
' ' << timeValue_ <<
nl;
637 timesUsed_.set(index, value);
652 const bool staticGeom = (geomTimes_.size() == 1 && geomTimes_.found(-1));
653 label tsGeom = staticGeom ? 0 : checkTimeset(geomTimes_);
656 label meshIndex = -1;
659 label tsCloud = checkTimeset(cloudTimes_);
667 if (geomTimes_.size() == 1)
670 meshIndex = *(geomTimes_.begin());
675 tsCloud = 1 +
std::max(label(1), tsGeom);
682 const fileName dataMask = (dataDirName/mask());
687 if (!geomTimes_.empty() || !cloudTimes_.empty())
699 <<
setw(16) <<
"model:" 700 << (dataDirName/word(
"constant")/geometryName).c_str()
703 else if (meshIndex >= 0)
707 <<
setw(16) <<
"model:" 708 << (dataDirName/padded(meshIndex)/geometryName).c_str()
711 else if (!geomTimes_.empty())
716 << (dataMask/geometryName).c_str()
721 const wordList cloudNames(cloudVars_.sortedToc());
725 const fileName masked =
734 << (masked/
"positions").c_str()
742 if (variables_.size() || cloudVars_.size())
754 for (
const word& varName : variables_.sortedToc())
756 const string& ensType = variables_[varName];
762 (nodeVariables_.found(varName) || nodeValues())
766 <<
setw(15) << varName <<
' ' 767 << (dataMask/ensight::FileName(varName)).c_str() <<
nl;
780 const fileName masked =
787 const HashTable<string>& vars = cloudVars_[
cloudName];
789 for (
const word& varName : vars.sortedToc())
791 const string& ensType = vars[varName];
795 << ensType.c_str() <<
" per " 798 << (
"c" +
Foam::name(cloudNo) + varName).c_str() <<
' ' 799 << (masked/ensight::FileName(varName)).c_str() <<
nl;
810 if (!timesUsed_.empty())
813 <<
nl <<
"TIME" <<
nl;
816 const scalar timeCorrection = writeTimeset();
821 writeTimeset(tsGeom, geomTimes_, timeCorrection);
827 writeTimeset(tsCloud, cloudTimes_, timeCorrection);
855 path = dataDir()/padded(timeIndex_);
864 noteGeometry(moving);
886 output().writeBinaryHeader();
903 os_->stdStream().seekp(0, std::ios_base::beg);
910 os <<
"Ensight case:" <<
nl 911 <<
" path: " << ensightDir_ <<
nl 912 <<
" name: " << caseName_ <<
nl 917 os <<
" values per node" <<
nl;
static void printTimeset(OSstream &os, const label ts, const scalar timeValue)
Print time-set for ensight case file with a single time.
Omanip< char > setfill(char fillch)
Generic output stream using a standard (STL) stream.
A class for handling file names.
static void setTimeFormat(OSstream &os, IOstreamOption::floatFormat timeFmt, const int timePrec)
Set output time format for ensight case file.
static void writeHeader(Ostream &os, const word &fieldName)
static word padded(const int nwidth, const label value)
Stringified zero-padded integer value.
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
floatFormat
Float formats (eg, time directory name formats)
Ostream & endl(Ostream &os)
Add newline and flush stream.
void nextTime(const scalar t)
Set time for time-set 1, using next available index.
void rewind() const
Rewind the output stream (master only).
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
scalar value() const noexcept
The value (const access)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Configuration options for the ensightCase.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
const word cloudName(propsDict.get< word >("cloud"))
virtual int precision() const override
Get precision of output field.
A class for handling words, derived from Foam::string.
static const char * geometryName
The name for geometry files: "geometry".
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
errorManip< error > abort(error &err)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
static word printf(const char *fmt, const PrimitiveType &val)
Use a printf-style formatter for a primitive.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Istream and Ostream manipulators taking arguments.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
autoPtr< ensightGeoFile > newGeometry(bool moving=false) const
Open stream for new geometry file (on master).
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
word format(conversionProperties.get< word >("format"))
List< word > wordList
List of word.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
void write() const
Write the case file.
Ostream & flush(Ostream &os)
Flush stream.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
streamFormat
Data format (ascii | binary)
messageStream Info
Information stream (stdout output on master, null elsewhere)
static Ostream & output(Ostream &os, const IntRange< T > &range)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
static const char * dataDirName
The name for data subdirectory: "data".
Omanip< int > setw(const int i)
List< label > labelList
A List of labels.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Ostream & printInfo(Ostream &os) const
Print some general information.
autoPtr< ensightFile > newCloud(const word &cloudName) const
Open stream for new cloud positions (on master).
void setTime(const scalar t, const label index)
Set current index and time for time-set 1.
forAllConstIters(mixture.phases(), phase)
static const word prefix
The prefix to local: lagrangian.