fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / fvPatchField / fvPatchField.H
blob8563e00f479fec54ecb5987a021e65b82b5c9cce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 #ifndef SWIG
118         declareRunTimeSelectionTable
119         (
120             tmp,
121             fvPatchField,
122             patch,
123             (
124                 const fvPatch& p,
125                 const DimensionedField<Type, volMesh>& iF
126             ),
127             (p, iF)
128         );
130         declareRunTimeSelectionTable
131         (
132             tmp,
133             fvPatchField,
134             patchMapper,
135             (
136                 const fvPatchField<Type>& ptf,
137                 const fvPatch& p,
138                 const DimensionedField<Type, volMesh>& iF,
139                 const fvPatchFieldMapper& m
140             ),
141             (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
142         );
144         declareRunTimeSelectionTable
145         (
146             tmp,
147             fvPatchField,
148             dictionary,
149             (
150                 const fvPatch& p,
151                 const DimensionedField<Type, volMesh>& iF,
152                 const dictionary& dict
153             ),
154             (p, iF, dict)
155         );
156 #endif
158     // Constructors
160         //- Construct from patch and internal field
161         fvPatchField
162         (
163             const fvPatch&,
164             const DimensionedField<Type, volMesh>&
165         );
167         //- Construct from patch and internal field and patch field
168         fvPatchField
169         (
170             const fvPatch&,
171             const DimensionedField<Type, volMesh>&,
172             const Field<Type>&
173         );
175         //- Construct from patch, internal field and dictionary
176         fvPatchField
177         (
178             const fvPatch&,
179             const DimensionedField<Type, volMesh>&,
180             const dictionary&,
181             const bool valueRequired = false
182         );
184         //- Construct by mapping the given fvPatchField onto a new patch
185         fvPatchField
186         (
187             const fvPatchField<Type>&,
188             const fvPatch&,
189             const DimensionedField<Type, volMesh>&,
190             const fvPatchFieldMapper&
191         );
193         //- Construct as copy
194         fvPatchField(const fvPatchField<Type>&);
196         //- Construct and return a clone
197         virtual tmp<fvPatchField<Type> > clone() const
198         {
199             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
200         }
202         //- Construct as copy setting internal field reference
203         fvPatchField
204         (
205             const fvPatchField<Type>&,
206             const DimensionedField<Type, volMesh>&
207         );
209         //- Construct and return a clone setting internal field reference
210         virtual tmp<fvPatchField<Type> > clone
211         (
212             const DimensionedField<Type, volMesh>& iF
213         ) const
214         {
215             return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
216         }
219     // Selectors
221         //- Return a pointer to a new patchField created on freestore given
222         //  patch and internal field
223         //  (does not set the patch field values)
224         static tmp<fvPatchField<Type> > New
225         (
226             const word&,
227             const fvPatch&,
228             const DimensionedField<Type, volMesh>&
229         );
231         //- Return a pointer to a new patchField created on freestore from
232         //  a given fvPatchField mapped onto a new patch
233         static tmp<fvPatchField<Type> > New
234         (
235             const fvPatchField<Type>&,
236             const fvPatch&,
237             const DimensionedField<Type, volMesh>&,
238             const fvPatchFieldMapper&
239         );
241         //- Return a pointer to a new patchField created on freestore
242         //  from dictionary
243         static tmp<fvPatchField<Type> > New
244         (
245             const fvPatch&,
246             const DimensionedField<Type, volMesh>&,
247             const dictionary&
248         );
250         //- Return a pointer to a new calculatedFvPatchField created on
251         //  freestore without setting patchField values
252         template<class Type2>
253         static tmp<fvPatchField<Type> > NewCalculatedType
254         (
255             const fvPatchField<Type2>&
256         );
259     // Destructor
261         virtual ~fvPatchField<Type>()
262         {}
265     // Member functions
267         // Access
269             //- Return local objectRegistry
270             const objectRegistry& db() const;
272             //- Return patch
273             const fvPatch& patch() const
274             {
275                 return patch_;
276             }
278             //- Return dimensioned internal field reference
279             const DimensionedField<Type, volMesh>&
280             dimensionedInternalField() const
281             {
282                 return internalField_;
283             }
285             //- Return internal field reference
286             const Field<Type>& internalField() const
287             {
288                 return internalField_;
289             }
291             //- Return the type of the calculated for of fvPatchField
292             static const word& calculatedType();
294             //- Return true if this patch field fixes a value.
295             //  Needed to check if a level has to be specified while solving
296             //  Poissons equations.
297             virtual bool fixesValue() const
298             {
299                 return false;
300             }
302             //- Return true if this patch field is coupled
303             virtual bool coupled() const
304             {
305                 return false;
306             }
308             //- Return true if the boundary condition has already been updated
309             bool updated() const
310             {
311                 return updated_;
312             }
315         // Mapping functions
317             //- Map (and resize as needed) from self given a mapping object
318             virtual void autoMap
319             (
320                 const fvPatchFieldMapper&
321             );
323             //- Reverse map the given fvPatchField onto this fvPatchField
324             virtual void rmap
325             (
326                 const fvPatchField<Type>&,
327                 const labelList&
328             );
331         // Evaluation functions
333             //- Return patch-normal gradient
334             virtual tmp<Field<Type> > snGrad() const;
336             //- Update the coefficients associated with the patch field
337             //  Sets Updated to true
338             virtual void updateCoeffs()
339             {
340                 updated_ = true;
341             }
343             //- Return internal field next to patch as patch field
344             virtual tmp<Field<Type> > patchInternalField() const;
346             //- Return patchField on the opposite patch of a coupled patch
347             virtual tmp<Field<Type> > patchNeighbourField() const
348             {
349                 notImplemented(type() + "patchNeighbourField()");
350                 return *this;
351             }
353             //- Initialise the evaluation of the patch field
354             virtual void initEvaluate
355             (
356                 const Pstream::commsTypes commsType=Pstream::blocking
357             )
358             {}
360             //- Evaluate the patch field, sets Updated to false
361             virtual void evaluate
362             (
363                 const Pstream::commsTypes commsType=Pstream::blocking
364             );
367             //- Return the matrix diagonal coefficients corresponding to the
368             //  evaluation of the value of this patchField with given weights
369             virtual tmp<Field<Type> > valueInternalCoeffs
370             (
371                 const tmp<Field<scalar> >&
372             ) const
373             {
374                 notImplemented
375                 (
376                     type()
377                   + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
378                 );
379                 return *this;
380             }
382             //- Return the matrix source coefficients corresponding to the
383             //  evaluation of the value of this patchField with given weights
384             virtual tmp<Field<Type> > valueBoundaryCoeffs
385             (
386                 const tmp<Field<scalar> >&
387             ) const
388             {
389                 notImplemented
390                 (
391                     type()
392                   + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
393                 );
394                 return *this;
395             }
397             //- Return the matrix diagonal coefficients corresponding to the
398             //  evaluation of the gradient of this patchField
399             virtual tmp<Field<Type> > gradientInternalCoeffs() const
400             {
401                 notImplemented(type() + "::gradientInternalCoeffs()");
402                 return *this;
403             }
405             //- Return the matrix source coefficients corresponding to the
406             //  evaluation of the gradient of this patchField
407             virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
408             {
409                 notImplemented(type() + "::gradientBoundaryCoeffs()");
410                 return *this;
411             }
414             //- Manipulate matrix
415             virtual void manipulateMatrix(fvMatrix<Type>& matrix);
418         // I-O
420             //- Write
421             virtual void write(Ostream&) const;
423             //- Helper function to write the keyword and entry only if the
424             //  values are not equal. The value is then output as value2
425             template<class EntryType>
426             void writeEntryIfDifferent
427             (
428                 Ostream& os,
429                 const word& entryName,
430                 const EntryType& value1,
431                 const EntryType& value2
432             ) const;
435         // Check
437             //- Check fvPatchField<Type> against given fvPatchField<Type>
438             void check(const fvPatchField<Type>&) const;
441     // Member operators
443         virtual void operator=(const UList<Type>&);
445         virtual void operator=(const fvPatchField<Type>&);
446         virtual void operator+=(const fvPatchField<Type>&);
447         virtual void operator-=(const fvPatchField<Type>&);
448         virtual void operator*=(const fvPatchField<scalar>&);
449         virtual void operator/=(const fvPatchField<scalar>&);
451         virtual void operator+=(const Field<Type>&);
452         virtual void operator-=(const Field<Type>&);
454         virtual void operator*=(const Field<scalar>&);
455         virtual void operator/=(const Field<scalar>&);
457         virtual void operator=(const Type&);
458         virtual void operator+=(const Type&);
459         virtual void operator-=(const Type&);
460         virtual void operator*=(const scalar);
461         virtual void operator/=(const scalar);
464         // Force an assignment irrespective of form of patch
466         virtual void operator==(const fvPatchField<Type>&);
467         virtual void operator==(const Field<Type>&);
468         virtual void operator==(const Type&);
471     // Ostream operator
473 #ifndef SWIG
474         friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
475 #endif
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 } // End namespace Foam
483 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 #ifdef NoRepository
486 #   include "fvPatchField.C"
487 #   include "calculatedFvPatchField.H"
488 #endif
491 #define makePatchTypeFieldTypeName(type)                                   \
492                                                                            \
493 defineNamedTemplateTypeNameAndDebug(type, 0);
495 #define makePatchFieldsTypeName(type)                                      \
496                                                                            \
497 makePatchTypeFieldTypeName(type##FvPatchScalarField);                      \
498 makePatchTypeFieldTypeName(type##FvPatchVectorField);                      \
499 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField);             \
500 makePatchTypeFieldTypeName(type##FvPatchSymmTensorField);                  \
501 makePatchTypeFieldTypeName(type##FvPatchTensorField);
503 #define makePatchTypeField(PatchTypeField, typePatchTypeField)             \
504                                                                            \
505 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                \
506                                                                            \
507 addToRunTimeSelectionTable                                                 \
508 (                                                                          \
509     PatchTypeField, typePatchTypeField, patch                              \
510 );                                                                         \
511                                                                            \
512 addToRunTimeSelectionTable                                                 \
513 (                                                                          \
514     PatchTypeField,                                                        \
515     typePatchTypeField,                                                    \
516     patchMapper                                                            \
517 );                                                                         \
518                                                                            \
519 addToRunTimeSelectionTable                                                 \
520 (                                                                          \
521     PatchTypeField, typePatchTypeField, dictionary                         \
525 #define makePatchFields(type)                                              \
526                                                                            \
527 makePatchTypeField(fvPatchScalarField, type##FvPatchScalarField);          \
528 makePatchTypeField(fvPatchVectorField, type##FvPatchVectorField);          \
529 makePatchTypeField                                                         \
530 (                                                                          \
531     fvPatchSphericalTensorField,                                           \
532     type##FvPatchSphericalTensorField                                      \
533 );                                                                         \
534 makePatchTypeField(fvPatchSymmTensorField, type##FvPatchSymmTensorField);  \
535 makePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);
538 #define makePatchTypeFieldTypedefs(type)                                   \
539                                                                            \
540 typedef type##FvPatchField<scalar> type##FvPatchScalarField;               \
541 typedef type##FvPatchField<vector> type##FvPatchVectorField;               \
542 typedef type##FvPatchField<sphericalTensor>                                \
543     type##FvPatchSphericalTensorField;                                     \
544 typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField;       \
545 typedef type##FvPatchField<tensor> type##FvPatchTensorField;
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
550 #endif
552 // ************************************************************************* //