functionObjects: Emit warning messages only for field names which do not exist for any type

Resolves bug-report https://bugs.openfoam.org/view.php?id=3583
This commit is contained in:
Henry Weller
2020-10-27 20:03:19 +00:00
parent efbf198022
commit f7848e62a1
27 changed files with 140 additions and 123 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -40,6 +40,17 @@ namespace functionObjects
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::functionObjects::regionFunctionObject::cannotFindObject
(
const word& fieldName
)
{
Warning
<< " functionObjects::" << type() << " " << name()
<< " cannot find required object " << fieldName << endl;
}
bool Foam::functionObjects::regionFunctionObject::writeObject bool Foam::functionObjects::regionFunctionObject::writeObject
( (
const word& fieldName const word& fieldName

View File

@ -78,6 +78,13 @@ protected:
template<class ObjectType> template<class ObjectType>
bool foundObject(const word& fieldName) const; bool foundObject(const word& fieldName) const;
//- Prints a warning message that fieldName cannot be found
template<class ObjectType>
void cannotFindObject(const word& fieldName);
//- Prints a warning message that fieldName cannot be found
void cannotFindObject(const word& fieldName);
//- Lookup object from the objectRegistry //- Lookup object from the objectRegistry
template<class ObjectType> template<class ObjectType>
const ObjectType& lookupObject(const word& fieldName) const; const ObjectType& lookupObject(const word& fieldName) const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -38,6 +38,19 @@ bool Foam::functionObjects::regionFunctionObject::foundObject
} }
template<class Type>
void Foam::functionObjects::regionFunctionObject::cannotFindObject
(
const word& fieldName
)
{
Warning
<< " functionObjects::" << type() << " " << name()
<< " cannot find required object " << fieldName << " of type "
<< Type::typeName << endl;
}
template<class ObjectType> template<class ObjectType>
const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -98,6 +98,8 @@ bool Foam::functionObjects::CourantNo::calc()
} }
else else
{ {
cannotFindObject<surfaceScalarField>(fieldName_);
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -69,6 +69,8 @@ bool Foam::functionObjects::Lambda2::calc()
} }
else else
{ {
cannotFindObject<volVectorField>(fieldName_);
return false; return false;
} }
} }

View File

@ -76,6 +76,8 @@ bool Foam::functionObjects::PecletNo::calc()
} }
else else
{ {
cannotFindObject<surfaceScalarField>(fieldName_);
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -63,6 +63,8 @@ bool Foam::functionObjects::Q::calc()
} }
else else
{ {
cannotFindObject<volVectorField>(fieldName_);
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,6 +47,11 @@ bool Foam::functionObjects::blendingFactor::calc()
processed = processed || calcBF<scalar>(); processed = processed || calcBF<scalar>();
processed = processed || calcBF<vector>(); processed = processed || calcBF<vector>();
if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -49,6 +49,11 @@ bool Foam::functionObjects::components::calc()
processed = processed || calcComponents<symmTensor>(); processed = processed || calcComponents<symmTensor>();
processed = processed || calcComponents<tensor>(); processed = processed || calcComponents<tensor>();
if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -53,11 +53,14 @@ bool Foam::functionObjects::ddt::calc()
bool processed = false; bool processed = false;
processed = processed || calcDdt<scalar>(); #define processType(fieldType, none) \
processed = processed || calcDdt<vector>(); processed = processed || calcDdt<fieldType>();
processed = processed || calcDdt<sphericalTensor>(); FOR_ALL_FIELD_TYPES(processType)
processed = processed || calcDdt<symmTensor>();
processed = processed || calcDdt<tensor>(); if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -49,6 +49,11 @@ bool Foam::functionObjects::div::calc()
processed = processed || calcDiv<surfaceScalarField>(); processed = processed || calcDiv<surfaceScalarField>();
processed = processed || calcDiv<volVectorField>(); processed = processed || calcDiv<volVectorField>();
if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -59,6 +59,8 @@ bool Foam::functionObjects::enstrophy::calc()
} }
else else
{ {
cannotFindObject<volVectorField>(fieldName_);
return false; return false;
} }

View File

@ -38,7 +38,6 @@ SourceFiles
#define functionObjects_fieldExpression_H #define functionObjects_fieldExpression_H
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,9 +69,6 @@ protected:
virtual bool calc() = 0; virtual bool calc() = 0;
template<class Type>
bool foundObject(const word& name);
public: public:
@ -129,12 +125,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldExpressionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,52 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldExpression.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldExpression::foundObject
(
const word& name
)
{
if (fvMeshFunctionObject::foundObject<Type>(name))
{
return true;
}
else
{
Warning
<< " functionObjects::" << type() << " " << this->name()
<< " cannot find required object " << name << " of type "
<< Type::typeName << endl;
return false;
}
}
// ************************************************************************* //

View File

@ -191,18 +191,13 @@ bool Foam::functionObjects::fieldValues::volFieldValue::write()
const word& fieldName = fields_[i]; const word& fieldName = fields_[i];
bool processed = false; bool processed = false;
processed = processed || writeValues<scalar>(fieldName); #define processType(fieldType, none) \
processed = processed || writeValues<vector>(fieldName); processed = processed || writeValues<fieldType>(fieldName);
processed = processed || writeValues<sphericalTensor>(fieldName); FOR_ALL_FIELD_TYPES(processType)
processed = processed || writeValues<symmTensor>(fieldName);
processed = processed || writeValues<tensor>(fieldName);
if (!processed) if (!processed)
{ {
WarningInFunction cannotFindObject(fieldName);
<< "Requested field " << fieldName
<< " not found in database and not processed"
<< endl;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -69,11 +69,9 @@ bool Foam::functionObjects::fieldsExpression::calcAllTypes(FOType& fo)
{ {
bool processed = false; bool processed = false;
processed = processed || fo.template calcType<scalar>(fo); #define processType(fieldType, none) \
processed = processed || fo.template calcType<vector>(fo); processed = processed || fo.template calcType<fieldType>(fo);
processed = processed || fo.template calcType<sphericalTensor>(fo); FOR_ALL_FIELD_TYPES(processType)
processed = processed || fo.template calcType<symmTensor>(fo);
processed = processed || fo.template calcType<tensor>(fo);
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -73,6 +73,8 @@ bool Foam::functionObjects::flowType::calc()
} }
else else
{ {
cannotFindObject<volVectorField>(fieldName_);
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,6 +47,11 @@ bool Foam::functionObjects::grad::calc()
processed = processed || calcGrad<scalar>(); processed = processed || calcGrad<scalar>();
processed = processed || calcGrad<vector>(); processed = processed || calcGrad<vector>();
if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -78,6 +78,8 @@ bool Foam::functionObjects::log::calc()
} }
else else
{ {
cannotFindObject<volScalarField>(fieldName_);
return false; return false;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -44,11 +44,14 @@ bool Foam::functionObjects::mag::calc()
{ {
bool processed = false; bool processed = false;
processed = processed || calcMag<scalar>(); #define processType(fieldType, none) \
processed = processed || calcMag<vector>(); processed = processed || calcMag<fieldType>();
processed = processed || calcMag<sphericalTensor>(); FOR_ALL_FIELD_TYPES(processType)
processed = processed || calcMag<symmTensor>();
processed = processed || calcMag<tensor>(); if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -44,11 +44,14 @@ bool Foam::functionObjects::magSqr::calc()
{ {
bool processed = false; bool processed = false;
processed = processed || calcMagSqr<scalar>(); #define processType(fieldType, none) \
processed = processed || calcMagSqr<vector>(); processed = processed || calcMagSqr<fieldType>();
processed = processed || calcMagSqr<sphericalTensor>(); FOR_ALL_FIELD_TYPES(processType)
processed = processed || calcMagSqr<symmTensor>();
processed = processed || calcMagSqr<tensor>(); if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -175,6 +175,8 @@ bool Foam::functionObjects::pressure::calc()
} }
else else
{ {
cannotFindObject<volScalarField>(fieldName_);
return false; return false;
} }
} }

View File

@ -44,11 +44,14 @@ bool Foam::functionObjects::randomise::calc()
{ {
bool processed = false; bool processed = false;
processed = processed || calcRandomised<scalar>(); #define processType(fieldType, none) \
processed = processed || calcRandomised<vector>(); processed = processed || calcRandomised<fieldType>();
processed = processed || calcRandomised<sphericalTensor>(); FOR_ALL_FIELD_TYPES(processType)
processed = processed || calcRandomised<symmTensor>();
processed = processed || calcRandomised<tensor>(); if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -44,11 +44,14 @@ bool Foam::functionObjects::scale::calc()
{ {
bool processed = false; bool processed = false;
processed = processed || calcScale<scalar>(); #define processType(fieldType, none) \
processed = processed || calcScale<vector>(); processed = processed || calcScale<fieldType>();
processed = processed || calcScale<sphericalTensor>(); FOR_ALL_FIELD_TYPES(processType)
processed = processed || calcScale<symmTensor>();
processed = processed || calcScale<tensor>(); if (!processed)
{
cannotFindObject(fieldName_);
}
return processed; return processed;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -420,6 +420,8 @@ bool Foam::functionObjects::streamFunction::calc()
} }
else else
{ {
cannotFindObject<surfaceScalarField>(fieldName_);
return false; return false;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2014-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -59,6 +59,8 @@ bool Foam::functionObjects::vorticity::calc()
} }
else else
{ {
cannotFindObject<volVectorField>(fieldName_);
return false; return false;
} }

View File

@ -17,7 +17,7 @@ FoamFile
application rhoCentralFoam; application rhoCentralFoam;
startFrom latestTime; startFrom startTime;
startTime 0; startTime 0;
@ -53,7 +53,7 @@ maxDeltaT 2e-8;
functions functions
{ {
#includeFunc wallHeatFlux #includeFunc wallHeatFlux(log = true)
#includeFunc sample #includeFunc sample
} }