fieldSelection.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::fieldSelection
28 
29 Description
30  Helper class to manage field selections
31 
32  The class holds a list of field name filters which are then applied to a
33  set of field objects (in derived classes) from which the resulting set is
34  available via the selection() function. This returns a list of
35  (fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
36 
37 SourceFiles
38  fieldSelection.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef functionObjects_fieldSelection_H
43 #define functionObjects_fieldSelection_H
44 
45 #include "fieldInfo.H"
46 #include "DynamicList.H"
47 #include "HashSet.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class dictionary;
55 class objectRegistry;
56 
57 namespace functionObjects
58 {
59 
60 /*---------------------------------------------------------------------------*\
61  Class fieldSelection Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class fieldSelection
65 :
66  public List<fieldInfo>
67 {
68 private:
69 
70  // Private Member Functions
71 
72  //- No copy construct
73  fieldSelection(const fieldSelection&) = delete;
74 
75 
76 protected:
77 
78  // Protected member data
79 
80  //- Reference to the database
81  const objectRegistry& obr_;
82 
83  //- Flag to indicate whether components are allowed
84  const bool includeComponents_;
85 
86  //- Current field selection
88 
89 
90  // Protected Member Functions
91 
92  //- Add registered objects of a given type
93  template<class Type>
95 
96 
97 public:
98 
99  //- Construct from object registry
101  (
102  const objectRegistry& obr,
103  const bool includeComponents = false
104  );
105 
106 
107  //- Destructor
108  virtual ~fieldSelection() = default;
109 
110 
111  // Member Functions
112 
113  //- Return the cuurent filters
114  inline HashSet<wordRe> filters() const;
115 
116  inline const List<fieldInfo>& selection() const;
117 
118  //- Return the current field selection
119  inline wordHashSet selectionNames() const;
120 
121  //- Reset the field filters to the given field names
122  virtual bool resetFieldFilters(const HashSet<wordRe>& names);
123 
124  //- Reset the field filters to the given field name
125  virtual bool resetFieldFilters(const wordRe& name);
126 
127  //- Read the fieldSelection data from dictionary
128  virtual bool read(const dictionary& dict);
129 
130  //- Return whether the field names contain a pattern
131  virtual bool containsPattern() const;
132 
133  //- Clear the current selection
134  virtual void clearSelection();
135 
136  //- Update the selection
137  virtual bool updateSelection();
138 
139  //- Check that all requested fielda have been found
140  virtual bool checkSelection();
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace functionObjects
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #include "fieldSelectionI.H"
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #ifdef NoRepository
156  #include "fieldSelectionTemplates.C"
157 #endif
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::functionObjects::fieldSelection::selection
const List< fieldInfo > & selection() const
Definition: fieldSelectionI.H:43
Foam::functionObjects::fieldSelection::checkSelection
virtual bool checkSelection()
Check that all requested fielda have been found.
Definition: fieldSelection.C:159
Foam::functionObjects::fieldSelection::updateSelection
virtual bool updateSelection()
Update the selection.
Definition: fieldSelection.C:153
Foam::functionObjects::fieldSelection::selectionNames
wordHashSet selectionNames() const
Return the current field selection.
Definition: fieldSelectionI.H:50
Foam::HashSet
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition: HashSet.H:77
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
Foam::functionObjects::fieldSelection
Helper class to manage field selections.
Definition: fieldSelection.H:63
Foam::functionObjects::fieldSelection::containsPattern
virtual bool containsPattern() const
Return whether the field names contain a pattern.
Definition: fieldSelection.C:133
Foam::functionObjects::fieldSelection::clearSelection
virtual void clearSelection()
Clear the current selection.
Definition: fieldSelection.C:147
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::fieldSelection::filters
HashSet< wordRe > filters() const
Return the cuurent filters.
Definition: fieldSelectionI.H:29
Foam::functionObjects::fieldSelection::obr_
const objectRegistry & obr_
Reference to the database.
Definition: fieldSelection.H:80
Foam::functionObjects::fieldSelection::addRegistered
void addRegistered(DynamicList< fieldInfo > &set) const
Add registered objects of a given type.
Definition: fieldSelectionTemplates.C:34
fieldSelectionI.H
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::fieldSelection::~fieldSelection
virtual ~fieldSelection()=default
Destructor.
Foam::functionObjects::fieldSelection::includeComponents_
const bool includeComponents_
Flag to indicate whether components are allowed.
Definition: fieldSelection.H:83
fieldSelectionTemplates.C
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
fieldInfo.H
Foam::functionObjects::fieldSelection::selection_
List< fieldInfo > selection_
Current field selection.
Definition: fieldSelection.H:86
Foam::List< fieldInfo >::set
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:341
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::fieldSelection::resetFieldFilters
virtual bool resetFieldFilters(const HashSet< wordRe > &names)
Reset the field filters to the given field names.
Definition: fieldSelection.C:48
DynamicList.H
Foam::functionObjects::fieldSelection::read
virtual bool read(const dictionary &dict)
Read the fieldSelection data from dictionary.
Definition: fieldSelection.C:125
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)