OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     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 template friend fuctions * * * * * * * //
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 
00258     // Constructors
00259 
00260         //- Constructor given IOobject, mesh, dimensions and patch type.
00261         //  This allocates storage for the field but not values.
00262         //  Used only within this class to create TEMPORARY variables
00263         GeometricField
00264         (
00265             const IOobject&,
00266             const Mesh&,
00267             const dimensionSet&,
00268             const word& patchFieldType=PatchField<Type>::calculatedType()
00269         );
00270 
00271         //- Constructor given IOobject, mesh, dimensions and patch types.
00272         //  This allocates storage for the field but not values.
00273         //  Used only within this class to create TEMPORARY variables
00274         GeometricField
00275         (
00276             const IOobject&,
00277             const Mesh&,
00278             const dimensionSet&,
00279             const wordList& patchFieldTypes
00280         );
00281 
00282         //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
00283         GeometricField
00284         (
00285             const IOobject&,
00286             const Mesh&,
00287             const dimensioned<Type>&,
00288             const word& patchFieldType=PatchField<Type>::calculatedType()
00289         );
00290 
00291         //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
00292         GeometricField
00293         (
00294             const IOobject&,
00295             const Mesh&,
00296             const dimensioned<Type>&,
00297             const wordList& patchFieldTypes
00298         );
00299 
00300         //- Constructor from components
00301         GeometricField
00302         (
00303             const IOobject&,
00304             const Mesh&,
00305             const dimensionSet&,
00306             const Field<Type>&,
00307             const PtrList<PatchField<Type> >&
00308         );
00309 
00310         //- Construct and read given IOobject
00311         GeometricField
00312         (
00313             const IOobject&,
00314             const Mesh&
00315         );
00316 
00317         //- Construct and read from given stream
00318         GeometricField
00319         (
00320             const IOobject&,
00321             const Mesh&,
00322             Istream&
00323         );
00324 
00325         //- Construct as copy
00326         GeometricField
00327         (
00328             const GeometricField<Type, PatchField, GeoMesh>&
00329         );
00330 
00331         //- Construct as copy of tmp<GeometricField> deleting argument
00332 #       ifdef ConstructFromTmp
00333         GeometricField
00334         (
00335             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00336         );
00337 #       endif
00338 
00339         //- Construct as copy resetting IO parameters
00340         GeometricField
00341         (
00342             const IOobject&,
00343             const GeometricField<Type, PatchField, GeoMesh>&
00344         );
00345 
00346         //- Construct as copy resetting name
00347         GeometricField
00348         (
00349             const word& newName,
00350             const GeometricField<Type, PatchField, GeoMesh>&
00351         );
00352 
00353         //- Construct as copy resetting name
00354 #       ifdef ConstructFromTmp
00355         GeometricField
00356         (
00357             const word& newName,
00358             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
00359         );
00360 #       endif
00361 
00362         //- Construct as copy resetting IO parameters and patch type
00363         GeometricField
00364         (
00365             const IOobject&,
00366             const GeometricField<Type, PatchField, GeoMesh>&,
00367             const word& patchFieldType
00368         );
00369 
00370         //- Construct as copy resetting IO parameters and boundary types
00371         GeometricField
00372         (
00373             const IOobject&,
00374             const GeometricField<Type, PatchField, GeoMesh>&,
00375             const wordList& patchFieldTypes
00376         );
00377 
00378 
00379     // Destructor
00380 
00381         virtual ~GeometricField();
00382 
00383 
00384     // Member functions
00385 
00386         //- Return dimensioned internal field
00387         DimensionedInternalField& dimensionedInternalField();
00388 
00389         //- Return dimensioned internal field
00390         inline const DimensionedInternalField& dimensionedInternalField() const;
00391 
00392         //- Return internal field
00393         InternalField& internalField();
00394 
00395         //- Return internal field
00396         inline const InternalField& internalField() const;
00397 
00398         //- Return reference to GeometricBoundaryField
00399         GeometricBoundaryField& boundaryField();
00400 
00401         //- Return reference to GeometricBoundaryField for const field
00402         inline const GeometricBoundaryField& boundaryField() const;
00403 
00404         //- Return the time index of the field
00405         inline label timeIndex() const;
00406 
00407         //- Return the time index of the field
00408         inline label& timeIndex();
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         //- WriteData member function required by regIOobject
00448         bool writeData(Ostream&) const;
00449 
00450         //- Return transpose (only if it is a tensor field)
00451         tmp<GeometricField<Type, PatchField, GeoMesh> > T() const;
00452 
00453         //- Relax field (for steady-state solution).
00454         //  alpha = 1 : no relaxation
00455         //  alpha < 1 : relaxation
00456         //  alpha = 0 : do nothing
00457         void relax(const scalar alpha);
00458 
00459         //- Relax field (for steady-state solution).
00460         //  alpha is read from controlDict
00461         void relax();
00462 
00463 
00464     // Member function *this operators
00465 
00466         void negate();
00467 
00468         void replace
00469         (
00470             const direction,
00471             const GeometricField<cmptType, PatchField, GeoMesh>&
00472         );
00473 
00474         void replace
00475         (
00476             const direction,
00477             const dimensioned<cmptType>&
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 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd