fvOptionListTemplates.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) 2016 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 \*---------------------------------------------------------------------------*/
30 
31 #include "profiling.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
39  const word& fieldName,
40  const dimensionSet& ds
41 )
42 {
43  checkApplied();
44 
45  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
46  fvMatrix<Type>& mtx = tmtx.ref();
47 
48  forAll(*this, i)
49  {
50  option& source = this->operator[](i);
51 
52  label fieldi = source.applyToField(fieldName);
53 
54  if (fieldi != -1)
55  {
56  addProfiling(fvopt, "fvOption()." + source.name());
57 
58  source.setApplied(fieldi);
59 
60  if (source.isActive())
61  {
62  if (debug)
63  {
64  Info<< "Applying source " << source.name() << " to field "
65  << fieldName << endl;
66  }
67 
68  source.addSup(mtx, fieldi);
69  }
70  }
71  }
72 
73  return tmtx;
74 }
75 
76 
77 template<class Type>
78 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
79 (
81 )
82 {
83  return this->operator()(field, field.name());
84 }
85 
86 
87 template<class Type>
88 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
89 (
91  const word& fieldName
92 )
93 {
94  return source(field, fieldName, field.dimensions()/dimTime*dimVolume);
95 }
96 
97 
98 template<class Type>
99 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
100 (
101  const volScalarField& rho,
103 )
104 {
105  return this->operator()(rho, field, field.name());
106 }
107 
108 
109 template<class Type>
110 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
111 (
112  const volScalarField& rho,
114  const word& fieldName
115 )
116 {
117  checkApplied();
118 
119  const dimensionSet ds
120  (
121  rho.dimensions()*field.dimensions()/dimTime*dimVolume
122  );
123 
124  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
125  fvMatrix<Type>& mtx = tmtx.ref();
126 
127  forAll(*this, i)
128  {
129  option& source = this->operator[](i);
130 
131  label fieldi = source.applyToField(fieldName);
132 
133  if (fieldi != -1)
134  {
135  addProfiling(fvopt, "fvOption()." + source.name());
136 
137  source.setApplied(fieldi);
138 
139  if (source.isActive())
140  {
141  if (debug)
142  {
143  Info<< "Applying source " << source.name() << " to field "
144  << fieldName << endl;
145  }
146 
147  source.addSup(rho, mtx, fieldi);
148  }
149  }
150  }
151 
152  return tmtx;
153 }
154 
155 
156 template<class Type>
157 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
158 (
159  const volScalarField& alpha,
160  const volScalarField& rho,
162 )
163 {
164  return this->operator()(alpha, rho, field, field.name());
165 }
166 
167 
168 template<class Type>
169 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
170 (
171  const volScalarField& alpha,
172  const volScalarField& rho,
174  const word& fieldName
175 )
176 {
177  checkApplied();
178 
179  const dimensionSet ds
180  (
181  alpha.dimensions()*rho.dimensions()*field.dimensions()
183  );
184 
185  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
186  fvMatrix<Type>& mtx = tmtx.ref();
187 
188  forAll(*this, i)
189  {
190  option& source = this->operator[](i);
191 
192  label fieldi = source.applyToField(fieldName);
193 
194  if (fieldi != -1)
195  {
196  addProfiling(fvopt, "fvOption()." + source.name());
197 
198  source.setApplied(fieldi);
199 
200  if (source.isActive())
201  {
202  if (debug)
203  {
204  Info<< "Applying source " << source.name() << " to field "
205  << fieldName << endl;
206  }
207 
208  source.addSup(alpha, rho, mtx, fieldi);
209  }
210  }
211  }
212 
213  return tmtx;
214 }
215 
216 
217 template<class Type>
218 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
219 (
220  const geometricOneField& alpha,
221  const geometricOneField& rho,
223 )
224 {
225  return this->operator()(field, field.name());
226 }
227 
228 
229 template<class Type>
230 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
231 (
232  const volScalarField& alpha,
233  const geometricOneField& rho,
235 )
236 {
238  (
239  IOobject
240  (
241  "one",
242  this->mesh_.time().timeName(),
243  this->mesh_,
244  IOobject::NO_READ,
245  IOobject::NO_WRITE,
246  false
247  ),
248  this->mesh_,
249  dimensionedScalar("one", dimless, 1.0)
250  );
251 
252  return this->operator()(alpha, one, field, field.name());
253 }
254 
255 
256 template<class Type>
257 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
258 (
259  const geometricOneField& alpha,
260  const volScalarField& rho,
262 )
263 {
264  return this->operator()(rho, field, field.name());
265 }
266 
267 
268 template<class Type>
270 (
272 )
273 {
274  return this->d2dt2(field, field.name());
275 }
276 
277 
278 template<class Type>
280 (
282  const word& fieldName
283 )
284 {
285  return source(field, fieldName, field.dimensions()/sqr(dimTime)*dimVolume);
286 }
287 
288 
289 template<class Type>
291 {
292  checkApplied();
293 
294  forAll(*this, i)
295  {
296  option& source = this->operator[](i);
297 
298  label fieldi = source.applyToField(eqn.psi().name());
299 
300  if (fieldi != -1)
301  {
302  addProfiling(fvopt, "fvOption::constrain." + eqn.psi().name());
303 
304  source.setApplied(fieldi);
305 
306  if (source.isActive())
307  {
308  if (debug)
309  {
310  Info<< "Applying constraint " << source.name()
311  << " to field " << eqn.psi().name() << endl;
312  }
313 
314  source.constrain(eqn, fieldi);
315  }
316  }
317  }
318 }
319 
320 
321 template<class Type>
323 (
325 )
326 {
327  const word& fieldName = field.name();
328 
329  forAll(*this, i)
330  {
331  option& source = this->operator[](i);
332 
333  label fieldi = source.applyToField(fieldName);
334 
335  if (fieldi != -1)
336  {
337  addProfiling(fvopt, "fvOption::correct." + source.name());
338 
339  source.setApplied(fieldi);
340 
341  if (source.isActive())
342  {
343  if (debug)
344  {
345  Info<< "Correcting source " << source.name()
346  << " for field " << fieldName << endl;
347  }
348 
349  source.correct(field);
350  }
351  }
352  }
353 }
354 
355 
356 template<class Type>
358 (
359  Field<Type>& sensField,
360  const word& fieldName,
361  const word& designVariablesName
362 )
363 {
364  forAll(*this, i)
365  {
366  option& source = this->operator[](i);
367 
368  label fieldi = source.applyToField(fieldName);
369 
370  if (fieldi != -1)
371  {
372  addProfiling(fvopt, "fvOption::postProcessSens." + source.name());
373 
374  if (source.isActive())
375  {
376  if (debug)
377  {
378  Info<< "Post processing sensitivity from source "
379  << source.name()
380  << " for field " << fieldName << endl;
381  }
382 
383  source.postProcessSens
384  (
385  sensField,
386  fieldName,
387  designVariablesName
388  );
389  }
390  }
391  }
392 }
393 
394 
395 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fv::option::correct
virtual void correct(volScalarField &field)
Definition: fvOption.C:309
profiling.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::fac::d2dt2
tmp< GeometricField< Type, faPatchField, areaMesh > > d2dt2(const dimensioned< Type > dt, const faMesh &mesh)
Definition: facD2dt2.C:46
Foam::fv::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: fvOptionI.H:54
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fa::option::name
const word & name() const
Return const access to the source name.
Definition: faOptionI.H:30
Foam::fv::optionList::correct
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
Definition: fvOptionListTemplates.C:323
Foam::fa::option::setApplied
void setApplied(const label fieldi)
Set the applied flag to true for field index fieldi.
Definition: faOptionI.H:60
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fa::option::addSup
virtual void addSup(const areaScalarField &h, faMatrix< scalar > &eqn, const label fieldi)
Definition: faOption.C:149
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:30
Foam::fv::optionList::constrain
void constrain(fvMatrix< Type > &eqn)
Apply constraints to equation.
Definition: fvOptionListTemplates.C:290
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::geometricOneField
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
Definition: geometricOneField.H:55
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:65
Foam::fv::optionList::d2dt2
tmp< fvMatrix< Type > > d2dt2(GeometricField< Type, fvPatchField, volMesh > &field)
Return source for equation with second time derivative.
rho
rho
Definition: readInitialConditions.H:88
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:287
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fa::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:128
Foam::fv::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:116
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fv::optionList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:75
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
field
rDeltaTY field()
addProfiling
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
Definition: profilingTrigger.H:113
Foam::fv::optionList::postProcessSens
void postProcessSens(Field< Type > &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Post process sensitivity field related to the fvOption.
Definition: fvOptionListTemplates.C:358
Foam::fv::option::postProcessSens
virtual void postProcessSens(scalarField &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Definition: fvOption.C:330
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:110
Foam::fa::option::isActive
virtual bool isActive()
Is the source active?
Definition: faOption.C:122
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:134
Foam::fv::optionList::source
tmp< fvMatrix< Type > > source(GeometricField< Type, fvPatchField, volMesh > &field, const word &fieldName, const dimensionSet &ds)
Return source for equation with specified name and dimensions.
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::dimensioned::dimensions
const dimensionSet & dimensions() const
Return const reference to dimensions.
Definition: dimensionedType.C:420
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:61
Foam::GeometricField< Type, fvPatchField, volMesh >