00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "FieldField.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037 #ifdef FULLDEBUG
00038
00039 template<template<class> class Field, class Type1, class Type2>
00040 void checkFields
00041 (
00042 const FieldField<Field, Type1>& f1,
00043 const FieldField<Field, Type2>& f2,
00044 const char* op
00045 )
00046 {
00047 if (f1.size() != f2.size())
00048 {
00049 FatalErrorIn
00050 (
00051 "checkFields(const FieldField<Field, Type1>&, "
00052 "const FieldField<Field, Type2>&, const char* op)"
00053 ) << " incompatible fields"
00054 << " FieldField<" << pTraits<Type1>::typeName
00055 << "> f1(" << f1.size() << ')'
00056 << " and FieldField<" << pTraits<Type2>::typeName
00057 << "> f2(" << f2.size() << ')'
00058 << endl << " for operation " << op
00059 << abort(FatalError);
00060 }
00061 }
00062
00063 template<template<class> class Field, class Type1, class Type2, class Type3>
00064 void checkFields
00065 (
00066 const FieldField<Field, Type1>& f1,
00067 const FieldField<Field, Type2>& f2,
00068 const FieldField<Field, Type3>& f3,
00069 const char* op
00070 )
00071 {
00072 if (f1.size() != f2.size() || f1.size() != f3.size())
00073 {
00074 FatalErrorIn
00075 (
00076 "checkFields(const FieldField<Field, Type1>&, "
00077 "const FieldField<Field, Type2>&, "
00078 "const FieldField<Field, Type3>&, "
00079 "const char* op)"
00080 ) << " incompatible fields"
00081 << " FieldField<" << pTraits<Type1>::typeName
00082 << "> f1(" << f1.size() << ')'
00083 << ", FieldField<" <<pTraits<Type2>::typeName
00084 << "> f2(" << f2.size() << ')'
00085 << " and FieldField<"<<pTraits<Type3>::typeName
00086 << "> f3("<<f3.size() << ')'
00087 << endl << " for operation " << op
00088 << abort(FatalError);
00089 }
00090 }
00091
00092 #else
00093
00094 template<template<class> class Field, class Type1, class Type2>
00095 void checkFields
00096 (
00097 const FieldField<Field, Type1>&,
00098 const FieldField<Field, Type2>&,
00099 const char* op
00100 )
00101 {}
00102
00103 template<template<class> class Field, class Type1, class Type2, class Type3>
00104 void checkFields
00105 (
00106 const FieldField<Field, Type1>&,
00107 const FieldField<Field, Type2>&,
00108 const FieldField<Field, Type3>&,
00109 const char* op
00110 )
00111 {}
00112
00113 #endif
00114
00115
00116
00117
00118 template<template<class> class Field, class Type>
00119 FieldField<Field, Type>::FieldField()
00120 :
00121 PtrList<Field<Type> >()
00122 {}
00123
00124
00125 template<template<class> class Field, class Type>
00126 FieldField<Field, Type>::FieldField(const label size)
00127 :
00128 PtrList<Field<Type> >(size)
00129 {}
00130
00131
00132 template<template<class> class Field, class Type>
00133 FieldField<Field, Type>::FieldField
00134 (
00135 const word& type,
00136 const FieldField<Field, Type>& ff
00137 )
00138 :
00139 PtrList<Field<Type> >(ff.size())
00140 {
00141 forAll(*this, i)
00142 {
00143 set(i, Field<Type>::New(type, ff[i]));
00144 }
00145 }
00146
00147
00148 template<template<class> class Field, class Type>
00149 FieldField<Field, Type>::FieldField(const FieldField<Field, Type>& f)
00150 :
00151 refCount(),
00152 PtrList<Field<Type> >(f)
00153 {}
00154
00155
00156 template<template<class> class Field, class Type>
00157 FieldField<Field, Type>::FieldField(FieldField<Field, Type>& f, bool reUse)
00158 :
00159 refCount(),
00160 PtrList<Field<Type> >(f, reUse)
00161 {}
00162
00163
00164 template<template<class> class Field, class Type>
00165 FieldField<Field, Type>::FieldField(const PtrList<Field<Type> >& tl)
00166 :
00167 PtrList<Field<Type> >(tl)
00168 {}
00169
00170
00171
00172 #ifdef ConstructFromTmp
00173 template<template<class> class Field, class Type>
00174 FieldField<Field, Type>::FieldField(const tmp<FieldField<Field, Type> >& tf)
00175 :
00176 PtrList<Field<Type> >
00177 (
00178 const_cast<FieldField<Field, Type>&>(tf()),
00179 tf.isTmp()
00180 )
00181 {
00182 const_cast<FieldField<Field, Type>&>(tf()).resetRefCount();
00183 }
00184 #endif
00185
00186
00187 template<template<class> class Field, class Type>
00188 FieldField<Field, Type>::FieldField(Istream& is)
00189 :
00190 PtrList<Field<Type> >(is)
00191 {}
00192
00193
00194 template<template<class> class Field, class Type>
00195 tmp<FieldField<Field, Type> > FieldField<Field, Type>::clone() const
00196 {
00197 return tmp<FieldField<Field, Type> >(new FieldField<Field, Type>(*this));
00198 }
00199
00200
00201 #ifndef __INTEL_COMPILER
00202 template<template<class> class Field, class Type>
00203 template<class Type2>
00204 tmp<FieldField<Field, Type> > FieldField<Field, Type>::NewCalculatedType
00205 (
00206 const FieldField<Field, Type2>& ff
00207 )
00208 {
00209 FieldField<Field, Type>* nffPtr
00210 (
00211 new FieldField<Field, Type>(ff.size())
00212 );
00213
00214 forAll(*nffPtr, i)
00215 {
00216 nffPtr->set(i, Field<Type>::NewCalculatedType(ff[i]).ptr());
00217 }
00218
00219 return tmp<FieldField<Field, Type> >(nffPtr);
00220 }
00221 #endif
00222
00223
00224
00225
00226 template<template<class> class Field, class Type>
00227 void FieldField<Field, Type>::negate()
00228 {
00229 forAll(*this, i)
00230 {
00231 this->operator[](i).negate();
00232 }
00233 }
00234
00235
00236 template<template<class> class Field, class Type>
00237 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType> >
00238 FieldField<Field, Type>::component
00239 (
00240 const direction d
00241 ) const
00242 {
00243 tmp<FieldField<Field, cmptType> > Component
00244 (
00245 FieldField<Field, typename FieldField<Field, Type>::cmptType>::
00246 NewCalculatedType(*this)
00247 );
00248
00249 ::Foam::component(Component(), *this, d);
00250
00251 return Component;
00252 }
00253
00254
00255 template<template<class> class Field, class Type>
00256 void FieldField<Field, Type>::replace
00257 (
00258 const direction d,
00259 const FieldField<Field, cmptType>& sf
00260 )
00261 {
00262 forAll(*this, i)
00263 {
00264 this->operator[](i).replace(d, sf[i]);
00265 }
00266 }
00267
00268
00269 template<template<class> class Field, class Type>
00270 void FieldField<Field, Type>::replace
00271 (
00272 const direction d,
00273 const cmptType& s
00274 )
00275 {
00276 forAll(*this, i)
00277 {
00278 this->operator[](i).replace(d, s);
00279 }
00280 }
00281
00282
00283 template<template<class> class Field, class Type>
00284 tmp<FieldField<Field, Type> > FieldField<Field, Type>::T() const
00285 {
00286 tmp<FieldField<Field, Type> > transpose
00287 (
00288 FieldField<Field, Type>::NewCalculatedType(*this)
00289 );
00290
00291 ::Foam::T(transpose(), *this);
00292 return transpose;
00293 }
00294
00295
00296
00297
00298 template<template<class> class Field, class Type>
00299 void FieldField<Field, Type>::operator=(const FieldField<Field, Type>& f)
00300 {
00301 if (this == &f)
00302 {
00303 FatalErrorIn
00304 (
00305 "FieldField<Field, Type>::"
00306 "operator=(const FieldField<Field, Type>&)"
00307 ) << "attempted assignment to self"
00308 << abort(FatalError);
00309 }
00310
00311 forAll(*this, i)
00312 {
00313 this->operator[](i) = f[i];
00314 }
00315 }
00316
00317
00318 template<template<class> class Field, class Type>
00319 void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf)
00320 {
00321 if (this == &(tf()))
00322 {
00323 FatalErrorIn
00324 (
00325 "FieldField<Field, Type>::operator=(const tmp<FieldField>&)"
00326 ) << "attempted assignment to self"
00327 << abort(FatalError);
00328 }
00329
00330
00331 FieldField* fieldPtr = tf.ptr();
00332 PtrList<Field<Type> >::transfer(*fieldPtr);
00333 delete fieldPtr;
00334 }
00335
00336
00337 template<template<class> class Field, class Type>
00338 void FieldField<Field, Type>::operator=(const Type& t)
00339 {
00340 forAll(*this, i)
00341 {
00342 this->operator[](i) = t;
00343 }
00344 }
00345
00346
00347 #define COMPUTED_ASSIGNMENT(TYPE, op) \
00348 \
00349 template<template<class> class Field, class Type> \
00350 void FieldField<Field, Type>::operator op(const FieldField<Field, TYPE>& f) \
00351 { \
00352 forAll(*this, i) \
00353 { \
00354 this->operator[](i) op f[i]; \
00355 } \
00356 } \
00357 \
00358 template<template<class> class Field, class Type> \
00359 void FieldField<Field, Type>::operator op \
00360 ( \
00361 const tmp<FieldField<Field, TYPE> >& tf \
00362 ) \
00363 { \
00364 operator op(tf()); \
00365 tf.clear(); \
00366 } \
00367 \
00368 template<template<class> class Field, class Type> \
00369 void FieldField<Field, Type>::operator op(const TYPE& t) \
00370 { \
00371 forAll(*this, i) \
00372 { \
00373 this->operator[](i) op t; \
00374 } \
00375 }
00376
00377 COMPUTED_ASSIGNMENT(Type, +=)
00378 COMPUTED_ASSIGNMENT(Type, -=)
00379 COMPUTED_ASSIGNMENT(scalar, *=)
00380 COMPUTED_ASSIGNMENT(scalar, /=)
00381
00382 #undef COMPUTED_ASSIGNMENT
00383
00384
00385
00386
00387 template<template<class> class Field, class Type>
00388 Ostream& operator<<(Ostream& os, const FieldField<Field, Type>& f)
00389 {
00390 os << static_cast<const PtrList<Field<Type> >&>(f);
00391 return os;
00392 }
00393
00394
00395 template<template<class> class Field, class Type>
00396 Ostream& operator<<(Ostream& os, const tmp<FieldField<Field, Type> >& tf)
00397 {
00398 os << tf();
00399 tf.clear();
00400 return os;
00401 }
00402
00403
00404
00405
00406 }
00407
00408
00409
00410 # include "FieldFieldFunctions.C"
00411
00412