Loading...
Searching...
No Matches
fvOption.C
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-2021 OpenCFD Ltd.
10 Copyright (C) 2020,2023 PCOpt/NTUA
11 Copyright (C) 2020,2023 FOSS GP
12-------------------------------------------------------------------------------
13License
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\*---------------------------------------------------------------------------*/
30
31#include "fvOption.H"
32#include "volFields.H"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38 namespace fv
39 {
46// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47
49{
50 applied_.resize_nocopy(fieldNames_.size());
51 applied_ = false;
52}
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
58(
59 const word& name,
60 const word& modelType,
61 const dictionary& dict,
62 const fvMesh& mesh
63)
64:
65 name_(name),
66 modelType_(modelType),
67 mesh_(mesh),
68 dict_(dict),
69 coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
70 fieldNames_(),
71 applied_(),
72 active_(dict_.getOrDefault("active", true)),
73 log(true)
74{
76 << indent << "Source: " << name_ << endl
77 << indent << "State: " << (active_ ? "active" : "inactive") << endl
78 << decrIndent;
79}
80
81
82// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
83
85(
86 const word& name,
87 const dictionary& coeffs,
88 const fvMesh& mesh
89)
90{
91 const word modelType(coeffs.get<word>("type"));
92
93 Info<< indent
94 << "Selecting finite volume options type " << modelType << endl;
95
96 mesh.time().libs().open
97 (
98 coeffs,
99 "libs",
100 dictionaryConstructorTablePtr_
101 );
102
103 auto* ctorPtr = dictionaryConstructorTable(modelType);
104
105 if (!ctorPtr)
106 {
108 (
109 coeffs,
110 "fvOption",
111 modelType,
112 *dictionaryConstructorTablePtr_
113 ) << exit(FatalIOError);
114 }
116 return autoPtr<fv::option>(ctorPtr(name, modelType, coeffs, mesh));
117}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123{
124 return active_;
125}
126
128Foam::label Foam::fv::option::applyToField(const word& fieldName) const
129{
130 return fieldNames_.find(fieldName);
131}
132
133
135{
136 forAll(applied_, i)
137 {
138 if (!applied_[i])
139 {
141 << "Source " << name_ << " defined for field "
142 << fieldNames_[i] << " but never used" << endl;
143 }
144 }
145}
146
147
150 fvMatrix<scalar>& eqn,
151 const label fieldi
152)
153{}
154
155
158 fvMatrix<vector>& eqn,
159 const label fieldi
160)
161{}
162
163
167 const label fieldi
168)
169{}
170
171
175 const label fieldi
176)
177{}
178
179
182 fvMatrix<tensor>& eqn,
183 const label fieldi
184)
185{}
186
187
189(
191 fvMatrix<scalar>& eqn,
192 const label fieldi
193)
194{}
195
196
198(
200 fvMatrix<vector>& eqn,
201 const label fieldi
202)
203{}
204
205
207(
210 const label fieldi
211)
212{}
213
214
216(
219 const label fieldi
220)
221{}
222
223
225(
227 fvMatrix<tensor>& eqn,
228 const label fieldi
229)
230{}
231
232
234(
235 const volScalarField& alpha,
236 const volScalarField& rho,
237 fvMatrix<scalar>& eqn,
238 const label fieldi
239)
240{
241 addSup(alpha*rho, eqn, fieldi);
242}
243
244
246(
247 const volScalarField& alpha,
248 const volScalarField& rho,
249 fvMatrix<vector>& eqn,
250 const label fieldi
251)
252{
253 addSup(alpha*rho, eqn, fieldi);
254}
255
256
258(
259 const volScalarField& alpha,
260 const volScalarField& rho,
262 const label fieldi
263)
264{
265 addSup(alpha*rho, eqn, fieldi);
266}
267
268
270(
271 const volScalarField& alpha,
272 const volScalarField& rho,
274 const label fieldi
275)
276{
277 addSup(alpha*rho, eqn, fieldi);
278}
279
280
282(
283 const volScalarField& alpha,
284 const volScalarField& rho,
285 fvMatrix<tensor>& eqn,
286 const label fieldi
287)
288{
289 addSup(alpha*rho, eqn, fieldi);
291
292
293void Foam::fv::option::constrain(fvMatrix<scalar>& eqn, const label fieldi)
295
296
297void Foam::fv::option::constrain(fvMatrix<vector>& eqn, const label fieldi)
298{}
299
300
304 const label fieldi
305)
306{}
307
308
312 const label fieldi
313)
315
316
317void Foam::fv::option::constrain(fvMatrix<tensor>& eqn, const label fieldi)
319
320
322{}
323
324
326{}
327
328
331
332
335
336
339
340
342{}
343
344
347
348
350{}
351
352
354(
355 scalarField& sensField,
356 const word& fieldName,
357 const word& designVariablesName
358)
359{}
360
361
363(
364 vectorField& sensField,
365 const word& fieldName,
366 const word& designVariablesName
367)
368{}
369
370
372(
373 tensorField& sensField,
374 const word& fieldName,
375 const word& designVariablesName
376)
377{}
378
379
381(
382 const volScalarField& primalField,
383 const volScalarField& adjointField,
384 scalarField& sensField,
385 const word& fieldName
386)
387{}
388
389
391(
392 const volVectorField& primalField,
393 const volVectorField& adjointField,
394 scalarField& sensField,
395 const word& fieldName
396)
397{}
398
399
401(
402 const volTensorField& primalField,
403 const volTensorField& adjointField,
404 scalarField& sensField,
405 const word& fieldName
406)
407{}
408
409
410// ************************************************************************* //
#define Log
Definition PDRblock.C:28
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
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Base abstract class for handling finite volume options (i.e. fvOption).
Definition fvOption.H:124
const word modelType_
Model type.
Definition fvOption.H:137
bool active_
Source active flag.
Definition fvOption.H:167
const word & name() const noexcept
Return const access to the source name.
Definition fvOptionI.H:24
const dictionary & coeffs() const noexcept
Return dictionary.
Definition fvOptionI.H:36
List< bool > applied_
Applied flag list - corresponds to each fieldNames_ entry.
Definition fvOption.H:162
const fvMesh & mesh_
Reference to the mesh database.
Definition fvOption.H:142
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition fvOption.C:78
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition fvOption.H:157
virtual void checkApplied() const
Check that the source has been applied.
Definition fvOption.C:127
virtual void postProcessSens(scalarField &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Definition fvOption.C:347
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition fvOption.C:51
dictionary dict_
Top level source dictionary.
Definition fvOption.H:147
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition fvOption.C:121
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition fvOption.C:142
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition fvOption.C:286
virtual void postProcessAuxSens(const volScalarField &primalField, const volScalarField &adjointField, scalarField &sensField, const word &fieldName=word::null)
Definition fvOption.C:374
dictionary coeffs_
Dictionary containing source coefficients.
Definition fvOption.H:152
virtual bool isActive()
Is the source active?
Definition fvOption.C:115
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition fvOption.C:41
virtual void correct(volScalarField &field)
Definition fvOption.C:314
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition fvOptionI.H:30
bool log
Switch write log to Info.
Definition fvOption.H:183
const word name_
Source name.
Definition fvOption.H:132
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
rDeltaTY field()
dynamicFvMesh & mesh
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition error.H:637
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for finite-volume.
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
GeometricField< tensor, fvPatchField, volMesh > volTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
volScalarField & alpha
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299