mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: fieldSelection - added checks for when fields are not found
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,11 +35,15 @@ 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()));
|
||||||
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);
|
selection_.transfer(newSelection);
|
||||||
|
|
||||||
|
(void)fieldSelection::checkSelection();
|
||||||
|
|
||||||
return selection_ != oldSet;
|
return selection_ != oldSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,15 +33,20 @@ template<class Type>
|
|||||||
void Foam::functionObjects::fileFieldSelection::addFromFile
|
void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||||
(
|
(
|
||||||
const IOobjectList& allFileObjects,
|
const IOobjectList& allFileObjects,
|
||||||
DynamicList<fieldInfo>& set
|
DynamicList<fieldInfo>& set
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
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()));
|
||||||
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
|
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)
|
||||||
|
{
|
||||||
|
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);
|
selection_.transfer(newSelection);
|
||||||
|
|
||||||
|
if (!fieldSelection::checkSelection())
|
||||||
|
{
|
||||||
|
WarningInFunction
|
||||||
|
<< "Valid solver fields are: " << solvedFieldNames;
|
||||||
|
}
|
||||||
|
|
||||||
return selection_ != oldSet;
|
return selection_ != oldSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
||||||
|
|
||||||
|
|||||||
@ -51,6 +51,8 @@ bool Foam::functionObjects::volFieldSelection::updateSelection()
|
|||||||
|
|
||||||
selection_.transfer(newSet);
|
selection_.transfer(newSet);
|
||||||
|
|
||||||
|
(void)fieldSelection::checkSelection();
|
||||||
|
|
||||||
return selection_ != oldSet;
|
return selection_ != oldSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user