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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
30 
31 #include "fvOption.H"
32 #include "volFields.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  namespace fv
39  {
40  defineTypeNameAndDebug(option, 0);
42  }
43 }
44 
45 
46 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47 
49 {
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 {
75  Log << incrIndent
76  << indent << "Source: " << name_ << endl
77  << indent << "State: " << (active_ ? "active" : "inactive") << endl
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 
128 Foam::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 
149 (
151  const label fieldi
152 )
153 {}
154 
155 
157 (
159  const label fieldi
160 )
161 {}
162 
163 
165 (
167  const label fieldi
168 )
169 {}
170 
171 
173 (
175  const label fieldi
176 )
177 {}
178 
179 
181 (
183  const label fieldi
184 )
185 {}
186 
187 
189 (
190  const volScalarField& rho,
192  const label fieldi
193 )
194 {}
195 
196 
198 (
199  const volScalarField& rho,
201  const label fieldi
202 )
203 {}
204 
205 
207 (
208  const volScalarField& rho,
210  const label fieldi
211 )
212 {}
213 
214 
216 (
217  const volScalarField& rho,
219  const label fieldi
220 )
221 {}
222 
223 
225 (
226  const volScalarField& rho,
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);
290 }
291 
292 
293 void Foam::fv::option::constrain(fvMatrix<scalar>& eqn, const label fieldi)
294 {}
296 
297 void Foam::fv::option::constrain(fvMatrix<vector>& eqn, const label fieldi)
298 {}
299 
300 
302 (
304  const label fieldi
305 )
306 {}
307 
308 
310 (
312  const label fieldi
313 )
314 {}
315 
316 
317 void Foam::fv::option::constrain(fvMatrix<tensor>& eqn, const label fieldi)
318 {}
319 
320 
322 {}
323 
324 
326 {}
327 
328 
330 {}
331 
332 
334 {}
335 
336 
338 {}
339 
340 
342 {}
343 
344 
346 {}
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 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
virtual void correct(volScalarField &field)
Definition: fvOption.C:314
rDeltaTY field()
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:491
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:157
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
virtual void postProcessAuxSens(const volScalarField &primalField, const volScalarField &adjointField, scalarField &sensField, const word &fieldName=word::null)
Definition: fvOption.C:374
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:168
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.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
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
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:142
const word name_
Source name.
Definition: fvOption.H:132
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList fv(nPoints)
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:127
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 void postProcessSens(scalarField &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Definition: fvOption.C:347
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:509
defineRunTimeSelectionTable(option, dictionary)
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:286
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
#define Log
Definition: PDRblock.C:28
messageStream Info
Information stream (stdout output on master, null elsewhere)
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:115
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:121
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:500
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:637
bool active_
Source active flag.
Definition: fvOption.H:167
Namespace for OpenFOAM.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:123
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...