From bd9626f95cab67ad9c3fc776c7ae7851e4383050 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Sat, 12 Nov 2016 23:22:47 +0100 Subject: [PATCH] DEFEATURE: remove broken OFS surfaceFormat (issue #296, #294) - This format is fortunately little-used (or never used) since its inception. Using raw stream operators to write zones, points and faces in a single file was not well thought out - the output content varies with the Face template type (face, triFace, labelledFace), which makes it not very robust at all. The static read in OFSsurfaceFormat also has a bug - keeping transcribed faces from being passed through. Conclusion: removing it makes more sense that repairing and still not having something good. Do retain stream operators for MeshedSurface and UnsortedMeshedSurface, since they are useful for passing around data (eg, between processors), but they shouldn't be used for files. --- src/surfMesh/Make/files | 2 - src/surfMesh/MeshedSurface/MeshedSurface.H | 2 + .../UnsortedMeshedSurface.H | 2 + .../surfaceFormats/ofs/OFSsurfaceFormat.C | 243 ------------------ .../surfaceFormats/ofs/OFSsurfaceFormat.H | 155 ----------- .../surfaceFormats/ofs/OFSsurfaceFormatCore.C | 71 ----- .../surfaceFormats/ofs/OFSsurfaceFormatCore.H | 79 ------ .../ofs/OFSsurfaceFormatRunTime.C | 81 ------ 8 files changed, 4 insertions(+), 631 deletions(-) delete mode 100644 src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C delete mode 100644 src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H delete mode 100644 src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C delete mode 100644 src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H delete mode 100644 src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C diff --git a/src/surfMesh/Make/files b/src/surfMesh/Make/files index f7beae2f7c0..40182bbb29e 100644 --- a/src/surfMesh/Make/files +++ b/src/surfMesh/Make/files @@ -30,8 +30,6 @@ $(surfaceFormats)/nas/NASsurfaceFormatRunTime.C $(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C $(surfaceFormats)/obj/OBJstream.C $(surfaceFormats)/off/OFFsurfaceFormatRunTime.C -$(surfaceFormats)/ofs/OFSsurfaceFormatCore.C -$(surfaceFormats)/ofs/OFSsurfaceFormatRunTime.C $(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C $(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C $(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index 3ff8eb73b41..c30686f6b48 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -500,6 +500,7 @@ public: // IOstream Operators //- Read MeshedSurface from Istream. + // Avoid using to read/write file content (fragile). friend Istream& operator>> <Face> ( Istream&, @@ -508,6 +509,7 @@ public: //- Write MeshedSurface to Ostream. + // Avoid using to read/write file content (fragile). friend Ostream& operator<< <Face> ( Ostream&, diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H index 68a78888d4e..9be2e3151d1 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H @@ -403,6 +403,7 @@ public: // IOstream Operators //- Read UnsortedMeshedSurface from Istream. + // Avoid using to read/write file content (fragile). friend Istream& operator>> <Face> ( Istream&, @@ -411,6 +412,7 @@ public: //- Write UnsortedMeshedSurface to Ostream. + // Avoid using to read/write file content (fragile). friend Ostream& operator<< <Face> ( Ostream&, diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C deleted file mode 100644 index 203a4653c73..00000000000 --- a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C +++ /dev/null @@ -1,243 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "OFSsurfaceFormat.H" -#include "IFstream.H" -#include "IStringStream.H" -#include "ListOps.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template<class Face> -Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat -( - const fileName& filename -) -{ - read(filename); -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template<class Face> -bool Foam::fileFormats::OFSsurfaceFormat<Face>::read -( - const fileName& filename -) -{ - this->clear(); - - IFstream is(filename); - if (!is.good()) - { - FatalErrorInFunction - << "Cannot read file " << filename - << exit(FatalError); - } - - // read surfZones: - is >> this->storedZones(); - - // read points: - is >> this->storedPoints(); - - // must triangulate? - if (MeshedSurface<Face>::isTri()) - { - // read faces as 'face' and transcribe to 'triFace' - List<face> faceLst(is); - - MeshedSurface<face> surf - ( - xferMove(this->storedPoints()), - xferMove(faceLst), - xferMove(this->storedZones()) - ); - - this->transcribe(surf); - } - else - { - // read faces directly - is >> this->storedFaces(); - } - - return true; -} - - -template<class Face> -bool Foam::fileFormats::OFSsurfaceFormat<Face>::read -( - Istream& is, - pointField& pointLst, - List<Face>& faceLst, - List<surfZone>& zoneLst -) -{ - if (!is.good()) - { - FatalErrorInFunction - << "read error " - << exit(FatalError); - } - - // read surfZones: - is >> zoneLst; - - // read points: - is >> pointLst; - - // must triangulate? - if (MeshedSurface<Face>::isTri()) - { - // read faces as 'face' and transcribe to 'triFace' - List<face> origFaces(is); - - MeshedSurface<face> origSurf - ( - xferMove(pointLst), - xferMove(origFaces), - xferMove(zoneLst) - ); - - MeshedSurface<Face> surf; - surf.transcribe(origSurf); - } - else - { - // read faces directly - is >> faceLst; - } - - return true; -} - - -template<class Face> -bool Foam::fileFormats::OFSsurfaceFormat<Face>::read -( - Istream& is, - MeshedSurface<Face>& surf -) -{ - surf.clear(); - - if (!is.good()) - { - FatalErrorInFunction - << "read error " - << exit(FatalError); - } - - pointField pointLst; - List<Face> faceLst; - List<surfZone> zoneLst; - - read(is, pointLst, faceLst, zoneLst); - - surf.reset - ( - xferMove(pointLst), - xferMove(faceLst), - xferMove(zoneLst) - ); - - return true; -} - - -template<class Face> -bool Foam::fileFormats::OFSsurfaceFormat<Face>::read -( - Istream& is, - UnsortedMeshedSurface<Face>& surf -) -{ - surf.clear(); - MeshedSurface<Face> origSurf(is); - surf.transfer(origSurf); - - return true; -} - - - -template<class Face> -void Foam::fileFormats::OFSsurfaceFormat<Face>::write -( - const fileName& filename, - const MeshedSurfaceProxy<Face>& surf -) -{ - const List<Face>& faceLst = surf.surfFaces(); - const List<label>& faceMap = surf.faceMap(); - - OFstream os(filename); - if (!os.good()) - { - FatalErrorInFunction - << "Cannot open file for writing " << filename - << exit(FatalError); - } - - - OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones()); - - const List<surfZone>& zones = surf.surfZones(); - const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); - - if (useFaceMap) - { - os << "\n// faces:" << nl - << faceLst.size() << token::BEGIN_LIST << nl; - - label facei = 0; - forAll(zones, zoneI) - { - // Print all faces belonging to this zone - const surfZone& zone = zones[zoneI]; - - forAll(zone, localFacei) - { - os << faceLst[faceMap[facei++]] << nl; - } - } - os << token::END_LIST << nl; - } - else - { - os << "\n// faces:" << nl << faceLst << nl; - } - - IOobject::writeDivider(os); - - // Check state of Ostream - os.check("OFSsurfaceFormat<Face>::write(Ostream&)"); -} - - -// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H deleted file mode 100644 index 33ab7212a52..00000000000 --- a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H +++ /dev/null @@ -1,155 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -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 <http://www.gnu.org/licenses/>. - -Class - Foam::fileFormats::OFSsurfaceFormat - -Description - Provide a means of reading/writing the single-file OpenFOAM surface format. - -Note - This class provides more methods than the regular surface format interface. - -SourceFiles - OFSsurfaceFormat.C - -\*---------------------------------------------------------------------------*/ - -#ifndef OFSsurfaceFormat_H -#define OFSsurfaceFormat_H - -#include "Ostream.H" -#include "OFstream.H" -#include "MeshedSurface.H" -#include "MeshedSurfaceProxy.H" -#include "UnsortedMeshedSurface.H" -#include "OFSsurfaceFormatCore.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ -namespace fileFormats -{ - -/*---------------------------------------------------------------------------*\ - Class OFSsurfaceFormat Declaration -\*---------------------------------------------------------------------------*/ - -template<class Face> -class OFSsurfaceFormat -: - public MeshedSurface<Face>, - public OFSsurfaceFormatCore -{ - // Private Member Functions - - //- Disallow default bitwise copy construct - OFSsurfaceFormat(const OFSsurfaceFormat<Face>&); - - //- Disallow default bitwise assignment - void operator=(const OFSsurfaceFormat<Face>&); - - -public: - - // Constructors - - //- Construct from file name - OFSsurfaceFormat(const fileName&); - - - // Selectors - - //- Read file and return surface - static autoPtr<MeshedSurface<Face>> New(const fileName& name) - { - return autoPtr<MeshedSurface<Face>> - ( - new OFSsurfaceFormat<Face>(name) - ); - } - - - //- Destructor - virtual ~OFSsurfaceFormat() - {} - - - - // Member Functions - - //- Read surface mesh components - static bool read - ( - Istream&, - pointField&, - List<Face>&, - List<surfZone>& - ); - - //- Read MeshedSurface - static bool read - ( - Istream&, - MeshedSurface<Face>& - ); - - //- Read UnsortedMeshedSurface - // The output is sorted by zones - static bool read - ( - Istream&, - UnsortedMeshedSurface<Face>& - ); - - //- Write surface mesh components by proxy - static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - - //- Read from file - virtual bool read(const fileName&); - - //- Write object - virtual void write(const fileName& name) const - { - write(name, MeshedSurfaceProxy<Face>(*this)); - } -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace fileFormats -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "OFSsurfaceFormat.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C deleted file mode 100644 index 89ab4290956..00000000000 --- a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C +++ /dev/null @@ -1,71 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -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 <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "OFSsurfaceFormatCore.H" -#include "clock.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::fileFormats::OFSsurfaceFormatCore::writeHeader -( - Ostream& os, - const pointField& pointLst, - const UList<surfZone>& zoneLst -) -{ - // just emit some information until we get a nice IOobject - IOobject::writeBanner(os) - << "// OpenFOAM Surface Format - written " - << clock::dateTime().c_str() << nl - << "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl << nl - << "// surfZones:" << nl; - - - // treat a single zone as being unzoned - if (zoneLst.size() <= 1) - { - os << "0" << token::BEGIN_LIST << token::END_LIST << nl << nl; - } - else - { - os << zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl; - - forAll(zoneLst, zoneI) - { - zoneLst[zoneI].writeDict(os); - } - os << decrIndent << token::END_LIST << nl << nl; - } - - // Note: write with global point numbering - - IOobject::writeDivider(os) - << "\n// points:" << nl << pointLst << nl; - - IOobject::writeDivider(os); -} - - -// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H deleted file mode 100644 index 65e93f274e9..00000000000 --- a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H +++ /dev/null @@ -1,79 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -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 <http://www.gnu.org/licenses/>. - -Class - Foam::fileFormats::OFSsurfaceFormatCore - -Description - Internal class used by the OFSsurfaceFormat - -SourceFiles - OFSsurfaceFormatCore.C - -\*---------------------------------------------------------------------------*/ - -#ifndef OFSsurfaceFormatCore_H -#define OFSsurfaceFormatCore_H - -#include "Ostream.H" -#include "OFstream.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ -namespace fileFormats -{ - -/*---------------------------------------------------------------------------*\ - Class OFSsurfaceFormatCore Declaration -\*---------------------------------------------------------------------------*/ - -class OFSsurfaceFormatCore -{ -protected: - - // Protected Member Functions - - //- Write header information and surfZoneList - static void writeHeader - ( - Ostream&, - const pointField&, - const UList<surfZone>& - ); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace fileFormats -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C deleted file mode 100644 index 1f1069f0aba..00000000000 --- a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C +++ /dev/null @@ -1,81 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -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 <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "OFSsurfaceFormat.H" - -#include "addToRunTimeSelectionTable.H" -#include "addToMemberFunctionSelectionTable.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ -namespace fileFormats -{ - -// read MeshedSurface -addNamedTemplatedToRunTimeSelectionTable -( - MeshedSurface, - OFSsurfaceFormat, - face, - fileExtension, - ofs -); -addNamedTemplatedToRunTimeSelectionTable -( - MeshedSurface, - OFSsurfaceFormat, - triFace, - fileExtension, - ofs -); - - -// write MeshedSurfaceProxy -addNamedTemplatedToMemberFunctionSelectionTable -( - MeshedSurfaceProxy, - OFSsurfaceFormat, - face, - write, - fileExtension, - ofs -); -addNamedTemplatedToMemberFunctionSelectionTable -( - MeshedSurfaceProxy, - OFSsurfaceFormat, - triFace, - write, - fileExtension, - ofs -); - - -} -} - -// ************************************************************************* // -- GitLab