diff --git a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C index 876a6d59be..4ccbe6f300 100644 --- a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C +++ b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C @@ -191,11 +191,11 @@ int main(int argc, char *argv[]) const scalar scaleFactor = args.getOrDefault("scale", 1); // Default to binary output, unless otherwise specified - const IOstream::streamFormat format = + const IOstreamOption::streamFormat format = ( args.found("ascii") - ? IOstream::ASCII - : IOstream::BINARY + ? IOstreamOption::ASCII + : IOstreamOption::BINARY ); // Increase the precision of the points data diff --git a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C index b3809ff160..ed4a1de4ee 100644 --- a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C +++ b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C @@ -90,11 +90,11 @@ int main(int argc, char *argv[]) // Binary output, unless otherwise specified - const IOstream::streamFormat format = + const IOstreamOption::streamFormat format = ( args.found("ascii") - ? IOstream::ASCII - : IOstream::BINARY + ? IOstreamOption::ASCII + : IOstreamOption::BINARY ); // increase the precision of the points data diff --git a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C index b48f1b6bd0..41d4e2b08e 100644 --- a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C +++ b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C @@ -96,11 +96,11 @@ int main(int argc, char *argv[]) Time runTime(args.rootPath(), args.caseName()); // Binary output, unless otherwise specified - const IOstream::streamFormat format = + const IOstreamOption::streamFormat format = ( args.found("ascii") - ? IOstream::ASCII - : IOstream::BINARY + ? IOstreamOption::ASCII + : IOstreamOption::BINARY ); // Increase the precision of the points data diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 706b5ae63d..f012773424 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -308,11 +308,11 @@ int main(int argc, char *argv[]) // Configuration // Default to binary output, unless otherwise specified - const IOstream::streamFormat format = + const IOstreamOption::streamFormat format = ( args.found("ascii") - ? IOstream::ASCII - : IOstream::BINARY + ? IOstreamOption::ASCII + : IOstreamOption::BINARY ); const bool doBoundary = !args.found("no-boundary"); diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 6b1d5018c2..26012e9f71 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -6,6 +6,7 @@ ensight/file/ensightCase.C ensight/file/ensightCaseOptions.C ensight/file/ensightFile.C ensight/file/ensightGeoFile.C +ensight/file/ensightWriterCaching.C ensight/mesh/ensightMesh.C ensight/mesh/ensightMeshOptions.C diff --git a/src/fileFormats/ensight/file/ensightCase.C b/src/fileFormats/ensight/file/ensightCase.C index efcf5cb927..66af71b5b6 100644 --- a/src/fileFormats/ensight/file/ensightCase.C +++ b/src/fileFormats/ensight/file/ensightCase.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,7 @@ License #include "Time.H" #include "cloud.H" #include "IOmanip.H" +#include "OSstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -37,6 +38,126 @@ const char* Foam::ensightCase::dataDirName = "data"; const char* Foam::ensightCase::geometryName = "geometry"; +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +void Foam::ensightCase::printTimeset +( + OSstream& os, + const label ts, + const scalar timeValue +) +{ + os + << "time set: " << ts << nl + << "number of steps: " << 1 << nl; + + // Single value - starts at index 0 + os << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl; + + os << " " << timeValue + << nl << nl; +} + + +void Foam::ensightCase::printTimeset +( + OSstream& os, + const label ts, + const UList& values +) +{ + label pos_(0); + + os + << "time set: " << ts << nl + << "number of steps: " << values.size() << nl; + + // Assume contiguous numbering - starts at index 0 + os << "filename start number: 0" << nl + << "filename increment: 1" << nl; + + + os << "time values:" << nl; + pos_ = 0; + for (const scalar val : values) + { + if (pos_ == 6) + { + os << nl; + pos_ = 0; + } + ++pos_; + + os << ' ' << setf(ios_base::right) << setw(12) << val; + } + os << nl << nl; +} + + +void Foam::ensightCase::printTimeset +( + OSstream& os, + const label ts, + const UList& values, + const bitSet& indices +) +{ + label pos_(0); + + // Check if continuous numbering can be used + if + ( + values.empty() + || (indices.size() == values.size() && indices.all()) + ) + { + // Can simply emit as 0-based with increment + printTimeset(os, ts, values); + return; + } + + + // Generate time set + os + << "time set: " << ts << nl + << "number of steps: " << indices.count() << nl; + + + os << "filename numbers:" << nl; + pos_ = 0; + for (const label idx : indices) + { + if (pos_ == 6) + { + os << nl; + pos_ = 0; + } + ++pos_; + + os << ' ' << setf(ios_base::right) << setw(8) << idx; + } + os << nl; + + + os << "time values:" << nl; + pos_ = 0; + for (const label idx : indices) + { + if (pos_ == 6) + { + os << nl; + pos_ = 0; + } + ++pos_; + + os << ' ' << setf(ios_base::right) << setw(12) << values[idx]; + } + os << nl << nl; +} + + // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * // Foam::fileName Foam::ensightCase::dataDir() const @@ -73,7 +194,7 @@ void Foam::ensightCase::initialize() mkDir(dataDir()); // The case file is always ASCII - os_.reset(new OFstream(ensightDir_/caseName_, IOstream::ASCII)); + os_.reset(new OFstream(ensightDir_/caseName_, IOstreamOption::ASCII)); // Format options os_->setf(ios_base::left); @@ -405,7 +526,7 @@ Foam::ensightCase::ensightCase ( const fileName& ensightDir, const word& caseName, - const IOstream::streamFormat format + const IOstreamOption::streamFormat format ) : options_(new options(format)), diff --git a/src/fileFormats/ensight/file/ensightCase.H b/src/fileFormats/ensight/file/ensightCase.H index d12fc889a5..dbdb306266 100644 --- a/src/fileFormats/ensight/file/ensightCase.H +++ b/src/fileFormats/ensight/file/ensightCase.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,15 +38,14 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ensightCase_H -#define ensightCase_H +#ifndef Foam_ensightCase_H +#define Foam_ensightCase_H #include "autoPtr.H" #include "HashSet.H" #include "InfoProxy.H" #include "Map.H" #include "HashSet.H" -#include "OSspecific.H" #include "Pstream.H" #include "ensightGeoFile.H" #include @@ -57,8 +56,10 @@ namespace Foam { // Forward Declarations +class bitSet; class ensightCase; class instant; +class OSstream; class Time; /*---------------------------------------------------------------------------*\ @@ -217,7 +218,7 @@ public: ( const fileName& ensightDir, const word& caseName, - const IOstream::streamFormat format = IOstream::BINARY + const IOstreamOption::streamFormat format = IOstreamOption::BINARY ); @@ -233,10 +234,10 @@ public: inline const ensightCase::options& option() const; //- The output file format (ascii/binary) - inline IOstream::streamFormat format() const; + inline IOstreamOption::streamFormat format() const; //- The nominal path to the case file - inline const fileName& path() const; + inline const fileName& path() const noexcept; //- The output '*' mask inline const word& mask() const; @@ -322,16 +323,67 @@ public: //- Print some general information. Ostream& printInfo(Ostream& os) const; + + + // Output Helpers + + //- Print time-set for ensight case file with a single time + static void printTimeset + ( + OSstream& os, + const label ts, + const scalar timeValue + ); + + //- Print time-set for ensight case file, with N times and 0-based + //- file numbering + // + // \verbatim + // TIME + // time set: ts + // number of steps: ns + // filename start number: 0 + // filename increment: 1 + // time values: time_1 time_2 ... time_ns + // \endverbatim + static void printTimeset + ( + OSstream& os, + const label ts, + const UList& times + ); + + //- Print time-set for ensight case file, with N times, 0-based + //- file numbering but perhaps non-contiguous + // + // \verbatim + // TIME + // time set: ts + // number of steps: ns + // filename numbers: idx_1 idx_2 ... idx_ns + // time values: time_1 time_2 ... time_ns + // \endverbatim + static void printTimeset + ( + OSstream& os, + const label ts, + const UList& times, + const bitSet& indices + ); }; +/*---------------------------------------------------------------------------*\ + Class ensightCase::options Declaration +\*---------------------------------------------------------------------------*/ + //- Configuration options for the ensightCase class ensightCase::options { // Private Data //- Ascii/Binary file output - IOstream::streamFormat format_; + IOstreamOption::streamFormat format_; //- Remove existing directory and sub-directories on creation bool overwrite_; @@ -357,7 +409,7 @@ public: // Constructors //- Construct with the specified format (default is binary) - options(IOstream::streamFormat format = IOstream::BINARY); + options(IOstreamOption::streamFormat format = IOstreamOption::BINARY); // Member Functions @@ -365,22 +417,22 @@ public: // Access //- Ascii/Binary file output - IOstream::streamFormat format() const; + IOstreamOption::streamFormat format() const noexcept { return format_; } //- The '*' mask appropriate for sub-directories - const word& mask() const; + const word& mask() const noexcept { return mask_; } //- Consistent zero-padded integer value word padded(const label i) const; //- Return current width of mask and padded. - label width() const; + label width() const noexcept { return width_; } //- Remove existing directory and sub-directories on creation - bool overwrite() const; + bool overwrite() const noexcept { return overwrite_; } //- Write clouds into their own directory instead in "data" directory - bool separateCloud() const; + bool separateCloud() const noexcept { return separateCloud_; } // Edit @@ -390,22 +442,22 @@ public: void width(const label i); //- Remove existing directory and sub-directories on creation - void overwrite(bool); + void overwrite(bool on) noexcept { overwrite_ = on; } //- Write clouds into their own directory instead in "data" directory - void separateCloud(bool); + void separateCloud(bool on) noexcept { separateCloud_ = on; } // Housekeeping - //- Force use of values per node instead of per element - bool nodeValues() const; + //- Forced use of values per node instead of per element + bool nodeValues() const noexcept { return nodeValues_; } //- Force use of values per node instead of per element // Deprecated(2020-02) - The newData() method with a second parameter // is more flexible. // \deprecated(2020-02) - newData() with second parameter - void nodeValues(bool); + void nodeValues(bool on) noexcept { nodeValues_ = on; } }; diff --git a/src/fileFormats/ensight/file/ensightCaseI.H b/src/fileFormats/ensight/file/ensightCaseI.H index 4157c27ee6..9008c1bde2 100644 --- a/src/fileFormats/ensight/file/ensightCaseI.H +++ b/src/fileFormats/ensight/file/ensightCaseI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,13 +33,13 @@ inline const Foam::ensightCase::options& Foam::ensightCase::option() const } -inline Foam::IOstream::streamFormat Foam::ensightCase::format() const +inline Foam::IOstreamOption::streamFormat Foam::ensightCase::format() const { return options_->format(); } -inline const Foam::fileName& Foam::ensightCase::path() const +inline const Foam::fileName& Foam::ensightCase::path() const noexcept { return ensightDir_; } diff --git a/src/fileFormats/ensight/file/ensightCaseOptions.C b/src/fileFormats/ensight/file/ensightCaseOptions.C index f3a1756385..a374709c34 100644 --- a/src/fileFormats/ensight/file/ensightCaseOptions.C +++ b/src/fileFormats/ensight/file/ensightCaseOptions.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,7 +29,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::ensightCase::options::options(IOstream::streamFormat format) +Foam::ensightCase::options::options(IOstreamOption::streamFormat format) : format_(format), overwrite_(false), @@ -45,18 +45,6 @@ Foam::ensightCase::options::options(IOstream::streamFormat format) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::IOstream::streamFormat Foam::ensightCase::options::format() const -{ - return format_; -} - - -const Foam::word& Foam::ensightCase::options::mask() const -{ - return mask_; -} - - Foam::word Foam::ensightCase::options::padded(const label i) const { // As per word::printf(), but with fixed length @@ -70,12 +58,6 @@ Foam::word Foam::ensightCase::options::padded(const label i) const } -Foam::label Foam::ensightCase::options::width() const -{ - return width_; -} - - void Foam::ensightCase::options::width(const label n) { // Enforce min/max sanity limits @@ -92,40 +74,4 @@ void Foam::ensightCase::options::width(const label n) } -bool Foam::ensightCase::options::overwrite() const -{ - return overwrite_; -} - - -void Foam::ensightCase::options::overwrite(bool b) -{ - overwrite_ = b; -} - - -bool Foam::ensightCase::options::nodeValues() const -{ - return nodeValues_; -} - - -void Foam::ensightCase::options::nodeValues(bool b) -{ - nodeValues_ = b; -} - - -bool Foam::ensightCase::options::separateCloud() const -{ - return separateCloud_; -} - - -void Foam::ensightCase::options::separateCloud(bool b) -{ - separateCloud_ = b; -} - - // ************************************************************************* // diff --git a/src/fileFormats/ensight/file/ensightFile.C b/src/fileFormats/ensight/file/ensightFile.C index f9262b8187..ac616ad652 100644 --- a/src/fileFormats/ensight/file/ensightFile.C +++ b/src/fileFormats/ensight/file/ensightFile.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -119,7 +119,7 @@ void Foam::ensightFile::initialize() Foam::ensightFile::ensightFile ( const fileName& pathname, - IOstream::streamFormat format + IOstreamOption::streamFormat format ) : OFstream(ensight::FileName(pathname), format) @@ -132,7 +132,7 @@ Foam::ensightFile::ensightFile ( const fileName& path, const fileName& name, - IOstream::streamFormat format + IOstreamOption::streamFormat format ) : OFstream(path/ensight::FileName(name), format) @@ -176,7 +176,7 @@ Foam::Ostream& Foam::ensightFile::writeString(const char* str) char buf[80+1]; strncpy(buf, str, 80); // max 80 chars or padded with nul if smaller - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { write(buf, 80); } @@ -227,7 +227,7 @@ Foam::Ostream& Foam::ensightFile::write Foam::Ostream& Foam::ensightFile::write(const int32_t val) { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { write ( @@ -255,7 +255,7 @@ Foam::Ostream& Foam::ensightFile::write(const int64_t val) Foam::Ostream& Foam::ensightFile::write(const floatScalar val) { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { write ( @@ -287,7 +287,7 @@ Foam::Ostream& Foam::ensightFile::write const label fieldWidth ) { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { write(value); } @@ -303,7 +303,7 @@ Foam::Ostream& Foam::ensightFile::write void Foam::ensightFile::newline() { - if (format() == IOstream::ASCII) + if (format() == IOstreamOption::ASCII) { stdStream() << nl; } @@ -338,7 +338,7 @@ Foam::Ostream& Foam::ensightFile::writeKeyword(const keyType& key) Foam::Ostream& Foam::ensightFile::writeBinaryHeader() { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { writeString("C Binary"); } diff --git a/src/fileFormats/ensight/file/ensightFile.H b/src/fileFormats/ensight/file/ensightFile.H index 2378d02a66..71ee812bde 100644 --- a/src/fileFormats/ensight/file/ensightFile.H +++ b/src/fileFormats/ensight/file/ensightFile.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,8 +33,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef ensightFile_H -#define ensightFile_H +#ifndef Foam_ensightFile_H +#define Foam_ensightFile_H #include "OFstream.H" #include "ensightFileName.H" @@ -105,7 +105,7 @@ public: explicit ensightFile ( const fileName& pathname, - IOstream::streamFormat format=IOstream::BINARY + IOstreamOption::streamFormat format = IOstreamOption::BINARY ); //- Construct from path and name. @@ -114,7 +114,7 @@ public: ( const fileName& path, const fileName& name, - IOstream::streamFormat format=IOstream::BINARY + IOstreamOption::streamFormat format = IOstreamOption::BINARY ); diff --git a/src/fileFormats/ensight/file/ensightGeoFile.C b/src/fileFormats/ensight/file/ensightGeoFile.C index 8a4f21a7ee..91a64cd91e 100644 --- a/src/fileFormats/ensight/file/ensightGeoFile.C +++ b/src/fileFormats/ensight/file/ensightGeoFile.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,7 +56,7 @@ void Foam::ensightGeoFile::initialize() Foam::ensightGeoFile::ensightGeoFile ( const fileName& pathname, - IOstream::streamFormat format + IOstreamOption::streamFormat format ) : ensightFile(pathname, format) @@ -69,7 +69,7 @@ Foam::ensightGeoFile::ensightGeoFile ( const fileName& path, const fileName& name, - IOstream::streamFormat format + IOstreamOption::streamFormat format ) : ensightFile(path, name, format) diff --git a/src/fileFormats/ensight/file/ensightGeoFile.H b/src/fileFormats/ensight/file/ensightGeoFile.H index 77a735a9c8..d57d03a3cb 100644 --- a/src/fileFormats/ensight/file/ensightGeoFile.H +++ b/src/fileFormats/ensight/file/ensightGeoFile.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,8 +32,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef ensightGeoFile_H -#define ensightGeoFile_H +#ifndef Foam_ensightGeoFile_H +#define Foam_ensightGeoFile_H #include "ensightFile.H" @@ -80,7 +80,7 @@ public: explicit ensightGeoFile ( const fileName& pathname, - IOstream::streamFormat format=IOstream::BINARY + IOstreamOption::streamFormat format = IOstreamOption::BINARY ); //- Construct from path and name. @@ -89,7 +89,7 @@ public: ( const fileName& path, const fileName& name, - IOstream::streamFormat format=IOstream::BINARY + IOstreamOption::streamFormat format = IOstreamOption::BINARY ); diff --git a/src/surfMesh/writers/caching/surfaceWriterCaching.C b/src/fileFormats/ensight/file/ensightWriterCaching.C similarity index 83% rename from src/surfMesh/writers/caching/surfaceWriterCaching.C rename to src/fileFormats/ensight/file/ensightWriterCaching.C index b4f5f15640..864a6eebcd 100644 --- a/src/surfMesh/writers/caching/surfaceWriterCaching.C +++ b/src/fileFormats/ensight/file/ensightWriterCaching.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ License \*---------------------------------------------------------------------------*/ -#include "surfaceWriterCaching.H" +#include "ensightWriterCaching.H" #include "ListOps.H" #include "Fstream.H" @@ -67,7 +67,7 @@ static label findTimeIndex(const UList& list, const scalar val) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::surfaceWriters::writerCaching::writerCaching(const word& cacheFileName) +Foam::ensightOutput::writerCaching::writerCaching(const word& cacheFileName) : dictName_(cacheFileName) {} @@ -75,7 +75,7 @@ Foam::surfaceWriters::writerCaching::writerCaching(const word& cacheFileName) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::dictionary& Foam::surfaceWriters::writerCaching::fieldsDict() const +const Foam::dictionary& Foam::ensightOutput::writerCaching::fieldsDict() const { const dictionary* dictptr = cache_.findDict("fields", keyType::LITERAL); @@ -88,7 +88,7 @@ const Foam::dictionary& Foam::surfaceWriters::writerCaching::fieldsDict() const } -Foam::dictionary& Foam::surfaceWriters::writerCaching::fieldDict +Foam::dictionary& Foam::ensightOutput::writerCaching::fieldDict ( const word& fieldName ) @@ -100,7 +100,7 @@ Foam::dictionary& Foam::surfaceWriters::writerCaching::fieldDict } -bool Foam::surfaceWriters::writerCaching::remove(const word& fieldName) +bool Foam::ensightOutput::writerCaching::remove(const word& fieldName) { dictionary* dictptr = cache_.findDict("fields", keyType::LITERAL); @@ -113,7 +113,7 @@ bool Foam::surfaceWriters::writerCaching::remove(const word& fieldName) } -void Foam::surfaceWriters::writerCaching::clear() +void Foam::ensightOutput::writerCaching::clear() { times_.clear(); geoms_.clear(); @@ -123,7 +123,7 @@ void Foam::surfaceWriters::writerCaching::clear() // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::label Foam::surfaceWriters::writerCaching::readPreviousTimes +Foam::label Foam::ensightOutput::writerCaching::readPreviousTimes ( const fileName& dictFile, const scalar timeValue @@ -184,9 +184,40 @@ Foam::label Foam::surfaceWriters::writerCaching::readPreviousTimes } +Foam::label Foam::ensightOutput::writerCaching::latestTimeIndex() const +{ + return max(0, times_.size()-1); +} + +Foam::label Foam::ensightOutput::writerCaching::latestGeomIndex() const +{ + return max(0, geoms_.find_last()); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +int Foam::ensightOutput::writerCaching::geometryTimeset() const +{ + if (geoms_.count() <= 1) + { + // Static + return 0; + } + if (geoms_.size() == times_.size() && geoms_.all()) + { + // Geometry changing is identical to fields changing + return 1; + } + + // Geometry changing differently from fields + return 2; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::surfaceWriters::writerCaching::update +bool Foam::ensightOutput::writerCaching::update ( const fileName& baseDir, const scalar timeValue, @@ -262,7 +293,7 @@ bool Foam::surfaceWriters::writerCaching::update if (stateChanged) { OFstream os(dictFile); - os << "// State file for surface writer output" << nl << nl; + os << "// State file for writer output" << nl << nl; cache_.write(os, false); os << nl << "// End" << nl; diff --git a/src/surfMesh/writers/caching/surfaceWriterCaching.H b/src/fileFormats/ensight/file/ensightWriterCaching.H similarity index 84% rename from src/surfMesh/writers/caching/surfaceWriterCaching.H rename to src/fileFormats/ensight/file/ensightWriterCaching.H index 3ad22142b0..b9a1abfd88 100644 --- a/src/surfMesh/writers/caching/surfaceWriterCaching.H +++ b/src/fileFormats/ensight/file/ensightWriterCaching.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,22 +24,22 @@ License along with OpenFOAM. If not, see . Class - Foam::surfaceWriters::writerCaching + Foam::ensightOutput::writerCaching Description - Information for surface writers with collated times. + State information for writers with collated times. The class maintains an internal list of the known times as well as a file-cached version with the field information. The information is used for restarts. SourceFiles - surfaceWriterCaching.C + ensightWriterCaching.C \*---------------------------------------------------------------------------*/ -#ifndef surfaceWriters_writerCaching_H -#define surfaceWriters_writerCaching_H +#ifndef Foam_ensightOutput_writerCaching_H +#define Foam_ensightOutput_writerCaching_H #include "bitSet.H" #include "dictionary.H" @@ -50,7 +50,7 @@ SourceFiles namespace Foam { -namespace surfaceWriters +namespace ensightOutput { /*---------------------------------------------------------------------------*\ @@ -106,28 +106,30 @@ public: // Member Functions //- The output times for fields - const scalarList& times() const + const scalarList& times() const noexcept { return times_; } //- Indices in times() when geometry (mesh) has been written - const bitSet& geometries() const + const bitSet& geometries() const noexcept { return geoms_; } //- The most current time index - label latestTimeIndex() const - { - return max(0, times_.size()-1); - } + label latestTimeIndex() const; //- The most current geometry index - label latestGeomIndex() const - { - return max(0, geoms_.find_last()); - } + label latestGeomIndex() const; + + //- Expected timeset for the geometry. + // Can be any of the following: + // + // 0: constant/static + // 1: moving, with the same frequency as the data + // 2: moving, with different frequency as the data + int geometryTimeset() const; //- Get or create the 'fields' information dictionary. const dictionary& fieldsDict() const; @@ -141,7 +143,7 @@ public: // geometry change or a new time interval bool update ( - const fileName& baseDir, //!< Directory containing the cache file + const fileName& baseDir, //!< Directory containing cache file const scalar timeValue, //!< The current time value const bool geomChanged, //!< Monitored geometry changed const word& fieldName, //!< Name of field @@ -153,7 +155,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace surfaceWriters +} // End namespace ensightOutput } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/ensight/read/ensightReadFile.C b/src/fileFormats/ensight/read/ensightReadFile.C index 1697fdea01..ba79da6ee6 100644 --- a/src/fileFormats/ensight/read/ensightReadFile.C +++ b/src/fileFormats/ensight/read/ensightReadFile.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -54,7 +54,7 @@ Foam::Istream& Foam::ensightReadFile::read Foam::Istream& Foam::ensightReadFile::read(string& value) { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { auto& iss = stdStream(); @@ -101,7 +101,7 @@ Foam::Istream& Foam::ensightReadFile::read(label& value) { int ivalue; - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { read ( @@ -123,7 +123,7 @@ Foam::Istream& Foam::ensightReadFile::read(scalar& value) { float fvalue; - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { read ( @@ -151,7 +151,7 @@ Foam::Istream& Foam::ensightReadFile::readKeyword(string& key) Foam::Istream& Foam::ensightReadFile::readBinaryHeader() { - if (format() == IOstream::BINARY) + if (format() == IOstreamOption::BINARY) { string buffer; read(buffer); diff --git a/src/fileFormats/nastran/NASCore.C b/src/fileFormats/nastran/NASCore.C index ab4de5915d..26c056e391 100644 --- a/src/fileFormats/nastran/NASCore.C +++ b/src/fileFormats/nastran/NASCore.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,6 +55,21 @@ Foam::fileFormats::NASCore::loadFormatNames }); +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +static inline void putValue(Ostream& os, const Type& value, const int width) +{ + if (width) os << setw(width); + os << value; +} + +} // End namespace Foam + + // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const std::string& str) @@ -133,10 +148,10 @@ void Foam::fileFormats::NASCore::setPrecision const fieldFormat format ) { - os.setf(ios_base::scientific); + os.setf(std::ios_base::scientific); // Capitalise the E marker - os.setf(ios_base::uppercase); + os.setf(std::ios_base::uppercase); const label offset = 7; @@ -168,7 +183,7 @@ Foam::Ostream& Foam::fileFormats::NASCore::writeKeyword const fieldFormat format ) { - os.setf(ios_base::left); + os.setf(std::ios_base::left); switch (format) { @@ -177,13 +192,11 @@ Foam::Ostream& Foam::fileFormats::NASCore::writeKeyword os << setw(8) << keyword; break; } - case fieldFormat::LONG : { os << setw(8) << word(keyword + '*'); break; } - case fieldFormat::FREE : { os << keyword; @@ -191,12 +204,78 @@ Foam::Ostream& Foam::fileFormats::NASCore::writeKeyword } } - os.unsetf(ios_base::left); + os.unsetf(std::ios_base::left); return os; } +void Foam::fileFormats::NASCore::writeCoord +( + Ostream& os, + const point& p, + const label pointId, // zero-based + const fieldFormat format +) +{ + // Field width (SHORT, LONG formats) + const int width = + ( + format == fieldFormat::SHORT ? 8 + : format == fieldFormat::LONG ? 16 + : 0 + ); + + // Separator char (FREE format) + const char sep = (format == fieldFormat::FREE ? ',' : '\0'); + + + // Fixed short/long formats: + // 1 GRID + // 2 ID : point ID - requires starting index of 1 + // 3 CP : coordinate system ID (blank) + // 4 X1 : point x coordinate + // 5 X2 : point x coordinate + // 6 X3 : point x coordinate + // 7 CD : coordinate system for displacements (blank) + // 8 PS : single point constraints (blank) + // 9 SEID : super-element ID + + writeKeyword(os, "GRID", format); + if (sep) os << sep; + + os.setf(std::ios_base::right); + + // Point ID (from 0-based to 1-based) + putValue(os, (pointId+1), width); + if (sep) os << sep; + + // Coordinate system ID (blank) + putValue(os, "", width); + if (sep) os << sep; + + putValue(os, p.x(), width); + if (sep) os << sep; + + putValue(os, p.y(), width); + if (sep) os << sep; + + if (format == fieldFormat::LONG) + { + // Continuation + os.unsetf(std::ios_base::right); + os << nl; + writeKeyword(os, "", format); + os.setf(std::ios_base::right); + } + + putValue(os, p.z(), width); + os << nl; + + os.unsetf(std::ios_base::right); +} + + Foam::label Foam::fileFormats::NASCore::faceDecomposition ( const UList& points, diff --git a/src/fileFormats/nastran/NASCore.H b/src/fileFormats/nastran/NASCore.H index 352d40d772..0fd8e9b160 100644 --- a/src/fileFormats/nastran/NASCore.H +++ b/src/fileFormats/nastran/NASCore.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +34,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef NASCore_H -#define NASCore_H +#ifndef Foam_fileFormats_NASCore_H +#define Foam_fileFormats_NASCore_H #include "scalar.H" #include "string.H" @@ -121,6 +121,15 @@ public: const fieldFormat format ); + //- Write a GRID point + static void writeCoord + ( + Ostream& os, + const point& p, + const label pointId, //!< 0-based Point Id + const fieldFormat format + ); + //- Calculate face decomposition for non tri/quad faces // // \param points the surface points diff --git a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C index b56c72db3c..2b8c973822 100644 --- a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C +++ b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C @@ -381,8 +381,8 @@ bool Foam::functionObjects::vtkCloud::read(const dictionary& dict) writeOpts_.ascii ( - IOstream::ASCII - == IOstream::formatEnum("format", dict, IOstream::BINARY) + IOstreamOption::ASCII + == IOstreamOption::formatEnum("format", dict, IOstreamOption::BINARY) ); writeOpts_.append(false); // No append supported diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C index b562df6fdb..66939d61cc 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWrite.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C @@ -183,8 +183,8 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict) writeOpts_.ascii ( - IOstream::ASCII - == IOstream::formatEnum("format", dict, IOstream::BINARY) + IOstreamOption::ASCII + == IOstreamOption::formatEnum("format", dict, IOstreamOption::BINARY) ); writeOpts_.legacy(dict.getOrDefault("legacy", false)); diff --git a/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriter.C b/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriter.C index 44c896bb19..5a330a54ae 100644 --- a/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriter.C +++ b/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriter.C @@ -29,6 +29,7 @@ License #include "ensightSetWriter.H" #include "coordSet.H" #include "IOmanip.H" +#include "ensightCase.H" #include "ensightGeoFile.H" #include "ensightPTraits.H" #include "addToRunTimeSelectionTable.H" diff --git a/src/meshTools/coordSet/writers/nastran/nastranCoordSetWriter.C b/src/meshTools/coordSet/writers/nastran/nastranCoordSetWriter.C index 5747dda885..369e90b893 100644 --- a/src/meshTools/coordSet/writers/nastran/nastranCoordSetWriter.C +++ b/src/meshTools/coordSet/writers/nastran/nastranCoordSetWriter.C @@ -76,24 +76,10 @@ void Foam::nastranSetWriter::write forAll(points, pointi) { - fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE); - - const point& pt = points[pointi]; - - //os.setf(std::ios_base::right); - //os << setw(8) << pointi+1 - // << setw(8) << ' ' - // << setw(8) << float(pt.x()) - // << setw(8) << float(pt.y()) - // << setw(8) << float(pt.z()) - // << nl; - //os.unsetf(std::ios_base::right); - os << ',' << pointi+1 - << ',' - << ',' << float(pt.x()) - << ',' << float(pt.y()) - << ',' << float(pt.z()) - << nl; + fileFormats::NASCore::writeCoord + ( + os, points[pointi], pointi, fieldFormat::FREE + ); } if (false) @@ -109,12 +95,15 @@ void Foam::nastranSetWriter::write fieldFormat::FREE ); + // fieldFormat::SHORT //os.setf(std::ios_base::right); //os << setw(8) << edgei+1 // << setw(8) << edgei+1 // << setw(8) << edgei+2 // << nl; //os.unsetf(std::ios_base::right); + + // fieldFormat::FREE os << ',' << edgei+1 << ',' << edgei+1 << ',' << edgei+2 @@ -162,27 +151,16 @@ void Foam::nastranSetWriter::write // nPoints += tracks[i].size(); // } - label globalPti = 0; + label globalPointi = 0; for (const coordSet& points : tracks) { - for (const point& pt : points) + for (const point& p : points) { - fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE); - - //os.setf(std::ios_base::right); - //os << setw(8) << globalPti++ - // << setw(8) << ' ' - // << setw(8) << float(pt.x()) - // << setw(8) << float(pt.y()) - // << setw(8) << float(pt.z()) - // << nl; - //os.unsetf(std::ios_base::right); - os << ',' << globalPti++ - << ',' - << ',' << float(pt.x()) - << ',' << float(pt.y()) - << ',' << float(pt.z()) - << nl; + fileFormats::NASCore::writeCoord + ( + os, p, globalPointi, fieldFormat::FREE + ); + ++globalPointi; } } @@ -203,6 +181,7 @@ void Foam::nastranSetWriter::write fieldFormat::FREE ); + // fieldFormat::SHORT //os.setf(std::ios_base::right); //os << setw(8) << globalEdgei+1 // << setw(8) << globalPointi+1 @@ -210,12 +189,14 @@ void Foam::nastranSetWriter::write // << nl; //os.unsetf(std::ios_base::right); + // fieldFormat::FREE os << ',' << globalEdgei+1 << ',' << globalPointi+1 << ',' << globalPointi+2 << nl; - globalEdgei++; - globalPointi++; + + ++globalEdgei; + ++globalPointi; } } } diff --git a/src/surfMesh/Make/files b/src/surfMesh/Make/files index 67e68eea3d..e98fac0c96 100644 --- a/src/surfMesh/Make/files +++ b/src/surfMesh/Make/files @@ -59,10 +59,9 @@ triSurface/patches/surfacePatch.C writers = writers -$(writers)/surfaceWriter.C -$(writers)/caching/surfaceWriterCaching.C +$(writers)/common/surfaceWriter.C $(writers)/abaqus/abaqusSurfaceWriter.C -$(writers)/boundaryData/boundaryDataSurfaceWriter.C +$(writers)/boundary/boundaryDataSurfaceWriter.C $(writers)/ensight/ensightSurfaceWriter.C $(writers)/foam/foamSurfaceWriter.C $(writers)/nastran/nastranSurfaceWriter.C diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C index 1b46d510cd..9ef4897d26 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C @@ -42,8 +42,8 @@ Foam::fileFormats::VTKsurfaceFormatCore::formatOptions opts.ascii ( - IOstream::ASCII - == IOstream::formatEnum("format", dict, IOstream::ASCII) + IOstreamOption::ASCII + == IOstreamOption::formatEnum("format", dict, IOstreamOption::ASCII) ); opts.precision diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C index b772c23b83..b0a7142745 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C @@ -42,8 +42,8 @@ Foam::fileFormats::VTPsurfaceFormatCore::formatOptions opts.ascii ( - IOstream::ASCII - == IOstream::formatEnum("format", dict, IOstream::BINARY) + IOstreamOption::ASCII + == IOstreamOption::formatEnum("format", dict, IOstreamOption::BINARY) ); opts.precision diff --git a/src/surfMesh/writers/abaqus/abaqusSurfaceWriter.H b/src/surfMesh/writers/abaqus/abaqusSurfaceWriter.H index 405e47cc19..891b6885a1 100644 --- a/src/surfMesh/writers/abaqus/abaqusSurfaceWriter.H +++ b/src/surfMesh/writers/abaqus/abaqusSurfaceWriter.H @@ -84,8 +84,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef abaqusSurfaceWriter_H -#define abaqusSurfaceWriter_H +#ifndef Foam_surfaceWriters_abaqusWriter_H +#define Foam_surfaceWriters_abaqusWriter_H #include "surfaceWriter.H" #include "ABAQUSCore.H" diff --git a/src/surfMesh/writers/abaqus/abaqusSurfaceWriterImpl.C b/src/surfMesh/writers/abaqus/abaqusSurfaceWriterImpl.C index b8d17ed306..5d1a8635d4 100644 --- a/src/surfMesh/writers/abaqus/abaqusSurfaceWriterImpl.C +++ b/src/surfMesh/writers/abaqus/abaqusSurfaceWriterImpl.C @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#include "OFstream.H" #include "IOmanip.H" +#include "OFstream.H" #include "OSspecific.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.C b/src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.C similarity index 97% rename from src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.C rename to src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.C index 94a63e2a51..844debe8da 100644 --- a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.C +++ b/src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.C @@ -70,8 +70,8 @@ Foam::surfaceWriters::boundaryDataWriter::boundaryDataWriter header_(options.getOrDefault("header", true)), streamOpt_ ( - IOstream::formatEnum("format", options, IOstream::ASCII), - IOstream::compressionEnum("compression", options) + IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII), + IOstreamOption::compressionEnum("compression", options) ), fieldScale_(options.subOrEmptyDict("fieldScale")) {} @@ -303,6 +303,8 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // Field writing methods defineSurfaceWriterWriteFields(Foam::surfaceWriters::boundaryDataWriter); diff --git a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H b/src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.H similarity index 98% rename from src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H rename to src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.H index ec7df24459..b77b89ea45 100644 --- a/src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H +++ b/src/surfMesh/writers/boundary/boundaryDataSurfaceWriter.H @@ -125,8 +125,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef boundaryDataSurfaceWriter_H -#define boundaryDataSurfaceWriter_H +#ifndef Foam_surfaceWriters_boundaryDataWriter_H +#define Foam_surfaceWriters_boundaryDataWriter_H #include "surfaceWriter.H" diff --git a/src/surfMesh/writers/surfaceWriter.C b/src/surfMesh/writers/common/surfaceWriter.C similarity index 95% rename from src/surfMesh/writers/surfaceWriter.C rename to src/surfMesh/writers/common/surfaceWriter.C index ac56c75071..fd3b7603e0 100644 --- a/src/surfMesh/writers/surfaceWriter.C +++ b/src/surfMesh/writers/common/surfaceWriter.C @@ -166,33 +166,6 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options) } -Foam::surfaceWriter::surfaceWriter -( - const meshedSurf& surf, - bool parallel, - const dictionary& options -) -: - surfaceWriter(options) -{ - setSurface(surf, parallel); -} - - -Foam::surfaceWriter::surfaceWriter -( - const pointField& points, - const faceList& faces, - bool parallel, - const dictionary& options -) -: - surfaceWriter(options) -{ - setSurface(points, faces, parallel); -} - - // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::surfaceWriter::~surfaceWriter() @@ -430,16 +403,14 @@ Foam::label Foam::surfaceWriter::size() const } -bool Foam::surfaceWriter::checkOpen() const +void Foam::surfaceWriter::checkOpen() const { - if (outputPath_.empty()) + if (!is_open()) { FatalErrorInFunction << type() << " : Attempted to write without a path" << nl << exit(FatalError); } - - return !outputPath_.empty(); } diff --git a/src/surfMesh/writers/surfaceWriter.H b/src/surfMesh/writers/common/surfaceWriter.H similarity index 93% rename from src/surfMesh/writers/surfaceWriter.H rename to src/surfMesh/writers/common/surfaceWriter.H index dde25e6540..db6d2341c5 100644 --- a/src/surfMesh/writers/surfaceWriter.H +++ b/src/surfMesh/writers/common/surfaceWriter.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,8 +68,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef surfaceWriter_H -#define surfaceWriter_H +#ifndef Foam_surfaceWriter_H +#define Foam_surfaceWriter_H #include #include "typeInfo.H" @@ -160,7 +160,7 @@ protected: // Protected Member Functions //- Verify that the outputPath_ has been set or FatalError - bool checkOpen() const; + void checkOpen() const; //- Merge surfaces if they are not already upToDate (parallel) //- or simply mark the surface as being up-to-date @@ -263,23 +263,6 @@ public: //- Default construct with specified options explicit surfaceWriter(const dictionary& options); - //- Construct from components - explicit surfaceWriter - ( - const meshedSurf& surf, - bool parallel = Pstream::parRun(), - const dictionary& options = dictionary() - ); - - //- Construct from components - surfaceWriter - ( - const pointField& points, - const faceList& faces, - bool parallel = Pstream::parRun(), - const dictionary& options = dictionary() - ); - //- Destructor. Calls close() virtual ~surfaceWriter(); @@ -368,6 +351,9 @@ public: // Queries, Access + //- Test if outputPath has been set + inline bool is_open() const noexcept; + //- Writer is associated with a surface bool hasSurface() const; @@ -379,40 +365,40 @@ public: //- The number of expected output fields. // Currently only used by the legacy VTK format. - inline label nFields() const; + inline label nFields() const noexcept; //- Set the number of expected output fields // Currently only used by the legacy VTK format. // \return old value - inline label nFields(const label n); + inline label nFields(const label n) noexcept; //- Are the field data to be treated as point data? - inline bool isPointData() const; + inline bool isPointData() const noexcept; //- Set handling of field data to face/point data // \return old value - inline bool isPointData(const bool on); + inline bool isPointData(const bool on) noexcept; //- Should a time directory be spliced into the output path? - inline bool useTimeDir() const; + inline bool useTimeDir() const noexcept; //- Enable/disable use of spliced output path // \return old value - inline bool useTimeDir(const bool on); + inline bool useTimeDir(const bool on) noexcept; //- Get output verbosity - inline bool verbose() const; + inline bool verbose() const noexcept; //- Enable/disable verbose output // \return old value - inline bool verbose(const bool on); + inline bool verbose(const bool on) noexcept; //- The current value of the point merge dimension (metre) - inline scalar mergeDim() const; + inline scalar mergeDim() const noexcept; //- Change the point merge dimension (metre) // \return old value - inline scalar mergeDim(const scalar dist); + inline scalar mergeDim(const scalar dist) noexcept; // Time diff --git a/src/surfMesh/writers/common/surfaceWriterCaching.H b/src/surfMesh/writers/common/surfaceWriterCaching.H new file mode 100644 index 0000000000..017e1e7096 --- /dev/null +++ b/src/surfMesh/writers/common/surfaceWriterCaching.H @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. + +Typedef + Foam::surfaceWriters::writerCaching + +Description + Compatibility name. Replaced (JAN-2022) by + Foam::ensightOutput::writerCaching + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_surfaceWriters_writerCaching_H +#define Foam_surfaceWriters_writerCaching_H + +#include "ensightWriterCaching.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace surfaceWriters +{ + +typedef Foam::ensightOutput::writerCaching writerCaching; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace surfaceWriters +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/writers/surfaceWriterI.H b/src/surfMesh/writers/common/surfaceWriterI.H similarity index 75% rename from src/surfMesh/writers/surfaceWriterI.H rename to src/surfMesh/writers/common/surfaceWriterI.H index e8a6b113fb..bded94061f 100644 --- a/src/surfMesh/writers/surfaceWriterI.H +++ b/src/surfMesh/writers/common/surfaceWriterI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,13 +27,19 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline Foam::label Foam::surfaceWriter::nFields() const +inline bool Foam::surfaceWriter::is_open() const noexcept +{ + return !outputPath_.empty(); +} + + +inline Foam::label Foam::surfaceWriter::nFields() const noexcept { return nFields_; } -inline Foam::label Foam::surfaceWriter::nFields(const label n) +inline Foam::label Foam::surfaceWriter::nFields(const label n) noexcept { label old(nFields_); nFields_ = n; @@ -41,13 +47,13 @@ inline Foam::label Foam::surfaceWriter::nFields(const label n) } -inline bool Foam::surfaceWriter::isPointData() const +inline bool Foam::surfaceWriter::isPointData() const noexcept { return isPointData_; } -inline bool Foam::surfaceWriter::isPointData(const bool on) +inline bool Foam::surfaceWriter::isPointData(const bool on) noexcept { bool old(isPointData_); isPointData_ = on; @@ -55,13 +61,13 @@ inline bool Foam::surfaceWriter::isPointData(const bool on) } -inline bool Foam::surfaceWriter::useTimeDir() const +inline bool Foam::surfaceWriter::useTimeDir() const noexcept { return useTimeDir_; } -inline bool Foam::surfaceWriter::useTimeDir(const bool on) +inline bool Foam::surfaceWriter::useTimeDir(const bool on) noexcept { bool old(useTimeDir_); useTimeDir_ = on; @@ -69,13 +75,13 @@ inline bool Foam::surfaceWriter::useTimeDir(const bool on) } -inline bool Foam::surfaceWriter::verbose() const +inline bool Foam::surfaceWriter::verbose() const noexcept { return verbose_; } -inline bool Foam::surfaceWriter::verbose(const bool on) +inline bool Foam::surfaceWriter::verbose(const bool on) noexcept { bool old(verbose_); verbose_ = on; @@ -83,13 +89,13 @@ inline bool Foam::surfaceWriter::verbose(const bool on) } -inline Foam::scalar Foam::surfaceWriter::mergeDim() const +inline Foam::scalar Foam::surfaceWriter::mergeDim() const noexcept { return mergeDim_; } -inline Foam::scalar Foam::surfaceWriter::mergeDim(const scalar dist) +inline Foam::scalar Foam::surfaceWriter::mergeDim(const scalar dist) noexcept { scalar old(mergeDim_); mergeDim_ = dist; diff --git a/src/surfMesh/writers/surfaceWriterMethods.H b/src/surfMesh/writers/common/surfaceWriterMethods.H similarity index 97% rename from src/surfMesh/writers/surfaceWriterMethods.H rename to src/surfMesh/writers/common/surfaceWriterMethods.H index 8db1366e18..a3d78e315b 100644 --- a/src/surfMesh/writers/surfaceWriterMethods.H +++ b/src/surfMesh/writers/common/surfaceWriterMethods.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef surfaceWriterMethods_H -#define surfaceWriterMethods_H +#ifndef Foam_surfaceWriterMethods_H +#define Foam_surfaceWriterMethods_H namespace Foam { diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriter.C b/src/surfMesh/writers/ensight/ensightSurfaceWriter.C index e90c9d5f48..8cdcc1bd2f 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriter.C +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriter.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -50,132 +50,12 @@ namespace surfaceWriters } -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -void Foam::surfaceWriters::ensightWriter::printTimeset -( - OSstream& os, - const label ts, - const scalar timeValue -) -{ - os - << "time set: " << ts << nl - << "number of steps: " << 1 << nl; - - // Single value - starts at index 0 - os << "filename start number: 0" << nl - << "filename increment: 1" << nl - << "time values:" << nl; - - os << " " << timeValue - << nl << nl; -} - - -void Foam::surfaceWriters::ensightWriter::printTimeset -( - OSstream& os, - const label ts, - const UList& values -) -{ - label pos_; - - os - << "time set: " << ts << nl - << "number of steps: " << values.size() << nl; - - // Assume contiguous numbering - starts at index 0 - os << "filename start number: 0" << nl - << "filename increment: 1" << nl; - - - os << "time values:" << nl; - pos_ = 0; - for (const scalar& val : values) - { - if (pos_ == 6) - { - os << nl; - pos_ = 0; - } - ++pos_; - - os << ' ' << setf(ios_base::right) << setw(12) << val; - } - os << nl << nl; -} - - -void Foam::surfaceWriters::ensightWriter::printTimeset -( - OSstream& os, - const label ts, - const UList& values, - const bitSet& indices -) -{ - label pos_; - - // Check if continuous numbering can be used - if - ( - values.empty() - || (indices.size() == values.size() && indices.all()) - ) - { - // Can simply emit as 0-based with increment - printTimeset(os, ts, values); - return; - } - - - // Generate time set - os - << "time set: " << ts << nl - << "number of steps: " << indices.count() << nl; - - - os << "filename numbers:" << nl; - pos_ = 0; - for (const label& idx : indices) - { - if (pos_ == 6) - { - os << nl; - pos_ = 0; - } - ++pos_; - - os << ' ' << setf(ios_base::right) << setw(8) << idx; - } - os << nl; - - - os << "time values:" << nl; - pos_ = 0; - for (const label& idx : indices) - { - if (pos_ == 6) - { - os << nl; - pos_ = 0; - } - ++pos_; - - os << ' ' << setf(ios_base::right) << setw(12) << values[idx]; - } - os << nl << nl; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::surfaceWriters::ensightWriter::ensightWriter() : surfaceWriter(), - writeFormat_(IOstream::ASCII), + writeFormat_(IOstreamOption::ASCII), collateTimes_(true), caching_("fieldsDict") // Historic name {} @@ -189,7 +69,7 @@ Foam::surfaceWriters::ensightWriter::ensightWriter surfaceWriter(options), writeFormat_ ( - IOstreamOption::formatEnum("format", options, IOstream::ASCII) + IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII) ), collateTimes_(options.getOrDefault("collateTimes", true)), caching_("fieldsDict") // Historic name diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriter.H b/src/surfMesh/writers/ensight/ensightSurfaceWriter.H index 4c4c97855e..a4e0ea9120 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriter.H +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriter.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,11 +57,11 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ensightSurfaceWriter_H -#define ensightSurfaceWriter_H +#ifndef Foam_surfaceWriters_ensightWriter_H +#define Foam_surfaceWriters_ensightWriter_H #include "surfaceWriter.H" -#include "surfaceWriterCaching.H" +#include "ensightWriterCaching.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,71 +80,18 @@ class ensightWriter { // Private Data - //- Output format option (default: IOstream::ASCII) - IOstream::streamFormat writeFormat_; + //- Output format option (default: ASCII) + IOstreamOption::streamFormat writeFormat_; //- Collate times (default: true) bool collateTimes_; //- Cached information for times, geometry, fields (collated) - writerCaching caching_; + ensightOutput::writerCaching caching_; // Private Member Functions - //- The geometry can be any of the following: - // - // 0: constant/static - // 1: moving, with the same frequency as the data - // 2: moving, with different frequency as the data - int geometryTimeset() const; - - //- Print time-set for ensight case file with a single time - static void printTimeset - ( - OSstream& os, - const label ts, - const scalar timeValue - ); - - //- Print time-set for ensight case file, with N times and 0-based - //- file numbering - // - // \verbatim - // TIME - // time set: ts - // number of steps: ns - // filename start number: 0 - // filename increment: 1 - // time values: time_1 time_2 ... time_ns - // \endverbatim - static void printTimeset - ( - OSstream& os, - const label ts, - const UList& times - ); - - - //- Print time-set for ensight case file, with N times, 0-based - //- file numbering but perhaps non-contiguous - // - // \verbatim - // TIME - // time set: ts - // number of steps: ns - // filename numbers: idx_1 idx_2 ... idx_ns - // time values: time_1 time_2 ... time_ns - // \endverbatim - static void printTimeset - ( - OSstream& os, - const label ts, - const UList& times, - const bitSet& indices - ); - - //- Write geometry fileName writeCollated(); diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C b/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C index 010195a4e7..564df9a18f 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,30 +26,6 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -int Foam::surfaceWriters::ensightWriter::geometryTimeset() const -{ - const scalarList& times = caching_.times(); - const bitSet& geoms = caching_.geometries(); - - if (geoms.count() <= 1) - { - // Static - return 0; - } - - if (geoms.size() == times.size() && geoms.all()) - { - // Geometry changing is the same as fields changing - return 1; - } - - // Geometry changing differently from fields - return 2; -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated() @@ -169,7 +145,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated // 1: moving, with the same frequency as the data // 2: moving, with different frequency as the data - const label tsGeom = geometryTimeset(); + const label tsGeom = caching_.geometryTimeset(); osCase << "FORMAT" << nl @@ -228,10 +204,10 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated << nl << "TIME" << nl; - printTimeset(osCase, 1, caching_.times()); + ensightCase::printTimeset(osCase, 1, caching_.times()); if (tsGeom == 2) { - printTimeset + ensightCase::printTimeset ( osCase, tsGeom, diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriterUncollated.C b/src/surfMesh/writers/ensight/ensightSurfaceWriterUncollated.C index 23ac92e38c..f1b8fe1c79 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriterUncollated.C +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriterUncollated.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,13 +32,13 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated() { checkOpen(); - const ensight::FileName surfName(outputPath_.name()); + const ensight::FileName baseName(outputPath_.name()); // Uncollated // ========== - // CaseFile: rootdir/