51 return word(std::string(nwidth,
'*'),
false);
62 std::ostringstream oss;
65 return word(oss.str(),
false);
76 os.
setf(std::ios_base::left);
79 std::ios_base::fmtflags(timeFmt),
80 std::ios_base::floatfield
93 const ensightCase::options& opts
96 os.
setf(std::ios_base::left);
99 std::ios_base::fmtflags(opts.timeFormat()),
100 std::ios_base::floatfield
111 const scalar timeValue
115 <<
"time set: " << ts <<
nl 116 <<
"number of steps: " << 1 <<
nl;
119 os <<
"filename start number: 0" <<
nl 120 <<
"filename increment: 1" <<
nl 121 <<
"time values:" <<
nl;
123 os <<
" " << timeValue
138 <<
"time set: " << ts <<
nl 139 <<
"number of steps: " <<
values.size() <<
nl;
142 os <<
"filename start number: 0" <<
nl 143 <<
"filename increment: 1" <<
nl;
146 os <<
"time values:" <<
nl;
148 for (
const scalar val :
values)
167 const UList<scalar>&
values,
168 const bitSet& indices
177 || (indices.size() ==
values.size() && indices.all())
188 <<
"time set: " << ts <<
nl 189 <<
"number of steps: " << indices.count() <<
nl;
192 os <<
"filename numbers:" <<
nl;
194 for (
const label idx : indices)
203 os <<
' ' <<
setf(ios_base::right) <<
setw(8) << idx;
208 os <<
"time values:" <<
nl;
210 for (
const label idx : indices)
229 return ensightDir_/dataDirName;
233 void Foam::ensightCase::initialize()
245 if (options_->overwrite())
252 <<
"Warning: re-using existing directory" <<
nl 253 <<
" " << ensightDir_ <<
endl;
269 Foam::label Foam::ensightCase::checkTimeset(
const labelHashSet& lookup)
const 283 else if (tsTimes.size() == timesUsed_.size())
287 tsTimes.erase(iter.key());
303 void Foam::ensightCase::writeHeader()
const 310 <<
"type: ensight gold" <<
nl;
315 Foam::scalar Foam::ensightCase::writeTimeset()
const 319 const labelList indices(timesUsed_.sortedToc());
320 label
count = indices.size();
323 scalar timeCorrection = timesUsed_[indices[0]];
324 if (timeCorrection < 0)
326 timeCorrection = -timeCorrection;
327 Info<<
"Correcting time values. Adding " << timeCorrection <<
endl;
336 <<
"time set: " << ts <<
nl 337 <<
"number of steps: " <<
count <<
nl;
339 if (indices[0] == 0 && indices[
count-1] ==
count-1)
343 <<
"filename start number: " << 0 <<
nl 344 <<
"filename increment: " << 1 <<
nl;
349 <<
"filename numbers:" <<
nl;
352 for (
const label idx : indices)
354 *os_ <<
' ' <<
setw(12) << idx;
356 if (++
count % 6 == 0)
369 *os_ <<
"time values:" <<
nl;
372 for (
const label idx : indices)
374 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
376 if (++
count % 6 == 0)
386 return timeCorrection;
390 void Foam::ensightCase::writeTimeset
394 const scalar timeCorrection
401 const labelList indices(hashed.sortedToc());
402 label
count = indices.size();
405 <<
"time set: " << ts <<
nl 406 <<
"number of steps: " <<
count <<
nl 407 <<
"filename numbers:" <<
nl;
410 for (
const label idx : indices)
412 *os_ <<
' ' <<
setw(12) << idx;
414 if (++
count % 6 == 0)
425 *os_ <<
"time values:" <<
nl;
428 for (
const label idx : indices)
430 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
432 if (++
count % 6 == 0)
444 void Foam::ensightCase::noteGeometry(
const bool moving)
const 448 geomTimes_.insert(timeIndex_);
452 geomTimes_.insert(-1);
459 void Foam::ensightCase::noteCloud(
const word&
cloudName)
const 466 cloudTimes_.insert(timeIndex_);
472 void Foam::ensightCase::noteCloud
476 const char* ensightType
489 <<
"Tried to add a cloud variable for writing" 490 <<
" - without having added a cloud" 496 void Foam::ensightCase::noteVariable
499 const char* ensightType
502 if (variables_.insert(varName, ensightType))
510 Foam::ensightCase::createDataFile
520 const fileName outdir = dataDir()/padded(timeIndex_);
531 Foam::ensightCase::createCloudFile
543 const fileName outdir =
564 const word& caseName,
568 options_(new options(opts)),
570 ensightDir_(ensightDir),
571 caseName_(caseName +
".case"),
583 const word& caseName,
587 options_(new options(fmt)),
589 ensightDir_(ensightDir),
590 caseName_(caseName +
".case"),
604 setTime(value, timesUsed_.size());
624 const fileName outdir = dataDir()/padded(timeIndex_);
630 <<
"# index time" <<
nl 631 << outdir.
name() <<
' ' << timeValue_ <<
nl;
635 timesUsed_.set(index, value);
650 const bool staticGeom = (geomTimes_.size() == 1 && geomTimes_.found(-1));
651 label tsGeom = staticGeom ? 0 : checkTimeset(geomTimes_);
654 label meshIndex = -1;
657 label tsCloud = checkTimeset(cloudTimes_);
665 if (geomTimes_.size() == 1)
668 meshIndex = *(geomTimes_.begin());
673 tsCloud = 1 +
std::max(label(1), tsGeom);
680 const fileName dataMask = (dataDirName/mask());
685 if (!geomTimes_.empty() || !cloudTimes_.empty())
697 <<
setw(16) <<
"model:" 698 << (dataDirName/word(
"constant")/geometryName).c_str()
701 else if (meshIndex >= 0)
705 <<
setw(16) <<
"model:" 706 << (dataDirName/padded(meshIndex)/geometryName).c_str()
709 else if (!geomTimes_.empty())
714 << (dataMask/geometryName).c_str()
719 const wordList cloudNames(cloudVars_.sortedToc());
723 const fileName masked =
732 << (masked/
"positions").c_str()
740 if (variables_.size() || cloudVars_.size())
752 for (
const word& varName : variables_.sortedToc())
754 const string& ensType = variables_[varName];
760 (nodeVariables_.found(varName) || nodeValues())
764 <<
setw(15) << varName <<
' ' 765 << (dataMask/ensight::FileName(varName)).c_str() <<
nl;
778 const fileName masked =
785 const HashTable<string>& vars = cloudVars_[
cloudName];
787 for (
const word& varName : vars.sortedToc())
789 const string& ensType = vars[varName];
793 << ensType.c_str() <<
" per " 796 << (
"c" +
Foam::name(cloudNo) + varName).c_str() <<
' ' 797 << (masked/ensight::FileName(varName)).c_str() <<
nl;
808 if (!timesUsed_.empty())
811 <<
nl <<
"TIME" <<
nl;
814 const scalar timeCorrection = writeTimeset();
819 writeTimeset(tsGeom, geomTimes_, timeCorrection);
825 writeTimeset(tsCloud, cloudTimes_, timeCorrection);
853 path = dataDir()/padded(timeIndex_);
862 noteGeometry(moving);
887 os.writeBinaryHeader();
904 os_->stdStream().seekp(0, std::ios_base::beg);
911 os <<
"Ensight case:" <<
nl 912 <<
" path: " << ensightDir_ <<
nl 913 <<
" name: " << caseName_ <<
nl 918 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)
virtual Ostream & write(const char c) override
Write character.
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))
ensightCase(const ensightCase &)=delete
No copy construct.
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
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.
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information...
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)
std::ios_base::fmtflags setf(std::ios_base::fmtflags f)
Set stream flag(s), return old stream flags.
scalar value() const noexcept
The value (const access)
autoPtr< OFstream > filePtr
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".
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.
Smanip< std::ios_base::fmtflags > setf(std::ios_base::fmtflags flags)
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). Does not include beginGeometry() marker.
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 word padded(const int nwidth, const label index)
Stringified zero-padded integer value of specified width.
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)
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)
const word & mask() const
The output '*' mask.
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.