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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
28 template<class Type>
30 (
32 )
33 {
34  return this->operator()(field, field.name());
35 }
36 
37 
38 template<class Type>
40 (
42  const word& fieldName
43 )
44 {
45  checkApplied();
46 
47  const dimensionSet ds = field.dimensions()/dimTime*dimVolume;
48 
49  tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
50  fvMatrix<Type>& mtx = tmtx();
51 
52  forAll(*this, i)
53  {
54  option& source = this->operator[](i);
55 
56  label fieldI = source.applyToField(fieldName);
57 
58  if (fieldI != -1)
59  {
60  source.setApplied(fieldI);
61 
62  if (source.isActive())
63  {
64  if (debug)
65  {
66  Info<< "Applying source " << source.name() << " to field "
67  << fieldName << endl;
68  }
69 
70  source.addSup(mtx, fieldI);
71  }
72  }
73  }
74 
75  return tmtx;
76 }
77 
78 
79 template<class Type>
81 (
82  const volScalarField& rho,
84 )
85 {
86  return this->operator()(rho, field, field.name());
87 }
88 
89 
90 template<class Type>
92 (
93  const volScalarField& rho,
95  const word& fieldName
96 )
97 {
98  checkApplied();
99 
100  const dimensionSet ds
101  (
102  rho.dimensions()*field.dimensions()/dimTime*dimVolume
103  );
104 
105  tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
106  fvMatrix<Type>& mtx = tmtx();
107 
108  forAll(*this, i)
109  {
110  option& source = this->operator[](i);
111 
112  label fieldI = source.applyToField(fieldName);
113 
114  if (fieldI != -1)
115  {
116  source.setApplied(fieldI);
117 
118  if (source.isActive())
119  {
120  if (debug)
121  {
122  Info<< "Applying source " << source.name() << " to field "
123  << fieldName << endl;
124  }
125 
126  source.addSup(rho, mtx, fieldI);
127  }
128  }
129  }
130 
131  return tmtx;
132 }
133 
134 
135 template<class Type>
137 (
138  const volScalarField& alpha,
139  const volScalarField& rho,
141 )
142 {
143  return this->operator()(alpha, rho, field, field.name());
144 }
145 
146 
147 template<class Type>
149 (
150  const volScalarField& alpha,
151  const volScalarField& rho,
153  const word& fieldName
154 )
155 {
156  checkApplied();
157 
158  const dimensionSet ds
159  (
160  alpha.dimensions()*rho.dimensions()*field.dimensions()
162  );
163 
164  tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
165  fvMatrix<Type>& mtx = tmtx();
166 
167  forAll(*this, i)
168  {
169  option& source = this->operator[](i);
170 
171  label fieldI = source.applyToField(fieldName);
172 
173  if (fieldI != -1)
174  {
175  source.setApplied(fieldI);
176 
177  if (source.isActive())
178  {
179  if (debug)
180  {
181  Info<< "Applying source " << source.name() << " to field "
182  << fieldName << endl;
183  }
184 
185  source.addSup(alpha, rho, mtx, fieldI);
186  }
187  }
188  }
189 
190  return tmtx;
191 }
192 
193 
194 template<class Type>
196 {
197  checkApplied();
198 
199  forAll(*this, i)
200  {
201  option& source = this->operator[](i);
202 
203  label fieldI = source.applyToField(eqn.psi().name());
204 
205  if (fieldI != -1)
206  {
207  source.setApplied(fieldI);
208 
209  if (source.isActive())
210  {
211  if (debug)
212  {
213  Info<< "Applying constraint " << source.name()
214  << " to field " << eqn.psi().name() << endl;
215  }
216 
217  source.constrain(eqn, fieldI);
218  }
219  }
220  }
221 }
222 
223 
224 template<class Type>
226 (
228 )
229 {
230  const word& fieldName = field.name();
231 
232  forAll(*this, i)
233  {
234  option& source = this->operator[](i);
235 
236  label fieldI = source.applyToField(fieldName);
237 
238  if (fieldI != -1)
239  {
240  source.setApplied(fieldI);
241 
242  if (source.isActive())
243  {
244  if (debug)
245  {
246  Info<< "Correcting source " << source.name()
247  << " for field " << fieldName << endl;
248  }
249 
250  source.correct(field);
251  }
252  }
253  }
254 }
255 
256 
257 // ************************************************************************* //
void correct(GeometricField< Type, fvPatchField, volMesh > &field)
Apply correction to field.
virtual bool isActive()
Is the source active?
Definition: fvOption.C:102
Finite volume options abtract base class. Provides a base set of controls, e.g.
Definition: fvOption.H:65
void setApplied(const label fieldI)
Set the applied flag to true for field index fieldI.
Definition: fvOptionI.H:52
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:28
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldI)
Definition: fvOption.C:273
A class for handling words, derived from string.
Definition: word.H:59
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:59
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:68
messageStream Info
friend Ostream & operator(Ostream &, const PtrList< option > &)
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldI)
Definition: fvOption.C:129
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Definition: fvMatrix.H:281
virtual void correct(volScalarField &field)
Definition: fvOption.C:301
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Dimension set for the base types.
Definition: dimensionSet.H:116
#define forAll(list, i)
Definition: UList.H:421
const dimensionSet & dimensions() const
Return dimensions.
const word & name() const
Return name.
Definition: IOobject.H:260
void constrain(fvMatrix< Type > &eqn)
Apply constraints to equation.
Generic GeometricField class.
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:108
A class for managing temporary objects.
Definition: PtrList.H:118
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:73
const option & operator[](const label) const
Return element const reference.