From 46e396af49e9d0e2028c69bf6500a6931dda778e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 1 Dec 2016 15:07:16 +0100 Subject: [PATCH] ENH: surfMesh::setWriteOption to adjust the write option of all components - otherwise difficult to avoid auto-write etc. - propagate similar changes to MeshedSurfaceAllocator, where is makes the most sense. --- .../MeshedSurfaceIOAllocator.C | 42 ++++++++++++++++++- .../MeshedSurfaceIOAllocator.H | 27 +++++++++++- src/surfMesh/surfMesh/surfMesh.H | 10 ++++- src/surfMesh/surfMesh/surfMeshIO.C | 17 ++++---- 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C index 9d063409df..06b6339b5b 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.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 | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,8 +72,32 @@ Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator {} +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::MeshedSurfaceIOAllocator::~MeshedSurfaceIOAllocator() +{ + clear(); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::MeshedSurfaceIOAllocator::setInstance(const fileName& inst) +{ + points_.instance() = inst; + faces_.instance() = inst; + zones_.instance() = inst; +} + + +void Foam::MeshedSurfaceIOAllocator::setWriteOption(IOobject::writeOption w) +{ + points_.writeOpt() = w; + faces_.writeOpt() = w; + zones_.writeOpt() = w; +} + + void Foam::MeshedSurfaceIOAllocator::clear() { points_.clear(); @@ -136,4 +160,20 @@ void Foam::MeshedSurfaceIOAllocator::reset } +bool Foam::MeshedSurfaceIOAllocator::writeObject +( + IOstream::streamFormat fmt, + IOstream::versionNumber ver, + IOstream::compressionType cmp +) const +{ + return + ( + points_.writeObject(fmt, ver, cmp) + && faces_.writeObject(fmt, ver, cmp) + && zones_.writeObject(fmt, ver, cmp) + ); +} + + // ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H index 6c8aa07e2a..ed74141bb9 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.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 | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -106,8 +106,21 @@ public: ); + //- Destructor + virtual ~MeshedSurfaceIOAllocator(); + + // Member Functions + // Database + + //- Set the instance for mesh files + void setInstance(const fileName&); + + //- Adjust the write option for all components + void setWriteOption(IOobject::writeOption); + + // Access //- Non-const access to the points @@ -177,6 +190,18 @@ public: const Xfer& faces, const Xfer& zones ); + + + // Writing + + //- Write using given format, version and compression + virtual bool writeObject + ( + IOstream::streamFormat, + IOstream::versionNumber, + IOstream::compressionType + ) const; + }; diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index 64e7c0239a..589c490a3b 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -200,7 +200,14 @@ public: const fileName& facesInstance() const; //- Set the instance for mesh files - void setInstance(const fileName&); + void setInstance + ( + const fileName&, + IOobject::writeOption = IOobject::AUTO_WRITE + ); + + //- Adjust the write option for all components + void setWriteOption(IOobject::writeOption); // Access @@ -322,6 +329,7 @@ public: //- Remove all files from mesh instance() void removeFiles() const; + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/surfMesh/surfMeshIO.C b/src/surfMesh/surfMesh/surfMeshIO.C index f2a5c54245..724c44d685 100644 --- a/src/surfMesh/surfMesh/surfMeshIO.C +++ b/src/surfMesh/surfMesh/surfMeshIO.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 | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::surfMesh::setInstance(const fileName& inst) +void Foam::surfMesh::setInstance(const fileName& inst, IOobject::writeOption w) { if (debug) { @@ -36,15 +36,16 @@ void Foam::surfMesh::setInstance(const fileName& inst) } instance() = inst; + Allocator::setInstance(inst); - storedIOPoints().writeOpt() = IOobject::AUTO_WRITE; - storedIOPoints().instance() = inst; + setWriteOption(w); +} - storedIOFaces().writeOpt() = IOobject::AUTO_WRITE; - storedIOFaces().instance() = inst; - storedIOZones().writeOpt() = IOobject::AUTO_WRITE; - storedIOZones().instance() = inst; +void Foam::surfMesh::setWriteOption(IOobject::writeOption w) +{ + writeOpt() = w; + Allocator::setWriteOption(w); }