diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H b/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H
new file mode 100644
index 0000000000..8ad94ff1fb
--- /dev/null
+++ b/src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H
@@ -0,0 +1,142 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
+ \\/ 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 .
+
+Class
+ Foam::functionObjects::fieldInfo
+
+Description
+ Helper class to store a wordRe and label used by
+ Foam::functionObjects::fieldSelection
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef functionObjects_fieldInfo_H
+#define functionObjects_fieldInfo_H
+
+#include "label.H"
+#include "wordRe.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace functionObjects
+{
+
+/*---------------------------------------------------------------------------*\
+ Class fieldInfo Declaration
+\*---------------------------------------------------------------------------*/
+
+class fieldInfo;
+Istream& operator>>(Istream&, fieldInfo&);
+Ostream& operator<<(Ostream&, const fieldInfo&);
+
+class fieldInfo
+{
+ // Pivate data
+
+ //- Pattern for the field name
+ wordRe name_;
+
+ //- Field component
+ label component_;
+
+
+public:
+
+ // Constructors
+
+ //- Null constructor
+ fieldInfo()
+ :
+ name_(word::null),
+ component_(-1)
+ {}
+
+
+ //- Construct from components
+ fieldInfo(const wordRe& name, const label component = -1)
+ :
+ name_(name),
+ component_(component)
+ {}
+
+ //- Construct from stream
+ fieldInfo(Istream& is)
+ :
+ name_(is),
+ component_(readLabel(is))
+ {}
+
+
+ //- Destructor
+ ~fieldInfo() = default;
+
+
+ // Member Functions
+
+ const wordRe& name() const
+ {
+ return name_;
+ }
+
+ label component() const
+ {
+ return component_;
+ }
+
+ friend bool operator==(const fieldInfo& a, const fieldInfo& b)
+ {
+ return a.name_ == b.name_ && a.component_ == b.component_;
+ }
+
+ friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
+ {
+ return !(a == b);
+ }
+
+
+ // IOstream Operators
+
+ friend Istream& operator>>(Istream& is, fieldInfo& fi)
+ {
+ is >> fi.name_ >> fi.component_;
+ return is;
+ }
+ friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
+ {
+ os << fi.name_ << ' ' << fi.component_;
+ return os;
+ }
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace functionObjects
+} // End namespace Foam
+
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C
index 63fa608ef5..9fa43e68be 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -31,36 +31,108 @@ License
Foam::functionObjects::fieldSelection::fieldSelection
(
- const objectRegistry& obr
+ const objectRegistry& obr,
+ const bool includeComponents
)
:
- HashSet(),
+ List(),
obr_(obr),
+ includeComponents_(includeComponents),
selection_()
{}
-// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
+bool Foam::functionObjects::fieldSelection::resetFieldFilters
+(
+ const HashSet& names
+)
+{
+ static word cmptStr(".component(");
+ static string::size_type len(cmptStr.size());
-Foam::functionObjects::fieldSelection::~fieldSelection()
-{}
+ DynamicList nameAndComponent(names.size());
+
+ for (const wordRe& name : names)
+ {
+ string::size_type n = name.find(cmptStr);
+ if (n != string::npos)
+ {
+ // Field should be written .component(i)
+
+ if (!includeComponents_)
+ {
+ FatalErrorInFunction
+ << "Component specification not allowed for " << name
+ << exit(FatalError);
+ }
+
+ if (name.isPattern())
+ {
+ FatalErrorInFunction
+ << "Cannot use \".component option\" in combination with "
+ << "wildcards for " << name
+ << exit(FatalError);
+ }
+
+ word baseName = name.substr(0, n);
+
+ // Extract the component - number between ()'s
+ string::size_type closei = name.find(')', n);
+
+ if (closei == string::npos)
+ {
+ FatalErrorInFunction
+ << "Invalid field component specification for "
+ << name << nl
+ << "Field should be expressed as .component(i)"
+ << exit(FatalError);
+ }
+
+ string::size_type cmptWidth = closei - n - len;
+
+ label component
+ (
+ readLabel(IStringStream(name.substr(n+len, cmptWidth))())
+ );
+
+ nameAndComponent.append(fieldInfo(wordRe(baseName), component));
+ }
+ else
+ {
+ nameAndComponent.append(fieldInfo(name));
+ }
+ }
+
+ this->transfer(nameAndComponent);
+
+ return true;
+}
+
+
+bool Foam::functionObjects::fieldSelection::resetFieldFilters
+(
+ const wordRe& name
+)
+{
+ return resetFieldFilters(HashSet({name}));
+}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldSelection::read(const dictionary& dict)
{
- dict.readEntry("fields", *this);
+ HashSet fields(dict.lookup("fields"));
- return true;
+ return resetFieldFilters(fields);
}
bool Foam::functionObjects::fieldSelection::containsPattern() const
{
- for (const wordRe& fieldName : *this)
+ for (const fieldInfo& fi : *this)
{
- if (fieldName.isPattern())
+ if (fi.name().isPattern())
{
return true;
}
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H
index 72af300dbc..fec94974db 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H
+++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -27,6 +27,11 @@ Class
Description
Helper class to manage field selections
+ The class holds a list of field name filters which are then applied to a
+ set of field objects (in derived classes) from which the resulting set is
+ available via the selection() function. This returns a list of
+ (fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
+
SourceFiles
fieldSelection.C
@@ -35,8 +40,9 @@ SourceFiles
#ifndef functionObjects_fieldSelection_H
#define functionObjects_fieldSelection_H
+#include "fieldInfo.H"
+#include "DynamicList.H"
#include "HashSet.H"
-#include "wordRe.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -55,7 +61,7 @@ namespace functionObjects
class fieldSelection
:
- public HashSet
+ public List
{
private:
@@ -72,35 +78,50 @@ protected:
//- Reference to the database
const objectRegistry& obr_;
+ //- Flag to indicate whether components are allowed
+ const bool includeComponents_;
+
//- Current field selection
- wordHashSet selection_;
+ List selection_;
// Protected Member Functions
//- Add registered objects of a given type
template
- void addRegistered(wordHashSet& set) const;
+ void addRegistered(DynamicList& set) const;
public:
//- Construct from object registry
- fieldSelection(const objectRegistry& obr);
+ fieldSelection
+ (
+ const objectRegistry& obr,
+ const bool includeComponents = false
+ );
//- Destructor
- virtual ~fieldSelection();
+ virtual ~fieldSelection() = default;
// Member Functions
- //- Return the current field selection
- const wordHashSet& selection() const
- {
- return selection_;
- }
+ //- Return the cuurent filters
+ inline HashSet filters() const;
+ inline const List& selection() const;
+
+ //- Return the current field selection
+ inline wordHashSet selectionNames() const;
+
+ //- Reset the field filters to the given field names
+ virtual bool resetFieldFilters(const HashSet& names);
+
+ //- Reset the field filters to the given field name
+ virtual bool resetFieldFilters(const wordRe& name);
+
//- Read the fieldSelection data from dictionary
virtual bool read(const dictionary& dict);
@@ -122,6 +143,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+#include "fieldSelectionI.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
#ifdef NoRepository
#include "fieldSelectionTemplates.C"
#endif
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionI.H b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionI.H
new file mode 100644
index 0000000000..3b656a1681
--- /dev/null
+++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionI.H
@@ -0,0 +1,60 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+inline Foam::HashSet
+Foam::functionObjects::fieldSelection::filters() const
+{
+ HashSet f;
+ for (const auto fieldInfo : *this)
+ {
+ f.insert(fieldInfo.name());
+ }
+
+ return f;
+}
+
+// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
+
+inline const Foam::List&
+Foam::functionObjects::fieldSelection::selection() const
+{
+ return selection_;
+}
+
+
+inline Foam::wordHashSet
+Foam::functionObjects::fieldSelection::selectionNames() const
+{
+ wordHashSet names;
+ for (const fieldInfo& fi : *this)
+ {
+ names.insert(fi.name());
+ }
+
+ return names;
+}
+
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C
index 95a692847e..560f8adf4d 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/
-#include "DynamicList.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
@@ -31,12 +30,17 @@ License
template
void Foam::functionObjects::fieldSelection::addRegistered
(
- wordHashSet& set
+ DynamicList& set
) const
{
- for (const wordRe& name : *this)
+ for (const fieldInfo& fi : *this)
{
set.insert(obr_.names(name));
+ wordList names(obr_.names(fi.name()));
+ for (const word& name : names)
+ {
+ set.append(fieldInfo(wordRe(name), fi.component()));
+ }
}
}
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C
index 0456be0dc1..6616562c6d 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -35,7 +35,7 @@ License
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
(
- wordHashSet& set
+ DynamicList& set
) const
{
const fvMesh& mesh = static_cast(obr_);
@@ -52,7 +52,7 @@ void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
(
- wordHashSet& set
+ DynamicList& set
) const
{
const fvMesh& mesh = static_cast(obr_);
@@ -71,16 +71,11 @@ void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
Foam::functionObjects::fileFieldSelection::fileFieldSelection
(
- const objectRegistry& obr
+ const objectRegistry& obr,
+ const bool includeComponents
)
:
- fieldSelection(obr)
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
+ fieldSelection(obr, includeComponents)
{}
@@ -88,19 +83,22 @@ Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
bool Foam::functionObjects::fileFieldSelection::updateSelection()
{
- wordHashSet oldSet;
- oldSet.swap(selection_);
+ List oldSet(std::move(selection_));
+
+ DynamicList newSelection(oldSet.size());
// Geometric fields
- addGeoFieldTypes(selection_);
- addGeoFieldTypes(selection_);
- addGeoFieldTypes(selection_);
+ addGeoFieldTypes(newSelection);
+ addGeoFieldTypes(newSelection);
+ addGeoFieldTypes(newSelection);
// Internal fields
- addInternalFieldTypes(selection_);
+ addInternalFieldTypes(newSelection);
// Uniform fields
- addUniformFieldTypes(selection_);
+ addUniformFieldTypes(newSelection);
+
+ selection_.transfer(newSelection);
return selection_ != oldSet;
}
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H
index cb94ce10b8..3955eb8319 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H
+++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -69,31 +69,35 @@ protected:
//- Add registered GeometricField types to selection
template class PatchType, class MeshType>
- void addGeoFieldTypes(wordHashSet& set) const;
+ void addGeoFieldTypes(DynamicList& set) const;
//- Add registered Internal types to selection
- void addInternalFieldTypes(wordHashSet& set) const;
+ void addInternalFieldTypes(DynamicList& set) const;
//- Add registered uniform types to selection
- void addUniformFieldTypes(wordHashSet& set) const;
+ void addUniformFieldTypes(DynamicList& set) const;
//- Add objects of a given type
template
void addFromFile
(
const IOobjectList& allFileObjects,
- wordHashSet& set
+ DynamicList& set
) const;
public:
//- Construct from object registry
- fileFieldSelection(const objectRegistry& obr);
+ fileFieldSelection
+ (
+ const objectRegistry& obr,
+ const bool includeComponents = false
+ );
//- Destructor
- virtual ~fileFieldSelection();
+ virtual ~fileFieldSelection() = default;
// Member Functions
diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C
index 463aeac040..3b360ff026 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C
@@ -33,12 +33,16 @@ template
void Foam::functionObjects::fileFieldSelection::addFromFile
(
const IOobjectList& allFileObjects,
- wordHashSet& set
+ DynamicList& set
) const
{
- for (const wordRe& fieldName : *this)
+ for (const fieldInfo& fi : *this)
{
- set.insert(allFileObjects.names(Type::typeName, fieldName));
+ const wordList names(allFileObjects.names(Type::typeName, fi.name()));
+ for (const word& name : names)
+ {
+ set.append(fieldInfo(wordRe(name)));
+ }
}
}
@@ -46,7 +50,7 @@ void Foam::functionObjects::fileFieldSelection::addFromFile
template class PatchType, class MeshType>
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
(
- wordHashSet& set
+ DynamicList& set
) const
{
const fvMesh& mesh = static_cast(obr_);
diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C
index d7508642d2..247051da98 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C
@@ -32,10 +32,11 @@ License
Foam::functionObjects::solverFieldSelection::solverFieldSelection
(
- const objectRegistry& obr
+ const objectRegistry& obr,
+ const bool includeComponents
)
:
- volFieldSelection(obr)
+ volFieldSelection(obr, includeComponents)
{
if (!isA(obr))
{
@@ -46,34 +47,33 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
}
-// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::solverFieldSelection::~solverFieldSelection()
-{}
-
-
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::solverFieldSelection::updateSelection()
{
- wordHashSet oldSet;
- oldSet.swap(selection_);
+ List oldSet(std::move(selection_));
- wordHashSet volFields;
+ DynamicList volFields;
addRegisteredGeoFields(volFields);
+ DynamicList newSelection(oldSet.size());
+
const fvMesh& mesh = static_cast(obr_);
- const Foam::dictionary& solverDict = mesh.solverPerformanceDict();
+ const dictionary& solverDict = mesh.solverPerformanceDict();
- for (const word& fieldName : volFields)
+ for (const fieldInfo& fi : volFields)
{
- if (solverDict.found(fieldName))
+ const wordRe& name = fi.name();
+
+ if (solverDict.found(name))
{
- selection_.insert(fieldName);
+ newSelection.append(fi);
}
}
+ selection_.transfer(newSelection);
+
return selection_ != oldSet;
}
diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H
index 7473c9e536..4ae1e670ac 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H
+++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -25,7 +25,7 @@ Class
Foam::functionObjects::volFieldSelection
Description
- Helper class to manage volume field selections
+ Helper class to manage solver field selections
SourceFiles
volFieldSelection.C
@@ -63,11 +63,15 @@ private:
public:
//- Construct from object registry
- solverFieldSelection(const objectRegistry& obr);
+ solverFieldSelection
+ (
+ const objectRegistry& obr,
+ const bool includeComponents = false
+ );
//- Destructor
- virtual ~solverFieldSelection();
+ virtual ~solverFieldSelection() = default;
// Member Functions
diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C
index b0b61eb524..606ff341eb 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2109 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -31,16 +31,11 @@ License
Foam::functionObjects::volFieldSelection::volFieldSelection
(
- const objectRegistry& obr
+ const objectRegistry& obr,
+ const bool includeComponents
)
:
- fieldSelection(obr)
-{}
-
-
-// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
-
-Foam::functionObjects::volFieldSelection::~volFieldSelection()
+ fieldSelection(obr, includeComponents)
{}
@@ -48,11 +43,13 @@ Foam::functionObjects::volFieldSelection::~volFieldSelection()
bool Foam::functionObjects::volFieldSelection::updateSelection()
{
- wordHashSet oldSet;
+ List oldSet(std::move(selection_));
- oldSet.swap(selection_);
+ DynamicList newSet(oldSet.size());
- addRegisteredGeoFields(selection_);
+ addRegisteredGeoFields(newSet);
+
+ selection_.transfer(newSet);
return selection_ != oldSet;
}
diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H
index 4dca6608e3..66dcebbbd9 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H
+++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -66,17 +66,21 @@ protected:
//- Add registered GeometricField types to selection
template class PatchType, class MeshType>
- void addRegisteredGeoFields(wordHashSet& set) const;
+ void addRegisteredGeoFields(DynamicList& set) const;
public:
//- Construct from object registry
- volFieldSelection(const objectRegistry& obr);
+ volFieldSelection
+ (
+ const objectRegistry& obr,
+ const bool includeComponents = false
+ );
//- Destructor
- virtual ~volFieldSelection();
+ virtual ~volFieldSelection() = default;
// Member Functions
diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C
index f1e0ea195f..55f53fc939 100644
--- a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C
+++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -30,7 +30,7 @@ License
template class PatchType, class MeshType>
void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields
(
- wordHashSet& set
+ DynamicList& set
) const
{
addRegistered>(set);
diff --git a/src/finiteVolume/functionObjects/fieldSelections/fieldSelection/fieldSelection.H b/src/finiteVolume/functionObjects/fieldSelections/fieldSelection/fieldSelection.H
new file mode 100644
index 0000000000..55ed6eb39a
--- /dev/null
+++ b/src/finiteVolume/functionObjects/fieldSelections/fieldSelection/fieldSelection.H
@@ -0,0 +1,161 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
+ \\/ 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 .
+
+Class
+ Foam::functionObjects::fieldSelection
+
+Description
+ Helper class to manage field selections
+
+ The class holds a list of field name filters which are then applied to a
+ set of field objects (in derived classes) from which the resulting set is
+ available via the selection() function. This returns a list of
+ (fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
+
+SourceFiles
+ fieldSelection.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef functionObjects_fieldSelection_H
+#define functionObjects_fieldSelection_H
+
+#include "fieldInfo.H"
+#include "DynamicList.H"
+#include "HashSet.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+class dictionary;
+class objectRegistry;
+
+namespace functionObjects
+{
+
+/*---------------------------------------------------------------------------*\
+ Class fieldSelection Declaration
+\*---------------------------------------------------------------------------*/
+
+class fieldSelection
+:
+ public List
+{
+private:
+
+ // Private Member Functions
+
+ //- No copy construct
+ fieldSelection(const fieldSelection&) = delete;
+
+
+protected:
+
+ // Protected member data
+
+ //- Reference to the database
+ const objectRegistry& obr_;
+
+ //- Flag to indicate whether components are allowed
+ const bool includeComponents_;
+
+ //- Current field selection
+ List selection_;
+
+
+ // Protected Member Functions
+
+ //- Add registered objects of a given type
+ template
+ void addRegistered(DynamicList& set) const;
+
+
+public:
+
+ //- Construct from object registry
+ fieldSelection
+ (
+ const objectRegistry& obr,
+ const bool includeComponents = false
+ );
+
+
+ //- Destructor
+ virtual ~fieldSelection() = default;
+
+
+ // Member Functions
+
+ //- Return the cuurent filters
+ inline HashSet filters() const;
+
+ inline const List& selection() const;
+
+ //- Return the current field selection
+ inline wordHashSet selectionNames() const;
+
+ //- Reset the field filters to the given field names
+ virtual bool resetFieldFilters(const HashSet& names);
+
+ //- Reset the field filters to the given field name
+ virtual bool resetFieldFilters(const wordRe& name);
+
+ //- Read the fieldSelection data from dictionary
+ virtual bool read(const dictionary& dict);
+
+ //- Return whether the field names contain a pattern
+ virtual bool containsPattern() const;
+
+ //- Clear the current selection
+ virtual void clearSelection();
+
+ //- Update the selection
+ virtual bool updateSelection();
+
+ //- Check that all requested fielda have been found
+ virtual bool checkSelection();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace functionObjects
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#include "fieldSelectionI.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+ #include "fieldSelectionTemplates.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //