OpenFOAM logo
Open Source CFD Toolkit

fvPatchField.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     fvPatchField
00027 
00028 Description
00029     fvPatchField<Type> abstract base class.  This class gives a fat-interface
00030     to all derived classes covering all possible ways in which they might be
00031     used.  The first level of derivation is to basic patchFields which cover
00032     zero-gradient, fixed-gradient, fixed-value and mixed conditions.  The next
00033     level of derivation covers all the specialised typed with specific
00034     evaluation proceedures, particularly with respect to specific fields.
00035 
00036 SourceFiles
00037     fvPatchField.C
00038     newPatchField.C
00039 
00040 \*---------------------------------------------------------------------------*/
00041 
00042 #ifndef fvPatchField_H
00043 #define fvPatchField_H
00044 
00045 #include "fvPatch.H"
00046 #include "primitiveFields.H"
00047 #include "lduCoupledInterface.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 class objectRegistry;
00055 class dictionary;
00056 class fvPatchFieldMapper;
00057 class lduMatrix;
00058 
00059 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00060 
00061 template<class Type>
00062 class fvPatchField;
00063 
00064 template<class Type>
00065 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
00066 
00067 
00068 /*---------------------------------------------------------------------------*\
00069                            Class patch Declaration
00070 \*---------------------------------------------------------------------------*/
00071 
00072 template<class Type>
00073 class fvPatchField
00074 :
00075     virtual public lduCoupledInterface,
00076     public Field<Type>
00077 {
00078     // Private data
00079 
00080         const fvPatch& patch_;
00081         const Field<Type>& internalField_;
00082 
00083         //- Update index used so that updateCoeffs is called only once during
00084         //  the construction of the matrix
00085         bool updated_;
00086 
00087 
00088     // Private member functions
00089 
00090         void checkPatch() const;
00091         void checkInternalField() const;
00092 
00093 
00094 public:
00095 
00096     typedef fvPatch Patch;
00097 
00098 
00099     //- Runtime type information
00100     TypeName("fvPatchField");
00101 
00102     //- Debug switch to disallow the use of 
00103     static int disallowDefaultFvPatchField;
00104 
00105 
00106     // Declare run-time constructor selection tables
00107 
00108         declareRunTimeSelectionTable
00109         (
00110             tmp,
00111             fvPatchField,
00112             patch,
00113             (const fvPatch& p, const Field<Type>& iF),
00114             (p, iF)
00115         );
00116 
00117         declareRunTimeSelectionTable
00118         (
00119             tmp,
00120             fvPatchField,
00121             patchMapper,
00122             (
00123                 const fvPatchField<Type>& ptf,
00124                 const fvPatch& p,
00125                 const Field<Type>& iF,
00126                 const fvPatchFieldMapper& m
00127             ),
00128             (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
00129         );
00130 
00131         declareRunTimeSelectionTable
00132         (
00133             tmp,
00134             fvPatchField,
00135             dictionary,
00136             (const fvPatch& p, const Field<Type>& iF, const dictionary& dict),
00137             (p, iF, dict)
00138         );
00139 
00140 
00141     // Constructors
00142 
00143         //- Construct from patch and internal field
00144         fvPatchField
00145         (
00146             const fvPatch&,
00147             const Field<Type>&
00148         );
00149 
00150         //- Construct from patch and internal field and patch field
00151         fvPatchField
00152         (
00153             const fvPatch&,
00154             const Field<Type>&,
00155             const Field<Type>&
00156         );
00157 
00158         //- Construct from patch, internal field and dictionary
00159         fvPatchField
00160         (
00161             const fvPatch&,
00162             const Field<Type>&,
00163             const dictionary&
00164         );
00165 
00166         //- Construct by mapping the given fvPatchField onto a new patch
00167         fvPatchField
00168         (
00169             const fvPatchField<Type>&,
00170             const fvPatch&,
00171             const Field<Type>&,
00172             const fvPatchFieldMapper&
00173         );
00174 
00175         //- Construct as copy
00176         fvPatchField(const fvPatchField<Type>&);
00177 
00178         //- Construct and return a clone
00179         virtual tmp<fvPatchField<Type> > clone() const
00180         {
00181             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
00182         }
00183 
00184         //- Construct as copy setting internal field reference
00185         fvPatchField(const fvPatchField<Type>&, const Field<Type>&);
00186 
00187         //- Construct and return a clone setting internal field reference
00188         virtual tmp<fvPatchField<Type> > clone(const Field<Type>& iF) const
00189         {
00190             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
00191         }
00192 
00193 
00194     // Selectors
00195 
00196         //- Return a pointer to a new patchField created on freestore given
00197         //  patch and internal field
00198         //  (does not set the patch field values)
00199         static tmp<fvPatchField<Type> > New
00200         (
00201             const word&,
00202             const fvPatch&,
00203             const Field<Type>&
00204         );
00205 
00206         //- Return a pointer to a new patchField created on freestore from
00207         //  a given fvPatchField mapped onto a new patch
00208         static tmp<fvPatchField<Type> > New
00209         (
00210             const fvPatchField<Type>&,
00211             const fvPatch&,
00212             const Field<Type>&,
00213             const fvPatchFieldMapper&
00214         );
00215 
00216         //- Return a pointer to a new patchField created on freestore
00217         //  from dictionary
00218         static tmp<fvPatchField<Type> > New
00219         (
00220             const fvPatch&,
00221             const Field<Type>&,
00222             const dictionary&
00223         );
00224 
00225         //- Return a pointer to a new calculatedFvPatchField created on
00226         //  freestore without setting patchField values
00227         template<class Type2>
00228         static tmp<fvPatchField<Type> > NewCalculatedType
00229         (
00230             const fvPatchField<Type2>&
00231         );
00232 
00233 
00234     // Destructor
00235 
00236         virtual ~fvPatchField<Type>()
00237         {}
00238 
00239 
00240     // Member functions
00241 
00242         // Access
00243 
00244             //- Return local objectRegistry
00245             const objectRegistry& db() const;
00246 
00247             //- Return patch
00248             const fvPatch& patch() const
00249             {
00250                 return patch_;
00251             }
00252 
00253             //- Return internal field reference
00254             const Field<Type>& internalField() const
00255             {
00256                 return internalField_;
00257             }
00258 
00259             //- Return the type of the calculated for of fvPatchField
00260             static const word& calculatedType();
00261 
00262             //- Return true if this patch field fixes a value.
00263             //  Needed to check if a level has to be specified while solving
00264             //  Poissons equations.
00265             virtual bool fixesValue() const
00266             {
00267                 return false;
00268             }
00269 
00270             //- Return true if the boundary condition has already been updated
00271             bool updated() const
00272             {
00273                 return updated_;
00274             }
00275 
00276             //- Does this patchField correspond to a volTypeField
00277             bool isVolField() const;
00278 
00279             //- Check that this patchField corresponds to a volTypeField,
00280             // if not abort!
00281             void checkVolField() const;
00282 
00283             //- Return the corresponding patchField of the named field
00284             template<class GeometricField, class Type2>
00285             const fvPatchField<Type2>& patchField(const GeometricField&) const;
00286 
00287             //- Lookup and return the patchField of the named field from the
00288             //  local objectRegistry.
00289             //  N.B.  The dummy pointer arguments are used if this function is 
00290             //  instantiated within a templated function to avoid a bug in gcc.
00291             //  See inletOutletFvPatchField.C and outletInletFvPatchField.C
00292             template<class GeometricField, class Type2>
00293             const fvPatchField<Type2>& lookupPatchField
00294             (
00295                 const word& name,
00296                 const GeometricField* = NULL,
00297                 const Type2* = NULL
00298             ) const;
00299 
00300 
00301         // Mapping functions
00302 
00303             //- Map (and resize as needed) from self given a mapping object
00304             virtual void autoMap
00305             (
00306                 const fvPatchFieldMapper&
00307             );
00308 
00309             //- Reverse map the given fvPatchField onto this fvPatchField
00310             virtual void rmap
00311             (
00312                 const fvPatchField<Type>&,
00313                 const labelList&
00314             );
00315 
00316 
00317         // Evaluation functions
00318 
00319             //- Return patch-normal gradient
00320             virtual tmp<Field<Type> > snGrad() const;
00321 
00322             //- Update the coefficients associated with the patch field
00323             //  Sets Updated to true
00324             virtual void updateCoeffs()
00325             {
00326                 updated_ = true;
00327             }
00328 
00329             //- Return given internal field next to patch as patch field
00330             template<class Type2>
00331             tmp<Field<Type2> > patchInternalField
00332             (
00333                 const Field<Type2>&
00334             ) const;
00335 
00336             //- Return internal field next to patch as patch field
00337             virtual tmp<Field<Type> > patchInternalField() const;
00338 
00339             //- Return neighbour coupled given internal cell data
00340             virtual tmp<Field<Type> > patchNeighbourField
00341             (
00342                 const Field<Type>& iField
00343             ) const;
00344 
00345             //- Return neighbour colouring.
00346             //  Needed for AMG solver agglomeration
00347             virtual tmp<labelField> nbrColour
00348             (
00349                 const labelField& iColour
00350             ) const;
00351 
00352             //- Return patchField of the values on the patch or on the
00353             //  opposite patch
00354             virtual tmp<Field<Type> > patchNeighbourField() const;
00355 
00356             //- Initialise the evaluation of the patch field
00357             virtual void initEvaluate(const bool=false)
00358             {}
00359 
00360             //- Evaluate the patch field, sets Updated to false
00361             virtual void evaluate();
00362 
00363 
00364             //- Return the matrix diagonal coefficients corresponding to the
00365             //  evaluation of the value of this patchField with given weights
00366             virtual tmp<Field<Type> > valueInternalCoeffs
00367             (
00368                 const tmp<Field<scalar> >&
00369             ) const
00370             {
00371                 notImplemented
00372                 (
00373                     type()
00374                   + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
00375                 );
00376                 return *this;
00377             }
00378 
00379             //- Return the matrix source coefficients corresponding to the
00380             //  evaluation of the value of this patchField with given weights
00381             virtual tmp<Field<Type> > valueBoundaryCoeffs
00382             (
00383                 const tmp<Field<scalar> >&
00384             ) const
00385             {
00386                 notImplemented
00387                 (
00388                     type()
00389                   + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
00390                 );
00391                 return *this;
00392             }
00393 
00394             //- Return the matrix diagonal coefficients corresponding to the
00395             //  evaluation of the gradient of this patchField
00396             virtual tmp<Field<Type> > gradientInternalCoeffs() const
00397             {
00398                 notImplemented(type() + "::gradientInternalCoeffs()");
00399                 return *this;
00400             }
00401 
00402             //- Return the matrix source coefficients corresponding to the
00403             //  evaluation of the gradient of this patchField
00404             virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
00405             {
00406                 notImplemented(type() + "::gradientBoundaryCoeffs()");
00407                 return *this;
00408             }
00409 
00410 
00411         //- Write
00412         virtual void write(Ostream&) const;
00413 
00414 
00415         // Check
00416 
00417             //- Check fvPatchField<Type> against given fvPatchField<Type>
00418             void check(const fvPatchField<Type>&) const;
00419 
00420 
00421     // Member operators
00422 
00423         virtual void operator=(const UList<Type>&);
00424 
00425         virtual void operator=(const fvPatchField<Type>&);
00426         virtual void operator+=(const fvPatchField<Type>&);
00427         virtual void operator-=(const fvPatchField<Type>&);
00428         virtual void operator*=(const fvPatchField<scalar>&);
00429         virtual void operator/=(const fvPatchField<scalar>&);
00430 
00431         virtual void operator+=(const Field<Type>&);
00432         virtual void operator-=(const Field<Type>&);
00433 
00434         virtual void operator*=(const Field<scalar>&);
00435         virtual void operator/=(const Field<scalar>&);
00436 
00437         virtual void operator=(const Type&);
00438         virtual void operator+=(const Type&);
00439         virtual void operator-=(const Type&);
00440         virtual void operator*=(const scalar);
00441         virtual void operator/=(const scalar);
00442 
00443 
00444         // Force an assignment irrespective of form of patch
00445 
00446         virtual void operator==(const fvPatchField<Type>&);
00447         virtual void operator==(const Field<Type>&);
00448         virtual void operator==(const Type&);
00449 
00450 
00451     // Ostream operator
00452 
00453         friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
00454 };
00455 
00456 
00457 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00458 
00459 } // End namespace Foam
00460 
00461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00462 
00463 #ifdef NoRepository
00464 #   include "fvPatchField.C"
00465 #   include "calculatedFvPatchField.H"
00466 #endif
00467 
00468 
00469 #define makePatchTypeFieldTypeName(type)                                   \
00470                                                                            \
00471 defineNamedTemplateTypeNameAndDebug(type, 0);
00472 
00473 #define makePatchFieldsTypeName(type)                                      \
00474                                                                            \
00475 makePatchTypeFieldTypeName(type##FvPatchScalarField);                      \
00476 makePatchTypeFieldTypeName(type##FvPatchVectorField);                      \
00477 makePatchTypeFieldTypeName(type##FvPatchTensorField);                      \
00478 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField);
00479 
00480 
00481 #define makePatchTypeField(PatchTypeField, typePatchTypeField)             \
00482                                                                            \
00483 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                \
00484                                                                            \
00485 addToRunTimeSelectionTable                                                 \
00486 (                                                                          \
00487     PatchTypeField, typePatchTypeField, patch                              \
00488 );                                                                         \
00489                                                                            \
00490 addToRunTimeSelectionTable                                                 \
00491 (                                                                          \
00492     PatchTypeField,                                                        \
00493     typePatchTypeField,                                                    \
00494     patchMapper                                                            \
00495 );                                                                         \
00496                                                                            \
00497 addToRunTimeSelectionTable                                                 \
00498 (                                                                          \
00499     PatchTypeField, typePatchTypeField, dictionary                         \
00500 );
00501 
00502 
00503 #define makePatchFields(type)                                              \
00504                                                                            \
00505 makePatchTypeField(fvPatchScalarField, type##FvPatchScalarField);          \
00506 makePatchTypeField(fvPatchVectorField, type##FvPatchVectorField);          \
00507 makePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);          \
00508 makePatchTypeField(fvPatchSphericalTensorField, type##FvPatchSphericalTensorField);
00509 
00510 
00511 #define makePatchTypeFieldTypedefs(type)                                   \
00512                                                                            \
00513 typedef type##FvPatchField<scalar> type##FvPatchScalarField;               \
00514 typedef type##FvPatchField<vector> type##FvPatchVectorField;               \
00515 typedef type##FvPatchField<tensor> type##FvPatchTensorField;               \
00516 typedef type##FvPatchField<sphericalTensor> type##FvPatchSphericalTensorField;
00517 
00518 
00519 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00520 
00521 #endif
00522 
00523 // ************************************************************************* //
For further information go to www.openfoam.org