diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H b/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H index 8ad94ff1fb..7eb048005b 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H @@ -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; } }; diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C index 9fa43e68be..f21835a12d 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C @@ -84,7 +84,7 @@ bool Foam::functionObjects::fieldSelection::resetFieldFilters FatalErrorInFunction << "Invalid field component specification for " << name << nl - << "Field should be expressed as .component(i)" + << ". Field should be expressed as .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; +} + + // ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H index fec94974db..e4a510679c 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H @@ -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(); }; diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C index 560f8adf4d..4e80fc2602 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C @@ -35,11 +35,15 @@ void Foam::functionObjects::fieldSelection::addRegistered { for (const fieldInfo& fi : *this) { - set.insert(obr_.names(name)); wordList names(obr_.names(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; } } } diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C index 6616562c6d..5387d0b7e3 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C @@ -100,6 +100,8 @@ bool Foam::functionObjects::fileFieldSelection::updateSelection() selection_.transfer(newSelection); + (void)fieldSelection::checkSelection(); + return selection_ != oldSet; } diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C index 3b360ff026..6dda18bb90 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C @@ -33,15 +33,20 @@ template void Foam::functionObjects::fileFieldSelection::addFromFile ( const IOobjectList& allFileObjects, - DynamicList& set + DynamicList& 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; } } } diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C index 247051da98..14e955b66f 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C +++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C @@ -36,7 +36,7 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection const bool includeComponents ) : - volFieldSelection(obr, includeComponents) + fieldSelection(obr, includeComponents) { if (!isA(obr)) { @@ -53,27 +53,37 @@ bool Foam::functionObjects::solverFieldSelection::updateSelection() { List oldSet(std::move(selection_)); - DynamicList volFields; - addRegisteredGeoFields(volFields); - DynamicList newSelection(oldSet.size()); const fvMesh& mesh = static_cast(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; } diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H index 4ae1e670ac..d1a239b853 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H +++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H @@ -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: diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C index 606ff341eb..bd367b8301 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C +++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C @@ -51,6 +51,8 @@ bool Foam::functionObjects::volFieldSelection::updateSelection() selection_.transfer(newSet); + (void)fieldSelection::checkSelection(); + return selection_ != oldSet; } diff --git a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C index 0d96061784..0f5b6794ab 100644 --- a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C +++ b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C @@ -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))