From 8b1514c99b466e2e2512c10755bc20ec7c3cef30 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 11 Jul 2022 18:48:13 +0200 Subject: [PATCH] GIT: relocate rawIOField to src/OpenFOAM (closer to IOField classes) STYLE: RunFunctions - missed message for failure to find nFaces --- bin/tools/RunFunctions | 2 +- bin/tools/lib-dir | 6 +-- src/OpenFOAM/Make/files | 3 +- .../db/IOobjects/rawIOField}/rawIOField.C | 44 ++++++++++++------- .../db/IOobjects/rawIOField}/rawIOField.H | 25 ++++++++--- .../db/IOobjects/rawIOField}/rawIOFields.C | 0 src/meshTools/Make/files | 1 - 7 files changed, 51 insertions(+), 30 deletions(-) rename src/{meshTools/PatchFunction1/MappedFile => OpenFOAM/db/IOobjects/rawIOField}/rawIOField.C (87%) rename src/{meshTools/PatchFunction1/MappedFile => OpenFOAM/db/IOobjects/rawIOField}/rawIOField.H (84%) rename src/{meshTools/PatchFunction1/MappedFile => OpenFOAM/db/IOobjects/rawIOField}/rawIOFields.C (100%) diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions index 479d200327d..5d05ae82369 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 f423411fa3b..4a3abedf364 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 0d7679c36c6..e5c33e8ec44 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 efa47470890..8ea42a6ef42 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 57bd0ec1742..df71f7ca65b 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 f26fc1966dd..7713661d993 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 -- GitLab