OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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