Commit 8da6e8eb authored by Mark Olesen's avatar Mark Olesen
Browse files

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".
parent 62e7ddcc
......@@ -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
......
......@@ -111,7 +111,7 @@ public:
// Member Functions
// Access
// Access
//- Explicity close the file and terminate ccmio access.
// Return false if it was already closed.
......
......@@ -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)
{
......
......@@ -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;
}
......
......@@ -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);
};
......
......@@ -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)
......
......@@ -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;
......
......@@ -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