OpenFOAM logo
Open Source CFD Toolkit

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