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  //- 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 
131 
132 public:
133 
134  //- Switch write log to Info
135  bool log;
136 
137 
138  //- Runtime type information
139  TypeName("option");
140 
141 
142  // Declare run-time constructor selection table
143 
145  (
146  autoPtr,
147  option,
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 
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 
224 
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 // ************************************************************************* //
Foam::fv::option::correct
virtual void correct(volScalarField &field)
Definition: fvOption.C:318
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::Tensor< scalar >
Foam::fv::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
Foam::SymmTensor< scalar >
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::fv::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: fvOptionI.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::option::clone
autoPtr< option > clone() const
Return clone.
Definition: fvOption.H:202
Foam::fv::option::resetApplied
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:48
Foam::fv::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:131
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:229
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:62
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:125
Foam::fv::option::active
bool active() const noexcept
True if source is active.
Definition: fvOptionI.H:49
Foam::fv::option::option
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fvOption.C:58
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::fv::option::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:146
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::coeffs
const dictionary & coeffs() const noexcept
Return dictionary.
Definition: fvOptionI.H:43
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:148
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:166
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fv::option::constrain
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:290
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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:85
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:82
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
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:339
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:119
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
Foam::fv::option::mesh
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition: fvOptionI.H:37
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Vector< scalar >
Foam::fv::option::active_
bool active_
Source active flag.
Definition: fvOption.H:154
Foam::List< word >
dictionary.H
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
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:151
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::fv::option::iNew::iNew
iNew(const fvMesh &mesh, const word &name)
Definition: fvOption.H:220
Foam::fv::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:39