BUGFIX: Seg-fault in multiphaseInterFoam. Author: Henrik Rusche. Merge: Hrvoje Jasak
[foam-extend-3.2.git] / src / finiteVolume / fields / fvsPatchFields / fvsPatchField / fvsPatchField.H
blobbda649684cbcaf808f8bffda31b10bd04e29bd96
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::fvsPatchField
27 Description
28     An 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 typed with
35     specific evaluation proceedures, particularly with respect to specific
36     fields.
38 SourceFiles
39     fvsPatchField.C
40     newFvsPatchField.C
42 \*---------------------------------------------------------------------------*/
44 #ifndef fvsPatchField_H
45 #define fvsPatchField_H
47 #include "fvPatch.H"
48 #include "DimensionedField.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 // Forward declaration of classes
57 class objectRegistry;
58 class dictionary;
59 class fvPatchFieldMapper;
60 class surfaceMesh;
62 template<class Type>
63 class fvPatchField;
65 // Forward declaration of friend functions and operators
67 template<class Type>
68 class fvsPatchField;
70 template<class Type>
71 Ostream& operator<<(Ostream&, const fvsPatchField<Type>&);
74 /*---------------------------------------------------------------------------*\
75                            Class patch Declaration
76 \*---------------------------------------------------------------------------*/
78 template<class Type>
79 class fvsPatchField
81     public Field<Type>
83     // Private data
85         //- Reference to patch
86         const fvPatch& patch_;
88         //- Reference to internal field
89         const DimensionedField<Type, surfaceMesh>& internalField_;
92 public:
94     typedef fvPatch Patch;
97     //- Runtime type information
98     TypeName("fvsPatchField");
100     //- Debug switch to disallow the use of
101     static debug::debugSwitch disallowDefaultFvsPatchField;
104     // Declare run-time constructor selection tables
106 #ifndef SWIG
107         declareRunTimeSelectionTable
108         (
109             tmp,
110             fvsPatchField,
111             patch,
112             (
113                 const fvPatch& p,
114                 const DimensionedField<Type, surfaceMesh>& iF
115             ),
116             (p, iF)
117         );
119         declareRunTimeSelectionTable
120         (
121             tmp,
122             fvsPatchField,
123             patchMapper,
124             (
125                 const fvsPatchField<Type>& ptf,
126                 const fvPatch& p,
127                 const DimensionedField<Type, surfaceMesh>& iF,
128                 const fvPatchFieldMapper& m
129             ),
130             (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
131         );
133         declareRunTimeSelectionTable
134         (
135             tmp,
136             fvsPatchField,
137             dictionary,
138             (
139                 const fvPatch& p,
140                 const DimensionedField<Type, surfaceMesh>& iF,
141                 const dictionary& dict
142             ),
143             (p, iF, dict)
144         );
145 #endif
147     // Constructors
149         //- Construct from patch and internal field
150         fvsPatchField
151         (
152             const fvPatch&,
153             const DimensionedField<Type, surfaceMesh>&
154         );
156         //- Construct from patch and internal field and patch field
157         fvsPatchField
158         (
159             const fvPatch&,
160             const DimensionedField<Type, surfaceMesh>&,
161             const Field<Type>&
162         );
164         //- Construct from patch, internal field and dictionary
165         fvsPatchField
166         (
167             const fvPatch&,
168             const DimensionedField<Type, surfaceMesh>&,
169             const dictionary&,
170             const bool valueRequired = false
171         );
173         //- Construct by mapping the given fvsPatchField onto a new patch
174         fvsPatchField
175         (
176             const fvsPatchField<Type>&,
177             const fvPatch&,
178             const DimensionedField<Type, surfaceMesh>&,
179             const fvPatchFieldMapper&
180         );
182         //- Construct as copy
183         fvsPatchField(const fvsPatchField<Type>&);
185         //- Construct and return a clone
186         virtual tmp<fvsPatchField<Type> > clone() const
187         {
188             return tmp<fvsPatchField<Type> >(new fvsPatchField<Type>(*this));
189         }
191         //- Construct as copy setting internal field reference
192         fvsPatchField
193         (
194             const fvsPatchField<Type>&,
195             const DimensionedField<Type, surfaceMesh>&
196         );
198         //- Construct and return a clone setting internal field reference
199         virtual tmp<fvsPatchField<Type> > clone
200         (
201             const DimensionedField<Type, surfaceMesh>& iF
202         ) const
203         {
204             return tmp<fvsPatchField<Type> >
205             (
206                 new fvsPatchField<Type>(*this, iF)
207             );
208         }
211     // Selectors
213         //- Return a pointer to a new patchField created on freestore given
214         //  patch and internal field
215         //  (does not set the patch field values)
216         static tmp<fvsPatchField<Type> > New
217         (
218             const word&,
219             const fvPatch&,
220             const DimensionedField<Type, surfaceMesh>&
221         );
223         //- Return a pointer to a new patchField created on freestore from
224         //  a given fvsPatchField mapped onto a new patch
225         static tmp<fvsPatchField<Type> > New
226         (
227             const fvsPatchField<Type>&,
228             const fvPatch&,
229             const DimensionedField<Type, surfaceMesh>&,
230             const fvPatchFieldMapper&
231         );
233         //- Return a pointer to a new patchField created on freestore
234         //  from dictionary
235         static tmp<fvsPatchField<Type> > New
236         (
237             const fvPatch&,
238             const DimensionedField<Type, surfaceMesh>&,
239             const dictionary&
240         );
242         //- Return a pointer to a new calculatedFvsPatchField created on
243         //  freestore without setting patchField values
244         template<class Type2>
245         static tmp<fvsPatchField<Type> > NewCalculatedType
246         (
247             const fvsPatchField<Type2>&
248         );
251     // Destructor
253         virtual ~fvsPatchField<Type>()
254         {}
257     // Member functions
259         // Access
261             //- Return local objectRegistry
262             const objectRegistry& db() const;
264             //- Lookup and return the patchField of the named field from the
265             //  field's objectRegistry.
266             //  N.B.  The dummy pointer arguments are used if this function is
267             //  instantiated within a templated function to avoid a bug in gcc.
268             //  See inletOutletFvPatchField.C and outletInletFvPatchField.C
269             template<class GeometricField, class Type2>
270             const typename GeometricField::PatchFieldType& lookupPatchField
271             (
272                 const word& name,
273                 const GeometricField* = NULL,
274                 const Type2* = NULL
275             ) const;
277             //- Return patch
278             const fvPatch& patch() const
279             {
280                 return patch_;
281             }
283             //- Return dimensioned internal field reference
284             const DimensionedField<Type, surfaceMesh>&
285             dimensionedInternalField() const
286             {
287                 return internalField_;
288             }
290             //- Return internal field reference
291             const Field<Type>& internalField() const
292             {
293                 return internalField_;
294             }
296             //- Return the type of the calculated for of fvsPatchField
297             static const word& calculatedType();
299             //- Return true if this patch field fixes a value.
300             //  Needed to check if a level has to be specified while solving
301             //  Poissons equations.
302             virtual bool fixesValue() const
303             {
304                 return false;
305             }
307             //- Return true if this patch field is coupled
308             virtual bool coupled() const
309             {
310                 return false;
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 fvsPatchField onto this fvsPatchField
323             virtual void rmap
324             (
325                 const fvsPatchField<Type>&,
326                 const labelList&
327             );
330         // Evaluation functions
332             //- Initialise the evaluation of the patch field
333             virtual void initEvaluate
334             (
335                 const Pstream::commsTypes commsType = Pstream::blocking
336             )
337             {}
339             //- Evaluate the patch field, sets Updated to false
340             virtual void evaluate
341             (
342                 const Pstream::commsTypes commsType = Pstream::blocking
343             )
344             {}
347         //- Write
348         virtual void write(Ostream&) const;
351         // Check
353             //- Check fvsPatchField<Type> against given fvsPatchField<Type>
354             void check(const fvsPatchField<Type>&) const;
356             //- Check fvsPatchField<Type> against given fvPatchField<Type>
357             void check(const fvPatchField<Type>&) const;
360     // Member operators
362         virtual void operator=(const UList<Type>&);
364         virtual void operator=(const fvsPatchField<Type>&);
365         virtual void operator+=(const fvsPatchField<Type>&);
366         virtual void operator-=(const fvsPatchField<Type>&);
367         virtual void operator*=(const fvsPatchField<scalar>&);
368         virtual void operator/=(const fvsPatchField<scalar>&);
370         virtual void operator=(const fvPatchField<Type>&);
372         virtual void operator+=(const Field<Type>&);
373         virtual void operator-=(const Field<Type>&);
375         virtual void operator*=(const Field<scalar>&);
376         virtual void operator/=(const Field<scalar>&);
378         virtual void operator=(const Type&);
379         virtual void operator+=(const Type&);
380         virtual void operator-=(const Type&);
381         virtual void operator*=(const scalar);
382         virtual void operator/=(const scalar);
385         // Force an assignment irrespective of form of patch
387         virtual void operator==(const fvsPatchField<Type>&);
388         virtual void operator==(const Field<Type>&);
389         virtual void operator==(const Type&);
392     // Ostream operator
394 #ifndef SWIG
395         friend Ostream& operator<< <Type>
396         (
397             Ostream&,
398             const fvsPatchField<Type>&
399         );
400 #endif
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 } // End namespace Foam
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 #ifdef NoRepository
411 #   include "fvsPatchField.C"
412 #   include "calculatedFvsPatchField.H"
413 #endif
416 #define makeFvsPatchTypeFieldTypeName(type)                                \
417                                                                            \
418 defineNamedTemplateTypeNameAndDebug(type, 0);
420 #define makeFvsPatchFieldsTypeName(type)                                   \
421                                                                            \
422 makeFvsPatchTypeFieldTypeName(type##FvsPatchScalarField);                  \
423 makeFvsPatchTypeFieldTypeName(type##FvsPatchVectorField);                  \
424 makeFvsPatchTypeFieldTypeName(type##FvsPatchSphericalTensorField);         \
425 makeFvsPatchTypeFieldTypeName(type##FvsPatchSymmTensorField);              \
426 makeFvsPatchTypeFieldTypeName(type##FvsPatchSymmTensor4thOrderField);      \
427 makeFvsPatchTypeFieldTypeName(type##FvsPatchDiagTensorField);              \
428 makeFvsPatchTypeFieldTypeName(type##FvsPatchTensorField);
430 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField)          \
431                                                                            \
432 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);                \
433                                                                            \
434 addToRunTimeSelectionTable                                                 \
435 (                                                                          \
436     PatchTypeField, typePatchTypeField, patch                              \
437 );                                                                         \
438                                                                            \
439 addToRunTimeSelectionTable                                                 \
440 (                                                                          \
441     PatchTypeField,                                                        \
442     typePatchTypeField,                                                    \
443     patchMapper                                                            \
444 );                                                                         \
445                                                                            \
446 addToRunTimeSelectionTable                                                 \
447 (                                                                          \
448     PatchTypeField, typePatchTypeField, dictionary                         \
452 #define makeFvsPatchFields(type)                                           \
453                                                                            \
454 makeFvsPatchTypeField(fvsPatchScalarField, type##FvsPatchScalarField);     \
455 makeFvsPatchTypeField(fvsPatchVectorField, type##FvsPatchVectorField);     \
456 makeFvsPatchTypeField                                                      \
457 (                                                                          \
458     fvsPatchSphericalTensorField,                                          \
459     type##FvsPatchSphericalTensorField                                     \
460 );                                                                         \
461 makeFvsPatchTypeField(fvsPatchSymmTensorField, type##FvsPatchSymmTensorField); \
462 makeFvsPatchTypeField                                                      \
463 (                                                                          \
464     fvsPatchSymmTensor4thOrderField,                                       \
465     type##FvsPatchSymmTensor4thOrderField                                  \
466 );                                                                         \
467 makeFvsPatchTypeField                                                      \
468 (                                                                          \
469     fvsPatchDiagTensorField,                                               \
470     type##FvsPatchDiagTensorField                                          \
471 );                                                                         \
472 makeFvsPatchTypeField(fvsPatchTensorField, type##FvsPatchTensorField);
475 #define makeFvsPatchTypeFieldTypedefs(type)                                \
476                                                                            \
477 typedef type##FvsPatchField<scalar> type##FvsPatchScalarField;             \
478 typedef type##FvsPatchField<vector> type##FvsPatchVectorField;             \
479 typedef type##FvsPatchField<sphericalTensor>                               \
480     type##FvsPatchSphericalTensorField;                                    \
481 typedef type##FvsPatchField<symmTensor> type##FvsPatchSymmTensorField;     \
482 typedef type##FvsPatchField<symmTensor4thOrder>                            \
483     type##FvsPatchSymmTensor4thOrderField;                                 \
484 typedef type##FvsPatchField<diagTensor>                                    \
485     type##FvsPatchDiagTensorField;                                         \
486 typedef type##FvsPatchField<tensor> type##FvsPatchTensorField;
489 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 #endif
493 // ************************************************************************* //