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,2023 PCOpt/NTUA
11  Copyright (C) 2020,2023 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 "surfaceFieldsFwd.H"
78 #include "dictionary.H"
79 #include "runTimeSelectionTables.H"
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 namespace Foam
84 {
85 
86 // Forward Declarations
87 class fvMesh;
88 
89 namespace fv
90 {
91 
92 /*---------------------------------------------------------------------------*\
93  Class option Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class option
97 {
98 protected:
99 
100  // Protected Data
101 
102  //- Source name
103  const word name_;
104 
105  //- Model type
106  const word modelType_;
107 
108  //- Reference to the mesh database
109  const fvMesh& mesh_;
110 
111  //- Top level source dictionary
113 
114  //- Dictionary containing source coefficients
116 
117  //- Field names to apply source to - populated by derived models
119 
120  //- Applied flag list - corresponds to each fieldNames_ entry
121  List<bool> applied_;
122 
123  //- Source active flag
124  bool active_;
125 
126 
127  // Protected Member Functions
128 
129  //- Resize/reset applied flag list for all fieldNames_ entries
130  void resetApplied();
131 
133 public:
134 
135  //- Switch write log to Info
136  bool log;
138 
139  //- Runtime type information
140  TypeName("option");
141 
143  // Declare run-time constructor selection table
144 
146  (
148  option,
149  dictionary,
150  (
151  const word& name,
152  const word& modelType,
153  const dictionary& dict,
154  const fvMesh& mesh
155  ),
156  (name, modelType, dict, mesh)
157  );
158 
159 
160  // Constructors
161 
162  //- Construct from components
163  option
164  (
165  const word& name,
166  const word& modelType,
167  const dictionary& dict,
168  const fvMesh& mesh
169  );
170 
171  //- Return clone
172  autoPtr<option> clone() const
173  {
175  return nullptr;
176  }
177 
178  //- Return pointer to new fvOption object created
179  // on the freestore from an Istream
180  class iNew
181  {
182  //- Reference to the mesh
183  const fvMesh& mesh_;
184 
185  const word& name_;
186 
187  public:
188 
189  iNew
190  (
191  const fvMesh& mesh,
192  const word& name
193  )
194  :
195  mesh_(mesh),
196  name_(name)
197  {}
198 
200  {
201  const dictionary dict(is);
202 
203  return autoPtr<option>
204  (
205  option::New(name_, dict, mesh_)
206  );
207  }
208  };
209 
210 
211  // Selectors
212 
213  //- Return a reference to the selected fvOption model
214  static autoPtr<option> New
215  (
216  const word& name,
217  const dictionary& dict,
218  const fvMesh& mesh
219  );
220 
221 
222  //- Destructor
223  virtual ~option() = default;
224 
226  // Member Functions
227 
228  // Access
229 
230  //- Return const access to the source name
231  inline const word& name() const noexcept;
232 
233  //- Return const access to the mesh database
234  inline const fvMesh& mesh() const noexcept;
235 
236  //- Return dictionary
237  inline const dictionary& coeffs() const noexcept;
238 
239  //- True if source is active
240  inline bool active() const noexcept;
241 
242  //- Set the applied flag to true for field index fieldi
243  inline void setApplied(const label fieldi);
244 
245 
246  // Edit
247 
248  //- Change source active flag, return previous value
249  inline bool active(const bool on) noexcept;
250 
251 
252  // Checks
253 
254  //- Is the source active?
255  virtual bool isActive();
256 
257  //- Return index of field name if found in fieldNames list
258  virtual label applyToField(const word& fieldName) const;
259 
260  //- Check that the source has been applied
261  virtual void checkApplied() const;
262 
263 
264  // Evaluation
265 
266  // Explicit and implicit sources
267 
268  virtual void addSup
269  (
270  fvMatrix<scalar>& eqn,
271  const label fieldi
272  );
273 
274  virtual void addSup
275  (
276  fvMatrix<vector>& eqn,
277  const label fieldi
278  );
279 
280  virtual void addSup
281  (
282  fvMatrix<symmTensor>& eqn,
283  const label fieldi
284  );
285 
286  virtual void addSup
287  (
289  const label fieldi
290  );
291 
292  virtual void addSup
293  (
294  fvMatrix<tensor>& eqn,
295  const label fieldi
296  );
297 
298 
299  // Explicit and implicit sources for compressible equations
300 
301  virtual void addSup
302  (
303  const volScalarField& rho,
304  fvMatrix<scalar>& eqn,
305  const label fieldi
306  );
307 
308  virtual void addSup
309  (
310  const volScalarField& rho,
311  fvMatrix<vector>& eqn,
312  const label fieldi
313  );
314 
315  virtual void addSup
316  (
317  const volScalarField& rho,
318  fvMatrix<symmTensor>& eqn,
319  const label fieldi
320  );
321 
322  virtual void addSup
323  (
324  const volScalarField& rho,
326  const label fieldi
327  );
328 
329  virtual void addSup
330  (
331  const volScalarField& rho,
332  fvMatrix<tensor>& eqn,
333  const label fieldi
334  );
335 
336 
337  // Explicit and implicit sources for phase equations
338 
339  virtual void addSup
340  (
341  const volScalarField& alpha,
342  const volScalarField& rho,
343  fvMatrix<scalar>& eqn,
344  const label fieldi
345  );
346 
347  virtual void addSup
348  (
349  const volScalarField& alpha,
350  const volScalarField& rho,
351  fvMatrix<vector>& eqn,
352  const label fieldi
353  );
354 
355  virtual void addSup
356  (
357  const volScalarField& alpha,
358  const volScalarField& rho,
359  fvMatrix<symmTensor>& eqn,
360  const label fieldi
361  );
362 
363  virtual void addSup
364  (
365  const volScalarField& alpha,
366  const volScalarField& rho,
368  const label fieldi
369  );
370 
371  virtual void addSup
372  (
373  const volScalarField& alpha,
374  const volScalarField& rho,
375  fvMatrix<tensor>& eqn,
376  const label fieldi
377  );
378 
379 
380  // Constraints
381 
382  virtual void constrain
383  (
384  fvMatrix<scalar>& eqn,
385  const label fieldi
386  );
387 
388  virtual void constrain
389  (
390  fvMatrix<vector>& eqn,
391  const label fieldi
392  );
393 
394  virtual void constrain
395  (
397  const label fieldi
398  );
399 
400  virtual void constrain
401  (
402  fvMatrix<symmTensor>& eqn,
403  const label fieldi
404  );
405 
406  virtual void constrain
407  (
408  fvMatrix<tensor>& eqn,
409  const label fieldi
410  );
411 
412 
413  // Correction
414 
415  virtual void correct(volScalarField& field);
416  virtual void correct(volVectorField& field);
417  virtual void correct(volSphericalTensorField& field);
418  virtual void correct(volSymmTensorField& field);
419  virtual void correct(volTensorField& field);
420 
421  virtual void correct(surfaceScalarField& field);
422  virtual void correct(surfaceVectorField& field);
423  virtual void correct(surfaceTensorField& field);
424 
425 
426  // Post process sensitivity field related to the fvOption
427 
428  virtual void postProcessSens
429  (
430  scalarField& sensField,
431  const word& fieldName = word::null,
432  const word& designVariablesName = word::null
433  );
434  virtual void postProcessSens
435  (
436  vectorField& sensField,
437  const word& fieldName = word::null,
438  const word& designVariablesName = word::null
439  );
440  virtual void postProcessSens
441  (
442  tensorField& sensField,
443  const word& fieldName = word::null,
444  const word& designVariablesName = word::null
445  );
446 
447  virtual void postProcessAuxSens
448  (
449  const volScalarField& primalField,
450  const volScalarField& adjointField,
451  scalarField& sensField,
452  const word& fieldName = word::null
453  );
454  virtual void postProcessAuxSens
455  (
456  const volVectorField& primalField,
457  const volVectorField& adjointField,
458  scalarField& sensField,
459  const word& fieldName = word::null
460  );
461  virtual void postProcessAuxSens
462  (
463  const volTensorField& primalField,
464  const volTensorField& adjointField,
465  scalarField& sensField,
466  const word& fieldName = word::null
467  );
468 
469 
470  // IO
471 
472  //- Write the source header information
473  virtual void writeHeader(Ostream&) const;
474 
475  //- Write the source footer information
476  virtual void writeFooter(Ostream&) const;
477 
478  //- Write the source properties
479  virtual void writeData(Ostream&) const;
480 
481  //- Read source dictionary
482  virtual bool read(const dictionary& dict);
483 };
484 
485 
486 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
487 
488 } // End namespace fv
489 } // End namespace Foam
490 
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 
493 #include "fvOptionI.H"
494 
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 
497 #endif
498 
499 // ************************************************************************* //
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:157
Forwards and collection of common volume field types.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:142
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void postProcessAuxSens(const volScalarField &primalField, const volScalarField &adjointField, scalarField &sensField, const word &fieldName=word::null)
Definition: fvOption.C:371
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:147
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:248
const word name_
Source name.
Definition: fvOption.H:132
autoPtr< option > clone() const
Return clone.
Definition: fvOption.H:225
A class for handling words, derived from Foam::string.
Definition: word.H:63
const word modelType_
Model type.
Definition: fvOption.H:137
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:344
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:56
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:183
List< word > wordList
List of word.
Definition: fileName.H:59
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:78
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:257
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:162
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:686
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:152
bool active_
Source active flag.
Definition: fvOption.H:167
TypeName("option")
Runtime type information.
Namespace for OpenFOAM.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:123