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-2020 OpenCFD Ltd.
10  Copyright (C) 2020 PCOpt/NTUA
11  Copyright (C) 2020 FOSS GP
12 ------------------------------------------------------------------------------
13 License
14  This file is part of OpenFOAM.
15 
16  OpenFOAM is free software: you can redistribute it and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 
29 Class
30  Foam::fv::option
31 
32 Description
33  Base abstract class for handling finite volume options (i.e. \c fvOption).
34 
35 Usage
36  Minimal example by using \c constant/fvOptions:
37  \verbatim
38  <userDefinedName1>
39  {
40  // Mandatory entries (unmodifiable)
41  type <fvOptionName>;
42 
43  // Optional entries (unmodifiable/runtime modifiable)
44  <fvOption>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 fvOption | word | yes | -
59  <fvOption>Coeffs | Dictionary containing settings of <!--
60  --> the selected fvOption settings | dictionary | no | -
61  active | Flag to (de)activate fvOption | bool | no | true
62  log | Flag to log fvOption-related info | bool | no | true
63  \endtable
64 
65 SourceFiles
66  fvOption.C
67  fvOptionIO.C
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef fvOption_H
72 #define fvOption_H
73 
74 #include "fvMatricesFwd.H"
75 #include "primitiveFieldsFwd.H"
76 #include "volFieldsFwd.H"
77 #include "dictionary.H"
78 #include "Switch.H"
79 #include "runTimeSelectionTables.H"
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 namespace Foam
84 {
85 
86 class fvMesh;
87 
88 namespace fv
89 {
90 
91 /*---------------------------------------------------------------------------*\
92  Class option Declaration
93 \*---------------------------------------------------------------------------*/
94 
95 class option
96 {
97 protected:
98 
99  // Protected Data
100 
101  //- Source name
102  const word name_;
103 
104  //- Model type
105  const word modelType_;
106 
107  //- Reference to the mesh database
108  const fvMesh& mesh_;
109 
110  //- Top level source dictionary
111  dictionary dict_;
112 
113  //- Dictionary containing source coefficients
114  dictionary coeffs_;
115 
116  //- Source active flag
117  Switch active_;
118 
119  //- Field names to apply source to - populated by derived models
121 
122  //- Applied flag list - corresponds to each fieldNames_ entry
123  List<bool> applied_;
124 
125 
126 public:
127 
128  //- Runtime type information
129  TypeName("option");
130 
131  //- Switch write log to Info
132  bool log;
133 
134  // Declare run-time constructor selection table
135 
137  (
138  autoPtr,
140  dictionary,
141  (
142  const word& name,
143  const word& modelType,
144  const dictionary& dict,
145  const fvMesh& mesh
146  ),
147  (name, modelType, dict, mesh)
148  );
149 
150 
151  // Constructors
152 
153  //- Construct from components
155  (
156  const word& name,
157  const word& modelType,
158  const dictionary& dict,
159  const fvMesh& mesh
160  );
161 
162  //- Return clone
164  {
166  return nullptr;
167  }
168 
169  //- Return pointer to new fvOption object created
170  // on the freestore from an Istream
171  class iNew
172  {
173  //- Reference to the mesh
174  const fvMesh& mesh_;
175 
176  const word& name_;
177 
178  public:
179 
180  iNew
181  (
182  const fvMesh& mesh,
183  const word& name
184  )
185  :
186  mesh_(mesh),
187  name_(name)
188  {}
189 
191  {
192  const dictionary dict(is);
193 
195  (
196  option::New(name_, dict, mesh_)
197  );
198  }
199  };
200 
201 
202  // Selectors
203 
204  //- Return a reference to the selected fvOption model
205  static autoPtr<option> New
206  (
207  const word& name,
208  const dictionary& dict,
209  const fvMesh& mesh
210  );
211 
212 
213  //- Destructor
214  virtual ~option() = default;
215 
216 
217  // Member Functions
218 
219  // Access
220 
221  //- Return const access to the source name
222  inline const word& name() const;
223 
224  //- Return const access to the mesh database
225  inline const fvMesh& mesh() const;
226 
227  //- Return dictionary
228  inline const dictionary& coeffs() const;
229 
230  //- Return const access to the source active flag
231  inline bool active() const;
232 
233  //- Set the applied flag to true for field index fieldi
234  inline void setApplied(const label fieldi);
235 
236 
237  // Edit
238 
239  //- Return access to the source active flag
240  inline Switch& active();
241 
242 
243  // Checks
244 
245  //- Is the source active?
246  virtual bool isActive();
247 
248  //- Return index of field name if found in fieldNames list
249  virtual label applyToField(const word& fieldName) const;
250 
251  //- Check that the source has been applied
252  virtual void checkApplied() const;
253 
254 
255  // Evaluation
256 
257  // Explicit and implicit sources
258 
259  virtual void addSup
260  (
261  fvMatrix<scalar>& eqn,
262  const label fieldi
263  );
264 
265  virtual void addSup
266  (
267  fvMatrix<vector>& eqn,
268  const label fieldi
269  );
270 
271  virtual void addSup
272  (
274  const label fieldi
275  );
276 
277  virtual void addSup
278  (
280  const label fieldi
281  );
282 
283  virtual void addSup
284  (
285  fvMatrix<tensor>& eqn,
286  const label fieldi
287  );
288 
289 
290  // Explicit and implicit sources for compressible equations
291 
292  virtual void addSup
293  (
294  const volScalarField& rho,
295  fvMatrix<scalar>& eqn,
296  const label fieldi
297  );
298 
299  virtual void addSup
300  (
301  const volScalarField& rho,
302  fvMatrix<vector>& eqn,
303  const label fieldi
304  );
305 
306  virtual void addSup
307  (
308  const volScalarField& rho,
310  const label fieldi
311  );
312 
313  virtual void addSup
314  (
315  const volScalarField& rho,
317  const label fieldi
318  );
319 
320  virtual void addSup
321  (
322  const volScalarField& rho,
323  fvMatrix<tensor>& eqn,
324  const label fieldi
325  );
326 
327 
328  // Explicit and implicit sources for phase equations
329 
330  virtual void addSup
331  (
332  const volScalarField& alpha,
333  const volScalarField& rho,
334  fvMatrix<scalar>& eqn,
335  const label fieldi
336  );
337 
338  virtual void addSup
339  (
340  const volScalarField& alpha,
341  const volScalarField& rho,
342  fvMatrix<vector>& eqn,
343  const label fieldi
344  );
345 
346  virtual void addSup
347  (
348  const volScalarField& alpha,
349  const volScalarField& rho,
351  const label fieldi
352  );
353 
354  virtual void addSup
355  (
356  const volScalarField& alpha,
357  const volScalarField& rho,
359  const label fieldi
360  );
361 
362  virtual void addSup
363  (
364  const volScalarField& alpha,
365  const volScalarField& rho,
366  fvMatrix<tensor>& eqn,
367  const label fieldi
368  );
369 
370 
371  // Constraints
372 
373  virtual void constrain
374  (
375  fvMatrix<scalar>& eqn,
376  const label fieldi
377  );
378 
379  virtual void constrain
380  (
381  fvMatrix<vector>& eqn,
382  const label fieldi
383  );
384 
385  virtual void constrain
386  (
388  const label fieldi
389  );
390 
391  virtual void constrain
392  (
394  const label fieldi
395  );
396 
397  virtual void constrain
398  (
399  fvMatrix<tensor>& eqn,
400  const label fieldi
401  );
402 
403 
404  // Correction
405 
406  virtual void correct(volScalarField& field);
407  virtual void correct(volVectorField& field);
408  virtual void correct(volSphericalTensorField& field);
409  virtual void correct(volSymmTensorField& field);
410  virtual void correct(volTensorField& field);
411 
412 
413  // Post process sensitivity field related to the fvOption
414 
415  virtual void postProcessSens
416  (
417  scalarField& sensField,
418  const word& fieldName = word::null,
419  const word& designVariablesName = word::null
420  );
421  virtual void postProcessSens
422  (
423  vectorField& sensField,
424  const word& fieldName = word::null,
425  const word& designVariablesName = word::null
426  );
427  virtual void postProcessSens
428  (
429  tensorField& sensField,
430  const word& fieldName = word::null,
431  const word& designVariablesName = word::null
432  );
433 
434 
435  // IO
436 
437  //- Write the source header information
438  virtual void writeHeader(Ostream&) const;
439 
440  //- Write the source footer information
441  virtual void writeFooter(Ostream&) const;
442 
443  //- Write the source properties
444  virtual void writeData(Ostream&) const;
445 
446  //- Read source dictionary
447  virtual bool read(const dictionary& dict);
448 };
449 
450 
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 
453 } // End namespace fv
454 } // End namespace Foam
455 
456 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
457 
458 #include "fvOptionI.H"
459 
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461 
462 #endif
463 
464 // ************************************************************************* //
Foam::fv::option::correct
virtual void correct(volScalarField &field)
Definition: fvOption.C:309
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
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
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:194
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:122
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:221
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:133
rho
rho
Definition: readInitialConditions.H:88
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
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:116
Foam::fv::option::option
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvOption.C:49
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::fv::option::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:137
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
Foam::Field< scalar >
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:148
Foam::fv::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
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:151
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:163
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fv::option::constrain
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:281
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:83
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:73
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::postProcessSens
virtual void postProcessSens(scalarField &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Definition: fvOption.C:330
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:110
Foam::fv::option::modelType_
const word modelType_
Model type.
Definition: fvOption.H:136
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::word::null
static const word null
An empty word.
Definition: word.H:77
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:142
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:154
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::fv::option::iNew::iNew
iNew(const fvMesh &mesh, const word &name)
Definition: fvOption.H:212
Foam::fv::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:39