1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "DimensionedField.H"
27 #include "dimensionedType.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // check mesh for two fields
37 #define checkField(df1, df2, op) \
38 if (&(df1).mesh() != &(df2).mesh()) \
40 FatalErrorIn("checkField(df1, df2, op)") \
41 << "different mesh for fields " \
42 << (df1).name() << " and " << (df2).name() \
43 << " during operatrion " << op \
44 << abort(FatalError); \
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 template<class Type, class GeoMesh>
51 DimensionedField<Type, GeoMesh>::DimensionedField
55 const dimensionSet& dims,
56 const Field<Type>& field
64 if (field.size() && field.size() != GeoMesh::size(mesh))
68 "DimensionedField<Type, GeoMesh>::DimensionedField"
69 "(const IOobject& io,const Mesh& mesh, "
70 "const dimensionSet& dims, const Field<Type>& field)"
71 ) << "size of field = " << field.size()
72 << " is not the same as the size of mesh = "
73 << GeoMesh::size(mesh)
79 template<class Type, class GeoMesh>
80 DimensionedField<Type, GeoMesh>::DimensionedField
84 const dimensionSet& dims,
85 const bool checkIOFlags
89 Field<Type>(GeoMesh::size(mesh)),
100 template<class Type, class GeoMesh>
101 DimensionedField<Type, GeoMesh>::DimensionedField
105 const dimensioned<Type>& dt,
106 const bool checkIOFlags
110 Field<Type>(GeoMesh::size(mesh), dt.value()),
112 dimensions_(dt.dimensions())
121 template<class Type, class GeoMesh>
122 DimensionedField<Type, GeoMesh>::DimensionedField
124 const DimensionedField<Type, GeoMesh>& df
130 dimensions_(df.dimensions_)
134 template<class Type, class GeoMesh>
135 DimensionedField<Type, GeoMesh>::DimensionedField
137 DimensionedField<Type, GeoMesh>& df,
141 regIOobject(df, reUse),
142 Field<Type>(df, reUse),
144 dimensions_(df.dimensions_)
148 template<class Type, class GeoMesh>
149 DimensionedField<Type, GeoMesh>::DimensionedField
151 const Xfer<DimensionedField<Type, GeoMesh> >& df
154 regIOobject(df(), true),
157 dimensions_(df->dimensions_)
161 #ifdef ConstructFromTmp
162 template<class Type, class GeoMesh>
163 DimensionedField<Type, GeoMesh>::DimensionedField
165 const tmp<DimensionedField<Type, GeoMesh> >& tdf
168 regIOobject(tdf(), tdf.isTmp()),
171 const_cast<DimensionedField<Type, GeoMesh>&>(tdf()),
175 dimensions_(tdf().dimensions_)
182 template<class Type, class GeoMesh>
183 DimensionedField<Type, GeoMesh>::DimensionedField
186 const DimensionedField<Type, GeoMesh>& df
192 dimensions_(df.dimensions_)
196 template<class Type, class GeoMesh>
197 DimensionedField<Type, GeoMesh>::DimensionedField
200 const DimensionedField<Type, GeoMesh>& df
203 regIOobject(IOobject(newName, df.time().timeName(), df.db())),
206 dimensions_(df.dimensions_)
210 template<class Type, class GeoMesh>
211 DimensionedField<Type, GeoMesh>::DimensionedField
214 DimensionedField<Type, GeoMesh>& df,
218 regIOobject(IOobject(newName, df.time().timeName(), df.db())),
219 Field<Type>(df, reUse),
221 dimensions_(df.dimensions_)
225 template<class Type, class GeoMesh>
226 DimensionedField<Type, GeoMesh>::DimensionedField
229 const Xfer<DimensionedField<Type, GeoMesh> >& df
232 regIOobject(IOobject(newName, df->time().timeName(), df->db())),
235 dimensions_(df->dimensions_)
239 #ifdef ConstructFromTmp
240 template<class Type, class GeoMesh>
241 DimensionedField<Type, GeoMesh>::DimensionedField
244 const tmp<DimensionedField<Type, GeoMesh> >& tdf
247 regIOobject(IOobject(newName, tdf().time().timeName(), tdf().db())),
250 const_cast<DimensionedField<Type, GeoMesh>&>(tdf()),
254 dimensions_(tdf().dimensions_)
261 template<class Type, class GeoMesh>
262 tmp<DimensionedField<Type, GeoMesh> >
263 DimensionedField<Type, GeoMesh>::clone() const
265 return tmp<DimensionedField<Type, GeoMesh> >
267 new DimensionedField<Type, GeoMesh>(*this)
272 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
274 template<class Type, class GeoMesh>
275 DimensionedField<Type, GeoMesh>::~DimensionedField()
279 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
281 template<class Type, class GeoMesh>
285 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
287 DimensionedField<Type, GeoMesh>::component
292 tmp<DimensionedField<cmptType, GeoMesh> > result
294 new DimensionedField<cmptType, GeoMesh>
298 name() + ".component(" + ::Foam::name(d) + ')',
307 Foam::component(result(), *this, d);
313 template<class Type, class GeoMesh>
314 void DimensionedField<Type, GeoMesh>::replace
317 const DimensionedField
318 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>& df
321 Field<Type>::replace(d, df);
325 template<class Type, class GeoMesh>
326 void DimensionedField<Type, GeoMesh>::replace
332 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
341 template<class Type, class GeoMesh>
342 tmp<DimensionedField<Type, GeoMesh> >
343 DimensionedField<Type, GeoMesh>::T() const
345 tmp<DimensionedField<Type, GeoMesh> > result
347 new DimensionedField<Type, GeoMesh>
360 Foam::T(result(), *this);
366 template<class Type, class GeoMesh>
367 dimensioned<Type> DimensionedField<Type, GeoMesh>::average() const
369 dimensioned<Type> Average
371 this->name() + ".average()",
380 template<class Type, class GeoMesh>
381 dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage
383 const DimensionedField<scalar, GeoMesh>& weightField
390 this->name() + ".weightedAverage(weights)",
392 gSum(weightField*field())/gSum(weightField)
398 template<class Type, class GeoMesh>
399 dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage
401 const tmp<DimensionedField<scalar, GeoMesh> >& tweightField
404 dimensioned<Type> wa = weightedAverage(tweightField());
405 tweightField.clear();
410 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
412 template<class Type, class GeoMesh>
413 void DimensionedField<Type, GeoMesh>::operator=
415 const DimensionedField<Type, GeoMesh>& df
418 // Check for assignment to self
423 "DimensionedField<Type, GeoMesh>::operator="
424 "(const DimensionedField<Type, GeoMesh>&)"
425 ) << "attempted assignment to self"
426 << abort(FatalError);
429 checkField(*this, df, "=");
431 dimensions_ = df.dimensions();
432 Field<Type>::operator=(df);
436 template<class Type, class GeoMesh>
437 void DimensionedField<Type, GeoMesh>::operator=
439 const tmp<DimensionedField<Type, GeoMesh> >& tdf
442 const DimensionedField<Type, GeoMesh>& df = tdf();
444 // Check for assignment to self
449 "DimensionedField<Type, GeoMesh>::operator="
450 "(const tmp<DimensionedField<Type, GeoMesh> >&)"
451 ) << "attempted assignment to self"
452 << abort(FatalError);
455 checkField(*this, df, "=");
457 dimensions_ = df.dimensions();
458 this->transfer(const_cast<DimensionedField<Type, GeoMesh>&>(df));
463 template<class Type, class GeoMesh>
464 void DimensionedField<Type, GeoMesh>::operator=
466 const dimensioned<Type>& dt
469 dimensions_ = dt.dimensions();
470 Field<Type>::operator=(dt.value());
474 #define COMPUTED_ASSIGNMENT(TYPE, op) \
476 template<class Type, class GeoMesh> \
477 void DimensionedField<Type, GeoMesh>::operator op \
479 const DimensionedField<TYPE, GeoMesh>& df \
482 checkField(*this, df, #op); \
484 dimensions_ op df.dimensions(); \
485 Field<Type>::operator op(df); \
488 template<class Type, class GeoMesh> \
489 void DimensionedField<Type, GeoMesh>::operator op \
491 const tmp<DimensionedField<TYPE, GeoMesh> >& tdf \
494 operator op(tdf()); \
498 template<class Type, class GeoMesh> \
499 void DimensionedField<Type, GeoMesh>::operator op \
501 const dimensioned<TYPE>& dt \
504 dimensions_ op dt.dimensions(); \
505 Field<Type>::operator op(dt.value()); \
508 COMPUTED_ASSIGNMENT(Type, +=)
509 COMPUTED_ASSIGNMENT(Type, -=)
510 COMPUTED_ASSIGNMENT(scalar, *=)
511 COMPUTED_ASSIGNMENT(scalar, /=)
513 #undef COMPUTED_ASSIGNMENT
516 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
520 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
522 } // End namespace Foam
524 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
526 #include "DimensionedFieldIO.C"
527 #include "DimensionedFieldFunctions.C"
529 // ************************************************************************* //