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 Foam_functionObjects_fieldSelection_H
43 #define Foam_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 // Forward Declarations
55 class dictionary;
56 class objectRegistry;
57 
58 namespace functionObjects
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class fieldSelection Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class fieldSelection
66 :
67  public List<fieldInfo>
68 {
69  // Private Member Functions
70 
71  //- Reset the field filters to the given field names
72  template<class Container>
73  bool resetFieldFiltersImpl(const Container& names);
74 
75  //- No copy construct
76  fieldSelection(const fieldSelection&) = delete;
77 
78 
79 protected:
80 
81  // Protected Member Data
82 
83  //- Reference to the database
84  const objectRegistry& obr_;
85 
86  //- Flag to indicate whether components are allowed
87  const bool includeComponents_;
88 
89  //- Current field selection
91 
92 
93  // Protected Member Functions
94 
95  //- Add registered objects of a given type
96  template<class Type>
97  void addRegistered(DynamicList<fieldInfo>& set) const;
98 
99 
100 public:
101 
102  //- Construct from object registry
103  explicit fieldSelection
104  (
105  const objectRegistry& obr,
106  const bool includeComponents = false
107  );
108 
109 
110  //- Destructor
111  virtual ~fieldSelection() = default;
112 
113 
114  // Member Functions
115 
116  //- The current field selection
117  const List<fieldInfo>& selection() const noexcept
118  {
119  return selection_;
120  }
121 
122  //- Return the current filters
123  inline HashSet<wordRe> filters() const;
124 
125  //- Return the current field selection, in sorted order
126  inline wordList selectionNames() const;
127 
128  //- Reset the field filters to the given field names
129  virtual bool resetFieldFilters(const HashSet<wordRe>& names);
131  //- Reset the field filters to the given field name
132  virtual bool resetFieldFilters(const wordRe& name);
133 
134  //- Read the fieldSelection data from dictionary
135  virtual bool read(const dictionary& dict);
136 
137  //- Return whether the field names contain a pattern
138  virtual bool containsPattern() const;
139 
140  //- Clear the current selection
141  virtual void clearSelection();
142 
143  //- Update the selection
144  virtual bool updateSelection();
145 
146  //- Check that all requested fielda have been found
147  virtual bool checkSelection();
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace functionObjects
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #include "fieldSelectionI.H"
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 #ifdef NoRepository
163  #include "fieldSelectionTemplates.C"
164 #endif
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #endif
169 
170 // ************************************************************************* //
List< fieldInfo > selection_
Current field selection.
virtual bool checkSelection()
Check that all requested fielda have been found.
A HashTable with keys but without contents that is similar to std::unordered_set. ...
Definition: HashSet.H:73
dictionary dict
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
virtual bool containsPattern() const
Return whether the field names contain a pattern.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
wordList selectionNames() const
Return the current field selection, in sorted order.
void addRegistered(DynamicList< fieldInfo > &set) const
Add registered objects of a given type.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
virtual bool updateSelection()
Update the selection.
const bool includeComponents_
Flag to indicate whether components are allowed.
HashSet< wordRe > filters() const
Return the current filters.
const objectRegistry & obr_
Reference to the database.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
const direction noexcept
Definition: Scalar.H:258
virtual void clearSelection()
Clear the current selection.
virtual bool read(const dictionary &dict)
Read the fieldSelection data from dictionary.
const List< fieldInfo > & selection() const noexcept
The current field selection.
virtual bool resetFieldFilters(const HashSet< wordRe > &names)
Reset the field filters to the given field names.
Helper class to manage field selections.
Registry of regIOobjects.
virtual ~fieldSelection()=default
Destructor.
Namespace for OpenFOAM.