FreeFOAM The Cross-Platform CFD Toolkit
scalarField.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) 1991-2010 OpenCFD Ltd.
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 Description
25  Specialisation of Field<T> for scalar.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include <OpenFOAM/scalarField.H>
30 
31 #define TEMPLATE
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 template<>
43 {
44  return *this;
45 }
46 
48 {
49  sf = f;
50 }
51 
52 template<>
53 void scalarField::replace(const direction, const UList<scalar>& sf)
54 {
55  *this = sf;
56 }
57 
58 template<>
59 void scalarField::replace(const direction, const scalar& s)
60 {
61  *this = s;
62 }
63 
64 
65 void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
66 {
68  (
69  scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf
70  )
71 }
72 
73 tmp<scalarField> stabilise(const UList<scalar>& sf, const scalar s)
74 {
75  tmp<scalarField> tRes(new scalarField(sf.size()));
76  stabilise(tRes(), sf, s);
77  return tRes;
78 }
79 
80 tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
81 {
83  stabilise(tRes(), tsf(), s);
85  return tRes;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add)
92 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, subtract)
93 
94 BINARY_OPERATOR(scalar, scalar, scalar, *, multiply)
95 BINARY_OPERATOR(scalar, scalar, scalar, /, divide)
96 
97 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, divide)
98 
99 BINARY_FUNCTION(scalar, scalar, scalar, pow)
100 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
101 
102 BINARY_FUNCTION(scalar, scalar, scalar, atan2)
103 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 UNARY_FUNCTION(scalar, scalar, pow3)
108 UNARY_FUNCTION(scalar, scalar, pow4)
109 UNARY_FUNCTION(scalar, scalar, pow5)
110 UNARY_FUNCTION(scalar, scalar, pow6)
111 UNARY_FUNCTION(scalar, scalar, sqrt)
112 UNARY_FUNCTION(scalar, scalar, sign)
113 UNARY_FUNCTION(scalar, scalar, pos)
114 UNARY_FUNCTION(scalar, scalar, neg)
115 UNARY_FUNCTION(scalar, scalar, exp)
116 UNARY_FUNCTION(scalar, scalar, log)
117 UNARY_FUNCTION(scalar, scalar, log10)
118 UNARY_FUNCTION(scalar, scalar, sin)
119 UNARY_FUNCTION(scalar, scalar, cos)
120 UNARY_FUNCTION(scalar, scalar, tan)
121 UNARY_FUNCTION(scalar, scalar, asin)
122 UNARY_FUNCTION(scalar, scalar, acos)
123 UNARY_FUNCTION(scalar, scalar, atan)
124 UNARY_FUNCTION(scalar, scalar, sinh)
125 UNARY_FUNCTION(scalar, scalar, cosh)
126 UNARY_FUNCTION(scalar, scalar, tanh)
127 UNARY_FUNCTION(scalar, scalar, asinh)
128 UNARY_FUNCTION(scalar, scalar, acosh)
129 UNARY_FUNCTION(scalar, scalar, atanh)
130 UNARY_FUNCTION(scalar, scalar, erf)
131 UNARY_FUNCTION(scalar, scalar, erfc)
132 UNARY_FUNCTION(scalar, scalar, lgamma)
133 UNARY_FUNCTION(scalar, scalar, j0)
134 UNARY_FUNCTION(scalar, scalar, j1)
135 UNARY_FUNCTION(scalar, scalar, y0)
136 UNARY_FUNCTION(scalar, scalar, y1)
137 
138 
139 #define BesselFunc(func) \
140 void func(scalarField& res, const int n, const UList<scalar>& sf) \
141 { \
142  TFOR_ALL_F_OP_FUNC_S_F(scalar, res, =, ::Foam::func, int, n, scalar, sf) \
143 } \
144  \
145 tmp<scalarField> func(const int n, const UList<scalar>& sf) \
146 { \
147  tmp<scalarField> tRes(new scalarField(sf.size())); \
148  func(tRes(), n, sf); \
149  return tRes; \
150 } \
151  \
152 tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
153 { \
154  tmp<scalarField> tRes = reuseTmp<scalar, scalar>::New(tsf); \
155  func(tRes(), n, tsf()); \
156  reuseTmp<scalar, scalar>::clear(tsf); \
157  return tRes; \
158 }
159 
162 
163 #undef BesselFunc
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
173 
174 // ************************ vim: set sw=4 sts=4 et: ************************ //