fvOption.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) 2019 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::option
29 
30 Description
31  Finite volume options abstract base class. Provides a base set of
32  controls, e.g.:
33  \verbatim
34  type scalarExplicitSource // source type
35  active on; // on/off switch
36  \endverbatim
37 
38 Note
39  On evaluation, source/sink options are to be added to the equation R.H.S.
40 
41 SourceFiles
42  fvOption.C
43  fvOptionIO.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef fvOption_H
48 #define fvOption_H
49 
50 #include "fvMatricesFwd.H"
51 #include "volFieldsFwd.H"
52 #include "dictionary.H"
53 #include "Switch.H"
54 #include "runTimeSelectionTables.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 class fvMesh;
62 
63 namespace fv
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class option Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class option
71 {
72 protected:
73 
74  // Protected data
75 
76  //- Source name
77  const word name_;
78 
79  //- Model type
80  const word modelType_;
81 
82  //- Reference to the mesh database
83  const fvMesh& mesh_;
84 
85  //- Top level source dictionary
87 
88  //- Dictionary containing source coefficients
90 
91  //- Source active flag
93 
94  //- Field names to apply source to - populated by derived models
96 
97  //- Applied flag list - corresponds to each fieldNames_ entry
99 
100 
101 public:
102 
103  //- Runtime type information
104  TypeName("option");
105 
106  //- Switch write log to Info
107  bool log;
108 
109  // Declare run-time constructor selection table
110 
112  (
113  autoPtr,
114  option,
115  dictionary,
116  (
117  const word& name,
118  const word& modelType,
119  const dictionary& dict,
120  const fvMesh& mesh
121  ),
122  (name, modelType, dict, mesh)
123  );
124 
125 
126  // Constructors
127 
128  //- Construct from components
129  option
130  (
131  const word& name,
132  const word& modelType,
133  const dictionary& dict,
134  const fvMesh& mesh
135  );
136 
137  //- Return clone
138  autoPtr<option> clone() const
139  {
141  return nullptr;
142  }
143 
144  //- Return pointer to new fvOption object created
145  // on the freestore from an Istream
146  class iNew
147  {
148  //- Reference to the mesh
149  const fvMesh& mesh_;
150 
151  const word& name_;
152 
153  public:
154 
156  (
157  const fvMesh& mesh,
158  const word& name
159  )
160  :
161  mesh_(mesh),
162  name_(name)
163  {}
164 
166  {
167  //const word name(is);
168  const dictionary dict(is);
169 
170  return autoPtr<option>
171  (
172  option::New(name_, dict, mesh_)
173  );
174  }
175  };
176 
177 
178  // Selectors
179 
180  //- Return a reference to the selected fvOption model
181  static autoPtr<option> New
182  (
183  const word& name,
184  const dictionary& dict,
185  const fvMesh& mesh
186  );
187 
188 
189  //- Destructor
190  virtual ~option() = default;
191 
192 
193  // Member Functions
194 
195  // Access
196 
197  //- Return const access to the source name
198  inline const word& name() const;
199 
200  //- Return const access to the mesh database
201  inline const fvMesh& mesh() const;
202 
203  //- Return dictionary
204  inline const dictionary& coeffs() const;
205 
206  //- Return const access to the source active flag
207  inline bool active() const;
208 
209  //- Set the applied flag to true for field index fieldi
210  inline void setApplied(const label fieldi);
211 
212 
213  // Edit
214 
215  //- Return access to the source active flag
216  inline Switch& active();
217 
218 
219  // Checks
220 
221  //- Is the source active?
222  virtual bool isActive();
223 
224  //- Return index of field name if found in fieldNames list
225  virtual label applyToField(const word& fieldName) const;
226 
227  //- Check that the source has been applied
228  virtual void checkApplied() const;
229 
230 
231  // Evaluation
232 
233  // Explicit and implicit sources
234 
235  virtual void addSup
236  (
237  fvMatrix<scalar>& eqn,
238  const label fieldi
239  );
240 
241  virtual void addSup
242  (
243  fvMatrix<vector>& eqn,
244  const label fieldi
245  );
246 
247  virtual void addSup
248  (
250  const label fieldi
251  );
252 
253  virtual void addSup
254  (
256  const label fieldi
257  );
258 
259  virtual void addSup
260  (
261  fvMatrix<tensor>& eqn,
262  const label fieldi
263  );
264 
265 
266  // Explicit and implicit sources for compressible equations
267 
268  virtual void addSup
269  (
270  const volScalarField& rho,
271  fvMatrix<scalar>& eqn,
272  const label fieldi
273  );
274 
275  virtual void addSup
276  (
277  const volScalarField& rho,
278  fvMatrix<vector>& eqn,
279  const label fieldi
280  );
281 
282  virtual void addSup
283  (
284  const volScalarField& rho,
286  const label fieldi
287  );
288 
289  virtual void addSup
290  (
291  const volScalarField& rho,
293  const label fieldi
294  );
295 
296  virtual void addSup
297  (
298  const volScalarField& rho,
299  fvMatrix<tensor>& eqn,
300  const label fieldi
301  );
302 
303 
304  // Explicit and implicit sources for phase equations
305 
306  virtual void addSup
307  (
308  const volScalarField& alpha,
309  const volScalarField& rho,
310  fvMatrix<scalar>& eqn,
311  const label fieldi
312  );
313 
314  virtual void addSup
315  (
316  const volScalarField& alpha,
317  const volScalarField& rho,
318  fvMatrix<vector>& eqn,
319  const label fieldi
320  );
321 
322  virtual void addSup
323  (
324  const volScalarField& alpha,
325  const volScalarField& rho,
327  const label fieldi
328  );
329 
330  virtual void addSup
331  (
332  const volScalarField& alpha,
333  const volScalarField& rho,
335  const label fieldi
336  );
337 
338  virtual void addSup
339  (
340  const volScalarField& alpha,
341  const volScalarField& rho,
342  fvMatrix<tensor>& eqn,
343  const label fieldi
344  );
345 
346 
347  // Constraints
348 
349  virtual void constrain
350  (
351  fvMatrix<scalar>& eqn,
352  const label fieldi
353  );
354 
355  virtual void constrain
356  (
357  fvMatrix<vector>& eqn,
358  const label fieldi
359  );
360 
361  virtual void constrain
362  (
364  const label fieldi
365  );
366 
367  virtual void constrain
368  (
370  const label fieldi
371  );
372 
373  virtual void constrain
374  (
375  fvMatrix<tensor>& eqn,
376  const label fieldi
377  );
378 
379 
380  // Correction
381 
382  virtual void correct(volScalarField& field);
383  virtual void correct(volVectorField& field);
384  virtual void correct(volSphericalTensorField& field);
385  virtual void correct(volSymmTensorField& field);
386  virtual void correct(volTensorField& field);
387 
388 
389  // IO
390 
391  //- Write the source header information
392  virtual void writeHeader(Ostream&) const;
393 
394  //- Write the source footer information
395  virtual void writeFooter(Ostream&) const;
396 
397  //- Write the source properties
398  virtual void writeData(Ostream&) const;
399 
400  //- Read source dictionary
401  virtual bool read(const dictionary& dict);
402 };
403 
404 
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 
407 } // End namespace fv
408 } // End namespace Foam
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 #include "fvOptionI.H"
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #endif
417 
418 // ************************************************************************* //
Foam::fv::option::correct
virtual void correct(volScalarField &field)
Definition: fvOption.C:307
Foam::fv::option::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, option, dictionary,(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh),(name, modelType, dict, mesh))
volFieldsFwd.H
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:76
fvOptionI.H
Foam::fv::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: fvOptionI.H:54
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::option::clone
autoPtr< option > clone() const
Return clone.
Definition: fvOption.H:137
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:30
Foam::fv::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:120
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::fv::option::iNew::operator()
autoPtr< option > operator()(Istream &is) const
Definition: fvOption.H:164
Foam::fv::option::coeffs
const dictionary & coeffs() const
Return dictionary.
Definition: fvOptionI.H:42
fvMatricesFwd.H
Forward declarations of fvMatrix specializations.
Foam::fv::option::name_
const word name_
Source name.
Definition: fvOption.H:76
rho
rho
Definition: readInitialConditions.H:88
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:82
Foam::fv::option::writeData
virtual void writeData(Ostream &) const
Write the source properties.
Definition: fvOptionIO.C:45
Foam::fv::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:114
Foam::fv::option::option
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvOption.C:47
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:436
Foam::fv::option::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:135
Foam::fv::option
Finite volume options abstract base class. Provides a base set of controls, e.g.:
Definition: fvOption.H:69
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::fv::option::active_
Switch active_
Source active flag.
Definition: fvOption.H:91
Foam::fv::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:88
Foam::fv::option::TypeName
TypeName("option")
Runtime type information.
Foam::fv::option::fieldNames_
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:94
Foam::fv::option::active
bool active() const
Return const access to the source active flag.
Definition: fvOptionI.H:48
Switch.H
Foam::fv::option::~option
virtual ~option()=default
Destructor.
field
rDeltaTY field()
Foam::fv::option::log
bool log
Switch write log to Info.
Definition: fvOption.H:106
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fv::option::iNew
Return pointer to new fvOption object created.
Definition: fvOption.H:145
Foam::fv::option::constrain
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:279
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::fv::option::writeHeader
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: fvOptionIO.C:33
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam::fv::option::New
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition: fvOption.C:71
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fv::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:108
Foam::fv::option::modelType_
const word modelType_
Model type.
Definition: fvOption.H:79
fv
labelList fv(nPoints)
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::List< word >
dictionary.H
Foam::fv::option::mesh
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:36
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::fv::option::dict_
dictionary dict_
Top level source dictionary.
Definition: fvOption.H:85
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::fv::option::applied_
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: fvOption.H:97
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::fv::option::iNew::iNew
iNew(const fvMesh &mesh, const word &name)
Definition: fvOption.H:155
Foam::fv::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:39