cellSetOption.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fv::cellSetOption
29 
30 Description
31  Intermediate abstract class for handling
32  cell-set options for the derived fvOptions.
33 
34 Usage
35  Minimal example by using \c constant/fvOptions:
36  \verbatim
37  fvOption1
38  {
39  // Mandatory entries
40  selectionMode <word>;
41 
42  // Optional entries
43  timeStart <scalar>;
44  updateSelection <bool>;
45 
46  // Conditional entries
47 
48  // when timeStart entry is present
49  duration <scalar>;
50 
51  // when selectionMode=cellSet
52  cellSet <word>;
53 
54  // when selectionMode=cellZone
55  cellZone <word>;
56 
57  //OR: cellZones (<word> ...);
58 
59  // when selectionMode=points
60  points (<point1> <point2> ... <pointN>);
61 
62  // when selectionMode=movingPoints
63  movingPoints
64  (
65  <word> <Function1<vector>>;
66  // e.g.
67  point1 <Function1<vector>>;
68  pointN <Function1<vector>>;
69  ...
70  );
71 
72  // when selectionMode=geometric
73  selection
74  {
75  topoSet1 <dictionary>;
76 
77  box1
78  {
79  action use;
80  source box;
81  min (-0.1 -0.01 -0.1);
82  max (0.1 0.30 0.1);
83  }
84  ball
85  {
86  action add;
87  source sphere;
88  origin (-0.1 -0.01 -0.1);
89  radius 0.25;
90  }
91  ...
92  }
93 
94  // Inherited entries
95  ...
96  }
97  \endverbatim
98 
99  where the entries mean:
100  \table
101  Property | Description | Type | Reqd | Deflt
102  selectionMode | Mode of cell selection - see below | word | yes | -
103  timeStart | Start time of fvOption | scalar | no | -1
104  updateSelection | Flag to enable selection updates | bool | no | false
105  duration | Duration of fvOption execution <!--
106  --> starting from timeStart | scalar | choice | 0
107  cellSet | Name of operand cellSet | word | choice | -
108  cellZone | Name of operand cellZone | wordRe | choice | -
109  cellZones | Name of operand cellZones | wordRes | choice | -
110  points | Set of points in global coordinate <!--
111  --> system | vectorList | choice | -
112  movingPoints | Set of moving points in global coordinate system <!--
113  --> | Function1<vector> | choice | -
114  selection | Dictionary of geometric selections | dict | choice | -
115  \endtable
116 
117  Options for the \c selectionMode entry:
118  \verbatim
119  all | Use all cells in the computational domain
120  cellZone | Use specified cellZone
121  cellSet | Use specified cellSet
122  points | Use cells containing a given set of points
123  movingPoints | Use cells containing a given set of moving points
124  geometric | Select cells based on topoSetCellSource actions
125  \endverbatim
126 
127  The inherited entries are elaborated in:
128  - \link fvOption.H \endlink
129  - \link Function1.H \endlink
130 
131 Note
132  - Source/sink options are to be added to the right-hand side of equations.
133  - The geometric selection uses \c topoSetCellSource to select cells.
134  Any \c searchableSurface selections must describe a closed volume.
135  Ie, its \c hasVolumeType() method must be \c true.
136 
137 See also
138  Foam::cellBitSet::select
139 
140 SourceFiles
141  cellSetOption.C
142 
143 \*---------------------------------------------------------------------------*/
144 
145 #ifndef Foam_fv_cellSetOption_H
146 #define Foam_fv_cellSetOption_H
147 
148 #include "fvOption.H"
149 #include "fvMesh.H"
150 #include "dictionary.H"
151 #include "Time.H"
152 #include "Function1.H"
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 namespace Foam
157 {
158 namespace fv
159 {
160 
161 /*---------------------------------------------------------------------------*\
162  Class cellSetOption Declaration
163 \*---------------------------------------------------------------------------*/
164 
165 class cellSetOption
166 :
167  public fv::option
168 {
169 public:
170 
171  // Public Data
172 
173  //- Enumeration for selection mode types
174  enum selectionModeType : char
175  {
176  smAll,
177  smCellSet,
178  smCellZone,
179  smPoints,
181  smGeometric,
182  smCellType
183  };
184 
185  //- List of selection mode type names
186  static const Enum<selectionModeType> selectionModeTypeNames_;
187 
188 
189 protected:
190 
191  // Protected Data
192 
193  //- Cell selection mode
195 
196  //- Flag to enable dictionary-based updates of selections
197  bool updateSelection_;
198 
199  //- Start time of fvOption
200  scalar timeStart_;
201 
202  //- Duration of fvOption execution starting from timeStart
203  scalar duration_;
204 
205  //- Face selection names (for set or zone selections)
206  wordRes selectionNames_;
207 
208  //- List of points for "points" selectionMode
209  List<point> points_;
210 
211  //- List of points for "movingPoints" selectionMode
212  PtrList<Function1<point>> movingPoints_;
213 
214  //- Dictionary entries for "geometric" (topoSetCellSource) selection
216 
217  //- Set of cells to apply source to
219 
220  //- Sum of cell volumes
221  scalar V_;
222 
223 
224  // Protected Functions
225 
226  //- Set cell selection name or points selection from dictionary input
227  void setSelection(const dictionary& dict);
228 
229  //- Set the cell selection based on user input selection mode
230  void setCellSelection();
231 
232  //- Recalculate the volume
233  void setVol();
234 
235 
236 public:
237 
238  //- Runtime type information
239  TypeName("cellSetOption");
240 
241 
242  // Constructors
244  //- Construct from components
246  (
247  const word& name,
248  const word& modelType,
249  const dictionary& dict,
250  const fvMesh& mesh
251  );
252 
253 
254  //- Destructor
255  virtual ~cellSetOption() = default;
256 
258  // Member Functions
259 
260  // Access
261 
262  //- Return const access to the time start
263  inline scalar timeStart() const noexcept;
264 
265  //- Return const access to the duration
266  inline scalar duration() const noexcept;
268  //- True if within time limits
269  inline bool inTimeLimits(const scalar timeValue) const;
270 
271  //- True if sub-selection should be used
272  inline bool useSubMesh() const noexcept;
273 
274  //- Return the cell selection mode
276 
277  //- Return const access to the selection names
278  //- (set or zone selection)
279  inline const wordRes& selectionNames() const noexcept;
280 
281  //- Return const access to the first set/zone name
282  inline const wordRe& zoneName() const;
283 
284  //- Return const access to the total cell volume
285  inline scalar V() const noexcept;
286 
287  //- Return const access to the cell selection
288  inline const labelList& cells() const noexcept;
289 
290  //- Return flag for selection updates
291  bool isSelectionUpdated() const noexcept
292  {
293  return updateSelection_;
294  }
295 
296 
297  // Edit
298 
299  //- Adjust the time start, return the old value
300  inline scalar timeStart(scalar val) noexcept;
301 
302  //- Adjust the duration, return the old value
303  inline scalar duration(scalar val) noexcept;
304 
305 
306  // Checks
308  //- Is the source active?
309  virtual bool isActive();
310 
311 
312  // IO
313 
314  //- Read source dictionary
315  virtual bool read(const dictionary& dict);
316 
317 
318  // Housekeeping
319 
320  //- The name of the cell set/zone [as a word]
321  //- for "cellSet" / "cellZone" selection modes)
322  const word& cellSetName() const { return zoneName(); }
323 };
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace fv
329 } // End namespace Foam
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 #include "cellSetOptionI.H"
334 
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 
337 #endif
338 
339 // ************************************************************************* //
selectionModeType selectionMode_
Cell selection mode.
scalar V_
Sum of cell volumes.
dictionary dict
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: fvOptionI.H:30
const word & cellSetName() const
The name of the cell set/zone [as a word] for "cellSet" / "cellZone" selection modes) ...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
scalar timeStart() const noexcept
Return const access to the time start.
const labelList & cells() const noexcept
Return const access to the cell selection.
PtrList< Function1< point > > movingPoints_
List of points for "movingPoints" selectionMode.
scalar duration_
Duration of fvOption execution starting from timeStart.
virtual bool read(const dictionary &dict)
Read source dictionary.
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
cellSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
wordRes selectionNames_
Face selection names (for set or zone selections)
bool isSelectionUpdated() const noexcept
Return flag for selection updates.
scalar duration() const noexcept
Return const access to the duration.
scalar V() const noexcept
Return const access to the total cell volume.
virtual bool isActive()
Is the source active?
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList fv(nPoints)
const wordRe & zoneName() const
Return const access to the first set/zone name.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:24
bool inTimeLimits(const scalar timeValue) const
True if within time limits.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
bool updateSelection_
Flag to enable dictionary-based updates of selections.
const direction noexcept
Definition: Scalar.H:258
selectionModeType
Enumeration for selection mode types.
dictionary geometricSelection_
Dictionary entries for "geometric" (topoSetCellSource) selection.
labelList cells_
Set of cells to apply source to.
void setCellSelection()
Set the cell selection based on user input selection mode.
void setSelection(const dictionary &dict)
Set cell selection name or points selection from dictionary input.
Definition: cellSetOption.C:57
selectionModeType selectionMode() const noexcept
Return the cell selection mode.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
List< point > points_
List of points for "points" selectionMode.
TypeName("cellSetOption")
Runtime type information.
List< label > labelList
A List of labels.
Definition: List.H:62
const wordRes & selectionNames() const noexcept
Return const access to the selection names (set or zone selection)
virtual ~cellSetOption()=default
Destructor.
bool useSubMesh() const noexcept
True if sub-selection should be used.
scalar timeStart_
Start time of fvOption.
Namespace for OpenFOAM.
void setVol()
Recalculate the volume.