From 8da6e8eb746b9a362560724aaabe4ed25b619635 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Wed, 31 May 2017 12:34:07 +0200 Subject: [PATCH] DEFEATURE: remove CCM combine boundary code - was generally somewhat fragile. The main problem stems from the fact that several interfaces may be attached to a boundary. No trivial means of solving this without too much work for a feature that is only "nice-to-have". --- .../mesh/conversion/ccm/ccmToFoam/ccmToFoam.C | 12 +- src/conversion/ccm/common/ccmBase.H | 2 +- src/conversion/ccm/reader/ccmBoundaryInfo.H | 8 +- .../ccm/reader/ccmInterfaceDefinitions.H | 77 +++++++---- src/conversion/ccm/reader/ccmReader.H | 66 +++++----- src/conversion/ccm/reader/ccmReaderMesh.C | 120 ++++-------------- src/conversion/ccm/reader/ccmReaderOptions.C | 13 -- src/conversion/ccm/reader/ccmSolutionTable.H | 37 +++--- src/conversion/ccm/writer/ccmWriter.C | 1 - src/conversion/ccm/writer/ccmWriter.H | 11 +- 10 files changed, 143 insertions(+), 204 deletions(-) diff --git a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C index 13049e8c9e3..52377df3393 100644 --- a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C +++ b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C @@ -125,12 +125,6 @@ int main(int argc, char *argv[]) "provide alternative base name when re-exporting (implies -export). " "Default is <meshExport>." ); - // This often works, but is not entirely stable - // argList::addBoolOption - // ( - // "combine", - // "combine identically named patches" - // ); argList::addBoolOption ( "noBaffles", @@ -211,10 +205,6 @@ int main(int argc, char *argv[]) { rOpts.useNumberedNames(true); } - else if (args.optionFound("combine")) - { - rOpts.combineBoundaries(true); - } if (args.optionFound("solids")) { @@ -295,7 +285,7 @@ int main(int argc, char *argv[]) { const fileName geomName = exportName + ".ccmg"; Info<< nl << "Re-exporting geometry as " << geomName << nl; - ccm::writer(geomName, mesh).writeGeometry(); + ccm::writer(geomName, mesh()).writeGeometry(); } } else diff --git a/src/conversion/ccm/common/ccmBase.H b/src/conversion/ccm/common/ccmBase.H index 5f789eadd0a..203420d9227 100644 --- a/src/conversion/ccm/common/ccmBase.H +++ b/src/conversion/ccm/common/ccmBase.H @@ -111,7 +111,7 @@ public: // Member Functions - // Access + // Access //- Explicity close the file and terminate ccmio access. // Return false if it was already closed. diff --git a/src/conversion/ccm/reader/ccmBoundaryInfo.H b/src/conversion/ccm/reader/ccmBoundaryInfo.H index 2e5f2377eb8..78655b898d8 100644 --- a/src/conversion/ccm/reader/ccmBoundaryInfo.H +++ b/src/conversion/ccm/reader/ccmBoundaryInfo.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Description - Containers for holding STARCCM boundary information + Container for holding STARCCM boundary information \*---------------------------------------------------------------------------*/ #ifndef ccmBoundaryInfo_H @@ -40,8 +40,11 @@ namespace Foam namespace ccm { +class ccmBoundaryInfo; +Ostream& operator<<(Ostream& os, const ccmBoundaryInfo& entry); + /*---------------------------------------------------------------------------*\ - Class ccm::ccmBoundaryInfo Declaration + Class Foam::ccm::ccmBoundaryInfo Declaration \*---------------------------------------------------------------------------*/ //- Helper when reading raw boundary information @@ -95,6 +98,7 @@ public: return ccmIndex != rhs.ccmIndex; } + //- Ostream Operator friend Ostream& operator<<(Ostream& os, const ccmBoundaryInfo& entry) { diff --git a/src/conversion/ccm/reader/ccmInterfaceDefinitions.H b/src/conversion/ccm/reader/ccmInterfaceDefinitions.H index a96a7b52b15..066340be806 100644 --- a/src/conversion/ccm/reader/ccmInterfaceDefinitions.H +++ b/src/conversion/ccm/reader/ccmInterfaceDefinitions.H @@ -38,8 +38,14 @@ namespace Foam namespace ccm { +class interfaceEntry; +class interfaceDefinitions; + +Ostream& operator<<(Ostream& os, const interfaceEntry& entry); +Ostream& operator<<(Ostream& os, const interfaceDefinitions& defs); + /*---------------------------------------------------------------------------*\ - Class ccm::interfaceEntry Declaration + Class Foam::ccm::interfaceEntry Declaration \*---------------------------------------------------------------------------*/ //- A STARCCM interface definition is a pair of boundary ids @@ -107,6 +113,12 @@ public: return bndId == bnd0 || bndId == bnd1; } + //- True if all internal ids are non-negative + bool valid() const + { + return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1); + } + //- Canonical name for boundary 0 word canonicalName0() const @@ -162,42 +174,57 @@ class interfaceDefinitions : public Map<interfaceEntry> { + + inline Map<interfaceEntry>& map() + { + return *this; + } + + inline const Map<interfaceEntry>& map() const + { + return *this; + } + + public: // Constructor //- Null construct interfaceDefinitions() - : - Map<interfaceEntry>() {} + //- Size + label size() const + { + return map().size(); + } - //- Scan available interface entries for one matching this boundary id - bool add(interfaceEntry entry) + //- Size + bool empty() const { - if - ( - entry.id >= 0 - && entry.bnd0 >= 0 && entry.bnd1 >= 0 - && entry.bnd0 != entry.bnd1 - ) - { - this->set(entry.id, entry); - return true; - } - else - { - return false; - } + return map().empty(); + } + + //- Clear + void clear() + { + map().clear(); + } + + + //- Add (valid) interface entry + bool add(const interfaceEntry& entry) + { + return (entry.valid() && map().set(entry.id, entry)); } //- Scan available interface entries for one matching this boundary id bool isInterface(label bndId) { - forAllConstIters(*this, iter) + forAllConstIters(map(), iter) { - if (iter().inInterface(bndId)) + if (iter.object().inInterface(bndId)) { return true; } @@ -211,9 +238,9 @@ public: word interfaceName(label bndId) { word ifname; - forAllConstIters(*this, iter) + forAllConstIters(map(), iter) { - ifname = iter().canonicalName(bndId); + ifname = iter.object().canonicalName(bndId); if (!ifname.empty()) { break; @@ -232,9 +259,7 @@ public: const interfaceDefinitions& defs ) { - os << static_cast<const Map<interfaceEntry>&>(defs) - << nl; - + os << defs.map() << nl; return os; } diff --git a/src/conversion/ccm/reader/ccmReader.H b/src/conversion/ccm/reader/ccmReader.H index 14408d3f944..67d937f1365 100644 --- a/src/conversion/ccm/reader/ccmReader.H +++ b/src/conversion/ccm/reader/ccmReader.H @@ -368,7 +368,7 @@ private: void validateInterface(List<labelPair>&); //- Renumber interface faces - void renumberInterfaces(const List<label>&); + void renumberInterfaces(const labelUList& oldToNew); //- Remove interfaces between domains (fluid/porosity; fluid/solid, etc) // reorganize baffle interfaces into [0-N/2; N/2-N] lists at the @@ -394,23 +394,27 @@ private: ) const; // polyMesh Friend Functions - void addPatches(polyMesh&) const; + void addPatches(polyMesh& mesh) const; //- Add faceZones based on monitoring boundary conditions - void addFaceZones(polyMesh&) const; + void addFaceZones(polyMesh& mesh) const; //- Get information about all available solutions bool detectSolution(); //- Get information about available fields // assume that all fields are available for all solution intervals - void determineFieldInfo(const ccmID& fieldSetNode, fieldTable&); + void determineFieldInfo + ( + const ccmID& fieldSetNode, + fieldTable& table + ); // Static Members //- Get map of porous regions - static Map<word> selectPorous(const Map<dictionary>&); + static Map<word> selectPorous(const Map<dictionary>& table); public: @@ -418,13 +422,13 @@ public: // Static Members //- Warn about repeated name - static void warnDuplicates(const word& context, const wordList&); + static void warnDuplicates(const word& context, const wordList& lst); // Constructors //- Open a file for reading - reader(const fileName&, const options& opts); + reader(const fileName& file, const reader::options& opts); //- Destructor (closes file) @@ -433,7 +437,7 @@ public: // Member Functions - // Access + // Access //- Reference to the reader options const reader::options& option() const; @@ -459,7 +463,7 @@ public: // const pointField& points() const { return points_; } - // Check + // Check //- Return true if file has geometry associated with it bool hasGeometry(); @@ -468,7 +472,7 @@ public: bool hasSolution(); - // Edit + // Edit //- Remap cellTable and boundaryRegion according to dictionary bool remapMeshInfo @@ -478,17 +482,17 @@ public: ); - // Write + // Write //- Write the polyMesh void writeMesh ( - const polyMesh&, + const polyMesh& mesh, IOstream::streamFormat fmt = IOstream::BINARY ) const; //- Write cellTable, boundaryRegion and interface information - void writeAux(const objectRegistry&) const; + void writeAux(const objectRegistry& registry) const; //- Detect and read geometry if possible bool readGeometry(const scalar scaleFactor = 1.0); @@ -593,12 +597,10 @@ class reader::options //- Merge in-place interfaces (default true) bool mergeInterfaces_; - //- Rename interface boundaries as InterfaceN_0, InterfaceN_1 (default true) + //- Rename interface boundaries as InterfaceN_0, InterfaceN_1 + // (default true) bool renameInterfaces_; - //- Combine identically named boundaries (default false) - bool combineBoundaries_; - //- Remove baffles by merging their respective faces (default false) bool removeBaffles_; @@ -623,7 +625,7 @@ public: // Member Functions - // Access + // Access //- Keep fluid regions (default true) bool keepFluid() const; @@ -640,12 +642,10 @@ public: //- Merge in-place interfaces (default true) bool mergeInterfaces() const; - //- Rename interface boundaries as InterfaceN_0, InterfaceN_1 (default true) + //- Rename interface boundaries as InterfaceN_0, InterfaceN_1 + // (default true) bool renameInterfaces() const; - //- Combine identically named boundaries (default false) - bool combineBoundaries() const; - //- Remove baffles by merging their respective faces (default false) bool removeBaffles() const; @@ -660,37 +660,35 @@ public: scalar undefScalar() const; - // Edit + // Edit //- Keep fluid regions - void keepFluid(bool); + void keepFluid(bool b); //- Keep porous regions - void keepPorous(bool); + void keepPorous(bool b); //- Keep solid regions - void keepSolid(bool); + void keepSolid(bool b); //- Merge in-place interfaces - void mergeInterfaces(bool); + void mergeInterfaces(bool b); //- Rename interface boundaries as InterfaceN_0, InterfaceN_1 - void renameInterfaces(bool); + void renameInterfaces(bool b); - //- Combine identically named boundaries - void combineBoundaries(bool); //- Remove baffles by merging their respective faces - void removeBaffles(bool); + void removeBaffles(bool b); //- Use numbered names (eg, patch_0, zone_0) instead of human-readable - void useNumberedNames(bool); + void useNumberedNames(bool b); //- Merge tolerance for points (default 0.05e-3) - void mergeTol(const scalar&); + void mergeTol(const scalar& tol); //- Value to assign for undefined solutions (default: NaN) - void undefScalar(const scalar&); + void undefScalar(const scalar& val); }; diff --git a/src/conversion/ccm/reader/ccmReaderMesh.C b/src/conversion/ccm/reader/ccmReaderMesh.C index c1f5077bdf1..bb819606252 100644 --- a/src/conversion/ccm/reader/ccmReaderMesh.C +++ b/src/conversion/ccm/reader/ccmReaderMesh.C @@ -517,51 +517,6 @@ void Foam::ccm::reader::readCells origBndId_ = -1; nPatches = 0; - HashTable<label, std::string> hashedNames; - if (option().combineBoundaries()) - { - // Ensure all the interfaces are orderd up-front: - forAll(interfaceDefinitions_, interI) - { - const interfaceEntry& ifentry = interfaceDefinitions_[interI]; - - label info0Index = -1; - label info1Index = -1; - - forAll(bndInfo, infoI) - { - if (bndInfo[infoI].ccmIndex == ifentry.bnd0) - { - info0Index = infoI; - } - else if (bndInfo[infoI].ccmIndex == ifentry.bnd1) - { - info1Index = infoI; - } - } - - if (info0Index == info1Index || info0Index < 0 || info1Index < 0) - { - // this should never be able to happen - continue; - } - - ccmBoundaryInfo& info0 = bndInfo[info0Index]; - ccmBoundaryInfo& info1 = bndInfo[info1Index]; - - // Preserve interface order - info0.patchId = nPatches++; - info1.patchId = nPatches++; - - // full safety: - info0.patchName = ifentry.canonicalName0(); - info1.patchName = ifentry.canonicalName1(); - - hashedNames.insert(info0.patchName, info0Index); - hashedNames.insert(info1.patchName, info1Index); - } - } - forAll(bndInfo, infoI) { ccmBoundaryInfo& info = bndInfo[infoI]; @@ -573,27 +528,8 @@ void Foam::ccm::reader::readCells } else { - if (option().combineBoundaries()) - { - // Check if patch name was already seen - auto citer = hashedNames.cfind(info.patchName); - if (citer.found()) - { - info.patchId = bndInfo[citer()].patchId; - } - else - { - hashedNames.insert(info.patchName, infoI); - - info.patchId = nPatches++; - origBndId_[info.patchId] = info.ccmIndex; - } - } - else - { - info.patchId = nPatches++; - origBndId_[info.patchId] = info.ccmIndex; - } + info.patchId = nPatches++; + origBndId_[info.patchId] = info.ccmIndex; } patchSizes_[info.patchId] += info.size; @@ -622,20 +558,6 @@ void Foam::ccm::reader::readCells ccmLookupOrder.resetAddressing(addr.xfer()); } - if (option().combineBoundaries()) - { - Info<<"patches combined by name: "; - if (nPatches == bndInfo.size()) - { - Info<<"none" << endl; - } - else - { - Info<< bndInfo.size() << " into " << nPatches << endl; - } - // Info<< ccmLookupOrder << endl; - } - // // Now we are ready to do the reading @@ -1521,7 +1443,7 @@ void Foam::ccm::reader::validateInterface void Foam::ccm::reader::renumberInterfaces ( - const labelList& oldToNew + const labelUList& oldToNew ) { forAll(domInterfaces_, elemI) @@ -1553,8 +1475,8 @@ void Foam::ccm::reader::cleanupInterfaces() if (bafInterfaces_.size() <= 0 && domInterfaces_.size() <= 0) { - Info<<"0 baffle interface pairs" << endl; - Info<<"0 domain interface pairs" << endl; + Info<<"0 baffle interface pairs" << nl + <<"0 domain interface pairs" << endl; return; } @@ -1568,8 +1490,8 @@ void Foam::ccm::reader::cleanupInterfaces() forAll(domInterfaces_, elemI) { - label face0 = domInterfaces_[elemI][0]; - label face1 = domInterfaces_[elemI][1]; + const label face0 = domInterfaces_[elemI][0]; + const label face1 = domInterfaces_[elemI][1]; Info<< "interface [" << elemI << "] = " << face0 << " - " << face1 << " own/neigh = " @@ -1902,9 +1824,11 @@ void Foam::ccm::reader::mergeInplaceInterfaces() // List of patch pairs that are interfaces DynamicList<labelPair> interfacePatches(interfaceDefinitions_.size()); - forAll(interfaceDefinitions_, interI) + label nWarn = 0; + + forAllConstIters(interfaceDefinitions_, iter) { - const interfaceEntry& ifentry = interfaceDefinitions_[interI]; + const interfaceEntry& ifentry = iter.object(); labelPair patchPair ( @@ -1920,7 +1844,7 @@ void Foam::ccm::reader::mergeInplaceInterfaces() ) { // This should not happen - Info<<"Warning : bad interface " << interI << " " << ifentry + Info<<"Warning : bad interface " << ifentry.id << " " << ifentry <<" on patches " << patchPair << endl; } else if @@ -1930,11 +1854,18 @@ void Foam::ccm::reader::mergeInplaceInterfaces() || patchSizes_[patchPair[1]] == 0 ) { - Info<<"Warning : skip interface " << interI << " " << ifentry - <<" on patches " << patchPair << nl - <<" has zero or different number of faces: (" - << patchSizes_[patchPair[0]] << " " << patchSizes_[patchPair[1]] << ")" - << endl; + if (!nWarn++) + { + Info<<"Warning: skip interface with zero or different" + << " number of faces" << nl; + } + + Info<<" Interface:" << ifentry.id << " " << ifentry + <<" patches " << patchPair + <<" sizes (" + << patchSizes_[patchPair[0]] + << " " << patchSizes_[patchPair[1]] << ")" + << nl; } else { @@ -1961,7 +1892,8 @@ void Foam::ccm::reader::mergeInplaceInterfaces() // Markup points to merge PackedBoolList whichPoints(points_.size()); - Info<< "interface merge points (tol=" << option().mergeTol() << "):" << endl; + Info<< "interface merge points (tol=" + << option().mergeTol() << "):" << endl; DynamicList<label> interfacesToMerge(interfacePatches.size()); forAll(interfacePatches, interI) diff --git a/src/conversion/ccm/reader/ccmReaderOptions.C b/src/conversion/ccm/reader/ccmReaderOptions.C index c6bfe87d7dc..994dba080ca 100644 --- a/src/conversion/ccm/reader/ccmReaderOptions.C +++ b/src/conversion/ccm/reader/ccmReaderOptions.C @@ -34,7 +34,6 @@ Foam::ccm::reader::options::options() keepSolid_(true), mergeInterfaces_(false), renameInterfaces_(true), - combineBoundaries_(false), removeBaffles_(false), useNumberedNames_(false), mergeTol_(0.05e-3), @@ -80,12 +79,6 @@ bool Foam::ccm::reader::options::renameInterfaces() const } -bool Foam::ccm::reader::options::combineBoundaries() const -{ - return combineBoundaries_; -} - - bool Foam::ccm::reader::options::removeBaffles() const { return removeBaffles_; @@ -141,12 +134,6 @@ void Foam::ccm::reader::options::renameInterfaces(bool b) } -void Foam::ccm::reader::options::combineBoundaries(bool b) -{ - combineBoundaries_ = b; -} - - void Foam::ccm::reader::options::removeBaffles(bool b) { removeBaffles_ = b; diff --git a/src/conversion/ccm/reader/ccmSolutionTable.H b/src/conversion/ccm/reader/ccmSolutionTable.H index 1be10bc2ddd..1a58d67cc68 100644 --- a/src/conversion/ccm/reader/ccmSolutionTable.H +++ b/src/conversion/ccm/reader/ccmSolutionTable.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,8 +29,8 @@ Description #define ccmSolutionTable_H #include "SLList.H" -#include "stringListOps.H" #include "Ostream.H" +#include "stringListOps.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -39,8 +39,16 @@ namespace Foam namespace ccm { +class fieldEntry; +class fieldTable; +class solutionEntry; + +Ostream& operator<<(Ostream& os, const fieldEntry& entry); +Ostream& operator<<(Ostream& os, const fieldTable& entry); +Ostream& operator<<(Ostream& os, const solutionEntry& entry); + /*---------------------------------------------------------------------------*\ - Class ccm::namesList Declaration + Class Foam::ccm::namesList Declaration \*---------------------------------------------------------------------------*/ //- A linked-list that is searchable by the 'name()' of the items @@ -124,7 +132,7 @@ public: /*---------------------------------------------------------------------------*\ - Class ccm::fieldEntry Declaration + Class Foam::ccm::fieldEntry Declaration \*---------------------------------------------------------------------------*/ //- A ccm field entry with short name, name, maxId and type @@ -208,15 +216,6 @@ public: // Edit - //- Set the field units - void units(const char* units) - { - if (units && *units) - { - units_ = units; - } - } - //- Set the field units void units(const std::string& units) { @@ -264,8 +263,9 @@ public: }; + /*---------------------------------------------------------------------------*\ - Class ccm::solutionEntry Declaration + Class Foam::ccm::solutionEntry Declaration \*---------------------------------------------------------------------------*/ //- A ccm solution entry with name, iteration and time @@ -291,8 +291,8 @@ public: solutionEntry ( const word& name, - const label& iteration, - const scalar& timeValue = 0 + const label iteration, + const scalar timeValue = 0 ) : name_(name), @@ -340,7 +340,7 @@ public: /*---------------------------------------------------------------------------*\ - Class ccm::solutionTable Declaration + Class Foam::ccm::solutionTable Declaration \*---------------------------------------------------------------------------*/ // Typedef: ccm::solutionTable @@ -349,7 +349,7 @@ typedef namesList<solutionEntry> solutionTable; /*---------------------------------------------------------------------------*\ - Class ccm::fieldTable Declaration + Class Foam::ccm::fieldTable Declaration \*---------------------------------------------------------------------------*/ //- A list of the available fields @@ -392,7 +392,6 @@ public: label maxFaceId() const { label maxId = 0; - forAllConstIters(*this, iter) { const label currMax = iter().maxFaceId(); diff --git a/src/conversion/ccm/writer/ccmWriter.C b/src/conversion/ccm/writer/ccmWriter.C index c08c653caea..8cd6dfdd503 100644 --- a/src/conversion/ccm/writer/ccmWriter.C +++ b/src/conversion/ccm/writer/ccmWriter.C @@ -292,7 +292,6 @@ void Foam::ccm::writer::writeProblem // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct for writing geometry Foam::ccm::writer::writer ( const fileName& file, diff --git a/src/conversion/ccm/writer/ccmWriter.H b/src/conversion/ccm/writer/ccmWriter.H index a2d57148c9b..c7b71c6311d 100644 --- a/src/conversion/ccm/writer/ccmWriter.H +++ b/src/conversion/ccm/writer/ccmWriter.H @@ -219,7 +219,12 @@ public: // Constructors //- Open a file for writing, with backup/overwrite existing file - writer(const fileName&, const polyMesh&, const bool backup=true); + writer + ( + const fileName& file, + const polyMesh& mesh, + const bool backup=true + ); //- Destructor (closes file) @@ -228,7 +233,7 @@ public: // Member Functions - // Write + // Write //- Write the mesh void writeGeometry(); @@ -237,7 +242,7 @@ public: // provide optional remapping dictionary void writeSolution ( - const IOobjectList&, + const IOobjectList& objects, const fileName& remappingDictName = fileName::null ); -- GitLab