52 std::ostringstream oss;
55 return word(oss.str(),
false);
63 const scalar timeValue
67 <<
"time set: " << ts <<
nl 68 <<
"number of steps: " << 1 <<
nl;
71 os <<
"filename start number: 0" <<
nl 72 <<
"filename increment: 1" <<
nl 73 <<
"time values:" <<
nl;
75 os <<
" " << timeValue
90 <<
"time set: " << ts <<
nl 91 <<
"number of steps: " <<
values.size() <<
nl;
94 os <<
"filename start number: 0" <<
nl 95 <<
"filename increment: 1" <<
nl;
98 os <<
"time values:" <<
nl;
100 for (
const scalar val :
values)
119 const UList<scalar>&
values,
120 const bitSet& indices
129 || (indices.size() ==
values.size() && indices.all())
140 <<
"time set: " << ts <<
nl 141 <<
"number of steps: " << indices.count() <<
nl;
144 os <<
"filename numbers:" <<
nl;
146 for (
const label idx : indices)
155 os <<
' ' <<
setf(ios_base::right) <<
setw(8) << idx;
160 os <<
"time values:" <<
nl;
162 for (
const label idx : indices)
181 return ensightDir_/dataDirName;
185 void Foam::ensightCase::initialize()
195 if (
isDir(ensightDir_))
197 if (options_->overwrite())
204 <<
"Warning: re-using existing directory" <<
nl 205 <<
" " << ensightDir_ <<
endl;
216 os_->setf(ios_base::left);
225 Foam::label Foam::ensightCase::checkTimeset(
const labelHashSet& lookup)
const 239 else if (tsTimes.size() == timesUsed_.size())
243 tsTimes.erase(iter.key());
259 void Foam::ensightCase::writeHeader()
const 266 <<
"type: ensight gold" <<
nl;
271 Foam::scalar Foam::ensightCase::writeTimeset()
const 275 const labelList indices(timesUsed_.sortedToc());
276 label
count = indices.size();
279 scalar timeCorrection = timesUsed_[indices[0]];
280 if (timeCorrection < 0)
282 timeCorrection = -timeCorrection;
283 Info<<
"Correcting time values. Adding " << timeCorrection <<
endl;
292 <<
"time set: " << ts <<
nl 293 <<
"number of steps: " <<
count <<
nl;
295 if (indices[0] == 0 && indices[
count-1] ==
count-1)
299 <<
"filename start number: " << 0 <<
nl 300 <<
"filename increment: " << 1 <<
nl;
305 <<
"filename numbers:" <<
nl;
308 for (
const label idx : indices)
310 *os_ <<
' ' <<
setw(12) << idx;
312 if (++
count % 6 == 0)
325 *os_ <<
"time values:" <<
nl;
328 for (
const label idx : indices)
330 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
332 if (++
count % 6 == 0)
342 return timeCorrection;
346 void Foam::ensightCase::writeTimeset
350 const scalar timeCorrection
357 const labelList indices(hashed.sortedToc());
358 label
count = indices.size();
361 <<
"time set: " << ts <<
nl 362 <<
"number of steps: " <<
count <<
nl 363 <<
"filename numbers:" <<
nl;
366 for (
const label idx : indices)
368 *os_ <<
' ' <<
setw(12) << idx;
370 if (++
count % 6 == 0)
381 *os_ <<
"time values:" <<
nl;
384 for (
const label idx : indices)
386 *os_ <<
' ' <<
setw(12) << timesUsed_[idx] + timeCorrection;
388 if (++
count % 6 == 0)
400 void Foam::ensightCase::noteGeometry(
const bool moving)
const 404 geomTimes_.insert(timeIndex_);
408 geomTimes_.insert(-1);
415 void Foam::ensightCase::noteCloud(
const word&
cloudName)
const 422 cloudTimes_.insert(timeIndex_);
428 void Foam::ensightCase::noteCloud
432 const char* ensightType
445 <<
"Tried to add a cloud variable for writing" 446 <<
" - without having added a cloud" 452 void Foam::ensightCase::noteVariable
455 const char* ensightType
458 if (variables_.insert(varName, ensightType))
466 Foam::ensightCase::createDataFile
476 const fileName outdir = dataDir()/padded(timeIndex_);
487 Foam::ensightCase::createCloudFile
499 const fileName outdir =
517 Foam::ensightCase::ensightCase
520 const word& caseName,
524 options_(new options(opts)),
526 ensightDir_(ensightDir),
527 caseName_(caseName +
".case"),
542 Foam::ensightCase::ensightCase
545 const word& caseName,
549 options_(new options(fmt)),
551 ensightDir_(ensightDir),
552 caseName_(caseName +
".case"),
572 setTime(value, timesUsed_.size());
592 const fileName outdir = dataDir()/padded(timeIndex_);
598 <<
"# index time" <<
nl 599 << outdir.
name() <<
' ' << timeValue_ <<
nl;
603 timesUsed_.set(index, value);
618 const bool staticGeom = (geomTimes_.size() == 1 && geomTimes_.found(-1));
619 label tsGeom = staticGeom ? 0 : checkTimeset(geomTimes_);
622 label meshIndex = -1;
625 label tsCloud = checkTimeset(cloudTimes_);
633 if (geomTimes_.size() == 1)
636 meshIndex = *(geomTimes_.begin());
641 tsCloud = 1 +
std::max(label(1), tsGeom);
648 const fileName dataMask = (dataDirName/mask());
653 if (!geomTimes_.empty() || !cloudTimes_.empty())
665 <<
setw(16) <<
"model:" 666 << (dataDirName/word(
"constant")/geometryName).c_str()
669 else if (meshIndex >= 0)
673 <<
setw(16) <<
"model:" 674 << (dataDirName/padded(meshIndex)/geometryName).c_str()
677 else if (!geomTimes_.empty())
682 << (dataMask/geometryName).c_str()
687 const wordList cloudNames(cloudVars_.sortedToc());
691 const fileName masked =
700 << (masked/
"positions").c_str()
708 if (variables_.size() || cloudVars_.size())
720 for (
const word& varName : variables_.sortedToc())
722 const string& ensType = variables_[varName];
728 (nodeVariables_.found(varName) || nodeValues())
732 <<
setw(15) << varName <<
' ' 733 << (dataMask/ensight::FileName(varName)).c_str() <<
nl;
746 const fileName masked =
753 const HashTable<string>& vars = cloudVars_[
cloudName];
755 for (
const word& varName : vars.sortedToc())
757 const string& ensType = vars[varName];
761 << ensType.c_str() <<
" per " 764 << (
"c" +
Foam::name(cloudNo) + varName).c_str() <<
' ' 765 << (masked/ensight::FileName(varName)).c_str() <<
nl;
776 if (!timesUsed_.empty())
779 <<
nl <<
"TIME" <<
nl;
782 const scalar timeCorrection = writeTimeset();
787 writeTimeset(tsGeom, geomTimes_, timeCorrection);
793 writeTimeset(tsCloud, cloudTimes_, timeCorrection);
821 path = dataDir()/padded(timeIndex_);
830 noteGeometry(moving);
852 output().writeBinaryHeader();
869 os_->stdStream().seekp(0, std::ios_base::beg);
876 os <<
"Ensight case:" <<
nl 877 <<
" path: " << ensightDir_ <<
nl 878 <<
" name: " << caseName_ <<
nl 883 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 writeHeader(Ostream &os, const word &fieldName)
static word padded(const int nwidth, const label value)
Stringified zero-padded integer value.
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)
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 INVALID.
const word cloudName(propsDict.get< word >("cloud"))
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
A List of words.
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)
Am I the master rank.
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).
IOstream & scientific(IOstream &io)
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.