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 Foam_fvOption_H
72 #define Foam_fvOption_H
73 
74 #include "fvMatricesFwd.H"
75 #include "primitiveFieldsFwd.H"
76 #include "volFieldsFwd.H"
77 #include "dictionary.H"
78 #include "runTimeSelectionTables.H"
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 namespace Foam
83 {
84 
85 // Forward Declarations
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  //- Field names to apply source to - populated by derived models
118 
119  //- Applied flag list - corresponds to each fieldNames_ entry
120  List<bool> applied_;
121 
122  //- Source active flag
123  bool active_;
124 
125 
126  // Protected Member Functions
127 
128  //- Resize/reset applied flag list for all fieldNames_ entries
129  void resetApplied();
130 
132 public:
133 
134  //- Switch write log to Info
135  bool log;
137 
138  //- Runtime type information
139  TypeName("option");
140 
142  // Declare run-time constructor selection table
143 
145  (
147  option,
148  dictionary,
149  (
150  const word& name,
151  const word& modelType,
152  const dictionary& dict,
153  const fvMesh& mesh
154  ),
155  (name, modelType, dict, mesh)
156  );
157 
158 
159  // Constructors
160 
161  //- Construct from components
162  option
163  (
164  const word& name,
165  const word& modelType,
166  const dictionary& dict,
167  const fvMesh& mesh
168  );
169 
170  //- Return clone
171  autoPtr<option> clone() const
172  {
174  return nullptr;
175  }
176 
177  //- Return pointer to new fvOption object created
178  // on the freestore from an Istream
179  class iNew
180  {
181  //- Reference to the mesh
182  const fvMesh& mesh_;
183 
184  const word& name_;
185 
186  public:
187 
188  iNew
189  (
190  const fvMesh& mesh,
191  const word& name
192  )
193  :
194  mesh_(mesh),
195  name_(name)
196  {}
197 
199  {
200  const dictionary dict(is);
201 
202  return autoPtr<option>
203  (
204  option::New(name_, dict, mesh_)
205  );
206  }
207  };
208 
209 
210  // Selectors
211 
212  //- Return a reference to the selected fvOption model
213  static autoPtr<option> New
214  (
215  const word& name,
216  const dictionary& dict,
217  const fvMesh& mesh
218  );
219 
220 
221  //- Destructor
222  virtual ~option() = default;
223 
225  // Member Functions
226 
227  // Access
228 
229  //- Return const access to the source name
230  inline const word& name() const noexcept;
231 
232  //- Return const access to the mesh database
233  inline const fvMesh& mesh() const noexcept;
234 
235  //- Return dictionary
236  inline const dictionary& coeffs() const noexcept;
237 
238  //- True if source is active
239  inline bool active() const noexcept;
240 
241  //- Set the applied flag to true for field index fieldi
242  inline void setApplied(const label fieldi);
243 
244 
245  // Edit
246 
247  //- Change source active flag, return previous value
248  inline bool active(const bool on) noexcept;
249 
250 
251  // Checks
252 
253  //- Is the source active?
254  virtual bool isActive();
255 
256  //- Return index of field name if found in fieldNames list
257  virtual label applyToField(const word& fieldName) const;
258 
259  //- Check that the source has been applied
260  virtual void checkApplied() const;
261 
262 
263  // Evaluation
264 
265  // Explicit and implicit sources
266 
267  virtual void addSup
268  (
269  fvMatrix<scalar>& eqn,
270  const label fieldi
271  );
272 
273  virtual void addSup
274  (
275  fvMatrix<vector>& eqn,
276  const label fieldi
277  );
278 
279  virtual void addSup
280  (
281  fvMatrix<symmTensor>& eqn,
282  const label fieldi
283  );
284 
285  virtual void addSup
286  (
288  const label fieldi
289  );
290 
291  virtual void addSup
292  (
293  fvMatrix<tensor>& eqn,
294  const label fieldi
295  );
296 
297 
298  // Explicit and implicit sources for compressible equations
299 
300  virtual void addSup
301  (
302  const volScalarField& rho,
303  fvMatrix<scalar>& eqn,
304  const label fieldi
305  );
306 
307  virtual void addSup
308  (
309  const volScalarField& rho,
310  fvMatrix<vector>& eqn,
311  const label fieldi
312  );
313 
314  virtual void addSup
315  (
316  const volScalarField& rho,
317  fvMatrix<symmTensor>& eqn,
318  const label fieldi
319  );
320 
321  virtual void addSup
322  (
323  const volScalarField& rho,
325  const label fieldi
326  );
327 
328  virtual void addSup
329  (
330  const volScalarField& rho,
331  fvMatrix<tensor>& eqn,
332  const label fieldi
333  );
334 
335 
336  // Explicit and implicit sources for phase equations
337 
338  virtual void addSup
339  (
340  const volScalarField& alpha,
341  const volScalarField& rho,
342  fvMatrix<scalar>& eqn,
343  const label fieldi
344  );
345 
346  virtual void addSup
347  (
348  const volScalarField& alpha,
349  const volScalarField& rho,
350  fvMatrix<vector>& eqn,
351  const label fieldi
352  );
353 
354  virtual void addSup
355  (
356  const volScalarField& alpha,
357  const volScalarField& rho,
358  fvMatrix<symmTensor>& eqn,
359  const label fieldi
360  );
361 
362  virtual void addSup
363  (
364  const volScalarField& alpha,
365  const volScalarField& rho,
367  const label fieldi
368  );
369 
370  virtual void addSup
371  (
372  const volScalarField& alpha,
373  const volScalarField& rho,
374  fvMatrix<tensor>& eqn,
375  const label fieldi
376  );
377 
378 
379  // Constraints
380 
381  virtual void constrain
382  (
383  fvMatrix<scalar>& eqn,
384  const label fieldi
385  );
386 
387  virtual void constrain
388  (
389  fvMatrix<vector>& eqn,
390  const label fieldi
391  );
392 
393  virtual void constrain
394  (
396  const label fieldi
397  );
398 
399  virtual void constrain
400  (
401  fvMatrix<symmTensor>& eqn,
402  const label fieldi
403  );
404 
405  virtual void constrain
406  (
407  fvMatrix<tensor>& eqn,
408  const label fieldi
409  );
410 
411 
412  // Correction
413 
414  virtual void correct(volScalarField& field);
415  virtual void correct(volVectorField& field);
416  virtual void correct(volSphericalTensorField& field);
417  virtual void correct(volSymmTensorField& field);
418  virtual void correct(volTensorField& field);
419 
420 
421  // Post process sensitivity field related to the fvOption
422 
423  virtual void postProcessSens
424  (
425  scalarField& sensField,
426  const word& fieldName = word::null,
427  const word& designVariablesName = word::null
428  );
429  virtual void postProcessSens
430  (
431  vectorField& sensField,
432  const word& fieldName = word::null,
433  const word& designVariablesName = word::null
434  );
435  virtual void postProcessSens
436  (
437  tensorField& sensField,
438  const word& fieldName = word::null,
439  const word& designVariablesName = word::null
440  );
441 
442 
443  // IO
444 
445  //- Write the source header information
446  virtual void writeHeader(Ostream&) const;
447 
448  //- Write the source footer information
449  virtual void writeFooter(Ostream&) const;
450 
451  //- Write the source properties
452  virtual void writeData(Ostream&) const;
453 
454  //- Read source dictionary
455  virtual bool read(const dictionary& dict);
456 };
457 
458 
459 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
460 
461 } // End namespace fv
462 } // End namespace Foam
463 
464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
465 
466 #include "fvOptionI.H"
467 
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
469 
470 #endif
471 
472 // ************************************************************************* //
dictionary dict
virtual void correct(volScalarField &field)
Definition: fvOption.C:311
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: fvOptionI.H:30
rDeltaTY field()
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:156
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:141
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: fvOptionI.H:56
dictionary dict_
Top level source dictionary.
Definition: fvOption.H:146
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition: fvOption.C:75
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
bool active() const noexcept
True if source is active.
Definition: fvOptionI.H:42
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:139
iNew(const fvMesh &mesh, const word &name)
Definition: fvOption.H:247
const word name_
Source name.
Definition: fvOption.H:131
autoPtr< option > clone() const
Return clone.
Definition: fvOption.H:224
A class for handling words, derived from Foam::string.
Definition: word.H:63
const word modelType_
Model type.
Definition: fvOption.H:136
labelList fv(nPoints)
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:32
const dictionary & coeffs() const noexcept
Return dictionary.
Definition: fvOptionI.H:36
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:124
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:48
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:64
virtual ~option()=default
Destructor.
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:24
virtual void postProcessSens(scalarField &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Definition: fvOption.C:332
declareRunTimeSelectionTable(autoPtr, option, dictionary,(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh),(name, modelType, dict, mesh))
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
bool log
Switch write log to Info.
Definition: fvOption.H:182
List< word > wordList
A List of words.
Definition: fileName.H:58
virtual void writeData(Ostream &) const
Write the source properties.
Definition: fvOptionIO.C:38
Forward declarations of fvMatrix specializations.
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:283
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:41
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: fvOptionIO.C:26
autoPtr< option > operator()(Istream &is) const
Definition: fvOption.H:256
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvOption.C:51
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition: fvOption.H:161
virtual bool isActive()
Is the source active?
Definition: fvOption.C:112
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:118
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Tensor of scalars, i.e. Tensor<scalar>.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:666
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:151
bool active_
Source active flag.
Definition: fvOption.H:166
TypeName("option")
Runtime type information.
Namespace for OpenFOAM.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:122