faOptionListTemplates.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) 2019-2020 OpenCFD Ltd.
9 ------------------------------------------------------------------------------
10 License
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 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "profiling.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
36  const areaScalarField& h,
37  const word& fieldName,
38  const dimensionSet& ds
39 )
40 {
41  checkApplied();
42 
43  tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, ds));
44  faMatrix<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(faopt, "faOption()." + 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(h, mtx, fieldi);
67  }
68  }
69  }
70 
71  return tmtx;
72 }
73 
74 
75 template<class Type>
76 Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
77 (
78  const areaScalarField& h,
80 )
81 {
82  return this->operator()(h, field, field.name());
83 }
84 
85 
86 template<class Type>
87 Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
88 (
89  const areaScalarField& h,
91  const word& fieldName
92 )
93 {
94  return source(field, h, fieldName, field.dimensions()/dimTime*dimArea);
95 }
96 
97 
98 template<class Type>
99 Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
100 (
101  const areaScalarField& h,
102  const areaScalarField& rho,
104 )
105 {
106  return this->operator()(h, rho, field, field.name());
107 }
108 
109 
110 template<class Type>
111 Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
112 (
113  const areaScalarField& h,
114  const areaScalarField& rho,
116  const word& fieldName
117 )
118 {
119  checkApplied();
120 
121  const dimensionSet ds
122  (
123  rho.dimensions()*field.dimensions()/dimTime*dimArea
124  );
125 
126  tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, ds));
127  faMatrix<Type>& mtx = tmtx.ref();
128 
129  forAll(*this, i)
130  {
131  option& source = this->operator[](i);
132 
133  label fieldi = source.applyToField(fieldName);
134 
135  if (fieldi != -1)
136  {
137  addProfiling(faopt, "faOption()." + source.name());
138 
139  source.setApplied(fieldi);
140 
141  if (source.isActive())
142  {
143  if (debug)
144  {
145  Info<< "Applying source " << source.name() << " to field "
146  << fieldName << endl;
147  }
148 
149  source.addSup(h, rho, mtx, fieldi);
150  }
151  }
152  }
153 
154  return tmtx;
155 }
156 
157 
158 template<class Type>
159 Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
160 (
161  const areaScalarField& rho,
163  const dimensionSet& ds
164 )
165 {
166  checkApplied();
167 
168  const dimensionSet dsMat(ds*dimArea);
169 
170  tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, dsMat));
171  faMatrix<Type>& mtx = tmtx.ref();
172 
173  forAll(*this, i)
174  {
175  option& source = this->operator[](i);
176 
177  label fieldi = source.applyToField(field.name());
178 
179  if (fieldi != -1)
180  {
181  addProfiling(faopt, "faOption()." + source.name());
182 
183  source.setApplied(fieldi);
184 
185  if (source.isActive())
186  {
187  if (debug)
188  {
189  Info<< "Applying source " << source.name() << " to field "
190  << field.name() << endl;
191  }
192 
193  source.addSup(rho, mtx, fieldi);
194  }
195  }
196  }
197 
198  return tmtx;
199 }
200 
201 
202 template<class Type>
204 (
206 )
207 {
208  return this->d2dt2(field, field.name());
209 }
210 
211 
212 template<class Type>
214 (
216  const word& fieldName
217 )
218 {
219  return source(field, fieldName, field.dimensions()/sqr(dimTime)*dimArea);
220 }
221 
222 
223 template<class Type>
225 {
226  checkApplied();
227 
228  forAll(*this, i)
229  {
230  option& source = this->operator[](i);
231 
232  label fieldi = source.applyToField(eqn.psi().name());
233 
234  if (fieldi != -1)
235  {
236  addProfiling(faopt, "faOption::constrain." + eqn.psi().name());
237 
238  source.setApplied(fieldi);
239 
240  if (source.isActive())
241  {
242  if (debug)
243  {
244  Info<< "Applying constraint " << source.name()
245  << " to field " << eqn.psi().name() << endl;
246  }
247 
248  source.constrain(eqn, fieldi);
249  }
250  }
251  }
252 }
253 
254 
255 template<class Type>
257 (
259 )
260 {
261  const word& fieldName = field.name();
262 
263  forAll(*this, i)
264  {
265  option& source = this->operator[](i);
266 
267  label fieldi = source.applyToField(fieldName);
268 
269  if (fieldi != -1)
270  {
271  addProfiling(faopt, "faOption::correct." + source.name());
272 
273  source.setApplied(fieldi);
274 
275  if (source.isActive())
276  {
277  if (debug)
278  {
279  Info<< "Correcting source " << source.name()
280  << " for field " << fieldName << endl;
281  }
282 
283  source.correct(field);
284  }
285  }
286  }
287 }
288 
289 
290 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
profiling.H
Foam::fa::optionList::source
tmp< faMatrix< Type > > source(GeometricField< Type, faPatchField, areaMesh > &field, const areaScalarField &h, const word &fieldName, const dimensionSet &ds)
Return source for equation with specified name and dimensions.
Foam::faMatrix
A special matrix type and solver, designed for finite area solutions of scalar equations....
Definition: faMatrix.H:59
Foam::fac::d2dt2
tmp< GeometricField< Type, faPatchField, areaMesh > > d2dt2(const dimensioned< Type > dt, const faMesh &mesh)
Definition: facD2dt2.C:46
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::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::fa::optionList::d2dt2
tmp< faMatrix< Type > > d2dt2(GeometricField< Type, faPatchField, areaMesh > &field)
Return source for equation with second time derivative.
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
rho
rho
Definition: readInitialConditions.H:88
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::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::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:60
Foam::constant::universal::h
const dimensionedScalar h
Planck constant.
Definition: setRegionSolidFields.H:33
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fa::optionList::constrain
void constrain(faMatrix< Type > &eqn)
Apply constraints to equation.
Definition: faOptionListTemplates.C:224
field
rDeltaTY field()
addProfiling
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
Definition: profilingTrigger.H:113
Foam::fa::option::isActive
virtual bool isActive()
Is the source active?
Definition: faOption.C:122
Foam::fa::option::correct
virtual void correct(areaScalarField &field)
Definition: faOption.C:271
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::faMatrix::psi
const GeometricField< Type, faPatchField, areaMesh > & psi() const
Definition: faMatrix.H:239
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:134
Foam::fa::optionList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: faOptionList.C:74
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::fa::optionList::correct
void correct(GeometricField< Type, faPatchField, areaMesh > &field)
Apply correction to field.
Definition: faOptionListTemplates.C:257