diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions index 479d200327d9a2fa3474e715ab58992051ed74f7..5d05ae8236989a0f7ec4dfb11ed02f5355f80811 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 f423411fa3bc1e9c8dd207b00c01679c98bb2630..4a3abedf36436ffc89848df66ddb1e4450e174c9 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 0d7679c36c6f677c1248dab0b3ebe40383440e39..e5c33e8ec445c1d451c9b3313d9d584e308c816f 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 efa474708907b5c51cdb881abe7567e8310b0295..8ea42a6ef42b6910a461a60fcaa3371a9b2ac4cd 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<class Type> Foam::rawIOField<Type>::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<Type>::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,33 +89,36 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage) is >> static_cast<Field<Type>&>(*this); if (readAverage) { - average_ = pTraits<Type>(is); + hasAverage_ = true; + is >> average_; } close(); } } else if (haveFile) { - // Failed reading - fall back to IFstream + // Failed reading header - fall back to IFstream autoPtr<ISstream> isPtr(fileHandler().NewIFstream(io.objectPath())); - if (!isPtr || !isPtr->good()) + if (isPtr && isPtr->good()) { - if (io.readOpt() != IOobject::READ_IF_PRESENT) + auto& is = *isPtr; + + is >> static_cast<Field<Type>&>(*this); + if (readAverage) { - FatalIOErrorInFunction(*isPtr) - << "Trying to read raw field" << endl - << exit(FatalIOError); + hasAverage_ = true; + is >> average_; } } else { - ISstream& is = isPtr(); - - is >> static_cast<Field<Type>&>(*this); - if (readAverage) + // Error if missing and MUST_READ or MUST_READ_IF_MODIFIED + if (io.readOpt() != IOobject::READ_IF_PRESENT) { - average_ = pTraits<Type>(is); + FatalIOErrorInFunction(*isPtr) + << "Trying to read raw field" << endl + << exit(FatalIOError); } } } @@ -132,11 +134,19 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template<class Type> +void Foam::rawIOField<Type>::setAverage(const Type& val) +{ + hasAverage_ = true; + average_ = val; +} + + template<class Type> bool Foam::rawIOField<Type>::writeData(Ostream& os) const { os << static_cast<const Field<Type>&>(*this); - if (average_ != pTraits<Type>::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 57bd0ec1742a3201f09446c8777fbc96bda4cf6d..df71f7ca65b87e4cc5bc3fe8b1dd84e8200f7972 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 f26fc1966dda369052bb02b1f8e4de6566f26d59..7713661d9939f84208ed921c6f571dba0206382e 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