GIT: relocate rawIOField to src/OpenFOAM (closer to IOField classes)

STYLE: RunFunctions - missed message for failure to find nFaces
This commit is contained in:
Mark Olesen 2022-07-11 18:48:13 +02:00
parent 1afd27db6c
commit 8b1514c99b
7 changed files with 52 additions and 31 deletions

View File

@ -157,7 +157,7 @@ getNumberOfPatchFaces()
'/^ *'"$patch"' *$/,/}/{s/^ *nFaces *\([0-9][0-9]*\) *;.*$/\1/p}' \ '/^ *'"$patch"' *$/,/}/{s/^ *nFaces *\([0-9][0-9]*\) *;.*$/\1/p}' \
"$file") "$file")
if [ -n "nFaces" ] if [ -n "$nFaces" ]
then then
echo "$nFaces" echo "$nFaces"
else else

View File

@ -6,7 +6,7 @@
# \\ / A nd | www.openfoam.com # \\ / A nd | www.openfoam.com
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd. # Copyright (C) 2018-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -65,7 +65,7 @@ die()
echo "Error encountered:" echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " $1"; shift; done while [ "$#" -ge 1 ]; do echo " $1"; shift; done
echo echo
echo "See '${Script##*/} -help' for usage" echo "See '${0##*/} -help' for usage"
echo echo
exit 1 exit 1
} }
@ -73,7 +73,7 @@ die()
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
optSyntax=sh optSyntax="sh"
unset verboseOutput unset verboseOutput
# Parse options # Parse options

View File

@ -339,9 +339,8 @@ $(IOdictionary)/IOdictionary.C
db/IOobjects/IOMap/IOMaps.C db/IOobjects/IOMap/IOMaps.C
db/IOobjects/decomposedBlockData/decomposedBlockData.C db/IOobjects/decomposedBlockData/decomposedBlockData.C
db/IOobjects/decomposedBlockData/decomposedBlockDataHeader.C db/IOobjects/decomposedBlockData/decomposedBlockDataHeader.C
db/IOobjects/rawIOField/rawIOFields.C
db/IOobjects/GlobalIOField/GlobalIOFields.C db/IOobjects/GlobalIOField/GlobalIOFields.C
db/IOobjects/GlobalIOList/globalIOLists.C db/IOobjects/GlobalIOList/globalIOLists.C

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,6 +34,7 @@ template<class Type>
Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage) Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage)
: :
regIOobject(io), regIOobject(io),
hasAverage_(false),
average_(Zero) average_(Zero)
{ {
// Check for MUST_READ_IF_MODIFIED // Check for MUST_READ_IF_MODIFIED
@ -61,15 +62,13 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage)
{ {
haveFile = true; haveFile = true;
ISstream& is = isPtr(); auto& is = *isPtr;
const token firstToken(is); const token firstToken(is);
headerOk = is.good() && firstToken.isWord("FoamFile"); headerOk = is.good() && firstToken.isWord("FoamFile");
} }
isPtr.clear();
if (debug) if (debug)
{ {
Pout<< "rawIOField : object:" << io.name() Pout<< "rawIOField : object:" << io.name()
@ -90,18 +89,31 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage)
is >> static_cast<Field<Type>&>(*this); is >> static_cast<Field<Type>&>(*this);
if (readAverage) if (readAverage)
{ {
average_ = pTraits<Type>(is); hasAverage_ = true;
is >> average_;
} }
close(); close();
} }
} }
else if (haveFile) else if (haveFile)
{ {
// Failed reading - fall back to IFstream // Failed reading header - fall back to IFstream
autoPtr<ISstream> isPtr(fileHandler().NewIFstream(io.objectPath())); autoPtr<ISstream> isPtr(fileHandler().NewIFstream(io.objectPath()));
if (!isPtr || !isPtr->good()) if (isPtr && isPtr->good())
{ {
auto& is = *isPtr;
is >> static_cast<Field<Type>&>(*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) if (io.readOpt() != IOobject::READ_IF_PRESENT)
{ {
FatalIOErrorInFunction(*isPtr) FatalIOErrorInFunction(*isPtr)
@ -109,16 +121,6 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage)
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
else
{
ISstream& is = isPtr();
is >> static_cast<Field<Type>&>(*this);
if (readAverage)
{
average_ = pTraits<Type>(is);
}
}
} }
if (debug) if (debug)
@ -132,11 +134,19 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::rawIOField<Type>::setAverage(const Type& val)
{
hasAverage_ = true;
average_ = val;
}
template<class Type> template<class Type>
bool Foam::rawIOField<Type>::writeData(Ostream& os) const bool Foam::rawIOField<Type>::writeData(Ostream& os) const
{ {
os << static_cast<const Field<Type>&>(*this); os << static_cast<const Field<Type>&>(*this);
if (average_ != pTraits<Type>::zero) if (hasAverage_)
{ {
os << token::NL << average_; os << token::NL << average_;
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef rawIOField_H #ifndef Foam_rawIOField_H
#define rawIOField_H #define Foam_rawIOField_H
#include "IOField.H" #include "IOField.H"
@ -57,7 +57,10 @@ class rawIOField
{ {
// Private Data // 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_; Type average_;
@ -72,7 +75,7 @@ public:
rawIOField(const rawIOField&) = default; rawIOField(const rawIOField&) = default;
//- Construct from IOobject //- Construct from IOobject
explicit rawIOField(const IOobject& io, const bool readAverage); explicit rawIOField(const IOobject& io, const bool readAverage=false);
//- Destructor //- Destructor
@ -81,11 +84,21 @@ public:
// Member Functions // 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_; return average_;
} }
//- Set an average value
void setAverage(const Type& val);
bool writeData(Ostream& os) const; bool writeData(Ostream& os) const;

View File

@ -325,7 +325,6 @@ PatchFunction1/PatchFunction1/patchFunction1Base.C
PatchFunction1/makePatchFunction1s.C PatchFunction1/makePatchFunction1s.C
PatchFunction1/coordinateScaling/coordinateScalings.C PatchFunction1/coordinateScaling/coordinateScalings.C
PatchFunction1/CodedField/makeCodedFields.C PatchFunction1/CodedField/makeCodedFields.C
PatchFunction1/MappedFile/rawIOFields.C
meshStructure/meshStructure.C meshStructure/meshStructure.C