OpenFOAM logo
Open Source CFD Toolkit

GeometricField.H

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-2005 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     GeometricField<Type, PatchField, GeoMesh>
00027 
00028 Description
00029     Generic GeometricField class.
00030 
00031 SourceFiles
00032     GeometricField.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef GeometricField_H
00037 #define GeometricField_H
00038 
00039 #include "regIOobject.H"
00040 #include "dimensionedTypes.H"
00041 #include "Field.H"
00042 #include "FieldField.H"
00043 #include "scalarField.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 class dictionary;
00051 
00052 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00053 
00054 template<class Type, template<class> class PatchField, class GeoMesh>
00055 class GeometricField;
00056 
00057 template<class Type, template<class> class PatchField, class GeoMesh>
00058 Ostream& operator<<
00059 (
00060     Ostream&,
00061     const GeometricField<Type, PatchField, GeoMesh>&
00062 );
00063 
00064 template<class Type, template<class> class PatchField, class GeoMesh>
00065 Ostream& operator<<
00066 (
00067     Ostream&,
00068     const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00069 );
00070 
00071 
00072 /*---------------------------------------------------------------------------*\
00073                            Class GeometricField Declaration
00074 \*---------------------------------------------------------------------------*/
00075 
00076 template<class Type, template<class> class PatchField, class GeoMesh>
00077 class GeometricField
00078 :
00079     public regIOobject,
00080     public Field<Type>
00081 {
00082     // Private member functions
00083 
00084         //- Read from file if it is present
00085         bool readIfPresent();
00086 
00087         //- Read old time field from file if it is present
00088         bool readOldTimeIfPresent();
00089 
00090 
00091 public:
00092 
00093     // Public typedefs
00094 
00095         typedef typename GeoMesh::Mesh Mesh;
00096         typedef typename Mesh::BoundaryMesh BoundaryMesh;
00097 
00098 
00099     class GeometricBoundaryField
00100     :
00101         public FieldField<PatchField, Type>
00102     {
00103         // Private data
00104 
00105             //- Reference to BoundaryMesh for which this field is defined
00106             const BoundaryMesh& bmesh_;
00107 
00108 
00109     public:
00110 
00111         // Constructors
00112 
00113             //- Construct from a BoundaryMesh a field reference and a patch type
00114             GeometricBoundaryField
00115             (
00116                 const BoundaryMesh&,
00117                 const Field<Type>&,
00118                 const word&
00119             );
00120 
00121             //- Construct from a BoundaryMesh, field reference
00122             //  and a wordList of patch types
00123             GeometricBoundaryField
00124             (
00125                 const BoundaryMesh&,
00126                 const Field<Type>&,
00127                 const wordList&
00128             );
00129 
00130             //- Construct from a BoundaryMesh, field reference
00131             //  and a PtrList<PatchField<Type> >
00132             GeometricBoundaryField
00133             (
00134                 const BoundaryMesh&,
00135                 const Field<Type>&,
00136                 const PtrList<PatchField<Type> >&
00137             );
00138 
00139             //- Construct as copy but setting Field correctly
00140             GeometricBoundaryField
00141             (
00142                 const Field<Type>&,
00143                 const GeometricBoundaryField&
00144             );
00145 
00146             //- Construct as copy
00147             //  Dangerous because Field may be set to a field which gets deleted
00148             //  Need new type of BoundaryField, one which is part of a geometric
00149             //  field for which snGrad etc. may be called and a free standing
00150             //  BoundaryField for which such operations are unavailable.
00151             GeometricBoundaryField
00152             (
00153                 const GeometricBoundaryField&
00154             );
00155 
00156             //- Construct from dictionary
00157             GeometricBoundaryField
00158             (
00159                 const BoundaryMesh&,
00160                 const Field<Type>&,
00161                 const dictionary&
00162             );
00163 
00164 
00165         // Member functions
00166 
00167             //- Update the boundary condition coefficients
00168             void updateCoeffs();
00169 
00170             //- Evaluate boundary conditions
00171             void evaluate();
00172 
00173             //- Return a list of the patch types
00174             wordList types() const;
00175 
00176             //- Return BoundaryField of the cell values neighbouring 
00177             //  the boundary
00178             GeometricBoundaryField boundaryInternalField() const;
00179 
00180             //- Write boundary field as dictionary entry
00181             void writeEntry(const word& keyword, Ostream& os) const;
00182  
00183 
00184         // Member operators
00185 
00186             //- Assignment to BoundaryField<Type, PatchField, BoundaryMesh>
00187             void operator=
00188             (
00189                 const GeometricBoundaryField&
00190             );
00191 
00192             //- Assignment to FieldField<PatchField, Type>
00193             void operator=(const FieldField<PatchField, Type>&);
00194 
00195             //- Assignment to Type
00196             void operator=(const Type&);
00197 
00198 
00199             //- Forced assignment to 
00200             //  BoundaryField<Type, PatchField, BoundaryMesh>
00201             void operator==
00202             (
00203                 const GeometricBoundaryField&
00204             );
00205 
00206             //- Forced assignment to FieldField<PatchField, Type>
00207             void operator==(const FieldField<PatchField, Type>&);
00208 
00209             //- Forced assignment to Type
00210             void operator==(const Type&);
00211     };
00212 
00213 
00214 private:
00215 
00216     // Private data
00217 
00218         //- Reference to mesh
00219         const Mesh& mesh_;
00220 
00221         //- Dimension set
00222         dimensionSet dimensions_;
00223 
00224         //- Current time index.  
00225         //  Used to trigger the storing of the old-time value
00226         mutable label timeIndex_;
00227 
00228         //- Pointer to old time field
00229         mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
00230 
00231         //-  Pointer to previous iteration (used for under-relaxation)
00232         mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
00233 
00234         //- Boundary Type field containing boundary field values
00235         GeometricBoundaryField boundaryField_;
00236 
00237 
00238     // Private member functions
00239 
00240         tmp<GeometricBoundaryField> readField();
00241 
00242 
00243 public:
00244 
00245     //- Runtime type information
00246     TypeName("GeometricField");
00247 
00248 
00249     // Public typedefs
00250 
00251         typedef typename Field<Type>::cmptType cmptType;
00252 
00253 
00254     // Constructors
00255 
00256         //- Constructor given IOobject, mesh, dimensions and patch type.
00257         //  This allocates storage for the field but not values.
00258         //  Used only within this class to create TEMPORARY variables
00259         GeometricField
00260         (
00261             const IOobject&,
00262             const Mesh&,
00263             const dimensionSet&,
00264             const word& patchFieldType=PatchField<Type>::calculatedType()
00265         );
00266 
00267         //- Constructor given IOobject, mesh, dimensions and patch types.
00268         //  This allocates storage for the field but not values.
00269         //  Used only within this class to create TEMPORARY variables
00270         GeometricField
00271         (
00272             const IOobject&,
00273             const Mesh&,
00274             const dimensionSet&,
00275             const wordList& patchFieldTypes
00276         );
00277 
00278         //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
00279         GeometricField
00280         (
00281             const IOobject&,
00282             const Mesh&,
00283             const dimensioned<Type>&,
00284             const word& patchFieldType=PatchField<Type>::calculatedType()
00285         );
00286 
00287         //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
00288         GeometricField
00289         (
00290             const IOobject&,
00291             const Mesh&,
00292             const dimensioned<Type>&,
00293             const wordList& patchFieldTypes
00294         );
00295 
00296         //- Constructor from components
00297         GeometricField
00298         (
00299             const IOobject&,
00300             const Mesh&,
00301             const dimensionSet&,
00302             const Field<Type>&,
00303             const PtrList<PatchField<Type> >&
00304         );
00305 
00306         //- Construct and read
00307         GeometricField
00308         (
00309             const IOobject&,
00310             const Mesh&
00311         );
00312 
00313         //- Construct as copy
00314         GeometricField
00315         (
00316             const GeometricField<Type, PatchField, GeoMesh>&
00317         );
00318 
00319         //- Construct as copy of tmp<GeometricField> deleting argument
00320 #       ifdef ConstructFromTmp
00321         GeometricField
00322         (
00323             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00324         );
00325 #       endif
00326 
00327         //- Construct as copy resetting IO parameters
00328         GeometricField
00329         (
00330             const IOobject&,
00331             const GeometricField<Type, PatchField, GeoMesh>&
00332         );
00333 
00334         //- Construct as copy resetting name
00335         GeometricField
00336         (
00337             const word& newName,
00338             const GeometricField<Type, PatchField, GeoMesh>&
00339         );
00340 
00341         //- Construct as copy resetting name
00342 #       ifdef ConstructFromTmp
00343         GeometricField
00344         (
00345             const word& newName,
00346             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00347         );
00348 #       endif
00349 
00350         //- Construct as copy resetting IO parameters and patch type
00351         GeometricField
00352         (
00353             const IOobject&,
00354             const GeometricField<Type, PatchField, GeoMesh>&,
00355             const word& patchFieldType
00356         );
00357 
00358         //- Construct as copy resetting IO parameters and boundary types
00359         GeometricField
00360         (
00361             const IOobject&,
00362             const GeometricField<Type, PatchField, GeoMesh>&,
00363             const wordList& patchFieldTypes
00364         );
00365 
00366 
00367     // Selectors
00368 
00369         //- Return a pointer to a GeometricField created by re-using the given
00370         //  tmp<GeometricField>
00371         static tmp<GeometricField<Type, PatchField, GeoMesh> > New
00372         (
00373             const IOobject&,
00374             const tmp<GeometricField<Type, PatchField, GeoMesh> >&,
00375             const dimensionSet&
00376         );
00377 
00378 
00379     // Destructor
00380 
00381         virtual ~GeometricField();
00382 
00383 
00384     // Member functions
00385 
00386         //- Return reference to mesh
00387         inline const Mesh& mesh() const;
00388 
00389         //- Return dimensions
00390         inline dimensionSet& dimensions();
00391 
00392         //- Return dimensions
00393         inline const dimensionSet& dimensions() const;
00394 
00395         //- Return internal field
00396         Field<Type>& internalField();
00397 
00398         //- Return internal field
00399         inline const Field<Type>& internalField() const;
00400 
00401         //- Return reference to GeometricBoundaryField
00402         GeometricBoundaryField& boundaryField();
00403 
00404         //- Return reference to GeometricBoundaryField for const field
00405         inline const GeometricBoundaryField& boundaryField() const;
00406 
00407         //- Return the time index of the field
00408         inline label timeIndex() const;
00409 
00410         //- Store the old-time fields
00411         void storeOldTimes() const;
00412 
00413         //- Store the old-time field
00414         void storeOldTime() const;
00415 
00416         //- Return the number of old time fields stored
00417         label nOldTimes() const;
00418 
00419         //- Return old time field
00420         const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;
00421 
00422         //- Return non-const old time field
00423         //  (Not a good idea but it is used for sub-cycling)
00424         GeometricField<Type, PatchField, GeoMesh>& oldTime();
00425 
00426         //- Store the field as the previous iteration value
00427         void storePrevIter() const;
00428 
00429         //- Return previous iteration field
00430         const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;
00431 
00432         //- Correct boundary field
00433         void correctBoundaryConditions();
00434 
00435         //- Does the field need a reference level for solution
00436         bool needReference() const;
00437 
00438         //- Return a null geometric field
00439         static GeometricField<Type, PatchField, GeoMesh>& null();
00440 
00441         //- Return a component of the field
00442         tmp<GeometricField<cmptType, PatchField, GeoMesh> > component
00443         (
00444             const direction
00445         ) const;
00446 
00447         //- Calculate and return arithmetic average
00448         dimensioned<Type> average() const;
00449 
00450         //- Calculate and return weighted average
00451         dimensioned<Type> weightedAverage(const scalarField&) const;
00452 
00453         //- WriteData member function required by regIOobject
00454         bool writeData(Ostream&) const;
00455 
00456         //- Return transpose (only if it is a tensor field)
00457         tmp<GeometricField<Type, PatchField, GeoMesh> > T() const;
00458 
00459         //- Relax field (for steady-state solution).
00460         //  alpha = 1 : no relaxation
00461         //  alpha < 1 : relaxation
00462         //  alpha = 0 : do nothing
00463         void relax(const scalar alpha);
00464 
00465         //- Relax field (for steady-state solution).
00466         //  alpha is read from controlDict
00467         void relax();
00468 
00469 
00470     // Member function *this operators
00471 
00472         void negate();
00473 
00474         void replace
00475         (
00476             const direction,
00477             const GeometricField<cmptType, PatchField, GeoMesh>&
00478         );
00479 
00480         void max(const dimensioned<Type>&);
00481         void min(const dimensioned<Type>&);
00482 
00483         void max
00484         (
00485             const GeometricField<Type, PatchField, GeoMesh>&,
00486             const dimensioned<Type>&
00487         );
00488 
00489         void min
00490         (
00491             const GeometricField<Type, PatchField, GeoMesh>&,
00492             const dimensioned<Type>&
00493         );
00494 
00495         void scale
00496         (
00497             const GeometricField<Type, PatchField, GeoMesh>&,
00498             const GeometricField<Type, PatchField, GeoMesh>&
00499         );
00500 
00501         void scale
00502         (
00503             const GeometricField<Type, PatchField, GeoMesh>&,
00504             const dimensioned<Type>&
00505         );
00506 
00507 
00508     // Member operators
00509 
00510         void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
00511         void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
00512         void operator=(const dimensioned<Type>&);
00513 
00514         void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
00515         void operator==(const dimensioned<Type>&);
00516 
00517         void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
00518         void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
00519 
00520         void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
00521         void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
00522 
00523         void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
00524         void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
00525 
00526         void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&);
00527         void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
00528 
00529         void operator+=(const dimensioned<Type>&);
00530         void operator-=(const dimensioned<Type>&);
00531 
00532         void operator*=(const dimensioned<scalar>&);
00533         void operator/=(const dimensioned<scalar>&);
00534 
00535 
00536     // Ostream operators
00537 
00538         friend Ostream& operator<< <Type, PatchField, GeoMesh>
00539         (
00540             Ostream&,
00541             const GeometricField<Type, PatchField, GeoMesh>&
00542         );
00543 
00544         friend Ostream& operator<< <Type, PatchField, GeoMesh>
00545         (
00546             Ostream&,
00547             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00548         );
00549 };
00550 
00551 
00552 template<class Type, template<class> class PatchField, class GeoMesh>
00553 Ostream& operator<<
00554 (
00555     Ostream&,
00556     const typename GeometricField<Type, PatchField, GeoMesh>::
00557     GeometricBoundaryField&
00558 );
00559 
00560 
00561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00562 
00563 } // End namespace Foam
00564 
00565 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00566 
00567 #include "GeometricFieldI.H"
00568 
00569 #ifdef NoRepository
00570 #   include "GeometricField.C"
00571 #endif
00572 
00573 #include "GeometricFieldFunctions.H"
00574 
00575 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00576 
00577 #endif
00578 
00579 // ************************************************************************* //
For further information go to www.openfoam.org