diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions index 479d200327..5d05ae8236 100644 --- a/bin/tools/RunFunctions +++ b/bin/tools/RunFunctions @@ -157,7 +157,7 @@ getNumberOfPatchFaces() '/^ *'"$patch"' *$/,/}/{s/^ *nFaces *\([0-9][0-9]*\) *;.*$/\1/p}' \ "$file") - if [ -n "nFaces" ] + if [ -n "$nFaces" ] then echo "$nFaces" else diff --git a/bin/tools/lib-dir b/bin/tools/lib-dir index f423411fa3..4a3abedf36 100755 --- a/bin/tools/lib-dir +++ b/bin/tools/lib-dir @@ -6,7 +6,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2018-2020 OpenCFD Ltd. +# Copyright (C) 2018-2022 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -65,7 +65,7 @@ die() echo "Error encountered:" while [ "$#" -ge 1 ]; do echo " $1"; shift; done echo - echo "See '${Script##*/} -help' for usage" + echo "See '${0##*/} -help' for usage" echo exit 1 } @@ -73,7 +73,7 @@ die() #------------------------------------------------------------------------------ -optSyntax=sh +optSyntax="sh" unset verboseOutput # Parse options diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 0d7679c36c..e5c33e8ec4 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -339,9 +339,8 @@ $(IOdictionary)/IOdictionary.C db/IOobjects/IOMap/IOMaps.C db/IOobjects/decomposedBlockData/decomposedBlockData.C db/IOobjects/decomposedBlockData/decomposedBlockDataHeader.C +db/IOobjects/rawIOField/rawIOFields.C db/IOobjects/GlobalIOField/GlobalIOFields.C - - db/IOobjects/GlobalIOList/globalIOLists.C diff --git a/src/meshTools/PatchFunction1/MappedFile/rawIOField.C b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C similarity index 87% rename from src/meshTools/PatchFunction1/MappedFile/rawIOField.C rename to src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C index efa4747089..8ea42a6ef4 100644 --- a/src/meshTools/PatchFunction1/MappedFile/rawIOField.C +++ b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,6 +34,7 @@ template Foam::rawIOField::rawIOField(const IOobject& io, const bool readAverage) : regIOobject(io), + hasAverage_(false), average_(Zero) { // Check for MUST_READ_IF_MODIFIED @@ -61,15 +62,13 @@ Foam::rawIOField::rawIOField(const IOobject& io, const bool readAverage) { haveFile = true; - ISstream& is = isPtr(); + auto& is = *isPtr; const token firstToken(is); headerOk = is.good() && firstToken.isWord("FoamFile"); } - isPtr.clear(); - if (debug) { Pout<< "rawIOField : object:" << io.name() @@ -90,18 +89,31 @@ Foam::rawIOField::rawIOField(const IOobject& io, const bool readAverage) is >> static_cast&>(*this); if (readAverage) { - average_ = pTraits(is); + hasAverage_ = true; + is >> average_; } close(); } } else if (haveFile) { - // Failed reading - fall back to IFstream + // Failed reading header - fall back to IFstream autoPtr isPtr(fileHandler().NewIFstream(io.objectPath())); - if (!isPtr || !isPtr->good()) + if (isPtr && isPtr->good()) { + auto& is = *isPtr; + + is >> static_cast&>(*this); + if (readAverage) + { + hasAverage_ = true; + is >> average_; + } + } + else + { + // Error if missing and MUST_READ or MUST_READ_IF_MODIFIED if (io.readOpt() != IOobject::READ_IF_PRESENT) { FatalIOErrorInFunction(*isPtr) @@ -109,16 +121,6 @@ Foam::rawIOField::rawIOField(const IOobject& io, const bool readAverage) << exit(FatalIOError); } } - else - { - ISstream& is = isPtr(); - - is >> static_cast&>(*this); - if (readAverage) - { - average_ = pTraits(is); - } - } } if (debug) @@ -132,11 +134,19 @@ Foam::rawIOField::rawIOField(const IOobject& io, const bool readAverage) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::rawIOField::setAverage(const Type& val) +{ + hasAverage_ = true; + average_ = val; +} + + template bool Foam::rawIOField::writeData(Ostream& os) const { os << static_cast&>(*this); - if (average_ != pTraits::zero) + if (hasAverage_) { os << token::NL << average_; } diff --git a/src/meshTools/PatchFunction1/MappedFile/rawIOField.H b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H similarity index 84% rename from src/meshTools/PatchFunction1/MappedFile/rawIOField.H rename to src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H index 57bd0ec174..df71f7ca65 100644 --- a/src/meshTools/PatchFunction1/MappedFile/rawIOField.H +++ b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOField.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef rawIOField_H -#define rawIOField_H +#ifndef Foam_rawIOField_H +#define Foam_rawIOField_H #include "IOField.H" @@ -57,7 +57,10 @@ class rawIOField { // Private Data - //- The average of the field (Zero if not used) + //- Has an average value + bool hasAverage_; + + //- The average for the field (zero if not used) Type average_; @@ -72,7 +75,7 @@ public: rawIOField(const rawIOField&) = default; //- Construct from IOobject - explicit rawIOField(const IOobject& io, const bool readAverage); + explicit rawIOField(const IOobject& io, const bool readAverage=false); //- Destructor @@ -81,11 +84,21 @@ public: // Member Functions - const Type& average() const + //- Has an average value + bool hasAverage() const noexcept + { + return hasAverage_; + } + + //- The average value (if any) + const Type& average() const noexcept { return average_; } + //- Set an average value + void setAverage(const Type& val); + bool writeData(Ostream& os) const; diff --git a/src/meshTools/PatchFunction1/MappedFile/rawIOFields.C b/src/OpenFOAM/db/IOobjects/rawIOField/rawIOFields.C similarity index 100% rename from src/meshTools/PatchFunction1/MappedFile/rawIOFields.C rename to src/OpenFOAM/db/IOobjects/rawIOField/rawIOFields.C diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index f26fc1966d..7713661d99 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -325,7 +325,6 @@ PatchFunction1/PatchFunction1/patchFunction1Base.C PatchFunction1/makePatchFunction1s.C PatchFunction1/coordinateScaling/coordinateScalings.C PatchFunction1/CodedField/makeCodedFields.C -PatchFunction1/MappedFile/rawIOFields.C meshStructure/meshStructure.C