51 return word(std::string(nwidth,
'*'),
false);
62 std::ostringstream oss;
63 oss << std::setfill(
'0') << std::setw(nwidth) << index;
65 return word(oss.str(),
false);
76 os.setf(std::ios_base::left);
79 std::ios_base::fmtflags(timeFmt),
80 std::ios_base::floatfield
85 os.precision(timePrec);
93 const ensightCase::options& opts
96 os.setf(std::ios_base::left);
99 std::ios_base::fmtflags(opts.timeFormat()),
100 std::ios_base::floatfield
103 os.precision(opts.timePrecision());
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)
157 os <<
' ' <<
setf(ios_base::right) <<
setw(12) << val;
167 const UList<scalar>& values,
168 const bitSet& indices
177 || (indices.size() == values.size() && indices.all())
181 printTimeset(
os, ts, values);
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)
227Foam::fileName Foam::ensightCase::dataDir()
const
229 return ensightDir_/dataDirName;
233void Foam::ensightCase::initialize()
245 if (options_->overwrite())
252 <<
"Warning: re-using existing directory" <<
nl
253 <<
" " << ensightDir_ <<
endl;
283 else if (tsTimes.size() == timesUsed_.size())
287 tsTimes.erase(iter.key());
303void Foam::ensightCase::writeHeader()
const
310 <<
"type: ensight gold" <<
nl;
315Foam::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;
390void 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)
444void Foam::ensightCase::noteGeometry(
const bool moving)
const
448 geomTimes_.insert(timeIndex_);
452 geomTimes_.insert(-1);
459void Foam::ensightCase::noteCloud(
const word&
cloudName)
const
466 cloudTimes_.insert(timeIndex_);
472void Foam::ensightCase::noteCloud
476 const char* ensightType
489 <<
"Tried to add a cloud variable for writing"
490 <<
" - without having added a cloud"
496void Foam::ensightCase::noteVariable
499 const char* ensightType
502 if (variables_.insert(varName, ensightType))
509Foam::autoPtr<Foam::ensightFile>
510Foam::ensightCase::createDataFile
520 const fileName outdir = dataDir()/padded(timeIndex_);
530Foam::autoPtr<Foam::ensightFile>
531Foam::ensightCase::createCloudFile
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());
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 <<
' '
787 for (
const word& varName : vars.sortedToc())
789 const string& ensType = vars[varName];
793 << ensType.c_str() <<
" per "
794 << word::printf(
"measured node: %-5d", tsCloud)
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;
Istream and Ostream manipulators taking arguments.
const word cloudName(propsDict.get< word >("cloud"))
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
floatFormat
Float formats (eg, time directory name formats).
streamFormat
Data format (ascii | binary | coherent).
@ ASCII
"ascii" (normal default)
scalar value() const noexcept
The value (const access).
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Generic output stream using a standard (STL) stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
label size() const noexcept
Number of entries.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
unsigned int count(const bool on=true) const
Count number of bits set.
bool all() const
True if all bits in this bitset are set or if the set is empty.
A cloud is a registry collection of lagrangian particles.
static const word prefix
The prefix to local: lagrangian.
Configuration options for the ensightCase.
IOstreamOption::floatFormat timeFormat() const noexcept
Time format for case file (general/fixed/scientific).
int timePrecision() const noexcept
Time precision for case file.
const word & mask() const
The output '*' mask.
autoPtr< ensightFile > newCloud(const word &cloudName) const
Open stream for new cloud positions (on master).
static const char * dataDirName
The name for data subdirectory: "data".
void write() const
Write the case file.
Ostream & printInfo(Ostream &os) const
Print some general information.
const fileName & path() const noexcept
The nominal path to the case file.
bool nodeValues() const
Force use of values per node instead of per element.
autoPtr< ensightGeoFile > newGeometry(bool moving=false) const
Open stream for new geometry file (on master). Does not include beginGeometry() marker.
void setTime(const scalar t, const label index)
Set current index and time for time-set 1.
static const char * geometryName
The name for geometry files: "geometry".
void rewind() const
Rewind the output stream (master only).
bool separateCloud() const
Write clouds into their own directory instead in "data" directory.
static word mask(const int nwidth)
A '*' mask of specified width.
void nextTime(const scalar t)
Set time for time-set 1, using next available index.
ensightCase(const ensightCase &)=delete
No copy construct.
static void setTimeFormat(OSstream &os, IOstreamOption::floatFormat timeFmt, const int timePrec)
Set output time format for ensight case file.
static word padded(const int nwidth, const label index)
Stringified zero-padded integer value of specified width.
static void printTimeset(OSstream &os, const label ts, const scalar timeValue)
Print time-set for ensight case file with a single time.
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information.
Specification of a valid Ensight file-name.
A class for handling file names.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Lookup type of boundary radiation properties.
A class for handling words, derived from Foam::string.
static word printf(const char *fmt, const PrimitiveType &val)
Use a printf-style formatter for a primitive.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
List< word > wordList
List of word.
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Smanip< std::ios_base::fmtflags > setf(std::ios_base::fmtflags flags)
static void writeHeader(Ostream &os, const word &fieldName)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Ostream & flush(Ostream &os)
Flush stream.
constexpr char nl
The newline '\n' character (0x0a).
word format(conversionProperties.get< word >("format"))
nonInt insert("surfaceSum(((S|magSf)*S)")
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
autoPtr< OFstream > filePtr