Commit 24577907 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add faceZone::resetAddressing with constant flipMap

- remove unused static variable, use updated hashtable methods
parent 44cfc93b
......@@ -76,100 +76,102 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
label addPointZone(const polyMesh& mesh, const word& name)
label addPointZone(polyMesh& mesh, const word& name)
{
label zoneID = mesh.pointZones().findZoneID(name);
pointZoneMesh& zones = mesh.pointZones();
label zoneID = zones.findZoneID(name);
if (zoneID != -1)
{
Info<< "Reusing existing pointZone "
<< mesh.pointZones()[zoneID].name()
Info<< "Reusing existing pointZone " << zones[zoneID].name()
<< " at index " << zoneID << endl;
return zoneID;
}
else
{
pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh).pointZones();
zoneID = pointZones.size();
Info<< "Adding pointZone " << name << " at index " << zoneID << endl;
pointZones.setSize(zoneID+1);
pointZones.set
zoneID = zones.size();
Info<< "Adding pointZone " << name << " at index " << zoneID << endl;
zones.setSize(zoneID+1);
zones.set
(
zoneID,
new pointZone
(
name,
labelList(0),
zoneID,
new pointZone
(
name,
labelList(0),
zoneID,
pointZones
)
);
}
zones
)
);
return zoneID;
}
label addFaceZone(const polyMesh& mesh, const word& name)
label addFaceZone(polyMesh& mesh, const word& name)
{
label zoneID = mesh.faceZones().findZoneID(name);
faceZoneMesh& zones = mesh.faceZones();
label zoneID = zones.findZoneID(name);
if (zoneID != -1)
{
Info<< "Reusing existing faceZone " << mesh.faceZones()[zoneID].name()
Info<< "Reusing existing faceZone " << zones[zoneID].name()
<< " at index " << zoneID << endl;
return zoneID;
}
else
{
faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh).faceZones();
zoneID = faceZones.size();
Info<< "Adding faceZone " << name << " at index " << zoneID << endl;
faceZones.setSize(zoneID+1);
faceZones.set
zoneID = zones.size();
Info<< "Adding faceZone " << name << " at index " << zoneID << endl;
zones.setSize(zoneID+1);
zones.set
(
zoneID,
new faceZone
(
name,
labelList(0),
boolList(),
zoneID,
new faceZone
(
name,
labelList(0),
boolList(),
zoneID,
faceZones
)
);
}
zones
)
);
return zoneID;
}
label addCellZone(const polyMesh& mesh, const word& name)
label addCellZone(polyMesh& mesh, const word& name)
{
label zoneID = mesh.cellZones().findZoneID(name);
cellZoneMesh& zones = mesh.cellZones();
label zoneID = zones.findZoneID(name);
if (zoneID != -1)
{
Info<< "Reusing existing cellZone " << mesh.cellZones()[zoneID].name()
Info<< "Reusing existing cellZone " << zones[zoneID].name()
<< " at index " << zoneID << endl;
return zoneID;
}
else
{
cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh).cellZones();
zoneID = cellZones.size();
Info<< "Adding cellZone " << name << " at index " << zoneID << endl;
cellZones.setSize(zoneID+1);
cellZones.set
zoneID = zones.size();
Info<< "Adding cellZone " << name << " at index " << zoneID << endl;
zones.setSize(zoneID+1);
zones.set
(
zoneID,
new cellZone
(
name,
labelList(0),
zoneID,
new cellZone
(
name,
labelList(0),
zoneID,
cellZones
)
);
}
zones
)
);
return zoneID;
}
......@@ -340,13 +342,9 @@ int main(int argc, char *argv[])
if (perfectCover)
{
// Add empty zone for resulting internal faces
label cutZoneID = addFaceZone(mesh, cutZoneName);
const label cutZoneID = addFaceZone(mesh, cutZoneName);
mesh.faceZones()[cutZoneID].resetAddressing
(
isf,
boolList(masterPatch.size(), false)
);
mesh.faceZones()[cutZoneID].resetAddressing(isf.xfer(), false);
// Add the perfect interface mesh modifier
stitcher.set
......@@ -370,11 +368,7 @@ int main(int argc, char *argv[])
label masterZoneID = addFaceZone(mesh, mergePatchName + "MasterZone");
mesh.faceZones()[masterZoneID].resetAddressing
(
isf,
boolList(masterPatch.size(), false)
);
mesh.faceZones()[masterZoneID].resetAddressing(isf.xfer(), false);
// Slave patch
const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchName];
......@@ -387,19 +381,11 @@ int main(int argc, char *argv[])
}
label slaveZoneID = addFaceZone(mesh, mergePatchName + "SlaveZone");
mesh.faceZones()[slaveZoneID].resetAddressing
(
osf,
boolList(slavePatch.size(), false)
);
mesh.faceZones()[slaveZoneID].resetAddressing(osf.xfer(), false);
// Add empty zone for cut faces
label cutZoneID = addFaceZone(mesh, cutZoneName);
mesh.faceZones()[cutZoneID].resetAddressing
(
labelList(0),
boolList(0, false)
);
const label cutZoneID = addFaceZone(mesh, cutZoneName);
mesh.faceZones()[cutZoneID].resetAddressing(labelList(0), false);
// Add the sliding interface mesh modifier
......
......@@ -247,17 +247,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::whichZone
const label objectIndex
) const
{
const Map<label>& zm = zoneMap();
Map<label>::const_iterator zmIter = zm.find(objectIndex);
if (zmIter == zm.end())
{
return -1;
}
else
{
return zmIter();
}
return zoneMap().lookup(objectIndex, -1);
}
......@@ -579,13 +569,13 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::checkParallelSync
template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::movePoints(const pointField& p)
void Foam::ZoneMesh<ZoneType, MeshType>::movePoints(const pointField& pts)
{
PtrList<ZoneType>& zones = *this;
forAll(zones, zonei)
{
zones[zonei].movePoints(p);
zones[zonei].movePoints(pts);
}
}
......
......@@ -176,7 +176,7 @@ public:
//- Return zone index for the first match, return -1 if not found
label findIndex(const keyType& key) const;
//- Find zone index given a name
//- Find zone index given a name, return -1 if not found
label findZoneID(const word& zoneName) const;
//- Mark cells that match the zone specification
......@@ -191,12 +191,12 @@ public:
//- Check zone definition. Return true if in error.
bool checkDefinition(const bool report = false) const;
//- Check whether all procs have all zones and in same order. Return
// true if in error.
//- Check whether all procs have all zones and in same order.
// \return True if any errors.
bool checkParallelSync(const bool report = false) const;
//- Correct zone mesh after moving points
void movePoints(const pointField& p);
void movePoints(const pointField& pts);
//- writeData member function required by regIOobject
bool writeData(Ostream& os) const;
......
......@@ -33,8 +33,6 @@ Description
#include "cellZone.H"
#include "cellZoneMeshFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -36,10 +36,10 @@ Description
namespace Foam
{
template<class Zone, class MeshType> class ZoneMesh;
class cellZone;
class polyMesh;
template<class Zone, class MeshType> class ZoneMesh;
typedef ZoneMesh<cellZone, polyMesh> cellZoneMesh;
}
......
......@@ -33,8 +33,6 @@ Description
#include "faceZone.H"
#include "faceZoneMeshFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -36,10 +36,10 @@ Description
namespace Foam
{
template<class Zone, class MeshType> class ZoneMesh;
class faceZone;
class polyMesh;
template<class Zone, class MeshType> class ZoneMesh;
typedef ZoneMesh<faceZone, polyMesh> faceZoneMesh;
}
......
......@@ -33,8 +33,6 @@ Description
#include "pointZone.H"
#include "pointZoneMeshFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -36,10 +36,10 @@ Description
namespace Foam
{
template<class Zone, class MeshType> class ZoneMesh;
class pointZone;
class polyMesh;
template<class Zone, class MeshType> class ZoneMesh;
typedef ZoneMesh<pointZone, polyMesh> pointZoneMesh;
}
......
......@@ -42,6 +42,7 @@ namespace Foam
const char * const Foam::cellZone::labelsName = "cellLabels";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cellZone::cellZone
......
......@@ -52,7 +52,7 @@ namespace Foam
// Forward declaration of friend functions and operators
class cellZone;
Ostream& operator<<(Ostream&, const cellZone&);
Ostream& operator<<(Ostream& os, const cellZone& zn);
/*---------------------------------------------------------------------------*\
......@@ -64,6 +64,12 @@ class cellZone
public zone
{
// Private Member Functions
//- Disallow default bitwise copy construct
cellZone(const cellZone&) = delete;
protected:
// Protected data
......@@ -72,14 +78,6 @@ protected:
const cellZoneMesh& zoneMesh_;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
cellZone(const cellZone&);
public:
// Static data members
......@@ -117,7 +115,7 @@ public:
const word& name,
const labelUList& addr,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
//- Construct from components, transferring contents
......@@ -126,36 +124,36 @@ public:
const word& name,
const Xfer<labelList>& addr,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
//- Construct from dictionary
cellZone
(
const word& name,
const dictionary&,
const dictionary& dict,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
//- Construct given the original zone and resetting the
// cell list and zone mesh information
//- Construct given the original zone,
// resetting the cell list and zone mesh information
cellZone
(
const cellZone&,
const cellZone& cz,
const labelUList& addr,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
//- Construct given the original zone, resetting the
// cell list and zone mesh information
//- Construct given the original zone,
// resetting the cell list and zone mesh information
cellZone
(
const cellZone&,
const cellZone& cz,
const Xfer<labelList>& addr,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
//- Construct and return a clone, resetting the zone mesh
......@@ -190,9 +188,9 @@ public:
static autoPtr<cellZone> New
(
const word& name,
const dictionary&,
const dictionary& dict,
const label index,
const cellZoneMesh&
const cellZoneMesh& zm
);
......@@ -211,33 +209,33 @@ public:
//- Check zone definition. Return true if in error.
virtual bool checkDefinition(const bool report = false) const;
//- Check whether zone is synchronised across coupled boundaries. Return
// true if in error.
//- Check whether zone is synchronised across coupled boundaries.
// \return True if any errors.
virtual bool checkParallelSync(const bool report = false) const
{
return false;
}
//- Write dictionary
virtual void writeDict(Ostream&) const;
virtual void writeDict(Ostream& os) const;
// Member Operators
//- Assign to zone, clearing demand-driven data
void operator=(const cellZone&);
void operator=(const cellZone& zn);
//- Assign addressing, clearing demand-driven data
void operator=(const labelUList&);
void operator=(const labelUList& addr);
//- Assign addressing, clearing demand-driven data
void operator=(const Xfer<labelList>&);
void operator=(const Xfer<labelList>& addr);
// I-O
//- Ostream Operator
friend Ostream& operator<<(Ostream&, const cellZone&);
friend Ostream& operator<<(Ostream& os, const cellZone& zn);
};
......
......@@ -43,6 +43,23 @@ namespace Foam
const char* const Foam::faceZone::labelsName = "faceLabels";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::faceZone::setFlipMap(const bool flipValue)
{
// Match size for flipMap
if (flipMap_.size() == this->size())
{
flipMap_ = flipValue;
}
else
{
// Avoid copying old values on resize
flipMap_.clear();
flipMap_.setSize(this->size(), flipValue);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -128,8 +145,8 @@ void Foam::faceZone::calcCellLayers() const
forAll(mf, facei)
{
label ownCelli = own[mf[facei]];
label neiCelli =
const label ownCelli = own[mf[facei]];
const label neiCelli =
(
zoneMesh().mesh().isInternalFace(mf[facei])
? nei[mf[facei]]
......@@ -386,6 +403,30 @@ void Foam::faceZone::resetAddressing
}
void Foam::faceZone::resetAddressing
(
const labelUList& addr,
const bool flipValue
)
{
clearAddressing();
labelList::operator=(addr);
setFlipMap(flipValue);
}
void Foam::faceZone::resetAddressing
(
const Xfer<labelList>& addr,
const bool flipValue
)
{
clearAddressing();
labelList::operator=(addr);
setFlipMap(flipValue);
}
void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
{
clearAddressing();
......@@ -511,11 +552,11 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
}
void Foam::faceZone::movePoints(const pointField& p)
void Foam::faceZone::movePoints(const pointField& pts)
{
if (patchPtr_)
{
patchPtr_->movePoints(p);
patchPtr_->movePoints(pts);
}
}
......
......@@ -55,7 +55,7 @@ class mapPolyMesh;
// Forward declaration of friend functions and operators
class faceZone;
Ostream& operator<<(Ostream&, const faceZone&);
Ostream& operator<<(Ostream& os, const faceZone& zn);
/*---------------------------------------------------------------------------*\
......@@ -66,46 +66,43 @@ class faceZone
:
public zone
{
// Private data
//- The name associated with the zone-labels dictionary entry
static const word labelsName_;
// Private Member Functions
//- Set flip-map to constant value
void setFlipMap(const bool flipValue);
//- Disallow default bitwise copy construct
faceZone(const faceZone&);
faceZone(const faceZone&) = delete;
//- Disallow default bitwise assignment
void operator=(const faceZone&);
void operator=(const faceZone&) = delete;