From 52a389786347da4083047a5affb3b554befe23d5 Mon Sep 17 00:00:00 2001
From: andy <a.heather@opencfd.co.uk>
Date: Mon, 17 Aug 2009 17:36:37 +0100
Subject: [PATCH] restructured zones - now have common base (zone)

---
 src/OpenFOAM/Make/files                       |   3 +
 .../meshes/polyMesh/zones/ZoneID/ZoneID.H     |   1 +
 .../meshes/polyMesh/zones/cellZone/cellZone.C | 149 ++-----------
 .../meshes/polyMesh/zones/cellZone/cellZone.H |  57 +----
 .../meshes/polyMesh/zones/faceZone/faceZone.C | 139 ++----------
 .../meshes/polyMesh/zones/faceZone/faceZone.H |  56 ++---
 .../polyMesh/zones/pointZone/pointZone.C      | 157 ++-----------
 .../polyMesh/zones/pointZone/pointZone.H      |  58 +----
 .../meshes/polyMesh/zones/zone/zone.C         | 209 ++++++++++++++++++
 .../meshes/polyMesh/zones/zone/zone.H         | 207 +++++++++++++++++
 10 files changed, 513 insertions(+), 523 deletions(-)
 create mode 100644 src/OpenFOAM/meshes/polyMesh/zones/zone/zone.C
 create mode 100644 src/OpenFOAM/meshes/polyMesh/zones/zone/zone.H

diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index e608e4695bc..7bff2143ec5 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -345,6 +345,9 @@ $(globalMeshData)/globalIndex.C
 
 $(polyMesh)/syncTools/syncTools.C
 
+zone = $(polyMesh)/zones/zone
+$(zone)/zone.C
+
 cellZone = $(polyMesh)/zones/cellZone
 $(cellZone)/cellZone.C
 $(cellZone)/newCellZone.C
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H
index 5c98efd84a0..b6800dceb68 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H
+++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H
@@ -114,6 +114,7 @@ public:
                 return index_ > -1;
             }
 
+
         // Edit
 
             //- Update
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C
index ff8041fc602..a6c3293466b 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C
+++ b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C
@@ -45,59 +45,9 @@ namespace Foam
     addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
 }
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-const Foam::Map<Foam::label>& Foam::cellZone::cellLookupMap() const
-{
-    if (!cellLookupMapPtr_)
-    {
-        calcCellLookupMap();
-    }
-
-    return *cellLookupMapPtr_;
-}
-
-
-void Foam::cellZone::calcCellLookupMap() const
-{
-    if (debug)
-    {
-        Info<< "void cellZone::calcCellLookupMap() const : "
-            << "Calculating cell lookup map"
-            << endl;
-    }
-
-    if (cellLookupMapPtr_)
-    {
-        FatalErrorIn
-        (
-            "void cellZone::calcCellLookupMap() const"
-        )   << "cell lookup map already calculated"
-            << abort(FatalError);
-    }
-
-    const labelList& addr = *this;
-
-    cellLookupMapPtr_ = new Map<label>(2*addr.size());
-    Map<label>& clm = *cellLookupMapPtr_;
-
-    forAll (addr, cellI)
-    {
-        clm.insert(addr[cellI], cellI);
-    }
-
-    if (debug)
-    {
-        Info<< "void cellZone::calcCellLookupMap() const : "
-            << "Finished calculating cell lookup map"
-            << endl;
-    }
-}
-
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::cellZone::cellZone
 (
     const word& name,
@@ -106,11 +56,8 @@ Foam::cellZone::cellZone
     const cellZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    cellLookupMapPtr_(NULL)
+    zone(name, addr, index),
+    zoneMesh_(zm)
 {}
 
 
@@ -122,15 +69,11 @@ Foam::cellZone::cellZone
     const cellZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    cellLookupMapPtr_(NULL)
+    zone(name, addr, index),
+    zoneMesh_(zm)
 {}
 
 
-// Construct from dictionary
 Foam::cellZone::cellZone
 (
     const word& name,
@@ -139,16 +82,11 @@ Foam::cellZone::cellZone
     const cellZoneMesh& zm
 )
 :
-    labelList(dict.lookup("cellLabels")),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    cellLookupMapPtr_(NULL)
+    zone("cell", name, dict, index),
+    zoneMesh_(zm)
 {}
 
 
-// Construct given the original zone and resetting the
-//  cell list and zone mesh information
 Foam::cellZone::cellZone
 (
     const cellZone& cz,
@@ -157,11 +95,8 @@ Foam::cellZone::cellZone
     const cellZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(cz.name()),
-    index_(index),
-    zoneMesh_(zm),
-    cellLookupMapPtr_(NULL)
+    zone(cz, addr, index),
+    zoneMesh_(zm)
 {}
 
 Foam::cellZone::cellZone
@@ -172,38 +107,22 @@ Foam::cellZone::cellZone
     const cellZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(cz.name()),
-    index_(index),
-    zoneMesh_(zm),
-    cellLookupMapPtr_(NULL)
+    zone(cz, addr, index),
+    zoneMesh_(zm)
 {}
 
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
 Foam::cellZone::~cellZone()
-{
-    clearAddressing();
-}
+{}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
 {
-    const Map<label>& clm = cellLookupMap();
-
-    Map<label>::const_iterator clmIter = clm.find(globalCellID);
-
-    if (clmIter == clm.end())
-    {
-        return -1;
-    }
-    else
-    {
-        return clmIter();
-    }
+    return zone::localID(globalCellID);
 }
 
 
@@ -213,45 +132,9 @@ const Foam::cellZoneMesh& Foam::cellZone::zoneMesh() const
 }
 
 
-void Foam::cellZone::clearAddressing()
-{
-    deleteDemandDrivenData(cellLookupMapPtr_);
-}
-
-
 bool Foam::cellZone::checkDefinition(const bool report) const
 {
-    const labelList& addr = *this;
-
-    bool boundaryError = false;
-
-    forAll(addr, i)
-    {
-        if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().nCells())
-        {
-            boundaryError = true;
-
-            if (report)
-            {
-                SeriousErrorIn
-                (
-                    "bool cellZone::checkDefinition("
-                    "const bool report) const"
-                )   << "Zone " << name()
-                    << " contains invalid cell label " << addr[i] << nl
-                    << "Valid cell labels are 0.."
-                    << zoneMesh_.mesh().nCells()-1 << endl;
-            }
-        }
-    }
-    return boundaryError;
-}
-
-
-void Foam::cellZone::write(Ostream& os) const
-{
-    os  << nl << name()
-        << nl << static_cast<const labelList&>(*this);
+    return zone::checkDefinition(zoneMesh_.mesh().nCells(), report);
 }
 
 
@@ -284,10 +167,10 @@ void Foam::cellZone::operator=(const labelList& addr)
 
 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& p)
+Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& cz)
 {
-    p.write(os);
-    os.check("Ostream& operator<<(Ostream& f, const cellZone& p");
+    cz.write(os);
+    os.check("Ostream& operator<<(Ostream& os, const cellZone& cz");
     return os;
 }
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.H b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.H
index b133eee4361..0880e6eafb4 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.H
+++ b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.H
@@ -42,12 +42,8 @@ SourceFiles
 #ifndef cellZone_H
 #define cellZone_H
 
-#include "labelList.H"
-#include "typeInfo.H"
-#include "dictionary.H"
+#include "zone.H"
 #include "cellZoneMeshFwd.H"
-#include "pointFieldFwd.H"
-#include "Map.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -66,36 +62,22 @@ Ostream& operator<<(Ostream&, const cellZone&);
 
 class cellZone
 :
-    public labelList
+    public zone
 {
-    // Private data
 
-        //- Name of zone
-        word name_;
+protected:
 
-        //- Index of zone
-        label index_;
+    // Protected data
 
         //- Reference to zone list
         const cellZoneMesh& zoneMesh_;
 
-        // Demand-driven private data
-
-            //- Map of cell labels in zone for fast location lookup
-            mutable Map<label>* cellLookupMapPtr_;
-
 
     // Private Member Functions
 
         //- Disallow default bitwise copy construct
         cellZone(const cellZone&);
 
-        //- Return map of local cell indices
-        const Map<label>& cellLookupMap() const;
-
-        //- Build map of local cell indices
-        void calcCellLookupMap() const;
-
 
 public:
 
@@ -208,42 +190,22 @@ public:
 
 
     //- Destructor
-
-        virtual ~cellZone();
+    virtual ~cellZone();
 
 
     // Member Functions
 
-        //- Return name
-        const word& name() const
-        {
-            return name_;
-        }
-
-        //- Map storing the local cell index for every global cell
-        //  index.  Used to find out the index of cell in the zone from
-        //  the known global cell index.  If the cell is not in the
-        //  zone, returns -1
+        //- Helper function to re-direct to zone::localID(...)
         label whichCell(const label globalCellID) const;
 
-        //- Return the index of this zone in zone list
-        label index() const
-        {
-            return index_;
-        }
-
         //- Return zoneMesh reference
         const cellZoneMesh& zoneMesh() const;
 
         //- Clear addressing
-        void clearAddressing();
+        virtual void clearAddressing();
 
         //- Check zone definition. Return true if in error.
-        bool checkDefinition(const bool report = false) const;
-
-        //- Correct patch after moving points
-        virtual void movePoints(const pointField&)
-        {}
+        virtual bool checkDefinition(const bool report = false) const;
 
         //- Write
         virtual void write(Ostream&) const;
@@ -261,8 +223,9 @@ public:
         void operator=(const labelList&);
 
 
-    // Ostream Operator
+    // I-O
 
+        //- Ostream Operator
         friend Ostream& operator<<(Ostream&, const cellZone&);
 };
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C
index d4cc0a28436..93851f6d3b4 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C
+++ b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C
@@ -100,54 +100,6 @@ void Foam::faceZone::calcFaceZonePatch() const
 }
 
 
-const Foam::Map<Foam::label>& Foam::faceZone::faceLookupMap() const
-{
-    if (!faceLookupMapPtr_)
-    {
-        calcFaceLookupMap();
-    }
-
-    return *faceLookupMapPtr_;
-}
-
-
-void Foam::faceZone::calcFaceLookupMap() const
-{
-    if (debug)
-    {
-        Info<< "void faceZone::calcFaceLookupMap() const : "
-            << "Calculating face lookup map"
-            << endl;
-    }
-
-    if (faceLookupMapPtr_)
-    {
-        FatalErrorIn
-        (
-            "void faceZone::calcFaceLookupMap() const"
-        )   << "face lookup map already calculated"
-            << abort(FatalError);
-    }
-
-    const labelList& addr = *this;
-
-    faceLookupMapPtr_ = new Map<label>(2*addr.size());
-    Map<label>& flm = *faceLookupMapPtr_;
-
-    forAll (addr, faceI)
-    {
-        flm.insert(addr[faceI], faceI);
-    }
-
-    if (debug)
-    {
-        Info<< "void faceZone::calcFaceLookupMap() const : "
-            << "Finished calculating face lookup map"
-            << endl;
-    }
-}
-
-
 void Foam::faceZone::calcCellLayers() const
 {
     if (debug)
@@ -228,16 +180,13 @@ Foam::faceZone::faceZone
     const faceZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
+    zone(name, addr, index),
     flipMap_(fm),
-    index_(index),
     zoneMesh_(zm),
     patchPtr_(NULL),
     masterCellsPtr_(NULL),
     slaveCellsPtr_(NULL),
-    mePtr_(NULL),
-    faceLookupMapPtr_(NULL)
+    mePtr_(NULL)
 {
     checkAddressing();
 }
@@ -252,22 +201,18 @@ Foam::faceZone::faceZone
     const faceZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
+    zone(name, addr, index),
     flipMap_(fm),
-    index_(index),
     zoneMesh_(zm),
     patchPtr_(NULL),
     masterCellsPtr_(NULL),
     slaveCellsPtr_(NULL),
-    mePtr_(NULL),
-    faceLookupMapPtr_(NULL)
+    mePtr_(NULL)
 {
     checkAddressing();
 }
 
 
-// Construct from dictionary
 Foam::faceZone::faceZone
 (
     const word& name,
@@ -276,23 +221,18 @@ Foam::faceZone::faceZone
     const faceZoneMesh& zm
 )
 :
-    labelList(dict.lookup("faceLabels")),
-    name_(name),
+    zone("face", name, dict, index),
     flipMap_(dict.lookup("flipMap")),
-    index_(index),
     zoneMesh_(zm),
     patchPtr_(NULL),
     masterCellsPtr_(NULL),
     slaveCellsPtr_(NULL),
-    mePtr_(NULL),
-    faceLookupMapPtr_(NULL)
+    mePtr_(NULL)
 {
     checkAddressing();
 }
 
 
-// Construct given the original zone and resetting the
-// face list and zone mesh information
 Foam::faceZone::faceZone
 (
     const faceZone& fz,
@@ -302,16 +242,13 @@ Foam::faceZone::faceZone
     const faceZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(fz.name()),
+    zone(fz, addr, index),
     flipMap_(fm),
-    index_(index),
     zoneMesh_(zm),
     patchPtr_(NULL),
     masterCellsPtr_(NULL),
     slaveCellsPtr_(NULL),
-    mePtr_(NULL),
-    faceLookupMapPtr_(NULL)
+    mePtr_(NULL)
 {
     checkAddressing();
 }
@@ -326,16 +263,13 @@ Foam::faceZone::faceZone
     const faceZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(fz.name()),
+    zone(fz, addr, index),
     flipMap_(fm),
-    index_(index),
     zoneMesh_(zm),
     patchPtr_(NULL),
     masterCellsPtr_(NULL),
     slaveCellsPtr_(NULL),
-    mePtr_(NULL),
-    faceLookupMapPtr_(NULL)
+    mePtr_(NULL)
 {
     checkAddressing();
 }
@@ -351,26 +285,15 @@ Foam::faceZone::~faceZone()
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
+const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
 {
-    const Map<label>& flm = faceLookupMap();
-
-    Map<label>::const_iterator flmIter = flm.find(globalFaceID);
-
-    if (flmIter == flm.end())
-    {
-        return -1;
-    }
-    else
-    {
-        return flmIter();
-    }
+    return zoneMesh_;
 }
 
 
-const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
+Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
 {
-    return zoneMesh_;
+    return zone::localID(globalFaceID);
 }
 
 
@@ -450,13 +373,14 @@ const Foam::labelList& Foam::faceZone::meshEdges() const
 
 void Foam::faceZone::clearAddressing()
 {
+    zone::clearAddressing();
+
     deleteDemandDrivenData(patchPtr_);
 
     deleteDemandDrivenData(masterCellsPtr_);
     deleteDemandDrivenData(slaveCellsPtr_);
 
     deleteDemandDrivenData(mePtr_);
-    deleteDemandDrivenData(faceLookupMapPtr_);
 }
 
 
@@ -504,30 +428,7 @@ void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
 
 bool Foam::faceZone::checkDefinition(const bool report) const
 {
-    const labelList& addr = *this;
-
-    bool boundaryError = false;
-
-    forAll(addr, i)
-    {
-        if (addr[i] < 0 || addr[i] >= zoneMesh().mesh().faces().size())
-        {
-            boundaryError = true;
-
-            if (report)
-            {
-                SeriousErrorIn
-                (
-                    "bool faceZone::checkDefinition("
-                    "const bool report) const"
-                )   << "Zone " << name()
-                    << " contains invalid face label " << addr[i] << nl
-                    << "Valid face labels are 0.."
-                    << zoneMesh().mesh().faces().size()-1 << endl;
-            }
-        }
-    }
-    return boundaryError;
+    return zone::checkDefinition(zoneMesh().mesh().faces().size(), report);
 }
 
 
@@ -642,10 +543,10 @@ void Foam::faceZone::writeDict(Ostream& os) const
 
 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& p)
+Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& fz)
 {
-    p.write(os);
-    os.check("Ostream& operator<<(Ostream& f, const faceZone& p");
+    fz.write(os);
+    os.check("Ostream& operator<<(Ostream& os, const faceZone& fz");
     return os;
 }
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H
index 16c7e82b09c..7b1b46d2c4d 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H
+++ b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H
@@ -41,13 +41,10 @@ SourceFiles
 #ifndef faceZone_H
 #define faceZone_H
 
-#include "typeInfo.H"
-#include "dictionary.H"
-#include "labelList.H"
+#include "zone.H"
 #include "faceZoneMeshFwd.H"
 #include "boolList.H"
 #include "primitiveFacePatch.H"
-#include "Map.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -68,20 +65,17 @@ Ostream& operator<<(Ostream&, const faceZone&);
 
 class faceZone
 :
-    public labelList
+    public zone
 {
-    // Private data
 
-        //- Name of zone
-        word name_;
+protected:
+
+    // Protected data
 
         //- Flip map for all faces in the zone.  Set to true if the
         //  face needs to be flipped to achieve the correct orientation.
         boolList flipMap_;
 
-        //- Index of zone
-        label index_;
-
         //- Reference to zone list
         const faceZoneMesh& zoneMesh_;
 
@@ -100,9 +94,6 @@ class faceZone
             //- Global edge addressing
             mutable labelList* mePtr_;
 
-            //- Map of face labels in zone for fast location lookup
-            mutable Map<label>* faceLookupMapPtr_;
-
 
     // Private Member Functions
 
@@ -118,9 +109,6 @@ class faceZone
         //- Return map of local face indices
         const Map<label>& faceLookupMap() const;
 
-        //- Build map of local face indices
-        void calcFaceLookupMap() const;
-
         //- Calculate master and slave face layer
         void calcCellLayers() const;
 
@@ -244,38 +232,23 @@ public:
 
 
     //- Destructor
-
-        virtual ~faceZone();
+    virtual ~faceZone();
 
 
     // Member Functions
 
-        //- Return name
-        const word& name() const
-        {
-            return name_;
-        }
-
         //- Return face flip map
         const boolList& flipMap() const
         {
             return flipMap_;
         }
 
-        //- Map storing the local face index for every global face index.
-        //  Used to find out the index of face in the zone from the known global
-        //  face index.  If the face is not in the zone, returns -1
-        label whichFace(const label globalFaceID) const;
+        //- Helper function to re-direct to zone::localID(...)
+        label whichFace(const label globalCellID) const;
 
         //- Return reference to primitive patch
         const primitiveFacePatch& operator()() const;
 
-        //- Return the index of this zone in zone list
-        label index() const
-        {
-            return index_;
-        }
-
         //- Return zoneMesh reference
         const faceZoneMesh& zoneMesh() const;
 
@@ -294,23 +267,23 @@ public:
 
 
         //- Clear addressing
-        void clearAddressing();
+        virtual void clearAddressing();
 
         //- Reset addressing and flip map (clearing demand-driven data)
-        void resetAddressing(const labelList&, const boolList&);
+        virtual void resetAddressing(const labelList&, const boolList&);
 
         //- Check zone definition. Return true if in error.
-        bool checkDefinition(const bool report = false) const;
+        virtual bool checkDefinition(const bool report = false) const;
 
         //- Check whether all procs have faces synchronised. Return
         //  true if in error.
-        bool checkParallelSync(const bool report = false) const;
+        virtual bool checkParallelSync(const bool report = false) const;
 
         //- Correct patch after moving points
         virtual void movePoints(const pointField&);
 
         //- Update for changes in topology
-        void updateMesh(const mapPolyMesh& mpm);
+        virtual void updateMesh(const mapPolyMesh& mpm);
 
         //- Write
         virtual void write(Ostream&) const;
@@ -319,8 +292,9 @@ public:
         virtual void writeDict(Ostream&) const;
 
 
-    // Ostream Operator
+    // I-O
 
+        //- Ostream Operator
         friend Ostream& operator<<(Ostream&, const faceZone&);
 };
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.C b/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.C
index d1c450691f1..78ca4fbc69b 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.C
+++ b/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.C
@@ -43,59 +43,9 @@ namespace Foam
     addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
 }
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-const Foam::Map<Foam::label>& Foam::pointZone::pointLookupMap() const
-{
-    if (!pointLookupMapPtr_)
-    {
-        calcPointLookupMap();
-    }
-
-    return *pointLookupMapPtr_;
-}
-
-
-void Foam::pointZone::calcPointLookupMap() const
-{
-    if (debug)
-    {
-        Info<< "void pointZone::calcPointLookupMap() const : "
-            << "Calculating point lookup map"
-            << endl;
-    }
-
-    if (pointLookupMapPtr_)
-    {
-        FatalErrorIn
-        (
-            "void pointZone::calcPointLookupMap() const"
-        )   << "point lookup map already calculated"
-            << abort(FatalError);
-    }
-
-    const labelList& addr = *this;
-
-    pointLookupMapPtr_ = new Map<label>(2*addr.size());
-    Map<label>& plm = *pointLookupMapPtr_;
-
-    forAll (addr, pointI)
-    {
-        plm.insert(addr[pointI], pointI);
-    }
-
-    if (debug)
-    {
-        Info<< "void pointZone::calcPointLookupMap() const : "
-            << "Finished calculating point lookup map"
-            << endl;
-    }
-}
-
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::pointZone::pointZone
 (
     const word& name,
@@ -104,11 +54,8 @@ Foam::pointZone::pointZone
     const pointZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    pointLookupMapPtr_(NULL)
+    zone(name, addr, index),
+    zoneMesh_(zm)
 {}
 
 
@@ -120,15 +67,11 @@ Foam::pointZone::pointZone
     const pointZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    pointLookupMapPtr_(NULL)
+    zone(name, addr, index),
+    zoneMesh_(zm)
 {}
 
 
-// Construct from dictionary
 Foam::pointZone::pointZone
 (
     const word& name,
@@ -137,16 +80,11 @@ Foam::pointZone::pointZone
     const pointZoneMesh& zm
 )
 :
-    labelList(dict.lookup("pointLabels")),
-    name_(name),
-    index_(index),
-    zoneMesh_(zm),
-    pointLookupMapPtr_(NULL)
+    zone("point", name, dict, index),
+    zoneMesh_(zm)
 {}
 
 
-// Construct given the original zone and resetting the
-// point list and zone mesh information
 Foam::pointZone::pointZone
 (
     const pointZone& pz,
@@ -155,11 +93,8 @@ Foam::pointZone::pointZone
     const pointZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(pz.name()),
-    index_(index),
-    zoneMesh_(zm),
-    pointLookupMapPtr_(NULL)
+    zone(pz, addr, index),
+    zoneMesh_(zm)
 {}
 
 
@@ -171,92 +106,40 @@ Foam::pointZone::pointZone
     const pointZoneMesh& zm
 )
 :
-    labelList(addr),
-    name_(pz.name()),
-    index_(index),
-    zoneMesh_(zm),
-    pointLookupMapPtr_(NULL)
+    zone(pz, addr, index),
+    zoneMesh_(zm)
 {}
 
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
 Foam::pointZone::~pointZone()
-{
-    clearAddressing();
-}
+{}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
-{
-    const Map<label>& plm = pointLookupMap();
-
-    Map<label>::const_iterator plmIter = plm.find(globalPointID);
-
-    if (plmIter == plm.end())
-    {
-        return -1;
-    }
-    else
-    {
-        return plmIter();
-    }
-}
-
-
 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
 {
     return zoneMesh_;
 }
 
 
-void Foam::pointZone::clearAddressing()
+Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
 {
-    deleteDemandDrivenData(pointLookupMapPtr_);
+    return zone::localID(globalPointID);
 }
 
 
 bool Foam::pointZone::checkDefinition(const bool report) const
 {
-    const labelList& addr = *this;
-
-    bool boundaryError = false;
-
-    forAll(addr, i)
-    {
-        if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
-        {
-            boundaryError = true;
-
-            if (report)
-            {
-                SeriousErrorIn
-                (
-                    "bool pointZone::checkDefinition("
-                    "const bool report) const"
-                )   << "Zone " << name()
-                    << " contains invalid point label " << addr[i] << nl
-                    << "Valid point labels are 0.."
-                    << zoneMesh_.mesh().points().size()-1 << endl;
-            }
-        }
-    }
-    return boundaryError;
-}
-
-
-void Foam::pointZone::write(Ostream& os) const
-{
-    os  << nl << name()
-        << nl << static_cast<const labelList&>(*this);
+    return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
 }
 
 
 void Foam::pointZone::writeDict(Ostream& os) const
 {
-    os  << nl << name() << nl << token::BEGIN_BLOCK << nl
+    os  << nl << name_ << nl << token::BEGIN_BLOCK << nl
         << "    type " << type() << token::END_STATEMENT << nl;
 
     writeEntry("pointLabels", os);
@@ -267,10 +150,10 @@ void Foam::pointZone::writeDict(Ostream& os) const
 
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
-void Foam::pointZone::operator=(const pointZone& cz)
+void Foam::pointZone::operator=(const pointZone& pz)
 {
     clearAddressing();
-    labelList::operator=(cz);
+    labelList::operator=(pz);
 }
 
 
@@ -283,10 +166,10 @@ void Foam::pointZone::operator=(const labelList& addr)
 
 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
+Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& pz)
 {
-    p.write(os);
-    os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
+    pz.write(os);
+    os.check("Ostream& operator<<(Ostream& os, const pointZone& pz");
     return os;
 }
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.H b/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.H
index 66719530f52..3d50354530f 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.H
+++ b/src/OpenFOAM/meshes/polyMesh/zones/pointZone/pointZone.H
@@ -43,12 +43,8 @@ SourceFiles
 #ifndef pointZone_H
 #define pointZone_H
 
-#include "labelList.H"
-#include "typeInfo.H"
-#include "dictionary.H"
+#include "zone.H"
 #include "pointZoneMeshFwd.H"
-#include "Map.H"
-#include "pointField.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -67,37 +63,22 @@ Ostream& operator<<(Ostream&, const pointZone&);
 
 class pointZone
 :
-    public labelList
+    public zone
 {
-    // Private data
 
-        //- Name of zone
-        word name_;
+protected:
 
-        //- Index of zone
-        label index_;
+    // Private data
 
         //- Reference to zone list
         const pointZoneMesh& zoneMesh_;
 
 
-        // Demand-driven private data
-
-            //- Map of point labels in zone for fast location lookup
-            mutable Map<label>* pointLookupMapPtr_;
-
-
     // Private Member Functions
 
         //- Disallow default bitwise copy construct
         pointZone(const pointZone&);
 
-        //- Return map of local point indices
-        const Map<label>& pointLookupMap() const;
-
-        //- Build map of local point indices
-        void calcPointLookupMap() const;
-
 
 public:
 
@@ -210,38 +191,22 @@ public:
 
 
     //- Destructor
-
-        virtual ~pointZone();
+    virtual ~pointZone();
 
 
     // Member Functions
 
-        //- Return name
-        const word& name() const
-        {
-            return name_;
-        }
-
-        //- Map storing the local point index for every global point
-        //  index.  Used to find out the index of point in the zone from
-        //  the known global point index.  If the point is not in the
-        //  zone, returns -1
-        label whichPoint(const label globalPointID) const;
-
-        //- Return the index of this zone in zone list
-        label index() const
-        {
-            return index_;
-        }
-
         //- Return zoneMesh reference
         const pointZoneMesh& zoneMesh() const;
 
+        //- Helper function to re-direct to zone::localID(...)
+        label whichPoint(const label globalPointID) const;
+
         //- Clear addressing
-        void clearAddressing();
+        virtual void clearAddressing();
 
         //- Check zone definition. Return true if in error.
-        bool checkDefinition(const bool report = false) const;
+        virtual bool checkDefinition(const bool report = false) const;
 
         //- Correct patch after moving points
         virtual void movePoints(const pointField&)
@@ -263,8 +228,9 @@ public:
         void operator=(const labelList&);
 
 
-    // Ostream Operator
+    // I-O
 
+        //- Ostream Operator
         friend Ostream& operator<<(Ostream&, const pointZone&);
 };
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.C b/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.C
new file mode 100644
index 00000000000..2d5592bdadd
--- /dev/null
+++ b/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.C
@@ -0,0 +1,209 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2009-2009 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "zone.H"
+#include "IOstream.H"
+#include "demandDrivenData.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    defineTypeNameAndDebug(zone, 0);
+}
+
+// * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
+
+const Foam::Map<Foam::label>& Foam::zone::lookupMap() const
+{
+    if (!lookupMapPtr_)
+    {
+        calcLookupMap();
+    }
+
+    return *lookupMapPtr_;
+}
+
+
+void Foam::zone::calcLookupMap() const
+{
+    if (debug)
+    {
+        Info<< "void zone::calcLookupMap() const: "
+            << "Calculating lookup map"
+            << endl;
+    }
+
+    if (lookupMapPtr_)
+    {
+        FatalErrorIn("void zone::calcLookupMap() const")
+            << "Lookup map already calculated" << nl
+            << abort(FatalError);
+    }
+
+    const labelList& addr = *this;
+
+    lookupMapPtr_ = new Map<label>(2*addr.size());
+    Map<label>& lm = *lookupMapPtr_;
+
+    forAll(addr, i)
+    {
+        lm.insert(addr[i], i);
+    }
+
+    if (debug)
+    {
+        Info<< "void zone::calcLookupMap() const: "
+            << "Finished calculating lookup map"
+            << endl;
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::zone::zone
+(
+    const word& name,
+    const labelList& addr,
+    const label index
+)
+:
+    labelList(addr),
+    name_(name),
+    index_(index),
+    lookupMapPtr_(NULL)
+{}
+
+
+Foam::zone::zone
+(
+    const word& name,
+    const Xfer<labelList>& addr,
+    const label index
+)
+:
+    labelList(addr),
+    name_(name),
+    index_(index),
+    lookupMapPtr_(NULL)
+{}
+
+
+Foam::zone::zone
+(
+    const word& zoneType,
+    const word& name,
+    const dictionary& dict,
+    const label index
+)
+:
+    labelList(dict.lookup(zoneType + "Labels")),
+    name_(name),
+    index_(index),
+    lookupMapPtr_(NULL)
+{}
+
+
+Foam::zone::zone
+(
+    const zone& z,
+    const labelList& addr,
+    const label index
+)
+:
+    labelList(addr),
+    name_(z.name()),
+    index_(index),
+    lookupMapPtr_(NULL)
+{}
+
+
+Foam::zone::zone
+(
+    const zone& z,
+    const Xfer<labelList>& addr,
+    const label index
+)
+:
+    labelList(addr),
+    name_(z.name()),
+    index_(index),
+    lookupMapPtr_(NULL)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::zone::~zone()
+{
+    clearAddressing();
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+Foam::label Foam::zone::localID(const label globalCellID) const
+{
+    const Map<label>& lm = lookupMap();
+
+    Map<label>::const_iterator lmIter = lm.find(globalCellID);
+
+    if (lmIter == lm.end())
+    {
+        return -1;
+    }
+    else
+    {
+        return lmIter();
+    }
+}
+
+
+void Foam::zone::clearAddressing()
+{
+    deleteDemandDrivenData(lookupMapPtr_);
+}
+
+
+void Foam::zone::write(Ostream& os) const
+{
+    os  << nl << name_
+        << nl << static_cast<const labelList&>(*this);
+}
+
+
+// * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
+
+Foam::Ostream& Foam::operator<<(Ostream& os, const zone& z)
+{
+    z.write(os);
+    os.check("Ostream& operator<<(Ostream& f, const zone& z");
+    return os;
+}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.H b/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.H
new file mode 100644
index 00000000000..fb5d2453e65
--- /dev/null
+++ b/src/OpenFOAM/meshes/polyMesh/zones/zone/zone.H
@@ -0,0 +1,207 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::cellZone
+
+Description
+    Base class for zones
+
+SourceFiles
+    zone.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef zone_H
+#define zone_H
+
+#include "labelList.H"
+#include "typeInfo.H"
+#include "dictionary.H"
+#include "Map.H"
+#include "pointFieldFwd.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// Forward declaration of friend functions and operators
+
+class zone;
+Ostream& operator<<(Ostream&, const zone&);
+
+/*---------------------------------------------------------------------------*\
+                           Class zone Declaration
+\*---------------------------------------------------------------------------*/
+
+class zone
+:
+    public labelList
+{
+
+protected:
+
+    // Protected data
+
+        //- Name of zone
+        word name_;
+
+        //- Index of zone
+        label index_;
+
+
+        // Demand-driven private data
+
+            //- Map of labels in zone for fast location lookup
+            mutable Map<label>* lookupMapPtr_;
+
+
+    // Protected Member Functions
+
+        //- Return a reference to the look-up map
+        const Map<label>& lookupMap() const;
+
+        //- Construct the look-up map
+        void calcLookupMap() const;
+
+        //- Disallow default bitwise copy construct
+        zone(const zone&);
+
+
+public:
+
+    //- Runtime type information
+    TypeName("zone");
+
+
+    // Constructors
+
+        //- Construct from components
+        zone
+        (
+            const word& name,
+            const labelList& addr,
+            const label index
+        );
+
+        //- Construct from components, transferring contents
+        zone
+        (
+            const word& name,
+            const Xfer<labelList>& addr,
+            const label index
+        );
+
+        //- Construct from dictionary
+        zone
+        (
+            const word& zoneType,
+            const word& name,
+            const dictionary&,
+            const label index
+        );
+
+        //- Construct given the original zone and resetting the
+        //  cell list and zone mesh information
+        zone
+        (
+            const zone&,
+            const labelList& addr,
+            const label index
+        );
+
+        //- Construct given the original zone, resetting the
+        //  cell list and zone mesh information
+        zone
+        (
+            const zone&,
+            const Xfer<labelList>& addr,
+            const label index
+        );
+
+
+    //- Destructor
+    virtual ~zone();
+
+
+    // Member Functions
+
+        //- Return name
+        const word& name() const
+        {
+            return name_;
+        }
+
+        //- Map storing the local index for every global index.  Used to find
+        //  the index of the item in the zone from the known global index. If
+        //  the item is not in the zone, returns -1
+        label localID(const label globalID) const;
+
+        //- Return the index of this zone in zone list
+        label index() const
+        {
+            return index_;
+        }
+
+        //- Clear addressing
+        virtual void clearAddressing();
+
+        //- Check zone definition. Return true if in error.
+        virtual bool checkDefinition(const bool report = false) const = 0;
+
+        //- Check zone definition with max size given. Return true if in error.
+        virtual bool checkDefinition
+        (
+            const label maxSize,
+            const bool report = false
+        ) const;
+
+        //- Correct patch after moving points
+        virtual void movePoints(const pointField&)
+        {}
+
+        //- Write
+        virtual void write(Ostream&) const;
+
+        //- Write dictionary
+        virtual void writeDict(Ostream&) const = 0;
+
+
+    // I-O
+
+        //- Ostream Operator
+        friend Ostream& operator<<(Ostream&, const zone&);
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab