diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C index aaf8124192f7cbe656f1cf0153640b818a7dd344..c20581256367d9cbe78f97a34c564dc32fecb69e 100644 --- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C @@ -128,7 +128,7 @@ void Foam::MeshedSurfaceProxy<Face>::write } - // write surfMesh/points + // Write surfMesh/points { pointIOField io ( @@ -154,7 +154,7 @@ void Foam::MeshedSurfaceProxy<Face>::write } - // write surfMesh/faces + // Write surfMesh/faces { faceCompactIOList io ( @@ -187,7 +187,7 @@ void Foam::MeshedSurfaceProxy<Face>::write } - // write surfMesh/surfZones + // Write surfMesh/surfZones { surfZoneIOList io ( @@ -244,7 +244,7 @@ inline Foam::label Foam::MeshedSurfaceProxy<Face>::nTriangles() const } label nTri = 0; - for (const Face& f : this->surfFaces()) + for (const auto& f : faces_) { nTri += f.nTriangles(); } diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H index 3cfe055527b5781fb61965eb8cebde8864afd740..12e4891b180d2214ce6dc5e4f994904c0d0d78e3 100644 --- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H @@ -41,9 +41,6 @@ SourceFiles #define MeshedSurfaceProxy_H #include "pointField.H" -#include "labelledTri.H" -#include "HashSet.H" -#include "ListOps.H" #include "surfZoneList.H" #include "surfaceFormatsCore.H" #include "runTimeSelectionTables.H" @@ -55,7 +52,6 @@ namespace Foam { // Forward Declarations - template<class Face> class MeshedSurface; /*---------------------------------------------------------------------------*\ @@ -156,19 +152,19 @@ public: // Access //- The surface size is the number of faces - inline label size() const + label size() const { return faces_.size(); } //- Return const access to the points - inline const pointField& points() const + const pointField& points() const { return points_; } //- Return const access to the faces - inline const UList<Face>& surfFaces() const + const UList<Face>& surfFaces() const { return faces_; } @@ -176,19 +172,19 @@ public: //- Const access to the surface zones. // If zones are defined, they must be contiguous and cover the // entire surface - inline const UList<surfZone>& surfZones() const + const UList<surfZone>& surfZones() const { return zones_; } //- Const access to the faceMap, zero-sized when unused - inline const labelUList& faceMap() const + const labelUList& faceMap() const { return faceMap_; } - //- Use faceMap? - inline bool useFaceMap() const + //- Can/should use faceMap? + bool useFaceMap() const { return faceMap_.size() == faces_.size(); } diff --git a/src/surfMesh/mergedSurf/mergedSurf.C b/src/surfMesh/mergedSurf/mergedSurf.C index 579084685a7352cdafea61d27e12429ac3195a9a..fc0f2ed500c0c1f17257f367dbadaba64ee2098f 100644 --- a/src/surfMesh/mergedSurf/mergedSurf.C +++ b/src/surfMesh/mergedSurf/mergedSurf.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,13 +60,19 @@ Foam::mergedSurf::mergedSurf ( const pointField& unmergedPoints, const faceList& unmergedFaces, - const labelList& originalIds, + const labelList& origZoneIds, const scalar mergeDim ) : mergedSurf() { - merge(unmergedPoints, unmergedFaces, originalIds, mergeDim); + merge + ( + unmergedPoints, + unmergedFaces, + origZoneIds, + mergeDim + ); } @@ -82,8 +88,9 @@ void Foam::mergedSurf::clear() { points_.clear(); faces_.clear(); - zones_.clear(); pointsMap_.clear(); + + zoneIds_.clear(); } @@ -111,7 +118,14 @@ bool Foam::mergedSurf::merge const scalar mergeDim ) { - return merge(unmergedPoints, unmergedFaces, labelList(), mergeDim); + return + merge + ( + unmergedPoints, + unmergedFaces, + labelList(), + mergeDim + ); } @@ -119,7 +133,7 @@ bool Foam::mergedSurf::merge ( const pointField& unmergedPoints, const faceList& unmergedFaces, - const labelList& originalIds, + const labelList& origZoneIds, const scalar mergeDim ) { @@ -143,9 +157,9 @@ bool Foam::mergedSurf::merge ); - // Now handle zone/region information + // Now handle per-face information - globalIndex::gatherOp(originalIds, zones_); + globalIndex::gatherOp(origZoneIds, zoneIds_); return true; } diff --git a/src/surfMesh/mergedSurf/mergedSurf.H b/src/surfMesh/mergedSurf/mergedSurf.H index fda29e4031296acd6f2fdb6063f7d471abab09f3..f2adba45295930a3a06daa3628328db41b51a278 100644 --- a/src/surfMesh/mergedSurf/mergedSurf.H +++ b/src/surfMesh/mergedSurf/mergedSurf.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,31 +56,33 @@ class mergedSurf { pointField points_; faceList faces_; - labelList zones_; labelList pointsMap_; + labelList zoneIds_; + labelList faceIds_; + public: // Constructors - //- Construct null + //- Default construct mergedSurf() = default; - //- Copy construct null + //- Copy construct mergedSurf(const mergedSurf&) = default; //- Move construct mergedSurf(mergedSurf&&) = default; - //- Construct and merge. + //- Construct and merge mergedSurf ( const meshedSurf& unmergedSurface, const scalar mergeDim ); - //- Construct and merge. + //- Construct and merge mergedSurf ( const pointField& unmergedPoints, @@ -93,7 +95,7 @@ public: ( const pointField& unmergedPoints, const faceList& unmergedFaces, - const labelList& originalIds, + const labelList& origZoneIds, const scalar mergeDim ); @@ -128,7 +130,7 @@ public: //- Per-face zone/region information virtual const labelList& zoneIds() const { - return zones_; + return zoneIds_; } //- Map for reordered points (old-to-new) @@ -163,7 +165,7 @@ public: ( const pointField& unmergedPoints, const faceList& unmergedFaces, - const labelList& originalIds, + const labelList& origZoneIds, const scalar mergeDim ); @@ -175,7 +177,6 @@ public: //- Move assignment mergedSurf& operator=(mergedSurf&&) = default; - }; diff --git a/src/surfMesh/meshedSurf/meshedSurf.H b/src/surfMesh/meshedSurf/meshedSurf.H index 6d7b2415152432951efb469cc9489cee69666c30..36420372e36008b31bcecaab9ea6bb4f771f5d26 100644 --- a/src/surfMesh/meshedSurf/meshedSurf.H +++ b/src/surfMesh/meshedSurf/meshedSurf.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,8 +57,8 @@ public: // Constructors - //- Construct null - meshedSurf() = default; + //- Default construct + constexpr meshedSurf() noexcept = default; //- Destructor @@ -86,7 +86,7 @@ public: Class meshedSurf::emptySurface Declaration \*---------------------------------------------------------------------------*/ -//- A meshedSurf class with no faces, points or zoneId +//- A concrete meshedSurf class without faces, points, etc. class meshedSurf::emptySurface : public meshedSurf @@ -95,8 +95,8 @@ public: // Constructors - //- Construct null - emptySurface() = default; + //- Default construct + constexpr emptySurface() noexcept = default; //- Destructor diff --git a/src/surfMesh/meshedSurf/meshedSurfRef.H b/src/surfMesh/meshedSurf/meshedSurfRef.H index 7194780f8cce5a977e405db3ded25b77daf74bed..7ec13c203b87dd223befd9fbea960127f776dae4 100644 --- a/src/surfMesh/meshedSurf/meshedSurfRef.H +++ b/src/surfMesh/meshedSurf/meshedSurfRef.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,33 +52,33 @@ class meshedSurfRef { std::reference_wrapper<const pointField> points_; std::reference_wrapper<const faceList> faces_; - std::reference_wrapper<const labelList> ids_; + std::reference_wrapper<const labelList> zoneIds_; public: // Constructors - //- Construct null + //- Default construct meshedSurfRef() : points_(std::cref<pointField>(pointField::null())), faces_(std::cref<faceList>(faceList::null())), - ids_(std::cref<labelList>(labelList::null())) + zoneIds_(std::cref<labelList>(labelList::null())) {} //- Construct from components meshedSurfRef ( - const pointField& pts, - const faceList& fcs, - const labelList& ids = labelList::null() + const pointField& pointLst, + const faceList& faceLst, + const labelList& zoneIdLst = labelList::null() ) : - points_(std::cref<pointField>(pts)), - faces_(std::cref<faceList>(fcs)), - ids_(std::cref<labelList>(ids)) + points_(std::cref<pointField>(pointLst)), + faces_(std::cref<faceList>(faceLst)), + zoneIds_(std::cref<labelList>(zoneIdLst)) {} @@ -103,7 +103,7 @@ public: //- Per-face zone/region information. virtual const labelList& zoneIds() const { - return ids_.get(); + return zoneIds_.get(); } //- Remove all references by redirecting to null objects @@ -111,20 +111,20 @@ public: { points_ = std::cref<pointField>(pointField::null()); faces_ = std::cref<faceList>(faceList::null()); - ids_ = std::cref<labelList>(labelList::null()); + zoneIds_ = std::cref<labelList>(labelList::null()); } //- Reset components void reset ( - const pointField& pts, - const faceList& fcs, - const labelList& ids = labelList::null() + const pointField& pointLst, + const faceList& faceLst, + const labelList& zoneIdLst = labelList::null() ) { - points_ = std::cref<pointField>(pts); - faces_ = std::cref<faceList>(fcs); - ids_ = std::cref<labelList>(ids); + points_ = std::cref<pointField>(pointLst); + faces_ = std::cref<faceList>(faceLst); + zoneIds_ = std::cref<labelList>(zoneIdLst); } }; diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C index adfbe1f75452494d31ed455f21f2bfbd1964c71d..92046f20b38aa9a419c9761f8771291bc78f0fe1 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C @@ -51,13 +51,14 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } @@ -84,7 +85,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read if (!cueTo(is, "OBJECT", args) || args != "world") { FatalErrorInFunction - << "Cannot find \"OBJECT world\" in file " << filename + << "Cannot find 'OBJECT world' in file " << filename << nl << exit(FatalError); } @@ -119,8 +120,8 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read if (!readCmd(is, cmd, args)) { FatalErrorInFunction - << "Did not read up to \"kids 0\" while reading zone " - << zoneI << " from file " << filename + << "Did not read up to 'kids 0' while reading zone " + << zoneI << " from file " << filename << nl << exit(FatalError); } @@ -332,7 +333,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -354,7 +355,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write { if (useFaceMap) { - SubList<label> zoneMap(surf.faceMap(), zone.size(), zone.start()); + SubList<label> zoneMap(surf.faceMap(), zone.range()); PrimitivePatch<Face, UIndirectList, const pointField&> patch ( UIndirectList<Face>(faceLst, zoneMap), @@ -367,7 +368,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write { PrimitivePatch<Face, UList, const pointField&> patch ( - SubList<Face>(faceLst, zone.size(), zone.start()), + SubList<Face>(faceLst, zone.range()), pointLst ); @@ -395,7 +396,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -421,7 +422,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write label zoneIndex = 0; for (const surfZone& zone : zoneLst) { - SubList<label> zoneMap(faceMap, zone.size(), zone.start()); + SubList<label> zoneMap(faceMap, zone.range()); PrimitivePatch<Face, UIndirectList, const pointField&> patch ( UIndirectList<Face>(surf.surfFaces(), zoneMap), diff --git a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C index ead3c8236a32ca7679202c9878f6118fa4a16684..8a314f923ee401c84df66c6e984cb0b8c8ab95da 100644 --- a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C @@ -183,31 +183,26 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write // determine the number of faces by counting the // tri/quads/triangulated) faces in each zone label nFaces = 0; - List<label> zoneCount(zones.size()); + labelList zoneCount(zones.size()); { label faceIndex = 0; - forAll(zones, zoneI) + forAll(zones, zonei) { - const surfZone& zone = zones[zoneI]; + const surfZone& zone = zones[zonei]; label selCount = 0; - if (useFaceMap) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - forAll(zone, localFaceI) - { - selCount += countFaces(faceLst[faceMap[faceIndex++]]); - } - } - else - { - forAll(zone, localFaceI) - { - selCount += countFaces(faceLst[faceIndex++]); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + selCount += countFaces(f); } - zoneCount[zoneI] = selCount; + zoneCount[zonei] = selCount; nFaces += selCount; } } @@ -239,21 +234,14 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write label faceIndex = 0; for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - writeShell(os, faceLst[faceMap[faceIndex++]]); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - writeShell(os, faceLst[faceIndex++]); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeShell(os, f); } } newline(os); @@ -269,21 +257,14 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write label faceIndex = 0; for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - writeType(os, faceLst[faceMap[faceIndex++]]); - } - } - else - { - for (label i=0; i<nLocalFaces; ++i) - { - writeType(os, faceLst[faceIndex++]); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeType(os, f); } } newline(os); @@ -296,10 +277,10 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write newline(os); label faceIndex = 0; - forAll(zones, zoneI) + forAll(zones, zonei) { - const surfZone& zone = zones[zoneI]; - const label selCount = zoneCount[zoneI]; + const surfZone& zone = zones[zonei]; + const label selCount = zoneCount[zonei]; putFireString(os, zone.name()); putFireLabel(os, static_cast<int>(FIRECore::cellSelection)); @@ -345,7 +326,7 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write else { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } } diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C index 8ec55d8286552bbad0e23c3fffc3412a7b048a7c..fbf49ed0939d2a06e725f079bc1dd1ebd4c7ee04 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C @@ -57,7 +57,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::checkIfTriangulated if (nNonTris) { FatalErrorInFunction - << "Surface has " << nNonTris << "/" << faceLst.size() + << "Surface has " << nNonTris << '/' << faceLst.size() << " non-triangulated faces - not writing!" << endl; } @@ -86,13 +86,14 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } @@ -109,14 +110,14 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read } - // write directly into the lists: - pointField& pointLst = this->storedPoints(); - List<Face>& faceLst = this->storedFaces(); - List<label>& zoneIds = this->storedZoneIds(); + // Write directly into the lists + auto& pointLst = this->storedPoints(); + auto& faceLst = this->storedFaces(); + auto& zoneIds = this->storedZoneIds(); - pointLst.setSize(nPoints); - faceLst.setSize(nElems); - zoneIds.setSize(nElems); + pointLst.resize(nPoints); + faceLst.resize(nElems); + zoneIds.resize(nElems); // Read points forAll(pointLst, pointi) @@ -160,7 +161,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read lineStream >> e0Label >> e1Label >> e2Label; - // Optional zone number: read first, then check state on stream + // Optional zone number: read first, then check stream state if (lineStream) { label num; @@ -257,7 +258,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write streamOpt.format(IOstream::ASCII); const UList<point>& pointLst = surf.points(); - const UList<Face>& faceLst = surf.surfFaces(); + const UList<Face>& faceLst = surf.surfFaces(); const surfZoneList zones = ( @@ -272,7 +273,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -281,10 +282,10 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write os << "# GTS file" << nl << "# Zones:" << nl; - forAll(zones, zoneI) + forAll(zones, zonei) { - os << "# " << zoneI << " " - << zones[zoneI].name() << nl; + os << "# " << zonei << " " + << zones[zonei].name() << nl; } os << "#" << nl; @@ -311,18 +312,19 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write << meshPts[e.end()] + 1 << nl; } - // Write faces in terms of edges. + // Write faces in terms of edges const labelListList& faceEs = surf.faceEdges(); label faceIndex = 0; label zoneIndex = 0; + for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - for (label i=0; i<nLocalFaces; ++i) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - const labelList& fEdges = faceEs[faceIndex++]; + const label facei = faceIndex; + + const labelList& fEdges = faceEs[facei]; os << fEdges[0] + 1 << ' ' << fEdges[1] + 1 << ' ' @@ -358,7 +360,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -367,14 +369,13 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write os << "# GTS file" << nl << "# Zones:" << nl; - forAll(zoneToc, zoneI) + forAll(zoneToc, zonei) { - os << "# " << zoneI << " " - << zoneToc[zoneI].name() << nl; + os << "# " << zonei << " " + << zoneToc[zonei].name() << nl; } os << "#" << nl; - os << "# nPoints nEdges nTriangles" << nl << pointLst.size() << ' ' << surf.nEdges() << ' ' << surf.size() << nl; diff --git a/src/surfMesh/surfaceFormats/gts/triSurfaceGTSformat.C b/src/surfMesh/surfaceFormats/gts/triSurfaceGTSformat.C index f8374a62ba5c2faff9f8b2cc958e59edb0c61ac9..a405ca45c4c300252413680872cf5ebf455d2954 100644 --- a/src/surfMesh/surfaceFormats/gts/triSurfaceGTSformat.C +++ b/src/surfMesh/surfaceFormats/gts/triSurfaceGTSformat.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,7 +41,7 @@ void Foam::triSurface::writeGTS if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -89,11 +90,9 @@ void Foam::triSurface::writeGTS label faceIndex = 0; for (const surfacePatch& p : patches) { - const label nLocalFaces = p.size(); - - for (label i = 0; i<nLocalFaces; ++i) + for (label nLocal = p.size(); nLocal--; ++faceIndex) { - const label facei = faceMap[faceIndex++]; + const label facei = faceMap[faceIndex]; const labelList& fEdges = faceEdges()[facei]; diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C index 5e0f2b1666270bdd81ce66e8cf639305c883acc8..34632ffa60c0289b93f556608065ac524f49fbe1 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C @@ -38,8 +38,8 @@ inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell ( Ostream& os, const Face& f, - const label groupId, - label elementId + label elemId, + const label groupId ) { const label n = f.size(); @@ -47,7 +47,7 @@ inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell if (n == 3) { os << "CTRIA3" << ',' - << ++elementId << ',' + << (++elemId) << ',' << (groupId + 1) << ',' << (f[0] + 1) << ',' << (f[1] + 1) << ',' @@ -56,7 +56,7 @@ inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell else if (n == 4) { os << "CQUAD4" << ',' - << ++elementId << ',' + << (++elemId) << ',' << (groupId + 1) << ',' << (f[0] + 1) << ',' << (f[1] + 1) << ',' @@ -72,7 +72,7 @@ inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell const label fp2 = f.fcIndex(fp1); os << "CTRIA3" << ',' - << ++elementId << ',' + << (++elemId) << ',' << (groupId + 1) << ',' << (f[0] + 1) << ',' << (f[fp1] + 1) << ',' @@ -80,7 +80,7 @@ inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell } } - return elementId; + return elemId; } @@ -104,18 +104,18 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } - // Nastran index of points - DynamicList<label> pointId; + DynamicList<label> pointId; // Nastran point id (1-based) DynamicList<point> dynPoints; DynamicList<Face> dynFaces; DynamicList<label> dynZones; @@ -140,10 +140,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read // A single warning per unrecognized command wordHashSet unhandledCmd; + string line; while (is.good()) { string::size_type linei = 0; // Parsing position within current line - string line; is.getLine(line); // ANSA extension @@ -358,7 +358,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read // << " points:" << dynPoints.size() // << endl; - // transfer to normal lists + + // Transfer to normal lists this->storedPoints().transfer(dynPoints); pointId.shrink(); @@ -375,16 +376,16 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read // ~~~~~~~~~~~~~ for (Face& f : dynFaces) { - forAll(f, fp) + for (label& vert : f) { - f[fp] = mapPointId[f[fp]]; + vert = mapPointId[vert]; } } pointId.clearStorage(); mapPointId.clear(); - // create default zone names, or from ANSA/Hypermesh information + // Create default zone names, or from ANSA/Hypermesh information List<word> names(dynSizes.size()); forAllConstIters(zoneLookup, iter) { @@ -442,7 +443,7 @@ void Foam::fileFormats::NASsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -477,26 +478,18 @@ void Foam::fileFormats::NASsurfaceFormat<Face>::write label faceIndex = 0; label zoneIndex = 0; - label elementId = 0; + label elemId = 0; + for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; - elementId = writeShell(os, f, zoneIndex, elementId); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceIndex++]; - elementId = writeShell(os, f, zoneIndex, elementId); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + elemId = writeShell(os, f, elemId, zoneIndex); } ++zoneIndex; diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H index 7b553d3f019a20fc0ccada306a04ae8e956bbd82..47efac2d4393838ebb84cef2e8a522ad376cfadb 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H @@ -83,8 +83,8 @@ class NASsurfaceFormat ( Ostream& os, const Face& f, - const label groupId, - label elementId + label elemId, //!< 0-based element id + const label groupId //!< 0-based property/group id ); diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 407bd75dbcb80e4d5860d0876bcb8588be87f46f..25928e9732ccdc3dcdade5dc9f0bab4fdf01ae6e 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -52,13 +52,14 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } @@ -246,7 +247,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -280,6 +281,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write label faceIndex = 0; + for (const surfZone& zone : zones) { if (zone.name().size()) @@ -287,35 +289,19 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write os << "g " << zone.name() << nl; } - const label nLocalFaces = zone.size(); - - if (useFaceMap) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); - os << 'f'; - for (const label verti : f) - { - os << ' ' << verti + 1; - } - os << nl; - } - } - else - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceIndex++]; + const Face& f = faceLst[facei]; - os << 'f'; - for (const label verti : f) - { - os << ' ' << verti + 1; - } - os << nl; + os << 'f'; + for (const label verti : f) + { + os << ' ' << (verti + 1); } + os << nl; } } os << "# </faces>" << nl; diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C index db0ddff026f6baf288069576a0628a55c587b222..057584e1e56c8c390fb025fd3bc4a2defa32e07c 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C @@ -52,13 +52,14 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } @@ -83,15 +84,17 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read // Read points pointField pointLst(nPoints); - forAll(pointLst, pointi) + for (point& pt : pointLst) { scalar x, y, z; + line = this->getLineNoComment(is); { IStringStream lineStream(line); lineStream >> x >> y >> z; } - pointLst[pointi] = point(x, y, z); + + pt = point(x, y, z); } // Read faces - ignore optional zone information @@ -161,16 +164,18 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write const UList<label>& faceMap = surf.faceMap(); const UList<surfZone>& zoneLst = surf.surfZones(); + const bool useFaceMap = surf.useFaceMap(); + OFstream os(filename, streamOpt); if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } // Write header - os << "OFF" << endl + os << "OFF" << nl << "# Geomview OFF file written " << clock::dateTime().c_str() << nl << nl << "# points : " << pointLst.size() << nl @@ -188,62 +193,49 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write << "# nPoints nFaces nEdges" << nl << pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl << nl - << "# <points count=\"" << pointLst.size() << "\">" << endl; + << "# <points count=\"" << pointLst.size() << "\">" << nl; // Write vertex coords forAll(pointLst, ptI) { os << pointLst[ptI].x() << ' ' << pointLst[ptI].y() << ' ' - << pointLst[ptI].z() << " #" << ptI << endl; + << pointLst[ptI].z() << " #" << ptI << nl; } os << "# </points>" << nl << nl - << "# <faces count=\"" << faceLst.size() << "\">" << endl; + << "# <faces count=\"" << faceLst.size() << "\">" << nl; label faceIndex = 0; - forAll(zoneLst, zoneI) - { - os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl; + label zoneIndex = 0; - const label nLocalFaces = zoneLst[zoneI].size(); + for (const surfZone& zone : zoneLst) + { + os << "# <zone name=\"" << zone.name() << "\">" << nl; - if (surf.useFaceMap()) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); - os << f.size(); - for (const label verti : f) - { - os << ' ' << verti; - } + const Face& f = faceLst[facei]; - // add optional zone information - os << ' ' << zoneI << endl; - } - } - else - { - for (label i=0; i<nLocalFaces; ++i) + os << f.size(); + for (const label verti : f) { - const Face& f = faceLst[faceIndex++]; - - os << f.size(); - for (const label verti : f) - { - os << ' ' << verti; - } - - // add optional zone information - os << ' ' << zoneI << endl; + os << ' ' << verti; } + + // Add optional zone information + os << ' ' << zoneIndex << nl; } - os << "# </zone>" << endl; + + os << "# </zone>" << nl; + ++zoneIndex; } - os << "# </faces>" << endl; + + os << "# </faces>" << nl; } diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C index c23f0c993968ce4e5eaac2bd7957dc3e5de4cbaf..20fba29a2bc345bb0fc42103d706db8026a5810d 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C @@ -61,7 +61,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -87,37 +87,22 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write label faceIndex = 0; label zoneIndex = 0; + for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; - - os << f.size(); - for (const label verti : f) - { - os << ' ' << verti; - } - os << ' ' << zoneIndex << nl; - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + os << f.size(); + for (const label verti : f) { - const Face& f = faceLst[faceIndex++]; - - os << f.size(); - for (const label verti : f) - { - os << ' ' << verti; - } - os << ' ' << zoneIndex << nl; + os << ' ' << verti; } + os << ' ' << zoneIndex << nl; } ++zoneIndex; diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C index d354ba178f64d77cb25bcfc98ff9f934e24ebde1..797cee86520d898483e3bdf0ebf0963b2052bfa5 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C @@ -41,11 +41,11 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell const label cellTableId ) { - os << cellId // includes 1 offset - << ' ' << starcdShell // 3(shell) shape + os << (cellId + 1) + << ' ' << starcdShell // 3(shell) shape << ' ' << f.size() - << ' ' << cellTableId - << ' ' << starcdShellType; // 4(shell) + << ' ' << (cellTableId + 1) + << ' ' << starcdShellType; // 4(shell) // Primitives have <= 8 vertices, but prevent overrun anyhow // indent following lines for ease of reading @@ -54,9 +54,9 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell { if ((count % 8) == 0) { - os << nl << " " << cellId; + os << nl << " " << (cellId + 1); } - os << ' ' << pointi + 1; + os << ' ' << (pointi + 1); ++count; } os << nl; @@ -83,6 +83,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); fileName baseName = filename.lessExt(); @@ -120,7 +121,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << is.name() + << "Cannot read file " << is.name() << nl << exit(FatalError); } @@ -132,7 +133,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read DynamicList<label> dynSizes; Map<label> lookup; - // assume the cellTableIds are not intermixed + // Assume the cellTableIds are not intermixed bool sorted = true; label zoneId = 0; @@ -201,7 +202,8 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read SubList<label> vertices(vertexLabels, vertexLabels.size()); if (faceTraits<Face>::isTri() && nLabels > 3) { - // face needs triangulation + // The face needs triangulation + face f(vertices); faceList trias(f.nTriangles()); @@ -274,27 +276,22 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write writeHeader(os, STARCDCore::HEADER_CEL); label faceIndex = 0; - forAll(zones, zonei) + label zoneIndex = 0; + label elemId = 0; + for (const surfZone& zone : zones) { - const surfZone& zone = zones[zonei]; - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; - writeShell(os, f, faceIndex, zonei + 1); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceIndex++]; - writeShell(os, f, faceIndex, zonei + 1); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeShell(os, f, elemId, zoneIndex); + ++elemId; } + + ++zoneIndex; } // Simple .inp file - always UNCOMPRESSED diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H index 4bb1ad11db4b44e97ab23d9f2f39de446c9a6532..ac098419b50a5814e6b600192c83ef493784c579 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H @@ -78,8 +78,8 @@ class STARCDsurfaceFormat ( Ostream& os, const Face& f, - const label cellId, - const label cellTableId + const label cellId, //!< 0-based element Id + const label cellTableId //!< 0-based table id ); diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index 3154cb586f655142cfc96f8737c22126a47f3783..e002ea79d46a28523aa4f7fdf8f94d0fc7a46969 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -119,6 +119,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); // Read in the values @@ -181,7 +182,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read } zoneIds.clear(); - // Transfer: + // Transfer this->storedFaces().transfer(faceLst); if (names.size()) @@ -210,7 +211,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -230,23 +231,16 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii label faceIndex = 0; for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - os << "solid " << zone.name() << nl; - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - writeShell(os, pointLst, faceLst[faceMap[faceIndex++]]); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - writeShell(os, pointLst, faceLst[faceIndex++]); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeShell(os, pointLst, f); } os << "endsolid " << zone.name() << endl; } @@ -264,7 +258,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -289,23 +283,14 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary label zoneIndex = 0; for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; - writeShell(os, pointLst, f, zoneIndex); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceIndex++]; - writeShell(os, pointLst, f, zoneIndex); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeShell(os, pointLst, f, zoneIndex); } ++zoneIndex; @@ -331,7 +316,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -374,7 +359,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } diff --git a/src/surfMesh/surfaceFormats/stl/triSurfaceSTLformat.C b/src/surfMesh/surfaceFormats/stl/triSurfaceSTLformat.C index 209238912e4916d34831296431c8521ddab3c7e3..e9ae731a0857f9ae61157f2a79070e8653736a39 100644 --- a/src/surfMesh/surfaceFormats/stl/triSurfaceSTLformat.C +++ b/src/surfMesh/surfaceFormats/stl/triSurfaceSTLformat.C @@ -116,7 +116,7 @@ void Foam::triSurface::writeSTLASCII if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } diff --git a/src/surfMesh/surfaceFormats/tri/TRIReader.C b/src/surfMesh/surfaceFormats/tri/TRIReader.C index 107cf40806e5a26320a9060279a863c91bad9d5e..8125cc497dfa3b383c8ad45a9c92c1ebab3ab350 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIReader.C +++ b/src/surfMesh/surfaceFormats/tri/TRIReader.C @@ -53,6 +53,7 @@ static inline STLpoint getSTLpoint(Istream& is) bool Foam::fileFormats::TRIReader::readFile(const fileName& filename) { + // Clear everything this->clear(); sorted_ = true; @@ -60,7 +61,7 @@ bool Foam::fileFormats::TRIReader::readFile(const fileName& filename) if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } diff --git a/src/surfMesh/surfaceFormats/tri/TRIReader.H b/src/surfMesh/surfaceFormats/tri/TRIReader.H index 58084eb71d06e60659655e98d36916ad952a481b..957aa0fb56f9d791b50e0b0b317b8bbe8738dcfd 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIReader.H +++ b/src/surfMesh/surfaceFormats/tri/TRIReader.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -113,31 +113,31 @@ public: //- File read was already sorted - inline bool sorted() const + bool sorted() const { return sorted_; } //- Return full access to the points - inline List<STLpoint>& points() + List<STLpoint>& points() { return points_; } //- Return full access to the zones - inline List<label>& zoneIds() + List<label>& zoneIds() { return zoneIds_; } //- The list of solid names in the order of their first appearance - inline List<word>& names() + List<word>& names() { return names_; } //- The list of zone sizes in the order of their first appearance - inline List<label>& sizes() + List<label>& sizes() { return sizes_; } diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C index ad247808e4739b04b4b19e5bef76d820c6cac900..cc310bb50dfecf666019594b7849310836c109c0 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C @@ -81,6 +81,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); // Read in the values @@ -141,7 +142,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read } zoneIds.clear(); - // Transfer: + // Transfer this->storedFaces().transfer(faceLst); this->addZones(sizes); @@ -180,7 +181,7 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -188,23 +189,14 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write label zoneIndex = 0; for (const surfZone& zone : zones) { - const label nLocalFaces = zone.size(); - - if (useFaceMap) - { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceMap[faceIndex++]]; - writeShell(os, pointLst, f, zoneIndex); - } - } - else + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - for (label i=0; i<nLocalFaces; ++i) - { - const Face& f = faceLst[faceIndex++]; - writeShell(os, pointLst, f, zoneIndex); - } + const label facei = + (useFaceMap ? faceMap[faceIndex] : faceIndex); + + const Face& f = faceLst[facei]; + + writeShell(os, pointLst, f, zoneIndex); } ++zoneIndex; @@ -231,7 +223,7 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); } @@ -252,13 +244,15 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write label faceIndex = 0; label zoneIndex = 0; + for (const surfZone& zone : zoneLst) { - const label nLocalFaces = zone.size(); - - for (label i=0; i<nLocalFaces; ++i) + for (label nLocal = zone.size(); nLocal--; ++faceIndex) { - const Face& f = faceLst[faceMap[faceIndex++]]; + const label facei = faceMap[faceIndex]; + + const Face& f = faceLst[facei]; + writeShell(os, pointLst, f, zoneIndex); } diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C index 3cb9a747b9c3ab8bfbd92be03c41c9d459d7ecaf..068c6c77f231ac657a1f79971926b3a4a94b2185 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C @@ -89,13 +89,14 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read const fileName& filename ) { + // Clear everything this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction - << "Cannot read file " << filename + << "Cannot read file " << filename << nl << exit(FatalError); } diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C index 1d21d8781f007afe61dd6b958cdbf7b8963f0306..3b2982d94697749fe1044a58adf1060266a52afb 100644 --- a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C @@ -61,7 +61,7 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write if (!os.good()) { FatalErrorInFunction - << "Cannot open file for writing " << filename + << "Cannot write file " << filename << nl << exit(FatalError); }