initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / fvPatchField / fvPatchField.H
blob851d9d33ae7e44d3f9d5ca72e0d2d5fa934bac3b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::fvPatchField
28 Description
29     Abstract base class with a fat-interface to all derived classes
30     covering all possible ways in which they might be used.
32     The first level of derivation is to basic patchFields which cover
33     zero-gradient, fixed-gradient, fixed-value and mixed conditions.
35     The next level of derivation covers all the specialised types with
36     specific evaluation proceedures, particularly with respect to specific
37     fields.
39 SourceFiles
40     fvPatchField.C
41     newFvPatchField.C
43 \*---------------------------------------------------------------------------*/
45 #ifndef fvPatchField_H
46 #define fvPatchField_H
48 #include "fvPatch.H"
49 #include "DimensionedField.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace Foam
56 // Forward declaration of classes
58 class objectRegistry;
59 class dictionary;
60 class fvPatchFieldMapper;
61 class volMesh;
64 // Forward declaration of friend functions and operators
66 template<class Type>
67 class fvPatchField;
69 template<class Type>
70 class fvMatrix;
72 template<class Type>
73 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
76 /*---------------------------------------------------------------------------*\
77                            Class patch Declaration
78 \*---------------------------------------------------------------------------*/
80 template<class Type>
81 class fvPatchField
83     public Field<Type>
85     // Private data
87         //- Reference to patch
88         const fvPatch& patch_;
90         //- Reference to internal field
91         const DimensionedField<Type, volMesh>& internalField_;
93         //- Update index used so that updateCoeffs is called only once during
94         //  the construction of the matrix
95         bool updated_;
97         //- Optional patch type, used to allow specified boundary conditions
98         //  to be applied to constraint patches by providing the constraint
99         //  patch type as 'patchType'
100         word patchType_;
103 public:
105     typedef fvPatch Patch;
108     //- Runtime type information
109     TypeName("fvPatchField");
111     //- Debug switch to disallow the use of genericFvPatchField
112     static int disallowGenericFvPatchField;
115     // Declare run-time constructor selection tables
117         declareRunTimeSelectionTable
118         (
119             tmp,
120             fvPatchField,
121             patch,
122             (
123                 const fvPatch& p,
124                 const DimensionedField<Type, volMesh>& iF
125             ),
126             (p, iF)
127         );
129         declareRunTimeSelectionTable
130         (
131             tmp,
132             fvPatchField,
133             patchMapper,
134             (
135                 const fvPatchField<Type>& ptf,
136                 const fvPatch& p,
137                 const DimensionedField<Type, volMesh>& iF,
138                 const fvPatchFieldMapper& m
139             ),
140             (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
141         );
143         declareRunTimeSelectionTable
144         (
145             tmp,
146             fvPatchField,
147             dictionary,
148             (
149                 const fvPatch& p,
150                 const DimensionedField<Type, volMesh>& iF,
151                 const dictionary& dict
152             ),
153             (p, iF, dict)
154         );
157     // Constructors
159         //- Construct from patch and internal field
160         fvPatchField
161         (
162             const fvPatch&,
163             const DimensionedField<Type, volMesh>&
164         );
166         //- Construct from patch and internal field and patch field
167         fvPatchField
168         (
169             const fvPatch&,
170             const DimensionedField<Type, volMesh>&,
171             const Field<Type>&
172         );
174         //- Construct from patch, internal field and dictionary
175         fvPatchField
176         (
177             const fvPatch&,
178             const DimensionedField<Type, volMesh>&,
179             const dictionary&,
180             const bool valueRequired=false
181         );
183         //- Construct by mapping the given fvPatchField onto a new patch
184         fvPatchField
185         (
186             const fvPatchField<Type>&,
187             const fvPatch&,
188             const DimensionedField<Type, volMesh>&,
189             const fvPatchFieldMapper&
190         );
192         //- Construct as copy
193         fvPatchField(const fvPatchField<Type>&);
195         //- Construct and return a clone
196         virtual tmp<fvPatchField<Type> > clone() const
197         {
198             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
199         }
201         //- Construct as copy setting internal field reference
202         fvPatchField
203         (
204             const fvPatchField<Type>&,
205             const DimensionedField<Type, volMesh>&
206         );
208         //- Construct and return a clone setting internal field reference
209         virtual tmp<fvPatchField<Type> > clone
210         (
211             const DimensionedField<Type, volMesh>& iF
212         ) const
213         {
214             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
215         }
218     // Selectors
220         //- Return a pointer to a new patchField created on freestore given
221         //  patch and internal field
222         //  (does not set the patch field values)
223         static tmp<fvPatchField<Type> > New
224         (
225             const word&,
226             const fvPatch&,
227             const DimensionedField<Type, volMesh>&
228         );
230         //- Return a pointer to a new patchField created on freestore from
231         //  a given fvPatchField mapped onto a new patch
232         static tmp<fvPatchField<Type> > New
233         (
234             const fvPatchField<Type>&,
235             const fvPatch&,
236             const DimensionedField<Type, volMesh>&,
237             const fvPatchFieldMapper&
238         );
240         //- Return a pointer to a new patchField created on freestore
241         //  from dictionary
242         static tmp<fvPatchField<Type> > New
243         (
244             const fvPatch&,
245             const DimensionedField<Type, volMesh>&,
246             const dictionary&
247         );
249         //- Return a pointer to a new calculatedFvPatchField created on
250         //  freestore without setting patchField values
251         template<class Type2>
252         static tmp<fvPatchField<Type> > NewCalculatedType
253         (
254             const fvPatchField<Type2>&
255         );
258     // Destructor
260         virtual ~fvPatchField<Type>()
261         {}
264     // Member functions
266         // Access
268             //- Return local objectRegistry
269             const objectRegistry& db() const;
271             //- Return patch
272             const fvPatch& patch() const
273             {
274                 return patch_;
275             }
277             //- Return dimensioned internal field reference
278             const DimensionedField<Type, volMesh>&
279             dimensionedInternalField() const
280             {
281                 return internalField_;
282             }
284             //- Return internal field reference
285             const Field<Type>& internalField() const
286             {
287                 return internalField_;
288             }
290             //- Return the type of the calculated for of fvPatchField
291             static const word& calculatedType();
293             //- Return true if this patch field fixes a value.
294             //  Needed to check if a level has to be specified while solving
295             //  Poissons equations.
296             virtual bool fixesValue() const
297             {
298                 return false;
299             }
301             //- Return true if this patch field is coupled
302             virtual bool coupled() const
303             {
304                 return false;
305             }
307             //- Return true if the boundary condition has already been updated
308             bool updated() const
309             {
310                 return updated_;
311             }
314         // Mapping functions
316             //- Map (and resize as needed) from self given a mapping object
317             virtual void autoMap
318             (
319                 const fvPatchFieldMapper&
320             );
322             //- Reverse map the given fvPatchField onto this fvPatchField
323             virtual void rmap
324             (
325                 const fvPatchField<Type>&,
326                 const labelList&
327             );
330         // Evaluation functions
332             //- Return patch-normal gradient
333             virtual tmp<Field<Type> > snGrad() const;
335             //- Update the coefficients associated with the patch field
336             //  Sets Updated to true
337             virtual void updateCoeffs()
338             {
339                 updated_ = true;
340             }
342             //- Return internal field next to patch as patch field
343             virtual tmp<Field<Type> > patchInternalField() const;
345             //- Return patchField on the opposite patch of a coupled patch
346             virtual tmp<Field<Type> > patchNeighbourField() const
347             {
348                 notImplemented(type() + "patchNeighbourField()");
349                 return *this;
350             }
352             //- Initialise the evaluation of the patch field
353             virtual void initEvaluate
354             (
355                 const Pstream::commsTypes commsType=Pstream::blocking
356             )
357             {}
359             //- Evaluate the patch field, sets Updated to false
360             virtual void evaluate
361             (
362                 const Pstream::commsTypes commsType=Pstream::blocking
363             );
366             //- Return the matrix diagonal coefficients corresponding to the
367             //  evaluation of the value of this patchField with given weights
368             virtual tmp<Field<Type> > valueInternalCoeffs
369             (
370                 const tmp<Field<scalar> >&
371             ) const
372             {
373                 notImplemented
374                 (
375                     type()
376                   + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
377                 );
378                 return *this;
379             }
381             //- Return the matrix source coefficients corresponding to the
382             //  evaluation of the value of this patchField with given weights
383             virtual tmp<Field<Type> > valueBoundaryCoeffs
384             (
385                 const tmp<Field<scalar> >&
386             ) const
387             {
388                 notImplemented
389                 (
390                     type()
391                   + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
392                 );
393                 return *this;
394             }
396             //- Return the matrix diagonal coefficients corresponding to the
397             //  evaluation of the gradient of this patchField
398             virtual tmp<Field<Type> > gradientInternalCoeffs() const
399             {
400                 notImplemented(type() + "::gradientInternalCoeffs()");
401                 return *this;
402             }
404             //- Return the matrix source coefficients corresponding to the
405             //  evaluation of the gradient of this patchField
406             virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
407             {
408                 notImplemented(type() + "::gradientBoundaryCoeffs()");
409                 return *this;
410             }
413             //- Manipulate matrix
414             virtual void manipulateMatrix(fvMatrix<Type>& matrix);
417         // I-O
419             //- Write
420             virtual void write(Ostream&) const;
422             //- Helper function to write the keyword and entry only if the
423             //  values are not equal. The value is then output as value2
424             template<class EntryType>
425             void writeEntryIfDifferent
426             (
427                 Ostream& os,
428                 const word& entryName,
429                 const EntryType& value1,
430                 const EntryType& value2
431             ) const;
434         // Check
436             //- Check fvPatchField<Type> against given fvPatchField<Type>
437             void check(const fvPatchField<Type>&) const;
440     // Member operators
442         virtual void operator=(const UList<Type>&);
444         virtual void operator=(const fvPatchField<Type>&);
445         virtual void operator+=(const fvPatchField<Type>&);
446         virtual void operator-=(const fvPatchField<Type>&);
447         virtual void operator*=(const fvPatchField<scalar>&);
448         virtual void operator/=(const fvPatchField<scalar>&);
450         virtual void operator+=(const Field<Type>&);
451         virtual void operator-=(const Field<Type>&);
453         virtual void operator*=(const Field<scalar>&);
454         virtual void operator/=(const Field<scalar>&);
456         virtual void operator=(const Type&);
457         virtual void operator+=(const Type&);
458         virtual void operator-=(const Type&);
459         virtual void operator*=(const scalar);
460         virtual void operator/=(const scalar);
463         // Force an assignment irrespective of form of patch
465         virtual void operator==(const fvPatchField<Type>&);
466         virtual void operator==(const Field<Type>&);
467         virtual void operator==(const Type&);
470     // Ostream operator
472         friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
478 } // End namespace Foam
480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 #ifdef NoRepository
483 #   include "fvPatchField.C"
484 #   include "calculatedFvPatchField.H"
485 #endif
488 #define makePatchTypeFieldTypeName(type)                                   \
489                                                                            \
490 defineNamedTemplateTypeNameAndDebug(type, 0);
492 #define makePatchFieldsTypeName(type)                                      \
493                                                                            \
494 makePatchTypeFieldTypeName(type##FvPatchScalarField);                      \
495 makePatchTypeFieldTypeName(type##FvPatchVectorField);                      \
496 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField);             \
497 makePatchTypeFieldTypeName(type##FvPatchSymmTensorField);                  \
498 makePatchTypeFieldTypeName(type##FvPatchTensorField);
500 #define makePatchTypeField(PatchTypeField, typePatchTypeField)             \
501                                                                            \
502 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                \
503                                                                            \
504 addToRunTimeSelectionTable                                                 \
505 (                                                                          \
506     PatchTypeField, typePatchTypeField, patch                              \
507 );                                                                         \
508                                                                            \
509 addToRunTimeSelectionTable                                                 \
510 (                                                                          \
511     PatchTypeField,                                                        \
512     typePatchTypeField,                                                    \
513     patchMapper                                                            \
514 );                                                                         \
515                                                                            \
516 addToRunTimeSelectionTable                                                 \
517 (                                                                          \
518     PatchTypeField, typePatchTypeField, dictionary                         \
522 #define makePatchFields(type)                                              \
523                                                                            \
524 makePatchTypeField(fvPatchScalarField, type##FvPatchScalarField);          \
525 makePatchTypeField(fvPatchVectorField, type##FvPatchVectorField);          \
526 makePatchTypeField                                                         \
527 (                                                                          \
528     fvPatchSphericalTensorField,                                           \
529     type##FvPatchSphericalTensorField                                      \
530 );                                                                         \
531 makePatchTypeField(fvPatchSymmTensorField, type##FvPatchSymmTensorField);  \
532 makePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);
535 #define makePatchTypeFieldTypedefs(type)                                   \
536                                                                            \
537 typedef type##FvPatchField<scalar> type##FvPatchScalarField;               \
538 typedef type##FvPatchField<vector> type##FvPatchVectorField;               \
539 typedef type##FvPatchField<sphericalTensor>                                \
540     type##FvPatchSphericalTensorField;                                     \
541 typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField;       \
542 typedef type##FvPatchField<tensor> type##FvPatchTensorField;
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 #endif
549 // ************************************************************************* //