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

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