faOption.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) 2019-2022 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::fa::option
28 
29 Description
30  Base abstract class for handling finite area options (i.e. \c faOption).
31 
32 Usage
33  Minimal example by using \c constant/faOptions:
34  \verbatim
35  <userDefinedName1>
36  {
37  // Mandatory entries (unmodifiable)
38  type <faOptionName>;
39 
40  // Mandatory entries (runtime modifiable)
41  region <regionName>;
42 
43  // Optional entries (unmodifiable/runtime modifiable)
44  <faOption>Coeffs
45  {
46  // subdictionary entries
47  }
48 
49  // Optional entries (runtime modifiable)
50  active true;
51  log true;
52  }
53  \endverbatim
54 
55  where the entries mean:
56  \table
57  Property | Description | Type | Reqd | Dflt
58  type | Name of operand faOption | word | yes | -
59  region | Name of operand region | word | yes | -
60  <faOption>Coeffs | Dictionary containing settings of <!--
61  --> the selected faOption settings | dictionary | no | -
62  active | Flag to (de)activate faOption | bool | no | true
63  log | Flag to log faOption-related info | bool | no | true
64  \endtable
65 
66 Note
67  - Source/sink options are to be added to the right-hand side of equations.
68 
69 SourceFiles
70  faOption.C
71  faOptionIO.C
72 
73 \*---------------------------------------------------------------------------*/
74 
75 #ifndef Foam_fa_option_H
76 #define Foam_fa_option_H
77 
78 #include "faMatricesFwd.H"
79 #include "areaFieldsFwd.H"
80 #include "dictionary.H"
81 #include "fvMesh.H"
82 #include "volSurfaceMapping.H"
83 #include "runTimeSelectionTables.H"
84 
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 
87 namespace Foam
88 {
89 namespace fa
90 {
91 
92 /*---------------------------------------------------------------------------*\
93  Class option Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class option
97 {
98  // Private Member Functions
99 
100  //- Construct region mesh and fields
101  void constructMeshObjects();
102 
103 
104 protected:
105 
106  // Protected Data
107 
108  //- Source name
109  const word name_;
110 
111  //- Model type
112  const word modelType_;
113 
114  //- Reference to the mesh database
115  const fvMesh& mesh_;
116 
117  //- Top level source dictionary
119 
120  //- Dictionary containing source coefficients
122 
123  //- Field names to apply source to - populated by derived models
125 
126  //- Applied flag list - corresponds to each fieldNames_ entry
127  List<bool> applied_;
128 
129  //- Region name (finite-area)
131 
132 
133  // Protected Member Functions
134 
135  //- Resize/reset applied flag list for all fieldNames_ entries
136  void resetApplied();
137 
138 
139 private:
140 
141  // Private Data
142 
143  //- Demand-driven: pointer to region mesh database
144  mutable autoPtr<faMesh> regionMeshPtr_;
145 
146  //- Demand-driven: volume-to-surface mapping
147  mutable autoPtr<volSurfaceMapping> vsmPtr_;
148 
149  //- Source active flag
150  bool active_;
152 
153 public:
154 
155  //- Switch write log to Info
156  bool log;
157 
158 
159  //- Runtime type information
160  TypeName("option");
162 
163  // Declare run-time constructor selection table
164 
166  (
167  autoPtr,
168  option,
169  dictionary,
170  (
171  const word& name,
172  const word& modelType,
173  const dictionary& dict,
174  const fvMesh& mesh
175  ),
176  (name, modelType, dict, mesh)
177  );
178 
179 
180  // Constructors
182  //- Construct from components
183  option
184  (
185  const word& name,
186  const word& modelType,
187  const dictionary& dict,
188  const fvMesh& mesh
189  );
190 
191  //- Return clone
192  autoPtr<option> clone() const
193  {
195  return nullptr;
196  }
197 
198  //- Return pointer to new faOption object created
199  //- on the freestore from an Istream
200  class iNew
201  {
202  //- Reference to the mesh
203  const fvMesh& mesh_;
204 
205  //- Name
206  const word& name_;
207 
208  public:
209 
210  iNew
211  (
212  const fvMesh& mesh,
213  const word& name
214  )
215  :
216  mesh_(mesh),
217  name_(name)
218  {}
219 
221  {
222  const dictionary dict(is);
223 
224  return autoPtr<option>
225  (
226  option::New(name_, dict, mesh_)
227  );
228  }
229  };
230 
231 
232  // Selectors
233 
234  //- Return a reference to the selected faOption model
235  static autoPtr<option> New
236  (
237  const word& name,
238  const dictionary& dict,
239  const fvMesh& mesh
240  );
241 
242 
243  //- Destructor
244  virtual ~option() = default;
245 
246 
247  // Member Functions
248 
249  // Access
250 
251  //- Return const access to the source name
252  inline const word& name() const noexcept;
253 
254  //- Return const access to the mesh database
255  inline const fvMesh& mesh() const noexcept;
256 
257  //- Return dictionary
258  inline const dictionary& coeffs() const noexcept;
260  //- True if source is active
261  inline bool active() const noexcept;
262 
263  //- Set the applied flag to true for field index fieldi
264  inline void setApplied(const label fieldi);
265 
266  //- The region name
267  inline const word& regionName() const noexcept;
268 
269  //- Return the region mesh database (demand-driven)
270  inline const faMesh& regionMesh() const;
271 
272  //- Return volSurfaceMapping (demand-driven)
273  inline const volSurfaceMapping& vsm() const;
274 
275 
276  // Edit
277 
278  //- Change source active flag, return previous value
279  inline bool active(const bool on) noexcept;
280 
281 
282  // Checks
283 
284  //- Is the source active?
285  virtual bool isActive();
286 
287  //- Return index of field name if found in fieldNames list
288  virtual label applyToField(const word& fieldName) const;
289 
290  //- Check that the source has been applied
291  virtual void checkApplied() const;
292 
294  // Evaluation
295 
296  // Explicit and implicit sources
297 
298  virtual void addSup
299  (
300  const areaScalarField& h,
301  faMatrix<scalar>& eqn,
302  const label fieldi
303  );
304 
305  virtual void addSup
306  (
307  const areaScalarField& h,
308  faMatrix<vector>& eqn,
309  const label fieldi
310  );
311 
312  virtual void addSup
313  (
314  const areaScalarField& h,
315  faMatrix<symmTensor>& eqn,
316  const label fieldi
317  );
318 
319  virtual void addSup
320  (
321  const areaScalarField& h,
323  const label fieldi
324  );
325 
326  virtual void addSup
327  (
328  const areaScalarField& h,
329  faMatrix<tensor>& eqn,
330  const label fieldi
331  );
332 
333 
334  // Explicit and implicit sources for compressible equations
335 
336  virtual void addSup
337  (
338  const areaScalarField& h,
339  const areaScalarField& rho,
340  faMatrix<scalar>& eqn,
341  const label fieldi
342  );
343 
344  virtual void addSup
345  (
346  const areaScalarField& h,
347  const areaScalarField& rho,
348  faMatrix<vector>& eqn,
349  const label fieldi
350  );
351 
352  virtual void addSup
353  (
354  const areaScalarField& h,
355  const areaScalarField& rho,
356  faMatrix<symmTensor>& eqn,
357  const label fieldi
358  );
359 
360  virtual void addSup
361  (
362  const areaScalarField& h,
363  const areaScalarField& rho,
365  const label fieldi
366  );
367 
368  virtual void addSup
369  (
370  const areaScalarField& h,
371  const areaScalarField& rho,
372  faMatrix<tensor>& eqn,
373  const label fieldi
374  );
375 
376 
377  // Constraints
378 
379  virtual void constrain
380  (
381  faMatrix<scalar>& eqn,
382  const label fieldi
383  );
384 
385  virtual void constrain
386  (
387  faMatrix<vector>& eqn,
388  const label fieldi
389  );
390 
391  virtual void constrain
392  (
394  const label fieldi
395  );
396 
397  virtual void constrain
398  (
399  faMatrix<symmTensor>& eqn,
400  const label fieldi
401  );
402 
403  virtual void constrain
404  (
405  faMatrix<tensor>& eqn,
406  const label fieldi
407  );
408 
409 
410  // Correction
411 
412  virtual void correct(areaScalarField& field);
413  virtual void correct(areaVectorField& field);
414  virtual void correct(areaSphericalTensorField& field);
415  virtual void correct(areaSymmTensorField& field);
416  virtual void correct(areaTensorField& field);
417 
418 
419  // IO
420 
421  //- Write the source header information
422  virtual void writeHeader(Ostream&) const;
423 
424  //- Write the source footer information
425  virtual void writeFooter(Ostream&) const;
426 
427  //- Write the source properties
428  virtual void writeData(Ostream&) const;
429 
430  //- Read source dictionary
431  virtual bool read(const dictionary& dict);
432 };
433 
434 
435 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436 
437 } // End namespace fa
438 } // End namespace Foam
439 
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
441 
442 #include "faOptionI.H"
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 #endif
447 
448 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: faOptionI.H:29
dictionary dict
rDeltaTY field()
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: faOption.H:171
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const volSurfaceMapping & vsm() const
Return volSurfaceMapping (demand-driven)
Definition: faOptionI.H:77
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:156
virtual void constrain(faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:233
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const word & regionName() const noexcept
The region name.
Definition: faOptionI.H:61
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: faOptionI.H:55
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:129
Volume to surface and surface to volume mapping.
dictionary dict_
Top level source dictionary.
Definition: faOption.H:161
bool active() const noexcept
True if source is active.
Definition: faOptionI.H:41
autoPtr< option > operator()(Istream &is) const
Definition: faOption.H:293
const word modelType_
Model type.
Definition: faOption.H:151
autoPtr< option > clone() const
Return clone.
Definition: faOption.H:259
const word name_
Source name.
Definition: faOption.H:146
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void addSup(const areaScalarField &h, faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:139
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:124
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:31
const dictionary & coeffs() const noexcept
Return dictionary.
Definition: faOptionI.H:35
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:47
virtual ~option()=default
Destructor.
const word & name() const noexcept
Return const access to the source name.
Definition: faOptionI.H:23
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
virtual void correct(areaScalarField &field)
Definition: faOption.C:261
declareRunTimeSelectionTable(autoPtr, option, dictionary,(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh),(name, modelType, dict, mesh))
bool log
Switch write log to Info.
Definition: faOption.H:217
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Forward declarations of standard faMatrix types/specializations.
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected faOption model.
Definition: faOption.C:75
const dimensionedScalar h
Planck constant.
List< word > wordList
List of word.
Definition: fileName.H:59
word regionName_
Region name (finite-area)
Definition: faOption.H:181
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: faOption.C:38
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: faOptionIO.C:25
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:37
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A special matrix type and solver, designed for finite area solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: faMatricesFwd.H:37
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: faOption.C:48
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:118
virtual bool isActive()
Is the source active?
Definition: faOption.C:112
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
iNew(const fvMesh &mesh, const word &name)
Definition: faOption.H:284
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: faOption.H:176
Macros to ease declaration of run-time selection tables.
Tensor of scalars, i.e. Tensor<scalar>.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
TypeName("option")
Runtime type information.
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:166
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:67
Forwards and collection of common area field types.
Namespace for OpenFOAM.