DimensionedScalarField.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 #include "DimensionedScalarField.H"
27 
28 #define TEMPLATE template<class GeoMesh>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 template<class GeoMesh>
39 tmp<DimensionedField<scalar, GeoMesh> > stabilise
40 (
42  const dimensioned<scalar>& ds
43 )
44 {
46  (
48  (
49  IOobject
50  (
51  "stabilise(" + dsf.name() + ',' + ds.name() + ')',
52  dsf.instance(),
53  dsf.db()
54  ),
55  dsf.mesh(),
56  dsf.dimensions() + ds.dimensions()
57  )
58  );
59 
60  stabilise(tRes().field(), dsf.field(), ds.value());
61 
62  return tRes;
63 }
64 
65 
66 template<class GeoMesh>
68 (
70  const dimensioned<scalar>& ds
71 )
72 {
73  const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
74 
77  (
78  tdsf,
79  "stabilise(" + dsf.name() + ',' + ds.name() + ')',
80  dsf.dimensions() + ds.dimensions()
81  );
82 
83  stabilise(tRes().field(), dsf.field(), ds.value());
84 
86 
87  return tRes;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, '+', add)
94 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, '-', subtract)
95 
96 BINARY_OPERATOR(scalar, scalar, scalar, *, '*', multiply)
97 BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide)
98 
99 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide)
100 
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 
103 template<class GeoMesh>
105 (
108 )
109 {
111  (
113  (
114  IOobject
115  (
116  "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
117  dsf1.instance(),
118  dsf1.db()
119  ),
120  dsf1.mesh(),
121  pow
122  (
123  dsf1.dimensions(),
124  dimensionedScalar("1", 1.0, dsf2.dimensions())
125  )
126  )
127  );
128 
129  pow(tPow().field(), dsf1.field(), dsf2.field());
130 
131  return tPow;
132 }
133 
134 
135 template<class GeoMesh>
137 (
138  const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
140 )
141 {
142  const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
143 
146  (
147  tdsf1,
148  "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
149  pow
150  (
151  dsf1.dimensions(),
152  dimensionedScalar("1", 1.0, dsf2.dimensions())
153  )
154  );
155 
156  pow(tPow().field(), dsf1.field(), dsf2.field());
157 
159 
160  return tPow;
161 }
162 
163 
164 template<class GeoMesh>
166 (
169 )
170 {
171  const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
172 
175  (
176  tdsf2,
177  "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
178  pow
179  (
180  dsf1.dimensions(),
181  dimensionedScalar("1", 1.0, dsf2.dimensions())
182  )
183  );
184 
185  pow(tPow().field(), dsf1.field(), dsf2.field());
186 
188 
189  return tPow;
190 }
191 
192 template<class GeoMesh>
194 (
195  const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
197 )
198 {
199  const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
200  const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
201 
204  New
205  (
206  tdsf1,
207  tdsf2,
208  "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
209  pow
210  (
211  dsf1.dimensions(),
212  dimensionedScalar("1", 1.0, dsf2.dimensions())
213  )
214  );
215 
216  pow(tPow().field(), dsf1.field(), dsf2.field());
217 
219  (
220  tdsf1,
221  tdsf2
222  );
223 
224  return tPow;
225 }
226 
227 
228 template<class GeoMesh>
230 (
232  const dimensionedScalar& ds
233 )
234 {
236  (
238  (
239  IOobject
240  (
241  "pow(" + dsf.name() + ',' + ds.name() + ')',
242  dsf.instance(),
243  dsf.db()
244  ),
245  dsf.mesh(),
246  pow(dsf.dimensions(), ds)
247  )
248  );
249 
250  pow(tPow().field(), dsf.field(), ds.value());
251 
252  return tPow;
253 }
254 
255 template<class GeoMesh>
257 (
259  const dimensionedScalar& ds
260 )
261 {
262  const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
263 
266  (
267  tdsf,
268  "pow(" + dsf.name() + ',' + ds.name() + ')',
269  pow(dsf.dimensions(), ds)
270  );
271 
272  pow(tPow().field(), dsf.field(), ds.value());
273 
275 
276  return tPow;
277 }
278 
279 template<class GeoMesh>
281 (
283  const scalar& s
284 )
285 {
286  return pow(dsf, dimensionedScalar(s));
287 }
288 
289 template<class GeoMesh>
291 (
293  const scalar& s
294 )
295 {
296  return pow(tdsf, dimensionedScalar(s));
297 }
298 
299 
300 template<class GeoMesh>
302 (
303  const dimensionedScalar& ds,
305 )
306 {
308  (
310  (
311  IOobject
312  (
313  "pow(" + ds.name() + ',' + dsf.name() + ')',
314  dsf.instance(),
315  dsf.db()
316  ),
317  dsf.mesh(),
318  pow(ds, dsf.dimensions())
319  )
320  );
321 
322  pow(tPow().field(), ds.value(), dsf.field());
323 
324  return tPow;
325 }
326 
327 
328 template<class GeoMesh>
330 (
331  const dimensionedScalar& ds,
333 )
334 {
335  const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
336 
339  (
340  tdsf,
341  "pow(" + ds.name() + ',' + dsf.name() + ')',
342  pow(ds, dsf.dimensions())
343  );
344 
345  pow(tPow().field(), ds.value(), dsf.field());
346 
348 
349  return tPow;
350 }
351 
352 template<class GeoMesh>
354 (
355  const scalar& s,
357 )
358 {
359  return pow(dimensionedScalar(s), dsf);
360 }
361 
362 template<class GeoMesh>
364 (
365  const scalar& s,
367 )
368 {
369  return pow(dimensionedScalar(s), tdsf);
370 }
371 
372 
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 
375 template<class GeoMesh>
377 (
380 )
381 {
383  (
385  (
386  IOobject
387  (
388  "atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
389  dsf1.instance(),
390  dsf1.db()
391  ),
392  dsf1.mesh(),
393  atan2(dsf1.dimensions(), dsf2.dimensions())
394  )
395  );
396 
397  atan2(tAtan2().field(), dsf1.field(), dsf2.field());
398 
399  return tAtan2;
400 }
401 
402 
403 template<class GeoMesh>
405 (
406  const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
408 )
409 {
410  const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
411 
414  (
415  tdsf1,
416  "atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
417  atan2(dsf1.dimensions(), dsf2.dimensions())
418  );
419 
420  atan2(tAtan2().field(), dsf1.field(), dsf2.field());
421 
423 
424  return tAtan2;
425 }
426 
427 
428 template<class GeoMesh>
430 (
433 )
434 {
435  const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
436 
439  (
440  tdsf2,
441  "atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
442  atan2(dsf1.dimensions(), dsf2.dimensions())
443  );
444 
445  atan2(tAtan2().field(), dsf1.field(), dsf2.field());
446 
448 
449  return tAtan2;
450 }
451 
452 template<class GeoMesh>
454 (
455  const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
457 )
458 {
459  const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
460  const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
461 
464  New
465  (
466  tdsf1,
467  tdsf2,
468  "atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
469  atan2(dsf1.dimensions(), dsf2.dimensions())
470  );
471 
472  atan2(tAtan2().field(), dsf1.field(), dsf2.field());
473 
475  (
476  tdsf1,
477  tdsf2
478  );
479 
480  return tAtan2;
481 }
482 
483 
484 template<class GeoMesh>
486 (
488  const dimensionedScalar& ds
489 )
490 {
492  (
494  (
495  IOobject
496  (
497  "atan2(" + dsf.name() + ',' + ds.name() + ')',
498  dsf.instance(),
499  dsf.db()
500  ),
501  dsf.mesh(),
502  atan2(dsf.dimensions(), ds)
503  )
504  );
505 
506  atan2(tAtan2().field(), dsf.field(), ds.value());
507 
508  return tAtan2;
509 }
510 
511 template<class GeoMesh>
513 (
515  const dimensionedScalar& ds
516 )
517 {
518  const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
519 
522  (
523  tdsf,
524  "atan2(" + dsf.name() + ',' + ds.name() + ')',
525  atan2(dsf.dimensions(), ds)
526  );
527 
528  atan2(tAtan2().field(), dsf.field(), ds.value());
529 
531 
532  return tAtan2;
533 }
534 
535 template<class GeoMesh>
537 (
539  const scalar& s
540 )
541 {
542  return atan2(dsf, dimensionedScalar(s));
543 }
544 
545 template<class GeoMesh>
547 (
549  const scalar& s
550 )
551 {
552  return atan2(tdsf, dimensionedScalar(s));
553 }
554 
555 
556 template<class GeoMesh>
558 (
559  const dimensionedScalar& ds,
561 )
562 {
564  (
566  (
567  IOobject
568  (
569  "atan2(" + ds.name() + ',' + dsf.name() + ')',
570  dsf.instance(),
571  dsf.db()
572  ),
573  dsf.mesh(),
574  atan2(ds, dsf.dimensions())
575  )
576  );
577 
578  atan2(tAtan2().field(), ds.value(), dsf.field());
579 
580  return tAtan2;
581 }
582 
583 
584 template<class GeoMesh>
586 (
587  const dimensionedScalar& ds,
589 )
590 {
591  const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
592 
595  (
596  tdsf,
597  "atan2(" + ds.name() + ',' + dsf.name() + ')',
598  atan2(ds, dsf.dimensions())
599  );
600 
601  atan2(tAtan2().field(), ds.value(), dsf.field());
602 
604 
605  return tAtan2;
606 }
607 
608 template<class GeoMesh>
610 (
611  const scalar& s,
613 )
614 {
615  return atan2(dimensionedScalar(s), dsf);
616 }
617 
618 template<class GeoMesh>
620 (
621  const scalar& s,
623 )
624 {
625  return atan2(dimensionedScalar(s), tdsf);
626 }
627 
628 
629 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
630 
631 UNARY_FUNCTION(scalar, scalar, pow3, pow3)
632 UNARY_FUNCTION(scalar, scalar, pow4, pow4)
633 UNARY_FUNCTION(scalar, scalar, pow5, pow5)
634 UNARY_FUNCTION(scalar, scalar, pow6, pow6)
635 UNARY_FUNCTION(scalar, scalar, pow025, pow025)
636 UNARY_FUNCTION(scalar, scalar, sqrt, sqrt)
637 UNARY_FUNCTION(scalar, scalar, cbrt, cbrt)
638 UNARY_FUNCTION(scalar, scalar, sign, sign)
639 UNARY_FUNCTION(scalar, scalar, pos, pos)
640 UNARY_FUNCTION(scalar, scalar, neg, neg)
641 UNARY_FUNCTION(scalar, scalar, posPart, posPart)
642 UNARY_FUNCTION(scalar, scalar, negPart, negPart)
643 
644 UNARY_FUNCTION(scalar, scalar, exp, trans)
645 UNARY_FUNCTION(scalar, scalar, log, trans)
646 UNARY_FUNCTION(scalar, scalar, log10, trans)
647 UNARY_FUNCTION(scalar, scalar, sin, trans)
648 UNARY_FUNCTION(scalar, scalar, cos, trans)
649 UNARY_FUNCTION(scalar, scalar, tan, trans)
650 UNARY_FUNCTION(scalar, scalar, asin, trans)
651 UNARY_FUNCTION(scalar, scalar, acos, trans)
652 UNARY_FUNCTION(scalar, scalar, atan, trans)
653 UNARY_FUNCTION(scalar, scalar, sinh, trans)
654 UNARY_FUNCTION(scalar, scalar, cosh, trans)
655 UNARY_FUNCTION(scalar, scalar, tanh, trans)
656 UNARY_FUNCTION(scalar, scalar, asinh, trans)
657 UNARY_FUNCTION(scalar, scalar, acosh, trans)
658 UNARY_FUNCTION(scalar, scalar, atanh, trans)
659 UNARY_FUNCTION(scalar, scalar, erf, trans)
660 UNARY_FUNCTION(scalar, scalar, erfc, trans)
661 UNARY_FUNCTION(scalar, scalar, lgamma, trans)
662 UNARY_FUNCTION(scalar, scalar, j0, trans)
663 UNARY_FUNCTION(scalar, scalar, j1, trans)
664 UNARY_FUNCTION(scalar, scalar, y0, trans)
665 UNARY_FUNCTION(scalar, scalar, y1, trans)
666 
667 
668 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
669 
670 #define BesselFunc(func) \
671  \
672 template<class GeoMesh> \
673 tmp<DimensionedField<scalar, GeoMesh> > func \
674 ( \
675  const int n, \
676  const DimensionedField<scalar, GeoMesh>& dsf \
677 ) \
678 { \
679  if (!dsf.dimensions().dimensionless()) \
680  { \
681  FatalErrorIn \
682  ( \
683  #func"(const int n, " \
684  "const DimensionedField<scalar, GeoMesh>& dsf)" \
685  ) << "dsf not dimensionless" \
686  << abort(FatalError); \
687  } \
688  \
689  tmp<DimensionedField<scalar, GeoMesh> > tFunc \
690  ( \
691  new DimensionedField<scalar, GeoMesh> \
692  ( \
693  IOobject \
694  ( \
695  #func "(" + name(n) + ',' + dsf.name() + ')', \
696  dsf.instance(), \
697  dsf.db() \
698  ), \
699  dsf.mesh(), \
700  dimless \
701  ) \
702  ); \
703  \
704  func(tFunc().field(), n, dsf.field()); \
705  \
706  return tFunc; \
707 } \
708  \
709 template<class GeoMesh> \
710 tmp<DimensionedField<scalar, GeoMesh> > func \
711 ( \
712  const int n, \
713  const tmp<DimensionedField<scalar, GeoMesh> >& tdsf \
714 ) \
715 { \
716  const DimensionedField<scalar, GeoMesh>& dsf = tdsf(); \
717  \
718  if (!dsf.dimensions().dimensionless()) \
719  { \
720  FatalErrorIn \
721  ( \
722  #func"(const int n, " \
723  "const tmp<DimensionedField<scalar, GeoMesh> >& dsf)" \
724  ) << " : dsf not dimensionless" \
725  << abort(FatalError); \
726  } \
727  \
728  tmp<DimensionedField<scalar, GeoMesh> > tFunc \
729  ( \
730  reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New \
731  ( \
732  tdsf, \
733  #func "(" + name(n) + ',' + dsf.name() + ')', \
734  dimless \
735  ) \
736  ); \
737  \
738  func(tFunc().field(), n, dsf.field()); \
739  \
740  reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf); \
741  \
742  return tFunc; \
743 }
744 
747 
748 #undef BesselFunc
749 
750 
751 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
752 
753 } // End namespace Foam
754 
755 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
756 
757 #include "undefFieldFunctionsM.H"
758 
759 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow3(const dimensionedScalar &ds)
Scalar specific part of the implementation of DimensionedField.
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedScalar erfc(const dimensionedScalar &ds)
dimensionedScalar erf(const dimensionedScalar &ds)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensionedScalar j0(const dimensionedScalar &ds)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar neg(const dimensionedScalar &ds)
const Field< Type > & field() const
dimensionedScalar y1(const dimensionedScalar &ds)
dimensionedScalar j1(const dimensionedScalar &ds)
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
dimensionedScalar jn(const int n, const dimensionedScalar &ds)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensionedScalar posPart(const dimensionedScalar &ds)
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar log10(const dimensionedScalar &ds)
const fileName & instance() const
Definition: IOobject.H:337
dimensionedScalar exp(const dimensionedScalar &ds)
dimensionedScalar sign(const dimensionedScalar &ds)
const Mesh & mesh() const
Return mesh.
dimensionedScalar y0(const dimensionedScalar &ds)
Namespace for OpenFOAM.
const dimensionSet & dimensions() const
Return const reference to dimensions.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:438
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const tmp< DimensionedField< Type2, GeoMesh > > &tdf2, const word &name, const dimensionSet &dimensions)
#define BesselFunc(func)
const word & name() const
Return const reference to name.
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar asinh(const dimensionedScalar &ds)
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
const dimensionSet & dimensions() const
Return dimensions.
dimensionedScalar acos(const dimensionedScalar &ds)
dimensionedScalar lgamma(const dimensionedScalar &ds)
const word & name() const
Return name.
Definition: IOobject.H:260
dimensionedScalar tanh(const dimensionedScalar &ds)
dimensionedScalar yn(const int n, const dimensionedScalar &ds)
dimensionedScalar tan(const dimensionedScalar &ds)
dimensionedScalar atan(const dimensionedScalar &ds)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
static void clear(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1)
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar pos(const dimensionedScalar &ds)
static void clear(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const tmp< DimensionedField< Type2, GeoMesh > > &tdf2)
dimensionedScalar acosh(const dimensionedScalar &ds)
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:245
dimensionedScalar cosh(const dimensionedScalar &ds)
dimensionedScalar asin(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A class for managing temporary objects.
Definition: PtrList.H:118
dimensionedScalar atanh(const dimensionedScalar &ds)
dimensionedScalar sinh(const dimensionedScalar &ds)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
const Type & value() const
Return const reference to value.
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar sin(const dimensionedScalar &ds)