Loading...
Searching...
No Matches
faOption.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) 2019-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::fa::option
28
29Description
30 Base abstract class for handling finite area options (i.e. \c faOption).
31
32Usage
33 Minimal example by using \c constant/faOptions:
34 \verbatim
35 <userDefinedName1>
36 {
37 // Mandatory entries (unmodifiable)
38 type <faOptionName>;
39
40 // Mandatory entries (runtime modifiable)
41 region <regionName>;
42
43 // Optional entry (unmodifiable)
44 area <areaName>;
45
46 // Optional entries (unmodifiable/runtime modifiable)
47 <faOption>Coeffs
48 {
49 // subdictionary entries
50 }
51
52 // Optional entries (runtime modifiable)
53 active true;
54 log true;
55 }
56 \endverbatim
57
58 where the entries mean:
59 \table
60 Property | Description | Type | Reqd | Dflt
61 type | Name of operand faOption | word | yes | -
62 area | Name of finite-area mesh | word | no | region0
63 region | Name of operand region | word | yes | -
64 <faOption>Coeffs | Dictionary containing settings of <!--
65 --> the selected faOption settings | dictionary | no | -
66 active | Flag to (de)activate faOption | bool | no | true
67 log | Flag to log faOption-related info | bool | no | true
68 suffixing | Suffix hint for option variables | word | no | -
69 \endtable
70
71Note
72 - Source/sink options are to be added to the right-hand side of equations.
73 - Suffixing (true|false|none|default|...) currently selects between
74 no suffix and ('_'+region).
75
76SourceFiles
77 faOption.cxx
78 faOptionIO.cxx
79
80\*---------------------------------------------------------------------------*/
81
82#ifndef Foam_fa_option_H
83#define Foam_fa_option_H
84
85#include "faMatricesFwd.H"
86#include "areaFieldsFwd.H"
87#include "dictionary.H"
88#include "fvMesh.H"
89#include "volSurfaceMapping.H"
91
92// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93
94namespace Foam
95{
96namespace fa
97{
98
99/*---------------------------------------------------------------------------*\
100 Class option Declaration
101\*---------------------------------------------------------------------------*/
102
103class option
104{
105 // Private Member Functions
106
107 //- Construct region mesh and fields
108 void constructMeshObjects();
109
110
111protected:
112
113 // Protected Data
114
115 //- Source name
116 const word name_;
117
118 //- Model type
119 const word modelType_;
120
121 //- Reference to the mesh database
122 const fvMesh& mesh_;
123
124 //- Top level source dictionary
126
127 //- Dictionary containing source coefficients
129
130 //- Field names to apply source to - populated by derived models
132
133 //- Applied flag list - corresponds to each fieldNames_ entry
134 List<bool> applied_;
135
136 //- The finite-area mesh name
137 word areaName_;
138
139 //- The model region name (finite-area)
140 word regionName_;
141
142 //- Suffix hint for variable names (default: "")
143 word suffixHint_;
144
145
146 // Protected Member Functions
147
148 //- Resize/reset applied flag list for all fieldNames_ entries
149 void resetApplied();
150
151
152private:
153
154 // Private Data
155
156 //- Demand-driven: pointer to region mesh database
157 mutable autoPtr<faMesh> regionMeshPtr_;
158
159 //- Demand-driven: volume-to-surface mapping
160 mutable autoPtr<volSurfaceMapping> vsmPtr_;
161
162 //- Source active flag
163 bool active_;
164
166public:
167
168 //- Switch write log to Info
169 bool log;
171
172 //- Runtime type information
173 TypeName("option");
174
176 // Declare run-time constructor selection table
177
179 (
181 option,
183 (
184 const word& name,
185 const word& modelType,
186 const dictionary& dict,
187 const fvMesh& mesh,
188 const word& areaName
189 ),
190 (name, modelType, dict, mesh, areaName)
191 );
192
193
194 // Constructors
196 //- Construct from components
197 option
198 (
199 const word& name,
200 const word& modelType,
201 const dictionary& dict,
202 const fvMesh& mesh,
204 const word& defaultAreaName = word()
205 );
206
207 //- Return clone
208 autoPtr<option> clone() const
209 {
211 return nullptr;
212 }
213
214 //- Return pointer to new faOption object created
215 //- on the freestore from an Istream
216 class iNew
217 {
218 //- Reference to the mesh
219 const fvMesh& mesh_;
220
221 //- The option name
222 const word& name_;
223
224 //- The default area name
225 const word& area_;
226
227 public:
228
229 iNew
230 (
231 const fvMesh& mesh,
232 const word& name,
233 const word& defaultAreaName
234 ) noexcept
235 :
236 mesh_(mesh),
237 name_(name),
238 area_(defaultAreaName)
239 {}
240
242 {
243 const dictionary dict(is);
244
248 );
249 }
250 };
251
253 // Selectors
254
255 //- Return a reference to the selected faOption model
256 static autoPtr<option> New
258 const word& name,
259 const dictionary& dict,
260 const fvMesh& mesh,
262 const word& defaultAreaName = word()
263 );
264
265
266 //- Destructor
267 virtual ~option() = default;
268
269
270 // Member Functions
271
272 //- Compare the region names.
273 // Treats empty or polyMesh::defaultRegion as always matching
274 static bool sameRegionNames(const word& name1, const word& name2);
275
276
277 // Access
279 //- The source name
280 const word& name() const noexcept { return name_; }
281
282 //- Return const access to the volume mesh
283 const fvMesh& mesh() const noexcept { return mesh_; }
284
285 //- Return dictionary
286 const dictionary& coeffs() const noexcept { return coeffs_; }
287
288 //- True if source is active
289 bool active() const noexcept { return active_; }
290
291 //- Set the applied flag to true for field index fieldi
292 inline void setApplied(const label fieldi);
293
294 //- The finite-area mesh name
295 const word& areaName() const noexcept { return areaName_; }
296
297 //- The model region name
298 const word& regionName() const noexcept { return regionName_; }
299
300 //- Return the region mesh database (demand-driven)
301 inline const faMesh& regionMesh() const;
302
303 //- Return volSurfaceMapping (demand-driven)
304 inline const volSurfaceMapping& vsm() const;
305
306
307 // Edit
308
309 //- Change source active flag, return previous value
310 inline bool active(bool on) noexcept;
311
312
313 // Helper Functions
314
315 //- The suffix hint when generating variable names
316 const word& suffixHint() const noexcept { return suffixHint_; }
317
318 //- Return the concatenation of \p base and the suffix hint
319 inline word suffixed(const char* base) const;
321 //- Return the concatenation of \p base and the suffix hint
322 inline word suffixed(const std::string& base) const;
323
324
325 // Checks
326
327 //- Is the source active?
328 virtual bool isActive();
329
330 //- Return index of field name if found in fieldNames list
331 virtual label applyToField(const word& fieldName) const;
333 //- Check that the source has been applied
334 virtual void checkApplied() const;
335
336
337 // Member Functions
338
339 // Evaluation
340
341 // Explicit and implicit sources
342
343 virtual void addSup
344 (
345 const areaScalarField& h,
346 faMatrix<scalar>& eqn,
347 const label fieldi
348 );
350 virtual void addSup
351 (
352 const areaScalarField& h,
353 faMatrix<vector>& eqn,
354 const label fieldi
355 );
356
357 virtual void addSup
358 (
359 const areaScalarField& h,
361 const label fieldi
362 );
363
364 virtual void addSup
365 (
366 const areaScalarField& h,
368 const label fieldi
369 );
370
371 virtual void addSup
373 const areaScalarField& h,
374 faMatrix<tensor>& eqn,
375 const label fieldi
376 );
377
378
379 // Explicit and implicit sources for compressible equations
381 virtual void addSup
382 (
383 const areaScalarField& h,
384 const areaScalarField& rho,
386 const label fieldi
387 );
388
389 virtual void addSup
391 const areaScalarField& h,
392 const areaScalarField& rho,
393 faMatrix<vector>& eqn,
394 const label fieldi
395 );
396
397 virtual void addSup
398 (
399 const areaScalarField& h,
400 const areaScalarField& rho,
402 const label fieldi
403 );
404
405 virtual void addSup
406 (
407 const areaScalarField& h,
408 const areaScalarField& rho,
410 const label fieldi
411 );
412
413 virtual void addSup
414 (
415 const areaScalarField& h,
416 const areaScalarField& rho,
417 faMatrix<tensor>& eqn,
418 const label fieldi
419 );
420
421
422 // Constraints
423
424 virtual void constrain
425 (
426 faMatrix<scalar>& eqn,
427 const label fieldi
428 );
429
430 virtual void constrain
431 (
432 faMatrix<vector>& eqn,
433 const label fieldi
434 );
435
436 virtual void constrain
437 (
439 const label fieldi
440 );
441
442 virtual void constrain
443 (
445 const label fieldi
446 );
447
448 virtual void constrain
449 (
450 faMatrix<tensor>& eqn,
451 const label fieldi
452 );
453
455 // Correction
456
457 virtual void correct(areaScalarField& field);
458 virtual void correct(areaVectorField& field);
460 virtual void correct(areaSymmTensorField& field);
461 virtual void correct(areaTensorField& field);
462
463
464 // IO
465
466 //- Write the source header information
467 virtual void writeHeader(Ostream&) const;
468
469 //- Write the source footer information
470 virtual void writeFooter(Ostream&) const;
471
472 //- Write the source properties
473 virtual void writeData(Ostream&) const;
474
475 //- Read source dictionary
476 virtual bool read(const dictionary& dict);
477};
478
479
480// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481
482} // End namespace fa
483} // End namespace Foam
484
485// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
486
487#include "faOptionI.H"
488
489// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
490
491#endif
492
493// ************************************************************************* //
Forwards and collection of common area field types.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A special matrix type and solver, designed for finite area solutions of scalar equations....
Definition faMatrix.H:108
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
autoPtr< option > operator()(Istream &is) const
Definition faOption.H:332
iNew(const fvMesh &mesh, const word &name, const word &defaultAreaName) noexcept
Definition faOption.H:321
Base abstract class for handling finite area options (i.e. faOption).
Definition faOption.H:149
virtual void addSup(const areaScalarField &h, faMatrix< tensor > &eqn, const label fieldi)
autoPtr< option > clone() const
Return clone.
Definition faOption.H:291
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
virtual void constrain(faMatrix< tensor > &eqn, const label fieldi)
const fvMesh & mesh() const noexcept
Return const access to the volume mesh.
Definition faOption.H:385
virtual bool read(const dictionary &dict)
Read source dictionary.
const word modelType_
Model type.
Definition faOption.H:170
word areaName_
The finite-area mesh name.
Definition faOption.H:200
virtual void addSup(const areaScalarField &h, faMatrix< sphericalTensor > &eqn, const label fieldi)
word suffixHint_
Suffix hint for variable names (default: "").
Definition faOption.H:210
virtual void checkApplied() const
Check that the source has been applied.
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition faOption.H:195
const fvMesh & mesh_
Reference to the mesh database.
Definition faOption.H:175
virtual void correct(areaTensorField &field)
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition faOptionI.H:31
word suffixed(const char *base) const
Return the concatenation of base and the suffix hint.
Definition faOptionI.H:58
virtual ~option()=default
Destructor.
word regionName_
The model region name (finite-area).
Definition faOption.H:205
TypeName("option")
Runtime type information.
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition faOption.H:190
virtual void correct(areaVectorField &field)
static bool sameRegionNames(const word &name1, const word &name2)
Compare the region names.
const word & areaName() const noexcept
The finite-area mesh name.
Definition faOption.H:405
dictionary dict_
Top level source dictionary.
Definition faOption.H:180
declareRunTimeSelectionTable(autoPtr, option, dictionary,(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &areaName),(name, modelType, dict, mesh, areaName))
virtual bool isActive()
Is the source active?
bool active() const noexcept
True if source is active.
Definition faOption.H:395
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Return a reference to the selected faOption model.
virtual void correct(areaScalarField &field)
dictionary coeffs_
Dictionary containing source coefficients.
Definition faOption.H:185
virtual void writeData(Ostream &) const
Write the source properties.
virtual void constrain(faMatrix< scalar > &eqn, const label fieldi)
const word & name() const noexcept
The source name.
Definition faOption.H:380
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< tensor > &eqn, const label fieldi)
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< scalar > &eqn, const label fieldi)
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< symmTensor > &eqn, const label fieldi)
virtual void constrain(faMatrix< vector > &eqn, const label fieldi)
virtual void addSup(const areaScalarField &h, faMatrix< vector > &eqn, const label fieldi)
const volSurfaceMapping & vsm() const
Return volSurfaceMapping (demand-driven).
Definition faOptionI.H:47
virtual void writeHeader(Ostream &) const
Write the source header information.
virtual void correct(areaSymmTensorField &field)
virtual void addSup(const areaScalarField &h, faMatrix< scalar > &eqn, const label fieldi)
virtual void constrain(faMatrix< sphericalTensor > &eqn, const label fieldi)
virtual void constrain(faMatrix< symmTensor > &eqn, const label fieldi)
const faMesh & regionMesh() const
Return the region mesh database (demand-driven).
Definition faOptionI.H:37
const word & suffixHint() const noexcept
The suffix hint when generating variable names.
Definition faOption.H:436
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< sphericalTensor > &eqn, const label fieldi)
virtual void addSup(const areaScalarField &h, faMatrix< symmTensor > &eqn, const label fieldi)
bool log
Switch write log to Info.
Definition faOption.H:246
const word & regionName() const noexcept
The model region name.
Definition faOption.H:410
virtual void writeFooter(Ostream &) const
Write the source footer information.
virtual void addSup(const areaScalarField &h, const areaScalarField &rho, faMatrix< vector > &eqn, const label fieldi)
virtual void correct(areaSphericalTensorField &field)
const dictionary & coeffs() const noexcept
Return dictionary.
Definition faOption.H:390
const word name_
Source name.
Definition faOption.H:165
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Volume to surface and surface to volume mapping.
A class for handling words, derived from Foam::string.
Definition word.H:66
thermo correct()
rDeltaTY field()
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
Forward declarations of standard faMatrix types/specializations.
Namespace for finite-area.
Definition limitHeight.C:30
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
GeometricField< tensor, faPatchField, areaMesh > areaTensorField
GeometricField< sphericalTensor, faPatchField, areaMesh > areaSphericalTensorField
GeometricField< symmTensor, faPatchField, areaMesh > areaSymmTensorField
GeometricField< vector, faPatchField, areaMesh > areaVectorField
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
const direction noexcept
Definition scalarImpl.H:265
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
volScalarField & h
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68