initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / fvPatchField / fvPatchField.H
blob90cdb04a2024caacf2cb732297d8c7edb8f7eff6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 typed 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 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
73 /*---------------------------------------------------------------------------*\
74                            Class patch Declaration
75 \*---------------------------------------------------------------------------*/
77 template<class Type>
78 class fvPatchField
80     public Field<Type>
82     // Private data
84         //- Reference to patch
85         const fvPatch& patch_;
87         //- Reference to internal field
88         const DimensionedField<Type, volMesh>& internalField_;
90         //- Update index used so that updateCoeffs is called only once during
91         //  the construction of the matrix
92         bool updated_;
94         //- Optional patch type, used to allow specified boundary conditions
95         //  to be applied to constraint patches by providing the constraint
96         //  patch type as 'patchType'
97         word patchType_;
100 public:
102     typedef fvPatch Patch;
105     //- Runtime type information
106     TypeName("fvPatchField");
108     //- Debug switch to disallow the use of genericFvPatchField
109     static int disallowGenericFvPatchField;
112     // Declare run-time constructor selection tables
114         declareRunTimeSelectionTable
115         (
116             tmp,
117             fvPatchField,
118             patch,
119             (
120                 const fvPatch& p,
121                 const DimensionedField<Type, volMesh>& iF
122             ),
123             (p, iF)
124         );
126         declareRunTimeSelectionTable
127         (
128             tmp,
129             fvPatchField,
130             patchMapper,
131             (
132                 const fvPatchField<Type>& ptf,
133                 const fvPatch& p,
134                 const DimensionedField<Type, volMesh>& iF,
135                 const fvPatchFieldMapper& m
136             ),
137             (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
138         );
140         declareRunTimeSelectionTable
141         (
142             tmp,
143             fvPatchField,
144             dictionary,
145             (
146                 const fvPatch& p,
147                 const DimensionedField<Type, volMesh>& iF,
148                 const dictionary& dict
149             ),
150             (p, iF, dict)
151         );
154     // Constructors
156         //- Construct from patch and internal field
157         fvPatchField
158         (
159             const fvPatch&,
160             const DimensionedField<Type, volMesh>&
161         );
163         //- Construct from patch and internal field and patch field
164         fvPatchField
165         (
166             const fvPatch&,
167             const DimensionedField<Type, volMesh>&,
168             const Field<Type>&
169         );
171         //- Construct from patch, internal field and dictionary
172         fvPatchField
173         (
174             const fvPatch&,
175             const DimensionedField<Type, volMesh>&,
176             const dictionary&,
177             const bool valueRequired=false
178         );
180         //- Construct by mapping the given fvPatchField onto a new patch
181         fvPatchField
182         (
183             const fvPatchField<Type>&,
184             const fvPatch&,
185             const DimensionedField<Type, volMesh>&,
186             const fvPatchFieldMapper&
187         );
189         //- Construct as copy
190         fvPatchField(const fvPatchField<Type>&);
192         //- Construct and return a clone
193         virtual tmp<fvPatchField<Type> > clone() const
194         {
195             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
196         }
198         //- Construct as copy setting internal field reference
199         fvPatchField
200         (
201             const fvPatchField<Type>&,
202             const DimensionedField<Type, volMesh>&
203         );
205         //- Construct and return a clone setting internal field reference
206         virtual tmp<fvPatchField<Type> > clone
207         (
208             const DimensionedField<Type, volMesh>& iF
209         ) const
210         {
211             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
212         }
215     // Selectors
217         //- Return a pointer to a new patchField created on freestore given
218         //  patch and internal field
219         //  (does not set the patch field values)
220         static tmp<fvPatchField<Type> > New
221         (
222             const word&,
223             const fvPatch&,
224             const DimensionedField<Type, volMesh>&
225         );
227         //- Return a pointer to a new patchField created on freestore from
228         //  a given fvPatchField mapped onto a new patch
229         static tmp<fvPatchField<Type> > New
230         (
231             const fvPatchField<Type>&,
232             const fvPatch&,
233             const DimensionedField<Type, volMesh>&,
234             const fvPatchFieldMapper&
235         );
237         //- Return a pointer to a new patchField created on freestore
238         //  from dictionary
239         static tmp<fvPatchField<Type> > New
240         (
241             const fvPatch&,
242             const DimensionedField<Type, volMesh>&,
243             const dictionary&
244         );
246         //- Return a pointer to a new calculatedFvPatchField created on
247         //  freestore without setting patchField values
248         template<class Type2>
249         static tmp<fvPatchField<Type> > NewCalculatedType
250         (
251             const fvPatchField<Type2>&
252         );
255     // Destructor
257         virtual ~fvPatchField<Type>()
258         {}
261     // Member functions
263         // Access
265             //- Return local objectRegistry
266             const objectRegistry& db() const;
268             //- Return patch
269             const fvPatch& patch() const
270             {
271                 return patch_;
272             }
274             //- Return dimensioned internal field reference
275             const DimensionedField<Type, volMesh>&
276             dimensionedInternalField() const
277             {
278                 return internalField_;
279             }
281             //- Return internal field reference
282             const Field<Type>& internalField() const
283             {
284                 return internalField_;
285             }
287             //- Return the type of the calculated for of fvPatchField
288             static const word& calculatedType();
290             //- Return true if this patch field fixes a value.
291             //  Needed to check if a level has to be specified while solving
292             //  Poissons equations.
293             virtual bool fixesValue() const
294             {
295                 return false;
296             }
298             //- Return true if this patch field is coupled
299             virtual bool coupled() const
300             {
301                 return false;
302             }
304             //- Return true if the boundary condition has already been updated
305             bool updated() const
306             {
307                 return updated_;
308             }
311         // Mapping functions
313             //- Map (and resize as needed) from self given a mapping object
314             virtual void autoMap
315             (
316                 const fvPatchFieldMapper&
317             );
319             //- Reverse map the given fvPatchField onto this fvPatchField
320             virtual void rmap
321             (
322                 const fvPatchField<Type>&,
323                 const labelList&
324             );
327         // Evaluation functions
329             //- Return patch-normal gradient
330             virtual tmp<Field<Type> > snGrad() const;
332             //- Update the coefficients associated with the patch field
333             //  Sets Updated to true
334             virtual void updateCoeffs()
335             {
336                 updated_ = true;
337             }
339             //- Return internal field next to patch as patch field
340             virtual tmp<Field<Type> > patchInternalField() const;
342             //- Return patchField on the opposite patch of a coupled patch
343             virtual tmp<Field<Type> > patchNeighbourField() const
344             {
345                 notImplemented(type() + "patchNeighbourField()");
346                 return *this;
347             }
349             //- Initialise the evaluation of the patch field
350             virtual void initEvaluate
351             (
352                 const Pstream::commsTypes commsType=Pstream::blocking
353             )
354             {}
356             //- Evaluate the patch field, sets Updated to false
357             virtual void evaluate
358             (
359                 const Pstream::commsTypes commsType=Pstream::blocking
360             );
363             //- Return the matrix diagonal coefficients corresponding to the
364             //  evaluation of the value of this patchField with given weights
365             virtual tmp<Field<Type> > valueInternalCoeffs
366             (
367                 const tmp<Field<scalar> >&
368             ) const
369             {
370                 notImplemented
371                 (
372                     type()
373                   + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
374                 );
375                 return *this;
376             }
378             //- Return the matrix source coefficients corresponding to the
379             //  evaluation of the value of this patchField with given weights
380             virtual tmp<Field<Type> > valueBoundaryCoeffs
381             (
382                 const tmp<Field<scalar> >&
383             ) const
384             {
385                 notImplemented
386                 (
387                     type()
388                   + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
389                 );
390                 return *this;
391             }
393             //- Return the matrix diagonal coefficients corresponding to the
394             //  evaluation of the gradient of this patchField
395             virtual tmp<Field<Type> > gradientInternalCoeffs() const
396             {
397                 notImplemented(type() + "::gradientInternalCoeffs()");
398                 return *this;
399             }
401             //- Return the matrix source coefficients corresponding to the
402             //  evaluation of the gradient of this patchField
403             virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
404             {
405                 notImplemented(type() + "::gradientBoundaryCoeffs()");
406                 return *this;
407             }
410         //- Write
411         virtual void write(Ostream&) const;
414         // Check
416             //- Check fvPatchField<Type> against given fvPatchField<Type>
417             void check(const fvPatchField<Type>&) const;
420     // Member operators
422         virtual void operator=(const UList<Type>&);
424         virtual void operator=(const fvPatchField<Type>&);
425         virtual void operator+=(const fvPatchField<Type>&);
426         virtual void operator-=(const fvPatchField<Type>&);
427         virtual void operator*=(const fvPatchField<scalar>&);
428         virtual void operator/=(const fvPatchField<scalar>&);
430         virtual void operator+=(const Field<Type>&);
431         virtual void operator-=(const Field<Type>&);
433         virtual void operator*=(const Field<scalar>&);
434         virtual void operator/=(const Field<scalar>&);
436         virtual void operator=(const Type&);
437         virtual void operator+=(const Type&);
438         virtual void operator-=(const Type&);
439         virtual void operator*=(const scalar);
440         virtual void operator/=(const scalar);
443         // Force an assignment irrespective of form of patch
445         virtual void operator==(const fvPatchField<Type>&);
446         virtual void operator==(const Field<Type>&);
447         virtual void operator==(const Type&);
450     // Ostream operator
452         friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
456 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458 } // End namespace Foam
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 #ifdef NoRepository
463 #   include "fvPatchField.C"
464 #   include "calculatedFvPatchField.H"
465 #endif
468 #define makePatchTypeFieldTypeName(type)                                   \
469                                                                            \
470 defineNamedTemplateTypeNameAndDebug(type, 0);
472 #define makePatchFieldsTypeName(type)                                      \
473                                                                            \
474 makePatchTypeFieldTypeName(type##FvPatchScalarField);                      \
475 makePatchTypeFieldTypeName(type##FvPatchVectorField);                      \
476 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField);             \
477 makePatchTypeFieldTypeName(type##FvPatchSymmTensorField);                  \
478 makePatchTypeFieldTypeName(type##FvPatchTensorField);
480 #define makePatchTypeField(PatchTypeField, typePatchTypeField)             \
481                                                                            \
482 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                \
483                                                                            \
484 addToRunTimeSelectionTable                                                 \
485 (                                                                          \
486     PatchTypeField, typePatchTypeField, patch                              \
487 );                                                                         \
488                                                                            \
489 addToRunTimeSelectionTable                                                 \
490 (                                                                          \
491     PatchTypeField,                                                        \
492     typePatchTypeField,                                                    \
493     patchMapper                                                            \
494 );                                                                         \
495                                                                            \
496 addToRunTimeSelectionTable                                                 \
497 (                                                                          \
498     PatchTypeField, typePatchTypeField, dictionary                         \
502 #define makePatchFields(type)                                              \
503                                                                            \
504 makePatchTypeField(fvPatchScalarField, type##FvPatchScalarField);          \
505 makePatchTypeField(fvPatchVectorField, type##FvPatchVectorField);          \
506 makePatchTypeField                                                         \
507 (                                                                          \
508     fvPatchSphericalTensorField,                                           \
509     type##FvPatchSphericalTensorField                                      \
510 );                                                                         \
511 makePatchTypeField(fvPatchSymmTensorField, type##FvPatchSymmTensorField);  \
512 makePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);
515 #define makePatchTypeFieldTypedefs(type)                                   \
516                                                                            \
517 typedef type##FvPatchField<scalar> type##FvPatchScalarField;               \
518 typedef type##FvPatchField<vector> type##FvPatchVectorField;               \
519 typedef type##FvPatchField<sphericalTensor>                                \
520     type##FvPatchSphericalTensorField;                                     \
521 typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField;       \
522 typedef type##FvPatchField<tensor> type##FvPatchTensorField;
525 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
527 #endif
529 // ************************************************************************* //