1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
7 -------------------------------------------------------------------------------
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
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 * * * * * * * * * * * * * */
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;
45 tmp<DecoupledCoeffField<Type> > tresult
47 new DecoupledCoeffField<Type>(f.size())
49 DecoupledCoeffField<Type>& result = tresult();
51 if (f.activeType() == blockCoeffBase::SCALAR)
53 result = 1.0/f.asScalar();
55 else if (f.activeType() == blockCoeffBase::LINEAR)
57 const fieldType& lf = f.asLinear();
62 fieldType(lf.size(), pTraits<valueType>::one),
77 const DecoupledCoeffField<Type>& f1,
81 if (f1.activeType() == blockCoeffBase::SCALAR)
85 else if (f1.activeType() == blockCoeffBase::LINEAR)
87 f = cmptMultiply(f1.asLinear(), f2);
96 const DecoupledCoeffField<Type>& f1,
100 if (f1.activeType() == blockCoeffBase::SCALAR)
102 f = f1.asScalar()*f2;
104 else if (f1.activeType() == blockCoeffBase::LINEAR)
106 f = cmptMultiply(f1.asLinear(), f2);
115 const Field<Type>& f1,
116 const DecoupledCoeffField<Type>& f2
119 if (f2.activeType() == blockCoeffBase::SCALAR)
121 f = f1*f2.asScalar();
123 else if (f2.activeType() == blockCoeffBase::LINEAR)
125 f = cmptMultiply(f1, f2.asLinear());
130 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
132 #define UNARY_OPERATOR(op, opFunc) \
134 template<class Type> \
137 DecoupledCoeffField<Type>& f, \
138 const DecoupledCoeffField<Type>& f1 \
141 typedef DecoupledCoeffField<Type> TypeDecoupledCoeffField; \
143 typedef typename TypeDecoupledCoeffField::scalarTypeField scalarTypeField;\
144 typedef typename TypeDecoupledCoeffField::linearTypeField linearTypeField;\
146 if (f.activeType() == blockCoeffBase::SCALAR) \
148 scalarTypeField sf = f1.asScalar(); \
152 else if (f.activeType() == blockCoeffBase::LINEAR) \
154 linearTypeField sf = f1.asLinear(); \
160 template<class Type> \
161 Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op \
163 const DecoupledCoeffField<Type>& f1 \
166 tmp<DecoupledCoeffField<Type> > tf \
168 new DecoupledCoeffField<Type>(f1.size()) \
174 template<class Type> \
175 Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op \
177 const tmp<DecoupledCoeffField<Type> >& tf1 \
180 tmp<DecoupledCoeffField<Type> > tf(tf1.ptr()); \
181 opFunc(tf(), tf()); \
185 UNARY_OPERATOR(-, negate)
187 #undef UNARY_OPERATOR
190 #define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
192 template<class Type> \
193 Foam::tmp<Foam::Field<Type> > Foam::operator op \
195 const DecoupledCoeffField<Type1>& f1, \
199 tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
200 opFunc(tf(), f1, f2); \
205 template<class Type> \
206 Foam::tmp<Foam::Field<Type> > Foam::operator op \
208 const DecoupledCoeffField<Type1>& f1, \
209 const Field<Type2>& f2 \
212 tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
213 opFunc(tf(), f1, f2); \
218 template<class Type> \
219 Foam::tmp<Foam::Field<Type> > Foam::operator op \
221 const Field<Type2>& f1, \
222 const DecoupledCoeffField<Type1>& f2 \
225 tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
226 opFunc(tf(), f1, f2); \
230 #define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
231 template<class Type> \
232 Foam::tmp<Foam::Field<Type> > Foam::operator op \
234 const DecoupledCoeffField<Type1>& f1, \
235 const tmp<Field<Type2> >& tf2 \
238 tmp<Field<Type> > tf(tf2.ptr()); \
239 opFunc(tf(), f1, tf()); \
243 #define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc) \
244 template<class Type> \
245 Foam::tmp<Foam::Field<Type> > Foam::operator op \
247 const Field<Type1>& f1, \
248 const tmp<DecoupledCoeffField<Type2> >& tf2 \
251 tmp<Field<Type> > tf = f1 op tf2(); \
256 #define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
257 template<class Type> \
258 Foam::tmp<Foam::Field<Type> > Foam::operator op \
260 const tmp<DecoupledCoeffField<Type1> >& tf1, \
261 const Field<Type2>& f2 \
264 tmp<Field<Type> > tf(tf1.ptr()); \
265 opFunc(tf(), tf(), f2); \
269 #define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc) \
270 template<class Type> \
271 Foam::tmp<Foam::Field<Type> > Foam::operator op \
273 const tmp<DecoupledCoeffField<Type1> >& tf1, \
274 const Field<Type2>& f2 \
277 tmp<Field<Type> > tf = tf1() op f2; \
282 #define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc) \
283 template<class Type> \
284 Foam::tmp<Foam::Field<Type> > Foam::operator op \
286 const tmp<DecoupledCoeffField<Type1> >& tf1, \
287 const tmp<Field<Type2> >& tf2 \
290 tmp<Field<Type> > tf(tf1.ptr()); \
291 opFunc(tf(), tf(), tf2()); \
296 #define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc) \
297 template<class Type> \
298 Foam::tmp<Foam::Field<Type> > Foam::operator op \
300 const tmp<Field<Type1> >& tf1, \
301 const tmp<DecoupledCoeffField<Type2> >& tf2 \
304 tmp<Field<Type> > tf(tf2.ptr()); \
305 opFunc(tf(), tf1(), 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //