Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / CoeffField / DecoupledCoeffFieldFunctions.C
blobbfa1123aaf7cc18cdd023dcfffd62d8bd9b894ad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 \*---------------------------------------------------------------------------*/
27 #include "BlockCoeff.H"
29 /* * * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * */
31 template<class Type>
32 Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::inv
34     const DecoupledCoeffField<Type>& f
37     // The inverse of a linear coefficient type is currently done "by
38     // hand".  The need for this will disappear once the diagonal tensor
39     // type is introduced.  HJ, 24/May/2005
41     typedef typename DecoupledCoeffField<Type>::linearTypeField fieldType;
42     typedef typename DecoupledCoeffField<Type>::linearType valueType;
44     // Create result
45     tmp<DecoupledCoeffField<Type> > tresult
46     (
47         new DecoupledCoeffField<Type>(f.size())
48     );
49     DecoupledCoeffField<Type>& result = tresult();
51     if (f.activeType() == blockCoeffBase::SCALAR)
52     {
53         result = 1.0/f.asScalar();
54     }
55     else if (f.activeType() == blockCoeffBase::LINEAR)
56     {
57         const fieldType& lf = f.asLinear();
59         fieldType inverse =
60             cmptDivide
61             (
62                 fieldType(lf.size(), pTraits<valueType>::one),
63                 lf
64             );
66         result = inverse;
67     }
69     return tresult;
73 template<class Type>
74 void Foam::multiply
76     Field<Type>& f,
77     const DecoupledCoeffField<Type>& f1,
78     const Type& f2
81     if (f1.activeType() == blockCoeffBase::SCALAR)
82     {
83         f = f1.asScalar()*f2;
84     }
85     else if (f1.activeType() == blockCoeffBase::LINEAR)
86     {
87         f = cmptMultiply(f1.asLinear(), f2);
88     }
92 template<class Type>
93 void Foam::multiply
95     Field<Type>& f,
96     const DecoupledCoeffField<Type>& f1,
97     const Field<Type>& f2
100     if (f1.activeType() == blockCoeffBase::SCALAR)
101     {
102         f = f1.asScalar()*f2;
103     }
104     else if (f1.activeType() == blockCoeffBase::LINEAR)
105     {
106         f = cmptMultiply(f1.asLinear(), f2);
107     }
111 template<class Type>
112 void Foam::multiply
114     Field<Type>& f,
115     const Field<Type>& f1,
116     const DecoupledCoeffField<Type>& f2
119     if (f2.activeType() == blockCoeffBase::SCALAR)
120     {
121         f = f1*f2.asScalar();
122     }
123     else if (f2.activeType() == blockCoeffBase::LINEAR)
124     {
125         f = cmptMultiply(f1, f2.asLinear());
126     }
130 /* * * * * * * * * * * * * * * * Global operators  * * * * * * * * * * * * * */
132 #define UNARY_OPERATOR(op, opFunc)                                            \
133                                                                               \
134 template<class Type>                                                          \
135 void Foam::opFunc                                                             \
136 (                                                                             \
137     DecoupledCoeffField<Type>& f,                                             \
138     const DecoupledCoeffField<Type>& f1                                       \
139 )                                                                             \
140 {                                                                             \
141     typedef DecoupledCoeffField<Type> TypeDecoupledCoeffField;                \
142                                                                               \
143     typedef typename TypeDecoupledCoeffField::scalarTypeField scalarTypeField;\
144     typedef typename TypeDecoupledCoeffField::linearTypeField linearTypeField;\
145                                                                               \
146     if (f.activeType() == blockCoeffBase::SCALAR)                             \
147     {                                                                         \
148         scalarTypeField sf = f1.asScalar();                                   \
149         sf.opFunc();                                                          \
150         f = sf;                                                               \
151     }                                                                         \
152     else if (f.activeType() == blockCoeffBase::LINEAR)                        \
153     {                                                                         \
154         linearTypeField sf = f1.asLinear();                                   \
155         sf.opFunc();                                                          \
156         f = sf;                                                               \
157     }                                                                         \
158 }                                                                             \
159                                                                               \
160 template<class Type>                                                          \
161 Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op                 \
162 (                                                                             \
163     const DecoupledCoeffField<Type>& f1                                       \
164 )                                                                             \
165 {                                                                             \
166     tmp<DecoupledCoeffField<Type> > tf                                        \
167     (                                                                         \
168         new DecoupledCoeffField<Type>(f1.size())                              \
169     );                                                                        \
170     opFunc(tf(), f1);                                                         \
171     return tf;                                                                \
172 }                                                                             \
173                                                                               \
174 template<class Type>                                                          \
175 Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op                 \
176 (                                                                             \
177     const tmp<DecoupledCoeffField<Type> >& tf1                                \
178 )                                                                             \
179 {                                                                             \
180     tmp<DecoupledCoeffField<Type> > tf(tf1.ptr());                            \
181     opFunc(tf(), tf());                                                       \
182     return tf;                                                                \
185 UNARY_OPERATOR(-, negate)
187 #undef UNARY_OPERATOR
190 #define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc)                          \
191                                                                               \
192 template<class Type>                                                          \
193 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
194 (                                                                             \
195     const DecoupledCoeffField<Type1>& f1,                                     \
196     const Type2& f2                                                           \
197 )                                                                             \
198 {                                                                             \
199     tmp<Field<Type> > tf(new Field<Type>(f1.size()));                         \
200     opFunc(tf(), f1, f2);                                                     \
201     return tf;                                                                \
202 }                                                                             \
203                                                                               \
204                                                                               \
205 template<class Type>                                                          \
206 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
207 (                                                                             \
208     const DecoupledCoeffField<Type1>& f1,                                     \
209     const Field<Type2>& f2                                                    \
210 )                                                                             \
211 {                                                                             \
212     tmp<Field<Type> > tf(new Field<Type>(f1.size()));                         \
213     opFunc(tf(), f1, f2);                                                     \
214     return tf;                                                                \
215 }                                                                             \
216                                                                               \
217                                                                               \
218 template<class Type>                                                          \
219 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
220 (                                                                             \
221     const Field<Type2>& f1,                                                   \
222     const DecoupledCoeffField<Type1>& f2                                      \
223 )                                                                             \
224 {                                                                             \
225     tmp<Field<Type> > tf(new Field<Type>(f1.size()));                         \
226     opFunc(tf(), f1, f2);                                                     \
227     return tf;                                                                \
230 #define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc)                         \
231 template<class Type>                                                          \
232 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
233 (                                                                             \
234     const DecoupledCoeffField<Type1>& f1,                                     \
235     const tmp<Field<Type2> >& tf2                                             \
236 )                                                                             \
237 {                                                                             \
238     tmp<Field<Type> > tf(tf2.ptr());                                          \
239     opFunc(tf(), f1, tf());                                                   \
240     return tf;                                                                \
243 #define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc)                          \
244 template<class Type>                                                          \
245 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
246 (                                                                             \
247     const Field<Type1>& f1,                                                   \
248     const tmp<DecoupledCoeffField<Type2> >& tf2                               \
249 )                                                                             \
250 {                                                                             \
251     tmp<Field<Type> > tf = f1 op tf2();                                       \
252     tf2.clear();                                                              \
253     return tf;                                                                \
256 #define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc)                         \
257 template<class Type>                                                          \
258 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
259 (                                                                             \
260     const tmp<DecoupledCoeffField<Type1> >& tf1,                              \
261     const Field<Type2>& f2                                                    \
262 )                                                                             \
263 {                                                                             \
264     tmp<Field<Type> > tf(tf1.ptr());                                          \
265     opFunc(tf(), tf(), f2);                                                   \
266     return tf;                                                                \
269 #define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc)                          \
270 template<class Type>                                                          \
271 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
272 (                                                                             \
273     const tmp<DecoupledCoeffField<Type1> >& tf1,                              \
274     const Field<Type2>& f2                                                    \
275 )                                                                             \
276 {                                                                             \
277     tmp<Field<Type> > tf = tf1() op f2;                                       \
278     tf1.clear();                                                              \
279     return tf;                                                                \
282 #define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)                         \
283 template<class Type>                                                          \
284 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
285 (                                                                             \
286     const tmp<DecoupledCoeffField<Type1> >& tf1,                              \
287     const tmp<Field<Type2> >& tf2                                             \
288 )                                                                             \
289 {                                                                             \
290     tmp<Field<Type> > tf(tf1.ptr());                                          \
291     opFunc(tf(), tf(), tf2());                                                \
292     tf2.clear();                                                              \
293     return tf;                                                                \
296 #define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc)                         \
297 template<class Type>                                                          \
298 Foam::tmp<Foam::Field<Type> > Foam::operator op                               \
299 (                                                                             \
300     const tmp<Field<Type1> >& tf1,                                            \
301     const tmp<DecoupledCoeffField<Type2> >& tf2                               \
302 )                                                                             \
303 {                                                                             \
304     tmp<Field<Type> > tf(tf2.ptr());                                          \
305     opFunc(tf(), tf1(), tf());                                                \
306     tf1.clear();                                                              \
307     return tf;                                                                \
310 #define BINARY_OPERATOR_R(Type1, Type2, op, opFunc)                           \
311     BINARY_OPERATOR_FF(Type1, Type2, op, opFunc)                              \
312     BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc)                             \
313     BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc)                             \
314     BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)
316 // BINARY_OPERATOR_R(Type, Type, *, multiply)
318 #undef BINARY_OPERATOR_R
319 #undef BINARY_OPERATOR_FF
320 #undef BINARY_OPERATOR_FTR
321 #undef BINARY_OPERATOR_TF
322 #undef BINARY_OPERATOR_TTR
323 #undef BINARY_OPERATOR_FT
324 #undef BINARY_OPERATOR_TRF
325 #undef BINARY_OPERATOR_TRT
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //