FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

DimensionedField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "DimensionedField.H"
00027 #include <OpenFOAM/dimensionedType.H>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 // check mesh for two fields
00037 #define checkField(df1, df2, op)                                    \
00038 if (&(df1).mesh() != &(df2).mesh())                                 \
00039 {                                                                   \
00040     FatalErrorIn("checkField(df1, df2, op)")                        \
00041         << "different mesh for fields "                             \
00042         << (df1).name() << " and " << (df2).name()                  \
00043         << " during operatrion " <<  op                             \
00044         << abort(FatalError);                                       \
00045 }
00046 
00047 
00048 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00049 
00050 template<class Type, class GeoMesh>
00051 DimensionedField<Type, GeoMesh>::DimensionedField
00052 (
00053     const IOobject& io,
00054     const Mesh& mesh,
00055     const dimensionSet& dims,
00056     const Field<Type>& field
00057 )
00058 :
00059     regIOobject(io),
00060     Field<Type>(field),
00061     mesh_(mesh),
00062     dimensions_(dims)
00063 {
00064     if (field.size() && field.size() != GeoMesh::size(mesh))
00065     {
00066         FatalErrorIn
00067         (
00068             "DimensionedField<Type, GeoMesh>::DimensionedField"
00069             "(const IOobject& io,const Mesh& mesh, "
00070             "const dimensionSet& dims, const Field<Type>& field)"
00071         )   << "size of field = " << field.size()
00072             << " is not the same as the size of mesh = "
00073             << GeoMesh::size(mesh)
00074             << abort(FatalError);
00075     }
00076 }
00077 
00078 
00079 template<class Type, class GeoMesh>
00080 DimensionedField<Type, GeoMesh>::DimensionedField
00081 (
00082     const IOobject& io,
00083     const Mesh& mesh,
00084     const dimensionSet& dims
00085 )
00086 :
00087     regIOobject(io),
00088     Field<Type>(GeoMesh::size(mesh)),
00089     mesh_(mesh),
00090     dimensions_(dims)
00091 {}
00092 
00093 
00094 template<class Type, class GeoMesh>
00095 DimensionedField<Type, GeoMesh>::DimensionedField
00096 (
00097     const IOobject& io,
00098     const Mesh& mesh,
00099     const dimensioned<Type>& dt
00100 )
00101 :
00102     regIOobject(io),
00103     Field<Type>(GeoMesh::size(mesh), dt.value()),
00104     mesh_(mesh),
00105     dimensions_(dt.dimensions())
00106 {}
00107 
00108 
00109 template<class Type, class GeoMesh>
00110 DimensionedField<Type, GeoMesh>::DimensionedField
00111 (
00112     const DimensionedField<Type, GeoMesh>& df
00113 )
00114 :
00115 #   ifdef ConstructFromTmp
00116     regIOobject(df),
00117 #   else
00118     regIOobject(df, true),
00119 #   endif
00120     Field<Type>(df),
00121     mesh_(df.mesh_),
00122     dimensions_(df.dimensions_)
00123 {}
00124 
00125 
00126 template<class Type, class GeoMesh>
00127 DimensionedField<Type, GeoMesh>::DimensionedField
00128 (
00129     DimensionedField<Type, GeoMesh>& df,
00130     bool reUse
00131 )
00132 :
00133     regIOobject(df, true),
00134     Field<Type>(df, reUse),
00135     mesh_(df.mesh_),
00136     dimensions_(df.dimensions_)
00137 {}
00138 
00139 
00140 template<class Type, class GeoMesh>
00141 DimensionedField<Type, GeoMesh>::DimensionedField
00142 (
00143     const Xfer<DimensionedField<Type, GeoMesh> >& df
00144 )
00145 :
00146     regIOobject(df(), true),
00147     Field<Type>(df),
00148     mesh_(df->mesh_),
00149     dimensions_(df->dimensions_)
00150 {}
00151 
00152 
00153 #ifdef ConstructFromTmp
00154 template<class Type, class GeoMesh>
00155 DimensionedField<Type, GeoMesh>::DimensionedField
00156 (
00157     const tmp<DimensionedField<Type, GeoMesh> >& tdf
00158 )
00159 :
00160     regIOobject(tdf(), true),
00161     Field<Type>
00162     (
00163         const_cast<DimensionedField<Type, GeoMesh>&>(tdf()),
00164         tdf.isTmp()
00165     ),
00166     mesh_(tdf().mesh_),
00167     dimensions_(tdf().dimensions_)
00168 {
00169     tdf.clear();
00170 }
00171 #endif
00172 
00173 
00174 template<class Type, class GeoMesh>
00175 DimensionedField<Type, GeoMesh>::DimensionedField
00176 (
00177     const IOobject& io,
00178     const DimensionedField<Type, GeoMesh>& df
00179 )
00180 :
00181     regIOobject(io),
00182     Field<Type>(df),
00183     mesh_(df.mesh_),
00184     dimensions_(df.dimensions_)
00185 {}
00186 
00187 
00188 template<class Type, class GeoMesh>
00189 DimensionedField<Type, GeoMesh>::DimensionedField
00190 (
00191     const word& newName,
00192     const DimensionedField<Type, GeoMesh>& df
00193 )
00194 :
00195     regIOobject(IOobject(newName, df.time().timeName(), df.db())),
00196     Field<Type>(df),
00197     mesh_(df.mesh_),
00198     dimensions_(df.dimensions_)
00199 {}
00200 
00201 
00202 template<class Type, class GeoMesh>
00203 DimensionedField<Type, GeoMesh>::DimensionedField
00204 (
00205     const word& newName,
00206     DimensionedField<Type, GeoMesh>& df,
00207     bool reUse
00208 )
00209 :
00210     regIOobject(IOobject(newName, df.time().timeName(), df.db())),
00211     Field<Type>(df, reUse),
00212     mesh_(df.mesh_),
00213     dimensions_(df.dimensions_)
00214 {}
00215 
00216 
00217 template<class Type, class GeoMesh>
00218 DimensionedField<Type, GeoMesh>::DimensionedField
00219 (
00220     const word& newName,
00221     const Xfer<DimensionedField<Type, GeoMesh> >& df
00222 )
00223 :
00224     regIOobject(IOobject(newName, df->time().timeName(), df->db())),
00225     Field<Type>(df),
00226     mesh_(df->mesh_),
00227     dimensions_(df->dimensions_)
00228 {}
00229 
00230 
00231 #ifdef ConstructFromTmp
00232 template<class Type, class GeoMesh>
00233 DimensionedField<Type, GeoMesh>::DimensionedField
00234 (
00235     const word& newName,
00236     const tmp<DimensionedField<Type, GeoMesh> >& tdf
00237 )
00238 :
00239     regIOobject(IOobject(newName, tdf().time().timeName(), tdf().db())),
00240     Field<Type>
00241     (
00242         const_cast<DimensionedField<Type, GeoMesh>&>(tdf()),
00243         tdf.isTmp()
00244     ),
00245     mesh_(tdf().mesh_),
00246     dimensions_(tdf().dimensions_)
00247 {
00248     tdf().clear();
00249 }
00250 #endif
00251 
00252 
00253 template<class Type, class GeoMesh>
00254 tmp<DimensionedField<Type, GeoMesh> >
00255 DimensionedField<Type, GeoMesh>::clone() const
00256 {
00257     return tmp<DimensionedField<Type, GeoMesh> >
00258     (
00259         new DimensionedField<Type, GeoMesh>(*this)
00260     );
00261 }
00262 
00263 
00264 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00265 
00266 template<class Type, class GeoMesh>
00267 DimensionedField<Type, GeoMesh>::~DimensionedField()
00268 {}
00269 
00270 
00271 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00272 
00273 template<class Type, class GeoMesh>
00274 tmp
00275 <
00276     DimensionedField
00277         <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
00278 >
00279 DimensionedField<Type, GeoMesh>::component
00280 (
00281     const direction d
00282 ) const
00283 {
00284     tmp<DimensionedField<cmptType, GeoMesh> > result
00285     (
00286         new DimensionedField<cmptType, GeoMesh>
00287         (
00288             IOobject
00289             (
00290                 name() + ".component(" + ::Foam::name(d) + ')',
00291                 instance(),
00292                 db()
00293             ),
00294             mesh_,
00295             dimensions_
00296         )
00297     );
00298 
00299     Foam::component(result(), *this, d);
00300 
00301     return result;
00302 }
00303 
00304 
00305 template<class Type, class GeoMesh>
00306 void DimensionedField<Type, GeoMesh>::replace
00307 (
00308     const direction d,
00309     const DimensionedField
00310         <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>& df
00311 )
00312 {
00313     Field<Type>::replace(d, df);
00314 }
00315 
00316 
00317 template<class Type, class GeoMesh>
00318 void DimensionedField<Type, GeoMesh>::replace
00319 (
00320     const direction d,
00321     const tmp
00322     <
00323         DimensionedField
00324             <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
00325     >& tdf
00326 )
00327 {
00328     replace(d, tdf());
00329     tdf.clear();
00330 }
00331 
00332 
00333 template<class Type, class GeoMesh>
00334 tmp<DimensionedField<Type, GeoMesh> >
00335 DimensionedField<Type, GeoMesh>::T() const
00336 {
00337     tmp<DimensionedField<Type, GeoMesh> > result
00338     (
00339         new DimensionedField<Type, GeoMesh>
00340         (
00341             IOobject
00342             (
00343                 name() + ".T()",
00344                 instance(),
00345                 db()
00346             ),
00347             mesh_,
00348             dimensions_
00349         )
00350     );
00351 
00352     Foam::T(result(), *this);
00353 
00354     return result;
00355 }
00356 
00357 
00358 template<class Type, class GeoMesh>
00359 dimensioned<Type> DimensionedField<Type, GeoMesh>::average() const
00360 {
00361     dimensioned<Type> Average
00362     (
00363         this->name() + ".average()",
00364         this->dimensions(),
00365         gAverage(field())
00366     );
00367 
00368     return Average;
00369 }
00370 
00371 
00372 template<class Type, class GeoMesh>
00373 dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage
00374 (
00375     const DimensionedField<scalar, GeoMesh>& weightField
00376 ) const
00377 {
00378     return
00379     (
00380         dimensioned<Type>
00381         (
00382             this->name() + ".weightedAverage(weights)",
00383             this->dimensions(),
00384             gSum(weightField*field())/gSum(weightField)
00385         )
00386     );
00387 }
00388 
00389 
00390 template<class Type, class GeoMesh>
00391 dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage
00392 (
00393     const tmp<DimensionedField<scalar, GeoMesh> >& tweightField
00394 ) const
00395 {
00396     dimensioned<Type> wa = weightedAverage(tweightField());
00397     tweightField.clear();
00398     return wa;
00399 }
00400 
00401 
00402 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00403 
00404 template<class Type, class GeoMesh>
00405 void DimensionedField<Type, GeoMesh>::operator=
00406 (
00407     const DimensionedField<Type, GeoMesh>& df
00408 )
00409 {
00410     // Check for assignment to self
00411     if (this == &df)
00412     {
00413         FatalErrorIn
00414         (
00415             "DimensionedField<Type, GeoMesh>::operator="
00416             "(const DimensionedField<Type, GeoMesh>&)"
00417         )   << "attempted assignment to self"
00418             << abort(FatalError);
00419     }
00420 
00421     checkField(*this, df, "=");
00422 
00423     dimensions_ = df.dimensions();
00424     Field<Type>::operator=(df);
00425 }
00426 
00427 
00428 template<class Type, class GeoMesh>
00429 void DimensionedField<Type, GeoMesh>::operator=
00430 (
00431     const tmp<DimensionedField<Type, GeoMesh> >& tdf
00432 )
00433 {
00434     const DimensionedField<Type, GeoMesh>& df = tdf();
00435 
00436     // Check for assignment to self
00437     if (this == &df)
00438     {
00439         FatalErrorIn
00440         (
00441             "DimensionedField<Type, GeoMesh>::operator="
00442             "(const tmp<DimensionedField<Type, GeoMesh> >&)"
00443         )   << "attempted assignment to self"
00444             << abort(FatalError);
00445     }
00446 
00447     checkField(*this, df, "=");
00448 
00449     dimensions_ = df.dimensions();
00450     this->transfer(const_cast<DimensionedField<Type, GeoMesh>&>(df));
00451     tdf.clear();
00452 }
00453 
00454 
00455 template<class Type, class GeoMesh>
00456 void DimensionedField<Type, GeoMesh>::operator=
00457 (
00458     const dimensioned<Type>& dt
00459 )
00460 {
00461     dimensions_ = dt.dimensions();
00462     Field<Type>::operator=(dt.value());
00463 }
00464 
00465 
00466 #define COMPUTED_ASSIGNMENT(TYPE, op)                                         \
00467                                                                               \
00468 template<class Type, class GeoMesh>                                           \
00469 void DimensionedField<Type, GeoMesh>::operator op                             \
00470 (                                                                             \
00471     const DimensionedField<TYPE, GeoMesh>& df                                 \
00472 )                                                                             \
00473 {                                                                             \
00474     checkField(*this, df, #op);                                               \
00475                                                                               \
00476     dimensions_ op df.dimensions();                                           \
00477     Field<Type>::operator op(df);                                             \
00478 }                                                                             \
00479                                                                               \
00480 template<class Type, class GeoMesh>                                           \
00481 void DimensionedField<Type, GeoMesh>::operator op                             \
00482 (                                                                             \
00483     const tmp<DimensionedField<TYPE, GeoMesh> >& tdf                          \
00484 )                                                                             \
00485 {                                                                             \
00486     operator op(tdf());                                                       \
00487     tdf.clear();                                                              \
00488 }                                                                             \
00489                                                                               \
00490 template<class Type, class GeoMesh>                                           \
00491 void DimensionedField<Type, GeoMesh>::operator op                             \
00492 (                                                                             \
00493     const dimensioned<TYPE>& dt                                               \
00494 )                                                                             \
00495 {                                                                             \
00496     dimensions_ op dt.dimensions();                                           \
00497     Field<Type>::operator op(dt.value());                                     \
00498 }
00499 
00500 COMPUTED_ASSIGNMENT(Type, +=)
00501 COMPUTED_ASSIGNMENT(Type, -=)
00502 COMPUTED_ASSIGNMENT(scalar, *=)
00503 COMPUTED_ASSIGNMENT(scalar, /=)
00504 
00505 #undef COMPUTED_ASSIGNMENT
00506 
00507 
00508 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00509 
00510 #undef checkField
00511 
00512 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00513 
00514 } // End namespace Foam
00515 
00516 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00517 
00518 #include "DimensionedFieldIO.C"
00519 #include "DimensionedFieldFunctions.C"
00520 
00521 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines