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-2020 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 "faMatrices.H"
79 #include "areaFields.H"
80 #include "dictionary.H"
81 #include "Switch.H"
82 #include "runTimeSelectionTables.H"
83 #include "fvMesh.H"
84 #include "volSurfaceMapping.H"
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 namespace Foam
89 {
90 namespace fa
91 {
92 
93 /*---------------------------------------------------------------------------*\
94  Class option Declaration
95 \*---------------------------------------------------------------------------*/
96 
97 class option
98 {
99  // Private Member Functions
100 
101  //- Construct region mesh and fields
102  void constructMeshObjects();
103 
104 
105 protected:
106 
107  // Protected Data
108 
109  //- Source name
110  const word name_;
111 
112  //- Model type
113  const word modelType_;
114 
115  //- Reference to the mesh database
116  const fvMesh& mesh_;
117 
118  //- Reference to the patch
119  const fvPatch& patch_;
120 
121  //- Top level source dictionary
122  dictionary dict_;
123 
124  //- Dictionary containing source coefficients
125  dictionary coeffs_;
126 
127  //- Source active flag
128  Switch active_;
129 
130  //- Field names to apply source to - populated by derived models
132 
133  //- Applied flag list - corresponds to each fieldNames_ entry
135 
136  //- Region name
138 
139  //- Pointer to the region mesh database
141 
142  //-Volume-to surface mapping
144 
145 
146 public:
147 
148  //- Runtime type information
149  TypeName("option");
150 
151 
152  // Declare run-time constructor selection table
153 
155  (
157  option,
158  dictionary,
159  (
160  const word& name,
161  const word& modelType,
162  const dictionary& dict,
163  const fvPatch& patch
164  ),
165  (name, modelType, dict, patch)
166  );
167 
168 
169  // Constructors
170 
171  //- Construct from components
172  option
173  (
174  const word& name,
175  const word& modelType,
176  const dictionary& dict,
177  const fvPatch& patch
178  );
179 
180  //- Return clone
181  autoPtr<option> clone() const
182  {
184  return nullptr;
185  }
186 
187  //- Return pointer to new faOption object created
188  //- on the freestore from an Istream
189  class iNew
190  {
191 
192  //- Reference to the patch
193  const fvPatch& patch_;
194 
195  //- Name
196  const word& name_;
197 
198  public:
199 
200  iNew
201  (
202  const fvPatch& patch,
203  const word& name
204  )
205  :
206  patch_(patch),
207  name_(name)
208  {}
209 
211  {
212  const dictionary dict(is);
213 
214  return autoPtr<option>
215  (
216  option::New(name_, dict, patch_)
217  );
218  }
219  };
220 
221 
222  // Selectors
223 
224  //- Return a reference to the selected faOption model
225  static autoPtr<option> New
226  (
227  const word& name,
228  const dictionary& dict,
229  const fvPatch& patch
230  );
231 
232 
233  //- Destructor
234  virtual ~option() = default;
235 
236 
237  // Member Functions
238 
239  // Access
240 
241  //- Return const access to the source name
242  inline const word& name() const;
243 
244  //- Return const access to the mesh database
245  inline const fvMesh& mesh() const;
246 
247  //- Return const access to fvPatch
248  inline const fvPatch& patch() const;
249 
250  //- Return dictionary
251  inline const dictionary& coeffs() const;
252 
253  //- Return const access to the source active flag
254  inline bool active() const;
255 
256  //- Set the applied flag to true for field index fieldi
257  inline void setApplied(const label fieldi);
258 
259  //- Return the region mesh database
260  inline const faMesh& regionMesh() const;
261 
262  //- Return volSurfaceMapping
263  inline const volSurfaceMapping& vsm() const;
264 
265  //- Region name
266  inline const word& regionName() const;
267 
268 
269  // Edit
270 
271  //- Return access to the source active flag
272  inline Switch& active();
273 
274 
275  // Checks
276 
277  //- Is the source active?
278  virtual bool isActive();
279 
280  //- Return index of field name if found in fieldNames list
281  virtual label applyToField(const word& fieldName) const;
282 
283  //- Check that the source has been applied
284  virtual void checkApplied() const;
285 
286 
287  // Evaluation
288 
289  // Explicit and implicit sources
290 
291  virtual void addSup
292  (
293  const areaScalarField& h,
294  faMatrix<scalar>& eqn,
295  const label fieldi
296  );
297 
298  virtual void addSup
299  (
300  const areaScalarField& h,
301  faMatrix<vector>& eqn,
302  const label fieldi
303  );
304 
305  virtual void addSup
306  (
307  const areaScalarField& h,
309  const label fieldi
310  );
311 
312  virtual void addSup
313  (
314  const areaScalarField& h,
316  const label fieldi
317  );
318 
319  virtual void addSup
320  (
321  const areaScalarField& h,
322  faMatrix<tensor>& eqn,
323  const label fieldi
324  );
325 
326 
327  // Explicit and implicit sources for compressible equations
328 
329  virtual void addSup
330  (
331  const areaScalarField& h,
332  const areaScalarField& rho,
333  faMatrix<scalar>& eqn,
334  const label fieldi
335  );
336 
337  virtual void addSup
338  (
339  const areaScalarField& h,
340  const areaScalarField& rho,
341  faMatrix<vector>& eqn,
342  const label fieldi
343  );
344 
345  virtual void addSup
346  (
347  const areaScalarField& h,
348  const areaScalarField& rho,
350  const label fieldi
351  );
352 
353  virtual void addSup
354  (
355  const areaScalarField& h,
356  const areaScalarField& rho,
358  const label fieldi
359  );
360 
361  virtual void addSup
362  (
363  const areaScalarField& h,
364  const areaScalarField& rho,
365  faMatrix<tensor>& eqn,
366  const label fieldi
367  );
368 
369 
370  // Constraints
371 
372  virtual void constrain
373  (
374  faMatrix<scalar>& eqn,
375  const label fieldi
376  );
377 
378  virtual void constrain
379  (
380  faMatrix<vector>& eqn,
381  const label fieldi
382  );
383 
384  virtual void constrain
385  (
387  const label fieldi
388  );
389 
390  virtual void constrain
391  (
393  const label fieldi
394  );
395 
396  virtual void constrain
397  (
398  faMatrix<tensor>& eqn,
399  const label fieldi
400  );
401 
402 
403  // Correction
404 
405  virtual void correct(areaScalarField& field);
406  virtual void correct(areaVectorField& field);
407  virtual void correct(areaSphericalTensorField& field);
408  virtual void correct(areaSymmTensorField& field);
409  virtual void correct(areaTensorField& field);
410 
411 
412  // IO
413 
414  //- Write the source header information
415  virtual void writeHeader(Ostream&) const;
416 
417  //- Write the source footer information
418  virtual void writeFooter(Ostream&) const;
419 
420  //- Write the source properties
421  virtual void writeData(Ostream&) const;
422 
423  //- Read source dictionary
424  virtual bool read(const dictionary& dict);
425 };
426 
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 } // End namespace fa
431 } // End namespace Foam
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #include "faOptionI.H"
436 
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
438 
439 #endif
440 
441 // ************************************************************************* //
Foam::fa::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:38
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::faMatrix
A special matrix type and solver, designed for finite area solutions of scalar equations....
Definition: faMatrix.H:59
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fa::option::name
const word & name() const
Return const access to the source name.
Definition: faOptionI.H:30
Foam::fa::option::clone
autoPtr< option > clone() const
Return clone.
Definition: faOption.H:218
Foam::fa::option::constrain
virtual void constrain(faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:243
Foam::fa::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: faOptionI.H:60
Foam::fa::option::regionName
const word & regionName() const
Region name.
Definition: faOptionI.H:72
Foam::fa::option::addSup
virtual void addSup(const areaScalarField &h, faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:149
Foam::fa::option::coeffs
const dictionary & coeffs() const
Return dictionary.
Definition: faOptionI.H:48
Foam::fa::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:134
faMatrices.H
Foam::fa::option::patch
const fvPatch & patch() const
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:57
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:86
Foam::fa::option::name_
const word name_
Source name.
Definition: faOption.H:147
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::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOption.H:153
Foam::fa::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:128
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::fa::option::regionMeshPtr_
autoPtr< faMesh > regionMeshPtr_
Pointer to the region mesh database.
Definition: faOption.H:177
Foam::fa::option::iNew::iNew
iNew(const fvPatch &patch, const word &name)
Definition: faOption.H:238
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::fa::option::writeData
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:44
Foam::fa::option::vsmPtr_
autoPtr< volSurfaceMapping > vsmPtr_
Volume-to surface mapping.
Definition: faOption.H:180
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:168
Foam::fa::option::active_
Switch active_
Source active flag.
Definition: faOption.H:165
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::fa::option::active
bool active() const
Return const access to the source active flag.
Definition: faOptionI.H:54
Foam::constant::universal::h
const dimensionedScalar h
Planck constant.
Definition: setRegionSolidFields.H:33
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:162
Switch.H
field
rDeltaTY field()
Foam::fa::option::~option
virtual ~option()=default
Destructor.
Foam::fa::option::regionMesh
const faMesh & regionMesh() const
Return the region mesh database.
Definition: faOptionI.H:78
areaFields.H
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:121
Foam::fa::option::vsm
const volSurfaceMapping & vsm() const
Return volSurfaceMapping.
Definition: faOptionI.H:93
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
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:156
Foam::fa::option::modelType_
const word modelType_
Model type.
Definition: faOption.H:150
Foam::fa::option::isActive
virtual bool isActive()
Is the source active?
Definition: faOption.C:122
Foam::fa::option::regionName_
word regionName_
Region name.
Definition: faOption.H:174
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:271
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:134
Foam::fa::option::iNew::operator()
autoPtr< option > operator()(Istream &is) const
Definition: faOption.H:247
Foam::volSurfaceMapping
Volume to surface and surface to volume mapping.
Definition: volSurfaceMapping.H:56
Foam::List< word >
Foam::fa::option::mesh
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: faOptionI.H:36
faOptionI.H
Foam::fa::option::iNew
Definition: faOption.H:226
dictionary.H
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:77
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:159
Foam::fa::option::applied_
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: faOption.H:171