ENH: fieldSelection - added checks for when fields are not found

This commit is contained in:
Andrew Heather
2019-01-21 12:16:13 +00:00
parent 9e202d141d
commit 452a281a00
10 changed files with 89 additions and 30 deletions

View File

@ -33,8 +33,9 @@ Description
#ifndef functionObjects_fieldInfo_H #ifndef functionObjects_fieldInfo_H
#define functionObjects_fieldInfo_H #define functionObjects_fieldInfo_H
#include "label.H"
#include "wordRe.H" #include "wordRe.H"
#include "label.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -61,6 +62,9 @@ class fieldInfo
//- Field component //- Field component
label component_; label component_;
//- Found
mutable Switch found_;
public: public:
@ -70,7 +74,8 @@ public:
fieldInfo() fieldInfo()
: :
name_(word::null), name_(word::null),
component_(-1) component_(-1),
found_(false)
{} {}
@ -78,14 +83,16 @@ public:
fieldInfo(const wordRe& name, const label component = -1) fieldInfo(const wordRe& name, const label component = -1)
: :
name_(name), name_(name),
component_(component) component_(component),
found_(false)
{} {}
//- Construct from stream //- Construct from stream
fieldInfo(Istream& is) fieldInfo(Istream& is)
: :
name_(is), name_(is),
component_(readLabel(is)) component_(readLabel(is)),
found_(false)
{} {}
@ -105,9 +112,17 @@ public:
return component_; return component_;
} }
Switch& found() const
{
return found_;
}
friend bool operator==(const fieldInfo& a, const fieldInfo& b) friend bool operator==(const fieldInfo& a, const fieldInfo& b)
{ {
return a.name_ == b.name_ && a.component_ == b.component_; return
a.name_ == b.name_
&& a.component_ == b.component_
&& a.found_ == b.found_;
} }
friend bool operator!=(const fieldInfo& a, const fieldInfo& b) friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
@ -120,12 +135,12 @@ public:
friend Istream& operator>>(Istream& is, fieldInfo& fi) friend Istream& operator>>(Istream& is, fieldInfo& fi)
{ {
is >> fi.name_ >> fi.component_; is >> fi.name_ >> fi.component_ >> fi.found_;
return is; return is;
} }
friend Ostream& operator<<(Ostream& os, const fieldInfo& fi) friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
{ {
os << fi.name_ << ' ' << fi.component_; os << fi.name_ << ' ' << fi.component_ << ' ' << fi.found_;
return os; return os;
} }
}; };

View File

@ -84,7 +84,7 @@ bool Foam::functionObjects::fieldSelection::resetFieldFilters
FatalErrorInFunction FatalErrorInFunction
<< "Invalid field component specification for " << "Invalid field component specification for "
<< name << nl << name << nl
<< "Field should be expressed as <field>.component(i)" << ". Field should be expressed as <field>.component(i)"
<< exit(FatalError); << exit(FatalError);
} }
@ -154,4 +154,23 @@ bool Foam::functionObjects::fieldSelection::updateSelection()
} }
bool Foam::functionObjects::fieldSelection::checkSelection()
{
bool ok = true;
for (const fieldInfo& fi : *this)
{
if (!fi.found())
{
WarningInFunction
<< "Field " << fi.name() << " not found"
<< endl;
ok = false;
}
}
return ok;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -131,8 +131,11 @@ public:
//- Clear the current selection //- Clear the current selection
virtual void clearSelection(); virtual void clearSelection();
//- Update the selection using current contents of obr_ //- Update the selection
virtual bool updateSelection(); virtual bool updateSelection();
//- Check that all requested fielda have been found
virtual bool checkSelection();
}; };

View File

@ -35,12 +35,16 @@ void Foam::functionObjects::fieldSelection::addRegistered
{ {
for (const fieldInfo& fi : *this) for (const fieldInfo& fi : *this)
{ {
set.insert(obr_.names<Type>(name));
wordList names(obr_.names<Type>(fi.name())); wordList names(obr_.names<Type>(fi.name()));
if (names.size())
{
for (const word& name : names) for (const word& name : names)
{ {
set.append(fieldInfo(wordRe(name), fi.component())); set.append(fieldInfo(wordRe(name), fi.component()));
} }
fi.found() = true;
}
} }
} }

View File

@ -100,6 +100,8 @@ bool Foam::functionObjects::fileFieldSelection::updateSelection()
selection_.transfer(newSelection); selection_.transfer(newSelection);
(void)fieldSelection::checkSelection();
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -39,10 +39,15 @@ void Foam::functionObjects::fileFieldSelection::addFromFile
for (const fieldInfo& fi : *this) for (const fieldInfo& fi : *this)
{ {
const wordList names(allFileObjects.names(Type::typeName, fi.name())); const wordList names(allFileObjects.names(Type::typeName, fi.name()));
if (names.size())
{
for (const word& name : names) for (const word& name : names)
{ {
set.append(fieldInfo(wordRe(name))); set.append(fieldInfo(wordRe(name)));
} }
fi.found() = true;
}
} }
} }

View File

@ -36,7 +36,7 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
const bool includeComponents const bool includeComponents
) )
: :
volFieldSelection(obr, includeComponents) fieldSelection(obr, includeComponents)
{ {
if (!isA<fvMesh>(obr)) if (!isA<fvMesh>(obr))
{ {
@ -53,27 +53,37 @@ bool Foam::functionObjects::solverFieldSelection::updateSelection()
{ {
List<fieldInfo> oldSet(std::move(selection_)); List<fieldInfo> oldSet(std::move(selection_));
DynamicList<fieldInfo> volFields;
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
DynamicList<fieldInfo> newSelection(oldSet.size()); DynamicList<fieldInfo> newSelection(oldSet.size());
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const dictionary& solverDict = mesh.solverPerformanceDict(); const dictionary& solverDict = mesh.solverPerformanceDict();
for (const fieldInfo& fi : volFields) const wordList solvedFieldNames(solverDict.sortedToc());
{
const wordRe& name = fi.name();
if (solverDict.found(name)) for (const fieldInfo& fi : *this)
{ {
newSelection.append(fi); for (const word& solvedField : solvedFieldNames)
{
if (fi.name().match(solvedField))
{
newSelection.append
(
fieldInfo(wordRe(solvedField), fi.component())
);
fi.found() = true;
}
} }
} }
selection_.transfer(newSelection); selection_.transfer(newSelection);
if (!fieldSelection::checkSelection())
{
WarningInFunction
<< "Valid solver fields are: " << solvedFieldNames;
}
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -28,14 +28,14 @@ Description
Helper class to manage solver field selections Helper class to manage solver field selections
SourceFiles SourceFiles
volFieldSelection.C solverFieldSelection.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef functionObjects_solverFieldSelection_H #ifndef functionObjects_solverFieldSelection_H
#define functionObjects_solverFieldSelection_H #define functionObjects_solverFieldSelection_H
#include "volFieldSelection.H" #include "fieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,7 +50,7 @@ namespace functionObjects
class solverFieldSelection class solverFieldSelection
: :
public volFieldSelection public fieldSelection
{ {
private: private:

View File

@ -51,6 +51,8 @@ bool Foam::functionObjects::volFieldSelection::updateSelection()
selection_.transfer(newSet); selection_.transfer(newSet);
(void)fieldSelection::checkSelection();
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -70,8 +70,8 @@ operatingModeNames
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: Foam::functionObjects::runTimeControls::
equationInitialResidualCondition equationInitialResidualCondition::equationInitialResidualCondition
( (
const word& name, const word& name,
const objectRegistry& obr, const objectRegistry& obr,
@ -130,7 +130,6 @@ equationInitialResidualCondition::apply()
forAll(selection, fieldi) forAll(selection, fieldi)
{ {
const auto& fieldInfo = selection[fieldi]; const auto& fieldInfo = selection[fieldi];
const word& fieldName = fieldInfo.name(); const word& fieldName = fieldInfo.name();
if (solverDict.found(fieldName)) if (solverDict.found(fieldName))