1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Generic fieldField type.
28 \*---------------------------------------------------------------------------*/
30 #include "FieldField.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 template<template<class> class Field, class Type1, class Type2>
42 const FieldField<Field, Type1>& f1,
43 const FieldField<Field, Type2>& f2,
47 if (f1.size() != f2.size())
51 "checkFields(const FieldField<Field, Type1>&, "
52 "const FieldField<Field, Type2>&, const char* op)"
53 ) << " incompatible fields"
54 << " FieldField<" << pTraits<Type1>::typeName
55 << "> f1(" << f1.size() << ')'
56 << " and FieldField<" << pTraits<Type2>::typeName
57 << "> f2(" << f2.size() << ')'
58 << endl << " for operation " << op
63 template<template<class> class Field, class Type1, class Type2, class Type3>
66 const FieldField<Field, Type1>& f1,
67 const FieldField<Field, Type2>& f2,
68 const FieldField<Field, Type3>& f3,
72 if (f1.size() != f2.size() || f1.size() != f3.size())
76 "checkFields(const FieldField<Field, Type1>&, "
77 "const FieldField<Field, Type2>&, "
78 "const FieldField<Field, Type3>&, "
80 ) << " incompatible fields"
81 << " FieldField<" << pTraits<Type1>::typeName
82 << "> f1(" << f1.size() << ')'
83 << ", FieldField<" <<pTraits<Type2>::typeName
84 << "> f2(" << f2.size() << ')'
85 << " and FieldField<"<<pTraits<Type3>::typeName
86 << "> f3("<<f3.size() << ')'
87 << endl << " for operation " << op
94 template<template<class> class Field, class Type1, class Type2>
97 const FieldField<Field, Type1>&,
98 const FieldField<Field, Type2>&,
103 template<template<class> class Field, class Type1, class Type2, class Type3>
106 const FieldField<Field, Type1>&,
107 const FieldField<Field, Type2>&,
108 const FieldField<Field, Type3>&,
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 template<template<class> class Field, class Type>
119 FieldField<Field, Type>::FieldField()
121 PtrList<Field<Type> >()
125 template<template<class> class Field, class Type>
126 FieldField<Field, Type>::FieldField(const label size)
128 PtrList<Field<Type> >(size)
132 template<template<class> class Field, class Type>
133 FieldField<Field, Type>::FieldField
136 const FieldField<Field, Type>& ff
139 PtrList<Field<Type> >(ff.size())
143 set(i, Field<Type>::New(type, ff[i]));
148 template<template<class> class Field, class Type>
149 FieldField<Field, Type>::FieldField(const FieldField<Field, Type>& f)
152 PtrList<Field<Type> >(f)
156 template<template<class> class Field, class Type>
157 FieldField<Field, Type>::FieldField(FieldField<Field, Type>& f, bool reUse)
160 PtrList<Field<Type> >(f, reUse)
164 template<template<class> class Field, class Type>
165 FieldField<Field, Type>::FieldField(const PtrList<Field<Type> >& tl)
167 PtrList<Field<Type> >(tl)
171 // Construct as copy of tmp<FieldField>
172 #ifdef ConstructFromTmp
173 template<template<class> class Field, class Type>
174 FieldField<Field, Type>::FieldField(const tmp<FieldField<Field, Type> >& tf)
176 PtrList<Field<Type> >
178 const_cast<FieldField<Field, Type>&>(tf()),
182 const_cast<FieldField<Field, Type>&>(tf()).resetRefCount();
187 template<template<class> class Field, class Type>
188 FieldField<Field, Type>::FieldField(Istream& is)
190 PtrList<Field<Type> >(is)
194 template<template<class> class Field, class Type>
195 tmp<FieldField<Field, Type> > FieldField<Field, Type>::clone() const
197 return tmp<FieldField<Field, Type> >(new FieldField<Field, Type>(*this));
201 #ifndef __INTEL_COMPILER
202 template<template<class> class Field, class Type>
203 template<class Type2>
204 tmp<FieldField<Field, Type> > FieldField<Field, Type>::NewCalculatedType
206 const FieldField<Field, Type2>& ff
209 FieldField<Field, Type>* nffPtr
211 new FieldField<Field, Type>(ff.size())
216 nffPtr->set(i, Field<Type>::NewCalculatedType(ff[i]).ptr());
219 return tmp<FieldField<Field, Type> >(nffPtr);
224 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
226 template<template<class> class Field, class Type>
227 void FieldField<Field, Type>::negate()
231 this->operator[](i).negate();
236 template<template<class> class Field, class Type>
237 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType> >
238 FieldField<Field, Type>::component
243 tmp<FieldField<Field, cmptType> > Component
245 FieldField<Field, typename FieldField<Field, Type>::cmptType>::
246 NewCalculatedType(*this)
249 ::Foam::component(Component(), *this, d);
255 template<template<class> class Field, class Type>
256 void FieldField<Field, Type>::replace
259 const FieldField<Field, cmptType>& sf
264 this->operator[](i).replace(d, sf[i]);
269 template<template<class> class Field, class Type>
270 void FieldField<Field, Type>::replace
278 this->operator[](i).replace(d, s);
283 template<template<class> class Field, class Type>
284 tmp<FieldField<Field, Type> > FieldField<Field, Type>::T() const
286 tmp<FieldField<Field, Type> > transpose
288 FieldField<Field, Type>::NewCalculatedType(*this)
291 ::Foam::T(transpose(), *this);
296 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
298 template<template<class> class Field, class Type>
299 void FieldField<Field, Type>::operator=(const FieldField<Field, Type>& f)
305 "FieldField<Field, Type>::"
306 "operator=(const FieldField<Field, Type>&)"
307 ) << "attempted assignment to self"
308 << abort(FatalError);
313 this->operator[](i) = f[i];
318 template<template<class> class Field, class Type>
319 void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf)
325 "FieldField<Field, Type>::operator=(const tmp<FieldField>&)"
326 ) << "attempted assignment to self"
327 << abort(FatalError);
330 // This is dodgy stuff, don't try this at home.
331 FieldField* fieldPtr = tf.ptr();
332 PtrList<Field<Type> >::transfer(*fieldPtr);
337 template<template<class> class Field, class Type>
338 void FieldField<Field, Type>::operator=(const Type& t)
342 this->operator[](i) = t;
347 #define COMPUTED_ASSIGNMENT(TYPE, op) \
349 template<template<class> class Field, class Type> \
350 void FieldField<Field, Type>::operator op(const FieldField<Field, TYPE>& f) \
354 this->operator[](i) op f[i]; \
358 template<template<class> class Field, class Type> \
359 void FieldField<Field, Type>::operator op \
361 const tmp<FieldField<Field, TYPE> >& tf \
368 template<template<class> class Field, class Type> \
369 void FieldField<Field, Type>::operator op(const TYPE& t) \
373 this->operator[](i) op t; \
377 COMPUTED_ASSIGNMENT(Type, +=)
378 COMPUTED_ASSIGNMENT(Type, -=)
379 COMPUTED_ASSIGNMENT(scalar, *=)
380 COMPUTED_ASSIGNMENT(scalar, /=)
382 #undef COMPUTED_ASSIGNMENT
385 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
387 template<template<class> class Field, class Type>
388 Ostream& operator<<(Ostream& os, const FieldField<Field, Type>& f)
390 os << static_cast<const PtrList<Field<Type> >&>(f);
395 template<template<class> class Field, class Type>
396 Ostream& operator<<(Ostream& os, const tmp<FieldField<Field, Type> >& tf)
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 } // End namespace Foam
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 # include "FieldFieldFunctions.C"
412 // ************************************************************************* //