From fb20bc107ed98d69cc372dfb98cff652b0e3eed5 Mon Sep 17 00:00:00 2001
From: Andrew Heather <a.heather@opencfd.co.uk>
Date: Wed, 6 Sep 2017 16:05:12 +0100
Subject: [PATCH] INT: Updated dependent code following latest set of
 integrations

---
 .../mesh/advanced/selectCells/edgeStats.C     |  4 +-
 .../foamFormatConvert/writeMeshObject.H       |  2 +-
 .../decomposePar/decomposePar.C               |  2 +
 .../parLagrangianRedistributor.C              |  1 +
 .../unmappedPassiveParticleCloud.H            |  3 +-
 .../PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C |  2 +-
 .../createZeroDirectory/createZeroDirectory.C |  3 +-
 .../IOobjects/CompactIOList/CompactIOList.C   |  2 +-
 src/OpenFOAM/db/IOobjects/IOMap/IOMapName.C   |  8 +-
 .../decomposedBlockData/decomposedBlockData.C | 72 ++++++++++++--
 .../db/IOstreams/StringStreams/StringStream.H | 10 +-
 .../functionObjectList/functionObjectList.C   |  3 +-
 .../fileOperation/fileOperation.H             |  6 +-
 .../masterUncollatedFileOperation.C           | 99 +++++++++++--------
 .../masterUncollatedFileOperation.H           |  8 +-
 .../uncollatedFileOperation.C                 | 11 ++-
 .../uncollatedFileOperation.H                 | 11 ++-
 src/OpenFOAM/global/profiling/profiling.C     |  6 +-
 src/OpenFOAM/global/profiling/profiling.H     |  3 +-
 .../uniformInterpolationTable.C               |  3 +-
 .../porosityModel/porosityModel.H             |  2 +-
 src/lagrangian/basic/particle/particle.C      | 15 ++-
 src/lagrangian/basic/particle/particle.H      |  9 +-
 src/lagrangian/basic/particle/particleI.H     |  6 ++
 .../searchableSurface/searchableSurface.H     |  2 +-
 .../dynamicOversetFvMesh.C                    |  9 +-
 .../dynamicOversetFvMesh.H                    |  3 +-
 .../MeshedSurfaceIOAllocator.C                | 11 ++-
 .../MeshedSurfaceIOAllocator.H                |  5 +-
 src/surfMesh/surfMesh/surfMesh.H              |  5 +-
 src/surfMesh/surfMesh/surfMeshIO.C            |  7 +-
 31 files changed, 232 insertions(+), 101 deletions(-)

diff --git a/applications/utilities/mesh/advanced/selectCells/edgeStats.C b/applications/utilities/mesh/advanced/selectCells/edgeStats.C
index 907bb665f10..8d2fada35d8 100644
--- a/applications/utilities/mesh/advanced/selectCells/edgeStats.C
+++ b/applications/utilities/mesh/advanced/selectCells/edgeStats.C
@@ -68,7 +68,6 @@ Foam::direction Foam::edgeStats::getNormalDir
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from mesh
 Foam::edgeStats::edgeStats(const polyMesh& mesh)
 :
     mesh_(mesh),
@@ -144,7 +143,7 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
 
     const edgeList& edges = mesh_.edges();
 
-    forAll(const edge& e : edges)
+    for (const edge& e : edges)
     {
         vector eVec(e.vec(mesh_.points()));
 
@@ -208,5 +207,4 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
 }
 
 
-
 // ************************************************************************* //
diff --git a/applications/utilities/miscellaneous/foamFormatConvert/writeMeshObject.H b/applications/utilities/miscellaneous/foamFormatConvert/writeMeshObject.H
index 87afd6cf424..4f02dabaf40 100644
--- a/applications/utilities/miscellaneous/foamFormatConvert/writeMeshObject.H
+++ b/applications/utilities/miscellaneous/foamFormatConvert/writeMeshObject.H
@@ -61,7 +61,7 @@ inline bool writeMeshObject
 
     bool writeOk = false;
 
-    if (io.typeHeaderOk<T>(true, true, false))
+    if (io.typeHeaderOk<CheckType>(true, true, false))
     {
         Info<< "        Reading " << io.headerClassName()
             << " : " << name << endl;
diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
index 2ccf7cf4bbb..c5458159329 100644
--- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
+++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
@@ -451,6 +451,8 @@ int main(int argc, char *argv[])
                 fileOperations::collatedFileOperation::maxThreadFileBufferSize;
             fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0;
 
+            mesh.decomposeMesh();
+
             mesh.writeDecomposition(decomposeSets);
 
             if (writeCellDist)
diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C
index 2b0528737d7..9052b8df0b3 100644
--- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C
+++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C
@@ -231,6 +231,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
                 )
                 {
                     passiveParticle& newp = newpIter();
+                    newp.relocate();
 
                     lagrangianPositions.addParticle(newParticles.remove(&newp));
                 }
diff --git a/applications/utilities/parallelProcessing/redistributePar/unmappedPassiveParticleCloud.H b/applications/utilities/parallelProcessing/redistributePar/unmappedPassiveParticleCloud.H
index daa147d7bb6..c1b6d6a2081 100644
--- a/applications/utilities/parallelProcessing/redistributePar/unmappedPassiveParticleCloud.H
+++ b/applications/utilities/parallelProcessing/redistributePar/unmappedPassiveParticleCloud.H
@@ -92,7 +92,8 @@ public:
         (
             IOstream::streamFormat fmt,
             IOstream::versionNumber ver,
-            IOstream::compressionType cmp
+            IOstream::compressionType cmp,
+            const bool valid
         ) const
         {
             return true;
diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C
index 9e61618cab6..bae3336c120 100644
--- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C
+++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C
@@ -58,7 +58,7 @@ public:
         explicit zonesEntries(const IOobject& io)
         :
             regIOobject(io),
-            PtrList<entry>(readStream("regIOobject"))
+            PtrList<entry>(readStream(word("regIOobject")))
         {
             close();
         }
diff --git a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C
index 68ef4c3d69d..0e9b0fbd041 100644
--- a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C
+++ b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C
@@ -199,7 +199,8 @@ void createFieldFiles
         (
             IOstream::ASCII,
             IOstream::currentVersion,
-            IOstream::UNCOMPRESSED
+            IOstream::UNCOMPRESSED,
+            true
         );
     }
 }
diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
index 887f03bacb4..12112fb59e8 100644
--- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
+++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
@@ -224,7 +224,7 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
 
         const_cast<word&>(typeName) = IOList<T>::typeName;
 
-        bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp);
+        bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, valid);
 
         // Change type back
         const_cast<word&>(typeName) = oldTypeName;
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMapName.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMapName.C
index 40f655d1b29..ee3d90bfb69 100644
--- a/src/OpenFOAM/db/IOobjects/IOMap/IOMapName.C
+++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMapName.C
@@ -39,9 +39,13 @@ namespace Foam
 
     //- Template specialisation for obtaining filePath
     template<>
-    fileName typeFilePath<IOMap<dictionary>>(const IOobject& io)
+    fileName typeFilePath<IOMap<dictionary>>
+    (
+        const IOobject& io,
+        const bool search
+    )
     {
-        return io.globalFilePath(IOMap<dictionary>::typeName);
+        return io.globalFilePath(IOMap<dictionary>::typeName, search);
     }
 }
 
diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C
index 7afbd2fb82c..15809004dcd 100644
--- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C
+++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C
@@ -177,7 +177,13 @@ bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is)
     List<char> data(is);
     is.fatalCheck("read(Istream&) : reading entry");
     string buf(data.begin(), data.size());
-    IStringStream str(is.name(), buf);
+    IStringStream str
+    (
+        buf,
+        IOstream::ASCII,
+        IOstream::currentVersion,
+        is.name()
+    );
 
     return io.readHeader(str);
 }
@@ -241,7 +247,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
         is.fatalCheck("read(Istream&) : reading entry");
 
         string buf(data.begin(), data.size());
-        realIsPtr = new IStringStream(is.name(), buf);
+        realIsPtr = new IStringStream
+        (
+            buf,
+            IOstream::ASCII,
+            IOstream::currentVersion,
+            is.name()
+        );
 
         // Read header
         if (!headerIO.readHeader(realIsPtr()))
@@ -261,7 +273,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
         IOstream::streamFormat fmt;
         {
             string buf(data.begin(), data.size());
-            IStringStream headerStream(is.name(), buf);
+            IStringStream headerStream
+            (
+                buf,
+                IOstream::ASCII,
+                IOstream::currentVersion,
+                is.name()
+            );
 
             // Read header
             if (!headerIO.readHeader(headerStream))
@@ -281,7 +299,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
             is.fatalCheck("read(Istream&) : reading entry");
         }
         string buf(data.begin(), data.size());
-        realIsPtr = new IStringStream(is.name(), buf);
+        realIsPtr = new IStringStream
+        (
+            buf,
+            IOstream::ASCII,
+            IOstream::currentVersion,
+            is.name()
+        );
 
         // Apply master stream settings to realIsPtr
         realIsPtr().format(fmt);
@@ -445,7 +469,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
                 is.fatalCheck("read(Istream&) : reading entry");
 
                 string buf(data.begin(), data.size());
-                realIsPtr = new IStringStream(fName, buf);
+                realIsPtr = new IStringStream
+                (
+                    buf,
+                    IOstream::ASCII,
+                    IOstream::currentVersion,
+                    fName
+                );
 
                 // Read header
                 if (!headerIO.readHeader(realIsPtr()))
@@ -493,7 +523,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
             is >> data;
 
             string buf(data.begin(), data.size());
-            realIsPtr = new IStringStream(fName, buf);
+            realIsPtr = new IStringStream
+            (
+                buf,
+                IOstream::ASCII,
+                IOstream::currentVersion,
+                fName
+            );
         }
     }
     else
@@ -516,7 +552,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
                 is.fatalCheck("read(Istream&) : reading entry");
 
                 string buf(data.begin(), data.size());
-                realIsPtr = new IStringStream(fName, buf);
+                realIsPtr = new IStringStream
+                (
+                    buf,
+                    IOstream::ASCII,
+                    IOstream::currentVersion,
+                    fName
+                );
 
                 // Read header
                 if (!headerIO.readHeader(realIsPtr()))
@@ -554,7 +596,13 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
             is >> data;
 
             string buf(data.begin(), data.size());
-            realIsPtr = new IStringStream(fName, buf);
+            realIsPtr = new IStringStream
+            (
+                buf,
+                IOstream::ASCII,
+                IOstream::currentVersion,
+                fName
+            );
         }
     }
 
@@ -797,7 +845,13 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const
     IOobject io(*this);
     if (Pstream::master())
     {
-        IStringStream is(name(), str);
+        IStringStream is
+        (
+            str,
+            IOstream::ASCII,
+            IOstream::currentVersion,
+            name()
+        );
         io.readHeader(is);
     }
 
diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H
index 3f50c2fac78..1bdbad9adb7 100644
--- a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H
+++ b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H
@@ -138,11 +138,12 @@ public:
         (
             const Foam::string& buffer,
             streamFormat format=ASCII,
-            versionNumber version=currentVersion
+            versionNumber version=currentVersion,
+            const Foam::string& name="input"
         )
         :
             StringStreamAllocator<std::istringstream>(buffer),
-            ISstream(*allocatedPtr_, "input", format, version)
+            ISstream(*allocatedPtr_, name, format, version)
         {}
 
 
@@ -151,11 +152,12 @@ public:
         (
             const char* buffer,
             streamFormat format=ASCII,
-            versionNumber version=currentVersion
+            versionNumber version=currentVersion,
+            const Foam::string& name="input"
         )
         :
             StringStreamAllocator<std::istringstream>(buffer),
-            ISstream(*allocatedPtr_, "input", format, version)
+            ISstream(*allocatedPtr_, name, format, version)
         {}
 
 
diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
index 5f70e6fb5a1..0acd4e17d1c 100644
--- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
+++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
@@ -590,7 +590,8 @@ bool Foam::functionObjectList::execute()
         (
             IOstream::ASCII,
             IOstream::currentVersion,
-            time_.writeCompression()
+            time_.writeCompression(),
+            true
         );
 
         IOstream::precision_ = oldPrecision;
diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
index ccd55b2fdd9..6e776320d0a 100644
--- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
@@ -274,7 +274,8 @@ public:
             (
                 const bool checkGlobal,
                 const IOobject&,
-                const word& typeName
+                const word& typeName,
+                const bool search = true
             ) const = 0;
 
             //- Search for a directory. checkGlobal : also check undecomposed
@@ -282,7 +283,8 @@ public:
             virtual fileName dirPath
             (
                 const bool checkGlobal,
-                const IOobject&
+                const IOobject& io,
+                const bool search = true
             ) const = 0;
 
             //- Search directory for objects. Used in IOobjectList.
diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
index 41cf4bc7a00..f436b45776e 100644
--- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
@@ -95,6 +95,7 @@ Foam::fileName Foam::fileOperations::masterUncollatedFileOperation::filePathInfo
     const bool checkGlobal,
     const bool isFile,
     const IOobject& io,
+    const bool search,
     pathType& searchType,
     word& newInstancePath
 ) const
@@ -163,47 +164,47 @@ Foam::fileName Foam::fileOperations::masterUncollatedFileOperation::filePathInfo
             }
         }
 
-       // Check for approximately same time. E.g. if time = 1e-2 and
-       // directory is 0.01 (due to different time formats)
-       HashPtrTable<instantList>::const_iterator pathFnd
+        // Check for approximately same time. E.g. if time = 1e-2 and
+        // directory is 0.01 (due to different time formats)
+        HashPtrTable<instantList>::const_iterator pathFnd
         (
             times_.find
             (
                 io.time().path()
             )
         );
-       if (pathFnd != times_.end())
-       {
-           newInstancePath = findInstancePath
-           (
-               *pathFnd(),
-               instant(io.instance())
-           );
-
-           if (newInstancePath.size())
-           {
-               // 1. Try processors equivalent
-
-               fileName fName =
-                   processorsPath(io, newInstancePath)
-                  /io.name();
-               if (isFileOrDir(isFile, fName))
-               {
-                   searchType = fileOperation::PROCESSORSFINDINSTANCE;
-                   return fName;
-               }
-
-               fName =
-                   io.rootPath()/io.caseName()
-                  /newInstancePath/io.db().dbDir()/io.local()/io.name();
-
-               if (isFileOrDir(isFile, fName))
-               {
-                   searchType = fileOperation::FINDINSTANCE;
-                   return fName;
-               }
-           }
-       }
+        if (search && (pathFnd != times_.end()))
+        {
+            newInstancePath = findInstancePath
+            (
+                *pathFnd(),
+                instant(io.instance())
+            );
+
+            if (newInstancePath.size())
+            {
+                // 1. Try processors equivalent
+
+                fileName fName =
+                    processorsPath(io, newInstancePath)
+                   /io.name();
+                if (isFileOrDir(isFile, fName))
+                {
+                    searchType = fileOperation::PROCESSORSFINDINSTANCE;
+                    return fName;
+                }
+
+                fName =
+                    io.rootPath()/io.caseName()
+                   /newInstancePath/io.db().dbDir()/io.local()/io.name();
+
+                if (isFileOrDir(isFile, fName))
+                {
+                    searchType = fileOperation::FINDINSTANCE;
+                    return fName;
+                }
+            }
+        }
 
         searchType = fileOperation::NOTFOUND;
         return fileName::null;
@@ -688,7 +689,8 @@ Foam::fileName Foam::fileOperations::masterUncollatedFileOperation::filePath
 (
     const bool checkGlobal,
     const IOobject& io,
-    const word& typeName
+    const word& typeName,
+    const bool search
 ) const
 {
     if (debug)
@@ -773,7 +775,8 @@ Foam::fileName Foam::fileOperations::masterUncollatedFileOperation::filePath
 Foam::fileName Foam::fileOperations::masterUncollatedFileOperation::dirPath
 (
     const bool checkGlobal,
-    const IOobject& io
+    const IOobject& io,
+    const bool search
 ) const
 {
     if (debug)
@@ -1252,7 +1255,16 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
                     Pout<< "masterUncollatedFileOperation::readStream:"
                         << " Done reading " << buf.size() << " bytes" << endl;
                 }
-                isPtr.reset(new IStringStream(fName, buf));
+                isPtr.reset
+                (
+                    new IStringStream
+                    (
+                        buf,
+                        IOstream::ASCII,
+                        IOstream::currentVersion,
+                        fName
+                    )
+                );
 
                 if (!io.readHeader(isPtr()))
                 {
@@ -1617,7 +1629,16 @@ Foam::fileOperations::masterUncollatedFileOperation::NewIFstream
             // Note: IPstream is not an IStream so use a IStringStream to
             //       convert the buffer. Note that we construct with a string
             //       so it holds a copy of the buffer.
-            return autoPtr<ISstream>(new IStringStream(filePath, buf));
+            return autoPtr<ISstream>
+            (
+                new IStringStream
+                (
+                    buf,
+                    IOstream::ASCII,
+                    IOstream::currentVersion,
+                    filePath
+                )
+            );
         }
     }
     else
diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
index 73c15fa6515..5061b1e5cf8 100644
--- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
@@ -550,8 +550,9 @@ public:
             virtual fileName filePath
             (
                 const bool checkGlobal,
-                const IOobject&,
-                const word& typeName
+                const IOobject& io,
+                const word& typeName,
+                const bool search
             ) const;
 
             //- Search for a directory. checkGlobal : also check undecomposed
@@ -559,7 +560,8 @@ public:
             virtual fileName dirPath
             (
                 const bool checkGlobal,
-                const IOobject&
+                const IOobject& io,
+                const bool search
             ) const;
 
             //- Search directory for objects. Used in IOobjectList.
diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
index ca0dc84ccb5..2ee8ad8b615 100644
--- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
@@ -50,7 +50,8 @@ Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePathInfo
 (
     const bool checkGlobal,
     const bool isFile,
-    const IOobject& io
+    const IOobject& io,
+    const bool search
 ) const
 {
     if (io.instance().isAbsolute())
@@ -119,7 +120,7 @@ Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePathInfo
 
             // Check for approximately same time. E.g. if time = 1e-2 and
             // directory is 0.01 (due to different time formats)
-            if (!Foam::isDir(path))
+            if (search && !Foam::isDir(path))
             {
                 word newInstancePath = io.time().findInstancePath
                 (
@@ -347,7 +348,8 @@ Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePath
 (
     const bool checkGlobal,
     const IOobject& io,
-    const word& typeName
+    const word& typeName,
+    const bool search
 ) const
 {
     if (debug)
@@ -373,7 +375,8 @@ Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePath
 Foam::fileName Foam::fileOperations::uncollatedFileOperation::dirPath
 (
     const bool checkGlobal,
-    const IOobject& io
+    const IOobject& io,
+    const bool search
 ) const
 {
     if (debug)
diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
index 9ff5e55b328..f2d624a9c9d 100644
--- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
@@ -59,7 +59,8 @@ class uncollatedFileOperation
         (
             const bool checkGlobal,
             const bool isFile,
-            const IOobject&
+            const IOobject& io,
+            const bool search
         ) const;
 
 
@@ -208,8 +209,9 @@ public:
             virtual fileName filePath
             (
                 const bool checkGlobal,
-                const IOobject&,
-                const word& typeName
+                const IOobject& io,
+                const word& typeName,
+                const bool search
             ) const;
 
             //- Search for a directory. checkGlobal : also check undecomposed
@@ -217,7 +219,8 @@ public:
             virtual fileName dirPath
             (
                 const bool checkGlobal,
-                const IOobject&
+                const IOobject& io,
+                const bool search
             ) const;
 
             //- Search directory for objects. Used in IOobjectList.
diff --git a/src/OpenFOAM/global/profiling/profiling.C b/src/OpenFOAM/global/profiling/profiling.C
index 7b6c7c441a5..2c212044182 100644
--- a/src/OpenFOAM/global/profiling/profiling.C
+++ b/src/OpenFOAM/global/profiling/profiling.C
@@ -409,14 +409,16 @@ bool Foam::profiling::writeObject
 (
     IOstream::streamFormat,
     IOstream::versionNumber ver,
-    IOstream::compressionType
+    IOstream::compressionType,
+    const bool valid
 ) const
 {
     return regIOobject::writeObject
     (
         IOstream::ASCII,
         ver,
-        IOstream::UNCOMPRESSED
+        IOstream::UNCOMPRESSED,
+        true
     );
 }
 
diff --git a/src/OpenFOAM/global/profiling/profiling.H b/src/OpenFOAM/global/profiling/profiling.H
index 90f47b173a9..4b6fc498206 100644
--- a/src/OpenFOAM/global/profiling/profiling.H
+++ b/src/OpenFOAM/global/profiling/profiling.H
@@ -276,7 +276,8 @@ public:
         (
             IOstream::streamFormat ignoreAlwaysASCII,
             IOstream::versionNumber ver,
-            IOstream::compressionType ignoreAlwaysUncompressed
+            IOstream::compressionType ignoreAlwaysUncompressed,
+            const bool valid
         ) const;
 
 };
diff --git a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C
index 3a296f55002..dc1318b6ae2 100644
--- a/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C
+++ b/src/OpenFOAM/interpolations/uniformInterpolationTable/uniformInterpolationTable.C
@@ -234,7 +234,8 @@ void Foam::uniformInterpolationTable<Type>::write() const
     (
         IOstream::ASCII,
         IOstream::currentVersion,
-        dict.time().writeCompression()
+        dict.time().writeCompression(),
+        true
     );
 }
 
diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H
index dc5a6845934..bc7c496dd61 100644
--- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H
+++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H
@@ -272,7 +272,7 @@ public:
         //  either in the case/processor or case otherwise null
         virtual fileName filePath() const
         {
-            return globalFilePath();
+            return globalFilePath(type());
         }
 
         //- Read porosity dictionary
diff --git a/src/lagrangian/basic/particle/particle.C b/src/lagrangian/basic/particle/particle.C
index 2cd179b12c7..f7520aa76a6 100644
--- a/src/lagrangian/basic/particle/particle.C
+++ b/src/lagrangian/basic/particle/particle.C
@@ -475,7 +475,7 @@ void Foam::particle::locate
     const vector* direction,
     const label celli,
     const bool boundaryFail,
-    const string boundaryMsg
+    const string& boundaryMsg
 )
 {
     celli_ = celli;
@@ -1130,6 +1130,19 @@ void Foam::particle::autoMap
 }
 
 
+void Foam::particle::relocate()
+{
+    locate
+    (
+        position(),
+        nullptr,
+        celli_,
+        true,
+        "Particle mapped to a location outside of the mesh."
+    );
+}
+
+
 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
 
 bool Foam::operator==(const particle& pA, const particle& pB)
diff --git a/src/lagrangian/basic/particle/particle.H b/src/lagrangian/basic/particle/particle.H
index 0eae1ef01c8..fed069bfe9c 100644
--- a/src/lagrangian/basic/particle/particle.H
+++ b/src/lagrangian/basic/particle/particle.H
@@ -293,7 +293,7 @@ private:
                 const vector* direction,
                 const label celli,
                 const bool boundaryFail,
-                const string boundaryMsg
+                const string& boundaryMsg
             );
 
 
@@ -477,6 +477,9 @@ public:
             //- Return current cell particle is in
             inline label cell() const;
 
+            //- Return current cell particle is in for manipulation
+            inline label& cell();
+
             //- Return current tet face particle is in
             inline label tetFace() const;
 
@@ -687,6 +690,10 @@ public:
         //- Map after a topology change
         void autoMap(const vector& position, const mapPolyMesh& mapper);
 
+        //- Set the addressing based on the current position and cell
+        //  Used for e.g. redistributePar
+        void relocate();
+
 
     // I-O
 
diff --git a/src/lagrangian/basic/particle/particleI.H b/src/lagrangian/basic/particle/particleI.H
index 7249fcc2759..6667e83d58a 100644
--- a/src/lagrangian/basic/particle/particleI.H
+++ b/src/lagrangian/basic/particle/particleI.H
@@ -60,6 +60,12 @@ inline Foam::label Foam::particle::cell() const
 }
 
 
+inline Foam::label& Foam::particle::cell()
+{
+    return celli_;
+}
+
+
 inline Foam::label Foam::particle::tetFace() const
 {
     return tetFacei_;
diff --git a/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H b/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H
index 63fd160ad25..8dd26867a01 100644
--- a/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H
+++ b/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H
@@ -170,7 +170,7 @@ public:
         //  either in the case/processor or case otherwise null
         virtual fileName filePath() const
         {
-            return globalFilePath();
+            return globalFilePath(type());
         }
 
         //- Return const reference to boundBox
diff --git a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.C b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.C
index 7e5e3584a8c..deb346f0816 100644
--- a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.C
+++ b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.C
@@ -286,10 +286,11 @@ bool Foam::dynamicOversetFvMesh::writeObject
 (
     IOstream::streamFormat fmt,
     IOstream::versionNumber ver,
-    IOstream::compressionType cmp
+    IOstream::compressionType cmp,
+    const bool valid
 ) const
 {
-    bool ok = dynamicMotionSolverFvMesh::writeObject(fmt, ver, cmp);
+    bool ok = dynamicMotionSolverFvMesh::writeObject(fmt, ver, cmp, valid);
 
     // For postprocessing : write cellTypes and zoneID
     {
@@ -318,7 +319,7 @@ bool Foam::dynamicOversetFvMesh::writeObject
             volTypes[cellI] = cellTypes[cellI];
         }
         volTypes.correctBoundaryConditions();
-        volTypes.writeObject(fmt, ver, cmp);
+        volTypes.writeObject(fmt, ver, cmp, valid);
     }
     {
         volScalarField volZoneID
@@ -345,7 +346,7 @@ bool Foam::dynamicOversetFvMesh::writeObject
             volZoneID[cellI] = zoneID[cellI];
         }
         volZoneID.correctBoundaryConditions();
-        volZoneID.writeObject(fmt, ver, cmp);
+        volZoneID.writeObject(fmt, ver, cmp, valid);
     }
     return ok;
 }
diff --git a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
index 2be46218a3e..0b61ed42a70 100644
--- a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
+++ b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
@@ -288,7 +288,8 @@ public:
         (
             IOstream::streamFormat,
             IOstream::versionNumber,
-            IOstream::compressionType
+            IOstream::compressionType,
+            const bool valid
         ) const;
 
         //- Debug: check halo swap is ok
diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C
index 06b6339b5b7..fd5e7dd9354 100644
--- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C
+++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -164,14 +164,15 @@ bool Foam::MeshedSurfaceIOAllocator::writeObject
 (
     IOstream::streamFormat fmt,
     IOstream::versionNumber ver,
-    IOstream::compressionType cmp
+    IOstream::compressionType cmp,
+    const bool valid
 ) const
 {
     return
     (
-        points_.writeObject(fmt, ver, cmp)
-     && faces_.writeObject(fmt, ver, cmp)
-     && zones_.writeObject(fmt, ver, cmp)
+        points_.writeObject(fmt, ver, cmp, valid)
+     && faces_.writeObject(fmt, ver, cmp, valid)
+     && zones_.writeObject(fmt, ver, cmp, valid)
     );
 }
 
diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H
index ed74141bb9d..fd4bca64467 100644
--- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H
+++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -199,7 +199,8 @@ public:
             (
                 IOstream::streamFormat,
                 IOstream::versionNumber,
-                IOstream::compressionType
+                IOstream::compressionType,
+                const bool valid
             ) const;
 
 };
diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H
index a839d79a70d..4dbe151bd07 100644
--- a/src/surfMesh/surfMesh/surfMesh.H
+++ b/src/surfMesh/surfMesh/surfMesh.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016 OpenCFD-2017 Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -307,7 +307,8 @@ public:
         (
             IOstream::streamFormat fmt,
             IOstream::versionNumber ver,
-            IOstream::compressionType cmp
+            IOstream::compressionType cmp,
+            const bool valid
         ) const;
 
         //- Write to file
diff --git a/src/surfMesh/surfMesh/surfMeshIO.C b/src/surfMesh/surfMesh/surfMeshIO.C
index ec0b9f6106e..728c5820cc0 100644
--- a/src/surfMesh/surfMesh/surfMeshIO.C
+++ b/src/surfMesh/surfMesh/surfMeshIO.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -204,10 +204,11 @@ bool Foam::surfMesh::writeObject
 (
     IOstream::streamFormat fmt,
     IOstream::versionNumber ver,
-    IOstream::compressionType cmp
+    IOstream::compressionType cmp,
+    const bool valid
 ) const
 {
-    return Allocator::writeObject(fmt, ver, cmp);
+    return Allocator::writeObject(fmt, ver, cmp, valid);
 }
 
 
-- 
GitLab