Formatting
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / fvPatchField / fvPatchField.H
blob60c5fbae5ce057f2854662881332d147b70f97a9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::fvPatchField
27 Description
28     Abstract base class with a fat-interface to all derived classes
29     covering all possible ways in which they might be used.
31     The first level of derivation is to basic patchFields which cover
32     zero-gradient, fixed-gradient, fixed-value and mixed conditions.
34     The next level of derivation covers all the specialised types with
35     specific evaluation proceedures, particularly with respect to specific
36     fields.
38 SourceFiles
39     fvPatchField.C
40     newFvPatchField.C
42 \*---------------------------------------------------------------------------*/
44 #ifndef fvPatchField_H
45 #define fvPatchField_H
47 #include "fvPatch.H"
48 #include "DimensionedField.H"
49 #include "debugSwitch.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace Foam
56 // Forward declaration of classes
58 class objectRegistry;
59 class dictionary;
60 class fvPatchFieldMapper;
61 class volMesh;
62 class surfaceMesh;
64 // Forward declaration of friend functions and operators
66 template<class Type>
67 class fvPatchField;
69 template<class Type>
70 class fvsPatchField;
72 template<class Type, template<class> class PatchField, class GeoMesh>
73 class GeometricField;
75 template<class Type>
76 class fvMatrix;
78 template<class Type>
79 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
82 /*---------------------------------------------------------------------------*\
83                         Class fvPatchField Declaration
84 \*---------------------------------------------------------------------------*/
86 template<class Type>
87 class fvPatchField
89     public Field<Type>
91     // Private data
93         //- Reference to patch
94         const fvPatch& patch_;
96         //- Reference to internal field
97         const DimensionedField<Type, volMesh>& internalField_;
99         //- Update index used so that updateCoeffs is called only once during
100         //  the construction of the matrix
101         bool updated_;
103         //- Optional patch type, used to allow specified boundary conditions
104         //  to be applied to constraint patches by providing the constraint
105         //  patch type as 'patchType'
106         word patchType_;
109 public:
111     typedef fvPatch Patch;
113     //- Runtime type information
114     TypeName("fvPatchField");
116     //- Debug switch to disallow the use of genericFvPatchField
117     static debug::debugSwitch disallowGenericFvPatchField;
120     // Declare run-time constructor selection tables
122 #ifndef SWIG
123         declareRunTimeSelectionTable
124         (
125             tmp,
126             fvPatchField,
127             patch,
128             (
129                 const fvPatch& p,
130                 const DimensionedField<Type, volMesh>& iF
131             ),
132             (p, iF)
133         );
135         declareRunTimeSelectionTable
136         (
137             tmp,
138             fvPatchField,
139             patchMapper,
140             (
141                 const fvPatchField<Type>& ptf,
142                 const fvPatch& p,
143                 const DimensionedField<Type, volMesh>& iF,
144                 const fvPatchFieldMapper& m
145             ),
146             (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
147         );
149         declareRunTimeSelectionTable
150         (
151             tmp,
152             fvPatchField,
153             dictionary,
154             (
155                 const fvPatch& p,
156                 const DimensionedField<Type, volMesh>& iF,
157                 const dictionary& dict
158             ),
159             (p, iF, dict)
160         );
161 #endif
163     // Constructors
165         //- Construct from patch and internal field
166         fvPatchField
167         (
168             const fvPatch&,
169             const DimensionedField<Type, volMesh>&
170         );
172         //- Construct from patch and internal field and patch field
173         fvPatchField
174         (
175             const fvPatch&,
176             const DimensionedField<Type, volMesh>&,
177             const Field<Type>&
178         );
180         //- Construct from patch, internal field and dictionary
181         fvPatchField
182         (
183             const fvPatch&,
184             const DimensionedField<Type, volMesh>&,
185             const dictionary&,
186             const bool valueRequired = false
187         );
189         //- Construct by mapping the given fvPatchField onto a new patch
190         fvPatchField
191         (
192             const fvPatchField<Type>&,
193             const fvPatch&,
194             const DimensionedField<Type, volMesh>&,
195             const fvPatchFieldMapper&
196         );
198         //- Construct as copy
199         fvPatchField(const fvPatchField<Type>&);
201         //- Construct and return a clone
202         virtual tmp<fvPatchField<Type> > clone() const
203         {
204             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
205         }
207         //- Construct as copy setting internal field reference
208         fvPatchField
209         (
210             const fvPatchField<Type>&,
211             const DimensionedField<Type, volMesh>&
212         );
214         //- Construct and return a clone setting internal field reference
215         virtual tmp<fvPatchField<Type> > clone
216         (
217             const DimensionedField<Type, volMesh>& iF
218         ) const
219         {
220             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
221         }
224     // Selectors
226         //- Return a pointer to a new patchField created on freestore given
227         //  patch and internal field
228         //  (does not set the patch field values)
229         static tmp<fvPatchField<Type> > New
230         (
231             const word&,
232             const fvPatch&,
233             const DimensionedField<Type, volMesh>&
234         );
236         //- Return a pointer to a new patchField created on freestore from
237         //  a given fvPatchField mapped onto a new patch
238         static tmp<fvPatchField<Type> > New
239         (
240             const fvPatchField<Type>&,
241             const fvPatch&,
242             const DimensionedField<Type, volMesh>&,
243             const fvPatchFieldMapper&
244         );
246         //- Return a pointer to a new patchField created on freestore
247         //  from dictionary
248         static tmp<fvPatchField<Type> > New
249         (
250             const fvPatch&,
251             const DimensionedField<Type, volMesh>&,
252             const dictionary&
253         );
255         //- Return a pointer to a new calculatedFvPatchField created on
256         //  freestore without setting patchField values
257         template<class Type2>
258         static tmp<fvPatchField<Type> > NewCalculatedType
259         (
260             const fvPatchField<Type2>&
261         );
264     // Destructor
266         virtual ~fvPatchField<Type>()
267         {}
270     // Member functions
272         // Access
274             //- Return local objectRegistry
275             const objectRegistry& db() const;
277             //- Lookup and return the patchField of the named field from the
278             //  field's objectRegistry.
279             //  N.B.  The dummy pointer arguments are used if this function is
280             //  instantiated within a templated function to avoid a bug in gcc.
281             //  See inletOutletFvPatchField.C and outletInletFvPatchField.C
282             template<class GeometricField, class Type2>
283             const typename GeometricField::PatchFieldType& lookupPatchField
284             (
285                 const word& name,
286                 const GeometricField* = NULL,
287                 const Type2* = NULL
288             ) const;
290             //- Return patch
291             const fvPatch& patch() const
292             {
293                 return patch_;
294             }
296             //- Return dimensioned internal field reference
297             const DimensionedField<Type, volMesh>&
298             dimensionedInternalField() const
299             {
300                 return internalField_;
301             }
303             //- Return internal field reference
304             const Field<Type>& internalField() const
305             {
306                 return internalField_;
307             }
309             //- Return the type of the calculated for type of fvPatchField
310             static const word& calculatedType();
312             //- Return patch type (optional on read)
313             const word& patchType() const
314             {
315                 return patchType_;
316             }
318             //- Return true if this patch field fixes a value.
319             //  Needed to check if a level has to be specified while solving
320             //  Poissons equations.
321             virtual bool fixesValue() const
322             {
323                 return false;
324             }
326             //- Return true if this patch field is coupled
327             virtual bool coupled() const
328             {
329                 return false;
330             }
332             //- Return true if the boundary condition has already been updated
333             bool updated() const
334             {
335                 return updated_;
336             }
339         // Mapping functions
341             //- Map (and resize as needed) from self given a mapping object
342             virtual void autoMap
343             (
344                 const fvPatchFieldMapper&
345             );
347             //- Reverse map the given fvPatchField onto this fvPatchField
348             virtual void rmap
349             (
350                 const fvPatchField<Type>&,
351                 const labelList&
352             );
355         // Evaluation functions
357             //- Return patch-normal gradient
358             virtual tmp<Field<Type> > snGrad() const;
360             //- Update the coefficients associated with the patch field
361             //  Sets Updated to true
362             virtual void updateCoeffs()
363             {
364                 updated_ = true;
365             }
367             //- Return internal field next to patch as patch field
368             virtual tmp<Field<Type> > patchInternalField() const;
370             //- Return patchField on the opposite patch of a coupled patch
371             virtual tmp<Field<Type> > patchNeighbourField() const
372             {
373                 notImplemented(type() + "patchNeighbourField()");
374                 return *this;
375             }
377             //- Initialise the evaluation of the patch field
378             virtual void initEvaluate
379             (
380                 const Pstream::commsTypes commsType = Pstream::blocking
381             )
382             {}
384             //- Evaluate the patch field, sets Updated to false
385             virtual void evaluate
386             (
387                 const Pstream::commsTypes commsType = Pstream::blocking
388             );
391             //- Return the matrix diagonal coefficients corresponding to the
392             //  evaluation of the value of this patchField with given weights
393             virtual tmp<Field<Type> > valueInternalCoeffs
394             (
395                 const tmp<Field<scalar> >&
396             ) const
397             {
398                 notImplemented
399                 (
400                     type()
401                   + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
402                 );
403                 return *this;
404             }
406             //- Return the matrix source coefficients corresponding to the
407             //  evaluation of the value of this patchField with given weights
408             virtual tmp<Field<Type> > valueBoundaryCoeffs
409             (
410                 const tmp<Field<scalar> >&
411             ) const
412             {
413                 notImplemented
414                 (
415                     type()
416                   + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
417                 );
418                 return *this;
419             }
421             //- Return the matrix diagonal coefficients corresponding to the
422             //  evaluation of the gradient of this patchField
423             virtual tmp<Field<Type> > gradientInternalCoeffs() const
424             {
425                 notImplemented(type() + "::gradientInternalCoeffs()");
426                 return *this;
427             }
429             //- Return the matrix source coefficients corresponding to the
430             //  evaluation of the gradient of this patchField
431             virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
432             {
433                 notImplemented(type() + "::gradientBoundaryCoeffs()");
434                 return *this;
435             }
438         // Patch interpolation and patch flux
440             //- Calculate patch face interpolate given weighting factors
441             virtual void patchInterpolate
442             (
443                 GeometricField<Type, fvsPatchField, surfaceMesh>& fField,
444                 const scalarField& pL
445             ) const;
447             //- Calculate patch face interpolate given two weighting factors
448             virtual void patchInterpolate
449             (
450                 GeometricField<Type, fvsPatchField, surfaceMesh>& fField,
451                 const scalarField& pL,
452                 const scalarField& pY
453             ) const;
455             //- Calculate patch flux
456             virtual void patchFlux
457             (
458                 GeometricField<Type, fvsPatchField, surfaceMesh>& flux,
459                 const fvMatrix<Type>& matrix
460             ) const;
463         // Matrix manipulation
465             //- Manipulate matrix
466             virtual void manipulateMatrix(fvMatrix<Type>& matrix);
469         // I-O
471             //- Write
472             virtual void write(Ostream&) const;
474             //- Helper function to write the keyword and entry only if the
475             //  values are not equal. The value is then output as value2
476             template<class EntryType>
477             void writeEntryIfDifferent
478             (
479                 Ostream& os,
480                 const word& entryName,
481                 const EntryType& value1,
482                 const EntryType& value2
483             ) const;
486         // Check
488             //- Check fvPatchField<Type> against given fvPatchField<Type>
489             void check(const fvPatchField<Type>&) const;
492     // Member operators
494         virtual void operator=(const UList<Type>&);
496         virtual void operator=(const fvPatchField<Type>&);
497         virtual void operator+=(const fvPatchField<Type>&);
498         virtual void operator-=(const fvPatchField<Type>&);
499         virtual void operator*=(const fvPatchField<scalar>&);
500         virtual void operator/=(const fvPatchField<scalar>&);
502         virtual void operator+=(const Field<Type>&);
503         virtual void operator-=(const Field<Type>&);
505         virtual void operator*=(const Field<scalar>&);
506         virtual void operator/=(const Field<scalar>&);
508         virtual void operator=(const Type&);
509         virtual void operator+=(const Type&);
510         virtual void operator-=(const Type&);
511         virtual void operator*=(const scalar);
512         virtual void operator/=(const scalar);
515         // Force an assignment irrespective of form of patch
517         virtual void operator==(const fvPatchField<Type>&);
518         virtual void operator==(const Field<Type>&);
519         virtual void operator==(const Type&);
522     // Ostream operator
524 #ifndef SWIG
525         friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
526 #endif
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
532 } // End namespace Foam
534 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
536 #ifdef NoRepository
537 #   include "fvPatchField.C"
538 #   include "calculatedFvPatchField.H"
539 #endif
542 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)   \
543                                                                               \
544 addToRunTimeSelectionTable                                                    \
545 (                                                                             \
546     PatchTypeField, typePatchTypeField, patch                                 \
547 );                                                                            \
548                                                                               \
549 addToRunTimeSelectionTable                                                    \
550 (                                                                             \
551     PatchTypeField,                                                           \
552     typePatchTypeField,                                                       \
553     patchMapper                                                               \
554 );                                                                            \
555                                                                               \
556 addToRunTimeSelectionTable                                                    \
557 (                                                                             \
558     PatchTypeField, typePatchTypeField, dictionary                            \
562 #define makePatchTypeFieldTypeName(type)                                      \
563                                                                               \
564 defineNamedTemplateTypeNameAndDebug(type, 0);
567 #define makePatchFieldsTypeName(type)                                         \
568                                                                               \
569 makePatchTypeFieldTypeName(type##FvPatchScalarField);                         \
570 makePatchTypeFieldTypeName(type##FvPatchVectorField);                         \
571 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField);                \
572 makePatchTypeFieldTypeName(type##FvPatchSymmTensorField);                     \
573 makePatchTypeFieldTypeName(type##FvPatchSymmTensor4thOrderField);             \
574 makePatchTypeFieldTypeName(type##FvPatchDiagTensorField);                     \
575 makePatchTypeFieldTypeName(type##FvPatchTensorField);
578 #define makePatchTypeField(PatchTypeField, typePatchTypeField)                \
579                                                                               \
580 defineTypeNameAndDebug(typePatchTypeField, 0);                                \
581                                                                               \
582 addToPatchFieldRunTimeSelection                                               \
583 (                                                                             \
584     PatchTypeField, typePatchTypeField                                        \
588 #define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField)        \
589                                                                               \
590 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                   \
591                                                                               \
592 addToPatchFieldRunTimeSelection                                               \
593 (                                                                             \
594     PatchTypeField, typePatchTypeField                                        \
598 #define makePatchFields(type)                                                 \
599                                                                               \
600 makeTemplatePatchTypeField(fvPatchScalarField, type##FvPatchScalarField);     \
601 makeTemplatePatchTypeField(fvPatchVectorField, type##FvPatchVectorField);     \
602 makeTemplatePatchTypeField                                                    \
603 (                                                                             \
604     fvPatchSphericalTensorField,                                              \
605     type##FvPatchSphericalTensorField                                         \
606 );                                                                            \
607 makeTemplatePatchTypeField                                                    \
608 (                                                                             \
609     fvPatchSymmTensorField,                                                   \
610     type##FvPatchSymmTensorField                                              \
611 );                                                                            \
612 makeTemplatePatchTypeField                                                    \
613 (                                                                             \
614     fvPatchSymmTensor4thOrderField,                                           \
615     type##FvPatchSymmTensor4thOrderField                                      \
616 );                                                                            \
617 makeTemplatePatchTypeField                                                    \
618  (                                                                            \
619     fvPatchDiagTensorField,                                                   \
620     type##FvPatchDiagTensorField                                              \
621 );                                                                            \
622 makeTemplatePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);
625 #define makePatchTypeFieldTypedefs(type)                                      \
626                                                                               \
627 typedef type##FvPatchField<scalar> type##FvPatchScalarField;                  \
628 typedef type##FvPatchField<vector> type##FvPatchVectorField;                  \
629 typedef type##FvPatchField<sphericalTensor>                                   \
630     type##FvPatchSphericalTensorField;                                        \
631 typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField;          \
632 typedef type##FvPatchField<symmTensor4thOrder>                                \
633     type##FvPatchSymmTensor4thOrderField;                                     \
634 typedef type##FvPatchField<diagTensor>                                        \
635     type##FvPatchDiagTensorField;                                             \
636 typedef type##FvPatchField<tensor> type##FvPatchTensorField;
639 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641 #endif
643 // ************************************************************************* //