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 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "profiling.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
37  const word& fieldName,
38  const dimensionSet& ds
39 )
40 {
41  checkApplied();
42 
43  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
44  fvMatrix<Type>& mtx = tmtx.ref();
45 
46  forAll(*this, i)
47  {
48  option& source = this->operator[](i);
49 
50  label fieldi = source.applyToField(fieldName);
51 
52  if (fieldi != -1)
53  {
54  addProfiling(fvopt, "fvOption()." + source.name());
55 
56  source.setApplied(fieldi);
57 
58  if (source.isActive())
59  {
60  if (debug)
61  {
62  Info<< "Applying source " << source.name() << " to field "
63  << fieldName << endl;
64  }
65 
66  source.addSup(mtx, fieldi);
67  }
68  }
69  }
70 
71  return tmtx;
72 }
73 
74 
75 template<class Type>
76 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
77 (
79 )
80 {
81  return this->operator()(field, field.name());
82 }
83 
84 
85 template<class Type>
86 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
87 (
89  const word& fieldName
90 )
91 {
92  return source(field, fieldName, field.dimensions()/dimTime*dimVolume);
93 }
94 
95 
96 template<class Type>
97 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
98 (
99  const volScalarField& rho,
101 )
102 {
103  return this->operator()(rho, field, field.name());
104 }
105 
106 
107 template<class Type>
108 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
109 (
110  const volScalarField& rho,
112  const word& fieldName
113 )
114 {
115  checkApplied();
116 
117  const dimensionSet ds
118  (
119  rho.dimensions()*field.dimensions()/dimTime*dimVolume
120  );
121 
122  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
123  fvMatrix<Type>& mtx = tmtx.ref();
124 
125  forAll(*this, i)
126  {
127  option& source = this->operator[](i);
128 
129  label fieldi = source.applyToField(fieldName);
130 
131  if (fieldi != -1)
132  {
133  addProfiling(fvopt, "fvOption()." + source.name());
134 
135  source.setApplied(fieldi);
136 
137  if (source.isActive())
138  {
139  if (debug)
140  {
141  Info<< "Applying source " << source.name() << " to field "
142  << fieldName << endl;
143  }
144 
145  source.addSup(rho, mtx, fieldi);
146  }
147  }
148  }
149 
150  return tmtx;
151 }
152 
153 
154 template<class Type>
155 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
156 (
157  const volScalarField& alpha,
158  const volScalarField& rho,
160 )
161 {
162  return this->operator()(alpha, rho, field, field.name());
163 }
164 
165 
166 template<class Type>
167 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
168 (
169  const volScalarField& alpha,
170  const volScalarField& rho,
172  const word& fieldName
173 )
174 {
175  checkApplied();
176 
177  const dimensionSet ds
178  (
179  alpha.dimensions()*rho.dimensions()*field.dimensions()
181  );
182 
183  tmp<fvMatrix<Type>> tmtx(new fvMatrix<Type>(field, ds));
184  fvMatrix<Type>& mtx = tmtx.ref();
185 
186  forAll(*this, i)
187  {
188  option& source = this->operator[](i);
189 
190  label fieldi = source.applyToField(fieldName);
191 
192  if (fieldi != -1)
193  {
194  addProfiling(fvopt, "fvOption()." + source.name());
195 
196  source.setApplied(fieldi);
197 
198  if (source.isActive())
199  {
200  if (debug)
201  {
202  Info<< "Applying source " << source.name() << " to field "
203  << fieldName << endl;
204  }
205 
206  source.addSup(alpha, rho, mtx, fieldi);
207  }
208  }
209  }
210 
211  return tmtx;
212 }
213 
214 
215 template<class Type>
216 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
217 (
218  const geometricOneField& alpha,
219  const geometricOneField& rho,
221 )
222 {
223  return this->operator()(field, field.name());
224 }
225 
226 
227 template<class Type>
228 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
229 (
230  const volScalarField& alpha,
231  const geometricOneField& rho,
233 )
234 {
236  (
237  IOobject
238  (
239  "one",
240  this->mesh_.time().timeName(),
241  this->mesh_,
242  IOobject::NO_READ,
243  IOobject::NO_WRITE,
244  false
245  ),
246  this->mesh_,
247  dimensionedScalar("one", dimless, 1.0)
248  );
249 
250  return this->operator()(alpha, one, field, field.name());
251 }
252 
253 
254 template<class Type>
255 Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
256 (
257  const geometricOneField& alpha,
258  const volScalarField& rho,
260 )
261 {
262  return this->operator()(rho, field, field.name());
263 }
264 
265 
266 template<class Type>
268 (
270 )
271 {
272  return this->d2dt2(field, field.name());
273 }
274 
275 
276 template<class Type>
278 (
280  const word& fieldName
281 )
282 {
283  return source(field, fieldName, field.dimensions()/sqr(dimTime)*dimVolume);
284 }
285 
286 
287 template<class Type>
289 {
290  checkApplied();
291 
292  forAll(*this, i)
293  {
294  option& source = this->operator[](i);
295 
296  label fieldi = source.applyToField(eqn.psi().name());
297 
298  if (fieldi != -1)
299  {
300  addProfiling(fvopt, "fvOption::constrain." + eqn.psi().name());
301 
302  source.setApplied(fieldi);
303 
304  if (source.isActive())
305  {
306  if (debug)
307  {
308  Info<< "Applying constraint " << source.name()
309  << " to field " << eqn.psi().name() << endl;
310  }
311 
312  source.constrain(eqn, fieldi);
313  }
314  }
315  }
316 }
317 
318 
319 template<class Type>
321 (
323 )
324 {
325  const word& fieldName = field.name();
326 
327  forAll(*this, i)
328  {
329  option& source = this->operator[](i);
330 
331  label fieldi = source.applyToField(fieldName);
332 
333  if (fieldi != -1)
334  {
335  addProfiling(fvopt, "fvOption::correct." + source.name());
336 
337  source.setApplied(fieldi);
338 
339  if (source.isActive())
340  {
341  if (debug)
342  {
343  Info<< "Correcting source " << source.name()
344  << " for field " << fieldName << endl;
345  }
346 
347  source.correct(field);
348  }
349  }
350  }
351 }
352 
353 
354 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fv::option::correct
virtual void correct(volScalarField &field)
Definition: fvOption.C:307
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::fv::optionList::correct
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
Definition: fvOptionListTemplates.C:321
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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:288
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:54
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:96
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:285
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::fv::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:114
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::fv::option::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Definition: fvOption.C:135
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::fv::option
Finite volume options abstract base class. Provides a base set of controls, e.g.:
Definition: fvOption.H:69
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:114
Foam::fv::option::isActive
virtual bool isActive()
Is the source active?
Definition: fvOption.C:108
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
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:390
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:61
Foam::GeometricField< Type, fvPatchField, volMesh >