fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / fields / DimensionedFields / DimensionedScalarField / DimensionedScalarField.C
blobf48dce90fd5ba9db1a5e1bb57099602638b93f78
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "DimensionedScalarField.H"
29 #define TEMPLATE template<class GeoMesh>
30 #include "DimensionedFieldFunctionsM.C"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 template<class GeoMesh>
40 tmp<DimensionedField<scalar, GeoMesh> > stabilise
42     const DimensionedField<scalar, GeoMesh>& dsf,
43     const dimensioned<scalar>& ds
46     tmp<DimensionedField<scalar, GeoMesh> > tRes
47     (
48         new DimensionedField<scalar, GeoMesh>
49         (
50             IOobject
51             (
52                 "stabilise(" + dsf.name() + ',' + ds.name() + ')',
53                 dsf.instance(),
54                 dsf.db()
55             ),
56             dsf.mesh(),
57             dsf.dimensions() + ds.dimensions()
58         )
59     );
61     stabilise(tRes().field(), dsf.field(), ds.value());
63     return tRes;
67 template<class GeoMesh>
68 tmp<DimensionedField<scalar, GeoMesh> > stabilise
70     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
71     const dimensioned<scalar>& ds
74     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
76     tmp<DimensionedField<scalar, GeoMesh> > tRes =
77         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
78         (
79             tdsf,
80             "stabilise(" + dsf.name() + ',' + ds.name() + ')',
81             dsf.dimensions() + ds.dimensions()
82         );
84     stabilise(tRes().field(), dsf.field(), ds.value());
86     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
88     return tRes;
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, '+', add)
95 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, '-', subtract)
97 BINARY_OPERATOR(scalar, scalar, scalar, *, '*', multiply)
98 BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide)
100 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide)
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 template<class GeoMesh>
105 tmp<DimensionedField<scalar, GeoMesh> > pow
107     const DimensionedField<scalar, GeoMesh>& dsf1,
108     const DimensionedField<scalar, GeoMesh>& dsf2
111     tmp<DimensionedField<scalar, GeoMesh> > tPow
112     (
113         new DimensionedField<scalar, GeoMesh>
114         (
115             IOobject
116             (
117                 "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
118                 dsf1.instance(),
119                 dsf1.db()
120             ),
121             dsf1.mesh(),
122             pow
123             (
124                 dsf1.dimensions(),
125                 dimensionedScalar("1", 1.0, dsf2.dimensions())
126             )
127         )
128     );
130     pow(tPow().field(), dsf1.field(), dsf2.field());
132     return tPow;
136 template<class GeoMesh>
137 tmp<DimensionedField<scalar, GeoMesh> > pow
139     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
140     const DimensionedField<scalar, GeoMesh>& dsf2
143     const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
145     tmp<DimensionedField<scalar, GeoMesh> > tPow =
146         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
147         (
148             tdsf1,
149             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
150             pow
151             (
152                 dsf1.dimensions(),
153                 dimensionedScalar("1", 1.0, dsf2.dimensions())
154             )
155         );
157     pow(tPow().field(), dsf1.field(), dsf2.field());
159     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf1);
161     return tPow;
165 template<class GeoMesh>
166 tmp<DimensionedField<scalar, GeoMesh> > pow
168     const DimensionedField<scalar, GeoMesh>& dsf1,
169     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf2
172     const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
174     tmp<DimensionedField<scalar, GeoMesh> > tPow =
175         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
176         (
177             tdsf2,
178             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
179             pow
180             (
181                 dsf1.dimensions(),
182                 dimensionedScalar("1", 1.0, dsf2.dimensions())
183             )
184         );
186     pow(tPow().field(), dsf1.field(), dsf2.field());
188     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf2);
190     return tPow;
193 template<class GeoMesh>
194 tmp<DimensionedField<scalar, GeoMesh> > pow
196     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
197     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf2
200     const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
201     const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
203     tmp<DimensionedField<scalar, GeoMesh> > tPow =
204         reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::
205         New
206         (
207             tdsf1,
208             tdsf2,
209             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
210             pow
211             (
212                 dsf1.dimensions(),
213                 dimensionedScalar("1", 1.0, dsf2.dimensions())
214             )
215         );
217     pow(tPow().field(), dsf1.field(), dsf2.field());
219     reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::clear
220     (
221         tdsf1,
222         tdsf2
223     );
225     return tPow;
229 template<class GeoMesh>
230 tmp<DimensionedField<scalar, GeoMesh> > pow
232     const DimensionedField<scalar, GeoMesh>& dsf,
233     const dimensionedScalar& ds
236     tmp<DimensionedField<scalar, GeoMesh> > tPow
237     (
238         new DimensionedField<scalar, GeoMesh>
239         (
240             IOobject
241             (
242                 "pow(" + dsf.name() + ',' + ds.name() + ')',
243                 dsf.instance(),
244                 dsf.db()
245             ),
246             dsf.mesh(),
247             pow(dsf.dimensions(), ds)
248         )
249     );
251     pow(tPow().field(), dsf.field(), ds.value());
253     return tPow;
256 template<class GeoMesh>
257 tmp<DimensionedField<scalar, GeoMesh> > pow
259     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
260     const dimensionedScalar& ds
263     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
265     tmp<DimensionedField<scalar, GeoMesh> > tPow =
266         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
267         (
268             tdsf,
269             "pow(" + dsf.name() + ',' + ds.name() + ')',
270             pow(dsf.dimensions(), ds)
271         );
273     pow(tPow().field(), dsf.field(), ds.value());
275     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
277     return tPow;
280 template<class GeoMesh>
281 tmp<DimensionedField<scalar, GeoMesh> > pow
283     const DimensionedField<scalar, GeoMesh>& dsf,
284     const scalar& s
287     return pow(dsf, dimensionedScalar(s));
290 template<class GeoMesh>
291 tmp<DimensionedField<scalar, GeoMesh> > pow
293     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
294     const scalar& s
297     return pow(tdsf, dimensionedScalar(s));
301 template<class GeoMesh>
302 tmp<DimensionedField<scalar, GeoMesh> > pow
304     const dimensionedScalar& ds,
305     const DimensionedField<scalar, GeoMesh>& dsf
308     tmp<DimensionedField<scalar, GeoMesh> > tPow
309     (
310         new DimensionedField<scalar, GeoMesh>
311         (
312             IOobject
313             (
314                 "pow(" + ds.name() + ',' + dsf.name() + ')',
315                 dsf.instance(),
316                 dsf.db()
317             ),
318             dsf.mesh(),
319             pow(ds, dsf.dimensions())
320         )
321     );
323     pow(tPow().field(), ds.value(), dsf.field());
325     return tPow;
329 template<class GeoMesh>
330 tmp<DimensionedField<scalar, GeoMesh> > pow
332     const dimensionedScalar& ds,
333     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf
336     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
338     tmp<DimensionedField<scalar, GeoMesh> > tPow =
339         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
340         (
341             tdsf,
342             "pow(" + ds.name() + ',' + dsf.name() + ')',
343             pow(ds, dsf.dimensions())
344         );
346     pow(tPow().field(), ds.value(), dsf.field());
348     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
350     return tPow;
353 template<class GeoMesh>
354 tmp<DimensionedField<scalar, GeoMesh> > pow
356     const scalar& s,
357     const DimensionedField<scalar, GeoMesh>& dsf
360     return pow(dimensionedScalar(s), dsf);
363 template<class GeoMesh>
364 tmp<DimensionedField<scalar, GeoMesh> > pow
366     const scalar& s,
367     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf
370     return pow(dimensionedScalar(s), tdsf);
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 UNARY_FUNCTION(scalar, scalar, pow3, pow3)
376 UNARY_FUNCTION(scalar, scalar, pow4, pow4)
377 UNARY_FUNCTION(scalar, scalar, pow5, pow5)
378 UNARY_FUNCTION(scalar, scalar, pow6, pow6)
379 UNARY_FUNCTION(scalar, scalar, sqrt, sqrt)
380 UNARY_FUNCTION(scalar, scalar, sign, sign)
381 UNARY_FUNCTION(scalar, scalar, pos, pos)
382 UNARY_FUNCTION(scalar, scalar, neg, neg)
384 UNARY_FUNCTION(scalar, scalar, exp, trans)
385 UNARY_FUNCTION(scalar, scalar, log, trans)
386 UNARY_FUNCTION(scalar, scalar, log10, trans)
387 UNARY_FUNCTION(scalar, scalar, sin, trans)
388 UNARY_FUNCTION(scalar, scalar, cos, trans)
389 UNARY_FUNCTION(scalar, scalar, tan, trans)
390 UNARY_FUNCTION(scalar, scalar, asin, trans)
391 UNARY_FUNCTION(scalar, scalar, acos, trans)
392 UNARY_FUNCTION(scalar, scalar, atan, trans)
393 UNARY_FUNCTION(scalar, scalar, sinh, trans)
394 UNARY_FUNCTION(scalar, scalar, cosh, trans)
395 UNARY_FUNCTION(scalar, scalar, tanh, trans)
396 UNARY_FUNCTION(scalar, scalar, asinh, trans)
397 UNARY_FUNCTION(scalar, scalar, acosh, trans)
398 UNARY_FUNCTION(scalar, scalar, atanh, trans)
399 UNARY_FUNCTION(scalar, scalar, erf, trans)
400 UNARY_FUNCTION(scalar, scalar, erfc, trans)
401 UNARY_FUNCTION(scalar, scalar, lgamma, trans)
402 UNARY_FUNCTION(scalar, scalar, j0, trans)
403 UNARY_FUNCTION(scalar, scalar, j1, trans)
404 UNARY_FUNCTION(scalar, scalar, y0, trans)
405 UNARY_FUNCTION(scalar, scalar, y1, trans)
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 #define BesselFunc(func)                                                    \
411                                                                             \
412 template<class GeoMesh>                                                     \
413 tmp<DimensionedField<scalar, GeoMesh> > func                                \
414 (                                                                           \
415     const int n,                                                            \
416     const DimensionedField<scalar, GeoMesh>& dsf                            \
417 )                                                                           \
418 {                                                                           \
419     if (!dsf.dimensions().dimensionless())                                  \
420     {                                                                       \
421         FatalErrorIn                                                        \
422         (                                                                   \
423             #func"(const int n, "                                           \
424             "const DimensionedField<scalar, GeoMesh>& dsf)"                 \
425         )   << "dsf not dimensionless"                                      \
426             << abort(FatalError);                                           \
427     }                                                                       \
428                                                                             \
429     tmp<DimensionedField<scalar, GeoMesh> > tFunc                           \
430     (                                                                       \
431         new DimensionedField<scalar, GeoMesh>                               \
432         (                                                                   \
433             IOobject                                                        \
434             (                                                               \
435                 #func "(" + name(n) + ',' + dsf.name() + ')',               \
436                 dsf.instance(),                                             \
437                 dsf.db()                                                    \
438             ),                                                              \
439             dsf.mesh(),                                                     \
440             dimless                                                         \
441         )                                                                   \
442     );                                                                      \
443                                                                             \
444     func(tFunc().field(), n, dsf.field());                                  \
445                                                                             \
446     return tFunc;                                                           \
447 }                                                                           \
448                                                                             \
449 template<class GeoMesh>                                                     \
450 tmp<DimensionedField<scalar, GeoMesh> > func                                \
451 (                                                                           \
452     const int n,                                                            \
453     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf                     \
454 )                                                                           \
455 {                                                                           \
456     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();                  \
457                                                                             \
458     if (!dsf.dimensions().dimensionless())                                  \
459     {                                                                       \
460         FatalErrorIn                                                        \
461         (                                                                   \
462             #func"(const int n, "                                           \
463             "const tmp<DimensionedField<scalar, GeoMesh> >& dsf)"           \
464         )   << " : dsf not dimensionless"                                   \
465             << abort(FatalError);                                           \
466     }                                                                       \
467                                                                             \
468     tmp<DimensionedField<scalar, GeoMesh> > tFunc                           \
469     (                                                                       \
470         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New              \
471         (                                                                   \
472             tdsf,                                                           \
473             #func "(" + name(n) + ',' + dsf.name() + ')',                   \
474             dimless                                                         \
475         )                                                                   \
476     );                                                                      \
477                                                                             \
478     func(tFunc().field(), n, dsf.field());                                  \
479                                                                             \
480     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);         \
481                                                                             \
482     return tFunc;                                                           \
485 BesselFunc(jn)
486 BesselFunc(yn)
488 #undef BesselFunc
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
493 } // End namespace Foam
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 #include "undefFieldFunctionsM.H"
499 // ************************************************************************* //