From 4cbe0a81ac027f18b10d4890bb29ea54ab9671a2 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 7 Apr 2022 21:08:18 +0200
Subject: [PATCH] ENH: consolidate read handling within various regIOobjects

---
 .../IOobjects/CompactIOList/CompactIOList.C   | 59 +++++-------
 .../IOobjects/CompactIOList/CompactIOList.H   | 16 +++-
 src/OpenFOAM/db/IOobjects/IOField/IOField.C   | 93 ++++++-------------
 src/OpenFOAM/db/IOobjects/IOField/IOField.H   | 15 ++-
 src/OpenFOAM/db/IOobjects/IOList/IOList.C     | 75 ++++++---------
 src/OpenFOAM/db/IOobjects/IOList/IOList.H     | 15 ++-
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.C       | 82 ++++++----------
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.H       | 15 ++-
 .../mapDistribute/IOmapDistribute.C           | 58 +++++-------
 .../mapDistribute/IOmapDistribute.H           | 19 ++--
 .../mapDistribute/IOmapDistributePolyMesh.C   | 61 +++++-------
 .../mapDistribute/IOmapDistributePolyMesh.H   | 19 ++--
 .../polyBoundaryMesh/polyBoundaryMesh.C       | 86 +++++++----------
 .../polyBoundaryMesh/polyBoundaryMesh.H       |  3 +
 .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C | 14 ++-
 .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H |  8 +-
 .../hexRef8/refinementHistory.C               | 74 ++++++---------
 .../hexRef8/refinementHistory.H               |  3 +
 .../polyTopoChanger/polyTopoChanger.C         | 14 +--
 .../polyTopoChanger/polyTopoChanger.H         |  9 +-
 .../faMesh/faBoundaryMesh/faBoundaryMesh.C    | 41 +++++---
 .../faMesh/faBoundaryMesh/faBoundaryMesh.H    |  3 +
 .../coordinate/systems/coordinateSystems.C    | 17 ++--
 .../coordinate/systems/coordinateSystems.H    | 12 +--
 24 files changed, 354 insertions(+), 457 deletions(-)

diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
index a614641777d..fcedb1ced5c 100644
--- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
+++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -58,6 +58,23 @@ void Foam::CompactIOList<T, BaseType>::readFromStream()
 }
 
 
+template<class T, class BaseType>
+bool Foam::CompactIOList<T, BaseType>::readContents()
+{
+    if
+    (
+        readOpt() == IOobject::MUST_READ
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        readFromStream();
+        return true;
+    }
+
+    return false;
+}
+
+
 template<class T, class BaseType>
 bool Foam::CompactIOList<T, BaseType>::overflows() const
 {
@@ -82,14 +99,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList(const IOobject& io)
 :
     regIOobject(io)
 {
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readFromStream();
-    }
+    readContents();
 }
 
 
@@ -102,17 +112,9 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
 :
     regIOobject(io)
 {
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readFromStream();
-    }
-    else
+    if (!readContents())
     {
-        List<T>::setSize(len);
+        List<T>::resize(len);
     }
 }
 
@@ -126,15 +128,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
 :
     regIOobject(io)
 {
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readFromStream();
-    }
-    else
+    if (!readContents())
     {
         List<T>::operator=(content);
     }
@@ -152,14 +146,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
 {
     List<T>::transfer(content);
 
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readFromStream();
-    }
+    readContents();
 }
 
 
diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H
index 555114418bb..b609985bdf1 100644
--- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H
+++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -39,8 +39,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef CompactIOList_H
-#define CompactIOList_H
+#ifndef Foam_CompactIOList_H
+#define Foam_CompactIOList_H
 
 #include "IOList.H"
 #include "regIOobject.H"
@@ -50,7 +50,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
+// Forward Declarations
 class Istream;
 class Ostream;
 template<class T, class BaseType> class CompactIOList;
@@ -81,11 +81,19 @@ class CompactIOList
         //- Read according to header type
         void readFromStream();
 
+        //- Read if IOobject flags set. Return true if read.
+        //  Reads according to the header type
+        bool readContents();
+
         //- Has too many elements in it?
         bool overflows() const;
 
+
 public:
 
+    //- The underlying content type
+    typedef List<T> content_type;
+
     //- Runtime type information
     TypeName("CompactList");
 
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.C b/src/OpenFOAM/db/IOobjects/IOField/IOField.C
index b97ef622925..af07c9e91aa 100644
--- a/src/OpenFOAM/db/IOobjects/IOField/IOField.C
+++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2018 OpenCFD Ltd.
+    Copyright (C) 2016-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,28 +28,40 @@ License
 
 #include "IOField.H"
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class Type>
-Foam::IOField<Type>::IOField(const IOobject& io)
-:
-    regIOobject(io)
+bool Foam::IOField<Type>::readContents()
 {
-    // Check for MUST_READ_IF_MODIFIED
-    warnNoRereading<IOField<Type>>();
-
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         readStream(typeName) >> *this;
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::IOField<Type>::IOField(const IOobject& io)
+:
+    regIOobject(io)
+{
+    // Check for MUST_READ_IF_MODIFIED
+    warnNoRereading<IOField<Type>>();
+
+    readContents();
 }
 
 
@@ -91,28 +103,16 @@ Foam::IOField<Type>::IOField(const IOobject& io, const bool valid)
 
 
 template<class Type>
-Foam::IOField<Type>::IOField(const IOobject& io, const label size)
+Foam::IOField<Type>::IOField(const IOobject& io, const label len)
 :
     regIOobject(io)
 {
     // Check for MUST_READ_IF_MODIFIED
     warnNoRereading<IOField<Type>>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
+    if (!readContents())
     {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
-    {
-        Field<Type>::setSize(size);
+        Field<Type>::resize(len);
     }
 }
 
@@ -125,19 +125,7 @@ Foam::IOField<Type>::IOField(const IOobject& io, const UList<Type>& content)
     // Check for MUST_READ_IF_MODIFIED
     warnNoRereading<IOField<Type>>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         Field<Type>::operator=(content);
     }
@@ -154,18 +142,7 @@ Foam::IOField<Type>::IOField(const IOobject& io, Field<Type>&& content)
 
     Field<Type>::transfer(content);
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 }
 
 
@@ -181,19 +158,7 @@ Foam::IOField<Type>::IOField(const IOobject& io, const tmp<Field<Type>>& tfld)
         Field<Type>::transfer(tfld.ref());
     }
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else if (!reuse)
+    if (!readContents() && !reuse)
     {
         Field<Type>::operator=(tfld());
     }
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.H b/src/OpenFOAM/db/IOobjects/IOField/IOField.H
index 8edee8ee108..163ee129df8 100644
--- a/src/OpenFOAM/db/IOobjects/IOField/IOField.H
+++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOField_H
-#define IOField_H
+#ifndef Foam_IOField_H
+#define Foam_IOField_H
 
 #include "regIOobject.H"
 #include "Field.H"
@@ -56,8 +56,17 @@ class IOField
     public regIOobject,
     public Field<Type>
 {
+    // Private Member Functions
+
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
+
 public:
 
+    //- The underlying content type
+    typedef Field<Type> content_type;
+
+    //- Runtime type information
     TypeName("Field");
 
 
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.C b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
index 0820e614650..9c96b75374b 100644
--- a/src/OpenFOAM/db/IOobjects/IOList/IOList.C
+++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
@@ -28,28 +28,40 @@ License
 
 #include "IOList.H"
 
-// * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class T>
-Foam::IOList<T>::IOList(const IOobject& io)
-:
-    regIOobject(io)
+bool Foam::IOList<T>::readContents()
 {
-    // Check for MUST_READ_IF_MODIFIED
-    warnNoRereading<IOList<T>>();
-
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         readStream(typeName) >> *this;
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
+
+template<class T>
+Foam::IOList<T>::IOList(const IOobject& io)
+:
+    regIOobject(io)
+{
+    // Check for MUST_READ_IF_MODIFIED
+    warnNoRereading<IOList<T>>();
+
+    readContents();
 }
 
 
@@ -61,21 +73,9 @@ Foam::IOList<T>::IOList(const IOobject& io, const label len)
     // Check for MUST_READ_IF_MODIFIED
     warnNoRereading<IOList<T>>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
-        List<T>::setSize(len);
+        List<T>::resize(len);
     }
 }
 
@@ -88,19 +88,7 @@ Foam::IOList<T>::IOList(const IOobject& io, const UList<T>& content)
     // Check for MUST_READ_IF_MODIFIED
     warnNoRereading<IOList<T>>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         List<T>::operator=(content);
     }
@@ -117,18 +105,7 @@ Foam::IOList<T>::IOList(const IOobject& io, List<T>&& content)
 
     List<T>::transfer(content);
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 }
 
 
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.H b/src/OpenFOAM/db/IOobjects/IOList/IOList.H
index c36e78ab169..86cd0a1eb77 100644
--- a/src/OpenFOAM/db/IOobjects/IOList/IOList.H
+++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOList_H
-#define IOList_H
+#ifndef Foam_IOList_H
+#define Foam_IOList_H
 
 #include "List.H"
 #include "regIOobject.H"
@@ -56,8 +56,16 @@ class IOList
     public regIOobject,
     public List<T>
 {
+    // Private Member Functions
+
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
+
 public:
 
+    //- The underlying content type
+    typedef List<T> content_type;
+
     //- Runtime type information
     TypeName("List");
 
@@ -96,7 +104,6 @@ public:
 
         //- Copy or move assignment of entries
         using List<T>::operator=;
-
 };
 
 
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
index d0b3e44e815..fc1bdd57dc7 100644
--- a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
+++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,20 +28,18 @@ License
 
 #include "IOMap.H"
 
-// * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class T>
-Foam::IOMap<T>::IOMap(const IOobject& io)
-:
-    regIOobject(io)
+bool Foam::IOMap<T>::readContents()
 {
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         // For if MUST_READ_IF_MODIFIED
@@ -49,32 +47,33 @@ Foam::IOMap<T>::IOMap(const IOobject& io)
 
         readStream(typeName) >> *this;
         close();
+
+        return true;
     }
+
+    return false;
 }
 
+
+// * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
+
 template<class T>
-Foam::IOMap<T>::IOMap(const IOobject& io, const label size)
+Foam::IOMap<T>::IOMap(const IOobject& io)
 :
     regIOobject(io)
 {
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        // For if MUST_READ_IF_MODIFIED
-        addWatch();
+    readContents();
+}
 
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+
+template<class T>
+Foam::IOMap<T>::IOMap(const IOobject& io, const label size)
+:
+    regIOobject(io)
+{
+    if (!readContents())
     {
-        Map<T>::setSize(size);
+        Map<T>::resize(size);
     }
 }
 
@@ -84,22 +83,7 @@ Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& content)
 :
     regIOobject(io)
 {
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        // For if MUST_READ_IF_MODIFIED
-        addWatch();
-
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         Map<T>::operator=(content);
     }
@@ -113,21 +97,7 @@ Foam::IOMap<T>::IOMap(const IOobject& io, Map<T>&& content)
 {
     Map<T>::transfer(content);
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        // For if MUST_READ_IF_MODIFIED
-        addWatch();
-
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 }
 
 
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
index 68fa5fe9855..ea226239c8d 100644
--- a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
+++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,8 +36,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOMap_H
-#define IOMap_H
+#ifndef Foam_IOMap_H
+#define Foam_IOMap_H
 
 #include "Map.H"
 #include "regIOobject.H"
@@ -57,8 +57,16 @@ class IOMap
     public regIOobject,
     public Map<T>
 {
+    // Private Member Functions
+
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
+
 public:
 
+    //- The underlying content type
+    typedef Map<T> content_type;
+
     //- Runtime type information
     TypeName("Map");
 
@@ -102,6 +110,7 @@ public:
             return globalFilePath(type());
         }
 
+
     // Member Operators
 
         //- Copy assignment of entries
diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C
index 802cbdbe455..98b4686a931 100644
--- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C
+++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C
@@ -36,27 +36,38 @@ namespace Foam
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-Foam::IOmapDistribute::IOmapDistribute(const IOobject& io)
-:
-    regIOobject(io)
+bool Foam::IOmapDistribute::readContents()
 {
-    // Warn for MUST_READ_IF_MODIFIED
-    warnNoRereading<IOmapDistribute>();
-
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         readStream(typeName) >> *this;
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::IOmapDistribute::IOmapDistribute(const IOobject& io)
+:
+    regIOobject(io)
+{
+    // Warn for MUST_READ_IF_MODIFIED
+    warnNoRereading<IOmapDistribute>();
+
+    readContents();
 }
 
 
@@ -71,19 +82,7 @@ Foam::IOmapDistribute::IOmapDistribute
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<IOmapDistribute>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         mapDistribute::operator=(map);
     }
@@ -103,18 +102,7 @@ Foam::IOmapDistribute::IOmapDistribute
 
     mapDistribute::transfer(map);
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 }
 
 
diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.H
index d277c5723b9..eee7b25883d 100644
--- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.H
+++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -37,8 +37,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOmapDistribute_H
-#define IOmapDistribute_H
+#ifndef Foam_IOmapDistribute_H
+#define Foam_IOmapDistribute_H
 
 #include "mapDistribute.H"
 #include "regIOobject.H"
@@ -57,6 +57,10 @@ class IOmapDistribute
     public regIOobject,
     public mapDistribute
 {
+    // Private Member Functions
+
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
 
 public:
 
@@ -65,13 +69,13 @@ public:
 
     // Constructors
 
-        //- Construct given an IOobject
+        //- Construct from IOobject
         IOmapDistribute(const IOobject& io);
 
-        //- Construct given an IOobject, copying mapDistribute contents
+        //- Construct from IOobject, copying mapDistribute contents
         IOmapDistribute(const IOobject& io, const mapDistribute& map);
 
-        //- Construct, moving mapDistribute contents
+        //- Construct from IOobject, moving mapDistribute contents
         IOmapDistribute(const IOobject& io, mapDistribute&& map);
 
 
@@ -79,14 +83,13 @@ public:
     virtual ~IOmapDistribute() = default;
 
 
-    // Member functions
+    // Member Functions
 
         //- ReadData function required for regIOobject read operation
         virtual bool readData(Istream&);
 
         //- WriteData function required for regIOobject write operation
         virtual bool writeData(Ostream&) const;
-
 };
 
 
diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.C
index cc0992cb232..2af120a3d0f 100644
--- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2015 OpenFOAM Foundation
+    Copyright (C) 2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -31,31 +32,42 @@ License
 
 namespace Foam
 {
-defineTypeNameAndDebug(IOmapDistributePolyMesh, 0);
+    defineTypeNameAndDebug(IOmapDistributePolyMesh, 0);
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh(const IOobject& io)
-:
-    regIOobject(io)
+bool Foam::IOmapDistributePolyMesh::readContents()
 {
-    // Warn for MUST_READ_IF_MODIFIED
-    warnNoRereading<IOmapDistributePolyMesh>();
-
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         readStream(typeName) >> *this;
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh(const IOobject& io)
+:
+    regIOobject(io)
+{
+    // Warn for MUST_READ_IF_MODIFIED
+    warnNoRereading<IOmapDistributePolyMesh>();
+
+    readContents();
 }
 
 
@@ -70,19 +82,7 @@ Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<IOmapDistributePolyMesh>();
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         mapDistributePolyMesh::operator=(map);
     }
@@ -102,18 +102,7 @@ Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh
 
     mapDistributePolyMesh::transfer(map);
 
-    if
-    (
-        (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-        )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 }
 
 
diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.H
index 4ac988a5b33..46d326006eb 100644
--- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.H
+++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistributePolyMesh.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2015 OpenFOAM Foundation
+    Copyright (C) 2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,8 +37,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOmapDistributePolyMesh_H
-#define IOmapDistributePolyMesh_H
+#ifndef Foam_IOmapDistributePolyMesh_H
+#define Foam_IOmapDistributePolyMesh_H
 
 #include "mapDistributePolyMesh.H"
 #include "regIOobject.H"
@@ -56,25 +57,30 @@ class IOmapDistributePolyMesh
     public regIOobject,
     public mapDistributePolyMesh
 {
+    // Private Member Functions
+
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
 
 public:
 
     //- Runtime type information
     TypeName("mapDistributePolyMesh");
 
+
     // Constructors
 
-        //- Construct given an IOobject
-        IOmapDistributePolyMesh(const IOobject& io);
+        //- Construct from IOobject
+        explicit IOmapDistributePolyMesh(const IOobject& io);
 
-        //- Construct given an IOobject and mapDistributePolyMesh
+        //- Construct from IOobject, copying mapDistributePolyMesh contents
         IOmapDistributePolyMesh
         (
             const IOobject& io,
             const mapDistributePolyMesh& map
         );
 
-        //- Construct given an IOobject and mapDistributePolyMesh
+        //- Construct from IOobject, moving mapDistributePolyMesh contents
         IOmapDistributePolyMesh
         (
             const IOobject& io,
@@ -93,7 +99,6 @@ public:
 
         //- The writeData method for regIOobject write operation
         virtual bool writeData(Ostream& os) const;
-
 };
 
 
diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C
index d71112b0dad..507c2231070 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C
@@ -107,22 +107,17 @@ void Foam::polyBoundaryMesh::calcGroupIDs() const
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::polyBoundaryMesh::polyBoundaryMesh
-(
-    const IOobject& io,
-    const polyMesh& mesh
-)
-:
-    polyPatchList(),
-    regIOobject(io),
-    mesh_(mesh)
+bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent)
 {
     if
     (
-        readOpt() == IOobject::MUST_READ
-     || readOpt() == IOobject::MUST_READ_IF_MODIFIED
+        this->readOpt() == IOobject::MUST_READ
+     || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
+     ||
+        (
+            allowReadIfPresent
+         && (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
+        )
     )
     {
         // Warn for MUST_READ_IF_MODIFIED
@@ -133,9 +128,11 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
         // Read polyPatchList
         Istream& is = readStream(typeName);
 
+        // Read patches as entries
         PtrList<entry> patchEntries(is);
-        patches.setSize(patchEntries.size());
+        patches.resize(patchEntries.size());
 
+        // Transcribe
         forAll(patches, patchi)
         {
             patches.set
@@ -152,9 +149,27 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
         }
 
         is.check(FUNCTION_NAME);
-
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::polyBoundaryMesh::polyBoundaryMesh
+(
+    const IOobject& io,
+    const polyMesh& mesh
+)
+:
+    polyPatchList(),
+    regIOobject(io),
+    mesh_(mesh)
+{
+    readContents(false);  // READ_IF_PRESENT allowed: False
 }
 
 
@@ -182,47 +197,10 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
     regIOobject(io),
     mesh_(pm)
 {
-    if
-    (
-        (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
-     || this->readOpt() == IOobject::MUST_READ
-     || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
-    )
-    {
-        // Warn for MUST_READ_IF_MODIFIED
-        warnNoRereading<polyBoundaryMesh>();
-
-        polyPatchList& patches = *this;
-
-        // Read polyPatchList
-        Istream& is = readStream(typeName);
-
-        PtrList<entry> patchEntries(is);
-        patches.resize(patchEntries.size());
-
-        forAll(patches, patchi)
-        {
-            patches.set
-            (
-                patchi,
-                polyPatch::New
-                (
-                    patchEntries[patchi].keyword(),
-                    patchEntries[patchi].dict(),
-                    patchi,
-                    *this
-                )
-            );
-        }
-
-        is.check(FUNCTION_NAME);
-
-        close();
-    }
-    else
+    if (!readContents(true))  // READ_IF_PRESENT allowed: True
     {
         polyPatchList& patches = *this;
-        patches.setSize(ppl.size());
+        patches.resize(ppl.size());
         forAll(patches, patchi)
         {
             patches.set(patchi, ppl[patchi].clone(*this));
diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H
index f2d6fa01120..1ba87a53626 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H
@@ -91,6 +91,9 @@ class polyBoundaryMesh
         //- Calculate group name to patch ids lookup
         void calcGroupIDs() const;
 
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents(const bool allowReadIfPresent);
+
         //- No copy construct
         polyBoundaryMesh(const polyBoundaryMesh&) = delete;
 
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C
index 96c959d3b2b..ccef0ba4959 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C
@@ -152,7 +152,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
 
 
 template<class ZoneType, class MeshType>
-bool Foam::ZoneMesh<ZoneType, MeshType>::read()
+bool Foam::ZoneMesh<ZoneType, MeshType>::readContents()
 {
     if
     (
@@ -166,12 +166,13 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::read()
 
         PtrList<ZoneType>& zones = *this;
 
-        // Read zones
+        // Read zones as entries
         Istream& is = readStream(typeName);
 
         PtrList<entry> patchEntries(is);
         zones.resize(patchEntries.size());
 
+        // Transcribe
         forAll(zones, zonei)
         {
             zones.set
@@ -187,11 +188,8 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::read()
             );
         }
 
-        // Check state of IOstream
         is.check(FUNCTION_NAME);
-
         close();
-
         return true;
     }
 
@@ -213,7 +211,7 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
     regIOobject(io),
     mesh_(mesh)
 {
-    read();
+    readContents();
 }
 
 
@@ -230,7 +228,7 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
     mesh_(mesh)
 {
     // Optionally read contents, otherwise keep size
-    read();
+    readContents();
 }
 
 
@@ -246,7 +244,7 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
     regIOobject(io),
     mesh_(mesh)
 {
-    if (!read())
+    if (!readContents())
     {
         // Nothing read. Use supplied zones
         PtrList<ZoneType>& zones = *this;
diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H
index 25f99e1fed1..a97d172a7b2 100644
--- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H
+++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2021 OpenCFD Ltd.
+    Copyright (C) 2016-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef ZoneMesh_H
-#define ZoneMesh_H
+#ifndef Foam_ZoneMesh_H
+#define Foam_ZoneMesh_H
 
 #include "regIOobject.H"
 #include "pointField.H"
@@ -83,7 +83,7 @@ class ZoneMesh
     // Private Member Functions
 
         //- Read if IOobject flags set. Return true if read.
-        bool read();
+        bool readContents();
 
         //- Create zone map
         void calcZoneMap() const;
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C
index 032041ad9ca..f8dc175c9cf 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -43,6 +43,24 @@ namespace Foam
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
+bool Foam::refinementHistory::readContents()
+{
+    if
+    (
+        readOpt() == IOobject::MUST_READ
+     || readOpt() == IOobject::MUST_READ_IF_MODIFIED
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        readStream(typeName) >> *this;
+        close();
+        return true;
+    }
+
+    return false;
+}
+
+
 void Foam::refinementHistory::writeEntry
 (
     const List<splitCell8>& splitCells,
@@ -554,16 +572,7 @@ Foam::refinementHistory::refinementHistory(const IOobject& io)
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<refinementHistory>();
 
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 
     // When running in redistributePar + READ_IF_PRESENT it can happen
     // that some processors do have refinementHistory and some don't so
@@ -593,22 +602,13 @@ Foam::refinementHistory::refinementHistory
     regIOobject(io),
     active_(active),
     splitCells_(splitCells),
-    freeSplitCells_(0),
+    freeSplitCells_(),
     visibleCells_(visibleCells)
 {
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<refinementHistory>();
 
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
+    readContents();
 
     // Check indices.
     checkIndices();
@@ -633,22 +633,12 @@ Foam::refinementHistory::refinementHistory
 :
     regIOobject(io),
     active_(false),
-    freeSplitCells_(0)
+    freeSplitCells_()
 {
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<refinementHistory>();
 
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         visibleCells_.setSize(nCells);
         splitCells_.setCapacity(nCells);
@@ -688,22 +678,12 @@ Foam::refinementHistory::refinementHistory
 :
     regIOobject(io),
     active_(active),
-    freeSplitCells_(0)
+    freeSplitCells_()
 {
     // Warn for MUST_READ_IF_MODIFIED
     warnNoRereading<refinementHistory>();
 
-    if
-    (
-        io.readOpt() == IOobject::MUST_READ
-     || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
-    )
-    {
-        readStream(typeName) >> *this;
-        close();
-    }
-    else
+    if (!readContents())
     {
         visibleCells_.setSize(nCells);
         splitCells_.setCapacity(nCells);
@@ -870,7 +850,7 @@ Foam::refinementHistory::refinementHistory(const IOobject& io, Istream& is)
 :
     regIOobject(io),
     splitCells_(is),
-    freeSplitCells_(0),
+    freeSplitCells_(),
     visibleCells_(is)
 {
     active_ = (returnReduce(visibleCells_.size(), sumOp<label>()) > 0);
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.H
index c0be971d0be..49bd6fe7795 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.H
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.H
@@ -175,6 +175,9 @@ private:
             const List<splitCell8>&
         );
 
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
+
         //- Check consistency of structure, i.e. indices into splitCells_.
         void checkIndices() const;
 
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C
index 5434f8041a0..2bd56c078d1 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C
@@ -42,7 +42,7 @@ namespace Foam
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-void Foam::polyTopoChanger::readModifiers()
+bool Foam::polyTopoChanger::readContents()
 {
     if
     (
@@ -51,9 +51,6 @@ void Foam::polyTopoChanger::readModifiers()
      || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
-        // Warn for MUST_READ_IF_MODIFIED
-        warnNoRereading<polyTopoChanger>();
-
         PtrList<polyMeshModifier>& modifiers = *this;
 
         // Read modifiers
@@ -78,9 +75,11 @@ void Foam::polyTopoChanger::readModifiers()
         }
 
         is.check(FUNCTION_NAME);
-
         close();
+        return true;
     }
+
+    return false;
 }
 
 
@@ -96,7 +95,10 @@ Foam::polyTopoChanger::polyTopoChanger
     regIOobject(io),
     mesh_(mesh)
 {
-    readModifiers();
+    // Warn for MUST_READ_IF_MODIFIED
+    warnNoRereading<polyTopoChanger>();
+
+    readContents();
 }
 
 
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H
index bbfd2219507..a7791571170 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef polyTopoChanger_H
-#define polyTopoChanger_H
+#ifndef Foam_polyTopoChanger_H
+#define Foam_polyTopoChanger_H
 
 #include "regIOobject.H"
 #include "PtrList.H"
@@ -67,7 +67,8 @@ class polyTopoChanger
 {
     // Private Member Functions
 
-        void readModifiers();
+        //- Read if IOobject flags set, set modifiers. Return true if read.
+        bool readContents();
 
         //- No copy construct
         polyTopoChanger(const polyTopoChanger&) = delete;
diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C
index fbae5aedd64..ac28ba38225 100644
--- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C
+++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C
@@ -100,22 +100,17 @@ void Foam::faBoundaryMesh::calcGroupIDs() const
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::faBoundaryMesh::faBoundaryMesh
-(
-    const IOobject& io,
-    const faMesh& mesh
-)
-:
-    faPatchList(),
-    regIOobject(io),
-    mesh_(mesh)
+bool Foam::faBoundaryMesh::readContents(const bool allowReadIfPresent)
 {
     if
     (
         readOpt() == IOobject::MUST_READ
      || readOpt() == IOobject::MUST_READ_IF_MODIFIED
+     ||
+        (
+            allowReadIfPresent
+         && (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+        )
     )
     {
         // Warn for MUST_READ_IF_MODIFIED
@@ -126,9 +121,11 @@ Foam::faBoundaryMesh::faBoundaryMesh
         // Read faPatch list
         Istream& is = readStream(typeName);
 
+        // Read patches as entries
         PtrList<entry> patchEntries(is);
-        patches.setSize(patchEntries.size());
+        patches.resize(patchEntries.size());
 
+        // Transcribe
         forAll(patches, patchi)
         {
             patches.set
@@ -145,9 +142,27 @@ Foam::faBoundaryMesh::faBoundaryMesh
         }
 
         is.check(FUNCTION_NAME);
-
         close();
+        return true;
     }
+
+    return false;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::faBoundaryMesh::faBoundaryMesh
+(
+    const IOobject& io,
+    const faMesh& mesh
+)
+:
+    faPatchList(),
+    regIOobject(io),
+    mesh_(mesh)
+{
+    readContents(false);  // READ_IF_PRESENT allowed: False
 }
 
 
diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H
index fb1b7e4d088..c6ecd2ba39c 100644
--- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H
+++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H
@@ -86,6 +86,9 @@ class faBoundaryMesh
         //- Calculate group name to patch ids lookup
         void calcGroupIDs() const;
 
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents(const bool allowReadIfPresent);
+
         //- No copy construct
         faBoundaryMesh(const faBoundaryMesh&) = delete;
 
diff --git a/src/meshTools/coordinate/systems/coordinateSystems.C b/src/meshTools/coordinate/systems/coordinateSystems.C
index 0581a897a93..073094af1a1 100644
--- a/src/meshTools/coordinate/systems/coordinateSystems.C
+++ b/src/meshTools/coordinate/systems/coordinateSystems.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2021 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -86,15 +86,15 @@ void Foam::coordinateSystems::readFromStream(const bool valid)
 }
 
 
-bool Foam::coordinateSystems::readObject(const IOobject& io)
+bool Foam::coordinateSystems::readContents()
 {
     if
     (
         (
-            io.readOpt() == IOobject::MUST_READ
-         || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
+            readOpt() == IOobject::MUST_READ
+         || readOpt() == IOobject::MUST_READ_IF_MODIFIED
         )
-     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+     || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
     )
     {
         readFromStream();
@@ -105,7 +105,6 @@ bool Foam::coordinateSystems::readObject(const IOobject& io)
 }
 
 
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::coordinateSystems::coordinateSystems(const IOobject& io)
@@ -113,7 +112,7 @@ Foam::coordinateSystems::coordinateSystems(const IOobject& io)
     regIOobject(io),
     PtrList<coordinateSystem>()
 {
-    readObject(io);
+    readContents();
 }
 
 
@@ -126,7 +125,7 @@ Foam::coordinateSystems::coordinateSystems
     regIOobject(io),
     PtrList<coordinateSystem>()
 {
-    if (!readObject(io))
+    if (!readContents())
     {
         static_cast<PtrList<coordinateSystem>&>(*this) = content;
     }
@@ -142,7 +141,7 @@ Foam::coordinateSystems::coordinateSystems
     regIOobject(io),
     PtrList<coordinateSystem>(std::move(content))
 {
-    readObject(io);
+    readContents();
 }
 
 
diff --git a/src/meshTools/coordinate/systems/coordinateSystems.H b/src/meshTools/coordinate/systems/coordinateSystems.H
index eb81ff231bf..294e4255c58 100644
--- a/src/meshTools/coordinate/systems/coordinateSystems.H
+++ b/src/meshTools/coordinate/systems/coordinateSystems.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2021 OpenCFD Ltd.
+    Copyright (C) 2018-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -59,8 +59,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef coordinateSystems_H
-#define coordinateSystems_H
+#ifndef Foam_coordinateSystems_H
+#define Foam_coordinateSystems_H
 
 #include "regIOobject.H"
 #include "PtrList.H"
@@ -86,10 +86,8 @@ class coordinateSystems
         //- Read "coordinateSystems" or older "IOPtrList<coordinateSystem>"
         void readFromStream(const bool valid = true);
 
-        //- Attempt read if MUST_READ.., or READ_IF_PRESENT and has header
-        //  \return False if no read should have been attempted
-        bool readObject(const IOobject& io);
-
+        //- Read if IOobject flags set. Return true if read.
+        bool readContents();
 
         //- No copy construct
         coordinateSystems(const coordinateSystems&) = delete;
-- 
GitLab