diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C index 23c1ab964c..76d29074c1 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C @@ -55,25 +55,25 @@ std::size_t Foam::base64Layer::encodedLength(std::size_t n) // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -inline unsigned char Foam::base64Layer::encode0() const +inline unsigned char Foam::base64Layer::encode0() const noexcept { // Top 6 bits of char0 return base64Chars[((group_[0] & 0xFC) >> 2)]; } -inline unsigned char Foam::base64Layer::encode1() const +inline unsigned char Foam::base64Layer::encode1() const noexcept { // Bottom 2 bits of char0, Top 4 bits of char1 return base64Chars[((group_[0] & 0x03) << 4) | ((group_[1] & 0xF0) >> 4)]; } -inline unsigned char Foam::base64Layer::encode2() const +inline unsigned char Foam::base64Layer::encode2() const noexcept { // Bottom 4 bits of char1, Top 2 bits of char2 return base64Chars[((group_[1] & 0x0F) << 2) | ((group_[2] & 0xC0) >> 6)]; } -inline unsigned char Foam::base64Layer::encode3() const +inline unsigned char Foam::base64Layer::encode3() const noexcept { // Bottom 6 bits of char2 return base64Chars[(group_[2] & 0x3F)]; diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H index b4ee9fdc30..dada0296ac 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H @@ -39,8 +39,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef base64Layer_H -#define base64Layer_H +#ifndef Foam_base64Layer_H +#define Foam_base64Layer_H #include @@ -72,16 +72,10 @@ class base64Layer // Private Member Functions - inline unsigned char encode0() const; - inline unsigned char encode1() const; - inline unsigned char encode2() const; - inline unsigned char encode3() const; - - //- No copy construct - base64Layer(const base64Layer&) = delete; - - //- No copy assignment - void operator=(const base64Layer&) = delete; + inline unsigned char encode0() const noexcept; + inline unsigned char encode1() const noexcept; + inline unsigned char encode2() const noexcept; + inline unsigned char encode3() const noexcept; protected: @@ -91,6 +85,12 @@ protected: //- Add a character to the group, outputting when the group is full. void add(char c); + //- No copy construct + base64Layer(const base64Layer&) = delete; + + //- No copy assignment + void operator=(const base64Layer&) = delete; + public: diff --git a/src/fileFormats/vtk/base/foamVtkCore.H b/src/fileFormats/vtk/base/foamVtkCore.H index 08615850ec..c0b6c2485b 100644 --- a/src/fileFormats/vtk/base/foamVtkCore.H +++ b/src/fileFormats/vtk/base/foamVtkCore.H @@ -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. @@ -52,7 +52,7 @@ namespace vtk // Enumerations //- The context when outputting a VTK file (XML or legacy). - enum OutputContext + enum OutputContext : uint8_t { INLINE, //!< Generate header and inline data HEADER, //!< Generate header only @@ -72,21 +72,21 @@ namespace vtk LEGACY_BINARY = 0x22, //!< Legacy raw binary, legacyRawFormatter }; - //- Test for XML append format - inline bool isAppend(enum formatType fmt) + //- Test for vtk append format (xml) + inline bool isAppend(enum formatType fmt) noexcept { return (uint8_t(fmt) & 0x10); } //- Test for vtk legacy format - inline bool isLegacy(enum formatType fmt) + inline bool isLegacy(enum formatType fmt) noexcept { return (uint8_t(fmt) & 0x20); } - //- Equivalent to enumeration in "vtkCellType.h" - enum cellType + //- Equivalent to enumeration in "vtkCellType.h" (should be uint8_t) + enum cellType : uint8_t { VTK_EMPTY_CELL = 0, VTK_VERTEX = 1, @@ -110,7 +110,7 @@ namespace vtk //- Some common XML tags for vtk files - enum class fileTag + enum class fileTag : uint8_t { VTK_FILE, //!< "VTKFile" DATA_ARRAY, //!< "DataArray" @@ -140,7 +140,7 @@ namespace vtk extern const Foam::Enum fileTagNames; //- Some common XML attributes for vtk files - enum class fileAttr + enum class fileAttr : uint8_t { OFFSET, //!< "offset" NUMBER_OF_COMPONENTS, //!< "NumberOfComponents" @@ -156,7 +156,7 @@ namespace vtk extern const Foam::Enum fileAttrNames; //- Some common names for XML DataArray entries - enum class dataArrayAttr + enum class dataArrayAttr : uint8_t { POINTS, //!< "Points" OFFSETS, //!< "offsets" diff --git a/src/fileFormats/vtk/base/foamVtkPTraits.H b/src/fileFormats/vtk/base/foamVtkPTraits.H index 0a96729dae..a2a18854af 100644 --- a/src/fileFormats/vtk/base/foamVtkPTraits.H +++ b/src/fileFormats/vtk/base/foamVtkPTraits.H @@ -42,17 +42,17 @@ Description namespace Foam { -// Forward declarations +// Forward Declarations class endian; /*---------------------------------------------------------------------------*\ Class vtkPTraits Declaration \*---------------------------------------------------------------------------*/ -template +template struct vtkPTraits { - // Static data members + // Static Data Members static const char* const typeName; }; diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.C b/src/fileFormats/vtk/file/foamVtkFileWriter.C index 0d5626475b..27334a2ff7 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriter.C +++ b/src/fileFormats/vtk/file/foamVtkFileWriter.C @@ -290,10 +290,10 @@ Foam::vtk::fileWriter::fileWriter const vtk::outputOptions opts ) : - contentType_(contentType), - opts_(opts), - parallel_(false), state_(outputState::CLOSED), + contentType_(contentType), + parallel_(false), + opts_(opts), nCellData_(0), nPointData_(0), outputFile_(), @@ -360,7 +360,7 @@ bool Foam::vtk::fileWriter::open(const fileName& file, bool parallel) // This means we can always check if format_ is defined to know if output // is desired on any particular process. - if (Pstream::master() || !parallel_) + if (!parallel_ || Pstream::master()) { mkDir(outputFile_.path()); diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.H b/src/fileFormats/vtk/file/foamVtkFileWriter.H index cb9b6a371d..248b6a9004 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriter.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,6 +42,8 @@ Description SourceFiles foamVtkFileWriter.C + foamVtkFileWriterI.H + foamVtkFileWriterTemplates.C \*---------------------------------------------------------------------------*/ @@ -71,7 +73,7 @@ protected: // Protected Member Data //- Internal tracking of the output state. - enum outputState + enum outputState : uint8_t { CLOSED = 0, //!< File is closed OPENED, //!< File is opened @@ -86,18 +88,18 @@ protected: static const Enum stateNames; - //- The content type - vtk::fileTag contentType_; - - //- The requested output options - outputOptions opts_; - - //- Writing in parallel (via master) - bool parallel_; - //- The output state outputState state_; + //- The content type (PolyData, UnstructuredGrid ...) + vtk::fileTag contentType_; + + //- Parallel writing (via master) + bool parallel_; + + //- Requested output options + vtk::outputOptions opts_; + //- The number of CellData written for the Piece thus far. label nCellData_; @@ -128,7 +130,7 @@ protected: //- The backend ostream in use inline std::ofstream& os() noexcept; - //- The VTK formatter in use + //- The VTK formatter in use. FatalError for off-processor. inline vtk::formatter& format(); //- True if output state corresponds to the test state. @@ -231,16 +233,16 @@ public: // Member Functions //- The content type - inline vtk::fileTag contentType() const; + inline vtk::fileTag contentType() const noexcept; //- The output options in use - inline vtk::outputOptions opts() const; + inline vtk::outputOptions opts() const noexcept; //- File extension for current format type. inline word ext() const; //- Commonly used query - inline bool legacy() const; + inline bool legacy() const noexcept; //- Parallel output requested? inline bool parallel() const noexcept; @@ -258,7 +260,11 @@ public: // If the file name has an extension, it will be used where if // appropriate or changed to suit the format (legacy/xml) type. // \note Expected calling states: (CLOSED). - bool open(const fileName& file, bool parallel=Pstream::parRun()); + virtual bool open + ( + const fileName& file, + bool parallel = Pstream::parRun() + ); //- End the file contents and close the file after writing. // \note Expected calling states: (PIECE | CELL_DATA | POINT_DATA). diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterI.H b/src/fileFormats/vtk/file/foamVtkFileWriterI.H index 192eac45a7..b9cbfd677c 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriterI.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriterI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,13 +53,13 @@ inline bool Foam::vtk::fileWriter::notState(outputState test) const noexcept // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline Foam::vtk::fileTag Foam::vtk::fileWriter::contentType() const +inline Foam::vtk::fileTag Foam::vtk::fileWriter::contentType() const noexcept { return contentType_; } -inline Foam::vtk::outputOptions Foam::vtk::fileWriter::opts() const +inline Foam::vtk::outputOptions Foam::vtk::fileWriter::opts() const noexcept { return opts_; } @@ -71,7 +71,7 @@ inline Foam::word Foam::vtk::fileWriter::ext() const } -inline bool Foam::vtk::fileWriter::legacy() const +inline bool Foam::vtk::fileWriter::legacy() const noexcept { return opts_.legacy(); } diff --git a/src/fileFormats/vtk/file/foamVtmWriter.C b/src/fileFormats/vtk/file/foamVtmWriter.C index bca2c6617c..fe75496a02 100644 --- a/src/fileFormats/vtk/file/foamVtmWriter.C +++ b/src/fileFormats/vtk/file/foamVtmWriter.C @@ -40,7 +40,7 @@ void Foam::vtk::vtmWriter::vtmEntry::clear() } -bool Foam::vtk::vtmWriter::vtmEntry::good() const +bool Foam::vtk::vtmWriter::vtmEntry::good() const noexcept { return ( @@ -397,9 +397,7 @@ Foam::label Foam::vtk::vtmWriter::beginBlock(const word& blockName) Foam::label Foam::vtk::vtmWriter::endBlock(const word& blockName) { - label nblock = blocks_.size(); - - if (nblock) + if (!blocks_.empty()) { const word curr(blocks_.remove()); diff --git a/src/fileFormats/vtk/file/foamVtmWriter.H b/src/fileFormats/vtk/file/foamVtmWriter.H index ba8c7931b3..3641cde23a 100644 --- a/src/fileFormats/vtk/file/foamVtmWriter.H +++ b/src/fileFormats/vtk/file/foamVtmWriter.H @@ -118,7 +118,7 @@ class vtmWriter vtmEntry& operator=(const vtmEntry&) = default; vtmEntry& operator=(vtmEntry&&) = default; - //- Construct null + //- Default construct vtmEntry() : type_(NONE) @@ -157,7 +157,7 @@ class vtmWriter // Member Functions //- Test the type - bool isType(Type what) const + bool isType(Type what) const noexcept { return type_ == what; } @@ -166,7 +166,7 @@ class vtmWriter void clear(); //- True if the entry is good. - bool good() const; + bool good() const noexcept; //- Output valid entry as XML bool write(vtk::formatter& format) const; @@ -207,7 +207,7 @@ public: // Constructors - //- Construct null, with autoName on + //- Default construct, with autoName on vtmWriter(); //- Construct with specified behaviour for autoName diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H index daf2545e01..e9297fef9b 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H @@ -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. @@ -53,7 +53,7 @@ namespace vtk class appendBase64Formatter : - public foamVtkBase64Layer + public vtk::foamVtkBase64Layer { // Private Data Members @@ -78,7 +78,7 @@ public: // Constructors //- Construct and attach to an output stream - appendBase64Formatter(std::ostream& os); + explicit appendBase64Formatter(std::ostream& os); //- Destructor. Closes/flushes the underlying layer. @@ -88,7 +88,7 @@ public: // Member Functions //- The output is APPEND_BASE64. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Output name for XML type ("append") virtual const char* name() const; @@ -101,6 +101,7 @@ public: virtual uint64_t offset(const uint64_t numbytes); }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C index 24a907fb37..dfb557309b 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C @@ -54,7 +54,7 @@ void Foam::vtk::appendRawFormatter::write Foam::vtk::appendRawFormatter::appendRawFormatter(std::ostream& os) : - formatter(os), + vtk::formatter(os), offset_(0) {} diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H index ab2c3e6ac8..3e175b9fb0 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H @@ -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. @@ -52,7 +52,7 @@ namespace vtk class appendRawFormatter : - public formatter + public vtk::formatter { // Private Data Members @@ -64,7 +64,12 @@ class appendRawFormatter uint64_t offset_; - // Private Member Functions +protected: + + // Protected Member Functions + + //- Write + void write(const char* s, std::streamsize n); //- No copy construct appendRawFormatter(const appendRawFormatter&) = delete; @@ -73,20 +78,12 @@ class appendRawFormatter void operator=(const appendRawFormatter&) = delete; -protected: - - // Protected Member Functions - - //- Write - void write(const char* s, std::streamsize n); - - public: // Constructors //- Construct and attach to an output stream - appendRawFormatter(std::ostream& os); + explicit appendRawFormatter(std::ostream& os); //- Destructor @@ -96,7 +93,7 @@ public: // Member Functions //- The output is APPEND_BINARY. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Output name for XML type ("append") virtual const char* name() const; @@ -122,9 +119,9 @@ public: //- A no-op for this format virtual void flush(); - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C index 8533d20ac0..e5adf8a1b5 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C @@ -68,7 +68,7 @@ inline void Foam::vtk::asciiFormatter::done() Foam::vtk::asciiFormatter::asciiFormatter(std::ostream& os) : - formatter(os), + vtk::formatter(os), pos_(0) {} @@ -76,13 +76,13 @@ Foam::vtk::asciiFormatter::asciiFormatter(std::ostream& os) Foam::vtk::asciiFormatter::asciiFormatter ( std::ostream& os, - unsigned precision + unsigned prec ) : - formatter(os), + vtk::formatter(os), pos_(0) { - os.precision(precision); + os.precision(prec); } diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H index 49d00918f7..fec4dc1288 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H @@ -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 @@ namespace vtk class asciiFormatter : - public formatter + public vtk::formatter { // Private Data Members @@ -89,10 +89,10 @@ public: // Constructors //- Construct and attach to an output stream, use default precision - asciiFormatter(std::ostream& os); + explicit asciiFormatter(std::ostream& os); //- Construct and attach to an output stream, use specified precision - asciiFormatter(std::ostream& os, unsigned precision); + asciiFormatter(std::ostream& os, unsigned prec); //- Destructor. Finishes the output line as required. @@ -102,7 +102,7 @@ public: // Member Functions //- The output is INLINE_ASCII. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Name for the XML output type ("ascii") virtual const char* name() const; @@ -127,9 +127,9 @@ public: //- The encoded length for ascii output is not applicable. // \return 0 virtual std::size_t encodedLength(std::size_t ignored) const; - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H index f5667fb029..013ac71572 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ namespace vtk class base64Formatter : - public foamVtkBase64Layer + public vtk::foamVtkBase64Layer { // Private Data Members @@ -73,7 +73,7 @@ public: // Constructors //- Construct and attach to an output stream - base64Formatter(std::ostream& os); + explicit base64Formatter(std::ostream& os); //- Destructor. Closes/flushes the underlying layer. @@ -83,7 +83,7 @@ public: // Member Functions //- The output is INLINE_BASE64. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Name for the XML output type ("binary") virtual const char* name() const; @@ -92,9 +92,9 @@ public: //- End the encoding sequence (padding the final characters with '=') // and write a newline to the output if any encoding was done. virtual void flush(); - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.C b/src/fileFormats/vtk/format/foamVtkBase64Layer.C index 9f29f230c2..311e27e1f6 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Layer.C +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.C @@ -41,7 +41,7 @@ void Foam::vtk::foamVtkBase64Layer::write std::streamsize n ) { - base64Layer::write(s, n); + Foam::base64Layer::write(s, n); } @@ -49,8 +49,8 @@ void Foam::vtk::foamVtkBase64Layer::write Foam::vtk::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os) : - formatter(os), - base64Layer(os) + vtk::formatter(os), + Foam::base64Layer(os) {} @@ -58,7 +58,7 @@ Foam::vtk::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os) Foam::vtk::foamVtkBase64Layer::~foamVtkBase64Layer() { - base64Layer::close(); + Foam::base64Layer::close(); } @@ -79,7 +79,7 @@ bool Foam::vtk::foamVtkBase64Layer::writeSize(const uint64_t numbytes) void Foam::vtk::foamVtkBase64Layer::write(const uint8_t val) { - base64Layer::add(val); + Foam::base64Layer::add(val); } @@ -120,13 +120,13 @@ void Foam::vtk::foamVtkBase64Layer::write(const double val) void Foam::vtk::foamVtkBase64Layer::flush() { - base64Layer::close(); + Foam::base64Layer::close(); } std::size_t Foam::vtk::foamVtkBase64Layer::encodedLength(std::size_t n) const { - return base64Layer::encodedLength(n); + return Foam::base64Layer::encodedLength(n); } diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.H b/src/fileFormats/vtk/format/foamVtkBase64Layer.H index dd26310d27..cde6d57856 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Layer.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.H @@ -50,23 +50,14 @@ namespace vtk class foamVtkBase64Layer : - public formatter, - protected base64Layer + public vtk::formatter, + protected Foam::base64Layer { // Private Data Members static const char* encoding_; - // Private Member Functions - - //- No copy construct - foamVtkBase64Layer(const foamVtkBase64Layer&) = delete; - - //- No copy assignment - void operator=(const foamVtkBase64Layer&) = delete; - - protected: // Protected Member Functions @@ -74,11 +65,17 @@ protected: //- Write void write(const char* s, std::streamsize n); + //- No copy construct + foamVtkBase64Layer(const foamVtkBase64Layer&) = delete; + + //- No copy assignment + void operator=(const foamVtkBase64Layer&) = delete; + // Constructors //- Construct and attach to an output stream - foamVtkBase64Layer(std::ostream& os); + explicit foamVtkBase64Layer(std::ostream& os); public: @@ -105,9 +102,9 @@ public: //- The encoded length for base64 encoded output. virtual std::size_t encodedLength(std::size_t n) const; - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 0e2a01d0ac..da8b33e00b 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -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. @@ -132,7 +132,7 @@ protected: // Constructors //- Construct and attach to an output stream - inline formatter(std::ostream& os); + inline explicit formatter(std::ostream& os); public: @@ -155,10 +155,10 @@ public: // Access //- Access to the underlying output stream - inline std::ostream& os(); + inline std::ostream& os() noexcept; //- The format-type / output options. - virtual const outputOptions& opts() const = 0; + virtual const vtk::outputOptions& opts() const = 0; //- Name for the XML output type or the legacy output type. virtual const char* name() const = 0; @@ -540,7 +540,6 @@ public: dataName, formatter::npos, true ); } - }; diff --git a/src/fileFormats/vtk/format/foamVtkFormatterI.H b/src/fileFormats/vtk/format/foamVtkFormatterI.H index 962778d381..4bd23ea96f 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatterI.H +++ b/src/fileFormats/vtk/format/foamVtkFormatterI.H @@ -67,7 +67,7 @@ inline Foam::vtk::formatter::formatter(std::ostream& os) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline std::ostream& Foam::vtk::formatter::os() +inline std::ostream& Foam::vtk::formatter::os() noexcept { return os_; } diff --git a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C index 64d72b7790..977d71e080 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C @@ -50,10 +50,10 @@ Foam::vtk::legacyAsciiFormatter::legacyAsciiFormatter Foam::vtk::legacyAsciiFormatter::legacyAsciiFormatter ( std::ostream& os, - unsigned precision + unsigned prec ) : - asciiFormatter(os, precision) + asciiFormatter(os, prec) {} diff --git a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H index d4ed966a8c..9b2604a89d 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,7 +53,7 @@ namespace vtk class legacyAsciiFormatter : - public asciiFormatter + public vtk::asciiFormatter { // Private Data Members @@ -75,10 +75,10 @@ public: // Constructors //- Construct and attach to an output stream, use default precision - legacyAsciiFormatter(std::ostream& os); + explicit legacyAsciiFormatter(std::ostream& os); //- Construct and attach to an output stream, use specified precision - legacyAsciiFormatter(std::ostream& os, unsigned precision); + legacyAsciiFormatter(std::ostream& os, unsigned prec); //- Destructor @@ -88,7 +88,7 @@ public: // Member Functions //- The output is LEGACY_ASCII. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Name for the legacy ascii output type ("ASCII") virtual const char* name() const; @@ -107,9 +107,9 @@ public: inline virtual formatter& endPointData() { return *this; } inline virtual formatter& endPiece() { return *this; } inline virtual formatter& endVTKFile() { return *this; } - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C index 18bf81a5db..77ea735550 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C @@ -57,7 +57,7 @@ Foam::vtk::legacyRawFormatter::legacyRawFormatter std::ostream& os ) : - formatter(os) + vtk::formatter(os) {} diff --git a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H index 84084debcd..6c4ccd3390 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,21 +55,12 @@ namespace vtk class legacyRawFormatter : - public formatter + public vtk::formatter { // Private Data Members static const char* legacyName_; - static const outputOptions opts_; - - - // Private Member Functions - - //- No copy construct - legacyRawFormatter(const legacyRawFormatter&) = delete; - - //- No copy assignment - void operator=(const legacyRawFormatter&) = delete; + static const vtk::outputOptions opts_; protected: @@ -79,13 +70,19 @@ protected: //- Write void write(const char* s, std::streamsize n); + //- No copy construct + legacyRawFormatter(const legacyRawFormatter&) = delete; + + //- No copy assignment + void operator=(const legacyRawFormatter&) = delete; + public: // Constructors //- Construct and attach to an output stream - legacyRawFormatter(std::ostream& os); + explicit legacyRawFormatter(std::ostream& os); //- Destructor @@ -95,7 +92,7 @@ public: // Member Functions //- The output is LEGACY_BINARY. - virtual const outputOptions& opts() const; + virtual const vtk::outputOptions& opts() const; //- Name for the legacy binary output type ("BINARY") virtual const char* name() const; @@ -127,9 +124,9 @@ public: inline virtual formatter& endPointData() { return *this; } inline virtual formatter& endPiece() { return *this; } inline virtual formatter& endVTKFile() { return *this; } - }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/fileFormats/vtk/output/foamVtkOutput.H b/src/fileFormats/vtk/output/foamVtkOutput.H index ad7d6bf774..0f67899c29 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.H +++ b/src/fileFormats/vtk/output/foamVtkOutput.H @@ -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. @@ -254,11 +254,29 @@ namespace legacy //- Emit header for POINTS (with trailing newline). inline void beginPoints(std::ostream& os, label nPoints); + //- Emit header for VERTICES (with trailing newline). + // The nConnectivity is the sum of all connectivity points used, + // but \b without additional space for the size prefixes. + // The additional prefix sizes are added internally. + // \note With nConnectivity == 0, assume one point per element + inline void beginVerts + ( + std::ostream& os, + label nVerts, + label nConnectivity = 0 + ); + //- Emit header for LINES (with trailing newline). // The nConnectivity is the sum of all connectivity points used, // but \b without additional space for the size prefixes. // The additional prefix sizes are added internally. - inline void beginLines(std::ostream& os, label nLines, label nConnectivity); + // \note With nConnectivity == 0, assume two points per element + inline void beginLines + ( + std::ostream& os, + label nLines, + label nConnectivity = 0 + ); //- Emit header for POLYGONS (with trailing newline). // The nConnectivity is the sum of all connectivity points used, diff --git a/src/fileFormats/vtk/output/foamVtkOutputI.H b/src/fileFormats/vtk/output/foamVtkOutputI.H index 9789eecc41..b013c2d7ff 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputI.H +++ b/src/fileFormats/vtk/output/foamVtkOutputI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -119,6 +119,24 @@ inline void Foam::vtk::legacy::beginPoints(std::ostream& os, label nPoints) } +inline void Foam::vtk::legacy::beginVerts +( + std::ostream& os, + label nVerts, + label nConnectivity +) +{ + if (!nConnectivity) + { + nConnectivity = nVerts; + } + os << nl + << legacy::fileTagNames[vtk::fileTag::VERTS] + << ' ' << nVerts + << ' ' << (nVerts + nConnectivity) << nl; +} + + inline void Foam::vtk::legacy::beginLines ( std::ostream& os, @@ -126,6 +144,10 @@ inline void Foam::vtk::legacy::beginLines label nConnectivity ) { + if (!nConnectivity) + { + nConnectivity = 2*nLines; + } os << nl << legacy::fileTagNames[vtk::fileTag::LINES] << ' ' << nLines diff --git a/src/fileFormats/vtk/output/foamVtkOutputOptions.H b/src/fileFormats/vtk/output/foamVtkOutputOptions.H index 72250e82e2..3fcc23d6eb 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputOptions.H +++ b/src/fileFormats/vtk/output/foamVtkOutputOptions.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,15 +61,15 @@ class outputOptions { // Private Member Data - //- The output style tuning - enum styleType - { - NONE = 0x00, //!< Normal - HEADER = 0x01 //!< Emit xml header - }; + /// //- The output style tuning + /// enum styleType + /// { + /// NONE = 0x00, //!< Normal + /// HEADER = 0x01 //!< Emit xml header + /// }; //- The output format type - formatType fmtType_; + vtk::formatType fmtType_; //- ASCII write precision mutable unsigned precision_; @@ -79,15 +79,16 @@ public: // Constructors - //- Construct null - XML insitu ASCII format with default precision + //- Default construct - XML insitu ASCII format with default precision inline outputOptions(); //- Construct with specified format and default (ASCII) precision + // // \note This constructor should remain non-explicit. - inline outputOptions(enum formatType fmtType); + inline outputOptions(enum vtk::formatType fmtType); //- Construct with specified format and (ASCII) write precision - inline outputOptions(enum formatType fmtType, unsigned prec); + inline outputOptions(enum vtk::formatType fmtType, unsigned prec); // Selectors @@ -101,28 +102,28 @@ public: // Access //- The output format type - inline formatType fmt() const; + inline vtk::formatType fmt() const noexcept; //- The file extension (legacy or xml) for the given content-type inline word ext(vtk::fileTag contentType) const; //- True if writer uses legacy file format - inline bool legacy() const; + inline bool legacy() const noexcept; //- True if writer uses XML file format (non-legacy) - inline bool xml() const; + inline bool xml() const noexcept; //- True if output format uses an append mode - inline bool append() const; + inline bool append() const noexcept; //- True if output format does not use an append mode - inline bool insitu() const; + inline bool insitu() const noexcept; //- True if output format is ASCII - inline bool ascii() const; + inline bool ascii() const noexcept; //- Return the ASCII write precision - inline unsigned precision() const; + inline unsigned precision() const noexcept; // Edit diff --git a/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H b/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H index e7e26ff05f..0394dd02b0 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H +++ b/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,8 +25,6 @@ License \*---------------------------------------------------------------------------*/ -#include "foamVtkOutput.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::vtk::outputOptions::outputOptions() @@ -38,7 +36,7 @@ inline Foam::vtk::outputOptions::outputOptions() inline Foam::vtk::outputOptions::outputOptions ( - enum formatType fmtType + enum vtk::formatType fmtType ) : fmtType_(fmtType), @@ -48,7 +46,7 @@ inline Foam::vtk::outputOptions::outputOptions inline Foam::vtk::outputOptions::outputOptions ( - enum formatType fmtType, + enum vtk::formatType fmtType, unsigned prec ) : @@ -68,7 +66,7 @@ Foam::vtk::outputOptions::newFormatter(std::ostream& os) const // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -inline Foam::vtk::formatType Foam::vtk::outputOptions::fmt() const +inline Foam::vtk::formatType Foam::vtk::outputOptions::fmt() const noexcept { return fmtType_; } @@ -85,7 +83,7 @@ inline Foam::word Foam::vtk::outputOptions::ext(vtk::fileTag contentType) const } -inline bool Foam::vtk::outputOptions::legacy() const +inline bool Foam::vtk::outputOptions::legacy() const noexcept { return ( @@ -95,13 +93,13 @@ inline bool Foam::vtk::outputOptions::legacy() const } -inline bool Foam::vtk::outputOptions::xml() const +inline bool Foam::vtk::outputOptions::xml() const noexcept { return !legacy(); } -inline bool Foam::vtk::outputOptions::append() const +inline bool Foam::vtk::outputOptions::append() const noexcept { return ( @@ -111,19 +109,19 @@ inline bool Foam::vtk::outputOptions::append() const } -inline bool Foam::vtk::outputOptions::insitu() const +inline bool Foam::vtk::outputOptions::insitu() const noexcept { return !append(); } -inline bool Foam::vtk::outputOptions::ascii() const +inline bool Foam::vtk::outputOptions::ascii() const noexcept { return !(unsigned(fmtType_) & 0x0F); } -inline unsigned Foam::vtk::outputOptions::precision() const +inline unsigned Foam::vtk::outputOptions::precision() const noexcept { return precision_; } diff --git a/src/fileFormats/vtk/write/foamVtkPolyWriter.C b/src/fileFormats/vtk/write/foamVtkPolyWriter.C index 28de456d9c..ae303a4278 100644 --- a/src/fileFormats/vtk/write/foamVtkPolyWriter.C +++ b/src/fileFormats/vtk/write/foamVtkPolyWriter.C @@ -67,6 +67,7 @@ void Foam::vtk::polyWriter::beginPiece { // Basic sizes nLocalPoints_ = points.size(); + nLocalVerts_ = 0; nLocalLines_ = edges.size(); nLocalPolys_ = 0; @@ -104,6 +105,7 @@ void Foam::vtk::polyWriter::beginPiece { // Basic sizes nLocalPoints_ = points.size(); + nLocalVerts_ = 0; nLocalLines_ = 0; nLocalPolys_ = faces.size(); @@ -568,6 +570,7 @@ Foam::vtk::polyWriter::polyWriter numberOfPoints_(0), numberOfCells_(0), nLocalPoints_(0), + nLocalVerts_(0), nLocalLines_(0), nLocalPolys_(0) { diff --git a/src/fileFormats/vtk/write/foamVtkPolyWriter.H b/src/fileFormats/vtk/write/foamVtkPolyWriter.H index 30481c828c..73acd63281 100644 --- a/src/fileFormats/vtk/write/foamVtkPolyWriter.H +++ b/src/fileFormats/vtk/write/foamVtkPolyWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,6 +82,9 @@ protected: //- Local number of points label nLocalPoints_; + //- Local number of vertices (points) + label nLocalVerts_; + //- Local number of lines (edges) label nLocalLines_; diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 66a255ca91..4309290e20 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -143,6 +143,7 @@ $(setWriters)/gltf/gltfSetWriterRunTime.C $(setWriters)/gnuplot/gnuplotSetWriterRunTime.C $(setWriters)/nastran/nastranSetWriterRunTime.C $(setWriters)/raw/rawSetWriterRunTime.C +$(setWriters)/vtk/foamVtkCoordSetWriter.C $(setWriters)/vtk/vtkSetWriterRunTime.C $(setWriters)/xmgrace/xmgraceSetWriterRunTime.C diff --git a/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C new file mode 100644 index 0000000000..a5ba3adcc6 --- /dev/null +++ b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C @@ -0,0 +1,574 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkCoordSetWriter.H" +#include "foamVtkOutput.H" +#include "globalIndex.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::vtk::coordSetWriter::beginPiece() +{ + // Basic sizes + nLocalPoints_ = 0; + nLocalVerts_ = 0; + nLocalLines_ = 0; + nLocalPolys_ = 0; + + for (const pointField& pts : points_) + { + const label npts = pts.size(); + nLocalPoints_ += npts; + + if (npts) + { + ++nLocalLines_; + } + } + + switch (elemOutput_) + { + case elemOutputType::NO_ELEMENTS: + { + nLocalVerts_ = nLocalLines_ = 0; + break; + } + case elemOutputType::DEFAULT_ELEMENTS: + { + if (points_.size() < 2) + { + //OR nLocalVerts_ = nLocalPoints_; + nLocalVerts_ = 0; + nLocalLines_ = 0; + } + break; + } + case elemOutputType::POINT_ELEMENTS: + { + nLocalVerts_ = nLocalPoints_; + nLocalLines_ = 0; + break; + } + case elemOutputType::LINE_ELEMENTS: + { + // Already determined + break; + } + } + + // Nothing else to do for legacy + if (legacy()) return; + + if (format_) + { + format().openTag + ( + vtk::fileTag::PIECE, + vtk::fileAttr::NUMBER_OF_POINTS, nLocalPoints_ + ); + if (nLocalVerts_) + { + format().xmlAttr(vtk::fileAttr::NUMBER_OF_VERTS, nLocalVerts_); + } + if (nLocalLines_) + { + format().xmlAttr(vtk::fileAttr::NUMBER_OF_LINES, nLocalLines_); + } + format().closeTag(); + } +} + + +void Foam::vtk::coordSetWriter::writePoints() +{ + this->beginPoints(nLocalPoints_); + + { + for (const pointField& pts : points_) + { + vtk::writeList(format(), pts); + } + } + + this->endPoints(); +} + + +void Foam::vtk::coordSetWriter::writeVertsLegacy() +{ + if (!nLocalVerts_) + { + return; // Nothing to do + } + + // connectivity = 1 per vertex + const label nLocalConns = nLocalVerts_; + + legacy::beginVerts(os_, nLocalVerts_, nLocalConns); + + labelList vertLabels(nLocalVerts_ + nLocalConns); + + auto iter = vertLabels.begin(); + + for (label pointi = 0; pointi < nLocalVerts_; ++pointi) + { + *iter++ = 1; + *iter++ = pointi; + } + + vtk::writeList(format(), vertLabels); + + if (format_) + { + format().flush(); + } +} + + +void Foam::vtk::coordSetWriter::writeLinesLegacy() +{ + if (!nLocalLines_) + { + return; // Nothing to do + } + + // connectivity = use each point + label nLocalConns = nLocalPoints_; + + legacy::beginLines(os_, nLocalLines_, nLocalConns); + + labelList vertLabels(nLocalLines_ + nLocalConns); + + auto iter = vertLabels.begin(); + + label localPointi = 0; + for (const pointField& pts : points_) + { + label npts = pts.size(); + + if (npts) + { + *iter++ = npts; + while (npts--) + { + *iter++ = localPointi; + ++localPointi; + } + } + } + + vtk::writeList(format(), vertLabels); + + if (format_) + { + format().flush(); + } +} + + +void Foam::vtk::coordSetWriter::writeVerts() +{ + if (!nLocalVerts_) + { + return; // Nothing to do + } + + // connectivity = 1 per vertex + const label nLocalConns = nLocalVerts_; + + if (format_) + { + format().tag(vtk::fileTag::VERTS); + } + + // + // 'offsets' (connectivity offsets) + // + { + labelList vertOffsets(nLocalVerts_); + label nOffs = vertOffsets.size(); + + // if (parallel_) + // { + // reduce(nOffs, sumOp