diff --git a/applications/test/alloc/Test-malloc.C b/applications/test/alloc/Test-malloc.C
index 1614987e3c298f682926f30899877763b9236267..4bfc18a20ed9447277caed16bc48a19015541a22 100644
--- a/applications/test/alloc/Test-malloc.C
+++ b/applications/test/alloc/Test-malloc.C
@@ -1,6 +1,6 @@
 #include "stream.h"
 #include <unistd.h>
-#include <stdlib.h>
+#include <cstdlib>
 
 main()
 {
diff --git a/applications/test/alloc/Test.C b/applications/test/alloc/Test.C
index 67f77ab05c8d9248b72426af0bfd8e4219afac2e..a2de8b24df83c9a29894e76c40dd92930a627797 100644
--- a/applications/test/alloc/Test.C
+++ b/applications/test/alloc/Test.C
@@ -1,4 +1,4 @@
-#include <stdlib.h>
+#include <cstdlib>
 
 class Int
 {
diff --git a/applications/test/complex/Test-complex.C b/applications/test/complex/Test-complex.C
index bc4d3d05dc736941d6822e3f5c3a5565e309fd8f..938f63fb8eb3db5d501368b56bf9b59bbb54fa9d 100644
--- a/applications/test/complex/Test-complex.C
+++ b/applications/test/complex/Test-complex.C
@@ -30,6 +30,8 @@ Description
 
 #include "argList.H"
 #include "complexFields.H"
+#include "ops.H"
+#include "ListOps.H"
 
 using namespace Foam;
 
@@ -97,9 +99,6 @@ int main(int argc, char *argv[])
     }
 
 
-    Info<< "sum = " << sum(fld1) << nl;
-    // Not yet Info<< "min = " << min(fld1) << nl;
-
     fld1 *= 10;
     Info<< "scalar multiply: " << flatOutput(fld1) << nl;
 
@@ -120,6 +119,36 @@ int main(int argc, char *argv[])
     // Info<< "pow(2) : " << pow(fld1, 2) << nl;
 
 
+    // Make some changes
+    {
+        label i = 1;
+        for (complex& c : fld1)
+        {
+            c.Re() += i;
+            c.Im() -= 10 - i;
+            ++i;
+        }
+    }
+
+    Info<< nl
+        << "field = " << fld1 << nl;
+
+    Info<< "magSqr = "
+        << ListOps::create<scalar>
+           (
+               fld1,
+               [](const complex& c) { return magSqr(c); }
+           )
+        << nl;
+
+    Info
+        << "sum = " << sum(fld1) << nl
+        << "min = " << min(fld1) << nl
+        << "max = " << max(fld1) << nl;
+
+    // MinMax fails since there is no less comparison operator
+    // Info<< "min/max = " << MinMax<complex>(fld1) << nl;
+
     Info<< "\nEnd\n" << endl;
     return 0;
 }
diff --git a/applications/test/fileNameOS/Make/files b/applications/test/fileNameOS/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..0e1be7b39452df98c2aaad67de59793c995c2171
--- /dev/null
+++ b/applications/test/fileNameOS/Make/files
@@ -0,0 +1,3 @@
+Test-fileNameOS.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-fileNameOS
diff --git a/applications/test/fileNameOS/Make/options b/applications/test/fileNameOS/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..18e6fe47afacb902cddccf82632772447704fd88
--- /dev/null
+++ b/applications/test/fileNameOS/Make/options
@@ -0,0 +1,2 @@
+/* EXE_INC = */
+/* EXE_LIBS = */
diff --git a/applications/test/fileNameOS/Test-fileNameOS.C b/applications/test/fileNameOS/Test-fileNameOS.C
new file mode 100644
index 0000000000000000000000000000000000000000..b8c7be1ac922a48affc1091eac3d6adc5bafa6ff
--- /dev/null
+++ b/applications/test/fileNameOS/Test-fileNameOS.C
@@ -0,0 +1,106 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Application
+    Test-fileNameOS
+
+Description
+    Test fileName behaviour, potential OS capabilities etc.
+
+    In the distant future could possibly replace parts with C++ filesystem
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "fileName.H"
+#include "OSspecific.H"
+#include "Switch.H"
+
+#include <csignal>
+#include <cstdlib>
+#include <iostream>
+
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+void testDirname(const std::string& rawInput)
+{
+    fileName input(fileName::validate(rawInput));
+
+    Info<< nl
+        << "input:   " << rawInput << nl
+        << "fileName:" << input << nl
+        << "   path:" << input.path()
+        << "   name:\"" << input.name() << '"'
+        << "   ext:\"" << input.ext()  << '"'
+        << "   components: " << flatOutput(input.components()) << nl;
+
+    if (rawInput.size() != input.size())
+    {
+        Info<< "   This would be Fatal with debug > 1" << nl;
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+    argList::noParallel();
+    argList::addBoolOption("no-space", "allowSpaceInFileName = false");
+    argList::addBoolOption("with-space", "set allowSpaceInFileName = true");
+
+    #include "setRootCase.H"
+
+    if (args.found("with-space"))
+    {
+        fileName::allowSpaceInFileName = true;
+    }
+
+    if (args.found("no-space"))
+    {
+        fileName::allowSpaceInFileName = false;
+
+    }
+
+
+    Info<<"fileName with spaces? : "
+        << Switch(bool(fileName::allowSpaceInFileName)) << nl << nl;
+
+
+    {
+        testDirname("/abc");
+        testDirname("/abc/with space/name");
+        testDirname("/abc/with space/more space");
+    }
+
+
+    Info<< "\nEnd\n" << endl;
+    return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/maxMem/Test-maxMem.C b/applications/test/maxMem/Test-maxMem.C
index 590c542ee95d62b6ea404ba5cc2aa62f7feb7dce..3a6c5c5c6ef16f6c2365bcc72aa3d5eb5b70a11e 100644
--- a/applications/test/maxMem/Test-maxMem.C
+++ b/applications/test/maxMem/Test-maxMem.C
@@ -1,5 +1,6 @@
 #include <iostream>
-#include <stdlib.h>
+#include <cstdlib>
+
 using namespace std;
 
 int main(int argc, char *argv[])
diff --git a/applications/test/minMax1/Test-minMax1.C b/applications/test/minMax1/Test-minMax1.C
index 26d242a8041a6fc1ae8029d200a5cff485d39850..a33b3a31342aa21b763f1546694aaa4c256b0e23 100644
--- a/applications/test/minMax1/Test-minMax1.C
+++ b/applications/test/minMax1/Test-minMax1.C
@@ -32,6 +32,7 @@ Description
 #include "HashOps.H"
 #include "ListOps.H"
 #include "scalarField.H"
+#include "complexField.H"
 #include "MinMax.H"
 #include "dimensionedScalar.H"
 
@@ -47,6 +48,19 @@ Ostream& printInfo(const MinMax<T>& range)
 }
 
 
+template<class T>
+void testUniformField(const T& val)
+{
+    constexpr label N = 10;
+
+    //    Field<T> fld(N, val);
+    List<T> fld(N, val);
+
+    Info<< "field:   " << fld << nl
+        << "min/max: " << minMaxMag(fld) << nl;
+}
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // Main program:
 
@@ -225,6 +239,15 @@ int main(int argc, char *argv[])
         Info<< "filtered: " << hashed << nl;
     }
 
+
+    // Min/max of uniform fields
+    {
+        testUniformField<scalar>(100);
+        // testUniformField<complex>(complex(100, 0));
+    }
+
+    Info<< "\nEnd\n" << nl;
+
     return 0;
 }
 
diff --git a/applications/test/readDir/Make/files b/applications/test/readDir/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..4ef8e0d2b11ac72a6aedb7be8e7ff4de04677f7f
--- /dev/null
+++ b/applications/test/readDir/Make/files
@@ -0,0 +1,3 @@
+Test-readDir.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-readDir
diff --git a/applications/test/readDir/Make/options b/applications/test/readDir/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..4e772fdf9d7bc94221d127458f9d2ca32850fe69
--- /dev/null
+++ b/applications/test/readDir/Make/options
@@ -0,0 +1,2 @@
+/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
+/* EXE_LIBS = -lfiniteVolume */
diff --git a/applications/test/readDir/Test-readDir.C b/applications/test/readDir/Test-readDir.C
new file mode 100644
index 0000000000000000000000000000000000000000..17827e8ae7403d0674dcf676263f3124c8133ed1
--- /dev/null
+++ b/applications/test/readDir/Test-readDir.C
@@ -0,0 +1,74 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    Test functionality of Foam::readDir
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "OSspecific.H"
+#include "fileNameList.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+    argList::noBanner();
+    argList::noParallel();
+    argList::addBoolOption("dir", "list directories instead of files");
+
+    #include "setRootCase.H"
+
+    fileName::Type listType = fileName::FILE;
+
+    if (args.found("dir"))
+    {
+        Info<< "Listing directories" << nl;
+        listType = fileName::DIRECTORY;
+    }
+    else
+    {
+        Info<< "Listing files" << nl;
+    }
+
+
+    {
+        Info<< nl;
+        for (const word& item : readDir(".", listType))
+        {
+            Info<< "    " << item << nl;
+        }
+    }
+
+
+    Info<< "\nEnd\n" << endl;
+
+    return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/vector/Test-vector.C b/applications/test/vector/Test-vector.C
index 497dea43d10d1eb4a8fb068f2bafda15464d9d29..fc3e430882598ce8510cc7fc1d7030279f2ef3ae 100644
--- a/applications/test/vector/Test-vector.C
+++ b/applications/test/vector/Test-vector.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -31,6 +31,7 @@ Description
 
 #include "vector.H"
 #include "IOstreams.H"
+#include <algorithm>
 
 using namespace Foam;
 
@@ -74,6 +75,18 @@ void doTest(vector& vec1, vector& vec2)
 }
 
 
+template<class VecSpace>
+void testIterator(const VecSpace& vs)
+{
+    Info<< "size: " << vs.size() << " for:";
+    for (const auto& val : vs)
+    {
+        Info<< " " << val;
+    }
+    Info<< nl;
+}
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 //  Main program:
 
@@ -89,8 +102,21 @@ int main(int argc, char *argv[])
         vector vec2(0.5, 0.51, -0.5);
 
         doTest(vec1, vec2);
+
+        testIterator(vec1);
+        testIterator(vec2);
+
+        // Use STL algorithm(s)
+
+        std::sort(vec2.begin(), vec2.end());
+        Info<< "sorted: " << vec2 << nl;
+
+        std::random_shuffle(vec2.begin(), vec2.end());
+        Info<< "shuffled: " << vec2 << nl;
     }
 
+    Info<< "\nEnd\n" << nl;
+
     return 0;
 }
 
diff --git a/applications/test/wmake1/Make/files b/applications/test/wmake1/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..3ef1ed76a9321caf262e083de6ce884c8690e5a7
--- /dev/null
+++ b/applications/test/wmake1/Make/files
@@ -0,0 +1,10 @@
+Test-wmake1.C
+
+/* #if OPENFOAM == 1812 */
+#if OPENFOAM > 1812
+newStub.C
+#else
+oldStub.C
+#endif
+
+EXE = $(FOAM_APPBIN)/Test-wmake1
diff --git a/applications/test/wmake1/Make/options b/applications/test/wmake1/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..75c7356f1c6d09cf219b7d3357cdc94afc8d45e5
--- /dev/null
+++ b/applications/test/wmake1/Make/options
@@ -0,0 +1,2 @@
+EXE_INC =
+EXE_LIBS =
diff --git a/applications/test/wmake1/Test-wmake1.C b/applications/test/wmake1/Test-wmake1.C
new file mode 100644
index 0000000000000000000000000000000000000000..614d9189fb8e2c9964383340c2c7b0f7330ae0b1
--- /dev/null
+++ b/applications/test/wmake1/Test-wmake1.C
@@ -0,0 +1,56 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Application
+    Test-wmake1
+
+Description
+    Some tests for wmake features.
+    For example, testing how robust or fragile version-dependent conditional
+    compilation works.
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+
+namespace Foam
+{
+    void printTest();
+}
+
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+int main(int argc, char *argv[])
+{
+    printTest();
+
+    Info<< "\nEnd\n" << nl;
+
+    return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/wmake1/newStub.C b/applications/test/wmake1/newStub.C
new file mode 100644
index 0000000000000000000000000000000000000000..153ccd4173f9488d2cfcac10c3ba5662d11a0e12
--- /dev/null
+++ b/applications/test/wmake1/newStub.C
@@ -0,0 +1,13 @@
+// Some test code
+
+#include "foamVersion.H"
+#include "IOstreams.H"
+
+namespace Foam
+{
+    void printTest()
+    {
+        Info<< nl;
+        foamVersion::printBuildInfo();
+    }
+}
diff --git a/applications/test/wmake1/oldStub.C b/applications/test/wmake1/oldStub.C
new file mode 100644
index 0000000000000000000000000000000000000000..136b7d80866b9b0324739b6776980045dfc9f642
--- /dev/null
+++ b/applications/test/wmake1/oldStub.C
@@ -0,0 +1,17 @@
+// Some test code
+
+#include "IOstreams.H"
+
+namespace Foam
+{
+    void printTest()
+    {
+        Info<< nl << "Using old stub" << nl;
+
+        #if OPENFOAM
+        Info<< "OPENFOAM=" << OPENFOAM << nl;
+        #else
+        Info<< "OPENFOAM is undefined" << nl;
+        #endif
+    }
+}
diff --git a/applications/utilities/miscellaneous/OSspecific/addr2line/addr2line.C b/applications/utilities/miscellaneous/OSspecific/addr2line/addr2line.C
index 928c17216a34298f8b9dd7fc2583bdabec12d17f..399f81b5078eac5d4506f1f361fe509b3ae25920 100644
--- a/applications/utilities/miscellaneous/OSspecific/addr2line/addr2line.C
+++ b/applications/utilities/miscellaneous/OSspecific/addr2line/addr2line.C
@@ -121,14 +121,14 @@ void usage()
     std::cout
         << "usage: addr2line [-e filename|--exe=filename]"
            " address [address...]\n" << std::endl;
-    ::exit(1);
+    std::exit(1);
 }
 
 
 void version()
 {
     std::cout<< "OpenFOAM addr2line emulator\n" << std::endl;
-    ::exit(0);
+    std::exit(0);
 }
 
 
diff --git a/etc/controlDict b/etc/controlDict
index 3d6c94dd8003e42d21c61b21f81244a474c89b6d..bcc4096734edb9b0b3e008bdef5b981c7cbb9d58 100644
--- a/etc/controlDict
+++ b/etc/controlDict
@@ -64,6 +64,9 @@ InfoSwitches
 
     // Allow case-supplied C++ code (#codeStream, codedFixedValue)
     allowSystemOperations   1;
+
+    // Allow space character in fileName (use with caution)
+    allowSpaceInFileName    0;
 }
 
 
diff --git a/src/OSspecific/POSIX/Make/files b/src/OSspecific/POSIX/Make/files
index 26e735cb8831b43f81edb98d9a082b05acd8c326..1f91738212e947d73bac27490465839af9aa9878 100644
--- a/src/OSspecific/POSIX/Make/files
+++ b/src/OSspecific/POSIX/Make/files
@@ -1,18 +1,20 @@
+clockTime/clockTime.C
+clockValue/clockValue.C
+cpuInfo/cpuInfo.C
+cpuTime/cpuTime.C
+memInfo/memInfo.C
+
 signals/sigFpe.C
 signals/sigSegv.C
 signals/sigInt.C
 signals/sigQuit.C
 signals/sigStopAtWriteNow.C
 signals/sigWriteNow.C
+signals/timer.C
+
 regExpPosix.C
-timer.C
 fileStat.C
 POSIX.C
-cpuTime/cpuTime.C
-clockTime/clockTime.C
-clockValue/clockValue.C
-cpuInfo/cpuInfo.C
-memInfo/memInfo.C
 
 /*
  * Note: fileMonitor assumes inotify by default. Compile with -DFOAM_USE_STAT
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index 55fa68cbe93dabd1a000a42088132eaa12055fce..57ffb644768b0c1af318083bf0993c4e7d0da79a 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2017 OpenFOAM Foundation
@@ -34,14 +34,11 @@ Description
 
 #include "OSspecific.H"
 #include "POSIX.H"
-#include "foamVersion.H"
 #include "fileName.H"
 #include "fileStat.H"
 #include "timer.H"
-#include "IFstream.H"
 #include "DynamicList.H"
 #include "CStringList.H"
-#include "SubList.H"
 #include "IOstreams.H"
 #include "Pstream.H"
 
@@ -49,7 +46,7 @@ Description
 #include <cstdlib>
 #include <cctype>
 
-#include <stdio.h>
+#include <cstdio>
 #include <unistd.h>
 #include <dirent.h>
 #include <pwd.h>
@@ -87,44 +84,6 @@ static bool cwdPreference_(Foam::debug::optimisationSwitch("cwd", 0));
 
 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
 
-// Like fileName "/" global operator, but retain any invalid characters
-static inline Foam::fileName fileNameConcat
-(
-    const std::string& a,
-    const std::string& b
-)
-{
-    if (a.size())
-    {
-        if (b.size())
-        {
-            // Two non-empty strings: can concatenate
-
-            if (a.back() == '/' || b.front() == '/')
-            {
-                return Foam::fileName(a + b, false);
-            }
-            else
-            {
-                return Foam::fileName(a + '/' + b, false);
-            }
-        }
-
-        // The second string was empty
-        return Foam::fileName(a, false);
-    }
-
-    if (b.size())
-    {
-        // The first string is empty
-        return Foam::fileName(b, false);
-    }
-
-    // Both strings are empty
-    return Foam::fileName();
-}
-
-
 // After a fork in system(), before the exec() do the following
 // - close stdin when executing in background (daemon-like)
 // - redirect stdout to stderr when infoDetailLevel == 0
@@ -145,6 +104,141 @@ static inline void redirects(const bool bg)
 }
 
 
+// * * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace POSIX
+{
+
+//- A simple directory contents iterator
+class directoryIterator
+{
+    DIR* dirptr_;
+
+    bool exists_;
+
+    bool hidden_;
+
+    std::string item_;
+
+    //- Accept file/dir name
+    inline bool accept() const
+    {
+        return
+        (
+            item_.size() && item_ != "." && item_ != ".."
+         && (hidden_ || item_[0] != '.')
+        );
+    }
+
+
+public:
+
+    // Constructors
+
+        //- Construct for dirName, optionally allowing hidden files/dirs
+        directoryIterator(const fileName& dirName, bool allowHidden = false)
+        :
+            dirptr_(nullptr),
+            exists_(false),
+            hidden_(allowHidden),
+            item_()
+        {
+            if (!dirName.empty())
+            {
+                dirptr_ = ::opendir(dirName.c_str());
+                exists_ = (dirptr_ != nullptr);
+                next(); // Move to first element
+            }
+        }
+
+
+    //- Destructor
+    ~directoryIterator()
+    {
+        close();
+    }
+
+
+    // Member Functions
+
+        //- Directory open succeeded
+        bool exists() const
+        {
+            return exists_;
+        }
+
+        //- Directory pointer is valid
+        bool good() const
+        {
+            return dirptr_;
+        }
+
+        //- Close directory
+        void close()
+        {
+            if (dirptr_)
+            {
+                ::closedir(dirptr_);
+                dirptr_ = nullptr;
+            }
+        }
+
+        //- The current item
+        const std::string& val() const
+        {
+            return item_;
+        }
+
+        //- Read next item, always ignoring "." and ".." entries.
+        //  Normally also ignore hidden files/dirs (beginning with '.')
+        //  Automatically close when there are no more items
+        bool next()
+        {
+            struct dirent *list;
+
+            while (dirptr_ && (list = ::readdir(dirptr_)) != nullptr)
+            {
+                item_ = list->d_name;
+
+                if (accept())
+                {
+                    return true;
+                }
+            }
+            close(); // No more items
+
+            return false;
+        }
+
+
+    // Member Operators
+
+        //- Same as good()
+        operator bool() const
+        {
+            return good();
+        }
+
+        //- Same as val()
+        const std::string& operator*() const
+        {
+            return val();
+        }
+
+        //- Same as next()
+        directoryIterator& operator++()
+        {
+            next();
+            return *this;
+        }
+};
+
+} // End namespace POSIX
+} // End namespace Foam
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 pid_t Foam::pid()
@@ -455,135 +549,122 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
         // Directory made OK so return true
         return true;
     }
-    else
+
+    switch (errno)
     {
-        switch (errno)
+        case EPERM:
         {
-            case EPERM:
-            {
-                FatalErrorInFunction
-                    << "The filesystem containing " << pathName
-                    << " does not support the creation of directories."
-                    << exit(FatalError);
-
-                return false;
-            }
-
-            case EEXIST:
-            {
-                // Directory already exists so simply return true
-                return true;
-            }
-
-            case EFAULT:
-            {
-                FatalErrorInFunction
-                    << "" << pathName
-                    << " points outside your accessible address space."
-                    << exit(FatalError);
-
-                return false;
-            }
-
-            case EACCES:
-            {
-                FatalErrorInFunction
-                    << "The parent directory does not allow write "
-                       "permission to the process,"<< nl
-                    << "or one of the directories in " << pathName
-                    << " did not allow search (execute) permission."
-                    << exit(FatalError);
-
-                return false;
-            }
-
-            case ENAMETOOLONG:
-            {
-                FatalErrorInFunction
-                    << "" << pathName << " is too long."
-                    << exit(FatalError);
-
-                return false;
-            }
+            FatalErrorInFunction
+                << "The filesystem containing " << pathName
+                << " does not support the creation of directories."
+                << exit(FatalError);
+            break;
+        }
 
-            case ENOENT:
-            {
-                // Part of the path does not exist so try to create it
-                if (pathName.path().size() && mkDir(pathName.path(), mode))
-                {
-                    return mkDir(pathName, mode);
-                }
-                else
-                {
-                    FatalErrorInFunction
-                        << "Couldn't create directory " << pathName
-                        << exit(FatalError);
+        case EEXIST:
+        {
+            // Directory already exists so simply return true
+            return true;
+        }
 
-                    return false;
-                }
-            }
+        case EFAULT:
+        {
+            FatalErrorInFunction
+                << "" << pathName
+                << " points outside your accessible address space."
+                << exit(FatalError);
+            break;
+        }
 
-            case ENOTDIR:
-            {
-                FatalErrorInFunction
-                    << "A component used as a directory in " << pathName
-                    << " is not, in fact, a directory."
-                    << exit(FatalError);
+        case EACCES:
+        {
+            FatalErrorInFunction
+                << "The parent directory does not allow write "
+                   "permission to the process,"<< nl
+                << " or one of the directories in " << pathName
+                << " did not allow search (execute) permission."
+                << exit(FatalError);
+            break;
+        }
 
-                return false;
-            }
+        case ENAMETOOLONG:
+        {
+            FatalErrorInFunction
+                << "" << pathName << " is too long."
+                << exit(FatalError);
+            break;
+        }
 
-            case ENOMEM:
+        case ENOENT:
+        {
+            // Part of the path does not exist so try to create it
+            if (pathName.path().size() && mkDir(pathName.path(), mode))
             {
-                FatalErrorInFunction
-                    << "Insufficient kernel memory was available to make "
-                       "directory " << pathName << '.'
-                    << exit(FatalError);
-
-                return false;
+                return mkDir(pathName, mode);
             }
 
-            case EROFS:
-            {
-                FatalErrorInFunction
-                    << "" << pathName
-                    << " refers to a file on a read-only filesystem."
-                    << exit(FatalError);
-
-                return false;
-            }
+            FatalErrorInFunction
+                << "Couldn't create directory " << pathName
+                << exit(FatalError);
+            break;
+        }
 
-            case ELOOP:
-            {
-                FatalErrorInFunction
-                    << "Too many symbolic links were encountered in resolving "
-                    << pathName << '.'
-                    << exit(FatalError);
+        case ENOTDIR:
+        {
+            FatalErrorInFunction
+                << "A component used as a directory in " << pathName
+                << " is not, in fact, a directory."
+                << exit(FatalError);
+            break;
+        }
 
-                return false;
-            }
+        case ENOMEM:
+        {
+            FatalErrorInFunction
+                << "Insufficient kernel memory was available to make directory "
+                << pathName << '.'
+                << exit(FatalError);
+            break;
+        }
 
-            case ENOSPC:
-            {
-                FatalErrorInFunction
-                    << "The device containing " << pathName
-                    << " has no room for the new directory or "
-                    << "the user's disk quota is exhausted."
-                    << exit(FatalError);
+        case EROFS:
+        {
+            FatalErrorInFunction
+                << "" << pathName
+                << " refers to a file on a read-only filesystem."
+                << exit(FatalError);
+            break;
+        }
 
-                return false;
-            }
+        case ELOOP:
+        {
+            FatalErrorInFunction
+                << "Too many symbolic links were encountered in resolving "
+                << pathName << '.'
+                << exit(FatalError);
+            break;
+        }
 
-            default:
-            {
-                FatalErrorInFunction
-                    << "Couldn't create directory " << pathName
-                    << exit(FatalError);
+        case ENOSPC:
+        {
+            FatalErrorInFunction
+                << "The device containing " << pathName
+                << " has no room for the new directory or "
+                << "the user's disk quota is exhausted."
+                << exit(FatalError);
+            break;
+        }
 
-                return false;
-            }
+        default:
+        {
+            FatalErrorInFunction
+                << "Couldn't create directory " << pathName
+                << exit(FatalError);
+            break;
         }
     }
+
+    return false;
 }
 
 
@@ -797,7 +878,7 @@ Foam::fileNameList Foam::readDir
 )
 {
     // Initial filename list size and the increment when resizing the list
-    static const int maxNnames = 100;
+    constexpr int maxNnames = 100;
 
     // Basic sanity: cannot strip '.gz' from directory names
     const bool stripgz = filtergz && (type != fileName::DIRECTORY);
@@ -805,14 +886,10 @@ Foam::fileNameList Foam::readDir
 
     fileNameList dirEntries;
 
-    // Open directory and set the structure pointer
-    // Do not attempt to open an empty directory name
-    DIR *source;
-    if
-    (
-        directory.empty()
-     || (source = ::opendir(directory.c_str())) == nullptr
-    )
+    // Iterate contents (ignores an empty directory name)
+
+    POSIX::directoryIterator dirIter(directory);
+    if (!dirIter.exists())
     {
         if (POSIX::debug)
         {
@@ -835,19 +912,12 @@ Foam::fileNameList Foam::readDir
 
     label nFailed = 0;     // Entries with invalid characters
     label nEntries = 0;    // Number of selected entries
-    dirEntries.setSize(maxNnames);
+    dirEntries.resize(maxNnames);
 
-    // Read and parse all the entries in the directory
-    for (struct dirent *list; (list = ::readdir(source)) != nullptr; /*nil*/)
+    // Process the directory entries
+    for (/*nil*/; dirIter; ++dirIter)
     {
-        const std::string item(list->d_name);
-
-        // Ignore files/directories beginning with "."
-        // These are the ".", ".." directories and any hidden files/dirs
-        if (item.empty() || item[0] == '.')
-        {
-            continue;
-        }
+        const std::string& item = *dirIter;
 
         // Validate filename without spaces, quotes, etc in the name.
         // No duplicate slashes to strip - dirent will not have them anyhow.
@@ -867,7 +937,7 @@ Foam::fileNameList Foam::readDir
             {
                 if (nEntries >= dirEntries.size())
                 {
-                    dirEntries.setSize(dirEntries.size() + maxNnames);
+                    dirEntries.resize(dirEntries.size() + maxNnames);
                 }
 
                 if (stripgz && name.hasExt(extgz))
@@ -881,10 +951,9 @@ Foam::fileNameList Foam::readDir
             }
         }
     }
-    ::closedir(source);
 
     // Finalize the length of the entries list
-    dirEntries.setSize(nEntries);
+    dirEntries.resize(nEntries);
 
     if (nFailed && POSIX::debug)
     {
@@ -934,14 +1003,14 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
             return false;
         }
 
-        // Open and check streams.
-        std::ifstream srcStream(src);
+        // Open and check streams. Enforce binary for extra safety
+        std::ifstream srcStream(src, ios_base::in | ios_base::binary);
         if (!srcStream)
         {
             return false;
         }
 
-        std::ofstream destStream(destFile);
+        std::ofstream destStream(destFile, ios_base::out | ios_base::binary);
         if (!destStream)
         {
             return false;
@@ -1141,12 +1210,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
     {
         const fileName dstName(dst/src.name());
 
-        return ::rename(src.c_str(), dstName.c_str()) == 0;
-    }
-    else
-    {
-        return ::rename(src.c_str(), dst.c_str()) == 0;
+        return (0 == ::rename(src.c_str(), dstName.c_str()));
     }
+
+    return (0 == ::rename(src.c_str(), dst.c_str()));
 }
 
 
@@ -1187,7 +1254,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
             // possible index where we have no choice
             if (!exists(dstName, false) || n == maxIndex)
             {
-                return ::rename(src.c_str(), dstName.c_str()) == 0;
+                return (0 == ::rename(src.c_str(), dstName.c_str()));
             }
         }
     }
@@ -1215,28 +1282,23 @@ bool Foam::rm(const fileName& file)
         return false;
     }
 
-    // Try returning plain file name; if not there, try with .gz
-    if (::remove(file.c_str()) == 0)
-    {
-        return true;
-    }
-    else
-    {
-        return ::remove(string(file + ".gz").c_str()) == 0;
-    }
+    // If removal of plain file name fails, try with .gz
+
+    return
+    (
+        0 == ::remove(file.c_str())
+     || 0 == ::remove((file + ".gz").c_str())
+    );
 }
 
 
 bool Foam::rmDir(const fileName& directory, const bool silent)
 {
-    // Open directory and set the structure pointer
-    // Do not attempt to open an empty directory name
-    DIR *source;
-    if
-    (
-        directory.empty()
-     || (source = ::opendir(directory.c_str())) == nullptr
-    )
+    // Iterate contents (ignores an empty directory name)
+    // Also retain hidden files/dirs for removal
+
+    POSIX::directoryIterator dirIter(directory, true);
+    if (!dirIter.exists())
     {
         if (!silent)
         {
@@ -1259,21 +1321,16 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
 
     // Process each directory entry, counting any errors encountered
     label nErrors = 0;
-    for (struct dirent *list; (list = ::readdir(source)) != nullptr; /*nil*/)
-    {
-        const std::string item(list->d_name);
 
-        // Ignore "." and ".." directories
-        if (item.empty() || item == "." || item == "..")
-        {
-            continue;
-        }
+    for (/*nil*/; dirIter; ++dirIter)
+    {
+        const std::string& item = *dirIter;
 
         // Allow invalid characters (spaces, quotes, etc),
-        // otherwise we cannot subdirs with these types of names.
+        // otherwise we cannot remove subdirs with these types of names.
         // -> const fileName path = directory/name; <-
 
-        const fileName path(fileNameConcat(directory, item));
+        const fileName path(fileName::concat(directory, item));
 
         if (path.type(false) == fileName::DIRECTORY)
         {
@@ -1314,7 +1371,6 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
     }
 
     // clean up
-    ::closedir(source);
     return !nErrors;
 }
 
diff --git a/src/OSspecific/POSIX/POSIX.H b/src/OSspecific/POSIX/POSIX.H
index 855ccffc01678476f70130ac7bb0b8cee708ee3b..9f8927936ab64bfc45b10f9a69352620a5c0d3fc 100644
--- a/src/OSspecific/POSIX/POSIX.H
+++ b/src/OSspecific/POSIX/POSIX.H
@@ -51,8 +51,8 @@ namespace POSIX
     //- Declare namespace and its debug switch
     NamespaceName("POSIX");
 
-    const label pathLengthChunk = 256;
-    const label pathLengthMax = 4096;
+    constexpr label pathLengthChunk = 256;
+    constexpr label pathLengthMax = 4096;
 }
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OSspecific/POSIX/cpuTime/cpuTime.H b/src/OSspecific/POSIX/cpuTime/cpuTime.H
index 3643d5332e571594f1d9f0ccf542cba80900fafd..d4be85e7f051b768750ee8704817bd9e2c994c09 100644
--- a/src/OSspecific/POSIX/cpuTime/cpuTime.H
+++ b/src/OSspecific/POSIX/cpuTime/cpuTime.H
@@ -41,7 +41,7 @@ SourceFiles
 #define cpuTime_H
 
 #include <string>
-#include <time.h>
+#include <ctime>
 #include <sys/times.h>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OSspecific/POSIX/fileMonitor.C b/src/OSspecific/POSIX/fileMonitor.C
index c750e1633902c7247fec1946b381f006535a00ea..f8f9a46af72a1650ae827c5d8ffac8bd9789aeb0 100644
--- a/src/OSspecific/POSIX/fileMonitor.C
+++ b/src/OSspecific/POSIX/fileMonitor.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
diff --git a/src/OSspecific/POSIX/fileMonitor.H b/src/OSspecific/POSIX/fileMonitor.H
index ed7af013651a511763299539d22d9709b3d73ed5..9ccde7f074d3cbdacf292f8db9e1af36677f73c7 100644
--- a/src/OSspecific/POSIX/fileMonitor.H
+++ b/src/OSspecific/POSIX/fileMonitor.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -54,6 +54,7 @@ SourceFiles
 namespace Foam
 {
 
+// Forward Declarations
 class fileMonitor;
 class fileMonitorWatcher;
 
@@ -63,7 +64,6 @@ class fileMonitorWatcher;
 
 class fileMonitor
 {
-
 public:
 
     // Public data types
@@ -79,6 +79,7 @@ public:
         static const Enum<fileState> fileStateNames_;
 
 private:
+
     // Private data
 
         //- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
@@ -120,7 +121,7 @@ public:
     // Constructors
 
         //- Construct null
-        fileMonitor(const bool useInotify);
+        explicit fileMonitor(const bool useInotify);
 
 
     //- Destructor
diff --git a/src/OSspecific/POSIX/fileStat.C b/src/OSspecific/POSIX/fileStat.C
index 23f97cbe9c3aab2e52acb4aa89e41cbd804fc80f..df5c8ae95f4c90969c025ff54626d2e89e06bba1 100644
--- a/src/OSspecific/POSIX/fileStat.C
+++ b/src/OSspecific/POSIX/fileStat.C
@@ -29,7 +29,6 @@ License
 #include "IOstreams.H"
 #include "timer.H"
 
-#include <signal.h>
 #include <unistd.h>
 #ifndef darwin
     #include <sys/sysmacros.h>
diff --git a/src/OSspecific/POSIX/fileStat.H b/src/OSspecific/POSIX/fileStat.H
index ca0acc21ed73827d15028589f039de249e752f74..d390834243af0222f41ade38b0a121541194d110 100644
--- a/src/OSspecific/POSIX/fileStat.H
+++ b/src/OSspecific/POSIX/fileStat.H
@@ -111,7 +111,7 @@ public:
         );
 
         //- Construct from Istream
-        fileStat(Istream& is);
+        explicit fileStat(Istream& is);
 
 
     // Member Functions
diff --git a/src/OSspecific/POSIX/signals/sigFpe.C b/src/OSspecific/POSIX/signals/sigFpe.C
index cf8b5b161e8900eef9e48f4ba0db998e85bcc65e..abc3ae4f50ac79a456c8c6dd85c59f4afd463584 100644
--- a/src/OSspecific/POSIX/signals/sigFpe.C
+++ b/src/OSspecific/POSIX/signals/sigFpe.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -33,6 +33,8 @@ License
 #include "Switch.H"
 #include "UList.H"
 
+#include <limits>
+
 #if defined(__linux__) && defined(__GNUC__)
     #ifndef __USE_GNU
         #define __USE_GNU      // To use feenableexcept()
@@ -47,7 +49,9 @@ License
     #include "feexceptErsatz.H"
 #endif
 
-#include <limits>
+// File-local functions
+#include "signalMacros.C"
+
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -57,8 +61,6 @@ bool Foam::sigFpe::switchNan_(Foam::debug::optimisationSwitch("setNaN", 0));
 bool Foam::sigFpe::sigActive_ = false;
 bool Foam::sigFpe::nanActive_ = false;
 
-struct sigaction Foam::sigFpe::oldAction_;
-
 
 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
 
@@ -123,17 +125,11 @@ void Foam::sigFpe::sigHandler(int)
 {
     #if (defined(__linux__) && defined(__GNUC__)) || defined(darwin)
 
-    // Reset old handling
-    if (sigaction(SIGFPE, &oldAction_, nullptr) < 0)
-    {
-        FatalErrorInFunction
-            << "Cannot reset SIGFPE trapping"
-            << abort(FatalError);
-    }
+    resetHandler("SIGFPE", SIGFPE);
 
     jobInfo.signalEnd();        // Update jobInfo file
     error::printStack(Perr);
-    raise(SIGFPE);              // Throw signal (to old handler)
+    ::raise(SIGFPE);            // Throw signal (to old handler)
 
     #endif  // (__linux__ && __GNUC__) || darwin
 }
@@ -203,17 +199,7 @@ void Foam::sigFpe::set(bool verbose)
           | FE_OVERFLOW
         );
 
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-
-        if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot set SIGFPE trapping"
-                << abort(FatalError);
-        }
+        setHandler("SIGFPE", SIGFPE, sigHandler);
 
         sigActive_ = true;
 
@@ -293,12 +279,7 @@ void Foam::sigFpe::unset(bool verbose)
                 << endl;
         }
 
-        if (sigaction(SIGFPE, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot reset SIGFPE trapping"
-                << abort(FatalError);
-        }
+        resetHandler("SIGFPE", SIGFPE);
 
         // Reset exception raising
         const int oldExcept = fedisableexcept
diff --git a/src/OSspecific/POSIX/signals/sigFpe.H b/src/OSspecific/POSIX/signals/sigFpe.H
index a98541d720bae009804ce3043f5454884c845da1..38dd45bf352071192f80316a95ad163484941b41 100644
--- a/src/OSspecific/POSIX/signals/sigFpe.H
+++ b/src/OSspecific/POSIX/signals/sigFpe.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -56,7 +56,6 @@ SourceFiles
 #ifndef sigFpe_H
 #define sigFpe_H
 
-#include <signal.h>
 #include "scalar.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -64,7 +63,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
+// Forward Declarations
 template<class T> class UList;
 
 /*---------------------------------------------------------------------------*\
@@ -73,7 +72,7 @@ template<class T> class UList;
 
 class sigFpe
 {
-    // Private data
+    // Private Data
 
         //- Flag that floating point trapping should be used.
         //  Can override with FOAM_SIGFPE env variable
@@ -83,20 +82,16 @@ class sigFpe
         //  Can override with FOAM_SETNAN env variable
         static bool switchNan_;
 
-        //- Flag to indicate floating point trapping is currently active
+        //- Floating point trapping currently active?
         static bool sigActive_;
 
         //- Flag to indicate mallocNan is currently active
         static bool nanActive_;
 
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
-
 
     // Private Member Functions
 
-        //- Handler for caught signals.
-        //  Ends job and prints stack
+        //- Handler for caught signals - ends job and prints stack
         static void sigHandler(int);
 
 
diff --git a/src/OSspecific/POSIX/signals/sigInt.C b/src/OSspecific/POSIX/signals/sigInt.C
index f0a997a0103c173a0be9886e1c8365a04c2f358c..c66a91408b54e4e63892edf3f200a661f4bac93f 100644
--- a/src/OSspecific/POSIX/signals/sigInt.C
+++ b/src/OSspecific/POSIX/signals/sigInt.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -30,9 +30,11 @@ License
 #include "JobInfo.H"
 #include "IOstreams.H"
 
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+// File-local functions
+#include "signalMacros.C"
+
 
-struct sigaction Foam::sigInt::oldAction_;
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 bool Foam::sigInt::sigActive_ = false;
 
@@ -41,16 +43,10 @@ bool Foam::sigInt::sigActive_ = false;
 
 void Foam::sigInt::sigHandler(int)
 {
-    // Reset old handling
-    if (sigaction(SIGINT, &oldAction_, nullptr) < 0)
-    {
-        FatalErrorInFunction
-            << "Cannot reset SIGINT trapping"
-            << abort(FatalError);
-    }
+    resetHandler("SIGINT", SIGINT);
 
     jobInfo.signalEnd();        // Update jobInfo file
-    raise(SIGINT);              // Throw signal (to old handler)
+    ::raise(SIGINT);            // Throw signal (to old handler)
 }
 
 
@@ -74,35 +70,25 @@ Foam::sigInt::~sigInt()
 
 void Foam::sigInt::set(bool)
 {
-    if (!sigActive_)
+    if (sigActive_)
     {
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-        if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot call sigInt::set() more than once"
-                << abort(FatalError);
-        }
-        sigActive_ = true;
+        return;
     }
+    sigActive_ = true;
+
+    setHandler("SIGINT", SIGINT, sigHandler);
 }
 
 
 void Foam::sigInt::unset(bool)
 {
-    if (sigActive_)
+    if (!sigActive_)
     {
-        if (sigaction(SIGINT, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot set SIGINT trapping"
-                << abort(FatalError);
-        }
-        sigActive_ = false;
+        return;
     }
+    sigActive_ = false;
+
+    resetHandler("SIGINT", SIGINT);
 }
 
 
diff --git a/src/OSspecific/POSIX/signals/sigInt.H b/src/OSspecific/POSIX/signals/sigInt.H
index b62f52754d697dd74132a1e9eda35e410c28744b..a834362980a5012e75c57e3320462a900a901872 100644
--- a/src/OSspecific/POSIX/signals/sigInt.H
+++ b/src/OSspecific/POSIX/signals/sigInt.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -47,8 +47,6 @@ SourceFiles
 #ifndef sigInt_H
 #define sigInt_H
 
-#include <signal.h>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -62,10 +60,7 @@ class sigInt
 {
     // Private data
 
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
-
-        //- Flag to indicate signal trapping is enabled
+        //- Signal trapping enabled?
         static bool sigActive_;
 
 
diff --git a/src/OSspecific/POSIX/signals/sigQuit.C b/src/OSspecific/POSIX/signals/sigQuit.C
index 0e18a1c3ec15e7bd70ca33bc71d8b3c355dbb79d..ba4b0c6064e739a0cf6b99a95d7e78892a3ddb1d 100644
--- a/src/OSspecific/POSIX/signals/sigQuit.C
+++ b/src/OSspecific/POSIX/signals/sigQuit.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -30,9 +30,11 @@ License
 #include "JobInfo.H"
 #include "IOstreams.H"
 
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+// File-local functions
+#include "signalMacros.C"
+
 
-struct sigaction Foam::sigQuit::oldAction_;
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 bool Foam::sigQuit::sigActive_ = false;
 
@@ -41,17 +43,11 @@ bool Foam::sigQuit::sigActive_ = false;
 
 void Foam::sigQuit::sigHandler(int)
 {
-    // Reset old handling
-    if (sigaction(SIGQUIT, &oldAction_, nullptr) < 0)
-    {
-        FatalErrorInFunction
-            << "Cannot reset SIGQUIT trapping"
-            << abort(FatalError);
-    }
+    resetHandler("SIGQUIT", SIGQUIT);
 
     jobInfo.signalEnd();        // Update jobInfo file
     error::printStack(Perr);
-    raise(SIGQUIT);             // Throw signal (to old handler)
+    ::raise(SIGQUIT);           // Throw signal (to old handler)
 }
 
 
@@ -75,35 +71,25 @@ Foam::sigQuit::~sigQuit()
 
 void Foam::sigQuit::set(bool)
 {
-    if (!sigActive_)
+    if (sigActive_)
     {
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-        if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot call more than once"
-                << abort(FatalError);
-        }
-        sigActive_ = true;
+        return;
     }
+    sigActive_ = true;
+
+    setHandler("SIGQUIT", SIGQUIT, sigHandler);
 }
 
 
 void Foam::sigQuit::unset(bool)
 {
-    if (sigActive_)
+    if (!sigActive_)
     {
-        if (sigaction(SIGQUIT, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot unset SIGQUIT trapping"
-                << abort(FatalError);
-        }
-        sigActive_ = false;
+        return;
     }
+    sigActive_ = false;
+
+    resetHandler("SIGQUIT", SIGQUIT);
 }
 
 
diff --git a/src/OSspecific/POSIX/signals/sigQuit.H b/src/OSspecific/POSIX/signals/sigQuit.H
index 184786789170f5b0ecd36d16771ab7c33a3049a8..a12940c5009174773f5210e8a40d71385618a835 100644
--- a/src/OSspecific/POSIX/signals/sigQuit.H
+++ b/src/OSspecific/POSIX/signals/sigQuit.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -46,8 +46,6 @@ SourceFiles
 #ifndef sigQuit_H
 #define sigQuit_H
 
-#include <signal.h>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -59,12 +57,9 @@ namespace Foam
 
 class sigQuit
 {
-    // Private data
-
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
+    // Private Data
 
-        //- Flag to indicate signal trapping is enabled
+        //- Signal trapping enabled?
         static bool sigActive_;
 
 
@@ -86,7 +81,7 @@ public:
     ~sigQuit();
 
 
-    // Member functions
+    // Member Functions
 
         //- Activate SIGQUIT signal handler
         static void set(bool verbose=false);
diff --git a/src/OSspecific/POSIX/signals/sigSegv.C b/src/OSspecific/POSIX/signals/sigSegv.C
index 06ca476bc63536b9352ea874366b1fd3d24617e4..d3e5593df0b3be60abe5d3262ad24402260438d9 100644
--- a/src/OSspecific/POSIX/signals/sigSegv.C
+++ b/src/OSspecific/POSIX/signals/sigSegv.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -30,9 +30,11 @@ License
 #include "JobInfo.H"
 #include "IOstreams.H"
 
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+// File-local functions
+#include "signalMacros.C"
+
 
-struct sigaction Foam::sigSegv::oldAction_;
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 bool Foam::sigSegv::sigActive_ = false;
 
@@ -41,17 +43,11 @@ bool Foam::sigSegv::sigActive_ = false;
 
 void Foam::sigSegv::sigHandler(int)
 {
-    // Reset old handling
-    if (sigaction(SIGSEGV, &oldAction_, nullptr) < 0)
-    {
-        FatalErrorInFunction
-            << "Cannot reset SIGSEGV trapping"
-            << abort(FatalError);
-    }
+    resetHandler("SIGSEGV", SIGSEGV);
 
     jobInfo.signalEnd();        // Update jobInfo file
     error::printStack(Perr);
-    raise(SIGSEGV);             // Throw signal (to old handler)
+    ::raise(SIGSEGV);           // Throw signal (to old handler)
 }
 
 
@@ -75,35 +71,25 @@ Foam::sigSegv::~sigSegv()
 
 void Foam::sigSegv::set(bool)
 {
-    if (!sigActive_)
+    if (sigActive_)
     {
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-        if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot call more than once"
-                << abort(FatalError);
-        }
-        sigActive_ = true;
+        return;
     }
+    sigActive_ = true;
+
+    setHandler("SIGSEGV", SIGSEGV, sigHandler);
 }
 
 
 void Foam::sigSegv::unset(bool)
 {
-    if (sigActive_)
+    if (!sigActive_)
     {
-        if (sigaction(SIGSEGV, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot unset SIGSEGV trapping"
-                << abort(FatalError);
-        }
-        sigActive_ = false;
+        return;
     }
+    sigActive_ = false;
+
+    resetHandler("SIGSEGV", SIGSEGV);
 }
 
 
diff --git a/src/OSspecific/POSIX/signals/sigSegv.H b/src/OSspecific/POSIX/signals/sigSegv.H
index a5f0ae7e85f89f3056f68d0feadcb87828019e13..bbed12192d3df232449b9d73dc527f399993375b 100644
--- a/src/OSspecific/POSIX/signals/sigSegv.H
+++ b/src/OSspecific/POSIX/signals/sigSegv.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -46,8 +46,6 @@ SourceFiles
 #ifndef sigSegv_H
 #define sigSegv_H
 
-#include <signal.h>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -59,12 +57,9 @@ namespace Foam
 
 class sigSegv
 {
-    // Private data
-
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
+    // Private Data
 
-        //- Flag to indicate signal trapping is enabled
+        //- Signal trapping enabled?
         static bool sigActive_;
 
 
diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C
index b11ba2cf45c435e5a92c7e872c9d2c92df8881ce..6d55136a2d1dbbf1cf4cc019afd7c5531e0ed72e 100644
--- a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C
+++ b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -25,12 +25,17 @@ License
 
 \*---------------------------------------------------------------------------*/
 
+#include "sigWriteNow.H"
 #include "sigStopAtWriteNow.H"
 #include "error.H"
 #include "JobInfo.H"
 #include "IOstreams.H"
 #include "Time.H"
 
+// File-local functions
+#include "signalMacros.C"
+
+
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 // Signal number to catch
@@ -39,21 +44,19 @@ int Foam::sigStopAtWriteNow::signal_
     Foam::debug::optimisationSwitch("stopAtWriteNowSignal", -1)
 );
 
-Foam::Time const* Foam::sigStopAtWriteNow::runTimePtr_ = nullptr;
+// Pointer to Time (file-local variable)
+static Foam::Time const* runTimePtr_ = nullptr;
 
-struct sigaction Foam::sigStopAtWriteNow::oldAction_;
 
+// * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 // Register re-reader
-class addstopAtWriteNowSignalToOpt
+struct addstopAtWriteNowSignalToOpt
 :
     public ::Foam::simpleRegIOobject
 {
-
-public:
-
     addstopAtWriteNowSignalToOpt(const char* name)
     :
         ::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
@@ -85,15 +88,9 @@ addstopAtWriteNowSignalToOpt addstopAtWriteNowSignalToOpt_
 
 void Foam::sigStopAtWriteNow::sigHandler(int)
 {
-    // Reset old handling
-    if (sigaction(signal_, &oldAction_, nullptr) < 0)
-    {
-        FatalErrorInFunction
-            << "Cannot reset " << signal_ << " trapping"
-            << abort(FatalError);
-    }
+    resetHandler("stopAtWriteNow", signal_);
 
-    jobInfo.signalEnd();        // Update jobInfo file
+    jobInfo.signalEnd(); // Update jobInfo file
 
     if (runTimePtr_)
     {
@@ -113,7 +110,7 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow()
 
 Foam::sigStopAtWriteNow::sigStopAtWriteNow(const Time& runTime, bool verbose)
 {
-    runTimePtr_ = &runTime;      // Store runTime
+    runTimePtr_ = &runTime; // Store runTime
     set(verbose);
 }
 
@@ -122,60 +119,54 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow(const Time& runTime, bool verbose)
 
 Foam::sigStopAtWriteNow::~sigStopAtWriteNow()
 {
-    // Reset old handling
-    if (signal_ > 0)
+    if (!active())
     {
-        if (sigaction(signal_, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot reset " << signal_ << " trapping"
-                << abort(FatalError);
-        }
+        return;
     }
+
+    resetHandler("stopAtWriteNow", signal_);
 }
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
+bool Foam::sigStopAtWriteNow::active()
+{
+    return signal_ > 0;
+}
+
+
+int Foam::sigStopAtWriteNow::signalNumber()
+{
+    return signal_;
+}
+
+
 void Foam::sigStopAtWriteNow::set(bool verbose)
 {
-    if (signal_ > 0)
+    if (!active())
     {
-        // Check that the signal is different from the writeNowSignal
-        if (sigWriteNow::signal_ == signal_)
-        {
-            FatalErrorInFunction
-                << "stopAtWriteNowSignal : " << signal_
-                << " cannot be the same as the writeNowSignal."
-                << " Please change this in the etc/controlDict."
-                << exit(FatalError);
-        }
-
-
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-        if (sigaction(signal_, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot set " << signal_ << " trapping"
-                << abort(FatalError);
-        }
-
-        if (verbose)
-        {
-            Info<< "sigStopAtWriteNow :"
-                << " Enabling writing and stopping upon signal " << signal_
-                << endl;
-        }
+        return;
     }
-}
 
+    // Check that the signal is different from the writeNowSignal
+    if (sigWriteNow::signalNumber() == signal_)
+    {
+        FatalErrorInFunction
+            << "stopAtWriteNowSignal : " << signal_
+            << " cannot be the same as the writeNowSignal."
+            << " Please change this in the etc/controlDict."
+            << exit(FatalError);
+    }
 
-bool Foam::sigStopAtWriteNow::active() const
-{
-    return signal_ > 0;
+    if (verbose)
+    {
+        Info<< "sigStopAtWriteNow :"
+            << " Enabling writing and stopping upon signal " << signal_
+            << endl;
+    }
+
+    setHandler("stopAtWriteNow", signal_, sigHandler);
 }
 
 
diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H
index fb08a219fd500c54225ddcc3bae5f9a69817033f..0464a6d52a41dac277e23cbf939f7cc91e7a1995 100644
--- a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H
+++ b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -27,10 +27,8 @@ Class
     Foam::sigStopAtWriteNow
 
 Description
-    Signal handler for interupt defined by
-        OptimisationSwitches::stopAtWriteNowSignal
-
-    Write and stop the job.
+    Signal handler to write and stop the job.
+    The interrupt is defined by OptimisationSwitches::stopAtWriteNowSignal
 
 SourceFiles
     sigStopAtWriteNow.C
@@ -40,32 +38,25 @@ SourceFiles
 #ifndef sigStopAtWriteNow_H
 #define sigStopAtWriteNow_H
 
-#include <signal.h>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
+// Forward Declarations
 class Time;
 
 /*---------------------------------------------------------------------------*\
-                           Class sigStopAtWriteNow Declaration
+                      Class sigStopAtWriteNow Declaration
 \*---------------------------------------------------------------------------*/
 
 class sigStopAtWriteNow
 {
-    // Private data
+    // Private Data
 
-        //- Number of signal to use
+        //- Signal number to use
         static int signal_;
 
-        //- Pointer to Time
-        static Time const* runTimePtr_;
-
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
-
 
     // Private Member Functions
 
@@ -92,13 +83,16 @@ public:
     ~sigStopAtWriteNow();
 
 
-    // Member functions
-
-        //- (re)set signal catcher
-        static void set(bool verbose=false);
+    // Member Functions
 
         //- Is active?
-        bool active() const;
+        static bool active();
+
+        //- Signal number being used
+        static int signalNumber();
+
+        //- Set/reset signal handler
+        static void set(bool verbose=false);
 };
 
 
diff --git a/src/OSspecific/POSIX/signals/sigWriteNow.C b/src/OSspecific/POSIX/signals/sigWriteNow.C
index b47fb07c8002a1e77dac6d03f13c93f3afe31c74..71d309adc5d562a16a99717858cbe1d4afab15c1 100644
--- a/src/OSspecific/POSIX/signals/sigWriteNow.C
+++ b/src/OSspecific/POSIX/signals/sigWriteNow.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -31,6 +31,10 @@ License
 #include "IOstreams.H"
 #include "Time.H"
 
+// File-local functions
+#include "signalMacros.C"
+
+
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 // Signal number to catch
@@ -39,22 +43,20 @@ int Foam::sigWriteNow::signal_
     Foam::debug::optimisationSwitch("writeNowSignal", -1)
 );
 
-Foam::Time* Foam::sigWriteNow::runTimePtr_ = nullptr;
+// Pointer to Time (file-local variable)
+static Foam::Time* runTimePtr_ = nullptr;
 
-struct sigaction Foam::sigWriteNow::oldAction_;
 
+// * * * * * * * * * * * * * * * Local Classes * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
 // Register re-reader
-class addwriteNowSignalToOpt
+struct addwriteNowSignalToOpt
 :
     public ::Foam::simpleRegIOobject
 {
-
-public:
-
     addwriteNowSignalToOpt(const char* name)
     :
         ::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
@@ -100,7 +102,7 @@ Foam::sigWriteNow::sigWriteNow()
 
 Foam::sigWriteNow::sigWriteNow(Time& runTime, bool verbose)
 {
-    runTimePtr_ = &runTime;     // Store runTime
+    runTimePtr_ = &runTime; // Store runTime
     set(verbose);
 }
 
@@ -109,49 +111,43 @@ Foam::sigWriteNow::sigWriteNow(Time& runTime, bool verbose)
 
 Foam::sigWriteNow::~sigWriteNow()
 {
-    // Reset old handling
-    if (signal_ > 0)
+    if (!active())
     {
-        if (sigaction(signal_, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot reset " << signal_ << " trapping"
-                << abort(FatalError);
-        }
+        return;
     }
+
+    resetHandler("writeNow", signal_);
 }
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
+bool Foam::sigWriteNow::active()
+{
+    return signal_ > 0;
+}
+
+
+int Foam::sigWriteNow::signalNumber()
+{
+    return signal_;
+}
+
+
 void Foam::sigWriteNow::set(bool verbose)
 {
-    if (signal_ >= 0)
+    if (!active())
     {
-        struct sigaction newAction;
-        newAction.sa_handler = sigHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-        if (sigaction(signal_, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "Cannot set " << signal_ << " trapping"
-                << abort(FatalError);
-        }
-
-        if (verbose)
-        {
-            Info<< "sigWriteNow :"
-                << " Enabling writing upon signal " << signal_
-                << endl;
-        }
+        return;
     }
-}
 
+    if (verbose)
+    {
+        Info<< "sigWriteNow :"
+            << " Enabling writing upon signal " << signal_ << nl;
+    }
 
-bool Foam::sigWriteNow::active() const
-{
-    return signal_ > 0;
+    setHandler("writeNow", signal_, sigHandler);
 }
 
 
diff --git a/src/OSspecific/POSIX/signals/sigWriteNow.H b/src/OSspecific/POSIX/signals/sigWriteNow.H
index eec6bc5cc7e32c851d8d2407c8e7b067d46b7a06..8ba2cedc89f0122e67d74e3e0fd6b810967de8aa 100644
--- a/src/OSspecific/POSIX/signals/sigWriteNow.H
+++ b/src/OSspecific/POSIX/signals/sigWriteNow.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -27,9 +27,8 @@ Class
     Foam::sigWriteNow
 
 Description
-    Signal handler for interupt defined by OptimisationSwitches::writeNowSignal
-
-    Write once and continue.
+    Signal handler to write once and continue.
+    The interrupt is defined by OptimisationSwitches::writeNowSignal
 
 SourceFiles
     sigWriteNow.C
@@ -39,32 +38,25 @@ SourceFiles
 #ifndef sigWriteNow_H
 #define sigWriteNow_H
 
-#include <signal.h>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
+// Forward Declarations
 class Time;
 
 /*---------------------------------------------------------------------------*\
-                           Class sigWriteNow Declaration
+                         Class sigWriteNow Declaration
 \*---------------------------------------------------------------------------*/
 
 class sigWriteNow
 {
-    // Private data
+    // Private Data
 
-        //- Number of signal to use
+        //- Signal number to use
         static int signal_;
 
-        //- Pointer to Time
-        static Time* runTimePtr_;
-
-        //- Saved old signal trapping setting
-        static struct sigaction oldAction_;
-
 
     // Private Member Functions
 
@@ -74,8 +66,6 @@ class sigWriteNow
 
 public:
 
-    friend class sigStopAtWriteNow;
-
     //- Allow setter access to signal_
     friend class addwriteNowSignalToOpt;
 
@@ -96,9 +86,12 @@ public:
     // Member Functions
 
         //- Is active?
-        bool active() const;
+        static bool active();
+
+        //- The signal number being used
+        static int signalNumber();
 
-        //- (re)set signal catcher
+        //- Set/reset signal handler
         static void set(bool verbose=false);
 
 };
diff --git a/src/OSspecific/POSIX/signals/signalMacros.C b/src/OSspecific/POSIX/signals/signalMacros.C
new file mode 100644
index 0000000000000000000000000000000000000000..f1982073ba6815542b5c636a6ba23d2f19d03880
--- /dev/null
+++ b/src/OSspecific/POSIX/signals/signalMacros.C
@@ -0,0 +1,74 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    File-local code for setting/resetting signal handlers.
+
+SourceFiles
+    signalMacros.C
+
+\*---------------------------------------------------------------------------*/
+
+#include "error.H"
+#include <csignal>
+
+// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// Saved old signal trapping setting (file-local variable)
+static struct sigaction oldAction_;
+
+
+static void resetHandler(const char *what, int sigNum)
+{
+    if (sigaction(sigNum, &oldAction_, nullptr) < 0)
+    {
+        FatalError
+            << "Cannot unset " << what << " signal (" << sigNum
+            << ") trapping" << endl
+            << abort(FatalError);
+    }
+}
+
+
+static void setHandler(const char *what, int sigNum, void (*handler)(int))
+{
+    struct sigaction newAction;
+    newAction.sa_handler = handler;
+    newAction.sa_flags = SA_NODEFER;
+    sigemptyset(&newAction.sa_mask);
+    if (sigaction(sigNum, &newAction, &oldAction_) < 0)
+    {
+        FatalError
+            << "Could not set " << what << " signal (" << sigNum
+            << ") trapping" << endl
+            << abort(FatalError);
+    }
+}
+
+} // End namespace Foam
+
+
+// ************************************************************************* //
diff --git a/src/OSspecific/POSIX/signals/timer.C b/src/OSspecific/POSIX/signals/timer.C
new file mode 100644
index 0000000000000000000000000000000000000000..182eaa2077ac633a626c3c0be31d16998f62f407
--- /dev/null
+++ b/src/OSspecific/POSIX/signals/timer.C
@@ -0,0 +1,114 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+                            | Copyright (C) 2011-2016 OpenFOAM Foundation
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "error.H"
+#include "timer.H"
+
+#include <unistd.h>
+
+// File-local functions
+#include "signalMacros.C"
+
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    defineTypeNameAndDebug(timer, 0);
+}
+
+jmp_buf Foam::timer::envAlarm;
+
+unsigned int Foam::timer::oldTimeOut_ = 0;
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::timer::sigHandler(int)
+{
+    DebugInFunction<< "Timed out. Jumping." << endl;
+
+    longjmp(envAlarm, 1);
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::timer::timer(unsigned int seconds)
+:
+    timeOut_(seconds)
+{
+    if (!timeOut_)
+    {
+        return;
+    }
+
+    // Singleton since handler is static function
+    if (oldTimeOut_)
+    {
+        FatalErrorInFunction
+            << "timer already used."
+            << abort(FatalError);
+    }
+
+    // Set alarm signal handler
+    // - do not block any signals while in it
+    // - clear list of signals to mask
+
+    setHandler("SIGALRM", SIGALRM, sigHandler);
+
+    // Set alarm timer
+    oldTimeOut_ = ::alarm(timeOut_);
+
+    DebugInFunction
+        << "Installing timeout " << int(timeOut_) << " seconds"
+        << " (overriding old timeout " << int(oldTimeOut_) << ")." << endl;
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::timer::~timer()
+{
+    if (!timeOut_)
+    {
+        return;
+    }
+
+    DebugInFunction
+        << "timeOut=" << int(timeOut_)
+        << " : resetting timeOut to " << int(oldTimeOut_) << endl;
+
+    // Reset alarm timer
+    ::alarm(oldTimeOut_);
+    oldTimeOut_ = 0;
+
+    resetHandler("SIGALRM", SIGALRM);
+}
+
+
+// ************************************************************************* //
diff --git a/src/OSspecific/POSIX/timer.H b/src/OSspecific/POSIX/signals/timer.H
similarity index 84%
rename from src/OSspecific/POSIX/timer.H
rename to src/OSspecific/POSIX/signals/timer.H
index 390eeb0d565be94a027a97eeb0e2de718ad24c02..4af28d6007a4d8598b9dde9bb93e91defdd28741 100644
--- a/src/OSspecific/POSIX/timer.H
+++ b/src/OSspecific/POSIX/signals/timer.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -46,14 +46,15 @@ Description
     Constructor set signal handler on sigalarm and alarm(). Destructor
     clears these.
 
-    timedOut is macro because setjmp can't be in member function of timer.
-    ?something to do with stack frames.
-
 Warning
     The setjmp restores complete register state so including local vars
     held in regs. So if in blocking part something gets calced in a stack
     based variable make sure it is declared 'volatile'.
 
+Note
+    timedOut is macro because setjmp can't be in member function of timer.
+    ?something to do with stack frames.
+
 SourceFiles
     timer.C
 
@@ -63,16 +64,14 @@ SourceFiles
 #define timer_H
 
 #include "className.H"
-
-#include <signal.h>
-#include <setjmp.h>
+#include <csetjmp>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-//- Check it a timeout has occured
+//- Check if timeout has occurred
 //  keep setjmp in same stack frame so no function calls
 #define timedOut(x) \
-    (((x).newTimeOut_ > 0) ? setjmp(Foam::timer::envAlarm) : false)
+    ((x).timeOut_ ? setjmp(Foam::timer::envAlarm) : false)
 
 namespace Foam
 {
@@ -83,10 +82,7 @@ namespace Foam
 
 class timer
 {
-    // Private data
-
-        //- Old signal masks
-        static struct sigaction oldAction_;
+    // Private Data
 
         //- Old alarm() value
         static unsigned int oldTimeOut_;
@@ -95,18 +91,18 @@ class timer
     // Private Member Functions
 
         //- Alarm handler
-        static void signalHandler(int);
+        static void sigHandler(int);
 
 
 public:
 
-    // Public data
+    // Public Data
 
         //- Declare name of the class and its debug switch
         ClassName("timer");
 
-        //- Current time out value. Needed by macro timedOut
-        unsigned int newTimeOut_;
+        //- The time-out value (seconds). Needed by macro timedOut
+        unsigned int timeOut_;
 
         //- State for setjmp. Needed by macro timedOut
         static jmp_buf envAlarm;
@@ -114,12 +110,11 @@ public:
 
     // Constructors
 
-        //- Construct from components.
-        //  newTimeOut=0 makes it do nothing.
-        timer(const unsigned int newTimeOut);
+        //- Construct with specified time-out, a value of 0 makes it a no-op.
+        explicit timer(unsigned int seconds);
 
 
-    //- Destructor
+    //- Destructor. Restores the alarm and signal handler as required.
     ~timer();
 };
 
diff --git a/src/OSspecific/POSIX/timer.C b/src/OSspecific/POSIX/timer.C
deleted file mode 100644
index e43047abde37199742cef2b7a2ccf3ee63876708..0000000000000000000000000000000000000000
--- a/src/OSspecific/POSIX/timer.C
+++ /dev/null
@@ -1,133 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           |
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-                            | Copyright (C) 2011-2016 OpenFOAM Foundation
--------------------------------------------------------------------------------
-License
-    This file is part of OpenFOAM.
-
-    OpenFOAM is free software: you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-    for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#include <unistd.h>
-
-#include "error.H"
-#include "timer.H"
-
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
-
-namespace Foam
-{
-defineTypeNameAndDebug(timer, 0);
-
-jmp_buf timer::envAlarm;
-
-struct sigaction timer::oldAction_;
-
-unsigned int timer::oldTimeOut_ = 0;
-}
-
-
-// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
-
-void Foam::timer::signalHandler(int)
-{
-    if (debug)
-    {
-        InfoInFunction<< "Timed out. Jumping."
-            << endl;
-    }
-    longjmp(envAlarm, 1);
-}
-
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::timer::timer(const unsigned int newTimeOut)
-:
-    newTimeOut_(newTimeOut)
-{
-
-    if (newTimeOut > 0)
-    {
-        // Is singleton since handler is static function
-        if (oldTimeOut_ != 0)
-        {
-            FatalErrorInFunction
-                << "timer already used."
-                << abort(FatalError);
-        }
-
-        // Install alarm signal handler:
-        // - do not block any signals while in it
-        // - clear list of signals to mask
-        struct sigaction newAction;
-        newAction.sa_handler = timer::signalHandler;
-        newAction.sa_flags = SA_NODEFER;
-        sigemptyset(&newAction.sa_mask);
-
-        if (sigaction(SIGALRM, &newAction, &oldAction_) < 0)
-        {
-            FatalErrorInFunction
-                << "sigaction(SIGALRM) error"
-                << abort(FatalError);
-        }
-
-        oldTimeOut_ = ::alarm(newTimeOut);
-
-        if (debug)
-        {
-            InfoInFunction
-                << "Installing timeout " << int(newTimeOut_)
-                << " seconds"
-                << " (overriding old timeout " << int(oldTimeOut_)
-                << ")." << endl;
-        }
-    }
-}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::timer::~timer()
-{
-    if (newTimeOut_ > 0)
-    {
-        if (debug)
-        {
-            InfoInFunction
-                << "timeOut=" << int(newTimeOut_)
-                << " : resetting timeOut to " << int(oldTimeOut_) << endl;
-        }
-
-        // Reset timer
-        ::alarm(oldTimeOut_);
-        oldTimeOut_ = 0;
-
-        // Restore signal handler
-        if (sigaction(SIGALRM, &oldAction_, nullptr) < 0)
-        {
-            FatalErrorInFunction
-                << "sigaction(SIGALRM) error"
-                << abort(FatalError);
-        }
-    }
-}
-
-
-// ************************************************************************* //
diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C
index a4908d9c7ac1f446410f22887da4e8f3906340aa..00562483a9d6ad3c9082b9bd4b4f897c1a0690a7 100644
--- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C
+++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -52,7 +52,9 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
         }
     }
 
-    allocatedPtr_ = new std::ifstream(pathname);
+    const std::ios_base::openmode mode(std::ios_base::in|std::ios_base::binary);
+
+    allocatedPtr_ = new std::ifstream(pathname, mode);
 
     // If the file is compressed, decompress it before reading.
     if (!allocatedPtr_->good() && isFile(pathname + ".gz", false))
@@ -63,7 +65,7 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
         }
 
         delete allocatedPtr_;
-        allocatedPtr_ = new igzstream((pathname + ".gz").c_str());
+        allocatedPtr_ = new igzstream((pathname + ".gz").c_str(), mode);
 
         if (allocatedPtr_->good())
         {
diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C
index 709b0f07d3d45b5b4e1a12cfde35c413a575b182..027b7c82e22f7355d2141a84c58c1efa911e3756 100644
--- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C
+++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2017 OpenFOAM Foundation
@@ -55,7 +55,7 @@ Foam::Detail::OFstreamAllocator::OFstreamAllocator
         }
     }
 
-    std::ios_base::openmode mode(std::ios_base::out);
+    std::ios_base::openmode mode(std::ios_base::out|std::ios_base::binary);
     if (append)
     {
         mode |= std::ios_base::app;
diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C
index 37ba5fe66746f1d367f8426f19986763e81abca1..775d90ea5974dfa24ac1a26253ead15859cf3305 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.C
+++ b/src/OpenFOAM/db/dictionary/dictionary.C
@@ -272,7 +272,7 @@ void Foam::dictionary::checkITstream
                 << " at line " << is.lineNumber() << '.' << nl
                 << std::endl;
 
-            ::exit(1);
+            std::exit(1);
         }
     }
     else if (!is.size())
@@ -305,7 +305,7 @@ void Foam::dictionary::checkITstream
                 << " at line " << is.lineNumber() << '.' << nl
                 << std::endl;
 
-            ::exit(1);
+            std::exit(1);
         }
     }
 }
diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C
index eccfa396c7656a942630e0792ee06db02be8b492..9bd55a3e050587d76bf1417993e63ea0faa1546a 100644
--- a/src/OpenFOAM/db/dictionary/entry/entry.C
+++ b/src/OpenFOAM/db/dictionary/entry/entry.C
@@ -116,7 +116,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
                 << " at line " << is.lineNumber() << '.' << nl
                 << std::endl;
 
-            ::exit(1);
+            std::exit(1);
         }
     }
     else if (!is.size())
@@ -149,7 +149,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
                 << " at line " << is.lineNumber() << '.' << nl
                 << std::endl;
 
-            ::exit(1);
+            std::exit(1);
         }
     }
 }
diff --git a/src/OpenFOAM/db/error/IOerror.C b/src/OpenFOAM/db/error/IOerror.C
index 51b007342b55f5d3ea3de5f2103e14b19ca38636..d3b51b3e7175bb9052a651f07be9a7e6e6ffa808 100644
--- a/src/OpenFOAM/db/error/IOerror.C
+++ b/src/OpenFOAM/db/error/IOerror.C
@@ -153,7 +153,7 @@ void Foam::IOerror::SafeFatalIOError
             << "    in file " << sourceFileName
             << " at line " << sourceFileLineNumber << '.'
             << std::endl;
-        ::exit(1);
+        std::exit(1);
     }
 }
 
@@ -210,7 +210,7 @@ void Foam::IOerror::exit(const int)
         {
             Perr<< endl << *this << endl
                 << "\nFOAM exiting\n" << endl;
-            ::exit(1);
+            std::exit(1);
         }
     }
 }
@@ -229,7 +229,7 @@ void Foam::IOerror::abort()
         Perr<< endl << *this << endl
             << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
         printStack(Perr);
-        ::abort();
+        std::abort();
     }
 
     if (Pstream::parRun())
@@ -256,7 +256,7 @@ void Foam::IOerror::abort()
             Perr<< endl << *this << endl
                 << "\nFOAM aborting\n" << endl;
             printStack(Perr);
-            ::abort();
+            std::abort();
         }
     }
 }
diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C
index 8140ed6f9cf7b34df6d3bae6380cb5f18fe53c2d..c143fcf5f14d6de000f34d3b2841c9a76e65a849 100644
--- a/src/OpenFOAM/db/error/error.C
+++ b/src/OpenFOAM/db/error/error.C
@@ -244,7 +244,7 @@ void Foam::error::exit(const int errNo)
     {
         Perr<< endl << *this << endl
             << "\nFOAM exiting\n" << endl;
-        ::exit(errNo);
+        std::exit(errNo);
     }
 }
 
@@ -262,7 +262,7 @@ void Foam::error::abort()
         Perr<< endl << *this << endl
             << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
         printStack(Perr);
-        ::abort();
+        std::abort();
     }
 
     if (throwExceptions_)
@@ -287,7 +287,7 @@ void Foam::error::abort()
         Perr<< endl << *this << endl
             << "\nFOAM aborting\n" << endl;
         printStack(Perr);
-        ::abort();
+        std::abort();
     }
 }
 
diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
index a95b8d1b2b2bdd1f23fc66543ce6a27ab6f7ce9c..bdb0128cebc7c47a3f1a19a2ec0dace05f08bf63 100644
--- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
+++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
@@ -887,7 +887,7 @@ bool Foam::functionObjectList::read()
                 catch (const Foam::IOerror& ioErr)
                 {
                     Info<< ioErr << nl << endl;
-                    ::exit(1);
+                    std::exit(1);
                 }
                 catch (const Foam::error& err)
                 {
diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C
index 1e4abbb1724562c1017248bed1e872f567acea52..f9daf29dc8b9702c37222aaba57d986ab15a4b18 100644
--- a/src/OpenFOAM/global/argList/argList.C
+++ b/src/OpenFOAM/global/argList/argList.C
@@ -648,7 +648,7 @@ void Foam::argList::setCasePaths()
 
     if (optIter.found())
     {
-        caseDir = optIter.val();
+        caseDir = fileName::validate(optIter.val());
         caseDir.clean();
 
         if (caseDir.empty() || caseDir == ".")
@@ -906,7 +906,7 @@ void Foam::argList::parse
 
         if (quickExit)
         {
-            ::exit(0);
+            std::exit(0);
         }
     }
 
diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C
index a22251d9ce5f8d551fa3a3f580ec9bf13842be9b..bdbc0ce8c40ac9d91fa1996d5075cdb0e2d31938 100644
--- a/src/OpenFOAM/global/debug/debug.C
+++ b/src/OpenFOAM/global/debug/debug.C
@@ -147,7 +147,7 @@ Foam::dictionary& Foam::debug::switchSet
                 << controlDict().name().c_str()
                 << std::endl << std::endl;
 
-            ::exit(1);
+            std::exit(1);
         }
 
         subDictPtr = &(eptr->dict());
diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.C b/src/OpenFOAM/global/etcFiles/etcFiles.C
index de3c6f83c7f9adf8c9b8f76cd5396299a2a2608b..3e04dbe70fa17393bbd442378d829c74eefd73d2 100644
--- a/src/OpenFOAM/global/etcFiles/etcFiles.C
+++ b/src/OpenFOAM/global/etcFiles/etcFiles.C
@@ -82,7 +82,7 @@ static inline void errorMandatoryNotFound
         << locationToString(location) << ")\n    '"
         << name << "'\n"
         << std::endl;
-    ::exit(1);
+    std::exit(1);
 }
 
 
diff --git a/src/OpenFOAM/global/new.C b/src/OpenFOAM/global/new.C
index ac7f38f0774c937727c0c072aedf43d7b165139c..d98ec3d2fd8214b2f935533e38f4f1b2f1b96893 100644
--- a/src/OpenFOAM/global/new.C
+++ b/src/OpenFOAM/global/new.C
@@ -46,7 +46,7 @@ void newError()
         "by e.g. bad use of pointers or an out of date shared library"
         << std::endl;
 
-    ::abort();
+    std::abort();
 }
 
 void (*old_new_handler)() = std::set_new_handler(newError);
diff --git a/src/OpenFOAM/primitives/Barycentric/Barycentric.H b/src/OpenFOAM/primitives/Barycentric/Barycentric.H
index 529d975d131367284233a6004d9928dc09bde56b..ae4fe2fb420e8f2a5fadb5bac56df649618bcf7f 100644
--- a/src/OpenFOAM/primitives/Barycentric/Barycentric.H
+++ b/src/OpenFOAM/primitives/Barycentric/Barycentric.H
@@ -63,7 +63,7 @@ public:
     // Member constants
 
         //- Rank of Barycentric is 1
-        static const direction rank = 1;
+        static constexpr direction rank = 1;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/Barycentric/BarycentricTensor.H b/src/OpenFOAM/primitives/Barycentric/BarycentricTensor.H
index 83d5ac064ad106588e22996d370c673528e02de2..e603dc5304aee3fc4b31d2d2aba972eb03fff381 100644
--- a/src/OpenFOAM/primitives/Barycentric/BarycentricTensor.H
+++ b/src/OpenFOAM/primitives/Barycentric/BarycentricTensor.H
@@ -67,7 +67,7 @@ public:
     // Member constants
 
         //- Rank of BarycentricTensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H b/src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H
index 49d650da826864b0b7528ed03a4c06a50230620c..b5c46093c98de9495a0900e8c6daf08e91317517 100644
--- a/src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H
+++ b/src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H
@@ -63,7 +63,7 @@ public:
     // Member constants
 
         //- Rank of Barycentric2D is 1
-        static const direction rank = 1;
+        static constexpr direction rank = 1;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H
index 3792d35e06b5f93f8b86a84d1314a830864cea0b..797b7c68eb86a2802b6d56a56b6ede6e18fba44d 100644
--- a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H
+++ b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H
@@ -67,7 +67,7 @@ public:
     // Member constants
 
         //- Rank of DiagTensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
index 8c45d5669cf746dae9e0c1af08028c2893b86045..f83297a0567b5cfc276c2fa1fd4a49ec6a2bf02a 100644
--- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
+++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2016 OpenFOAM Foundation
@@ -68,20 +68,20 @@ public:
 
     // Member constants
 
-        static const direction mRows = Mrows;
-        static const direction nCols = Ncols;
+        static constexpr direction mRows = Mrows;
+        static constexpr direction nCols = Ncols;
 
 
     // Static member functions
 
         //- Return the number of rows
-        static direction m()
+        static direction m() noexcept
         {
             return Mrows;
         }
 
         //- Return the number of columns
-        static direction n()
+        static direction n() noexcept
         {
             return Ncols;
         }
diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
index d6ff7d796c9f14435aa1c2c0ee5ce51abae3f9bc..5e696035ae97d5d2a8612b6e11947ba5c94391c3 100644
--- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
+++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
@@ -345,7 +345,7 @@ inline const Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
 ) const
 {
     #ifdef FULLDEBUG
-    if (i > Mrows-1 || j > Ncols-1)
+    if (i >= Mrows || j >= Ncols)
     {
         FatalErrorInFunction
             << "indices out of range"
@@ -365,7 +365,7 @@ inline Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
 )
 {
     #ifdef FULLDEBUG
-    if (i > Mrows-1 || j > Ncols-1)
+    if (i >= Mrows || j >= Ncols)
     {
         FatalErrorInFunction
             << "indices out of range"
diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H
index 833f73fe933a7942282a09446965c606ee5566c4..9039dbdcb92ce7a0f3f95d283801cbbf7ae65555 100644
--- a/src/OpenFOAM/primitives/Scalar/Scalar.H
+++ b/src/OpenFOAM/primitives/Scalar/Scalar.H
@@ -59,13 +59,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of Scalar is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in Scalar is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H
index 722a81f23d089e533342eb8c62336cdc0ea8a5fd..ff9f8ec959524be82e83b5677e9a5e46cadd54b6 100644
--- a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H
+++ b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H
@@ -65,7 +65,7 @@ public:
     // Member constants
 
         //- Rank of SphericalTensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H
index c8015409982c48159c34af8dba0a7252a00ea4e2..73186231088b50a70bdb7f39a0c2259642f2eaa0 100644
--- a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H
+++ b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H
@@ -61,7 +61,7 @@ public:
     // Member constants
 
         //- Rank of SphericalTensor2D is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H
index 71a8fadb78abc712553ededd8ad50a73501754a2..2fb50c93b96d9f694e8372972e900496fbe9ab92 100644
--- a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H
+++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H
@@ -67,7 +67,7 @@ public:
     // Member constants
 
         //- Rank of SymmTensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H
index 7b026dc82f577eb12e2b632d3e0b741987221c4b..c961f6203a569b46545df76009ab125fef6f4b59 100644
--- a/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H
+++ b/src/OpenFOAM/primitives/SymmTensor2D/SymmTensor2D.H
@@ -67,7 +67,7 @@ public:
     // Member constants
 
         //- Rank of SymmTensor2D is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/Tensor/Tensor.H b/src/OpenFOAM/primitives/Tensor/Tensor.H
index c373a266cede237d24fe365dff72b8ee278a06ff..21fc9176d051670d9b95c25a3c35ddeb28aee8a6 100644
--- a/src/OpenFOAM/primitives/Tensor/Tensor.H
+++ b/src/OpenFOAM/primitives/Tensor/Tensor.H
@@ -53,8 +53,9 @@ See also
 namespace Foam
 {
 
-template<class Cmpt>
-class SymmTensor;
+// Forward Declarations
+template<class Cmpt> class SymmTensor;
+
 
 /*---------------------------------------------------------------------------*\
                            Class Tensor Declaration
@@ -75,7 +76,7 @@ public:
     // Member constants
 
         //- Rank of Tensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H
index 1606215fa6e2a4dd0b9891b7dcbfbdde5a3f2b68..332d74e9603fc803d0ff75368bbf7b92d90ef3f8 100644
--- a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H
+++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H
@@ -70,7 +70,7 @@ public:
     // Member constants
 
         //- Rank of Tensor2D is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/Vector/Vector.H b/src/OpenFOAM/primitives/Vector/Vector.H
index d46e29416f8e81faa41ab1e9a558165e36092530..bccc1bd25f810e8b8e207f187fc502b3af9ddd40 100644
--- a/src/OpenFOAM/primitives/Vector/Vector.H
+++ b/src/OpenFOAM/primitives/Vector/Vector.H
@@ -72,7 +72,7 @@ public:
     // Member constants
 
         //- Rank of Vector is 1
-        static const direction rank = 1;
+        static constexpr direction rank = 1;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/Vector2D/Vector2D.H b/src/OpenFOAM/primitives/Vector2D/Vector2D.H
index d2d25c5f9fe07290cca696a0dbf5d718c21bc162..ed69c95ed7dac57efa9af4c97c2099dc5fa76e6a 100644
--- a/src/OpenFOAM/primitives/Vector2D/Vector2D.H
+++ b/src/OpenFOAM/primitives/Vector2D/Vector2D.H
@@ -65,7 +65,7 @@ public:
     // Member constants
 
         //- Rank of Vector2D is 1
-        static const direction rank = 1;
+        static constexpr direction rank = 1;
 
 
     //- Component labeling enumeration
diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.C b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.C
index c88bb1f8fba3e9cb742698aa05b194ebeabedcbd..f40e9caacbf5d9c99e50b9cac7673b9dbdeef032 100644
--- a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.C
+++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.C
@@ -38,18 +38,15 @@ Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
     Istream& is
 )
 {
-    // Read beginning of VectorSpace<Cmpt>
-    is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
+    is.readBegin("VectorSpace");
 
     for (direction i=0; i<Ncmpts; i++)
     {
         is >> v_[i];
     }
 
-    // Read end of VectorSpace<Cmpt>
-    is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
+    is.readEnd("VectorSpace");
 
-    // Check state of Istream
     is.check(FUNCTION_NAME);
 }
 
@@ -64,7 +61,7 @@ Foam::word Foam::name
 
     buf << '(' << vs.v_[0];
 
-    for (direction i=1; i<Ncmpts; i++)
+    for (direction i=1; i<Ncmpts; ++i)
     {
         buf << ',' << vs.v_[i];
     }
@@ -84,18 +81,15 @@ Foam::Istream& Foam::operator>>
     VectorSpace<Form, Cmpt, Ncmpts>& vs
 )
 {
-    // Read beginning of VectorSpace<Cmpt, Ncmpts>
-    is.readBegin("VectorSpace<Form, Cmpt, Ncmpts>");
+    is.readBegin("VectorSpace");
 
     for (direction i=0; i<Ncmpts; i++)
     {
         is >> vs.v_[i];
     }
 
-    // Read end of VectorSpace<Cmpt, Ncmpts>
-    is.readEnd("VectorSpace<Form, Cmpt, Ncmpts>");
+    is.readEnd("VectorSpace");
 
-    // Check state of Istream
     is.check(FUNCTION_NAME);
 
     return is;
@@ -111,7 +105,7 @@ Foam::Ostream& Foam::operator<<
 {
     os << token::BEGIN_LIST << vs.v_[0];
 
-    for (direction i=1; i<Ncmpts; i++)
+    for (direction i=1; i<Ncmpts; ++i)
     {
         os << token::SPACE << vs.v_[i];
     }
diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
index fb3ad19163081d4926d7969d0ded3f4ae1a8d956..5fbb29aed0b6eee33b80c2f5f290e960c0bbf579 100644
--- a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
+++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -89,23 +89,23 @@ public:
     typedef Cmpt cmptType;
 
 
-    // Static constants
+    // Static Constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Number of components in this vector space
-        static const direction nComponents = Ncmpts;
+        static constexpr direction nComponents = Ncmpts;
 
 
         // VectorSpace currently defaults to a column-vector
         // This will be removed when column-vector is introduced
         // as a specialization
-        static const direction mRows = Ncmpts;
-        static const direction nCols = 1;
+        static constexpr direction mRows = Ncmpts;
+        static constexpr direction nCols = 1;
 
 
-    // Static data members
+    // Static Data Members
 
         static const char* const typeName;
         static const char* const componentNames[];
@@ -120,11 +120,7 @@ public:
     // Sub-Block Classes
 
         //- Const sub-block type
-        template
-        <
-            class SubVector,
-            direction BStart
-        >
+        template<class SubVector, direction BStart>
         class ConstBlock
         {
             const vsType& vs_;
@@ -158,12 +154,12 @@ public:
         inline VectorSpace(const Foam::zero);
 
         //- Construct from Istream
-        VectorSpace(Istream&);
+        VectorSpace(Istream& is);
 
-        //- Construct as copy
-        inline VectorSpace(const VectorSpace<Form, Cmpt, Ncmpts>&);
+        //- Copy construct
+        inline VectorSpace(const VectorSpace<Form, Cmpt, Ncmpts>& vs);
 
-        //- Construct as copy of a VectorSpace with the same size
+        //- Copy construct of a VectorSpace with the same size
         template<class Form2, class Cmpt2>
         inline explicit VectorSpace(const VectorSpace<Form2, Cmpt2, Ncmpts>&);
 
@@ -171,7 +167,7 @@ public:
     // Member Functions
 
         //- Return the number of elements in the VectorSpace = Ncmpts.
-        inline static direction size();
+        inline static constexpr direction size();
 
         inline const Cmpt& component(const direction) const;
         inline Cmpt& component(const direction);
@@ -200,6 +196,39 @@ public:
         inline void operator/=(const scalar);
 
 
+    // Iterators
+
+        //- Random access iterator for traversing VectorSpace
+        typedef Cmpt* iterator;
+
+        //- Random access iterator for traversing VectorSpace
+        typedef const Cmpt* const_iterator;
+
+
+    // Random access iterator (non-const)
+
+        //- Return an iterator to begin of VectorSpace
+        inline iterator begin();
+
+        //- Return an iterator to end of UListVectorSpace
+        inline iterator end();
+
+
+    // Random access iterator (const)
+
+        //- Return const_iterator to begin of VectorSpace
+        inline const_iterator cbegin() const;
+
+        //- Return const_iterator to end of VectorSpace
+        inline const_iterator cend() const;
+
+        //- Return const_iterator to begin of VectorSpace
+        inline const_iterator begin() const;
+
+        //- Return const_iterator to end of VectorSpace
+        inline const_iterator end() const;
+
+
     // IOstream Operators
 
         friend Istream& operator>> <Form, Cmpt, Ncmpts>
diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
index 89af43b3ab5602ece237ed56f15dc1ea56c1bc08..bba3f77740648d72228e4cc2531eda4da691ef6a 100644
--- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
+++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -31,27 +31,23 @@ License
 #include "ops.H"
 #include <type_traits>
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace()
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace()
 {}
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(const Foam::zero)
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace(const Foam::zero)
 {
     VectorSpaceOps<Ncmpts,0>::eqOpS(*this, Zero, eqOp<Cmpt>());
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
 (
     const VectorSpace<Form, Cmpt, Ncmpts>& vs
 )
@@ -60,9 +56,9 @@ inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
+template<class Form, class Cmpt, Foam::direction Ncmpts>
 template<class Form2, class Cmpt2>
-inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
+inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
 (
     const VectorSpace<Form2, Cmpt2, Ncmpts>& vs
 )
@@ -71,10 +67,10 @@ inline VectorSpace<Form, Cmpt, Ncmpts>::VectorSpace
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-template<class SubVector, direction BStart>
-inline
-VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>::ConstBlock
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+template<class SubVector, Foam::direction BStart>
+inline Foam::VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>
+    ::ConstBlock
 (
     const vsType& vs
 )
@@ -91,15 +87,15 @@ VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>::ConstBlock
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline direction VectorSpace<Form, Cmpt, Ncmpts>::size()
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline constexpr Foam::direction Foam::VectorSpace<Form, Cmpt, Ncmpts>::size()
 {
     return Ncmpts;
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
 (
     const direction d
 ) const
@@ -117,8 +113,8 @@ inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
 (
     const direction d
 )
@@ -136,8 +132,8 @@ inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::component
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::component
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::component
 (
     Cmpt& c,
     const direction d
@@ -156,8 +152,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::component
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::replace
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::replace
 (
     const direction d,
     const Cmpt& c
@@ -176,8 +172,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::replace
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline Form VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Form Foam::VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
 {
     Form v;
     VectorSpaceOps<Ncmpts,0>::eqOpS(v, s, eqOp<Cmpt>());
@@ -185,20 +181,64 @@ inline Form VectorSpace<Form, Cmpt, Ncmpts>::uniform(const Cmpt& s)
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-template<class SubVector, direction BStart>
-inline const typename VectorSpace<Form, Cmpt, Ncmpts>::template
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+template<class SubVector, Foam::direction BStart>
+inline const typename Foam::VectorSpace<Form, Cmpt, Ncmpts>::template
     ConstBlock<SubVector, BStart>
-VectorSpace<Form, Cmpt, Ncmpts>::block() const
+Foam::VectorSpace<Form, Cmpt, Ncmpts>::block() const
 {
     return *this;
 }
 
 
+// * * * * * * * * * * * * * * * * Iterator  * * * * * * * * * * * * * * * * //
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::begin()
+{
+    return v_;
+}
+
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::end()
+{
+    return (v_ + Ncmpts);
+}
+
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::cbegin() const
+{
+    return v_;
+}
+
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::cend() const
+{
+    return (v_ + Ncmpts);
+}
+
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::begin() const
+{
+    return v_;
+}
+
+
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt* Foam::VectorSpace<Form, Cmpt, Ncmpts>::end() const
+{
+    return (v_ + Ncmpts);
+}
+
+
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline const Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator[]
 (
     const direction d
 ) const
@@ -216,8 +256,8 @@ inline const Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline Cmpt& Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator[]
 (
     const direction d
 )
@@ -235,10 +275,10 @@ inline Cmpt& VectorSpace<Form, Cmpt, Ncmpts>::operator[]
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-template<class SubVector, direction BStart>
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+template<class SubVector, Foam::direction BStart>
 inline const Cmpt&
-VectorSpace<Form, Cmpt, Ncmpts>::
+Foam::VectorSpace<Form, Cmpt, Ncmpts>::
 ConstBlock<SubVector, BStart>::operator[]
 (
     const direction d
@@ -257,10 +297,10 @@ ConstBlock<SubVector, BStart>::operator[]
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-template<class SubVector, direction BStart>
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+template<class SubVector, Foam::direction BStart>
 inline const Cmpt&
-VectorSpace<Form, Cmpt, Ncmpts>::
+Foam::VectorSpace<Form, Cmpt, Ncmpts>::
 ConstBlock<SubVector, BStart>::operator()
 (
     const direction i,
@@ -275,7 +315,7 @@ ConstBlock<SubVector, BStart>::operator()
             << abort(FatalError);
     }
 
-    if (j != 0)
+    if (j)
     {
         FatalErrorInFunction
             << "index " << j << " != 0"
@@ -287,8 +327,8 @@ ConstBlock<SubVector, BStart>::operator()
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator=
 (
     const VectorSpace<Form, Cmpt, Ncmpts>& vs
 )
@@ -297,8 +337,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator+=
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator+=
 (
     const VectorSpace<Form, Cmpt, Ncmpts>& vs
 )
@@ -307,8 +347,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator+=
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator-=
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator-=
 (
     const VectorSpace<Form, Cmpt, Ncmpts>& vs
 )
@@ -317,15 +357,15 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator-=
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator=(const Foam::zero)
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator=(const Foam::zero)
 {
     VectorSpaceOps<Ncmpts,0>::eqOpS(*this, 0, eqOp<Cmpt>());
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator*=
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator*=
 (
     const scalar s
 )
@@ -334,8 +374,8 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator*=
 }
 
 
-template<class Form, class Cmpt, direction Ncmpts>
-inline void VectorSpace<Form, Cmpt, Ncmpts>::operator/=
+template<class Form, class Cmpt, Foam::direction Ncmpts>
+inline void Foam::VectorSpace<Form, Cmpt, Ncmpts>::operator/=
 (
     const scalar s
 )
@@ -344,6 +384,11 @@ inline void VectorSpace<Form, Cmpt, Ncmpts>::operator/=
 }
 
 
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
 
 template<class Form, class Cmpt, direction Ncmpts>
diff --git a/src/OpenFOAM/primitives/bools/bool/bool.H b/src/OpenFOAM/primitives/bools/bool/bool.H
index 6b6863b09614605008f0dc1e16bc8716496b044d..6874ca3be5cac705011618c42a1064f6a530ad08 100644
--- a/src/OpenFOAM/primitives/bools/bool/bool.H
+++ b/src/OpenFOAM/primitives/bools/bool/bool.H
@@ -77,13 +77,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of bool is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in bool is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/chars/char/char.H b/src/OpenFOAM/primitives/chars/char/char.H
index e42043ad72d68b78829a37fa99fb59150c9f7871..9c5cb5f315776068aa4f43d06c029e90fff0e856 100644
--- a/src/OpenFOAM/primitives/chars/char/char.H
+++ b/src/OpenFOAM/primitives/chars/char/char.H
@@ -47,11 +47,19 @@ class Ostream;
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-char readChar(Istream&);
-Istream& operator>>(Istream&, char&);
-Ostream& operator<<(Ostream&, const char);
-Ostream& operator<<(Ostream&, const char*);
+//- Read single character
+char readChar(Istream& is);
 
+//- Read single character
+Istream& operator>>(Istream& is, char& c);
+
+//- Write single character
+Ostream& operator<<(Ostream& os, const char c);
+
+//- Write a nul-terminated C-string
+Ostream& operator<<(Ostream& os, const char* str);
+
+//- Test for \em horizontal whitespace
 inline bool isspace(char c)
 {
     return
@@ -63,6 +71,7 @@ inline bool isspace(char c)
     );
 }
 
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/OpenFOAM/primitives/chars/char/charIO.C b/src/OpenFOAM/primitives/chars/char/charIO.C
index c15a71b002318a70e74f984ed8afcc0953a65f1d..24b02ecb9083e050f71297c614a0e4c898ed3258 100644
--- a/src/OpenFOAM/primitives/chars/char/charIO.C
+++ b/src/OpenFOAM/primitives/chars/char/charIO.C
@@ -32,9 +32,9 @@ License
 
 char Foam::readChar(Istream& is)
 {
-   char c;
-   is.read(c);
-   return c;
+    char c;
+    is.read(c);
+    return c;
 }
 
 
@@ -54,9 +54,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const char c)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const char* s)
+Foam::Ostream& Foam::operator<<(Ostream& os, const char* str)
 {
-    os.write(s);
+    os.write(str);
     os.check(FUNCTION_NAME);
     return os;
 }
diff --git a/src/OpenFOAM/primitives/complex/complex.C b/src/OpenFOAM/primitives/complex/complex.C
index 1368df2ae440e46ec5e7eab9c54f5b9f31ffe380..277864c487b54d8e421df9c21ac42c5dd6e609e1 100644
--- a/src/OpenFOAM/primitives/complex/complex.C
+++ b/src/OpenFOAM/primitives/complex/complex.C
@@ -35,6 +35,41 @@ const Foam::complex Foam::complex::zero(0, 0);
 const Foam::complex Foam::complex::one(1, 0);
 
 
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+const char* const Foam::pTraits<Foam::complex>::typeName = "complex";
+const char* const Foam::pTraits<Foam::complex>::componentNames[] = {"re", "im"};
+
+const Foam::complex Foam::pTraits<Foam::complex>::zero(0, 0);
+const Foam::complex Foam::pTraits<Foam::complex>::one(1, 0);
+
+const Foam::complex Foam::pTraits<Foam::complex>::min(-VGREAT, -VGREAT);
+const Foam::complex Foam::pTraits<Foam::complex>::max(VGREAT, VGREAT);
+
+const Foam::complex Foam::pTraits<Foam::complex>::rootMin
+(
+    -ROOTVGREAT, -ROOTVGREAT
+);
+
+const Foam::complex Foam::pTraits<Foam::complex>::rootMax
+(
+    ROOTVGREAT, ROOTVGREAT
+);
+
+
+Foam::pTraits<Foam::complex>::pTraits(const complex& val)
+:
+    p_(val)
+{}
+
+
+Foam::pTraits<Foam::complex>::pTraits(Istream& is)
+{
+    is >> p_;
+}
+
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::complex::complex(Istream& is)
diff --git a/src/OpenFOAM/primitives/complex/complex.H b/src/OpenFOAM/primitives/complex/complex.H
index 48e3505d1935ec874d945127aa9b1014c55bf627..06f4eded4e134772989b248fe574f929088cb592 100644
--- a/src/OpenFOAM/primitives/complex/complex.H
+++ b/src/OpenFOAM/primitives/complex/complex.H
@@ -232,6 +232,70 @@ public:
 };
 
 
+// Template specialisation for pTraits<complex>
+template<>
+class pTraits<complex>
+{
+    complex p_;
+
+public:
+
+    //- Component type
+    typedef complex cmptType;
+
+    //- Equivalent type of labels used for valid component indexing
+    typedef label labelType;
+
+
+    // Member constants
+
+        //- Dimensionality of space
+        static constexpr direction dim = 3;
+
+        //- Rank of complex is 0
+        static constexpr direction rank = 0;
+
+        //- Number of components in complex is 2
+        static constexpr direction nComponents = 2;
+
+
+    // Static Data Members
+
+        static const char* const typeName;
+        static const char* const componentNames[];
+        static const complex zero;
+        static const complex one;
+        static const complex max;
+        static const complex min;
+        static const complex rootMax;
+        static const complex rootMin;
+
+
+    // Constructors
+
+        //- Construct from primitive
+        explicit pTraits(const complex& val);
+
+        //- Construct from Istream
+        pTraits(Istream& is);
+
+
+    // Member Functions
+
+        //- Access to the value
+        operator complex() const
+        {
+            return p_;
+        }
+
+        //- Access to the value
+        operator complex&()
+        {
+            return p_;
+        }
+};
+
+
 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
 
 Istream& operator>>(Istream& is, complex& c);
diff --git a/src/OpenFOAM/primitives/complex/complexI.H b/src/OpenFOAM/primitives/complex/complexI.H
index 25b6cc5a49236ab682683d152bdf00dcce4f18c6..16e8594fb439d5501fcc00425563b6c9cd23fa76 100644
--- a/src/OpenFOAM/primitives/complex/complexI.H
+++ b/src/OpenFOAM/primitives/complex/complexI.H
@@ -350,6 +350,7 @@ inline complex operator/(const scalar s, const complex& c)
     return complex(s/c.re, s/c.im);
 }
 
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H
index 1840b66b32fe7c6624d7d3ab297fa1f4b5be8b25..5c4c22f020d97000eafa2a45571b3b5042d83fd3 100644
--- a/src/OpenFOAM/primitives/ints/int32/int32.H
+++ b/src/OpenFOAM/primitives/ints/int32/int32.H
@@ -142,13 +142,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of int32_t is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in int32_t is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H
index e8c5ece2fc9a18adbd947febc051ddd0132362b7..4027f8632817cd282c62956d69625214533c1252 100644
--- a/src/OpenFOAM/primitives/ints/int64/int64.H
+++ b/src/OpenFOAM/primitives/ints/int64/int64.H
@@ -143,13 +143,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of int64_t is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in int64_t is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H
index 81a97323ca9fabad992868985463ef8dcff5bf58..629c14c3f020c93e4f451df1a7d7dffe8bbd085b 100644
--- a/src/OpenFOAM/primitives/ints/uint32/uint32.H
+++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H
@@ -133,13 +133,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of uint32_t is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in uint32_t is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H
index dee834635ed00b3a129130e518d0fa9ddcd7fc3e..694e9f1158749f4b2b051a983cda1be84d43e9f5 100644
--- a/src/OpenFOAM/primitives/ints/uint64/uint64.H
+++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H
@@ -141,13 +141,13 @@ public:
     // Member constants
 
         //- Dimensionality of space
-        static const direction dim = 3;
+        static constexpr direction dim = 3;
 
         //- Rank of uint64_t is 0
-        static const direction rank = 0;
+        static constexpr direction rank = 0;
 
         //- Number of components in uint64_t is 1
-        static const direction nComponents = 1;
+        static constexpr direction nComponents = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/quaternion/quaternion.H b/src/OpenFOAM/primitives/quaternion/quaternion.H
index ab1e12111c7aa46b2163d1a62d5b5e7affa8b613..95878643ed9f85cd2cf188f8627b61c906af1a03 100644
--- a/src/OpenFOAM/primitives/quaternion/quaternion.H
+++ b/src/OpenFOAM/primitives/quaternion/quaternion.H
@@ -110,7 +110,7 @@ public:
     // Member constants
 
         //- Rank of quaternion is 1
-        static const direction rank = 1;
+        static constexpr direction rank = 1;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensor.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensor.H
index 5bd51f6f3f85c04ad084151f625ad54a9bf08001..923a05bd611bb49af341e02c3bb5791094a0f09c 100644
--- a/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensor.H
+++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/SpatialTensor/SpatialTensor.H
@@ -74,7 +74,7 @@ public:
     // Member constants
 
         //- Rank of Tensor is 2
-        static const direction rank = 2;
+        static constexpr direction rank = 2;
 
 
     // Static data members
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C
index 7002ebd7a24363f93a97f1b5f376c42a21e8a12c..f74c6877a68a228370cb217950d370e31cf4248d 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.C
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2017 OpenFOAM Foundation
@@ -36,7 +36,11 @@ License
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::fileName::typeName = "fileName";
-int Foam::fileName::debug(debug::debugSwitch(fileName::typeName, 0));
+int Foam::fileName::debug(Foam::debug::debugSwitch(fileName::typeName, 0));
+int Foam::fileName::allowSpaceInFileName
+(
+    Foam::debug::infoSwitch("allowSpaceInFileName", 0)
+);
 const Foam::fileName Foam::fileName::null;
 
 
@@ -48,16 +52,27 @@ Foam::fileName Foam::fileName::validate
     const bool doClean
 )
 {
+    // The logic is very similar to stripInvalid,
+    // but silently removes bad characters
+
     fileName out;
-    out.resize(s.size());
+    out.resize(s.length());
 
-    char prev = 0;
     std::string::size_type len = 0;
 
-    // Largely as per stripInvalid
+    char prev = 0;
     for (auto iter = s.cbegin(); iter != s.cend(); ++iter)
     {
-        const char c = *iter;
+        char c = *iter;
+
+        // Treat raw backslash like a path separator. There is no "normal"
+        // way for these to be there (except for an OS that uses them), but
+        // could also cause issues when writing strings, shell commands etc.
+
+        if (c == '\\')
+        {
+            c = '/';
+        }
 
         if (fileName::valid(c))
         {
@@ -84,6 +99,33 @@ Foam::fileName Foam::fileName::validate
 }
 
 
+Foam::fileName Foam::fileName::concat
+(
+    const std::string& s1,
+    const std::string& s2
+)
+{
+    const auto n1 = s1.length();
+    const auto n2 = s2.length();
+
+    fileName out;
+    out.reserve(n1 + n2 + 1);
+
+    out += s1;
+
+    if (n1 && n2 && s1.back() != '/' && s2.front() != '/')
+    {
+        // Add separator
+        out += '/';
+    }
+
+    out += s2;
+
+    // Could also remove trailing '/', if desired.
+    return out;
+}
+
+
 bool Foam::fileName::equals(const std::string& s1, const std::string& s2)
 {
     // Do not use (s1 == s2) or s1.compare(s2) first since this would
@@ -92,8 +134,8 @@ bool Foam::fileName::equals(const std::string& s1, const std::string& s2)
     std::string::size_type i1 = 0;
     std::string::size_type i2 = 0;
 
-    const auto n1 = s1.size();
-    const auto n2 = s2.size();
+    const auto n1 = s1.length();
+    const auto n2 = s2.length();
 
     //Info<< "compare " << s1 << " == " << s2 << endl;
     while (i1 < n1 && i2 < n2)
@@ -249,7 +291,7 @@ bool Foam::fileName::clean(std::string& str)
     // Number of output characters
     auto nChar = top+1;
 
-    const auto maxLen = str.size();
+    const auto maxLen = str.length();
 
     for (auto src = nChar; src < maxLen; /*nil*/)
     {
@@ -462,7 +504,7 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
                 s += '/';
             }
 
-            s.append(other);
+            s += other;
         }
     }
     else if (other.size())
@@ -477,32 +519,32 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
 
 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
 
-Foam::fileName Foam::operator/(const string& a, const string& b)
+Foam::fileName Foam::operator/(const string& s1, const string& s2)
 {
-    if (a.size())
+    if (s1.length())
     {
-        if (b.size())
+        if (s2.length())
         {
             // Two non-empty strings: can concatenate
 
-            if (a.back() == '/' || b.front() == '/')
+            if (s1.back() == '/' || s2.front() == '/')
             {
-                return fileName(a + b);
+                return fileName(s1 + s2);
             }
             else
             {
-                return fileName(a + '/' + b);
+                return fileName(s1 + '/' + s2);
             }
         }
 
         // The second string was empty
-        return a;
+        return s1;
     }
 
-    if (b.size())
+    if (s2.length())
     {
         // The first string is empty
-        return b;
+        return s2;
     }
 
     // Both strings are empty
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H
index 824345ad090b6b2c16921d9d362a899df60e5545..a0c1570e75a5d675bc2406e33fa80b6a7efeaf2a 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H
@@ -82,7 +82,7 @@ public:
     };
 
 
-    // Static data members
+    // Static Data Members
 
         //- The typeName
         static const char* const typeName;
@@ -90,6 +90,9 @@ public:
         //- Debugging
         static int debug;
 
+        //- Allow space character in fileName. To be used with caution.
+        static int allowSpaceInFileName;
+
         //- An empty fileName
         static const fileName null;
 
@@ -141,14 +144,16 @@ public:
         //- Is this character valid for a fileName?
         inline static bool valid(char c);
 
-        //- Construct validated fileName (no invalid characters).
-        //  Optionally perform some additional cleanup such as removing
-        //  duplicate or trailing slashes.
-        static fileName validate
-        (
-            const std::string& s,
-            const bool doClean=false
-        );
+        //- Construct fileName with no invalid characters, possibly applying
+        //- other transformations such as changing the path separator, 
+        //- removing duplicate or trailing slashes, etc.
+        static fileName validate(const std::string& s, const bool doClean=true);
+
+        //- Join two strings with '/' as a path separator.
+        //  No '/' separator is added if either argument is an empty string or
+        //  if the arguments already had the path separator at the junction.
+        //  Invalid characters are \em not stripped (ie, retained).
+        static fileName concat(const std::string& s1, const std::string& s2);
 
         //- This is a specialized (possibly slower) version of compare()
         //- that ignores duplicate or trailing slashes.
@@ -403,7 +408,7 @@ Ostream& operator<<(Ostream& os, const fileName& val);
 
 //- Assemble words and fileNames as pathnames by adding a '/' separator.
 //  No '/' separator is added if either argument is an empty string.
-fileName operator/(const string& a, const string& b);
+fileName operator/(const string& s1, const string& s2);
 
 
 //- Recursively search the given directory for the file
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
index fb23263c8c6aa0621f485f6a2ee0a3bcb795c413..2eefa95f72b4e782e744c78f978b9d28a5b8df68 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
@@ -102,9 +102,9 @@ inline bool Foam::fileName::valid(char c)
 {
     return
     (
-        !isspace(c)
-     && c != '"'   // string quote
-     && c != '\''  // string quote
+        c != '"'    // string quote
+     && c != '\''   // string quote
+     && (!isspace(c) || (allowSpaceInFileName && c == ' '))
     );
 }
 
@@ -134,7 +134,10 @@ inline void Foam::fileName::stripInvalid()
 
 inline bool Foam::fileName::isAbsolute(const std::string& str)
 {
-    return !str.empty() && str[0] == '/';
+    return
+    (
+        !str.empty() && str[0] == '/'
+    );
 }
 
 
diff --git a/src/Pstream/dummy/UPstream.C b/src/Pstream/dummy/UPstream.C
index 661e5a2cc5fe75ae84e1e41cfa8d723afa3476de..9dbaf0f5740b2658f0ec93731bd2f8deb7170c88 100644
--- a/src/Pstream/dummy/UPstream.C
+++ b/src/Pstream/dummy/UPstream.C
@@ -58,14 +58,14 @@ bool Foam::UPstream::init(int& argc, char**& argv, const bool needsThread)
 void Foam::UPstream::exit(int errnum)
 {
     // No MPI - just exit
-    ::exit(errnum);
+    std::exit(errnum);
 }
 
 
 void Foam::UPstream::abort()
 {
     // No MPI - just abort
-    ::abort();
+    std::abort();
 }
 
 
diff --git a/src/Pstream/mpi/UPstream.C b/src/Pstream/mpi/UPstream.C
index 5a2ec78973eab418154b4402f21af050ec14c48f..0fec38de2c896d9b12a68a5a296e96881384d2aa 100644
--- a/src/Pstream/mpi/UPstream.C
+++ b/src/Pstream/mpi/UPstream.C
@@ -213,7 +213,7 @@ void Foam::UPstream::exit(int errnum)
     if (!flag)
     {
         // Not initialized - just exit
-        ::exit(errnum);
+        std::exit(errnum);
         return;
     }
 
@@ -224,7 +224,7 @@ void Foam::UPstream::exit(int errnum)
         WarningInFunction
             << "MPI was already finalized (perhaps by a connected program)"
             << endl;
-        ::exit(1);
+        std::exit(1);
         return;
     }
 
@@ -271,7 +271,7 @@ void Foam::UPstream::exit(int errnum)
     if (errnum == 0)
     {
         MPI_Finalize();
-        ::exit(errnum);
+        std::exit(errnum);
     }
     else
     {
diff --git a/src/conversion/ccm/common/ccmInternal.C b/src/conversion/ccm/common/ccmInternal.C
index 47dd0c393397577c56db7e2702c663f1b27fcb54..42698b492488d6eccbea97d72ba8ef7270dd04e2 100644
--- a/src/conversion/ccm/common/ccmInternal.C
+++ b/src/conversion/ccm/common/ccmInternal.C
@@ -118,7 +118,7 @@ bool Foam::ccm::ccmGlobalState::assertNoError
             << "\n    libccmio reports -> " << errorMsg(err) << " <-\n"
             << endl;
 
-        ::exit(1);
+        std::exit(1);
     }
 
     return (err == kCCMIONoErr);
diff --git a/src/finiteVolume/cfdTools/general/meshObjects/gravity/gravityMeshObject.H b/src/finiteVolume/cfdTools/general/meshObjects/gravity/gravityMeshObject.H
index 7f0a0cade5e88509b064d941e9181f63a2535d4d..2083e6719e8038caf6dc0e350e1efacdaa9413fc 100644
--- a/src/finiteVolume/cfdTools/general/meshObjects/gravity/gravityMeshObject.H
+++ b/src/finiteVolume/cfdTools/general/meshObjects/gravity/gravityMeshObject.H
@@ -96,7 +96,7 @@ public:
             )
         );
     }
-        
+
 
     //- Destructor
     virtual ~gravity() = default;
diff --git a/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C b/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C
index 1a7d060a67f6f23785ab0ddd78a4d29886cd4210..16fe9f6d658155faaa8867b4b736a9e4e0bf7c90 100644
--- a/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C
+++ b/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -59,19 +59,20 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
     actualTypeName_(dict.get<word>("type")),
     dict_(dict)
 {
+    const label patchSize = this->size();
+
     if (!dict.found("value"))
     {
         FatalIOErrorInFunction(dict)
-            << "\n    Cannot find 'value' entry"
+            << nl << "    Cannot find 'value' entry"
             << " on patch " << this->patch().name()
             << " of field " << this->internalField().name()
-            << " in file " << this->internalField().objectPath()
-            << nl
+            << " in file " << this->internalField().objectPath() << nl
             << "    which is required to set the"
                " values of the generic patch field." << nl
-            << "    (Actual type " << actualTypeName_ << ")" << nl
-            << "\n    Please add the 'value' entry to the write function "
-               "of the user-defined boundary-condition\n"
+            << "    (Actual type " << actualTypeName_ << ')' << nl << nl
+            << "    Please add the 'value' entry to the write function"
+               " of the user-defined boundary-condition" << nl
             << exit(FatalIOError);
     }
 
@@ -79,338 +80,329 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if
+        (
+            key == "type"
+         || key == "value"
+         || !dEntry.isStream() || dEntry.stream().empty()
+        )
+        {
+            continue;
+        }
+
+
+        ITstream& is = dEntry.stream();
+
+        // Read first token
+        token firstToken(is);
+
+        if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "nonuniform"
+        )
         {
-            if
+            token fieldToken(is);
+
+            if (!fieldToken.isCompound())
+            {
+                if
+                (
+                    fieldToken.isLabel()
+                 && fieldToken.labelToken() == 0
+                )
+                {
+                    scalarFields_.insert(key, autoPtr<scalarField>::New());
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    token following 'nonuniform' "
+                           "is not a compound"
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+            }
+            else if
             (
-                dEntry.isStream()
-             && dEntry.stream().size()
+                fieldToken.compoundToken().type()
+             == token::Compound<List<scalar>>::typeName
             )
             {
-                ITstream& is = dEntry.stream();
+                auto fPtr = autoPtr<scalarField>::New();
 
-                // Read first token
-                token firstToken(is);
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<scalar>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
 
-                if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                scalarFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<vector>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<vectorField>::New();
+
+                fPtr->transfer
                 (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "nonuniform"
-                )
+                    dynamicCast<token::Compound<List<vector>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
+
+                if (fPtr->size() != patchSize)
                 {
-                    token fieldToken(is);
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
 
-                    if (!fieldToken.isCompound())
-                    {
-                        if
-                        (
-                            fieldToken.isLabel()
-                         && fieldToken.labelToken() == 0
-                        )
-                        {
-                            scalarFields_.insert
-                            (
-                                key,
-                                autoPtr<scalarField>::New()
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    token following 'nonuniform' "
-                                   "is not a compound"
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
-                    else if
+                vectorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<sphericalTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<sphericalTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<sphericalTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<scalar>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<scalarField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<scalar>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        scalarFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                sphTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<symmTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<symmTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<symmTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<vector>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<vectorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<vector>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        vectorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                symmTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<tensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<tensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<tensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<sphericalTensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<sphericalTensorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast
-                            <
-                                token::Compound<List<sphericalTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        sphTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                tensorFields_.insert(key, fPtr);
+            }
+            else
+            {
+                FatalIOErrorInFunction(dict)
+                    << "\n    compound " << fieldToken.compoundToken()
+                    << " not supported"
+                    << "\n    on patch " << this->patch().name()
+                    << " of field "
+                    << this->internalField().name()
+                    << " in file "
+                    << this->internalField().objectPath() << nl
+                    << exit(FatalIOError);
+            }
+        }
+        else if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "uniform"
+        )
+        {
+            token fieldToken(is);
+
+            if (!fieldToken.isPunctuation())
+            {
+                scalarFields_.insert
+                (
+                    key,
+                    autoPtr<scalarField>::New
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<symmTensor>>::typeName
+                        patchSize,
+                        fieldToken.number()
                     )
-                    {
-                        auto fPtr = autoPtr<symmTensorField>::New();
+                );
+            }
+            else
+            {
+                // Read as scalarList.
+                is.putBack(fieldToken);
+
+                scalarList l(is);
+
+                if (l.size() == vector::nComponents)
+                {
+                    vector vs(l[0], l[1], l[2]);
 
-                        fPtr->transfer
+                    vectorFields_.insert
+                    (
+                        key,
+                        autoPtr<vectorField>::New
                         (
-                            dynamicCast
-                            <
-                                token::Compound<List<symmTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        symmTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == sphericalTensor::nComponents)
+                {
+                    sphericalTensor vs(l[0]);
+
+                    sphTensorFields_.insert
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<tensor>>::typeName
-                    )
-                    {
-                        auto fPtr = autoPtr<tensorField>::New();
+                        key,
+                        autoPtr<sphericalTensorField>::New
+                        (
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == symmTensor::nComponents)
+                {
+                    symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
 
-                        fPtr->transfer
+                    symmTensorFields_.insert
+                    (
+                        key,
+                        autoPtr<symmTensorField>::New
                         (
-                            dynamicCast<token::Compound<List<tensor>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        tensorFields_.insert(key, fPtr);
-                    }
-                    else
-                    {
-                        FatalIOErrorInFunction(dict)
-                            << "\n    compound " << fieldToken.compoundToken()
-                            << " not supported"
-                            << "\n    on patch " << this->patch().name()
-                            << " of field "
-                            << this->internalField().name()
-                            << " in file "
-                            << this->internalField().objectPath()
-                            << exit(FatalIOError);
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
                 }
-                else if
-                (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "uniform"
-                )
+                else if (l.size() == tensor::nComponents)
                 {
-                    token fieldToken(is);
+                    tensor vs
+                    (
+                        l[0], l[1], l[2],
+                        l[3], l[4], l[5],
+                        l[6], l[7], l[8]
+                    );
 
-                    if (!fieldToken.isPunctuation())
-                    {
-                        scalarFields_.insert
+                    tensorFields_.insert
+                    (
+                        key,
+                        autoPtr<tensorField>::New
                         (
-                            key,
-                            autoPtr<scalarField>::New
-                            (
-                                this->size(),
-                                fieldToken.number()
-                            )
-                        );
-                    }
-                    else
-                    {
-                        // Read as scalarList.
-                        is.putBack(fieldToken);
-
-                        scalarList l(is);
-
-                        if (l.size() == vector::nComponents)
-                        {
-                            vector vs(l[0], l[1], l[2]);
-
-                            vectorFields_.insert
-                            (
-                                key,
-                                autoPtr<vectorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == sphericalTensor::nComponents)
-                        {
-                            sphericalTensor vs(l[0]);
-
-                            sphTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<sphericalTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == symmTensor::nComponents)
-                        {
-                            symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
-
-                            symmTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<symmTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == tensor::nComponents)
-                        {
-                            tensor vs
-                            (
-                                l[0], l[1], l[2],
-                                l[3], l[4], l[5],
-                                l[6], l[7], l[8]
-                            );
-
-                            tensorFields_.insert
-                            (
-                                key,
-                                autoPtr<tensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    unrecognised native type " << l
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    unrecognised native type " << l
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
                 }
             }
         }
@@ -707,46 +699,42 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if (key == "type" || key == "value")
         {
-            if
-            (
-                dEntry.isStream()
-             && dEntry.stream().size()
-             && dEntry.stream()[0].isWord()
-             && dEntry.stream()[0].wordToken() == "nonuniform"
-            )
+            continue;
+        }
+        else if
+        (
+            dEntry.isStream()
+         && dEntry.stream().size()
+         && dEntry.stream()[0].isWord()
+         && dEntry.stream()[0].wordToken() == "nonuniform"
+        )
+        {
+            if (scalarFields_.found(key))
             {
-                if (scalarFields_.found(key))
-                {
-                    scalarFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (vectorFields_.found(key))
-                {
-                    vectorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (sphTensorFields_.found(key))
-                {
-                    sphTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (symmTensorFields_.found(key))
-                {
-                    symmTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (tensorFields_.found(key))
-                {
-                    tensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
+                scalarFields_.cfind(key)()->writeEntry(key, os);
             }
-            else
+            else if (vectorFields_.found(key))
             {
-                dEntry.write(os);
+                vectorFields_.cfind(key)()->writeEntry(key, os);
             }
+            else if (sphTensorFields_.found(key))
+            {
+                sphTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (symmTensorFields_.found(key))
+            {
+                symmTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (tensorFields_.found(key))
+            {
+                tensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+        }
+        else
+        {
+            dEntry.write(os);
         }
     }
 
diff --git a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C
index bdf7e0351acf58663770004a01cff4ac2dc9f01e..cecaaac1727a86afc1e9d87645d847bb01f9dfee 100644
--- a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C
+++ b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           |
+    \\  /    A nd           | Copyright (C) 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -56,22 +56,23 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
 )
 :
     calculatedFvPatchField<Type>(p, iF, dict),
-    actualTypeName_(dict.lookup("type")),
+    actualTypeName_(dict.get<word>("type")),
     dict_(dict)
 {
+    const label patchSize = this->size();
+
     if (!dict.found("value"))
     {
         FatalIOErrorInFunction(dict)
-            << "\n    Cannot find 'value' entry"
+            << nl << "    Cannot find 'value' entry"
             << " on patch " << this->patch().name()
             << " of field " << this->internalField().name()
-            << " in file " << this->internalField().objectPath()
-            << nl
+            << " in file " << this->internalField().objectPath() << nl
             << "    which is required to set the"
                " values of the generic patch field." << nl
-            << "    (Actual type " << actualTypeName_ << ")" << nl
-            << "\n    Please add the 'value' entry to the write function "
-               "of the user-defined boundary-condition\n"
+            << "    (Actual type " << actualTypeName_ << ')' << nl << nl
+            << "    Please add the 'value' entry to the write function"
+               " of the user-defined boundary-condition" << nl
             << exit(FatalIOError);
     }
 
@@ -79,338 +80,329 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if
+        (
+            key == "type"
+         || key == "value"
+         || !dEntry.isStream() || dEntry.stream().empty()
+        )
+        {
+            continue;
+        }
+
+
+        ITstream& is = dEntry.stream();
+
+        // Read first token
+        token firstToken(is);
+
+        if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "nonuniform"
+        )
         {
-            if
+            token fieldToken(is);
+
+            if (!fieldToken.isCompound())
+            {
+                if
+                (
+                    fieldToken.isLabel()
+                 && fieldToken.labelToken() == 0
+                )
+                {
+                    scalarFields_.insert(key, autoPtr<scalarField>::New());
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    token following 'nonuniform' "
+                           "is not a compound"
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+            }
+            else if
             (
-                dEntry.isStream()
-             && dEntry.stream().size()
+                fieldToken.compoundToken().type()
+             == token::Compound<List<scalar>>::typeName
             )
             {
-                ITstream& is = dEntry.stream();
+                auto fPtr = autoPtr<scalarField>::New();
 
-                // Read first token
-                token firstToken(is);
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<scalar>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
 
-                if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                scalarFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<vector>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<vectorField>::New();
+
+                fPtr->transfer
                 (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "nonuniform"
-                )
+                    dynamicCast<token::Compound<List<vector>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
+
+                if (fPtr->size() != patchSize)
                 {
-                    token fieldToken(is);
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
 
-                    if (!fieldToken.isCompound())
-                    {
-                        if
-                        (
-                            fieldToken.isLabel()
-                         && fieldToken.labelToken() == 0
-                        )
-                        {
-                            scalarFields_.insert
-                            (
-                                dEntry.keyword(),
-                                autoPtr<scalarField>::New()
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    token following 'nonuniform' "
-                                   "is not a compound"
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
-                    else if
+                vectorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<sphericalTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<sphericalTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<sphericalTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<scalar>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<scalarField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<scalar>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        scalarFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                sphTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<symmTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<symmTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<symmTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<vector>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<vectorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<vector>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        vectorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                symmTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<tensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<tensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<tensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<sphericalTensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<sphericalTensorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast
-                            <
-                                token::Compound<List<sphericalTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        sphTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                tensorFields_.insert(key, fPtr);
+            }
+            else
+            {
+                FatalIOErrorInFunction(dict)
+                    << "\n    compound " << fieldToken.compoundToken()
+                    << " not supported"
+                    << "\n    on patch " << this->patch().name()
+                    << " of field "
+                    << this->internalField().name()
+                    << " in file "
+                    << this->internalField().objectPath() << nl
+                    << exit(FatalIOError);
+            }
+        }
+        else if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "uniform"
+        )
+        {
+            token fieldToken(is);
+
+            if (!fieldToken.isPunctuation())
+            {
+                scalarFields_.insert
+                (
+                    key,
+                    autoPtr<scalarField>::New
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<symmTensor>>::typeName
+                        patchSize,
+                        fieldToken.number()
                     )
-                    {
-                        auto fPtr = autoPtr<symmTensorField>::New();
+                );
+            }
+            else
+            {
+                // Read as scalarList.
+                is.putBack(fieldToken);
+
+                scalarList l(is);
+
+                if (l.size() == vector::nComponents)
+                {
+                    vector vs(l[0], l[1], l[2]);
 
-                        fPtr->transfer
+                    vectorFields_.insert
+                    (
+                        key,
+                        autoPtr<vectorField>::New
                         (
-                            dynamicCast
-                            <
-                                token::Compound<List<symmTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        symmTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == sphericalTensor::nComponents)
+                {
+                    sphericalTensor vs(l[0]);
+
+                    sphTensorFields_.insert
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<tensor>>::typeName
-                    )
-                    {
-                        auto fPtr = autoPtr<tensorField>::New();
+                        key,
+                        autoPtr<sphericalTensorField>::New
+                        (
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == symmTensor::nComponents)
+                {
+                    symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
 
-                        fPtr->transfer
+                    symmTensorFields_.insert
+                    (
+                        key,
+                        autoPtr<symmTensorField>::New
                         (
-                            dynamicCast<token::Compound<List<tensor>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        tensorFields_.insert(key, fPtr);
-                    }
-                    else
-                    {
-                        FatalIOErrorInFunction(dict)
-                            << "\n    compound " << fieldToken.compoundToken()
-                            << " not supported"
-                            << "\n    on patch " << this->patch().name()
-                            << " of field "
-                            << this->internalField().name()
-                            << " in file "
-                            << this->internalField().objectPath()
-                            << exit(FatalIOError);
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
                 }
-                else if
-                (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "uniform"
-                )
+                else if (l.size() == tensor::nComponents)
                 {
-                    token fieldToken(is);
+                    tensor vs
+                    (
+                        l[0], l[1], l[2],
+                        l[3], l[4], l[5],
+                        l[6], l[7], l[8]
+                    );
 
-                    if (!fieldToken.isPunctuation())
-                    {
-                        scalarFields_.insert
+                    tensorFields_.insert
+                    (
+                        key,
+                        autoPtr<tensorField>::New
                         (
-                            key,
-                            autoPtr<scalarField>::New
-                            (
-                                this->size(),
-                                fieldToken.number()
-                            )
-                        );
-                    }
-                    else
-                    {
-                        // Read as scalarList.
-                        is.putBack(fieldToken);
-
-                        scalarList l(is);
-
-                        if (l.size() == vector::nComponents)
-                        {
-                            vector vs(l[0], l[1], l[2]);
-
-                            vectorFields_.insert
-                            (
-                                key,
-                                autoPtr<vectorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == sphericalTensor::nComponents)
-                        {
-                            sphericalTensor vs(l[0]);
-
-                            sphTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<sphericalTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == symmTensor::nComponents)
-                        {
-                            symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
-
-                            symmTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<symmTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == tensor::nComponents)
-                        {
-                            tensor vs
-                            (
-                                l[0], l[1], l[2],
-                                l[3], l[4], l[5],
-                                l[6], l[7], l[8]
-                            );
-
-                            tensorFields_.insert
-                            (
-                                key,
-                                autoPtr<tensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    unrecognised native type " << l
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    unrecognised native type " << l
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
                 }
             }
         }
@@ -707,46 +699,42 @@ void Foam::genericFvPatchField<Type>::write(Ostream& os) const
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if (key == "type" || key == "value")
         {
-            if
-            (
-                dEntry.isStream()
-             && dEntry.stream().size()
-             && dEntry.stream()[0].isWord()
-             && dEntry.stream()[0].wordToken() == "nonuniform"
-            )
+            continue;
+        }
+        else if
+        (
+            dEntry.isStream()
+         && dEntry.stream().size()
+         && dEntry.stream()[0].isWord()
+         && dEntry.stream()[0].wordToken() == "nonuniform"
+        )
+        {
+            if (scalarFields_.found(key))
             {
-                if (scalarFields_.found(key))
-                {
-                    scalarFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (vectorFields_.found(key))
-                {
-                    vectorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (sphTensorFields_.found(key))
-                {
-                    sphTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (symmTensorFields_.found(key))
-                {
-                    symmTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (tensorFields_.found(key))
-                {
-                    tensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
+                scalarFields_.cfind(key)()->writeEntry(key, os);
             }
-            else
+            else if (vectorFields_.found(key))
             {
-                dEntry.write(os);
+                vectorFields_.cfind(key)()->writeEntry(key, os);
             }
+            else if (sphTensorFields_.found(key))
+            {
+                sphTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (symmTensorFields_.found(key))
+            {
+                symmTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (tensorFields_.found(key))
+            {
+                tensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+        }
+        else
+        {
+            dEntry.write(os);
         }
     }
 
diff --git a/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C b/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C
index a30745fa41423505dd7f2d29e1b501bf058c17a5..dbfaf0c591bfb5bd575819a7665953b3b0b37867 100644
--- a/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C
+++ b/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C
@@ -54,22 +54,23 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
 )
 :
     calculatedFvsPatchField<Type>(p, iF, dict),
-    actualTypeName_(dict.lookup("type")),
+    actualTypeName_(dict.get<word>("type")),
     dict_(dict)
 {
+    const label patchSize = this->size();
+
     if (!dict.found("value"))
     {
         FatalIOErrorInFunction(dict)
-            << "\n    Cannot find 'value' entry"
+            << nl << "    Cannot find 'value' entry"
             << " on patch " << this->patch().name()
             << " of field " << this->internalField().name()
-            << " in file " << this->internalField().objectPath()
-            << nl
+            << " in file " << this->internalField().objectPath() << nl
             << "    which is required to set the"
                " values of the generic patch field." << nl
-            << "    (Actual type " << actualTypeName_ << ")" << nl
-            << "\n    Please add the 'value' entry to the write function "
-               "of the user-defined boundary-condition\n"
+            << "    (Actual type " << actualTypeName_ << ')' << nl << nl
+            << "    Please add the 'value' entry to the write function"
+               " of the user-defined boundary-condition" << nl
             << exit(FatalIOError);
     }
 
@@ -77,338 +78,329 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if
+        (
+            key == "type"
+         || key == "value"
+         || !dEntry.isStream() || dEntry.stream().empty()
+        )
+        {
+            continue;
+        }
+
+
+        ITstream& is = dEntry.stream();
+
+        // Read first token
+        token firstToken(is);
+
+        if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "nonuniform"
+        )
         {
-            if
+            token fieldToken(is);
+
+            if (!fieldToken.isCompound())
+            {
+                if
+                (
+                    fieldToken.isLabel()
+                 && fieldToken.labelToken() == 0
+                )
+                {
+                    scalarFields_.insert(key, autoPtr<scalarField>::New());
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    token following 'nonuniform' "
+                           "is not a compound"
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+            }
+            else if
             (
-                dEntry.isStream()
-             && dEntry.stream().size()
+                fieldToken.compoundToken().type()
+             == token::Compound<List<scalar>>::typeName
             )
             {
-                ITstream& is = dEntry.stream();
+                auto fPtr = autoPtr<scalarField>::New();
 
-                // Read first token
-                token firstToken(is);
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<scalar>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
 
-                if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                scalarFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<vector>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<vectorField>::New();
+
+                fPtr->transfer
                 (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "nonuniform"
-                )
+                    dynamicCast<token::Compound<List<vector>>>
+                    (
+                        fieldToken.transferCompoundToken(is)
+                    )
+                );
+
+                if (fPtr->size() != patchSize)
                 {
-                    token fieldToken(is);
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
 
-                    if (!fieldToken.isCompound())
-                    {
-                        if
-                        (
-                            fieldToken.isLabel()
-                         && fieldToken.labelToken() == 0
-                        )
-                        {
-                            scalarFields_.insert
-                            (
-                                dEntry.keyword(),
-                                autoPtr<scalarField>::New()
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    token following 'nonuniform' "
-                                   "is not a compound"
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
-                    else if
+                vectorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<sphericalTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<sphericalTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<sphericalTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<scalar>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<scalarField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<scalar>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        scalarFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                sphTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<symmTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<symmTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<symmTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<vector>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<vectorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<vector>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        vectorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                symmTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<tensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<tensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<tensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<sphericalTensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<sphericalTensorField>::New();
+                );
 
-                        fPtr->transfer
-                        (
-                            dynamicCast
-                            <
-                                token::Compound<List<sphericalTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        sphTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                tensorFields_.insert(key, fPtr);
+            }
+            else
+            {
+                FatalIOErrorInFunction(dict)
+                    << "\n    compound " << fieldToken.compoundToken()
+                    << " not supported"
+                    << "\n    on patch " << this->patch().name()
+                    << " of field "
+                    << this->internalField().name()
+                    << " in file "
+                    << this->internalField().objectPath() << nl
+                    << exit(FatalIOError);
+            }
+        }
+        else if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "uniform"
+        )
+        {
+            token fieldToken(is);
+
+            if (!fieldToken.isPunctuation())
+            {
+                scalarFields_.insert
+                (
+                    key,
+                    autoPtr<scalarField>::New
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<symmTensor>>::typeName
+                        patchSize,
+                        fieldToken.number()
                     )
-                    {
-                        auto fPtr = autoPtr<symmTensorField>::New();
+                );
+            }
+            else
+            {
+                // Read as scalarList.
+                is.putBack(fieldToken);
+
+                scalarList l(is);
+
+                if (l.size() == vector::nComponents)
+                {
+                    vector vs(l[0], l[1], l[2]);
 
-                        fPtr->transfer
+                    vectorFields_.insert
+                    (
+                        key,
+                        autoPtr<vectorField>::New
                         (
-                            dynamicCast
-                            <
-                                token::Compound<List<symmTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        symmTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == sphericalTensor::nComponents)
+                {
+                    sphericalTensor vs(l[0]);
+
+                    sphTensorFields_.insert
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<tensor>>::typeName
-                    )
-                    {
-                        auto fPtr = autoPtr<tensorField>::New();
+                        key,
+                        autoPtr<sphericalTensorField>::New
+                        (
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else if (l.size() == symmTensor::nComponents)
+                {
+                    symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
 
-                        fPtr->transfer
+                    symmTensorFields_.insert
+                    (
+                        key,
+                        autoPtr<symmTensorField>::New
                         (
-                            dynamicCast<token::Compound<List<tensor>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        tensorFields_.insert(key, fPtr);
-                    }
-                    else
-                    {
-                        FatalIOErrorInFunction(dict)
-                            << "\n    compound " << fieldToken.compoundToken()
-                            << " not supported"
-                            << "\n    on patch " << this->patch().name()
-                            << " of field "
-                            << this->internalField().name()
-                            << " in file "
-                            << this->internalField().objectPath()
-                            << exit(FatalIOError);
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
                 }
-                else if
-                (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "uniform"
-                )
+                else if (l.size() == tensor::nComponents)
                 {
-                    token fieldToken(is);
+                    tensor vs
+                    (
+                        l[0], l[1], l[2],
+                        l[3], l[4], l[5],
+                        l[6], l[7], l[8]
+                    );
 
-                    if (!fieldToken.isPunctuation())
-                    {
-                        scalarFields_.insert
+                    tensorFields_.insert
+                    (
+                        key,
+                        autoPtr<tensorField>::New
                         (
-                            key,
-                            autoPtr<scalarField>::New
-                            (
-                                this->size(),
-                                fieldToken.number()
-                            )
-                        );
-                    }
-                    else
-                    {
-                        // Read as scalarList.
-                        is.putBack(fieldToken);
-
-                        scalarList l(is);
-
-                        if (l.size() == vector::nComponents)
-                        {
-                            vector vs(l[0], l[1], l[2]);
-
-                            vectorFields_.insert
-                            (
-                                key,
-                                autoPtr<vectorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == sphericalTensor::nComponents)
-                        {
-                            sphericalTensor vs(l[0]);
-
-                            sphTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<sphericalTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == symmTensor::nComponents)
-                        {
-                            symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
-
-                            symmTensorFields_.insert
-                            (
-                                key,
-                                autoPtr<symmTensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else if (l.size() == tensor::nComponents)
-                        {
-                            tensor vs
-                            (
-                                l[0], l[1], l[2],
-                                l[3], l[4], l[5],
-                                l[6], l[7], l[8]
-                            );
-
-                            tensorFields_.insert
-                            (
-                                key,
-                                autoPtr<tensorField>::New
-                                (
-                                    this->size(),
-                                    vs
-                                )
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    unrecognised native type " << l
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-                    }
+                            patchSize,
+                            vs
+                        )
+                    );
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    unrecognised native type " << l
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
                 }
             }
         }
@@ -705,46 +697,42 @@ void Foam::genericFvsPatchField<Type>::write(Ostream& os) const
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type" && key != "value")
+        if (key == "type" || key == "value")
         {
-            if
-            (
-                dEntry.isStream()
-             && dEntry.stream().size()
-             && dEntry.stream()[0].isWord()
-             && dEntry.stream()[0].wordToken() == "nonuniform"
-            )
+            continue;
+        }
+        else if
+        (
+            dEntry.isStream()
+         && dEntry.stream().size()
+         && dEntry.stream()[0].isWord()
+         && dEntry.stream()[0].wordToken() == "nonuniform"
+        )
+        {
+            if (scalarFields_.found(key))
             {
-                if (scalarFields_.found(key))
-                {
-                    scalarFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (vectorFields_.found(key))
-                {
-                    vectorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (sphTensorFields_.found(key))
-                {
-                    sphTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (symmTensorFields_.found(key))
-                {
-                    symmTensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
-                else if (tensorFields_.found(key))
-                {
-                    tensorFields_.find(key)()
-                        ->writeEntry(key, os);
-                }
+                scalarFields_.cfind(key)()->writeEntry(key, os);
             }
-            else
+            else if (vectorFields_.found(key))
             {
-                dEntry.write(os);
+                vectorFields_.cfind(key)()->writeEntry(key, os);
             }
+            else if (sphTensorFields_.found(key))
+            {
+                sphTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (symmTensorFields_.found(key))
+            {
+                symmTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (tensorFields_.found(key))
+            {
+                tensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+        }
+        else
+        {
+            dEntry.write(os);
         }
     }
 
diff --git a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C
index 264bf187287ae4b861e6eec285097fd20b543da3..aee5b2337a65e11fa86688212a62b44401c25155 100644
--- a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C
+++ b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -55,242 +55,234 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
     actualTypeName_(dict.get<word>("type")),
     dict_(dict)
 {
+    const label patchSize = this->size();
+
     for (const entry& dEntry : dict_)
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type")
+        if
+        (
+            key == "type"
+         || !dEntry.isStream() || dEntry.stream().empty()
+        )
         {
-            if
-            (
-                dEntry.isStream()
-             && dEntry.stream().size()
-            )
-            {
-                ITstream& is = dEntry.stream();
+            continue;
+        }
 
-                // Read first token
-                token firstToken(is);
 
+        ITstream& is = dEntry.stream();
+
+        // Read first token
+        token firstToken(is);
+
+        if
+        (
+            firstToken.isWord()
+         && firstToken.wordToken() == "nonuniform"
+        )
+        {
+            token fieldToken(is);
+
+            if (!fieldToken.isCompound())
+            {
                 if
                 (
-                    firstToken.isWord()
-                 && firstToken.wordToken() == "nonuniform"
+                    fieldToken.isLabel()
+                 && fieldToken.labelToken() == 0
                 )
                 {
-                    token fieldToken(is);
-
-                    if (!fieldToken.isCompound())
-                    {
-                        if
-                        (
-                            fieldToken.isLabel()
-                         && fieldToken.labelToken() == 0
-                        )
-                        {
-                            scalarFields_.insert
-                            (
-                                key,
-                                autoPtr<scalarField>::New()
-                            );
-                        }
-                        else
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    token following 'nonuniform' "
-                                   "is not a compound"
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                            << exit(FatalIOError);
-                        }
-                    }
-                    else if
+                    scalarFields_.insert(key, autoPtr<scalarField>::New());
+                }
+                else
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    token following 'nonuniform' "
+                           "is not a compound"
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<scalar>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<scalarField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<scalar>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<scalar>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<scalarField>::New();
-
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<scalar>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        scalarFields_.insert(key, fPtr);
-                    }
-                    else if
+                );
+
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                scalarFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<vector>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<vectorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<vector>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<vector>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<vectorField>::New();
-
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<vector>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        vectorFields_.insert(key, fPtr);
-                    }
-                    else if
+                );
+
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                vectorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<sphericalTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<sphericalTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<sphericalTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<sphericalTensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<sphericalTensorField>::New();
-
-                        fPtr->transfer
-                        (
-                            dynamicCast
-                            <
-                                token::Compound<List<sphericalTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        sphTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                );
+
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                sphTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<symmTensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<symmTensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<symmTensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<symmTensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<symmTensorField>::New();
-
-                        fPtr->transfer
-                        (
-                            dynamicCast
-                            <
-                                token::Compound<List<symmTensor>>
-                            >
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        symmTensorFields_.insert(key, fPtr);
-                    }
-                    else if
+                );
+
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
+                }
+
+                symmTensorFields_.insert(key, fPtr);
+            }
+            else if
+            (
+                fieldToken.compoundToken().type()
+             == token::Compound<List<tensor>>::typeName
+            )
+            {
+                auto fPtr = autoPtr<tensorField>::New();
+
+                fPtr->transfer
+                (
+                    dynamicCast<token::Compound<List<tensor>>>
                     (
-                        fieldToken.compoundToken().type()
-                     == token::Compound<List<tensor>>::typeName
+                        fieldToken.transferCompoundToken(is)
                     )
-                    {
-                        auto fPtr = autoPtr<tensorField>::New();
-
-                        fPtr->transfer
-                        (
-                            dynamicCast<token::Compound<List<tensor>>>
-                            (
-                                fieldToken.transferCompoundToken(is)
-                            )
-                        );
-
-                        if (fPtr->size() != this->size())
-                        {
-                            FatalIOErrorInFunction(dict)
-                                << "\n    size of field " << key
-                                << " (" << fPtr->size() << ')'
-                                << " is not the same size as the patch ("
-                                << this->size() << ')'
-                                << "\n    on patch " << this->patch().name()
-                                << " of field "
-                                << this->internalField().name()
-                                << " in file "
-                                << this->internalField().objectPath()
-                                << exit(FatalIOError);
-                        }
-
-                        tensorFields_.insert(key, fPtr);
-                    }
-                    else
-                    {
-                        FatalIOErrorInFunction(dict)
-                            << "\n    compound " << fieldToken.compoundToken()
-                            << " not supported"
-                            << "\n    on patch " << this->patch().name()
-                            << " of field "
-                            << this->internalField().name()
-                            << " in file "
-                            << this->internalField().objectPath()
-                            << exit(FatalIOError);
-                    }
+                );
+
+                if (fPtr->size() != patchSize)
+                {
+                    FatalIOErrorInFunction(dict)
+                        << "\n    size of field " << key
+                        << " (" << fPtr->size() << ')'
+                        << " is not the same size as the patch ("
+                        << patchSize << ')'
+                        << "\n    on patch " << this->patch().name()
+                        << " of field "
+                        << this->internalField().name()
+                        << " in file "
+                        << this->internalField().objectPath() << nl
+                        << exit(FatalIOError);
                 }
+
+                tensorFields_.insert(key, fPtr);
+            }
+            else
+            {
+                FatalIOErrorInFunction(dict)
+                    << "\n    compound " << fieldToken.compoundToken()
+                    << " not supported"
+                    << "\n    on patch " << this->patch().name()
+                    << " of field "
+                    << this->internalField().name()
+                    << " in file "
+                    << this->internalField().objectPath() << nl
+                    << exit(FatalIOError);
             }
         }
     }
@@ -488,41 +480,42 @@ void Foam::genericPointPatchField<Type>::write(Ostream& os) const
     {
         const keyType& key = dEntry.keyword();
 
-        if (key != "type")
+        if (key == "type" || key == "value")
         {
-            if
-            (
-                dEntry.isStream()
-             && dEntry.stream().size()
-             && dEntry.stream()[0].isWord()
-             && dEntry.stream()[0].wordToken() == "nonuniform"
-            )
+            continue;
+        }
+        else if
+        (
+            dEntry.isStream()
+         && dEntry.stream().size()
+         && dEntry.stream()[0].isWord()
+         && dEntry.stream()[0].wordToken() == "nonuniform"
+        )
+        {
+            if (scalarFields_.found(key))
             {
-                if (scalarFields_.found(key))
-                {
-                    scalarFields_.find(key)()->writeEntry(key, os);
-                }
-                else if (vectorFields_.found(key))
-                {
-                    vectorFields_.find(key)()->writeEntry(key, os);
-                }
-                else if (sphTensorFields_.found(key))
-                {
-                    sphTensorFields_.find(key)()->writeEntry(key, os);
-                }
-                else if (symmTensorFields_.found(key))
-                {
-                    symmTensorFields_.find(key)()->writeEntry(key, os);
-                }
-                else if (tensorFields_.found(key))
-                {
-                    tensorFields_.find(key)()->writeEntry(key, os);
-                }
+                scalarFields_.cfind(key)()->writeEntry(key, os);
             }
-            else
+            else if (vectorFields_.found(key))
             {
-                dEntry.write(os);
+                vectorFields_.cfind(key)()->writeEntry(key, os);
             }
+            else if (sphTensorFields_.found(key))
+            {
+                sphTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (symmTensorFields_.found(key))
+            {
+                symmTensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+            else if (tensorFields_.found(key))
+            {
+                tensorFields_.cfind(key)()->writeEntry(key, os);
+            }
+        }
+        else
+        {
+            dEntry.write(os);
         }
     }
 }
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
index 6518115a1331057dcc1d4e9af16138802e2ff24e..c8269b51d816c5982db7473229247604705f9c62 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
@@ -3916,7 +3916,7 @@ void Foam::snappyLayerDriver::addLayers
                     else
                     {
                         Perr<< "\nFOAM exiting\n" << endl;
-                        ::exit(0);
+                        std::exit(0);
                     }
                 }
             }
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
index 5ef4d1d974c53bea1833330964b14e381708745e..06509433232473b879911b33b3ca793185094735 100644
--- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
@@ -253,8 +253,17 @@ void Foam::PatchFunction1Types::ConstantField<Type>::writeData
 ) const
 {
     PatchFunction1<Type>::writeData(os);
-    //os  << token::SPACE << value_ << token::END_STATEMENT << nl;
-    value_.writeEntry(this->name_, os);
+
+    if (isUniform_)
+    {
+        os.writeKeyword(this->name_)
+            << "constant " << uniformValue_
+            << token::END_STATEMENT << nl;
+    }
+    else
+    {
+        value_.writeEntry(this->name_, os);
+    }
 }
 
 
diff --git a/src/parallel/decompose/Allwmake b/src/parallel/decompose/Allwmake
index b745c6a503293b54dae3fb0a5c4018d81565743c..ea5369a94cb2edece7ae44308cda1b20a0b75bb4 100755
--- a/src/parallel/decompose/Allwmake
+++ b/src/parallel/decompose/Allwmake
@@ -41,7 +41,8 @@ wmakeLnInclude -u decompositionMethods
 if have_scotch
 then
     wmake $targetType scotchDecomp
-    if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
+
+    if have_ptscotch
     then
         wmakeMpiLib "$SCOTCH_VERSION" ptscotchDecomp
     fi
diff --git a/src/parallel/decompose/ptscotchDecomp/Make/options b/src/parallel/decompose/ptscotchDecomp/Make/options
index 8cd4aa7b582c41172be2877b6994b4ed885513ef..42e41f81462e205aec209775911409470676466a 100644
--- a/src/parallel/decompose/ptscotchDecomp/Make/options
+++ b/src/parallel/decompose/ptscotchDecomp/Make/options
@@ -1,13 +1,12 @@
 /*
- * NB: mplib PINC must appear after the SCOTCH_ARCH_PATH/include/FOAM_MPI
- * to ensure we do not accidentally get a ptscotch header from the
- * mpi distribution.
+ * NB: mplib PINC must appear after PTSCOTCH_INC_DIR to ensure we
+ * do not accidentally get a ptscotch header from the MPI distribution.
  */
 sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB)
 sinclude $(DEFAULT_RULES)/mplib$(WM_MPLIB)
 
 EXE_INC = \
-    -I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \
+    -I$(PTSCOTCH_INC_DIR) \
     -I$(SCOTCH_INC_DIR) \
     $(PFLAGS) $(PINC) \
     -I../decompositionMethods/lnInclude
@@ -17,9 +16,8 @@ EXE_INC = \
  * ptscotch 6 requires scotch linked in, but does not declare the dependency
  */
 LIB_LIBS = \
+    -L$(PTSCOTCH_LIB_DIR) \
     -L$(SCOTCH_LIB_DIR) \
-    -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) \
-    -L$(FOAM_EXT_LIBBIN) \
     -lptscotch -lptscotcherrexit \
     -lscotch
 
diff --git a/src/surfMesh/writers/surfaceWriter.C b/src/surfMesh/writers/surfaceWriter.C
index d910897c9deff92272b720185922134e95905631..2198ff13865c1b172e3c75c02bd5b69f8a100008 100644
--- a/src/surfMesh/writers/surfaceWriter.C
+++ b/src/surfMesh/writers/surfaceWriter.C
@@ -384,9 +384,11 @@ bool Foam::surfaceWriter::expire()
 
     upToDate_ = false;
     wroteGeom_ = false;
-    nFields_ = 0;
     merged_.clear();
 
+    // Field count (nFields_) is a different type of accounting
+    // and is unaffected by geometry changes
+
     return changed;
 }
 
diff --git a/tutorials/basic/overLaplacianDyMFoam/heatTransfer/system/controlDict b/tutorials/basic/overLaplacianDyMFoam/heatTransfer/system/controlDict
index 2d9534c1a709cfde4afcc977fe1562ecfebec140..17c38062ffb8e7bca9ac82d7fac5d7ea11575adb 100644
--- a/tutorials/basic/overLaplacianDyMFoam/heatTransfer/system/controlDict
+++ b/tutorials/basic/overLaplacianDyMFoam/heatTransfer/system/controlDict
@@ -15,7 +15,7 @@ FoamFile
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Make sure all preprocessing tools know about the 'overset' bc
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overLaplacianDyMFoam;
 
diff --git a/tutorials/basic/overPotentialFoam/cylinder/cylinderAndBackground/system/controlDict b/tutorials/basic/overPotentialFoam/cylinder/cylinderAndBackground/system/controlDict
index 616dc8689cdb366dc58a2ca439887797c47e6ed4..289864eb29f9782ae156aee632c2309cd73f393c 100644
--- a/tutorials/basic/overPotentialFoam/cylinder/cylinderAndBackground/system/controlDict
+++ b/tutorials/basic/overPotentialFoam/cylinder/cylinderAndBackground/system/controlDict
@@ -16,7 +16,7 @@ FoamFile
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Make sure all preprocessing tools know about the 'overset' bc
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overPotentialFoam;
 
diff --git a/tutorials/compressible/overRhoPimpleDyMFoam/twoSimpleRotors/system/controlDict b/tutorials/compressible/overRhoPimpleDyMFoam/twoSimpleRotors/system/controlDict
index e620aa088272bff3bf79d62d960b7c5c67698d80..505268dcae2d656dcf2297af508346acaa3920ab 100644
--- a/tutorials/compressible/overRhoPimpleDyMFoam/twoSimpleRotors/system/controlDict
+++ b/tutorials/compressible/overRhoPimpleDyMFoam/twoSimpleRotors/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 DebugSwitches
 {
diff --git a/tutorials/compressible/overRhoSimpleFoam/hotCylinder/cylinderAndBackground/system/controlDict b/tutorials/compressible/overRhoSimpleFoam/hotCylinder/cylinderAndBackground/system/controlDict
index aa6fb00c88ed1580ee1de1a2b5634dd16269a72b..914f5d96784b625d4cf862d6004f5c4d9a585d9a 100644
--- a/tutorials/compressible/overRhoSimpleFoam/hotCylinder/cylinderAndBackground/system/controlDict
+++ b/tutorials/compressible/overRhoSimpleFoam/hotCylinder/cylinderAndBackground/system/controlDict
@@ -16,7 +16,7 @@ FoamFile
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Make sure all preprocessing tools know about the 'overset' bc
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overRhoSimpleFoam;
 
diff --git a/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/system/controlDict b/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/system/controlDict
index e7ce36f33b9c1f8f9804b50a7c83d1a9fdee02ad..9617cc01b87447c47808e29f2614540ffb0dfacf 100644
--- a/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/system/controlDict
+++ b/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/system/controlDict
@@ -16,7 +16,7 @@ FoamFile
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overPimpleDyMFoam;
 
diff --git a/tutorials/incompressible/overPimpleDyMFoam/simpleRotor/system/controlDict b/tutorials/incompressible/overPimpleDyMFoam/simpleRotor/system/controlDict
index a9099f27a773b4e5deccd9df28ec45b27fdb6f8e..97e9382d04a1f9910312e6a54a7da1fe2d6f7c27 100644
--- a/tutorials/incompressible/overPimpleDyMFoam/simpleRotor/system/controlDict
+++ b/tutorials/incompressible/overPimpleDyMFoam/simpleRotor/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overPimpleDyMFoam;
 
diff --git a/tutorials/incompressible/overPimpleDyMFoam/twoSimpleRotors/system/controlDict b/tutorials/incompressible/overPimpleDyMFoam/twoSimpleRotors/system/controlDict
index 51a08718769ab3d3d991c372df0f45e546d8623a..0d7803055c57e69b6fd44da7389622b3d8f6052a 100644
--- a/tutorials/incompressible/overPimpleDyMFoam/twoSimpleRotors/system/controlDict
+++ b/tutorials/incompressible/overPimpleDyMFoam/twoSimpleRotors/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 DebugSwitches
 {
diff --git a/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/system/controlDict b/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/system/controlDict
index a4aa61f505e8f71be7fcd57e3f81b2e81605b8a6..0a0adcbdd871649265bd460a3de903bde809156e 100644
--- a/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/system/controlDict
+++ b/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overSimpleFoam;
 
diff --git a/tutorials/multiphase/overInterDyMFoam/boatAndPropeller/system/controlDict b/tutorials/multiphase/overInterDyMFoam/boatAndPropeller/system/controlDict
index 20511197e005f14962ea36b521d76c634fd7f854..425b7a91c28cadcf10b4e005f5679d1b217b65cb 100644
--- a/tutorials/multiphase/overInterDyMFoam/boatAndPropeller/system/controlDict
+++ b/tutorials/multiphase/overInterDyMFoam/boatAndPropeller/system/controlDict
@@ -15,7 +15,12 @@ FoamFile
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 
-libs            ("liboverset.so" "librigidBodyDynamics.so");
+libs
+(
+    "liboverset.so"
+    "librigidBodyDynamics.so"
+    "libfvMotionSolvers.so"
+);
 
 application     overInterDyMFoam;
 
diff --git a/tutorials/multiphase/overInterDyMFoam/floatingBody/background/system/controlDict b/tutorials/multiphase/overInterDyMFoam/floatingBody/background/system/controlDict
index 26ce8daf7131dfd3b7cf35cb71c267bcbac6b668..7b6ac034bf566e54d1c739ceb38eecca0212f944 100644
--- a/tutorials/multiphase/overInterDyMFoam/floatingBody/background/system/controlDict
+++ b/tutorials/multiphase/overInterDyMFoam/floatingBody/background/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 application     overInterDyMFoam ;
 
diff --git a/tutorials/multiphase/overInterDyMFoam/twoSimpleRotors/system/controlDict b/tutorials/multiphase/overInterDyMFoam/twoSimpleRotors/system/controlDict
index 68a9ed9a5abcaccb77825147d39cea89599d902b..5d9e79b06424daf920a0175e04cb693474cac821 100644
--- a/tutorials/multiphase/overInterDyMFoam/twoSimpleRotors/system/controlDict
+++ b/tutorials/multiphase/overInterDyMFoam/twoSimpleRotors/system/controlDict
@@ -14,7 +14,7 @@ FoamFile
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-libs            ("liboverset.so");
+libs            ("liboverset.so" "libfvMotionSolvers.so");
 
 DebugSwitches
 {
diff --git a/wmake/makefiles/general b/wmake/makefiles/general
index 198e5c1e59a3eb6c7b56fca8a0be5d902fbd127a..2177e89a87c2b73e5d99726b6f95b0cbf9c9f161 100644
--- a/wmake/makefiles/general
+++ b/wmake/makefiles/general
@@ -175,7 +175,7 @@ lib: $(LIB).a | silent
 $(LIB).a: $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(LIB)
 	@rm -f $(LIB).a
-	$(call QUIET_MESSAGE,ar,$(LIB))
+	$(call QUIET_MESSAGE,ar,$(LIB).a)
 	$E $(AR) $(ARFLAGS) $(LIB).a $(OBJECTS)
 	$(call QUIET_MESSAGE,ranlib,$(notdir $(LIB)))
 	$E $(RANLIB) $(LIB).a
diff --git a/wmake/makefiles/info b/wmake/makefiles/info
index 90fa2b550df45c70030d48dda837ca346a36ffc4..c43841dcf71c531985dedc800e7eccb2ff08c78a 100644
--- a/wmake/makefiles/info
+++ b/wmake/makefiles/info
@@ -31,6 +31,13 @@ SHELL   = /bin/sh
 .SUFFIXES:
 
 
+#------------------------------------------------------------------------------
+# Some default values
+#------------------------------------------------------------------------------
+
+# Shared library extension (with '.' separator)
+EXT_SO  = .so
+
 #------------------------------------------------------------------------------
 # Compilation rules
 #------------------------------------------------------------------------------
@@ -38,37 +45,44 @@ SHELL   = /bin/sh
 GENERAL_RULES = $(WM_DIR)/rules/General
 include $(GENERAL_RULES)/general
 
+# Commands
+COMPILE_C    := $(strip $(cc) $(cFLAGS))
+COMPILE_CXX  := $(strip $(CC) $(c++FLAGS))
 
 #------------------------------------------------------------------------------
 # Display information
 #------------------------------------------------------------------------------
 
-export WM_VERSION
-
-
-.PHONY: compile
-compile:
-	@echo "$(strip $(CC) $(c++FLAGS))"
-
 .PHONY: api
 api:
-	@echo "$${WM_VERSION#*=}"
+	@echo "$(lastword $(subst =, ,$(WM_VERSION)))"
+
+.PHONY: ext-so
+ext-so:
+	@echo "$(EXT_SO)"
+
+.PHONY: compile-c
+compile-c:
+	@echo "$(COMP_C)"
 
 .PHONY: c
 c:
-	@echo "$(strip $(cc))"
+	@echo "$(firstword $(cc))"
 
 .PHONY: cflags
 cflags:
-	@echo "$(strip $(cFLAGS))"
+	@echo "$(wordlist 2,$(words $(COMPILE_C)), $(COMPILE_C))"
+
+.PHONY: compile-cxx
+compile-cxx:
+	@echo "$(COMPILE_CXX)"
 
 .PHONY: cxx
 cxx:
-	@echo "$(strip $(CC))"
+	@echo "$(firstword $(CC))"
 
 .PHONY: cxxflags
 cxxflags:
-	@echo "$(strip $(c++FLAGS))"
-
+	@echo "$(wordlist 2,$(words $(COMPILE_CXX)), $(COMPILE_CXX))"
 
 #----------------------------- vim: set ft=make: ------------------------------
diff --git a/wmake/scripts/have_scotch b/wmake/scripts/have_scotch
index e25525926a28c362c602ba6287b53d9e61ebe175..8d17fa7f17f3752e95ea1f3bd4ca752637ffcada 100644
--- a/wmake/scripts/have_scotch
+++ b/wmake/scripts/have_scotch
@@ -37,6 +37,7 @@ no_scotch()
 {
     unset HAVE_SCOTCH SCOTCH_ARCH_PATH SCOTCH_INC_DIR SCOTCH_LIB_DIR
     unset SCOTCH_VERSION
+    unset HAVE_PTSCOTCH PTSCOTCH_ARCH_PATH PTSCOTCH_INC_DIR PTSCOTCH_LIB_DIR
     return 0
 }
 
@@ -48,6 +49,11 @@ echo_scotch()
     echo "root=$SCOTCH_ARCH_PATH"
     echo "include=$SCOTCH_INC_DIR"
     echo "library=$SCOTCH_LIB_DIR"
+    echo
+    echo "ptscotch=${HAVE_PTSCOTCH:-false}"
+    echo "root=$PTSCOTCH_ARCH_PATH"
+    echo "include=$PTSCOTCH_INC_DIR"
+    echo "library=$PTSCOTCH_LIB_DIR"
 }
 
 
@@ -177,13 +183,105 @@ have_scotch()
 }
 
 
+# Must be called after have_scotch!
+#
+# On success, return 0 and export variables
+# -> HAVE_PTSCOTCH, PTSCOTCH_ARCH_PATH, PTSCOTCH_INC_DIR, PTSCOTCH_LIB_DIR
+have_ptscotch()
+{
+    local prefix header library static settings warn
+    warn="==> skip ptscotch"
+
+    if [ "$HAVE_SCOTCH" != true ]
+    then
+        echo "$warn (no serial scotch available?)"
+        return 1
+    fi
+
+    # Reuse old settings
+    [ -n "$PTSCOTCH_ARCH_PATH" ] || PTSCOTCH_ARCH_PATH="$SCOTCH_ARCH_PATH"
+
+    # Location
+    prefix="$PTSCOTCH_ARCH_PATH"
+
+    # Header/library names
+    header="ptscotch.h"
+    library="libptscotch$extLibso"
+    static="libptscotch$extLiba"
+
+    # ----------------------------------
+    if isNone "$prefix"
+    then
+        [ -n "$warn" ] && echo "$warn (disabled)"
+        return 1
+    elif hasAbsdir "$prefix"
+    then
+        header=$(findFirstFile  \
+            "$prefix/include/$FOAM_MPI/$header" \
+            "$prefix/include/$header"
+        )
+
+        library=$(findFirstFile \
+            "$(thirdExtLib $FOAM_MPI/$library)" \
+            "$(thirdExtLib $library)" \
+            "$prefix/lib/$static" \
+            "$prefix/lib/$library" \
+            "$prefix/lib$WM_COMPILER_LIB_ARCH/$static" \
+            "$prefix/lib$WM_COMPILER_LIB_ARCH/$library" \
+        )
+
+    elif isSystem "$prefix"
+    then
+        prefix=/usr
+
+        header=$(findFirstFile \
+            "/usr/local/include/ptscotch/$header" \
+            "/usr/local/include/scotch/$header" \
+            "/usr/local/include/$header" \
+            "/usr/include/ptscotch/$header" \
+            "/usr/include/scotch/$header" \
+            "/usr/include/$header" \
+        )
+
+        case "$header" in (/usr/local/*) prefix=/usr/local ;; esac
+
+        library=$(findFirstFile \
+            "$prefix/lib/$library" \
+            "$prefix/lib$WM_COMPILER_LIB_ARCH/$library" \
+        )
+    else
+        unset prefix header library
+    fi
+    # ----------------------------------
+
+    # Header found?
+    [ -n "$header" ] || {
+        [ -n "$warn" ] && echo "$warn (no header)"
+        return 2
+    }
+
+    # Library found?
+    [ -n "$library" ] || {
+        [ -n "$warn" ] && echo "$warn (no library)"
+        return 2
+    }
+
+    # OK
+    echo "ptscotch - $prefix"
+    export HAVE_PTSCOTCH=true
+    export PTSCOTCH_ARCH_PATH="$prefix"
+    export PTSCOTCH_INC_DIR="${header%/*}"     # Basename
+    export PTSCOTCH_LIB_DIR="${library%/*}"    # Basename
+}
+
+
 # Force reset of old variables
 no_scotch
 
 # Testing
 if [ "$1" = "-test" ]
 then
-    have_scotch
+    have_scotch && have_ptscotch
     echo_scotch
 fi
 
diff --git a/wmake/scripts/sysFunctions b/wmake/scripts/sysFunctions
index 30de032b90af4e91e182062270bd043d654436f5..a11f58c3c4eca62657a23683ce52853a9febc73a 100644
--- a/wmake/scripts/sysFunctions
+++ b/wmake/scripts/sysFunctions
@@ -48,14 +48,20 @@ then
     esac
 
 
-    # True if OS is Darwin.
-    # Uses libso extension to cache the value
-    # (instead of calling 'uname -s' each time)
+    # True if target OS is Darwin.
+    # Uses cached value from libso extension
     isDarwin()
     {
         test "$extLibso" = ".dylib"
     }
 
+    # True if target OS is Windows
+    # Uses cached value from libso extension
+    isWindows()
+    {
+        test "$extLibso" = ".dll"
+    }
+
 
     # True if '$1' begins with '/'
     isAbsdir()
diff --git a/wmake/wmake b/wmake/wmake
index 7591fc94512939c7335ca0f287a49311cbcd3925..71ecf5ccb6fd301d861e6b69263d3a77881f5403 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -70,18 +70,20 @@ options:
   -s | -silent      Quiet mode (does not echo commands)
   -a | -all         wmake all sub-directories, running Allwmake if present
   -q | -queue       wmakeCollect all sub-directories, running Allwmake if present
-  -k | -keep-going  Keep going without stopping when errors occur (-non-stop)
+  -k | -keep-going  Keep going even when errors occur (-non-stop)
   -j                Compile using all local cores/hyperthreads
-  -jN or -j N       Compile using N cores/hyperthreads
+  -jN | -j N        Compile using N cores/hyperthreads
   -no-scheduler     Disable scheduled parallel compilation
-  -pwd              Print root directory containing a Make/ directory and exit
-  -update           Update lnInclude directories, dep files, remove deprecated
-                    files and directories
-  -show             Identical to -show-compile
-  -show-api         Print api value and exit
-  -show-compile     Print C++ compiler value/flags and exit
-  -show-cxx         Print C++ compiler value and exit
-  -show-cxxflags    Print C++ compiler flags and exit
+  -pwd              Print root directory containing a Make/ directory
+  -update           Update lnInclude dirs, dep files, remove deprecated files/dirs
+  -show-api         Print api value
+  -show-ext-so      Print shared library extension (with '.' separator)
+  -show-compile-c   Same as '-show-c -show-cflags'
+  -show-compile-cxx Same as '-show-cxx -show-cxxflags'
+  -show-c           Print C compiler value
+  -show-cflags      Print C compiler flags
+  -show-cxx         Print C++ compiler value
+  -show-cxxflags    Print C++ compiler flags
   -h | -help        Print the usage
 
 
@@ -138,11 +140,9 @@ do
         -s | -silent)
             export WM_QUIET=true
             ;;
-        -show | -show-compile)
-            $make -f $WM_DIR/makefiles/info compile
-            optShow=true
-            ;;
-        -show-api | -show-cxx | -show-cxxflags | -show-c | -show-cflags)
+        -show-api | -show-ext-so | \
+        -show-compile-c | -show-c | -show-cflags | \
+        -show-compile-cxx | -show-cxx | -show-cxxflags)
             $make -f $WM_DIR/makefiles/info "${1#-show-}"
             optShow=true
             ;;