From f75af788c1b9e927af15eb17b9a14d6d98178dcb Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 28 Feb 2023 11:17:59 +0100
Subject: [PATCH] ENH: add factory method readContents to IO containers

- useful when regular contents are to be read via an IOobject and
  returned.

  Eg,  dictionary propsDict(IOdictionary::readContents(dictIO));
  vs.  dictionary propsDict(static_cast<dictionary&&>(IOdictionary(dictIO)));

  Commonly these would have simply been constructed directly as the
  IO container:

  eg,  IOdictionary propsDict(dictIO);

  However, that style may not ensure proper move semantics for return
  types.

  Now,
  =====
      labelList decomp(labelIOList::readContents(io));
      ... something
      return decomp;
  =====

  Previously,
  =====
      labelIOList decomp(io);

      // Hope for the best...
      return decomp;

      // Or be explicit and ensure elision occurs...
      return labelList(std::move(static_cast<labelList&>(decomp)));
  =====

  Note:
       labelList list(labelIOList(io));

       looks like a good idea, but generally fails to compile
---
 applications/test/Function1/Test-Function1.C  |  6 +++++-
 src/OpenFOAM/db/IOobject/IOobject.H           |  7 +++++++
 src/OpenFOAM/db/IOobject/IOobjectI.H          | 18 +++++++++++++++---
 src/OpenFOAM/db/IOobject/IOobjectTemplates.C  |  2 +-
 src/OpenFOAM/db/IOobjects/IOField/IOField.C   | 19 ++++++++++++++++++-
 src/OpenFOAM/db/IOobjects/IOField/IOField.H   |  8 +++++++-
 src/OpenFOAM/db/IOobjects/IOList/IOList.C     | 19 ++++++++++++++++++-
 src/OpenFOAM/db/IOobjects/IOList/IOList.H     |  8 +++++++-
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.C       | 19 ++++++++++++++++++-
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.H       |  8 +++++++-
 .../db/IOobjects/IOPtrList/IOPtrList.C        | 19 ++++++++++++++++++-
 .../db/IOobjects/IOPtrList/IOPtrList.H        | 12 +++++++++---
 .../db/IOobjects/IOdictionary/IOdictionary.C  | 18 +++++++++++++++++-
 .../db/IOobjects/IOdictionary/IOdictionary.H  | 12 +++++++++---
 .../IOobjects/IOdictionary/baseIOdictionary.H |  4 ++--
 .../IOdictionary/localIOdictionary.C          | 18 +++++++++++++++++-
 .../IOdictionary/localIOdictionary.H          | 12 +++++++++---
 .../IOdictionary/unwatchedIOdictionary.H      |  4 ++--
 .../db/IOobjects/rawIOField/rawIOField.C      | 19 ++++++++++++++++++-
 .../db/IOobjects/rawIOField/rawIOField.H      |  8 +++++++-
 20 files changed, 211 insertions(+), 29 deletions(-)

diff --git a/applications/test/Function1/Test-Function1.C b/applications/test/Function1/Test-Function1.C
index 3d27af76495..951786ad711 100644
--- a/applications/test/Function1/Test-Function1.C
+++ b/applications/test/Function1/Test-Function1.C
@@ -109,7 +109,11 @@ int main(int argc, char *argv[])
     {
         #include "setConstantRunTimeDictionaryIO.H"
 
-        IOdictionary propsDict(dictIO);
+        #if (OPENFOAM > 2212)
+        dictionary propsDict(IOdictionary::readContents(dictIO));
+        #else
+        dictionary propsDict(static_cast<dictionary&&>(IOdictionary(dictIO)));
+        #endif
 
         const scalarField xvals(propsDict.lookup("x"));
 
diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H
index 5f088ae206e..016032a180b 100644
--- a/src/OpenFOAM/db/IOobject/IOobject.H
+++ b/src/OpenFOAM/db/IOobject/IOobject.H
@@ -434,6 +434,13 @@ public:
             IOobjectOption::writeOption wOpt
         );
 
+        //- Copy construct, resetting register option
+        inline IOobject
+        (
+            const IOobject& io,
+            IOobjectOption::registerOption regOpt
+        );
+
 
         //- Clone
         autoPtr<IOobject> clone() const
diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H
index 41a410fc2ed..eed345e0d25 100644
--- a/src/OpenFOAM/db/IOobject/IOobjectI.H
+++ b/src/OpenFOAM/db/IOobject/IOobjectI.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2022 OpenCFD Ltd.
+    Copyright (C) 2017-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -145,8 +145,20 @@ inline Foam::IOobject::IOobject
 :
     IOobject(io)
 {
-    readOpt(rOpt);
-    writeOpt(wOpt);
+    IOobjectOption::readOpt(rOpt);
+    IOobjectOption::writeOpt(wOpt);
+}
+
+
+inline Foam::IOobject::IOobject
+(
+    const IOobject& io,
+    IOobjectOption::registerOption regOpt
+)
+:
+    IOobject(io)
+{
+    IOobjectOption::registerObject(regOpt);
 }
 
 
diff --git a/src/OpenFOAM/db/IOobject/IOobjectTemplates.C b/src/OpenFOAM/db/IOobject/IOobjectTemplates.C
index 2c95206a1d0..444d219dc5d 100644
--- a/src/OpenFOAM/db/IOobject/IOobjectTemplates.C
+++ b/src/OpenFOAM/db/IOobject/IOobjectTemplates.C
@@ -93,7 +93,7 @@ void Foam::IOobject::warnNoRereading() const
     {
         WarningInFunction
             << Type::typeName << ' ' << name()
-            << " constructed with IOobject::MUST_READ_IF_MODIFIED but "
+            << " constructed with MUST_READ_IF_MODIFIED but "
             << Type::typeName << " does not support automatic rereading."
             << endl;
     }
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.C b/src/OpenFOAM/db/IOobjects/IOField/IOField.C
index fd249924886..516971f8c07 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-2022 OpenCFD Ltd.
+    Copyright (C) 2016-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -180,6 +180,23 @@ Foam::IOFieldRef<Type>::IOFieldRef
 {}
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+template<class Type>
+Foam::Field<Type> Foam::IOField<Type>::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    IOField<Type> reader(rio);
+
+    return Field<Type>(std::move(static_cast<Field<Type>&>(reader)));
+}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.H b/src/OpenFOAM/db/IOobjects/IOField/IOField.H
index e7ac808430d..bb6bff25848 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-2022 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -98,6 +98,12 @@ public:
         IOField(const IOobject& io, const tmp<Field<Type>>& tfld);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static Field<Type> readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~IOField() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.C b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
index bb29720f1ca..59c6b63a8e9 100644
--- a/src/OpenFOAM/db/IOobjects/IOList/IOList.C
+++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2022 OpenCFD Ltd.
+    Copyright (C) 2016-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -126,6 +126,23 @@ Foam::IOListRef<T>::IOListRef
 {}
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+template<class T>
+Foam::List<T> Foam::IOList<T>::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    IOList<T> reader(rio);
+
+    return List<T>(std::move(static_cast<List<T>&>(reader)));
+}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.H b/src/OpenFOAM/db/IOobjects/IOList/IOList.H
index d22d73e7c52..d621655476c 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-2022 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,6 +92,12 @@ public:
         IOList(const IOobject& io, List<T>&& content);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject is never registered
+        static List<T> readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~IOList() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
index 253d9960a2e..702aebd322e 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-2022 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -94,6 +94,23 @@ Foam::IOMap<T>::IOMap(const IOobject& io, Map<T>&& content)
 }
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+template<class T>
+Foam::Map<T> Foam::IOMap<T>::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    IOMap<T> reader(rio);
+
+    return Map<T>(std::move(static_cast<Map<T>&>(reader)));
+}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
index ea226239c8d..637c302a240 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-2022 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,6 +89,12 @@ public:
         IOMap(const IOobject&, Map<T>&& content);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static Map<T> readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~IOMap() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
index cc46681dbf6..48efa21d5ea 100644
--- a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
+++ b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2018-2022 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -116,6 +116,23 @@ Foam::IOPtrList<T>::IOPtrList(const IOobject& io, PtrList<T>&& content)
 }
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+template<class T>
+Foam::PtrList<T> Foam::IOPtrList<T>::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    IOPtrList<T> reader(rio);
+
+    return PtrList<T>(std::move(static_cast<PtrList<T>&>(reader)));
+}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
index aa829d34a58..a838177aa96 100644
--- a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
+++ b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOPtrList_H
-#define IOPtrList_H
+#ifndef Foam_IOPtrList_H
+#define Foam_IOPtrList_H
 
 #include "PtrList.H"
 #include "regIOobject.H"
@@ -84,6 +84,12 @@ public:
         IOPtrList(const IOobject& io, PtrList<T>&& content);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static PtrList<T> readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~IOPtrList() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.C b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.C
index 009dddadc90..83834881ec7 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.C
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2021-2022 OpenCFD Ltd.
+    Copyright (C) 2021-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -91,4 +91,20 @@ Foam::IOdictionary::IOdictionary
 }
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+Foam::dictionary Foam::IOdictionary::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    IOdictionary reader(rio);
+
+    return dictionary(std::move(static_cast<dictionary&>(reader)));
+}
+
+
 // ************************************************************************* //
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H
index 2ba3eb25136..a10a3e25279 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2021 OpenCFD Ltd.
+    Copyright (C) 2021-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -38,8 +38,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IOdictionary_H
-#define IOdictionary_H
+#ifndef Foam_IOdictionary_H
+#define Foam_IOdictionary_H
 
 #include "baseIOdictionary.H"
 
@@ -87,6 +87,12 @@ public:
         IOdictionary(const IOobject& io, Istream& is);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static dictionary readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~IOdictionary() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/baseIOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/baseIOdictionary.H
index 943c1cd4751..4615703727b 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/baseIOdictionary.H
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/baseIOdictionary.H
@@ -39,8 +39,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef baseIOdictionary_H
-#define baseIOdictionary_H
+#ifndef Foam_baseIOdictionary_H
+#define Foam_baseIOdictionary_H
 
 #include "dictionary.H"
 #include "regIOobject.H"
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.C b/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.C
index 759ea26ce89..bd45e100c78 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.C
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2015-2017 OpenFOAM Foundation
-    Copyright (C) 2021-2022 OpenCFD Ltd.
+    Copyright (C) 2021-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -88,4 +88,20 @@ Foam::localIOdictionary::localIOdictionary
 }
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+Foam::dictionary Foam::localIOdictionary::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    localIOdictionary reader(rio);
+
+    return dictionary(std::move(static_cast<dictionary&>(reader)));
+}
+
+
 // ************************************************************************* //
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.H
index d2e03213930..e151f258fc3 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.H
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/localIOdictionary.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2015-2017 OpenFOAM Foundation
-    Copyright (C) 2021 OpenCFD Ltd.
+    Copyright (C) 2021-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,8 +36,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef localIOdictionary_H
-#define localIOdictionary_H
+#ifndef Foam_localIOdictionary_H
+#define Foam_localIOdictionary_H
 
 #include "baseIOdictionary.H"
 
@@ -84,6 +84,12 @@ public:
         localIOdictionary(const IOobject& io, Istream& is);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static dictionary readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~localIOdictionary() = default;
 
diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H
index b38f5cf165e..549666a0278 100644
--- a/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H
+++ b/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H
@@ -37,8 +37,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef unwatchedIOdictionary_H
-#define unwatchedIOdictionary_H
+#ifndef Foam_unwatchedIOdictionary_H
+#define Foam_unwatchedIOdictionary_H
 
 #include "baseIOdictionary.H"
 
diff --git a/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C
index 35f6283f74e..69f4d1772b5 100644
--- a/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C
+++ b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2022 OpenCFD Ltd.
+    Copyright (C) 2016-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -188,6 +188,23 @@ Foam::rawIOField<Type>::rawIOField
 {}
 
 
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+template<class Type>
+Foam::Field<Type> Foam::rawIOField<Type>::readContents(const IOobject& io)
+{
+    IOobject rio(io, IOobjectOption::NO_REGISTER);
+    if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
+    {
+        rio.readOpt(IOobjectOption::MUST_READ);
+    }
+
+    rawIOField<Type> reader(rio);
+
+    return Field<Type>(std::move(static_cast<Field<Type>&>(reader)));
+}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H
index 3dfc3d0c6d5..eaf5a9e934e 100644
--- a/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H
+++ b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020-2022 OpenCFD Ltd.
+    Copyright (C) 2020-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -99,6 +99,12 @@ public:
         rawIOField(const IOobject& io, const bool readAverage);
 
 
+    // Factory Methods
+
+        //- Read and return contents. The IOobject will not be registered
+        static Field<Type> readContents(const IOobject& io);
+
+
     //- Destructor
     virtual ~rawIOField() = default;
 
-- 
GitLab