diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 9d4c04b407..401d0eddd8 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -53,7 +53,13 @@ Description // Output surface format surfaceFormat vtk; - formatOptions { } + formatOptions + { + vtk + { + precision 10; + } + } surfaces ( diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index 5b0fdde98a..95c588ff3f 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -45,6 +45,18 @@ Foam::proxySurfaceWriter::proxySurfaceWriter(const word& fileExt) {} +Foam::proxySurfaceWriter::proxySurfaceWriter +( + const word& fileExt, + const dictionary& options +) +: + surfaceWriter(), + fileExtension_(fileExt), + options_(options) +{} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::fileName Foam::proxySurfaceWriter::write @@ -73,8 +85,16 @@ Foam::fileName Foam::proxySurfaceWriter::write Info<< "Writing geometry to " << outputFile << endl; } - MeshedSurfaceProxy(surf.points(), surf.faces()) - .write(outputFile, fileExtension_); + MeshedSurfaceProxy + ( + surf.points(), + surf.faces() + ).write + ( + outputFile, + fileExtension_, + options_ + ); return outputFile; } diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index bfcfcd6615..4aeada0987 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -40,6 +40,9 @@ Description `-- surfaceName.{obj|stl|..} \endverbatim +Note + The formatOptions for proxy are file-type dependent. + SourceFiles proxySurfaceWriter.C @@ -63,12 +66,14 @@ class proxySurfaceWriter : public surfaceWriter { - // Private data //- The file extension associated with the proxy word fileExtension_; + //- Format options + dictionary options_; + public: @@ -79,7 +84,10 @@ public: // Constructors //- Construct for a given extension - proxySurfaceWriter(const word& fileExt); + explicit proxySurfaceWriter(const word& fileExt); + + //- Construct for a given extension, with some output options + proxySurfaceWriter(const word& fileExt, const dictionary& options); //- Destructor diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.C b/src/sampling/sampledSurface/writers/surfaceWriter.C index a149a60610..d73d6bfd2e 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.C +++ b/src/sampling/sampledSurface/writers/surfaceWriter.C @@ -54,46 +54,70 @@ namespace Foam Foam::autoPtr Foam::surfaceWriter::New(const word& writeType) { - auto cstrIter = wordConstructorTablePtr_->cfind(writeType); + const auto cstrIter = wordConstructorTablePtr_->cfind(writeType); - if (!cstrIter.found()) + if (cstrIter.found()) { - if (MeshedSurfaceProxy::canWriteType(writeType)) - { - // generally unknown, but can be written via MeshedSurfaceProxy - // use 'proxy' handler instead - return autoPtr(new proxySurfaceWriter(writeType)); - } - - if (!cstrIter.found()) - { - FatalErrorInFunction - << "Unknown write type \"" << writeType << "\"\n\n" - << "Valid types : " - << wordConstructorTablePtr_->sortedToc() << nl - << "Valid proxy types : " - << MeshedSurfaceProxy::writeTypes() << endl - << exit(FatalError); - } + return autoPtr(cstrIter()()); + } + else if (MeshedSurfaceProxy::canWriteType(writeType)) + { + // Unknown, but proxy handler can manage it + return autoPtr(new proxySurfaceWriter(writeType)); } - return autoPtr(cstrIter()()); + FatalErrorInFunction + << "Unknown write type \"" << writeType << "\"\n\n" + << "Valid types : " + << wordConstructorTablePtr_->sortedToc() << nl + << "Valid proxy types : " + << MeshedSurfaceProxy::writeTypes() << endl + << exit(FatalError); + + return nullptr; } Foam::autoPtr Foam::surfaceWriter::New(const word& writeType, const dictionary& options) { - // Constructors with dictionary options - auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType); - - if (!cstrIter.found()) { - // Revert to version without options - return Foam::surfaceWriter::New(writeType); + // Constructor with options (dictionary) + const auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType); + + if (cstrIter.found()) + { + return autoPtr(cstrIter()(options)); + } } - return autoPtr(cstrIter()(options)); + + // Drop through to version without options + + const auto cstrIter = wordConstructorTablePtr_->cfind(writeType); + + if (cstrIter.found()) + { + return autoPtr(cstrIter()()); + } + else if (MeshedSurfaceProxy::canWriteType(writeType)) + { + // Unknown, but proxy handler can manage it + return autoPtr + ( + new proxySurfaceWriter(writeType, options) + ); + } + + FatalErrorInFunction + << "Unknown write type \"" << writeType << "\"\n\n" + << "Valid types : " + << wordConstructorTablePtr_->sortedToc() << nl + << "Valid proxy types : " + << MeshedSurfaceProxy::writeTypes() << endl + << exit(FatalError); + + return nullptr; } diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index 69f1cc105e..2d4472f5a4 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -142,7 +142,7 @@ public: vtkSurfaceWriter(); //- Construct with some output options - vtkSurfaceWriter(const dictionary& options); + explicit vtkSurfaceWriter(const dictionary& options); //- Destructor diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H index 6b83014750..45d5053e1a 100644 --- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H @@ -51,7 +51,7 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators +// Forward declarations template class MeshedSurface; diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H index 85b932e4ea..3d57e4db99 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H @@ -64,15 +64,6 @@ class AC3DsurfaceFormat public MeshedSurface, public AC3DsurfaceFormatCore { - // Private Member Functions - - //- No copy construct - AC3DsurfaceFormat(const AC3DsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const AC3DsurfaceFormat&) = delete; - - public: // Constructors @@ -109,7 +100,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.H b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.H index 4d3de24f58..48d681f685 100644 --- a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.H @@ -61,12 +61,6 @@ class FLMAsurfaceFormat static inline void writeShell(OSstream& os, const Face& f); static inline void writeType(OSstream& os, const Face& f); - //- No copy construct - FLMAsurfaceFormat(const FLMAsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const FLMAsurfaceFormat&) = delete; - protected: @@ -114,7 +108,7 @@ public: // Member Functions - //- Write flma file + //- Write surface mesh as flma file virtual void write ( const fileName& name, @@ -136,15 +130,6 @@ class FLMAZsurfaceFormat : public FLMAsurfaceFormat { - // Private Member Functions - - //- No copy construct - FLMAZsurfaceFormat(const FLMAZsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const FLMAZsurfaceFormat&) = delete; - - public: // Constructors @@ -170,7 +155,7 @@ public: // Member Functions - //- Write flmaz file + //- Write surface mesh as flmaz file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C index ca460aa019..16f1bbe924 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C @@ -30,7 +30,6 @@ License #include "StringStream.H" #include "faceTraits.H" - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H index bb113f625c..525dbca979 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H @@ -64,12 +64,6 @@ class GTSsurfaceFormat // Triangulating on-the-fly is otherwise too annoying static bool checkIfTriangulated(const UList& faceLst); - //- No copy construct - GTSsurfaceFormat(const GTSsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const GTSsurfaceFormat&) = delete; - public: @@ -107,7 +101,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H index 6220af3a50..147aa736b3 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H @@ -35,6 +35,8 @@ Description GRID 28 10.20269-.030265-2.358-8 \endverbatim + The Nastran writer uses FREE format only. + SourceFiles NASsurfaceFormat.C @@ -76,12 +78,6 @@ class NASsurfaceFormat label elementId ); - //- No copy construct - NASsurfaceFormat(const NASsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const NASsurfaceFormat&) = delete; - public: @@ -108,10 +104,10 @@ public: // Member Functions - //- Read from a file + //- Read from file virtual bool read(const fileName& filename); - //- Write object file + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H index 65f4ef2885..4cbf7cd3dc 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H @@ -57,15 +57,6 @@ class OBJsurfaceFormat : public MeshedSurface { - // Private Member Functions - - //- No copy construct - OBJsurfaceFormat(const OBJsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const OBJsurfaceFormat&) = delete; - - public: // Constructors @@ -94,7 +85,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object file + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H index 1eab499a6c..01fdc1c410 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H @@ -64,15 +64,6 @@ class OFFsurfaceFormat : public MeshedSurface { - // Private Member Functions - - //- No copy construct - OFFsurfaceFormat(const OFFsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const OFFsurfaceFormat&) = delete; - - public: // Constructors @@ -101,7 +92,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H index 9286e25df1..0d2aa51bc6 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H @@ -61,15 +61,6 @@ class SMESHsurfaceFormat : public MeshedSurface { - // Private Member Functions - - //- No copy construct - SMESHsurfaceFormat(const SMESHsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const SMESHsurfaceFormat&) = delete; - - public: // Constructors @@ -95,7 +86,7 @@ public: // Member Functions - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H index e54db0cb35..4c06580240 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H @@ -73,12 +73,6 @@ class STARCDsurfaceFormat const label cellTableId ); - //- No copy construct - STARCDsurfaceFormat(const STARCDsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const STARCDsurfaceFormat&) = delete; - public: @@ -108,7 +102,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H index e4697ab8a7..524ca518c9 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H @@ -82,13 +82,6 @@ class STLsurfaceFormat ); - //- No copy construct - STLsurfaceFormat(const STLsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const STLsurfaceFormat&) = delete; - - public: // Constructors @@ -174,7 +167,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/tri/TRIReader.H b/src/surfMesh/surfaceFormats/tri/TRIReader.H index e66e783cb1..3b99feb9f0 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIReader.H +++ b/src/surfMesh/surfaceFormats/tri/TRIReader.H @@ -78,12 +78,6 @@ class TRIReader bool readFile(const fileName& filename); - //- No copy construct - TRIReader(const TRIReader&) = delete; - - //- No copy assignment - TRIReader& operator=(const TRIReader&) = delete; - public: diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H index 74e4a07733..5a711663ce 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H @@ -69,12 +69,6 @@ class TRIsurfaceFormat const label zoneI ); - //- No copy construct - TRIsurfaceFormat(const TRIsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const TRIsurfaceFormat&) = delete; - public: @@ -98,8 +92,7 @@ public: const dictionary& options = dictionary::null ); - //- Write UnsortedMeshedSurface, - // by default the output is not sorted by zones + //- Write UnsortedMeshedSurface, the output remains unsorted static void write ( const fileName& filename, @@ -113,7 +106,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C index c5ccced0e0..582167ce93 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,20 +27,7 @@ License #include "vtkUnstructuredReader.H" #include "scalarIOField.H" #include "faceTraits.H" -#include "OFstream.H" -#include "foamVtkOutput.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -// File-scope constant. -// -// TODO: make this run-time selectable (ASCII | BINARY) -// - Legacy mode only - -static const Foam::vtk::formatType fmtType = - Foam::vtk::formatType::LEGACY_ASCII; - // Foam::vtk::formatType::LEGACY_BINARY; - +#include // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -278,10 +265,11 @@ void Foam::fileFormats::VTKsurfaceFormat::write const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); - std::ofstream os(filename); + vtk::outputOptions opts = formatOptions(options); - autoPtr format = - vtk::newFormatter(os, fmtType); + std::ofstream os(filename, std::ios::binary); + + autoPtr format = opts.newFormatter(os); writeHeader(format(), pointLst); @@ -337,10 +325,11 @@ void Foam::fileFormats::VTKsurfaceFormat::write const dictionary& options ) { - std::ofstream os(filename); + vtk::outputOptions opts = formatOptions(options); - autoPtr format = - vtk::newFormatter(os, fmtType); + std::ofstream os(filename, std::ios::binary); + + autoPtr format = opts.newFormatter(os); writeHeader(format(), surf.points()); diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H index 5463ca4eee..c1c4b006ec 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,13 @@ Description The output is never sorted by zone. + \heading Output Options + \table + Property | Description | Required | Default + format | ascii or binary format | no | ascii + precision | Write precision in ascii | no | same as IOstream + \endtable + SourceFiles VTKsurfaceFormat.C @@ -69,13 +76,6 @@ class VTKsurfaceFormat ); - //- No copy construct - VTKsurfaceFormat(const VTKsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const VTKsurfaceFormat&) = delete; - - public: // Constructors @@ -112,7 +112,7 @@ public: //- Read from file virtual bool read(const fileName& filename); - //- Write object file + //- Write meshed surface to file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C index a73985d804..9de55aae6f 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,10 +25,38 @@ License #include "VTKsurfaceFormatCore.H" #include "clock.H" -#include "foamVtkOutput.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // +Foam::vtk::outputOptions +Foam::fileFormats::VTKsurfaceFormatCore::formatOptions +( + const dictionary& dict, + vtk::outputOptions opts +) +{ + opts.legacy(true); // Legacy. Use VTPsurfaceFormat for non-legacy + opts.append(false); // No append format for legacy + + const word formatName = dict.lookupOrDefault("format", ""); + if (formatName.size()) + { + opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII); + } + + opts.precision + ( + dict.lookupOrDefault + ( + "precision", + IOstream::defaultPrecision() + ) + ); + + return opts; +} + + void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader ( vtk::formatter& format, diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H index 5f04c8e64a..2da9cbab45 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,6 +26,14 @@ Class Description Internal class used by the VTKsurfaceFormat + Format is LEGACY_ASCII + + \heading Output Options + \table + Property | Description | Required | Default + format | ascii or binary format | no | ascii + precision | Write precision in ascii | no | same as IOstream + \endtable SourceFiles VTKsurfaceFormatCore.C @@ -35,9 +43,9 @@ SourceFiles #ifndef VTKsurfaceFormatCore_H #define VTKsurfaceFormatCore_H -#include "foamVtkFormatter.H" #include "point.H" #include "surfZone.H" +#include "foamVtkOutputOptions.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -56,6 +64,13 @@ protected: // Protected Static Member Functions + //- Extract format options (default format LEGACY_ASCII) + static vtk::outputOptions formatOptions + ( + const dictionary& dict, + vtk::outputOptions opts = vtk::formatType::LEGACY_ASCII + ); + //- Write header information with points static void writeHeader ( @@ -76,7 +91,6 @@ protected: vtk::formatter& format, const labelUList& zoneIds ); - }; diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C index c1f22611bd..e4ed8d8865 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,21 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "VTPsurfaceFormat.H" -#include "OFstream.H" -#include "foamVtkOutput.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -// File-scope constant. -// -// TODO: make this run-time selectable -// - No append mode supported -// - Legacy mode is dispatched via 'VTKsurfaceFormat' instead - -static const Foam::vtk::formatType fmtType = - Foam::vtk::formatType::INLINE_ASCII; - // Foam::vtk::formatType::INLINE_BASE64; - +#include // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -127,10 +113,11 @@ void Foam::fileFormats::VTPsurfaceFormat::write const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + vtk::outputOptions opts = formatOptions(options); + std::ofstream os(filename, std::ios::binary); - autoPtr format = - vtk::newFormatter(os, fmtType); + autoPtr format = opts.newFormatter(os); writeHeader(format(), pointLst, faceLst.size()); @@ -224,10 +211,11 @@ void Foam::fileFormats::VTPsurfaceFormat::write const dictionary& options ) { + vtk::outputOptions opts = formatOptions(options); + std::ofstream os(filename, std::ios::binary); - autoPtr format = - vtk::newFormatter(os, fmtType); + autoPtr format = opts.newFormatter(os); const UList& faceLst = surf.surfFaces(); diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.H b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.H index 259f2fffc0..6aee547fd4 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,9 +26,17 @@ Class Description Write surfaces in VTP (xml) format. + The default format is INLINE_BASE64 The output is never sorted by zone. + \heading Output Options + \table + Property | Description | Required | Default + format | ascii or binary format | no | binary + precision | Write precision in ascii | no | same as IOstream + \endtable + SourceFiles VTPsurfaceFormat.C @@ -69,13 +77,6 @@ class VTPsurfaceFormat ); - //- No copy construct - VTPsurfaceFormat(const VTPsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const VTPsurfaceFormat&) = delete; - - public: // Constructors @@ -109,7 +110,7 @@ public: // Member Functions - //- Write object file + //- Write meshed surface to a file virtual void write ( const fileName& name, diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C index 3bb9323e70..5f24e5ade6 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,10 +25,38 @@ License #include "VTPsurfaceFormatCore.H" #include "clock.H" -#include "foamVtkOutput.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // +Foam::vtk::outputOptions +Foam::fileFormats::VTPsurfaceFormatCore::formatOptions +( + const dictionary& dict, + vtk::outputOptions opts +) +{ + opts.legacy(false); // Non-legacy. Use VTKsurfaceFormat for legacy + opts.append(false); // No append format + + const word formatName = dict.lookupOrDefault("format", ""); + if (formatName.size()) + { + opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII); + } + + opts.precision + ( + dict.lookupOrDefault + ( + "precision", + IOstream::defaultPrecision() + ) + ); + + return opts; +} + + void Foam::fileFormats::VTPsurfaceFormatCore::writeHeader ( vtk::formatter& format, diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.H index 69393e6684..3290170f8e 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,15 @@ Class Foam::fileFormats::VTPsurfaceFormatCore Description - Internal class used by the VTPsurfaceFormat + Internal class used by the VTPsurfaceFormat. + The default format is INLINE_BASE64 + + \heading Output Options + \table + Property | Description | Required | Default + format | ascii or binary format | no | binary + precision | Write precision in ascii | no | same as IOstream + \endtable SourceFiles VTPsurfaceFormatCore.C @@ -35,9 +43,9 @@ SourceFiles #ifndef VTPsurfaceFormatCore_H #define VTPsurfaceFormatCore_H -#include "foamVtkFormatter.H" #include "point.H" #include "surfZone.H" +#include "foamVtkOutputOptions.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -56,6 +64,13 @@ protected: // Protected Static Member Functions + //- Extract format options (default format INLINE_BASE64) + static vtk::outputOptions formatOptions + ( + const dictionary& dict, + vtk::outputOptions opts = vtk::formatType::INLINE_BASE64 + ); + //- Write header information with points static void writeHeader ( diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C index 03aee4006a..a9da4e6b45 100644 --- a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C @@ -84,9 +84,9 @@ void Foam::fileFormats::X3DsurfaceFormat::write { const Face& f = faceLst[faceMap[faceIndex++]]; - forAll(f, fp) + for (const label vrti : f) { - os << f[fp] << ' '; + os << vrti << ' '; } os << "-1\n"; } @@ -97,9 +97,9 @@ void Foam::fileFormats::X3DsurfaceFormat::write { const Face& f = faceLst[faceIndex++]; - forAll(f, fp) + for (const label vrti : f) { - os << f[fp] << ' '; + os << vrti << ' '; } os << "-1\n"; } @@ -110,9 +110,9 @@ void Foam::fileFormats::X3DsurfaceFormat::write "' >\n" " , public X3DsurfaceFormatCore { - // Private Member Functions - - //- No copy construct - X3DsurfaceFormat(const X3DsurfaceFormat&) = delete; - - //- No copy assignment - void operator=(const X3DsurfaceFormat&) = delete; - public: // Constructors @@ -90,7 +82,7 @@ public: // Member Functions - //- Write object + //- Write surface mesh to file virtual void write ( const fileName& name, @@ -99,7 +91,6 @@ public: { write(name, MeshedSurfaceProxy(*this), options); } - }; diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H index 2102decfa0..55a8b19b45 100644 --- a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H @@ -51,6 +51,7 @@ namespace fileFormats class X3DsurfaceFormatCore { protected: + // Protected Member Functions //- Write file header