diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C index 027ccc53ea..c5b082cca7 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C @@ -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. @@ -51,9 +51,9 @@ void Foam::CompactIOField::readFromStream(const bool valid) else { FatalIOErrorInFunction(is) - << "unexpected class name " << headerClassName() - << " expected " << typeName << " or " << IOField::typeName - << endl + << "Unexpected class name " << headerClassName() + << " expected " << typeName + << " or " << IOField::typeName << nl << " while reading object " << name() << exit(FatalIOError); } @@ -104,7 +104,27 @@ template Foam::CompactIOField::CompactIOField ( const IOobject& io, - const label size + Foam::zero +) +: + regIOobject(io) +{ + if + ( + io.readOpt() == IOobject::MUST_READ + || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) + ) + { + readFromStream(); + } +} + + +template +Foam::CompactIOField::CompactIOField +( + const IOobject& io, + const label len ) : regIOobject(io) @@ -119,7 +139,7 @@ Foam::CompactIOField::CompactIOField } else { - Field::setSize(size); + Field::resize(len); } } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H index 09b6fb943f..d4e9b193f7 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,18 +39,17 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef CompactIOField_H -#define CompactIOField_H +#ifndef Foam_CompactIOField_H +#define Foam_CompactIOField_H #include "IOField.H" -#include "regIOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward declarations +// Forward Declarations template class CompactIOField; template Istream& operator>> @@ -94,11 +93,14 @@ public: //- Construct from IOobject explicit CompactIOField(const IOobject& io); - //- Construct from IOobject; does local processor require reading? + //- Construct from IOobject, with local processor conditional reading CompactIOField(const IOobject& io, const bool valid); - //- Construct from IOobject and size - CompactIOField(const IOobject& io, const label size); + //- Construct from IOobject and zero size (if not read) + CompactIOField(const IOobject& io, Foam::zero); + + //- Construct from IOobject and size (if not read) + CompactIOField(const IOobject& io, const label len); //- Construct from IOobject and a List/Field content CompactIOField(const IOobject& io, const UList& content); diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index fcedb1ced5..32620ffd08 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C @@ -103,6 +103,19 @@ Foam::CompactIOList::CompactIOList(const IOobject& io) } +template +Foam::CompactIOList::CompactIOList +( + const IOobject& io, + Foam::zero +) +: + regIOobject(io) +{ + readContents(); +} + + template Foam::CompactIOList::CompactIOList ( diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H index b609985bdf..b3357a4ee2 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H @@ -67,7 +67,7 @@ template Ostream& operator<< ); /*---------------------------------------------------------------------------*\ - Class CompactIOList Declaration + Class CompactIOList Declaration \*---------------------------------------------------------------------------*/ template @@ -106,6 +106,9 @@ public: //- Construct from IOobject explicit CompactIOList(const IOobject& io); + //- Construct from IOobject and zero size (if not read) + CompactIOList(const IOobject& io, Foam::zero); + //- Construct from IOobject and default length of CompactIOList CompactIOList(const IOobject& io, const label len); @@ -115,9 +118,9 @@ public: //- Construct by transferring the List content CompactIOList(const IOobject& io, List&& content); - // Destructor - virtual ~CompactIOList() = default; + //- Destructor + virtual ~CompactIOList() = default; // Member Functions diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.C b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.C index 3c5988a24a..c73ff16cba 100644 --- a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.C +++ b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,7 +43,19 @@ Foam::GlobalIOList::GlobalIOList(const IOobject& io) template -Foam::GlobalIOList::GlobalIOList(const IOobject& io, const label size) +Foam::GlobalIOList::GlobalIOList(const IOobject& io, Foam::zero) +: + regIOobject(io) +{ + // Check for MUST_READ_IF_MODIFIED + warnNoRereading>(); + + readHeaderOk(IOstream::BINARY, typeName); +} + + +template +Foam::GlobalIOList::GlobalIOList(const IOobject& io, const label len) : regIOobject(io) { @@ -52,7 +64,7 @@ Foam::GlobalIOList::GlobalIOList(const IOobject& io, const label size) if (!readHeaderOk(IOstream::BINARY, typeName)) { - List::setSize(size); + List::resize(len); } } diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H index 2cf6f9e39f..a38a1097f4 100644 --- a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H +++ b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,8 +69,11 @@ public: //- Construct from IOobject explicit GlobalIOList(const IOobject& io); - //- Construct from IOobject - GlobalIOList(const IOobject& io, const label size); + //- Construct from IOobject and zero size (if not read) + GlobalIOList(const IOobject& io, Foam::zero); + + //- Construct from IOobject and list size (if not read) + GlobalIOList(const IOobject& io, const label len); //- Construct from IOobject and a List GlobalIOList(const IOobject& io, const UList& content); diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.C b/src/OpenFOAM/db/IOobjects/IOField/IOField.C index bb84a52e0c..c4edcd27da 100644 --- a/src/OpenFOAM/db/IOobjects/IOField/IOField.C +++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.C @@ -102,6 +102,18 @@ Foam::IOField::IOField(const IOobject& io, const bool valid) } +template +Foam::IOField::IOField(const IOobject& io, Foam::zero) +: + regIOobject(io) +{ + // Check for MUST_READ_IF_MODIFIED + warnNoRereading>(); + + readContents(); +} + + template Foam::IOField::IOField(const IOobject& io, const label len) : diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.H b/src/OpenFOAM/db/IOobjects/IOField/IOField.H index 7dc71fdf14..e7ac808430 100644 --- a/src/OpenFOAM/db/IOobjects/IOField/IOField.H +++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.H @@ -79,13 +79,16 @@ public: //- Construct from IOobject explicit IOField(const IOobject& io); - //- Construct from IOobject; does local processor require reading? + //- Construct from IOobject, with local processor conditional reading IOField(const IOobject& io, const bool valid); - //- Construct from IOobject and size (does not set values) - IOField(const IOobject& io, const label size); + //- Construct from IOobject and zero size (if not read) + IOField(const IOobject& io, Foam::zero); - //- Construct from IOobject and a List/Field content + //- Construct from IOobject and field size (if not read) + IOField(const IOobject& io, const label len); + + //- Construct from IOobject and copy of List/Field content IOField(const IOobject& io, const UList& content); //- Construct by transferring the Field content diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.C b/src/OpenFOAM/db/IOobjects/IOList/IOList.C index a058b52442..79c9cd690e 100644 --- a/src/OpenFOAM/db/IOobjects/IOList/IOList.C +++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.C @@ -65,6 +65,18 @@ Foam::IOList::IOList(const IOobject& io) } +template +Foam::IOList::IOList(const IOobject& io, Foam::zero) +: + regIOobject(io) +{ + // Check for MUST_READ_IF_MODIFIED + warnNoRereading>(); + + readContents(); +} + + template Foam::IOList::IOList(const IOobject& io, const label len) : diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.H b/src/OpenFOAM/db/IOobjects/IOList/IOList.H index 3894f96a3d..d22d73e7c5 100644 --- a/src/OpenFOAM/db/IOobjects/IOList/IOList.H +++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.H @@ -79,13 +79,16 @@ public: //- Construct from IOobject explicit IOList(const IOobject& io); - //- Construct from IOobject and size of IOList + //- Construct from IOobject and zero size (if not read) + IOList(const IOobject& io, Foam::zero); + + //- Construct from IOobject and list size (if not read) IOList(const IOobject& io, const label len); - //- Construct from IOobject and a copy of UList content + //- Construct from IOobject and a copy of content IOList(const IOobject& io, const UList& content); - //- Construct by transferring the List content + //- Construct by transferring the content IOList(const IOobject& io, List&& content);