From 4cbe0a81ac027f18b10d4890bb29ea54ab9671a2 Mon Sep 17 00:00:00 2001 From: Mark Olesen 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 | 97 ++++++------------ src/OpenFOAM/db/IOobjects/IOField/IOField.H | 15 ++- src/OpenFOAM/db/IOobjects/IOList/IOList.C | 79 ++++++--------- src/OpenFOAM/db/IOobjects/IOList/IOList.H | 15 ++- src/OpenFOAM/db/IOobjects/IOMap/IOMap.C | 98 +++++++------------ src/OpenFOAM/db/IOobjects/IOMap/IOMap.H | 15 ++- .../mapDistribute/IOmapDistribute.C | 62 +++++------- .../mapDistribute/IOmapDistribute.H | 19 ++-- .../mapDistribute/IOmapDistributePolyMesh.C | 65 +++++------- .../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, 370 insertions(+), 473 deletions(-) diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index a614641777..fcedb1ced5 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::readFromStream() } +template +bool Foam::CompactIOList::readContents() +{ + if + ( + readOpt() == IOobject::MUST_READ + || (readOpt() == IOobject::READ_IF_PRESENT && headerOk()) + ) + { + readFromStream(); + return true; + } + + return false; +} + + template bool Foam::CompactIOList::overflows() const { @@ -82,14 +99,7 @@ Foam::CompactIOList::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::CompactIOList : regIOobject(io) { - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) + if (!readContents()) { - readFromStream(); - } - else - { - List::setSize(len); + List::resize(len); } } @@ -126,15 +128,7 @@ Foam::CompactIOList::CompactIOList : regIOobject(io) { - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } - else + if (!readContents()) { List::operator=(content); } @@ -152,14 +146,7 @@ Foam::CompactIOList::CompactIOList { List::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 555114418b..b609985bdf 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 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 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 b97ef62292..af07c9e91a 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,6 +28,29 @@ License #include "IOField.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::IOField::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; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -38,18 +61,7 @@ Foam::IOField::IOField(const IOobject& io) // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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(); } @@ -91,28 +103,16 @@ Foam::IOField::IOField(const IOobject& io, const bool valid) template -Foam::IOField::IOField(const IOobject& io, const label size) +Foam::IOField::IOField(const IOobject& io, const label len) : regIOobject(io) { // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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::setSize(size); + Field::resize(len); } } @@ -125,19 +125,7 @@ Foam::IOField::IOField(const IOobject& io, const UList& content) // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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::operator=(content); } @@ -154,18 +142,7 @@ Foam::IOField::IOField(const IOobject& io, Field&& content) Field::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::IOField(const IOobject& io, const tmp>& tfld) Field::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::operator=(tfld()); } diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.H b/src/OpenFOAM/db/IOobjects/IOField/IOField.H index 8edee8ee10..163ee129df 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 { + // Private Member Functions + + //- Read if IOobject flags set. Return true if read. + bool readContents(); + public: + //- The underlying content type + typedef Field 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 0820e61465..9c96b75374 100644 --- a/src/OpenFOAM/db/IOobjects/IOList/IOList.C +++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.C @@ -28,6 +28,29 @@ License #include "IOList.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::IOList::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; +} + + // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // template @@ -38,18 +61,7 @@ Foam::IOList::IOList(const IOobject& io) // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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(); } @@ -61,21 +73,9 @@ Foam::IOList::IOList(const IOobject& io, const label len) // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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 - { - List::setSize(len); + List::resize(len); } } @@ -88,19 +88,7 @@ Foam::IOList::IOList(const IOobject& io, const UList& content) // Check for MUST_READ_IF_MODIFIED warnNoRereading>(); - 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::operator=(content); } @@ -117,18 +105,7 @@ Foam::IOList::IOList(const IOobject& io, List&& content) List::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 c36e78ab16..86cd0a1eb7 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 { + // Private Member Functions + + //- Read if IOobject flags set. Return true if read. + bool readContents(); + public: + //- The underlying content type + typedef List content_type; + //- Runtime type information TypeName("List"); @@ -96,7 +104,6 @@ public: //- Copy or move assignment of entries using List::operator=; - }; diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C index d0b3e44e81..fc1bdd57dc 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,6 +28,33 @@ License #include "IOMap.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::IOMap::readContents() +{ + if + ( + ( + readOpt() == IOobject::MUST_READ + || readOpt() == IOobject::MUST_READ_IF_MODIFIED + ) + || (readOpt() == IOobject::READ_IF_PRESENT && headerOk()) + ) + { + // For if MUST_READ_IF_MODIFIED + addWatch(); + + readStream(typeName) >> *this; + close(); + + return true; + } + + return false; +} + + // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // template @@ -35,46 +62,18 @@ Foam::IOMap::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(); - - readStream(typeName) >> *this; - close(); - } + readContents(); } + template Foam::IOMap::IOMap(const IOobject& io, const label size) : regIOobject(io) { - if - ( - ( - io.readOpt() == IOobject::MUST_READ - || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED - ) - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) + if (!readContents()) { - // For if MUST_READ_IF_MODIFIED - addWatch(); - - readStream(typeName) >> *this; - close(); - } - else - { - Map::setSize(size); + Map::resize(size); } } @@ -84,22 +83,7 @@ Foam::IOMap::IOMap(const IOobject& io, const Map& 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::operator=(content); } @@ -113,21 +97,7 @@ Foam::IOMap::IOMap(const IOobject& io, Map&& content) { Map::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 68fa5fe985..ea226239c8 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 { + // Private Member Functions + + //- Read if IOobject flags set. Return true if read. + bool readContents(); + public: + //- The underlying content type + typedef Map 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 802cbdbe45..98b4686a93 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/IOmapDistribute.C @@ -36,6 +36,28 @@ namespace Foam } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::IOmapDistribute::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; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::IOmapDistribute::IOmapDistribute(const IOobject& io) @@ -45,18 +67,7 @@ Foam::IOmapDistribute::IOmapDistribute(const IOobject& io) // Warn for MUST_READ_IF_MODIFIED warnNoRereading(); - 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(); } @@ -71,19 +82,7 @@ Foam::IOmapDistribute::IOmapDistribute // Warn for MUST_READ_IF_MODIFIED warnNoRereading(); - 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 d277c5723b..eee7b25883 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 cc0992cb23..2af120a3d0 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,7 +32,29 @@ License namespace Foam { -defineTypeNameAndDebug(IOmapDistributePolyMesh, 0); + defineTypeNameAndDebug(IOmapDistributePolyMesh, 0); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::IOmapDistributePolyMesh::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; } @@ -44,18 +67,7 @@ Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh(const IOobject& io) // Warn for MUST_READ_IF_MODIFIED warnNoRereading(); - 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(); } @@ -70,19 +82,7 @@ Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh // Warn for MUST_READ_IF_MODIFIED warnNoRereading(); - 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 4ac988a5b3..46d326006e 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 d71112b0da..507c223107 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 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(); - - polyPatchList& patches = *this; - - // Read polyPatchList - Istream& is = readStream(typeName); - - PtrList 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 f2d6fa0112..1ba87a5362 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 96c959d3b2..ccef0ba495 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::calcGroupIDs() const template -bool Foam::ZoneMesh::read() +bool Foam::ZoneMesh::readContents() { if ( @@ -166,12 +166,13 @@ bool Foam::ZoneMesh::read() PtrList& zones = *this; - // Read zones + // Read zones as entries Istream& is = readStream(typeName); PtrList patchEntries(is); zones.resize(patchEntries.size()); + // Transcribe forAll(zones, zonei) { zones.set @@ -187,11 +188,8 @@ bool Foam::ZoneMesh::read() ); } - // Check state of IOstream is.check(FUNCTION_NAME); - close(); - return true; } @@ -213,7 +211,7 @@ Foam::ZoneMesh::ZoneMesh regIOobject(io), mesh_(mesh) { - read(); + readContents(); } @@ -230,7 +228,7 @@ Foam::ZoneMesh::ZoneMesh mesh_(mesh) { // Optionally read contents, otherwise keep size - read(); + readContents(); } @@ -246,7 +244,7 @@ Foam::ZoneMesh::ZoneMesh regIOobject(io), mesh_(mesh) { - if (!read()) + if (!readContents()) { // Nothing read. Use supplied zones PtrList& zones = *this; diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 25f99e1fed..a97d172a7b 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 032041ad9c..f8dc175c9c 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& splitCells, @@ -554,16 +572,7 @@ Foam::refinementHistory::refinementHistory(const IOobject& io) // Warn for MUST_READ_IF_MODIFIED warnNoRereading(); - 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(); - 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(); - 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(); - 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