Commit 452a281a authored by Andrew Heather's avatar Andrew Heather
Browse files

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

parent 9e202d14
......@@ -33,8 +33,9 @@ Description
#ifndef functionObjects_fieldInfo_H
#define functionObjects_fieldInfo_H
#include "label.H"
#include "wordRe.H"
#include "label.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -61,6 +62,9 @@ class fieldInfo
//- Field component
label component_;
//- Found
mutable Switch found_;
public:
......@@ -70,7 +74,8 @@ public:
fieldInfo()
:
name_(word::null),
component_(-1)
component_(-1),
found_(false)
{}
......@@ -78,14 +83,16 @@ public:
fieldInfo(const wordRe& name, const label component = -1)
:
name_(name),
component_(component)
component_(component),
found_(false)
{}
//- Construct from stream
fieldInfo(Istream& is)
:
name_(is),
component_(readLabel(is))
component_(readLabel(is)),
found_(false)
{}
......@@ -105,9 +112,17 @@ public:
return component_;
}
Switch& found() const
{
return found_;
}
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)
......@@ -120,12 +135,12 @@ public:
friend Istream& operator>>(Istream& is, fieldInfo& fi)
{
is >> fi.name_ >> fi.component_;
is >> fi.name_ >> fi.component_ >> fi.found_;
return is;
}
friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
{
os << fi.name_ << ' ' << fi.component_;
os << fi.name_ << ' ' << fi.component_ << ' ' << fi.found_;
return os;
}
};
......
......@@ -84,7 +84,7 @@ bool Foam::functionObjects::fieldSelection::resetFieldFilters
FatalErrorInFunction
<< "Invalid field component specification for "
<< name << nl
<< "Field should be expressed as <field>.component(i)"
<< ". Field should be expressed as <field>.component(i)"
<< 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;
}
// ************************************************************************* //
......@@ -131,8 +131,11 @@ public:
//- Clear the current selection
virtual void clearSelection();
//- Update the selection using current contents of obr_
//- Update the selection
virtual bool updateSelection();
//- Check that all requested fielda have been found
virtual bool checkSelection();
};
......
......@@ -35,11 +35,15 @@ void Foam::functionObjects::fieldSelection::addRegistered
{
for (const fieldInfo& fi : *this)
{
set.insert(obr_.names<Type>(name));
wordList names(obr_.names<Type>(fi.name()));
for (const word& name : names)
if (names.size())
{
set.append(fieldInfo(wordRe(name), fi.component()));
for (const word& name : names)
{
set.append(fieldInfo(wordRe(name), fi.component()));
}
fi.found() = true;
}
}
}
......
......@@ -100,6 +100,8 @@ bool Foam::functionObjects::fileFieldSelection::updateSelection()
selection_.transfer(newSelection);
(void)fieldSelection::checkSelection();
return selection_ != oldSet;
}
......
......@@ -33,15 +33,20 @@ template<class Type>
void Foam::functionObjects::fileFieldSelection::addFromFile
(
const IOobjectList& allFileObjects,
DynamicList<fieldInfo>& set
DynamicList<fieldInfo>& set
) const
{
for (const fieldInfo& fi : *this)
{
const wordList names(allFileObjects.names(Type::typeName, fi.name()));
for (const word& name : names)
if (names.size())
{
set.append(fieldInfo(wordRe(name)));
for (const word& name : names)
{
set.append(fieldInfo(wordRe(name)));
}
fi.found() = true;
}
}
}
......
......@@ -36,7 +36,7 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
const bool includeComponents
)
:
volFieldSelection(obr, includeComponents)
fieldSelection(obr, includeComponents)
{
if (!isA<fvMesh>(obr))
{
......@@ -53,27 +53,37 @@ bool Foam::functionObjects::solverFieldSelection::updateSelection()
{
List<fieldInfo> oldSet(std::move(selection_));
DynamicList<fieldInfo> volFields;
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
DynamicList<fieldInfo> newSelection(oldSet.size());
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const dictionary& solverDict = mesh.solverPerformanceDict();
for (const fieldInfo& fi : volFields)
{
const wordRe& name = fi.name();
const wordList solvedFieldNames(solverDict.sortedToc());
if (solverDict.found(name))
for (const fieldInfo& fi : *this)
{
for (const word& solvedField : solvedFieldNames)
{
newSelection.append(fi);
if (fi.name().match(solvedField))
{
newSelection.append
(
fieldInfo(wordRe(solvedField), fi.component())
);
fi.found() = true;
}
}
}
selection_.transfer(newSelection);
if (!fieldSelection::checkSelection())
{
WarningInFunction
<< "Valid solver fields are: " << solvedFieldNames;
}
return selection_ != oldSet;
}
......
......@@ -28,14 +28,14 @@ Description
Helper class to manage solver field selections
SourceFiles
volFieldSelection.C
solverFieldSelection.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_solverFieldSelection_H
#define functionObjects_solverFieldSelection_H
#include "volFieldSelection.H"
#include "fieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -50,7 +50,7 @@ namespace functionObjects
class solverFieldSelection
:
public volFieldSelection
public fieldSelection
{
private:
......
......@@ -51,6 +51,8 @@ bool Foam::functionObjects::volFieldSelection::updateSelection()
selection_.transfer(newSet);
(void)fieldSelection::checkSelection();
return selection_ != oldSet;
}
......
......@@ -70,8 +70,8 @@ operatingModeNames
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
equationInitialResidualCondition
Foam::functionObjects::runTimeControls::
equationInitialResidualCondition::equationInitialResidualCondition
(
const word& name,
const objectRegistry& obr,
......@@ -130,7 +130,6 @@ equationInitialResidualCondition::apply()
forAll(selection, fieldi)
{
const auto& fieldInfo = selection[fieldi];
const word& fieldName = fieldInfo.name();
if (solverDict.found(fieldName))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment