1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Generic fieldField type.
27 \*---------------------------------------------------------------------------*/
29 #include "FieldField.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 template<template<class> class Field, class Type1, class Type2>
41 const FieldField<Field, Type1>& f1,
42 const FieldField<Field, Type2>& f2,
46 if (f1.size() != f2.size())
50 "checkFields(const FieldField<Field, Type1>&, "
51 "const FieldField<Field, Type2>&, const char* op)"
52 ) << " incompatible fields"
53 << " FieldField<" << pTraits<Type1>::typeName
54 << "> f1(" << f1.size() << ')'
55 << " and FieldField<" << pTraits<Type2>::typeName
56 << "> f2(" << f2.size() << ')'
57 << endl << " for operation " << op
62 template<template<class> class Field, class Type1, class Type2, class Type3>
65 const FieldField<Field, Type1>& f1,
66 const FieldField<Field, Type2>& f2,
67 const FieldField<Field, Type3>& f3,
71 if (f1.size() != f2.size() || f1.size() != f3.size())
75 "checkFields(const FieldField<Field, Type1>&, "
76 "const FieldField<Field, Type2>&, "
77 "const FieldField<Field, Type3>&, "
79 ) << " incompatible fields"
80 << " FieldField<" << pTraits<Type1>::typeName
81 << "> f1(" << f1.size() << ')'
82 << ", FieldField<" <<pTraits<Type2>::typeName
83 << "> f2(" << f2.size() << ')'
84 << " and FieldField<"<<pTraits<Type3>::typeName
85 << "> f3("<<f3.size() << ')'
86 << endl << " for operation " << op
93 template<template<class> class Field, class Type1, class Type2>
96 const FieldField<Field, Type1>&,
97 const FieldField<Field, Type2>&,
102 template<template<class> class Field, class Type1, class Type2, class Type3>
105 const FieldField<Field, Type1>&,
106 const FieldField<Field, Type2>&,
107 const FieldField<Field, Type3>&,
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 template<template<class> class Field, class Type>
118 FieldField<Field, Type>::FieldField()
120 PtrList<Field<Type> >()
124 template<template<class> class Field, class Type>
125 FieldField<Field, Type>::FieldField(const label size)
127 PtrList<Field<Type> >(size)
131 template<template<class> class Field, class Type>
132 FieldField<Field, Type>::FieldField
135 const FieldField<Field, Type>& ff
138 PtrList<Field<Type> >(ff.size())
142 set(i, Field<Type>::New(type, ff[i]));
147 template<template<class> class Field, class Type>
148 FieldField<Field, Type>::FieldField(const FieldField<Field, Type>& f)
151 PtrList<Field<Type> >(f)
155 template<template<class> class Field, class Type>
156 FieldField<Field, Type>::FieldField(FieldField<Field, Type>& f, bool reUse)
159 PtrList<Field<Type> >(f, reUse)
163 template<template<class> class Field, class Type>
164 FieldField<Field, Type>::FieldField(const PtrList<Field<Type> >& tl)
166 PtrList<Field<Type> >(tl)
170 // Construct as copy of tmp<FieldField>
171 #ifdef ConstructFromTmp
172 template<template<class> class Field, class Type>
173 FieldField<Field, Type>::FieldField(const tmp<FieldField<Field, Type> >& tf)
175 PtrList<Field<Type> >
177 const_cast<FieldField<Field, Type>&>(tf()),
181 const_cast<FieldField<Field, Type>&>(tf()).resetRefCount();
186 template<template<class> class Field, class Type>
187 FieldField<Field, Type>::FieldField(Istream& is)
189 PtrList<Field<Type> >(is)
193 template<template<class> class Field, class Type>
194 tmp<FieldField<Field, Type> > FieldField<Field, Type>::clone() const
196 return tmp<FieldField<Field, Type> >(new FieldField<Field, Type>(*this));
200 #ifndef __INTEL_COMPILER
201 template<template<class> class Field, class Type>
202 template<class Type2>
203 tmp<FieldField<Field, Type> > FieldField<Field, Type>::NewCalculatedType
205 const FieldField<Field, Type2>& ff
208 FieldField<Field, Type>* nffPtr
210 new FieldField<Field, Type>(ff.size())
215 nffPtr->set(i, Field<Type>::NewCalculatedType(ff[i]).ptr());
218 return tmp<FieldField<Field, Type> >(nffPtr);
223 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
225 template<template<class> class Field, class Type>
226 void FieldField<Field, Type>::negate()
230 this->operator[](i).negate();
235 template<template<class> class Field, class Type>
236 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType> >
237 FieldField<Field, Type>::component
242 tmp<FieldField<Field, cmptType> > Component
244 FieldField<Field, typename FieldField<Field, Type>::cmptType>::
245 NewCalculatedType(*this)
248 ::Foam::component(Component(), *this, d);
254 template<template<class> class Field, class Type>
255 void FieldField<Field, Type>::replace
258 const FieldField<Field, cmptType>& sf
263 this->operator[](i).replace(d, sf[i]);
268 template<template<class> class Field, class Type>
269 void FieldField<Field, Type>::replace
277 this->operator[](i).replace(d, s);
282 template<template<class> class Field, class Type>
283 tmp<FieldField<Field, Type> > FieldField<Field, Type>::T() const
285 tmp<FieldField<Field, Type> > transpose
287 FieldField<Field, Type>::NewCalculatedType(*this)
290 ::Foam::T(transpose(), *this);
295 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
297 template<template<class> class Field, class Type>
298 void FieldField<Field, Type>::operator=(const FieldField<Field, Type>& f)
304 "FieldField<Field, Type>::"
305 "operator=(const FieldField<Field, Type>&)"
306 ) << "attempted assignment to self"
307 << abort(FatalError);
312 this->operator[](i) = f[i];
317 template<template<class> class Field, class Type>
318 void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf)
324 "FieldField<Field, Type>::operator=(const tmp<FieldField>&)"
325 ) << "attempted assignment to self"
326 << abort(FatalError);
329 // This is dodgy stuff, don't try this at home.
330 FieldField* fieldPtr = tf.ptr();
331 PtrList<Field<Type> >::transfer(*fieldPtr);
336 template<template<class> class Field, class Type>
337 void FieldField<Field, Type>::operator=(const Type& t)
341 this->operator[](i) = t;
346 #define COMPUTED_ASSIGNMENT(TYPE, op) \
348 template<template<class> class Field, class Type> \
349 void FieldField<Field, Type>::operator op(const FieldField<Field, TYPE>& f) \
353 this->operator[](i) op f[i]; \
357 template<template<class> class Field, class Type> \
358 void FieldField<Field, Type>::operator op \
360 const tmp<FieldField<Field, TYPE> >& tf \
367 template<template<class> class Field, class Type> \
368 void FieldField<Field, Type>::operator op(const TYPE& t) \
372 this->operator[](i) op t; \
376 COMPUTED_ASSIGNMENT(Type, +=)
377 COMPUTED_ASSIGNMENT(Type, -=)
378 COMPUTED_ASSIGNMENT(scalar, *=)
379 COMPUTED_ASSIGNMENT(scalar, /=)
381 #undef COMPUTED_ASSIGNMENT
384 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
386 template<template<class> class Field, class Type>
387 Ostream& operator<<(Ostream& os, const FieldField<Field, Type>& f)
389 os << static_cast<const PtrList<Field<Type> >&>(f);
394 template<template<class> class Field, class Type>
395 Ostream& operator<<(Ostream& os, const tmp<FieldField<Field, Type> >& tf)
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 } // End namespace Foam
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 # include "FieldFieldFunctions.C"
411 // ************************************************************************* //