diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..99320914e0074c1110479d5afad17c0dbaa105a9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.dep
+**/lnInclude/*
+**/Make/**/*
diff --git a/executables/cartesian2DMesh/cartesian2DMesh.C b/executables/cartesian2DMesh/cartesian2DMesh.C
index 1a03a036769b465df621c75f6cdab46a68e535ef..91d954a2f2a2877ddfa9715eb152cace9a1f38ca 100644
--- a/executables/cartesian2DMesh/cartesian2DMesh.C
+++ b/executables/cartesian2DMesh/cartesian2DMesh.C
@@ -30,7 +30,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "cartesian2DMeshGenerator.H"
 
 using namespace Foam;
diff --git a/executables/pMesh/pMesh.C b/executables/pMesh/pMesh.C
index 18c63b1594508ea5f2e7d7327bbc2332fc1f3430..644106e970bbd7b3a0b2406ff17015a4689fddca 100644
--- a/executables/pMesh/pMesh.C
+++ b/executables/pMesh/pMesh.C
@@ -30,7 +30,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "voronoiMeshGenerator.H"
 
 using namespace Foam;
diff --git a/executables/tetMesh/tetMesh.C b/executables/tetMesh/tetMesh.C
index 307f590c10a39dcab4b72d7f336f297e6715ee80..3ebb6628bfa73e1853762300b10b4a4a20f6f4eb 100644
--- a/executables/tetMesh/tetMesh.C
+++ b/executables/tetMesh/tetMesh.C
@@ -30,7 +30,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "tetMeshGenerator.H"
 
 using namespace Foam;
diff --git a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/boxScaling.C b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/boxScaling.C
index 020e69b5b26ccebdecbda8d5a5d2164b9bea7782..37f33240d0967108cb6fe68328aca4f0b3ccc9da 100644
--- a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/boxScaling.C
+++ b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/boxScaling.C
@@ -176,7 +176,7 @@ void boxScaling::boundingPlanes(PtrList<plane>&pl) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary boxScaling::dict(bool ignoreType) const
+dictionary boxScaling::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModification.C b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModification.C
index 2c34d94674412dda36287132b4c19b6a26bc709c..b383cab7e62f830652851fb93399cc1190857cde 100644
--- a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModification.C
+++ b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModification.C
@@ -46,7 +46,7 @@ coordinateModification::coordinateModification()
 coordinateModification::coordinateModification
 (
     const word& name,
-    const dictionary& dict
+    const dictionary& /*dict*/
 )
 :
     name_(name)
diff --git a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModifier.H b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModifier.H
index 6e5a156d04806b8eadf7b911761247c802cad99d..e1c7c60b7843599f89754664990d9b97a2258f26 100644
--- a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModifier.H
+++ b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/coordinateModifier.H
@@ -39,7 +39,6 @@ SourceFiles
 #include "word.H"
 #include "point.H"
 #include "coordinateModificationList.H"
-#include "Time.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/planeScaling.C b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/planeScaling.C
index b782370963d6c01ad5a388bc3133ff4cc29457ba..3cf8aea3605a9014dd022daf26c8815cb84e53c8 100644
--- a/meshLibrary/utilities/anisotropicMeshing/coordinateModification/planeScaling.C
+++ b/meshLibrary/utilities/anisotropicMeshing/coordinateModification/planeScaling.C
@@ -153,7 +153,7 @@ void planeScaling::boundingPlanes(PtrList<plane>& pl) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary planeScaling::dict(bool ignoreType) const
+dictionary planeScaling::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/boundaryLayers/boundaryLayers/boundaryLayersCreateVertices.C b/meshLibrary/utilities/boundaryLayers/boundaryLayers/boundaryLayersCreateVertices.C
index bc8e9021ef39c50620353394d76bd1df60191c89..3aff65c60cbe72019a6e20fc0aed8364fd36b29b 100644
--- a/meshLibrary/utilities/boundaryLayers/boundaryLayers/boundaryLayersCreateVertices.C
+++ b/meshLibrary/utilities/boundaryLayers/boundaryLayers/boundaryLayersCreateVertices.C
@@ -686,7 +686,7 @@ void boundaryLayers::createNewPartitionVerticesParallel
 (
     const labelLongList& procPoints,
     const List<direction>& pVertices,
-    const boolList& treatPatches
+    const boolList& /*treatPatches*/
 )
 {
     if( !Pstream::parRun() )
diff --git a/meshLibrary/utilities/checkMeshDict/checkMeshDict.C b/meshLibrary/utilities/checkMeshDict/checkMeshDict.C
index 8d154e10bfcfe3eaac0e31c1b07257ed2d00c97c..3c490fde9b8e6c7fe7975379fb5a7bf56762ec46 100644
--- a/meshLibrary/utilities/checkMeshDict/checkMeshDict.C
+++ b/meshLibrary/utilities/checkMeshDict/checkMeshDict.C
@@ -860,7 +860,7 @@ void checkMeshDict::updatePatchCellSize
 
 void checkMeshDict::updateSubsetCellSize
 (
-    const std::map<word, wordList>& patchesFromPatch
+    const std::map<word, wordList>& /*patchesFromPatch*/
 )
 {
 
@@ -1028,7 +1028,7 @@ void checkMeshDict::updateRemoveCellsIntersectingPatches
 
 void checkMeshDict::updateObjectRefinements
 (
-    const std::map<word, wordList>& patchesFromPatch
+    const std::map<word, wordList>& /*patchesFromPatch*/
 )
 {
 
diff --git a/meshLibrary/utilities/containers/FRWGraph/FRWGraph.C b/meshLibrary/utilities/containers/FRWGraph/FRWGraph.C
index 190d1f4c4b0e0793673e6901c6c3c3a810f02521..a8d351fde791b469560d3917c0fddf24aa3837f3 100644
--- a/meshLibrary/utilities/containers/FRWGraph/FRWGraph.C
+++ b/meshLibrary/utilities/containers/FRWGraph/FRWGraph.C
@@ -34,15 +34,34 @@ Foam::Ostream& Foam::operator<<
     const Foam::FRWGraph<T, width>& DL
 )
 {
-    os << DL.size() << "(" << endl;
-    for(register label i=0;i<DL.size();++i)
+    os << DL.size() << "(" << nl;
+
+    for(label i=0;i<DL.size();++i)
     {
         os << width << "(";
+
         for(label j=0;j<width;++j)
-            os << DL(i, j) << " " << endl;
-        os << ")" << endl;
+        {
+            if( j )
+            {
+                os << " ";
+            }
+
+            os << DL(i, j);
+        }
+
+        os << ")" << nl;
     }
+
     os << ")";
+
+    // Check state of IOstream
+    os.check
+    (
+        "template<class T, Foam::label width>Foam::Ostream& Foam::operator<<"
+        "(Foam::Ostream& os, const Foam::FRWGraph<T, width>&)"
+    );
+
     return os;
 }
 
diff --git a/meshLibrary/utilities/containers/FRWGraph/FRWGraphI.H b/meshLibrary/utilities/containers/FRWGraph/FRWGraphI.H
index 2a1a6ad583ffa7c9be5ccb2647af15b3e616e3f8..497735c5b7617bb2129ccd00f736a8284072f00a 100644
--- a/meshLibrary/utilities/containers/FRWGraph/FRWGraphI.H
+++ b/meshLibrary/utilities/containers/FRWGraph/FRWGraphI.H
@@ -36,7 +36,7 @@ void Foam::FRWGraph<T, width>::checkIndex(const label i, const label j) const
             << " is not in range " << 0
             << " and " << nRows_ << abort(FatalError);
     }
-    
+
     if( (j < 0) || (j >= width) )
         FatalErrorIn
         (
@@ -105,7 +105,7 @@ inline Foam::label Foam::FRWGraph<T,width>::size() const
 }
 
 template<class T, Foam::label width>
-inline Foam::label Foam::FRWGraph<T,width>::sizeOfRow(const label rowI) const
+inline Foam::label Foam::FRWGraph<T,width>::sizeOfRow(const label) const
 {
     return width;
 }
@@ -155,10 +155,11 @@ inline bool Foam::FRWGraph<T,width>::contains
 ) const
 {
     const label start = rowI * width;
-    for(register label i=0;i<width;++i)
+
+    for(label i=0;i<width;++i)
         if( data_[start+i] == e )
             return true;
-    
+
     return false;
 }
 
@@ -170,10 +171,11 @@ inline Foam::label Foam::FRWGraph<T,width>::containsAtPosition
 ) const
 {
     const label start = rowI * width;
-    for(register label i=0;i<width;++i)
+
+    for(label i=0;i<width;++i)
         if( data_[start+i] == e )
             return i;
-    
+
     return -1;
 }
 
@@ -188,7 +190,7 @@ inline const T& Foam::FRWGraph<T,width>::operator()
     #ifdef FULLDEBUG
     checkIndex(i, j);
     #endif
-        
+
     return data_[i * width + j];
 }
 
@@ -201,7 +203,7 @@ inline T& Foam::FRWGraph<T,width>::operator()
     #ifdef FULLDEBUG
     checkIndex(i, j);
     #endif
-        
+
     return data_[i * width + j];
 }
 
diff --git a/meshLibrary/utilities/containers/LongList/LongList.C b/meshLibrary/utilities/containers/LongList/LongList.C
index f56faa655e063c06ecde0849178c80a9b1275ac7..2881d3840c9347fa0c52244f8ae202c07585aea6 100644
--- a/meshLibrary/utilities/containers/LongList/LongList.C
+++ b/meshLibrary/utilities/containers/LongList/LongList.C
@@ -202,7 +202,7 @@ Foam::Istream& Foam::operator>>
 
             if( listDelimiter == token::BEGIN_LIST )
             {
-                for(register label i=0;i<size;++i)
+                for(label i=0;i<size;++i)
                 {
                     is >> DL[i];
 
@@ -223,7 +223,7 @@ Foam::Istream& Foam::operator>>
                     "reading the single entry"
                 );
 
-                for(register label i=0;i<size;++i)
+                for(label i=0;i<size;++i)
                 {
                     DL[i] = element;
                 }
@@ -306,7 +306,7 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
 
             if( listDelimiter == token::BEGIN_LIST )
             {
-                for(register label i=0;i<size;++i)
+                for(label i=0;i<size;++i)
                 {
                     is >> this->operator[](origSize);
                     ++origSize;
@@ -328,7 +328,7 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
                     "reading the single entry"
                 );
 
-                for(register label i=0;i<size;++i)
+                for(label i=0;i<size;++i)
                 {
                     this->operator[](origSize) = element;
                     ++origSize;
@@ -346,31 +346,6 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
             forAll(buf, i)
                 this->operator[](origSize++) = buf[i];
 
-            /*const label blockSize = 1<<shift_;
-
-            Info << "nextFree_ " << nextFree_ << endl;
-
-            //- append elements by reading binary block
-            while( origSize < nextFree_ )
-            {
-                const label currBlock = origSize >> shift_;
-                const label currPos = origSize & mask_;
-
-                Info << "Orig size " << origSize
-                    << nl << "currBlock " << currBlock
-                    << nl << "currPos " << currPos << endl;
-
-                T* data = &dataPtr_[currBlock][currPos];
-
-                label bs = Foam::min(nextFree_-origSize, blockSize);
-                bs = Foam::min(blockSize - currPos, bs);
-
-                Info << "bs " << bs << endl;
-
-                is.read(reinterpret_cast<char*>(data), bs * sizeof(T));
-                origSize += bs;
-            } */
-
             is.fatalCheck
             (
                 "appendFromStream(Istream& is)"
diff --git a/meshLibrary/utilities/containers/LongList/LongList.H b/meshLibrary/utilities/containers/LongList/LongList.H
index e28f7998cb34ac11dc61fed18671273c3efbf57e..5b39a8044c1f5c4824b8237be0e98484668adabe 100644
--- a/meshLibrary/utilities/containers/LongList/LongList.H
+++ b/meshLibrary/utilities/containers/LongList/LongList.H
@@ -41,7 +41,6 @@ SourceFiles
 #define LongList_H
 
 #include "label.H"
-#include "longLong.H"
 #include "bool.H"
 #include "IOstreams.H"
 #include "error.H"
diff --git a/meshLibrary/utilities/containers/LongList/LongListI.H b/meshLibrary/utilities/containers/LongList/LongListI.H
index d590a3006ac92dcd5ac6ae7ee9f0422b58d8a0c1..122ad3c34d04115ddb629fcb7ec7cbb3920f30bb 100644
--- a/meshLibrary/utilities/containers/LongList/LongListI.H
+++ b/meshLibrary/utilities/containers/LongList/LongListI.H
@@ -78,7 +78,7 @@ inline void Foam::LongList<T, Offset>::allocateSize(const label s)
 
     if( numblock1 < numBlocks_ )
     {
-        for(register label i=numblock1;i<numBlocks_;++i)
+        for(label i=numblock1;i<numBlocks_;++i)
             delete [] dataPtr_[i];
     }
     else if( numblock1 > numBlocks_ )
@@ -91,7 +91,8 @@ inline void Foam::LongList<T, Offset>::allocateSize(const label s)
             } while( numblock1 > numAllocatedBlocks_ );
 
             T** dataptr1 = new T*[numAllocatedBlocks_];
-            for(register label i=0;i<numBlocks_;++i)
+
+            for(label i=0;i<numBlocks_;++i)
                 dataptr1[i] = dataPtr_[i];
 
             if( dataPtr_ )
@@ -99,7 +100,7 @@ inline void Foam::LongList<T, Offset>::allocateSize(const label s)
             dataPtr_ = dataptr1;
         }
 
-        for(register label i=numBlocks_;i<numblock1;++i)
+        for(label i=numBlocks_;i<numblock1;++i)
             dataPtr_[i] = new T[blockSize];
     }
 
@@ -110,7 +111,7 @@ inline void Foam::LongList<T, Offset>::allocateSize(const label s)
 template<class T, Foam::label Offset>
 void Foam::LongList<T, Offset>::clearOut()
 {
-    for(register label i=0;i<numBlocks_;++i)
+    for(label i=0;i<numBlocks_;++i)
         delete [] dataPtr_[i];
 
     if( dataPtr_ )
@@ -281,7 +282,7 @@ inline void Foam::LongList<T, Offset>::appendIfNotIn(const T& e)
 template<class T, Foam::label Offset>
 inline bool Foam::LongList<T, Offset>::contains(const T& e) const
 {
-    for(register label i=0;i<nextFree_;++i)
+    for(label i=0;i<nextFree_;++i)
         if( (*this)[i] == e )
             return true;
 
@@ -294,7 +295,7 @@ inline Foam::label Foam::LongList<T, Offset>::containsAtPosition
     const T& e
 ) const
 {
-    for(register label i=0;i<nextFree_;++i)
+    for(label i=0;i<nextFree_;++i)
         if( (*this)[i] == e )
             return i;
 
@@ -376,7 +377,7 @@ inline T& Foam::LongList<T, Offset>::newElmt(const label i)
 template<class T, Foam::label Offset>
 inline void Foam::LongList<T, Offset>::operator=(const T& t)
 {
-    for(register label i=0;i<nextFree_;++i)
+    for(label i=0;i<nextFree_;++i)
         operator[](i) = t;
 }
 
@@ -384,7 +385,8 @@ template<class T, Foam::label Offset>
 inline void Foam::LongList<T, Offset>::operator=(const LongList<T, Offset>& l)
 {
     setSize(l.size());
-    for(register label i=0;i<l.nextFree_;++i)
+
+    for(label i=0;i<l.nextFree_;++i)
         operator[](i) = l[i];
 }
 
diff --git a/meshLibrary/utilities/containers/VRWGraph/VRWGraph.C b/meshLibrary/utilities/containers/VRWGraph/VRWGraph.C
index b3b46a812252c61238bf1f6872a5b09b0d90aba1..14753cd5546e7cf11fcf19b7a5a273e4e3063a2e 100644
--- a/meshLibrary/utilities/containers/VRWGraph/VRWGraph.C
+++ b/meshLibrary/utilities/containers/VRWGraph/VRWGraph.C
@@ -35,22 +35,29 @@ Foam::Ostream& Foam::operator<<
     const Foam::VRWGraph& DL
 )
 {
-    os << DL.size() << nl << token::BEGIN_LIST;
-    
-    for(register label i=0;i<DL.size();++i)
+    os << DL.size() << nl << token::BEGIN_LIST << nl;
+
+    for(label i=0;i<DL.size();++i)
     {
-        os << nl << DL.sizeOfRow(i) << token::BEGIN_LIST;
+        os << DL.sizeOfRow(i) << token::BEGIN_LIST;
         for(label j=0;j<DL.sizeOfRow(i);++j)
         {
-            if( j > 0 ) os << token::SPACE;
-            
+            if( j ) os << token::SPACE;
+
             os << DL(i, j);
         }
-        
-        os << token::END_LIST;
+
+        os << token::END_LIST << nl;
     }
-    
-    os << nl << token::END_LIST;
+
+    os << token::END_LIST;
+
+    // Check state of IOstream
+    os.check
+    (
+        "Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::VRWGraph&)"
+    );
+
     return os;
 }
 
@@ -90,14 +97,14 @@ void Foam::VRWGraph::optimizeMemoryUsage()
         {
             newPosForNode[elI] = -1;
         }
-        
+
     //- create new data
     for(label elI=0;elI<nElements;++elI)
         if( (newPosForNode[elI] != -1) && (newPosForNode[elI] < elI) )
             data_[newPosForNode[elI]] = data_[elI];
-        
+
     data_.setSize(pos);
-    
+
     //- renumber rows
     nElements = rows_.size();
     for(label rowI=0;rowI<nElements;++rowI)
diff --git a/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H b/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H
index f12d02320fc6b65f7121f274352553a079f890d7..88f1e5d93979e45a9fb40e6fbc70386f7f1aef4a 100644
--- a/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H
+++ b/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H
@@ -518,7 +518,7 @@ inline bool Foam::VRWGraph::contains
         return false;
     const label size = rows_[rowI].size();
 
-    for(register label i=0;i<size;++i)
+    for(label i=0;i<size;++i)
         if( data_[start+i] == e )
             return true;
 
@@ -536,7 +536,8 @@ inline Foam::label Foam::VRWGraph::containsAtPosition
         return -1;
 
     const label size = rows_[rowI].size();
-    for(register label i=0;i<size;++i)
+
+    for(label i=0;i<size;++i)
         if( data_[start+i] == e )
             return i;
 
diff --git a/meshLibrary/utilities/containers/VRWGraphList/VRWGraphList.C b/meshLibrary/utilities/containers/VRWGraphList/VRWGraphList.C
index b68d52520b5cff000dc8a26c745412d5c1ac270f..50c0a569819ff8feb2c316afeb8f465ac2a501b1 100644
--- a/meshLibrary/utilities/containers/VRWGraphList/VRWGraphList.C
+++ b/meshLibrary/utilities/containers/VRWGraphList/VRWGraphList.C
@@ -36,13 +36,21 @@ Foam::Ostream& Foam::operator<<
 )
 {
     os << DL.size() << nl << token::BEGIN_LIST;
-    
-    for(register label i=0;i<DL.size();++i)
+
+    for(label i=0;i<DL.size();++i)
     {
         os << nl << DL[i];
     }
-    
+
     os << nl << token::END_LIST;
+
+    // Check state of IOstream
+    os.check
+    (
+        "Foam::Ostream& Foam::operator<<"
+        "(Foam::Ostream&, const Foam::VRWGraphList&)"
+    );
+
     return os;
 }
 
diff --git a/meshLibrary/utilities/decomposeCells/decomposeCellsDecomposition.C b/meshLibrary/utilities/decomposeCells/decomposeCellsDecomposition.C
index 3068fb9f7e1e56513ace1bf5acdb647fc12ffc5d..df4ed32dc437c1346ac6b325e0b2500e793c61fb 100644
--- a/meshLibrary/utilities/decomposeCells/decomposeCellsDecomposition.C
+++ b/meshLibrary/utilities/decomposeCells/decomposeCellsDecomposition.C
@@ -162,7 +162,7 @@ void decomposeCells::createPointsAndCellFaces(const boolList& decomposeCell)
         }
 }
 
-void decomposeCells::storeBoundaryFaces(const boolList& decomposeCell)
+void decomposeCells::storeBoundaryFaces(const boolList& /*decomposeCell*/)
 {
     meshSurfaceEngine mse(mesh_);
     const faceList::subList& bFaces = mse.boundaryFaces();
diff --git a/meshLibrary/utilities/decomposeCells/decomposeCellsPyramids.C b/meshLibrary/utilities/decomposeCells/decomposeCellsPyramids.C
index 669e4d7374f62c8ed4dacbb2f5e1b64b7b411d7b..786532ae5d0991a94be376e706693234b80a23a3 100644
--- a/meshLibrary/utilities/decomposeCells/decomposeCellsPyramids.C
+++ b/meshLibrary/utilities/decomposeCells/decomposeCellsPyramids.C
@@ -127,9 +127,9 @@ void decomposeCells::findAddressingForCell
 label decomposeCells::findTopVertex
 (
     const label cellI,
-    const DynList<label, 32>& vrt,
-    const DynList<edge, 64>& edges,
-    const DynList<DynList<label, 2>, 64>& edgeFaces
+    const DynList<label, 32>& /*vrt*/,
+    const DynList<edge, 64>& /*edges*/,
+    const DynList<DynList<label, 2>, 64>& /*edgeFaces*/
 )
 {
     const cell& c = mesh_.cells()[cellI];
diff --git a/meshLibrary/utilities/faceDecomposition/decomposeFaces.C b/meshLibrary/utilities/faceDecomposition/decomposeFaces.C
index f1903cc5794fa87ef1ccf1ca7ad5ea4e10e48954..8a23ef5af93e37b660227c64b5dfd3f8893099c8 100644
--- a/meshLibrary/utilities/faceDecomposition/decomposeFaces.C
+++ b/meshLibrary/utilities/faceDecomposition/decomposeFaces.C
@@ -370,7 +370,7 @@ void decomposeFaces::decomposeConcaveInternalFaces
     # endif
 
     //- decompose internal faces
-    for(register label faceI=0;faceI<nIntFaces;++faceI)
+    for(label faceI=0;faceI<nIntFaces;++faceI)
     {
         const face& f = faces[faceI];
 
diff --git a/meshLibrary/utilities/helperClasses/parallelHelpers/parPartTet/parPartTet.H b/meshLibrary/utilities/helperClasses/parallelHelpers/parPartTet/parPartTet.H
index 179ca79bcb43dff7574c476c9bfe110b75ce07f1..f10579c80a49e890087d28545ee531d7fc533a67 100644
--- a/meshLibrary/utilities/helperClasses/parallelHelpers/parPartTet/parPartTet.H
+++ b/meshLibrary/utilities/helperClasses/parallelHelpers/parPartTet/parPartTet.H
@@ -87,7 +87,7 @@ public:
             return pts_[i];
         }
         
-        inline bool operator !=(const parPartTet& ptf) const
+        inline bool operator !=(const parPartTet& /*ptf*/) const
         {
             Serr << "Not implemented" << endl;
             ::exit(1);
diff --git a/meshLibrary/utilities/helperClasses/parallelHelpers/parTriFace/parTriFace.H b/meshLibrary/utilities/helperClasses/parallelHelpers/parTriFace/parTriFace.H
index 1b0741f9dffcab64b0a83e3f26623a895fe3bb39..fa444c341db552767c88b74701568bde5ea1cad8 100644
--- a/meshLibrary/utilities/helperClasses/parallelHelpers/parTriFace/parTriFace.H
+++ b/meshLibrary/utilities/helperClasses/parallelHelpers/parTriFace/parTriFace.H
@@ -99,12 +99,10 @@ class parTriFace
 
     // Member operators
 
-        inline bool operator !=(const parTriFace& ptf) const
+        inline bool operator !=(const parTriFace& /*ptf*/) const
         {
             Serr << "parTriFace::operator!= Not implemented" << endl;
             ::exit(1);
-
-            return true;
         }
 
     // Friend operators
diff --git a/meshLibrary/utilities/meshes/partTetMesh/partTetMeshParallelAddressing.C b/meshLibrary/utilities/meshes/partTetMesh/partTetMeshParallelAddressing.C
index f179f065f3b8ebba5921a548d802924fc74c0947..c056c0297648d34d53cce323f096b1eff533e759 100644
--- a/meshLibrary/utilities/meshes/partTetMesh/partTetMeshParallelAddressing.C
+++ b/meshLibrary/utilities/meshes/partTetMesh/partTetMeshParallelAddressing.C
@@ -46,8 +46,8 @@ namespace Foam
 void partTetMesh::createParallelAddressing
 (
     const labelLongList& nodeLabelForPoint,
-    const labelLongList& nodeLabelForFace,
-    const labelLongList& nodeLabelForCell
+    const labelLongList& /*nodeLabelForFace*/,
+    const labelLongList& /*nodeLabelForCell*/
 )
 {
     //- vertices marked as SMOOTH and BOUNDARY are used by the smoother
diff --git a/meshLibrary/utilities/meshes/partTriMesh/partTriMeshParallelAddressing.C b/meshLibrary/utilities/meshes/partTriMesh/partTriMeshParallelAddressing.C
index 2d8376294df2e6ce885fb28ac42fb7aa114a9a0a..1bd7edb4f8521d99b2c6f3f5948643a4f6bd0c6f 100644
--- a/meshLibrary/utilities/meshes/partTriMesh/partTriMeshParallelAddressing.C
+++ b/meshLibrary/utilities/meshes/partTriMesh/partTriMeshParallelAddressing.C
@@ -47,7 +47,7 @@ namespace Foam
 void partTriMesh::createParallelAddressing
 (
     const labelList& nodeLabelForPoint,
-    const labelList& nodeLabelForFace
+    const labelList& /*nodeLabelForFace*/
 )
 {
     const meshSurfaceEngine& mse = mPart_.surfaceEngine();
diff --git a/meshLibrary/utilities/meshes/polyMeshGen/boundaryPatch/processorBoundaryPatch.C b/meshLibrary/utilities/meshes/polyMeshGen/boundaryPatch/processorBoundaryPatch.C
index 80e53576f8830273b18604215f4a1fbdf9b100bc..30dd3871f6340dc961e092dc20b402814873c9c0 100644
--- a/meshLibrary/utilities/meshes/polyMeshGen/boundaryPatch/processorBoundaryPatch.C
+++ b/meshLibrary/utilities/meshes/polyMeshGen/boundaryPatch/processorBoundaryPatch.C
@@ -90,7 +90,7 @@ void processorBoundaryPatch::write(Ostream& os) const
     this->operator<<(os);
 }
 
-void processorBoundaryPatch::writeDict(Ostream& os) const
+void processorBoundaryPatch::writeDict(Ostream& /*os*/) const
 {
     
 }
diff --git a/meshLibrary/utilities/meshes/polyMeshGenChecks/polyMeshGenChecksGeometry.C b/meshLibrary/utilities/meshes/polyMeshGenChecks/polyMeshGenChecksGeometry.C
index fd299864b2c60324a0bfbacc5c1a9755d90ed208..c44d09e9452e87adee76863670ee39eea199f3b0 100644
--- a/meshLibrary/utilities/meshes/polyMeshGenChecks/polyMeshGenChecksGeometry.C
+++ b/meshLibrary/utilities/meshes/polyMeshGenChecks/polyMeshGenChecksGeometry.C
@@ -367,7 +367,7 @@ bool checkFaceAreas
     const boolList* changedFacePtr
 )
 {
-    const scalarField magFaceAreas = mag(mesh.addressingData().faceAreas());
+    const vectorField& faceAreas = mesh.addressingData().faceAreas();
 
     const labelList& own = mesh.owner();
     const labelList& nei = mesh.neighbour();
@@ -384,12 +384,14 @@ bool checkFaceAreas
         # ifdef USE_OMP
         # pragma omp for schedule(guided)
         # endif
-        forAll(magFaceAreas, faceI)
+        forAll(faceAreas, faceI)
         {
             if( changedFacePtr && !changedFacePtr->operator[](faceI) )
                 continue;
 
-            if( magFaceAreas[faceI] < minFaceArea )
+            const scalar magFaceArea = mag(faceAreas[faceI]);
+
+            if( magFaceArea < minFaceArea )
             {
                 if( report )
                 {
@@ -399,14 +401,14 @@ bool checkFaceAreas
                             << "internal face " << faceI << " between cells "
                             << own[faceI] << " and " << nei[faceI]
                             << ".  Face area magnitude = "
-                            << magFaceAreas[faceI] << endl;
+                            << magFaceArea << endl;
                     }
                     else
                     {
                         Pout<< "Zero or negative face area detected for "
                             << "boundary face " << faceI << " next to cell "
                             << own[faceI] << ".  Face area magnitude = "
-                            << magFaceAreas[faceI] << endl;
+                            << magFaceArea << endl;
                     }
                 }
 
@@ -419,8 +421,8 @@ bool checkFaceAreas
                 }
             }
 
-            localMinArea = Foam::min(localMinArea, magFaceAreas[faceI]);
-            localMaxArea = Foam::max(localMaxArea, magFaceAreas[faceI]);
+            localMinArea = Foam::min(localMinArea, magFaceArea);
+            localMaxArea = Foam::max(localMaxArea, magFaceArea);
         }
 
         # ifdef USE_OMP
@@ -1604,10 +1606,10 @@ void checkVolumeUniformity
 bool checkVolumeUniformity
 (
     const polyMeshGen&,
-    const bool report,
-    const scalar warnUniform,
-    labelHashSet* setPtr,
-    const boolList* changedFacePtr
+    const bool /*report*/,
+    const scalar /*warnUniform*/,
+    labelHashSet* /*setPtr*/,
+    const boolList* /*changedFacePtr*/
 )
 {
 
@@ -2120,7 +2122,7 @@ label findWorstQualityFaces
 (
     const polyMeshGen& mesh,
     labelHashSet& badFaces,
-    const bool report,
+    const bool /*report*/,
     const boolList* activeFacePtr,
     const scalar relativeThreshold
 )
diff --git a/meshLibrary/utilities/meshes/polyMeshGenModifier/polyMeshGenModifierRemoveFaces.C b/meshLibrary/utilities/meshes/polyMeshGenModifier/polyMeshGenModifierRemoveFaces.C
index be0cc13474eb3b6ce69d38fa44d652f60c41a9a8..89a5487ac6c1d0a6ac1ebda87f52c63a82328a78 100644
--- a/meshLibrary/utilities/meshes/polyMeshGenModifier/polyMeshGenModifierRemoveFaces.C
+++ b/meshLibrary/utilities/meshes/polyMeshGenModifier/polyMeshGenModifierRemoveFaces.C
@@ -187,7 +187,7 @@ void polyMeshGenModifier::removeFaces(const boolList& removeFace)
             neiProcNo[npI] = procBoundaries[patchI].neiProcNo();
             nFacesInPatch[npI] = 0;
 
-            for(register label faceI=0;faceI<oldNumFacesInPatch;++faceI)
+            for(label faceI=0;faceI<oldNumFacesInPatch;++faceI)
             {
                 if(
                     !removeFace[oldStart+faceI] &&
diff --git a/meshLibrary/utilities/meshes/triSurf/triSurf.C b/meshLibrary/utilities/meshes/triSurf/triSurf.C
index cc1dd65960d18b3f25a7a880e3dd142be086fab3..504a3b27679d36333a275ecd0e631b9e931df89b 100644
--- a/meshLibrary/utilities/meshes/triSurf/triSurf.C
+++ b/meshLibrary/utilities/meshes/triSurf/triSurf.C
@@ -32,6 +32,8 @@ Description
 #include "gzstream.h"
 #include "triSurface.H"
 
+#include "helperFunctions.H"
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -163,6 +165,192 @@ void triSurf::writeToFMS(const fileName& fName) const
     fStream << subsets;
 }
 
+void triSurf::topologyCheck()
+{
+    const pointField& pts = this->points();
+    const LongList<labelledTri>& trias = this->facets();
+
+    //- check for inf and nan points
+    # ifdef USE_OMP
+    # pragma omp parallel for schedule(dynamic, 100)
+    # endif
+    forAll(pts, pointI)
+    {
+        const point& p = pts[pointI];
+
+        if( help::isnan(p) || help::isinf(p) )
+        {
+            # ifdef USE_OMP
+            # pragma omp critical
+            # endif
+            {
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Point " << pointI << " has invalid coordinates "
+                  << p << exit(FatalError);
+            }
+        }
+    }
+
+    //- check whether the nodes are within the scope
+    //- report duplicate nodes in the same triangle
+    # ifdef USE_OMP
+    # pragma omp parallel for schedule(dynamic, 100)
+    # endif
+    forAll(trias, triI)
+    {
+        const labelledTri& ltri = trias[triI];
+
+        forAll(ltri, pI)
+        {
+            if( ltri[pI] < 0 || (ltri[pI] >= pts.size()) )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Point " << ltri[pI] << " in triangle " << ltri
+                  << " is out of scope 0 " << pts.size() << exit(FatalError);
+            }
+
+            if( ltri[pI] == ltri[(pI+1)%3] || ltri[pI] == ltri[(pI+2)%3] )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                WarningIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Triangle " << ltri << " has duplicated points. "
+                  << "This may cause problems in the meshing process!" << endl;
+            }
+        }
+    }
+
+    //- check feature edges
+    const edgeLongList& featureEdges = this->featureEdges();
+
+    # ifdef USE_OMP
+    # pragma omp parallel for schedule(dynamic, 100)
+    # endif
+    forAll(featureEdges, eI)
+    {
+        const edge& fe = featureEdges[eI];
+
+        forAll(fe, pI)
+        {
+            if( fe[pI] < 0 || (fe[pI] >= pts.size()) )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Feature edge " << fe << " point " << fe[pI]
+                  << " is out of scope 0 " << pts.size() << exit(FatalError);
+            }
+        }
+
+        if( fe.start() == fe.end() )
+        {
+            # ifdef USE_OMP
+            # pragma omp critical
+            # endif
+            WarningIn
+            (
+                "void triSurf::topologyCheck()"
+            ) << "Feature edge " << fe << " has duplicated points. "
+              << "This may cause problems in the meshing process!" << endl;
+        }
+    }
+
+    //- check point subsets
+    DynList<label> subsetIds;
+    this->pointSubsetIndices(subsetIds);
+    forAll(subsetIds, i)
+    {
+        labelLongList elmts;
+        this->pointsInSubset(subsetIds[i], elmts);
+
+        forAll(elmts, elmtI)
+        {
+            const label elI = elmts[elmtI];
+
+            if( elI < 0 || elI >= pts.size() )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Point " << elI << " in point subset "
+                  << this->pointSubsetName(subsetIds[i])
+                  << " is out of scope 0 " << pts.size() << exit(FatalError);
+            }
+        }
+    }
+
+    //- check face subsets
+    subsetIds.clear();
+    this->facetSubsetIndices(subsetIds);
+    forAll(subsetIds, i)
+    {
+        labelLongList elmts;
+        this->facetsInSubset(subsetIds[i], elmts);
+
+        forAll(elmts, elmtI)
+        {
+            const label elI = elmts[elmtI];
+
+            if( elI < 0 || elI >= trias.size() )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Triangle " << elI << " in facet subset "
+                  << this->facetSubsetName(subsetIds[i])
+                  << " is out of scope 0 " << trias.size() << exit(FatalError);
+            }
+        }
+    }
+
+    //- check feature edge subsets
+    subsetIds.clear();
+    this->edgeSubsetIndices(subsetIds);
+    forAll(subsetIds, i)
+    {
+        labelLongList elmts;
+        this->edgesInSubset(subsetIds[i], elmts);
+
+        forAll(elmts, elmtI)
+        {
+            const label elI = elmts[elmtI];
+
+            if( elI < 0 || elI >= featureEdges.size() )
+            {
+                # ifdef USE_OMP
+                # pragma omp critical
+                # endif
+                FatalErrorIn
+                (
+                    "void triSurf::topologyCheck()"
+                ) << "Feature edge " << elI << " in edge subset "
+                  << this->edgeSubsetName(subsetIds[i])
+                  << " is out of scope 0 " << featureEdges.size()
+                  << exit(FatalError);
+            }
+        }
+    }
+}
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 triSurf::triSurf()
@@ -186,7 +374,9 @@ triSurf::triSurf
     triSurfFacets(triangles, patches),
     triSurfFeatureEdges(featureEdges),
     triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
-{}
+{
+    topologyCheck();
+}
 
 //- Read from file
 triSurf::triSurf(const fileName& fName)
@@ -197,6 +387,8 @@ triSurf::triSurf(const fileName& fName)
     triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
 {
     readSurface(fName);
+
+    topologyCheck();
 }
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
diff --git a/meshLibrary/utilities/meshes/triSurf/triSurf.H b/meshLibrary/utilities/meshes/triSurf/triSurf.H
index 1e542553c894b7ba7f6cc260d94cae4301e5bc2a..6af0d4134c29e4eecd870dd2157ecb67558fe96a 100644
--- a/meshLibrary/utilities/meshes/triSurf/triSurf.H
+++ b/meshLibrary/utilities/meshes/triSurf/triSurf.H
@@ -74,6 +74,8 @@ class triSurf
         inline LongList<labelledTri>& accessToFacets();
         inline geometricSurfacePatchList& accessToPatches();
 
+        void topologyCheck();
+
         //- Disallow default bitwise assignment
         void operator=(const triSurf&);
 
diff --git a/meshLibrary/utilities/meshes/triSurf/triSurfAddressing.C b/meshLibrary/utilities/meshes/triSurf/triSurfAddressing.C
index 88a704b6cad751457a73f2cb3b20000f562a43e1..6cb1d9b074a10ec500d0ccb09947e216d4c6534c 100644
--- a/meshLibrary/utilities/meshes/triSurf/triSurfAddressing.C
+++ b/meshLibrary/utilities/meshes/triSurf/triSurfAddressing.C
@@ -29,6 +29,8 @@ Description
 #include "VRWGraphSMPModifier.H"
 #include "demandDrivenData.H"
 
+#include <set>
+
 # ifdef USE_OMP
 #include <omp.h>
 # endif
@@ -70,49 +72,36 @@ void triSurfAddressing::calculateEdges() const
         # ifdef USE_OMP
         # pragma omp for schedule(static)
         # endif
-        forAll(facets_, fI)
+        forAll(pFacets, pI)
         {
-            const labelledTri& tri = facets_[fI];
+            std::set<std::pair<label, label> > edgesAtPoint;
 
-            forAll(tri, pI)
+            forAllRow(pFacets, pI, pfI)
             {
-                const edge fe(tri[pI], tri[(pI+1)%3]);
-                const label s = fe.start();
-                const label e = fe.end();
-
-                DynList<label> edgeFaces;
+                const label triI = pFacets(pI, pfI);
+                const labelledTri& tri = facets_[triI];
 
-                bool store(true);
-
-                //- find all faces attached to this edge
-                //- store the edge in case the face faceI is the face
-                //- with the smallest label
-                forAllRow(pFacets, s, pfI)
+                forAll(tri, i)
                 {
-                    const label ofI = pFacets(s, pfI);
-                    const labelledTri& of = facets_[ofI];
-
-                    label pos(-1);
-                    for(label i=0;i<3;++i)
-                        if( of[i] == e )
-                        {
-                            pos = i;
-                            break;
-                        }
-                    if( pos < 0 )
-                        continue;
-                    if( ofI < fI )
+                    if( tri[i] == pI )
                     {
-                        store = false;
-                        break;
+                        if( tri[(i+1)%3] >= pI )
+                            edgesAtPoint.insert
+                            (
+                                std::make_pair(pI, tri[(i+1)%3])
+                            );
+                        if( tri[(i+2)%3] >= pI )
+                            edgesAtPoint.insert
+                            (
+                                std::make_pair(pI, tri[(i+2)%3])
+                            );
                     }
-
-                    edgeFaces.append(ofI);
                 }
-
-                if( store )
-                    edgesHelper.append(fe);
             }
+
+            std::set<std::pair<label, label> >::const_iterator it;
+            for(it=edgesAtPoint.begin();it!=edgesAtPoint.end();++it)
+                edgesHelper.append(edge(it->first, it->second));
         }
 
         //- this enables other threads to see the number of edges
@@ -124,7 +113,6 @@ void triSurfAddressing::calculateEdges() const
         # endif
         nEdgesForThread[threadI] = edgesHelper.size();
 
-
         # ifdef USE_OMP
         # pragma omp critical
         # endif
@@ -158,56 +146,58 @@ void triSurfAddressing::calculateFacetEdges() const
     const edgeLongList& edges = this->edges();
     const VRWGraph& pointFaces = this->pointFacets();
 
-    facetEdgesPtr_ = new VRWGraph(facets_.size());
+    facetEdgesPtr_ = new VRWGraph(facets_.size(), 3, -1);
     VRWGraph& faceEdges = *facetEdgesPtr_;
 
-    labelList nfe(facets_.size());
-
     # ifdef USE_OMP
-    const label nThreads = 3 * omp_get_num_procs();
-    # pragma omp parallel num_threads(nThreads)
+    # pragma omp parallel for schedule(dynamic, 100)
     # endif
+    forAll(edges, edgeI)
     {
-        # ifdef USE_OMP
-        # pragma omp for schedule(static)
-        # endif
-        forAll(facets_, fI)
-            nfe[fI] = 3;
+        const edge ee = edges[edgeI];
+        const label pI = ee.start();
 
-        # ifdef USE_OMP
-        # pragma omp barrier
-
-        # pragma omp master
-        # endif
-        VRWGraphSMPModifier(faceEdges).setSizeAndRowSize(nfe);
-
-        # ifdef USE_OMP
-        # pragma omp barrier
-
-        # pragma omp for schedule(static)
-        # endif
-        forAll(edges, edgeI)
+        forAllRow(pointFaces, pI, pfI)
         {
-            const edge ee = edges[edgeI];
-            const label pI = ee.start();
+            const label fI = pointFaces(pI, pfI);
 
-            forAllRow(pointFaces, pI, pfI)
+            const labelledTri& tri = facets_[fI];
+            forAll(tri, eI)
             {
-                const label fI = pointFaces(pI, pfI);
+                const edge e(tri[eI], tri[(eI+1)%3]);
 
-                const labelledTri& tri = facets_[fI];
-                forAll(tri, eI)
+                if( e == ee )
                 {
-                    const edge e(tri[eI], tri[(eI+1)%3]);
-                    if( e == ee )
-                    {
-                        faceEdges(fI, eI) = edgeI;
-                        break;
-                    }
+                    faceEdges(fI, eI) = edgeI;
                 }
             }
         }
     }
+
+    # ifdef DEBUGTriSurfAddressing
+    forAll(faceEdges, triI)
+    {
+        forAllRow(faceEdges, triI, feI)
+        {
+            if( facets_[triI][feI] < 0 || facets_[triI][feI] >= points_.size() )
+                FatalErrorIn
+                (
+                    "void triSurfAddressing::calculateFacetEdges() const"
+                ) << "Invalid entry in triangle " << triI
+                  << " " << facets_[triI] << abort(FatalError);
+
+            const label edgeI = faceEdges(triI, feI);
+
+            if( edgeI < 0 || edgeI >= edges.size() )
+                FatalErrorIn
+                (
+                    "void triSurfAddressing::calculateFacetEdges() const"
+                ) << "Invalid entry in face " << triI << " "
+                     << facets_[triI] << " edges "
+                     << faceEdges[triI] << abort(FatalError);
+        }
+    }
+    # endif
 }
 
 void triSurfAddressing::calculateEdgeFacets() const
diff --git a/meshLibrary/utilities/octrees/meshOctree/meshOctreeAddressing/meshOctreeAddressingCreation.C b/meshLibrary/utilities/octrees/meshOctree/meshOctreeAddressing/meshOctreeAddressingCreation.C
index 3a868a212d6c5ef0eee7aed1febf041af72bbb9d..317787f684a7b2c177cb7270bc74d2d9bcf5c3b7 100644
--- a/meshLibrary/utilities/octrees/meshOctree/meshOctreeAddressing/meshOctreeAddressingCreation.C
+++ b/meshLibrary/utilities/octrees/meshOctree/meshOctreeAddressing/meshOctreeAddressingCreation.C
@@ -39,6 +39,10 @@ Description
 
 //#define DEBUGVrt
 
+# ifdef DEBUGVrt
+#include "OFstream.H"
+# endif
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -46,6 +50,76 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+# ifdef DEBUGVrt
+void writeOctreeToVTK
+(
+    const fileName& fName,
+    const meshOctree& octree,
+    const List<direction>& boxTypes,
+    const direction bType
+)
+{
+    OFstream file(fName);
+
+    //- write the header
+    file << "# vtk DataFile Version 3.0\n";
+    file << "vtk output\n";
+    file << "ASCII\n";
+    file << "DATASET UNSTRUCTURED_GRID\n";
+
+    label nBoxes(0);
+    forAll(boxTypes, leafI)
+        if( boxTypes[leafI] & bType )
+            ++nBoxes;
+
+    //- write points
+    file << "POINTS " << 8*nBoxes << " float\n";
+    forAll(boxTypes, leafI)
+    {
+        if( boxTypes[leafI] & bType )
+        {
+            FixedList<point, 8> vertices;
+            octree.returnLeaf(leafI).vertices(octree.rootBox(), vertices);
+
+            forAll(vertices, vI)
+            {
+                const point& p = vertices[vI];
+
+                file << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
+            }
+        }
+    }
+
+    //- write boxes
+    file << "\nCELLS " << nBoxes
+         << " " << 9 * nBoxes << nl;
+
+    nBoxes = 0;
+    forAll(boxTypes, leafI)
+    {
+        if( boxTypes[leafI] & bType )
+        {
+            const label start = 8 * nBoxes;
+            file << 8 << " " << start << " " << start+1
+                      << " " << start+3 << " " << start+2
+                      << " " << start+4 << " " << start+5
+                      << " " << start+7 << " " << start+6 << nl;
+
+            ++nBoxes;
+        }
+    }
+
+    file << nl;
+
+    //- write cell types
+    file << "CELL_TYPES " << nBoxes << nl;
+    for(label i=0;i<nBoxes;++i)
+        file << 12 << nl;
+
+    file << nl;
+}
+# endif
+
 void meshOctreeAddressing::createOctreePoints() const
 {
     const VRWGraph& nodeLabels = this->nodeLabels();
@@ -56,7 +130,7 @@ void meshOctreeAddressing::createOctreePoints() const
 
     const label nLeaves = nodeLabels.size();
     # ifdef USE_OMP
-    # pragma omp parallel for schedule(guided)
+    # pragma omp parallel for schedule(guided, 100)
     # endif
     for(label cubeI=0;cubeI<nLeaves;++cubeI)
     {
@@ -66,10 +140,12 @@ void meshOctreeAddressing::createOctreePoints() const
         FixedList<point, 8> vertices;
         const meshOctreeCubeBasic& oc = octree_.returnLeaf(cubeI);
         oc.vertices(rootBox, vertices);
-        forAllRow(nodeLabels, cubeI, pI)
+
+        forAllRow(nodeLabels, cubeI, nI)
         {
-            forAllRow(nodeLabels, cubeI, nI)
-                octreePoints[nodeLabels(cubeI, nI)] = vertices[nI];
+            const label nodeI = nodeLabels(cubeI, nI);
+
+            octreePoints[nodeI] = vertices[nI];
         }
     }
 }
@@ -97,7 +173,7 @@ void meshOctreeAddressing::createNodeLabels() const
     nNodes_ = 0;
     DynList<label> numLocalNodes;
     # ifdef USE_OMP
-    # pragma omp parallel //num_threads(Foam::max(nodeLabels.size() / 1000, 1))
+    # pragma omp parallel
     # endif
     {
         # ifdef USE_OMP
@@ -162,7 +238,7 @@ void meshOctreeAddressing::createNodeLabels() const
                     }
                 }
 
-                if( minLeaf == leafI && validLeaf[7-nI] )
+                if( (minLeaf == leafI) && validLeaf[7-nI] )
                 {
                     forAll(pLeaves, plI)
                         if( validLeaf[plI] )
@@ -251,6 +327,74 @@ void meshOctreeAddressing::createNodeLabels() const
             nNodes_ = Foam::max(nNodes_, startNode);
         }
     }
+
+    # ifdef DEBUGVrt
+    List<direction> badLeaves(nodeLabels.size(), direction(0));
+    forAll(nodeLabels, leafI)
+        forAllRow(nodeLabels, leafI, i)
+            if( nodeLabels(leafI, i) < 0 )
+                badLeaves[leafI] |= 1;
+    writeOctreeToVTK("badLeaves.vtk", octree_, badLeaves, 1);
+
+    writeOctreeToVTK("meshCells.vtk", octree_, boxType, MESHCELL);
+    writeOctreeToVTK("boundaryCells.vtk", octree_, boxType, BOUNDARY);
+
+    Info << "Checking for existence of negative node labels" << endl;
+    forAll(nodeLabels, leafI)
+    {
+        forAllRow(nodeLabels, leafI, nI)
+        {
+            if( nodeLabels(leafI, nI) < 0 )
+            {
+                FixedList<label, 8> pLeaves;
+                octree_.findLeavesForCubeVertex(leafI, nI, pLeaves);
+
+                FixedList<bool, 8> validLeaf(true);
+                label minLeaf(leafI);
+                forAll(pLeaves, plI)
+                {
+                    if( pLeaves[plI] > -1 )
+                    {
+                        for(label i=plI+1;i<8;++i)
+                            if( pLeaves[plI] == pLeaves[i] )
+                            {
+                                validLeaf[plI] = false;
+                                validLeaf[i] = false;
+                            }
+
+                        if( !boxType[pLeaves[plI]] )
+                        {
+                            validLeaf[plI] = false;
+                            pLeaves[plI] = -1;
+                        }
+
+                        if( validLeaf[plI] )
+                            minLeaf = Foam::min(minLeaf, pLeaves[plI]);
+                    }
+                    else
+                    {
+                        validLeaf[plI] = false;
+                    }
+                }
+
+                Info << "Min leaf " << minLeaf << endl;
+                Info << "Valid leaf " << validLeaf << endl;
+                Info << "pLeaves " << pLeaves << endl;
+                Info << "Node position " << nI << endl;
+
+                Info << "1.Leaf " << leafI << " node labels "
+                      << nodeLabels[leafI] << endl;
+
+                forAll(validLeaf, i)
+                    if( validLeaf[i] )
+                        Info << "Leaf at position " << i << " has node labels "
+                             << nodeLabels[pLeaves[i]]
+                             << " at level "
+                             << octree_.returnLeaf(pLeaves[i]).level() << endl;
+            }
+        }
+    }
+    # endif
 }
 
 void meshOctreeAddressing::createNodeLeaves() const
@@ -891,8 +1035,8 @@ void meshOctreeAddressing::createOctreeFaces() const
     {
         face f(octreeFacesPtr_->sizeOfRow(faceI));
         forAll(f, pI)
-            f[pI] = octreeFacesPtr->operator()(faceI, pI);
-        const vector n = (*octreeFacesPtr_)[faceI].normal(this->octreePoints());
+            f[pI] = octreeFacesPtr_->operator()(faceI, pI);
+        const vector n = f.normal(this->octreePoints());
 
         sum[(*octreeFacesOwnersPtr_)[faceI]] += n;
         const label nei = (*octreeFacesNeighboursPtr_)[faceI];
diff --git a/meshLibrary/utilities/octrees/meshOctree/meshOctreeFindNearestSurfacePoint.C b/meshLibrary/utilities/octrees/meshOctree/meshOctreeFindNearestSurfacePoint.C
index bc6f264111c10fadb4a63e8fa1e439362987a200..9bf19e0976652918019ada7c2b1a7e6f0d05469b 100644
--- a/meshLibrary/utilities/octrees/meshOctree/meshOctreeFindNearestSurfacePoint.C
+++ b/meshLibrary/utilities/octrees/meshOctree/meshOctreeFindNearestSurfacePoint.C
@@ -136,6 +136,16 @@ void meshOctree::findNearestSurfacePointInRegion
     const point& p
 ) const
 {
+    if( region < 0 )
+    {
+        WarningIn
+        (
+            "void meshOctree::findNearestSurfacePointInRegion(point&, scalar&,"
+            "label&, const label, const point&) const"
+        ) << "Region " << region << " is not valid!" << endl;
+
+        return;
+    }
     const label cLabel = findLeafContainingVertex(p);
     vector sizeVec;
     if( cLabel < 0 )
diff --git a/meshLibrary/utilities/octrees/meshOctree/meshOctreeModifier/meshOctreeModifierParallelRefinement.C b/meshLibrary/utilities/octrees/meshOctree/meshOctreeModifier/meshOctreeModifierParallelRefinement.C
index fa92e6ee6329358842d33716bdf3d9f77ab9bffa..1aebb1c2b77a8784f38455276c983d98fb560d7a 100644
--- a/meshLibrary/utilities/octrees/meshOctree/meshOctreeModifier/meshOctreeModifierParallelRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/meshOctreeModifier/meshOctreeModifierParallelRefinement.C
@@ -119,8 +119,8 @@ void meshOctreeModifier::refineTreeForCoordinates
 void meshOctreeModifier::refineTreeForCoordinates
 (
     const meshOctreeCubeCoordinates& cc,
-    const labelList& containedTriangles,
-    const labelList& containedEdges,
+    const labelList& /*containedTriangles*/,
+    const labelList& /*containedEdges*/,
     const short procNo,
     const direction cubeType
 )
diff --git a/meshLibrary/utilities/octrees/meshOctree/meshOctreeNeighbourSearches.C b/meshLibrary/utilities/octrees/meshOctree/meshOctreeNeighbourSearches.C
index 1c4cec63af80badc5756d279a93dcf2f5ef337e5..f0265310b855d3ce23d8fa187f29702630b40aa5 100644
--- a/meshLibrary/utilities/octrees/meshOctree/meshOctreeNeighbourSearches.C
+++ b/meshLibrary/utilities/octrees/meshOctree/meshOctreeNeighbourSearches.C
@@ -188,7 +188,7 @@ void meshOctree::findNeighboursOverEdge
     DynList<label>& neighbourLeaves
 ) const
 {
-    if( isQuadtree_ && (eI >= 8) )
+    if( isQuadtree_ && (eI < 8) )
     {
         neighbourLeaves.append(-1);
         return;
@@ -396,17 +396,26 @@ void meshOctree::findAllLeafNeighbours
     {
         for(label i=0;i<8;++i)
             neighbourLeaves.append(findNeighbourOverNode(cc, i));
-    }
 
-    //- neighbours over edges
-    const label nCubeEdges = isQuadtree_?8:12;
-    for(label i=0;i<nCubeEdges;++i)
-        findNeighboursOverEdge(cc, i, neighbourLeaves);
+        //- neighbours over edges
+        for(label i=0;i<12;++i)
+            findNeighboursOverEdge(cc, i, neighbourLeaves);
 
-    //- neighbours over faces
-    const label nCubeFaces = isQuadtree_?4:6;
-    for(label i=0;i<nCubeFaces;++i)
-        findNeighboursInDirection(cc, i, neighbourLeaves);
+        //- neighbours over faces
+        for(label i=0;i<6;++i)
+            findNeighboursInDirection(cc, i, neighbourLeaves);
+    }
+    else
+    {
+        //- neighbours of an quadtree leaf
+        //- neighbours over edges
+        for(label i=8;i<12;++i)
+            findNeighboursOverEdge(cc, i, neighbourLeaves);
+
+        //- neighbours over faces
+        for(label i=0;i<4;++i)
+            findNeighboursInDirection(cc, i, neighbourLeaves);
+    }
 }
 
 void meshOctree::findLeavesForCubeVertex
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/boxRefinement.C b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/boxRefinement.C
index cb98c86c924d0085e5dec448cea1b632a81ba2ec..232344a18528cbe265bd01285ffc1f3f40398e05 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/boxRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/boxRefinement.C
@@ -94,7 +94,7 @@ bool boxRefinement::intersectsObject(const boundBox& bb) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary boxRefinement::dict(bool ignoreType) const
+dictionary boxRefinement::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/coneRefinement.C b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/coneRefinement.C
index 792ac26a4812bee0b393630b827b9642cd274044..c63fee135d9d9df97656a413d973f8c12a65f66f 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/coneRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/coneRefinement.C
@@ -106,7 +106,7 @@ bool coneRefinement::intersectsObject(const boundBox& bb) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary coneRefinement::dict(bool ignoreType) const
+dictionary coneRefinement::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/hollowConeRefinement.C b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/hollowConeRefinement.C
index 623214fc8c270b3ac764bce6b910aa93c044dc36..507135f98f80f8a5350e9a74f61ab8910388385a 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/hollowConeRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/hollowConeRefinement.C
@@ -115,7 +115,7 @@ bool hollowConeRefinement::intersectsObject(const boundBox& bb) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary hollowConeRefinement::dict(bool ignoreType) const
+dictionary hollowConeRefinement::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/lineRefinement.C b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/lineRefinement.C
index 48cada863d055d843c951beb36b5d3277e76d2ea..d7ebcb85d3516768d360fdf84de69d88f5171201 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/lineRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/lineRefinement.C
@@ -206,7 +206,7 @@ bool lineRefinement::intersectsObject(const boundBox& bb) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary lineRefinement::dict(bool ignoreType) const
+dictionary lineRefinement::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/objectRefinement.H b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/objectRefinement.H
index 45ac72f7c7e7efe42d15ef75499f33c02a5e3a30..ce1ebafdd9213142d8e96a2644bdef3eabdafa3b 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/objectRefinement.H
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/objectRefinement.H
@@ -163,7 +163,7 @@ public:
         //- set refinement thickness
         void setRefinementThickness(const scalar refThickness)
         {
-            refThickness_ = refThickness_;
+            refThickness_ = refThickness;
         }
 
         //- return refinement thickness for this object
diff --git a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/sphereRefinement.C b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/sphereRefinement.C
index 82dae30ca28fc8392c4ac4b5b85ac6790501e58d..ccd269886a4688bcc624f796da2dc3536ae1e92a 100644
--- a/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/sphereRefinement.C
+++ b/meshLibrary/utilities/octrees/meshOctree/refinementControls/objectRefinement/sphereRefinement.C
@@ -87,7 +87,7 @@ bool sphereRefinement::intersectsObject(const boundBox& bb) const
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-dictionary sphereRefinement::dict(bool ignoreType) const
+dictionary sphereRefinement::dict(bool /*ignoreType*/) const
 {
     dictionary dict;
 
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizer.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizer.C
index fb873ac296fddb0d87170eb62e8f474a3746d22a..3a700a8a06dbfe18e65be4abae40cb1f2ce40121 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizer.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizer.C
@@ -107,7 +107,7 @@ label meshOptimizer::findBadFaces
 label meshOptimizer::findLowQualityFaces
 (
     labelHashSet& badFaces,
-    const boolList& changedFace
+    const boolList& /*changedFace*/
 ) const
 {
     badFaces.clear();
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizerOptimizePoint.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizerOptimizePoint.C
index 87cc7e72af1f516a9869f3fa6749fecc9cc56799..cc571521dc70859e92db13464ad8345c75311564 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizerOptimizePoint.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/meshOptimizerOptimizePoint.C
@@ -368,8 +368,8 @@ void meshOptimizer::laplaceSmoother::optimizeLaplacian(const label nIterations)
 
 void meshOptimizer::laplaceSmoother::optimizeLaplacian
 (
-    const labelHashSet& badFaces,
-    const label nIterations
+    const labelHashSet& /*badFaces*/,
+    const label /*nIterations*/
 )
 {
     FatalError << "Not implemented " << exit(FatalError);
@@ -377,8 +377,8 @@ void meshOptimizer::laplaceSmoother::optimizeLaplacian
 
 void meshOptimizer::laplaceSmoother::optimizeSurfaceLaplacian
 (
-    const labelHashSet& badFaces,
-    const label nIterations
+    const labelHashSet& /*badFaces*/,
+    const label /*nIterations*/
 )
 {
     FatalError << "Not implemented " << exit(FatalError);
@@ -402,8 +402,8 @@ void meshOptimizer::laplaceSmoother::optimizeLaplacianPC
 
 void meshOptimizer::laplaceSmoother::optimizeLaplacianPC
 (
-    const labelHashSet& badFaces,
-    const label nIterations
+    const labelHashSet& /*badFaces*/,
+    const label /*nIterations*/
 )
 {
     FatalError << "Not implemented " << exit(FatalError);
@@ -427,8 +427,8 @@ void meshOptimizer::laplaceSmoother::optimizeLaplacianWPC
 
 void meshOptimizer::laplaceSmoother::optimizeLaplacianWPC
 (
-    const labelHashSet& badFaces,
-    const label nIterations
+    const labelHashSet& /*badFaces*/,
+    const label /*nIterations*/
 )
 {
     FatalError << "Not implemented " << exit(FatalError);
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/optimizeMeshFV.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/optimizeMeshFV.C
index 6f7255c6bde65aa9b3df33219dfbb76517c95118..e21922358eec2d98ab320aaa4d44e531f56d55f7 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/optimizeMeshFV.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/optimizeMeshFV.C
@@ -196,7 +196,7 @@ void meshOptimizer::untangleMeshFV
         // move boundary vertices
         nIter = 0;
 
-        while( nIter++ < maxNumSurfaceIterations );
+        while( nIter++ < maxNumSurfaceIterations )
         {
             if( !relaxedCheck )
             {
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/knuppMetric/knuppMetric.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/knuppMetric/knuppMetric.C
index 0bb115b88d740c396bc2dfb324e7d19c692859d5..704a581d9925a192f3fce80d09ce743cc103ec28 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/knuppMetric/knuppMetric.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/knuppMetric/knuppMetric.C
@@ -121,7 +121,7 @@ knuppMetric::~knuppMetric()
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Implementation of knupp metric untangling
-void knuppMetric::optimizeNodePosition(const scalar tolObsolete)
+void knuppMetric::optimizeNodePosition(const scalar /*tolObsolete*/)
 {
     if( !bb_.contains(p_) )
         p_ = 0.5 * (bb_.min() + bb_.max());
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/meshUntangler/meshUntangler.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/meshUntangler/meshUntangler.C
index ea78ed86f2dfa39dcb4226028d0e9cf1d416b564..7065978d1e92e90dc349924d40071d8caca1c271 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/meshUntangler/meshUntangler.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/meshUntangler/meshUntangler.C
@@ -57,7 +57,7 @@ meshUntangler::~meshUntangler()
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-void meshUntangler::optimizeNodePosition(const scalar tol)
+void meshUntangler::optimizeNodePosition(const scalar /*tol*/)
 {
     # ifdef DEBUGSmooth
     Info << "Untangling point " << pointI_ << endl;
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/quadricMetric/quadricMetric.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/quadricMetric/quadricMetric.C
index 44c8d6ae289dad379d320efa2636b95b7840a158..78b84205d499cee312c040315c97a6fbded8b785 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/quadricMetric/quadricMetric.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/tetMeshOptimisation/advancedSmoothers/quadricMetric/quadricMetric.C
@@ -101,7 +101,7 @@ quadricMetric::~quadricMetric()
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Implementation of knupp metric untangling
-void quadricMetric::optimizeNodePosition(const scalar tolObsolete)
+void quadricMetric::optimizeNodePosition(const scalar /*tolObsolete*/)
 {
     if( !bb_.contains(p_) )
         p_ = 0.5 * (bb_.min() + bb_.max());
diff --git a/meshLibrary/utilities/smoothers/geometry/meshSurfaceOptimizer/meshSurfaceOptimizerOptimizePointParallel.C b/meshLibrary/utilities/smoothers/geometry/meshSurfaceOptimizer/meshSurfaceOptimizerOptimizePointParallel.C
index 6f206f60a2d8d3f0aadf0d8cbd0c6e22976de50b..f400f95669947b248fa23d2a7fbab0d9780a0e14 100644
--- a/meshLibrary/utilities/smoothers/geometry/meshSurfaceOptimizer/meshSurfaceOptimizerOptimizePointParallel.C
+++ b/meshLibrary/utilities/smoothers/geometry/meshSurfaceOptimizer/meshSurfaceOptimizerOptimizePointParallel.C
@@ -425,8 +425,8 @@ void meshSurfaceOptimizer::edgeNodeDisplacementParallel
 
 void meshSurfaceOptimizer::exchangeData
 (
-    const labelLongList& nodesToSmooth,
-    std::map<label, DynList<parTriFace> >& m
+    const labelLongList& /*nodesToSmooth*/,
+    std::map<label, DynList<parTriFace> >& /*m*/
 ) const
 {
     /*
diff --git a/meshLibrary/utilities/smoothers/topology/checkCellConnectionsOverFaces/checkCellConnectionsOverFaces.C b/meshLibrary/utilities/smoothers/topology/checkCellConnectionsOverFaces/checkCellConnectionsOverFaces.C
index a67d16d3d68fa24757027df8951dc011359eb593..fbb5c00e696cdb1b0e76a7415fb395324e3c95dd 100644
--- a/meshLibrary/utilities/smoothers/topology/checkCellConnectionsOverFaces/checkCellConnectionsOverFaces.C
+++ b/meshLibrary/utilities/smoothers/topology/checkCellConnectionsOverFaces/checkCellConnectionsOverFaces.C
@@ -171,7 +171,7 @@ public:
     meshConnectionsSelectorOperator()
     {}
 
-    bool operator()(const label cellI) const
+    bool operator()(const label /*cellI*/) const
     {
         return true;
     }
diff --git a/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologicalCleanerInvalidVertices.C b/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologicalCleanerInvalidVertices.C
index 7e354438fe45a984378b4f443621b4b1057b766a..ad368fe359f81890477b161dcfe286f3e26ca945 100644
--- a/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologicalCleanerInvalidVertices.C
+++ b/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologicalCleanerInvalidVertices.C
@@ -178,7 +178,7 @@ void topologicalCleaner::checkInvalidConnectionsForVerticesCells
 
 void topologicalCleaner::checkInvalidConnectionsForVerticesFaces
 (
-    labelHashSet* irregularNodesPtr
+    labelHashSet* /*irregularNodesPtr*/
 )
 {
     const meshSurfaceEngine mse(mesh_);
diff --git a/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologyCleanerNonConsecutiveBoundaryVertices.C b/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologyCleanerNonConsecutiveBoundaryVertices.C
index 1d65007311ca80b533afdcfa68cd2fe273314ebc..4a31b1fd8767781b27c40aeeb14588296875443d 100644
--- a/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologyCleanerNonConsecutiveBoundaryVertices.C
+++ b/meshLibrary/utilities/smoothers/topology/topologicalCleaner/topologyCleanerNonConsecutiveBoundaryVertices.C
@@ -59,67 +59,70 @@ void topologicalCleaner::checkNonConsecutiveBoundaryVertices()
 
         for(label faceI=start;faceI<end;++faceI)
         {
-            const face& bf = faces[faceI];
-
-            # ifdef DEBUGCleaner
-            Info << "Checking boundary face " << faceI << " with vertices "
-                << bf << endl;
+            # ifdef USE_OMP
+            # pragma omp task shared(decomposeFace,faces,cells,owner,faceI)
             # endif
+            {
+                const face& bf = faces[faceI];
 
-            const label bfsize = bf.size();
-
-            const cell& c = cells[owner[faceI]];
+                # ifdef DEBUGCleaner
+                Info << "Checking boundary face " << faceI << " with vertices "
+                    << bf << endl;
+                # endif
 
-            forAll(c, fI)
-                if(
-                    (c[fI] < nIntFaces) ||
-                    (mesh_.faceIsInProcPatch(c[fI]) != -1)
-                )
-                {
-                    const face& f = faces[c[fI]];
+                const cell& c = cells[owner[faceI]];
 
-                    DynList<label> shN;
+                forAll(c, fI)
+                    if(
+                        (c[fI] < nIntFaces) ||
+                        (mesh_.faceIsInProcPatch(c[fI]) != -1)
+                    )
+                    {
+                        const face& f = faces[c[fI]];
 
-                    forAll(bf, pI)
-                        forAll(f, pJ)
-                            if( bf[pI] == f[pJ] )
-                            {
-                                shN.append(pI);
-                            }
+                        DynList<label> shN;
 
-                    # ifdef DEBUGCleaner
-                    Info << "Shared vertices with internal face " << f
-                        << " are " << shN << endl;
-                    # endif
+                        forAll(bf, pI)
+                            forAll(f, pJ)
+                                if( bf[pI] == f[pJ] )
+                                {
+                                    shN.append(pI);
+                                }
 
-                    if( shN.size() > 2 )
-                    {
                         # ifdef DEBUGCleaner
-                        Info << "1. Face has to be split" << endl;
+                        Info << "Shared vertices with internal face " << f
+                            << " are " << shN << endl;
                         # endif
 
-                        decomposeFace[faceI] = true;
-                        decomposeCell_[owner[faceI]] = true;
-                        changed = true;
-                    }
-                    else if( shN.size() == 2 )
-                    {
-                        if( !(
-                                (shN[0] == ((shN[1] + 1) % bfsize)) ||
-                                (shN[0] == ((shN[1] + bfsize - 1) % bfsize))
-                            )
-                        )
+                        if( shN.size() > 2 )
                         {
                             # ifdef DEBUGCleaner
-                            Info << "2. Face has to be split" << endl;
+                            Info << "1. Face has to be split" << endl;
                             # endif
 
                             decomposeFace[faceI] = true;
                             decomposeCell_[owner[faceI]] = true;
                             changed = true;
                         }
+                        else if( shN.size() == 2 )
+                        {
+                            if( !(
+                                    (shN[0] == bf.fcIndex(shN[1])) ||
+                                    (shN[0] == bf.rcIndex(shN[1]))
+                                )
+                            )
+                            {
+                                # ifdef DEBUGCleaner
+                                Info << "2. Face has to be split" << endl;
+                                # endif
+
+                                decomposeFace[faceI] = true;
+                                decomposeCell_[owner[faceI]] = true;
+                                changed = true;
+                            }
+                        }
                     }
-                }
+            }
         }
     }
 
diff --git a/meshLibrary/utilities/surfaceTools/edgeExtraction/edgeExtractor/edgeExtractor.C b/meshLibrary/utilities/surfaceTools/edgeExtraction/edgeExtractor/edgeExtractor.C
index 9334f54186b8a1de9497f099d5c3ceb1323a824b..584f7202d05ae69992fa5b04ebf1d3ca8df11686 100644
--- a/meshLibrary/utilities/surfaceTools/edgeExtraction/edgeExtractor/edgeExtractor.C
+++ b/meshLibrary/utilities/surfaceTools/edgeExtraction/edgeExtractor/edgeExtractor.C
@@ -522,12 +522,15 @@ void edgeExtractor::findFaceCandidates
 
     const labelList& fPatches = *facePatchPtr;
 
+    bool deleteOtherFacePatchPtr(false);
     if( !otherFacePatchPtr )
     {
-        Map<label> otherFacePatch;
-        findOtherFacePatchesParallel(otherFacePatch, &fPatches);
+        Map<label>* helperPtr = new Map<label>();
 
-        otherFacePatchPtr = &otherFacePatch;
+        findOtherFacePatchesParallel(*helperPtr, facePatchPtr);
+
+        otherFacePatchPtr = helperPtr;
+        deleteOtherFacePatchPtr = true;
     }
 
     const Map<label>& otherFacePatch = *otherFacePatchPtr;
@@ -547,15 +550,15 @@ void edgeExtractor::findFaceCandidates
         forAll(faceEdges, bfI)
         {
             DynList<label> allNeiPatches;
-            forAllRow(faceEdges, bfI, eI)
+            forAllRow(faceEdges, bfI, feI)
             {
-                const label beI = faceEdges(bfI, eI);
+                const label beI = faceEdges(bfI, feI);
 
                 if( edgeFaces.sizeOfRow(beI) == 2 )
                 {
                     label fNei = edgeFaces(beI, 0);
                     if( fNei == bfI )
-                        fNei = edgeFaces(faceEdges(bfI, eI), 1);
+                        fNei = edgeFaces(beI, 1);
 
                     allNeiPatches.appendIfNotIn(fPatches[fNei]);
                 }
@@ -584,6 +587,9 @@ void edgeExtractor::findFaceCandidates
         }
         # endif
     }
+
+    if( deleteOtherFacePatchPtr )
+        deleteDemandDrivenData(otherFacePatchPtr);
 }
 
 void edgeExtractor::findOtherFacePatchesParallel
diff --git a/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.C b/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.C
index fd84feda2cab940477ff874b10fbc444c9513577..068a9800915d8b0d0aee9f6db9767b5e0d1415aa 100644
--- a/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.C
+++ b/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.C
@@ -69,7 +69,7 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
         problematicPoint[bp[it.key()]] = true;
 
     //- classify edges
-    edgeTypes_.setSize(edges.size());
+    edgeType_.setSize(edges.size());
 
     # ifdef USE_OMP
     label nThreads = 3 * omp_get_num_procs();
@@ -81,12 +81,6 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
     # pragma omp parallel num_threads(nThreads)
     # endif
     {
-        # ifdef USE_OMP
-        # pragma omp for schedule(static, 1)
-        # endif
-        forAll(edgeTypes_, edgeI)
-            edgeTypes_[edgeI] = NONE;
-
         // TODO: this is not valid for non-manifold meshes
         //- start checking feature edges
         # ifdef USE_OMP
@@ -94,26 +88,34 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
         # endif
         forAll(edgeFaces, edgeI)
         {
+            edgeType_[edgeI] = NONE;
+
             if( edgeFaces.sizeOfRow(edgeI) == 2 )
             {
                 const label f0 = edgeFaces(edgeI, 0);
                 const label f1 = edgeFaces(edgeI, 1);
 
                 if( facePatch[f0] == facePatch[f1] )
-                    edgeTypes_[edgeI] |= PATCHEDGE;
+                {
+                    edgeType_[edgeI] |= PATCHEDGE;
+                }
+                else
+                {
+                    edgeType_[edgeI] |= FEATUREEDGE;
+                }
 
                 const edge e = edges[edgeI];
 
                 //- check if the surface is tangled there
                 if( problematicPoint[bp[e.start()]] )
                 {
-                    edgeTypes_[edgeI] |= UNDETERMINED;
+                    edgeType_[edgeI] |= UNDETERMINED;
                     continue;
                 }
 
                 if( problematicPoint[bp[e.end()]] )
                 {
-                    edgeTypes_[edgeI] |= UNDETERMINED;
+                    edgeType_[edgeI] |= UNDETERMINED;
                     continue;
                 }
 
@@ -128,7 +130,7 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
 
                 if( tet0.mag() > -VSMALL )
                 {
-                    edgeTypes_[edgeI] |= CONCAVEEDGE;
+                    edgeType_[edgeI] |= CONCAVEEDGE;
                     continue;
                 }
 
@@ -142,11 +144,11 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
 
                 if( tet1.mag() > -VSMALL )
                 {
-                    edgeTypes_[edgeI] |= CONCAVEEDGE;
+                    edgeType_[edgeI] |= CONCAVEEDGE;
                     continue;
                 }
 
-                edgeTypes_[edgeI] |= CONVEXEDGE;
+                edgeType_[edgeI] |= CONVEXEDGE;
             }
         }
     }
@@ -175,7 +177,13 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
         forAllConstIter(Map<label>, otherPatch, eIter)
         {
             if( eIter() == facePatch[edgeFaces(eIter.key(), 0)] )
-                continue;
+            {
+                edgeType_[eIter()] |= PATCHEDGE;
+            }
+            else
+            {
+                edgeType_[eIter()] |= FEATUREEDGE;
+            }
 
             const edge& e = edges[eIter.key()];
             if
@@ -184,7 +192,7 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
                 problematicPoint[bp[e.end()]]
             )
             {
-                edgeTypes_[eIter.key()] |= UNDETERMINED;
+                edgeType_[eIter.key()] |= UNDETERMINED;
                 continue;
             }
 
@@ -231,7 +239,7 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
 
             if ( tet0.mag() > -VSMALL )
             {
-                edgeTypes_[edgeI] |= CONCAVEEDGE;
+                edgeType_[edgeI] |= CONCAVEEDGE;
                 continue;
             }
 
@@ -245,11 +253,11 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
 
             if ( tet1.mag() > -VSMALL )
             {
-                edgeTypes_[edgeI] |= CONCAVEEDGE;
+                edgeType_[edgeI] |= CONCAVEEDGE;
                 continue;
             }
 
-            edgeTypes_[edgeI] |= CONVEXEDGE;
+            edgeType_[edgeI] |= CONVEXEDGE;
         }
     }
 
@@ -264,27 +272,36 @@ void meshSurfaceCheckEdgeTypes::classifyEdges()
                 surfaceEngine_.boundaryPoints()[bpI]
             );
 
-    forAll(edgeTypes_, edgeI)
+    const label convexId = mesh_.addPointSubset("convexFeatures");
+    const label concaveId = mesh_.addPointSubset("concaveFeatures");
+    const label undeterminedId = mesh_.addPointSubset("undetermnedFeatures");
+    const label patchId = mesh_.addPointSubset("patchPoints");
+
+    forAll(edgeType_, edgeI)
     {
-        if( edgeTypes_[edgeI] & CONVEXEDGE )
+        if( edgeType_[edgeI] & CONVEXEDGE )
         {
             Info <<"Edge " << edgeI << " is convex" << endl;
+            mesh_.addPointToSubset(convexId, edges[edgeI].start());
+            mesh_.addPointToSubset(convexId, edges[edgeI].end());
         }
-        else if( edgeTypes_[edgeI] & CONCAVEEDGE )
+        if( edgeType_[edgeI] & CONCAVEEDGE )
         {
             Info << "Edge " << edgeI << " is concave" << endl;
+            mesh_.addPointToSubset(concaveId, edges[edgeI].start());
+            mesh_.addPointToSubset(concaveId, edges[edgeI].end());
         }
-        else if( edgeTypes_[edgeI] & UNDETERMINED )
+        if( edgeType_[edgeI] & UNDETERMINED )
         {
             Info << "Edge " << edgeI << " is not determined" << endl;
+            mesh_.addPointToSubset(undeterminedId, edges[edgeI].start());
+            mesh_.addPointToSubset(undeterminedId, edges[edgeI].end());
         }
-        else if( edgeTypes_[edgeI] & PATCHEDGE )
+        if( edgeType_[edgeI] & PATCHEDGE )
         {
             Info << "Edge " << edgeI << " is a patch edge" << endl;
-        }
-        else
-        {
-            Info << "Drekec spekec" << edgeI << endl;
+            mesh_.addPointToSubset(patchId, edges[edgeI].start());
+            mesh_.addPointToSubset(patchId, edges[edgeI].end());
         }
     }
     # endif
@@ -298,7 +315,7 @@ meshSurfaceCheckEdgeTypes::meshSurfaceCheckEdgeTypes
 )
 :
     surfaceEngine_(mse),
-    edgeTypes_()
+    edgeType_()
 {
     classifyEdges();
 }
@@ -314,9 +331,9 @@ void meshSurfaceCheckEdgeTypes::convexEdges(labelLongList& convexEdges) const
 {
     convexEdges.clear();
 
-    forAll(edgeTypes_, eI)
+    forAll(edgeType_, eI)
     {
-        if( edgeTypes_[eI] & CONVEXEDGE )
+        if( edgeType_[eI] & CONVEXEDGE )
             convexEdges.append(eI);
     }
 }
@@ -325,9 +342,9 @@ void meshSurfaceCheckEdgeTypes::concaveEdges(labelLongList& concaveEdges) const
 {
     concaveEdges.clear();
 
-    forAll(edgeTypes_, eI)
+    forAll(edgeType_, eI)
     {
-        if( edgeTypes_[eI] & CONCAVEEDGE )
+        if( edgeType_[eI] & CONCAVEEDGE )
             concaveEdges.append(eI);
     }
 }
diff --git a/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.H b/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.H
index f656b401817e1aa542ecaece2a2f289c0f6489ed..b88e2243f99b4870390b2d55bd7b603c00fd63b4 100644
--- a/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.H
+++ b/meshLibrary/utilities/surfaceTools/meshSurfaceCheckEdgeTypes/meshSurfaceCheckEdgeTypes.H
@@ -60,7 +60,7 @@ class meshSurfaceCheckEdgeTypes
         const meshSurfaceEngine& surfaceEngine_;
 
         //- a list which classifies each edge
-        List<direction> edgeTypes_;
+        List<direction> edgeType_;
 
     // Private member functions
         //- check feature edges and classify them
@@ -83,9 +83,10 @@ public:
         {
             NONE = 0,
             PATCHEDGE = 1,
-            CONVEXEDGE = 2,
-            CONCAVEEDGE = 4,
-            UNDETERMINED = 8
+            FEATUREEDGE = 2,
+            CONVEXEDGE = 4,
+            CONCAVEEDGE = 8,
+            UNDETERMINED = 16
         };
 
     // Constructors
@@ -101,7 +102,7 @@ public:
         //- return the information about classified edges
         const List<direction>& edgeTypes() const
         {
-            return edgeTypes_;
+            return edgeType_;
         }
 
         //- return indices of convex edges
diff --git a/meshLibrary/utilities/surfaceTools/meshSurfaceEngine/meshSurfaceEngineCalculateBoundaryNodesAndFaces.C b/meshLibrary/utilities/surfaceTools/meshSurfaceEngine/meshSurfaceEngineCalculateBoundaryNodesAndFaces.C
index f79069fea7b732b78040d09869131ad104e92651..e6e3f5ae6b9ba6c1cfb0843e751fe01422483594 100644
--- a/meshLibrary/utilities/surfaceTools/meshSurfaceEngine/meshSurfaceEngineCalculateBoundaryNodesAndFaces.C
+++ b/meshLibrary/utilities/surfaceTools/meshSurfaceEngine/meshSurfaceEngineCalculateBoundaryNodesAndFaces.C
@@ -29,7 +29,6 @@ Description
 #include "demandDrivenData.H"
 #include "boolList.H"
 #include "helperFunctions.H"
-#include "helperFunctionsPar.H"
 #include "VRWGraphSMPModifier.H"
 #include "labelledPoint.H"
 #include "HashSet.H"
@@ -887,6 +886,7 @@ void meshSurfaceEngine::calculateEdgesAndAddressing() const
 {
     const VRWGraph& pFaces = pointFaces();
     const faceList::subList& bFaces = boundaryFaces();
+    const labelList& bPoints = boundaryPoints();
     const labelList& bp = this->bp();
 
     edgesPtr_ = new edgeList();
@@ -911,47 +911,41 @@ void meshSurfaceEngine::calculateEdgesAndAddressing() const
     # pragma omp parallel num_threads(nThreads)
     # endif
     {
-        LongList<edge> edgesHelper;
+        edgeLongList edgesHelper;
 
         # ifdef USE_OMP
         # pragma omp for schedule(static)
         # endif
-        forAll(bFaces, bfI)
+        forAll(pFaces, bpI)
         {
-            const face& bf = bFaces[bfI];
+            std::set<std::pair<label, label> > edgesAtPoint;
 
-            forAll(bf, pI)
+            forAllRow(pFaces, bpI, pfI)
             {
-                const edge fe = bf.faceEdge(pI);
-                const label bpI = bp[fe.start()];
-                const label e = fe.end();
-
-                DynList<label> edgeFaces;
+                const label bfI = pFaces(bpI, pfI);
+                const face& bf = bFaces[bfI];
 
-                bool store(true);
+                const label pos = bf.which(bPoints[bpI]);
 
-                //- find all faces attached to this edge
-                //- store the edge in case the face faceI is the face
-                //- with the smallest label
-                forAllRow(pFaces, bpI, pfI)
+                if( bp[bf.nextLabel(pos)] >= bpI )
                 {
-                    const label ofI = pFaces(bpI, pfI);
-                    const face& of = bFaces[ofI];
-
-                    if( of.which(e) < 0 )
-                        continue;
-                    if( ofI < bfI )
-                    {
-                        store = false;
-                        break;
-                    }
-
-                    edgeFaces.append(ofI);
+                    edgesAtPoint.insert
+                    (
+                        std::make_pair(bf[pos], bf.nextLabel(pos))
+                    );
+                }
+                if( bp[bf.prevLabel(pos)] >= bpI )
+                {
+                    edgesAtPoint.insert
+                    (
+                        std::make_pair(bf[pos], bf.prevLabel(pos))
+                    );
                 }
-
-                if( store )
-                    edgesHelper.append(fe);
             }
+
+            std::set<std::pair<label, label> >::const_iterator it;
+            for(it=edgesAtPoint.begin();it!=edgesAtPoint.end();++it)
+                edgesHelper.append(edge(it->first, it->second));
         }
 
         //- this enables other threads to see the number of edges
@@ -1099,7 +1093,7 @@ void meshSurfaceEngine::calculateFaceEdgesAddressing() const
     const faceList::subList& bFaces = this->boundaryFaces();
     const labelList& bp = this->bp();
     const edgeList& edges = this->edges();
-    const VRWGraph& pointFaces = this->pointFaces();
+    const VRWGraph& bpEdges = this->boundaryPointEdges();
 
     faceEdgesPtr_ = new VRWGraph(bFaces.size());
     VRWGraph& faceEdges = *faceEdgesPtr_;
@@ -1122,29 +1116,36 @@ void meshSurfaceEngine::calculateFaceEdgesAddressing() const
         # pragma omp barrier
 
         # pragma omp master
+        {
         # endif
+
         VRWGraphSMPModifier(faceEdges).setSizeAndRowSize(nfe);
 
         # ifdef USE_OMP
+        }
+
         # pragma omp barrier
 
-        # pragma omp for schedule(static)
+        # pragma omp for schedule(dynamic, 100)
         # endif
-        forAll(edges, edgeI)
+        forAll(faceEdges, bfI)
         {
-            const edge ee = edges[edgeI];
-            const label bpI = bp[ee.start()];
+            const face& bf = bFaces[bfI];
 
-            forAllRow(pointFaces, bpI, pfI)
+            forAll(bf, eI)
             {
-                const label bfI = pointFaces(bpI, pfI);
+                const edge e = bf.faceEdge(eI);
 
-                const face& bf = bFaces[bfI];
-                forAll(bf, eI)
+                const label bps = bp[e.start()];
+
+                forAllRow(bpEdges, bps, peI)
                 {
-                    if( bf.faceEdge(eI) == ee )
+                    const label beI = bpEdges(bps, peI);
+                    const edge& ee = edges[beI];
+
+                    if( e == ee )
                     {
-                        faceEdges[bfI][eI] = edgeI;
+                        faceEdges(bfI, eI) = beI;
                         break;
                     }
                 }
@@ -1219,6 +1220,7 @@ void meshSurfaceEngine::calculateEdgeFacesAddressing() const
             const edge& ee = edges[edgeI];
             const label bpI = bp[ee.start()];
 
+            //- find boundary faces attached to this edge
             DynList<label> eFaces;
             forAllRow(pointFaces, bpI, pfI)
             {
@@ -1236,6 +1238,23 @@ void meshSurfaceEngine::calculateEdgeFacesAddressing() const
                 }
             }
 
+            //- the face that owns the edge shall be the first one in the list
+            // TODO: find out whether this will be necessary
+            if( eFaces.size() == 2 )
+            {
+                const face& bf = bFaces[eFaces[1]];
+
+                const label pos = bf.which(ee.start());
+
+                if( bf.nextLabel(pos) == ee.end() )
+                {
+                    //- this face shall be the first one in the list
+                    const label helper = eFaces[0];
+                    eFaces[0] = eFaces[1];
+                    eFaces[1] = helper;
+                }
+            }
+
             edgeFaces.setRow(edgeI, eFaces);
         }
     }
diff --git a/meshLibrary/utilities/surfaceTools/surfaceMorpherCells/surfaceMorpherCellsMorphInternalFaces.C b/meshLibrary/utilities/surfaceTools/surfaceMorpherCells/surfaceMorpherCellsMorphInternalFaces.C
index 8f4c6216b2e80456d282984f95d7d6741b13537f..b5d3f99bdde472ed52f96b303211060252c41234 100644
--- a/meshLibrary/utilities/surfaceTools/surfaceMorpherCells/surfaceMorpherCellsMorphInternalFaces.C
+++ b/meshLibrary/utilities/surfaceTools/surfaceMorpherCells/surfaceMorpherCellsMorphInternalFaces.C
@@ -531,7 +531,8 @@ bool surfaceMorpherCells::morphInternalFaces()
         //- remove faces which do not exist any more
         boolList removeFace(faces.size(), false);
         bool removeFaces(false);
-        for(register label faceI=0;faceI<nIntFaces;++faceI)
+
+        for(label faceI=0;faceI<nIntFaces;++faceI)
             if( faces[faceI].size() < 3 )
             {
                 removeFace[faceI] = true;
diff --git a/meshLibrary/utilities/triSurfaceTools/triSurfaceChecks/triSurfaceChecks.C b/meshLibrary/utilities/triSurfaceTools/triSurfaceChecks/triSurfaceChecks.C
index b1a314e2fc0ac8b30e2a1d749462b4389a4d68ff..3bdcac9c1e5051ce5a26da34314a04f9bec0b8eb 100644
--- a/meshLibrary/utilities/triSurfaceTools/triSurfaceChecks/triSurfaceChecks.C
+++ b/meshLibrary/utilities/triSurfaceTools/triSurfaceChecks/triSurfaceChecks.C
@@ -179,12 +179,11 @@ public:
         template<class labelListType>
         void collectGroups
         (
-            std::map<label, DynList<label> >& neiGroups,
-            const labelListType& elementInGroup,
-            const DynList<label>& localGroupLabel
+            std::map<label, DynList<label> >& /*neiGroups*/,
+            const labelListType& /*elementInGroup*/,
+            const DynList<label>& /*localGroupLabel*/
         ) const
         {
-
         }
 };
 
@@ -209,7 +208,7 @@ public:
     selectOp()
     {}
 
-    bool operator()(const label tI) const
+    bool operator()(const label /*tI*/) const
     {
         return true;
     }
@@ -443,9 +442,9 @@ public:
         template<class labelListType>
         void collectGroups
         (
-            std::map<label, DynList<label> >& neiGroups,
-            const labelListType& elementInGroup,
-            const DynList<label>& localGroupLabel
+            std::map<label, DynList<label> >& /*neiGroups*/,
+            const labelListType& /*elementInGroup*/,
+            const DynList<label>& /*localGroupLabel*/
         ) const
         {
 
@@ -564,9 +563,9 @@ public:
         template<class labelListType>
         void collectGroups
         (
-            std::map<label, DynList<label> >& neiGroups,
-            const labelListType& elementInGroup,
-            const DynList<label>& localGroupLabel
+            std::map<label, DynList<label> >& /*neiGroups*/,
+            const labelListType& /*elementInGroup*/,
+            const DynList<label>& /*localGroupLabel*/
         ) const
         {
 
diff --git a/meshLibrary/utilities/triSurfaceTools/triSurfaceImportSurfaceAsSubset/triSurfaceImportSurfaceAsSubset.C b/meshLibrary/utilities/triSurfaceTools/triSurfaceImportSurfaceAsSubset/triSurfaceImportSurfaceAsSubset.C
index 55dff8749f927ce36e6c10e1802662bda8003638..09e9935de22cbc9f8e2f1a1e52bc7679ec397902 100644
--- a/meshLibrary/utilities/triSurfaceTools/triSurfaceImportSurfaceAsSubset/triSurfaceImportSurfaceAsSubset.C
+++ b/meshLibrary/utilities/triSurfaceTools/triSurfaceImportSurfaceAsSubset/triSurfaceImportSurfaceAsSubset.C
@@ -39,11 +39,10 @@ namespace Foam
 
 void triSurfaceImportSurfaceAsSubset::createOctree
 (
-    const triSurf& surf,
-    meshOctree& octree
+    const triSurf& /*surf*/,
+    meshOctree& /*octree*/
 )
 {
-
 }
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/utilities/FLMAToSurface/FLMAToSurface.C b/utilities/FLMAToSurface/FLMAToSurface.C
index 7db8924627abc94c9b80d372532a93f77d605c4a..5c10fd65fde0da6892759da0beb719294cded9db 100644
--- a/utilities/FLMAToSurface/FLMAToSurface.C
+++ b/utilities/FLMAToSurface/FLMAToSurface.C
@@ -27,7 +27,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triSurfModifier.H"
 #include "triFaceList.H"
diff --git a/utilities/FMSToSurface/FMSToSurface.C b/utilities/FMSToSurface/FMSToSurface.C
index bd4ad4fde0eaf1cd15cc5802b5cd7f6f8ce21c8f..8c27c90424caadcadb4d1793ea99d9007d141310 100644
--- a/utilities/FMSToSurface/FMSToSurface.C
+++ b/utilities/FMSToSurface/FMSToSurface.C
@@ -27,7 +27,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triSurfaceCopyParts.H"
 #include "demandDrivenData.H"
diff --git a/utilities/FMSToVTK/FMSToVTK.C b/utilities/FMSToVTK/FMSToVTK.C
index 747fb4e3635796a6ee24b2fc4903167851cae331..9241bc6dde19a2ba4397a67b4903a17b79dc33e7 100644
--- a/utilities/FMSToVTK/FMSToVTK.C
+++ b/utilities/FMSToVTK/FMSToVTK.C
@@ -45,7 +45,7 @@ using namespace Foam;
 void writePointsToVTK
 (
     const fileName& fn,
-    const string& title,
+    const string& /*title*/,
     const UList<point>& points
 )
 {
@@ -102,7 +102,7 @@ void writePointsToVTK
 void writeEdgesToVTK
 (
     const fileName& fn,
-    const string& title,
+    const string& /*title*/,
     const UList<point>& points,
     const LongList<edge>& edges
 )
@@ -201,7 +201,7 @@ void writeEdgesToVTK
 void writeFacetsToVTK
 (
     const fileName& fn,
-    const string& title,
+    const string& /*title*/,
     const UList<point>& points,
     const LongList<labelledTri>& facets
 )
diff --git a/utilities/extrudeEdgesInto2DSurface/extrudeEdgesInto2DSurface.C b/utilities/extrudeEdgesInto2DSurface/extrudeEdgesInto2DSurface.C
index 0ff651237a55ff7866aa0d9aa1c7096379d7b5a6..1c3202978ee120b4857e5faa31a3395fd4ca63c9 100644
--- a/utilities/extrudeEdgesInto2DSurface/extrudeEdgesInto2DSurface.C
+++ b/utilities/extrudeEdgesInto2DSurface/extrudeEdgesInto2DSurface.C
@@ -28,7 +28,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triSurfaceExtrude2DEdges.H"
 #include "demandDrivenData.H"
diff --git a/utilities/generateBoundaryLayers/generateBoundaryLayers.C b/utilities/generateBoundaryLayers/generateBoundaryLayers.C
index 3481ce2bae87e9b7dda4693b0af2e8b5577112fb..38ae2fdbd8179747de5e75632b1c71d84bba37cc 100644
--- a/utilities/generateBoundaryLayers/generateBoundaryLayers.C
+++ b/utilities/generateBoundaryLayers/generateBoundaryLayers.C
@@ -28,7 +28,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "polyMeshGenModifier.H"
 #include "meshOptimizer.H"
 #include "boundaryLayers.H"
diff --git a/utilities/improveMeshQuality/improveMeshQuality.C b/utilities/improveMeshQuality/improveMeshQuality.C
index 775abca8f3ace4acbd32074cbaefb5259a004d51..1a31446e44aa00771f3f78b268707d8eb09dff4b 100644
--- a/utilities/improveMeshQuality/improveMeshQuality.C
+++ b/utilities/improveMeshQuality/improveMeshQuality.C
@@ -28,7 +28,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "polyMeshGenModifier.H"
 #include "meshOptimizer.H"
 
diff --git a/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C b/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C
index 6deae2c633c04f4a18933e14c6e8b9ff30bbcc71..72e90c4b905c36bc7ed39c18c20593cb5f813fd4 100644
--- a/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C
+++ b/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C
@@ -28,7 +28,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "polyMeshGenModifier.H"
 #include "symmetryPlaneOptimisation.H"
 
diff --git a/utilities/mergeSurfacePatches/mergeSurfacePatches.C b/utilities/mergeSurfacePatches/mergeSurfacePatches.C
index 53d0f8db0be69a5dbdb5cc8703d9fe3b086731f5..e5218154846107ffd67a2b716538620491e96d2d 100644
--- a/utilities/mergeSurfacePatches/mergeSurfacePatches.C
+++ b/utilities/mergeSurfacePatches/mergeSurfacePatches.C
@@ -32,7 +32,6 @@ Author
 
 #include "argList.H"
 #include "autoPtr.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triSurfModifier.H"
 #include "demandDrivenData.H"
diff --git a/utilities/meshToFPMA/meshToFPMA.C b/utilities/meshToFPMA/meshToFPMA.C
index 0a69f40db544ad50d3868783eb6608dd72eb6d38..7297df55b51c104fe139f919665c6ef9c4720acd 100644
--- a/utilities/meshToFPMA/meshToFPMA.C
+++ b/utilities/meshToFPMA/meshToFPMA.C
@@ -27,7 +27,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "polyMeshGenModifier.H"
 #include "writeMeshFPMA.H"
 
diff --git a/utilities/patchesToSubsets/patchesToSubsets.C b/utilities/patchesToSubsets/patchesToSubsets.C
index 57efd9ccbee665548e57e8288c1cb145317d1f0b..e5d705e4141119d7f830a7a93ce0c66c8863f8e8 100644
--- a/utilities/patchesToSubsets/patchesToSubsets.C
+++ b/utilities/patchesToSubsets/patchesToSubsets.C
@@ -27,7 +27,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triFaceList.H"
 #include "labelLongList.H"
diff --git a/utilities/preparePar/preparePar.C b/utilities/preparePar/preparePar.C
index a918b89dde280e82b9f6591f761eb33dc8420648..f352805f2757c8b144e45f654b44f5728dcfbace 100644
--- a/utilities/preparePar/preparePar.C
+++ b/utilities/preparePar/preparePar.C
@@ -29,6 +29,7 @@ Description
 
 \*---------------------------------------------------------------------------*/
 
+#include "objectRegistry.H"
 #include "argList.H"
 #include "Time.H"
 
diff --git a/utilities/removeSurfaceFacets/removeSurfaceFacets.C b/utilities/removeSurfaceFacets/removeSurfaceFacets.C
index 8fae8f439bf920bd10fc7901f0ecf46e9ab6ec03..31eec8bab646d41ca3d36feca8295ea466f9fce0 100644
--- a/utilities/removeSurfaceFacets/removeSurfaceFacets.C
+++ b/utilities/removeSurfaceFacets/removeSurfaceFacets.C
@@ -28,7 +28,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "triSurfaceRemoveFacets.H"
 
diff --git a/utilities/subsetToPatch/subsetToPatch.C b/utilities/subsetToPatch/subsetToPatch.C
index 5e71f89cd12c067575a238bc0696dce4b948446c..11fc8a88b5128f7723566679f83803cf4fc9e6bc 100644
--- a/utilities/subsetToPatch/subsetToPatch.C
+++ b/utilities/subsetToPatch/subsetToPatch.C
@@ -27,7 +27,6 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
-#include "Time.H"
 #include "triSurf.H"
 #include "demandDrivenData.H"