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-2021 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 faOption_H
76 #define faOption_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  //- Reference to the patch
118  const fvPatch& patch_;
119 
120  //- Top level source dictionary
121  dictionary dict_;
122 
123  //- Dictionary containing source coefficients
124  dictionary coeffs_;
125 
126  //- Field names to apply source to - populated by derived models
128 
129  //- Applied flag list - corresponds to each fieldNames_ entry
130  List<bool> applied_;
131 
132  //- Region name (finite-area)
134 
135 
136  // Protected Member Functions
137 
138  //- Resize/reset applied flag list for all fieldNames_ entries
139  void resetApplied();
140 
141 
142 private:
143 
144  // Private Data
145 
146  //- Demand-driven: pointer to region mesh database
147  mutable autoPtr<faMesh> regionMeshPtr_;
148 
149  //- Demand-driven: volume-to-surface mapping
150  mutable autoPtr<volSurfaceMapping> vsmPtr_;
151 
152  //- Source active flag
153  bool active_;
154 
155 
156 public:
157 
158  //- Switch write log to Info
159  bool log;
160 
161 
162  //- Runtime type information
163  TypeName("option");
164 
165 
166  // Declare run-time constructor selection table
167 
169  (
171  option,
172  dictionary,
173  (
174  const word& name,
175  const word& modelType,
176  const dictionary& dict,
177  const fvPatch& patch
178  ),
179  (name, modelType, dict, patch)
180  );
181 
182 
183  // Constructors
184 
185  //- Construct from components
186  option
187  (
188  const word& name,
189  const word& modelType,
190  const dictionary& dict,
191  const fvPatch& patch
192  );
193 
194  //- Return clone
195  autoPtr<option> clone() const
196  {
198  return nullptr;
199  }
200 
201  //- Return pointer to new faOption object created
202  //- on the freestore from an Istream
203  class iNew
204  {
205  //- Reference to the patch
206  const fvPatch& patch_;
207 
208  //- Name
209  const word& name_;
210 
211  public:
212 
213  iNew
214  (
215  const fvPatch& patch,
216  const word& name
217  )
218  :
219  patch_(patch),
220  name_(name)
221  {}
222 
224  {
225  const dictionary dict(is);
226 
227  return autoPtr<option>
228  (
229  option::New(name_, dict, patch_)
230  );
231  }
232  };
233 
234 
235  // Selectors
236 
237  //- Return a reference to the selected faOption model
238  static autoPtr<option> New
239  (
240  const word& name,
241  const dictionary& dict,
242  const fvPatch& patch
243  );
244 
245 
246  //- Destructor
247  virtual ~option() = default;
248 
249 
250  // Member Functions
251 
252  // Access
253 
254  //- Return const access to the source name
255  inline const word& name() const noexcept;
256 
257  //- Return const access to the mesh database
258  inline const fvMesh& mesh() const noexcept;
259 
260  //- Return const access to fvPatch
261  inline const fvPatch& patch() const noexcept;
262 
263  //- Return dictionary
264  inline const dictionary& coeffs() const noexcept;
265 
266  //- Return const access to the source active flag
267  inline bool active() const noexcept;
268 
269  //- Set the applied flag to true for field index fieldi
270  inline void setApplied(const label fieldi);
271 
272  //- The region name
273  inline const word& regionName() const noexcept;
274 
275  //- Return the region mesh database (demand-driven)
276  inline const faMesh& regionMesh() const;
277 
278  //- Return volSurfaceMapping (demand-driven)
279  inline const volSurfaceMapping& vsm() const;
280 
281 
282  // Edit
283 
284  //- Change source active flag, return previous value
285  inline bool active(const bool on) noexcept;
286 
287 
288  // Checks
289 
290  //- Is the source active?
291  virtual bool isActive();
292 
293  //- Return index of field name if found in fieldNames list
294  virtual label applyToField(const word& fieldName) const;
295 
296  //- Check that the source has been applied
297  virtual void checkApplied() const;
298 
299 
300  // Evaluation
301 
302  // Explicit and implicit sources
303 
304  virtual void addSup
305  (
306  const areaScalarField& h,
307  faMatrix<scalar>& eqn,
308  const label fieldi
309  );
310 
311  virtual void addSup
312  (
313  const areaScalarField& h,
314  faMatrix<vector>& eqn,
315  const label fieldi
316  );
317 
318  virtual void addSup
319  (
320  const areaScalarField& h,
321  faMatrix<symmTensor>& eqn,
322  const label fieldi
323  );
324 
325  virtual void addSup
326  (
327  const areaScalarField& h,
329  const label fieldi
330  );
331 
332  virtual void addSup
333  (
334  const areaScalarField& h,
335  faMatrix<tensor>& eqn,
336  const label fieldi
337  );
338 
339 
340  // Explicit and implicit sources for compressible equations
341 
342  virtual void addSup
343  (
344  const areaScalarField& h,
345  const areaScalarField& rho,
346  faMatrix<scalar>& eqn,
347  const label fieldi
348  );
349 
350  virtual void addSup
351  (
352  const areaScalarField& h,
353  const areaScalarField& rho,
354  faMatrix<vector>& eqn,
355  const label fieldi
356  );
357 
358  virtual void addSup
359  (
360  const areaScalarField& h,
361  const areaScalarField& rho,
362  faMatrix<symmTensor>& eqn,
363  const label fieldi
364  );
365 
366  virtual void addSup
367  (
368  const areaScalarField& h,
369  const areaScalarField& rho,
371  const label fieldi
372  );
373 
374  virtual void addSup
375  (
376  const areaScalarField& h,
377  const areaScalarField& rho,
378  faMatrix<tensor>& eqn,
379  const label fieldi
380  );
381 
382 
383  // Constraints
384 
385  virtual void constrain
386  (
387  faMatrix<scalar>& eqn,
388  const label fieldi
389  );
390 
391  virtual void constrain
392  (
393  faMatrix<vector>& eqn,
394  const label fieldi
395  );
396 
397  virtual void constrain
398  (
400  const label fieldi
401  );
402 
403  virtual void constrain
404  (
405  faMatrix<symmTensor>& eqn,
406  const label fieldi
407  );
408 
409  virtual void constrain
410  (
411  faMatrix<tensor>& eqn,
412  const label fieldi
413  );
414 
415 
416  // Correction
417 
418  virtual void correct(areaScalarField& field);
419  virtual void correct(areaVectorField& field);
420  virtual void correct(areaSphericalTensorField& field);
421  virtual void correct(areaSymmTensorField& field);
422  virtual void correct(areaTensorField& field);
423 
424 
425  // IO
426 
427  //- Write the source header information
428  virtual void writeHeader(Ostream&) const;
429 
430  //- Write the source footer information
431  virtual void writeFooter(Ostream&) const;
432 
433  //- Write the source properties
434  virtual void writeData(Ostream&) const;
435 
436  //- Read source dictionary
437  virtual bool read(const dictionary& dict);
438 };
439 
440 
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 
443 } // End namespace fa
444 } // End namespace Foam
445 
446 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
447 
448 #include "faOptionI.H"
449 
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
451 
452 #endif
453 
454 // ************************************************************************* //
Foam::fa::option::regionName
const word & regionName() const noexcept
The region name.
Definition: faOptionI.H:74
Foam::fa::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:38
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::faMatrix
A special matrix type and solver, designed for finite area solutions of scalar equations....
Definition: faMatricesFwd.H:43
Foam::fa::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: faOptionI.H:30
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fa::option::clone
autoPtr< option > clone() const
Return clone.
Definition: faOption.H:232
Foam::fa::option::constrain
virtual void constrain(faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:240
Foam::fa::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: faOptionI.H:68
Foam::fa::option::resetApplied
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: faOption.C:45
Foam::fa::option::addSup
virtual void addSup(const areaScalarField &h, faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:146
faMatricesFwd.H
Forward declarations of standard faMatrix types/specializations.
Foam::fa::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:131
Foam::fa::option::patch
const fvPatch & patch() const noexcept
Return const access to fvPatch.
Definition: faOptionI.H:42
Foam::fa::option::option
option(const word &name, const word &modelType, const dictionary &dict, const fvPatch &patch)
Construct from components.
Definition: faOption.C:55
Foam::fa::option::New
static autoPtr< option > New(const word &name, const dictionary &dict, const fvPatch &patch)
Return a reference to the selected faOption model.
Definition: faOption.C:83
Foam::fa::option::name_
const word name_
Source name.
Definition: faOption.H:146
Foam::fa::option::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, option, dictionary,(const word &name, const word &modelType, const dictionary &dict, const fvPatch &patch),(name, modelType, dict, patch))
rho
rho
Definition: readInitialConditions.H:88
Foam::fa::option::active
bool active() const noexcept
Return const access to the source active flag.
Definition: faOptionI.H:54
Foam::fa::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:152
Foam::fa::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:125
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::fa::option::iNew::iNew
iNew(const fvPatch &patch, const word &name)
Definition: faOption.H:251
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::fa::option::writeData
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:44
Foam::fa::option::TypeName
TypeName("option")
Runtime type information.
Foam::fa::option::fieldNames_
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: faOption.H:164
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::constant::universal::h
const dimensionedScalar h
Planck constant.
Definition: setRegionSolidFields.H:33
areaFieldsFwd.H
Forwards and collection of common area field types.
Foam::fa::option::coeffs
const dictionary & coeffs() const noexcept
Return dictionary.
Definition: faOptionI.H:48
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::fa::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:161
field
rDeltaTY field()
Foam::fa::option::log
bool log
Switch write log to Info.
Definition: faOption.H:196
Foam::fa::option::~option
virtual ~option()=default
Destructor.
Foam::fa::option::regionMesh
const faMesh & regionMesh() const
Return the region mesh database (demand-driven)
Definition: faOptionI.H:80
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fa::option::writeHeader
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: faOptionIO.C:32
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::fa::option::vsm
const volSurfaceMapping & vsm() const
Return volSurfaceMapping (demand-driven)
Definition: faOptionI.H:90
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fa::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:54
Foam::fa::option::patch_
const fvPatch & patch_
Reference to the patch.
Definition: faOption.H:155
Foam::SphericalTensor< scalar >
Foam::fa::option::modelType_
const word modelType_
Model type.
Definition: faOption.H:149
Foam::fa::option::isActive
virtual bool isActive()
Is the source active?
Definition: faOption.C:119
Foam::fa::option::regionName_
word regionName_
Region name (finite-area)
Definition: faOption.H:170
Foam::fa::option::mesh
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: faOptionI.H:36
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fa::option::correct
virtual void correct(areaScalarField &field)
Definition: faOption.C:268
volSurfaceMapping.H
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:133
Foam::Vector< scalar >
Foam::fa::option::iNew::operator()
autoPtr< option > operator()(Istream &is) const
Definition: faOption.H:260
Foam::volSurfaceMapping
Volume to surface and surface to volume mapping.
Definition: volSurfaceMapping.H:57
Foam::List< word >
Foam::fa::option::iNew
Definition: faOption.H:240
dictionary.H
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:82
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, faPatchField, areaMesh >
Foam::fa::option::dict_
dictionary dict_
Top level source dictionary.
Definition: faOption.H:158
Foam::fa::option::applied_
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: faOption.H:167