Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / pointPatchFields / pointPatchField / pointPatchField.H
blob59ffa633a26c26f0ab1b2ed7147bde8727b148dd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::pointPatchField
27 Description
28     Abstract base class for point-mesh patch fields.
30     The base-field does not store values as they are part of the
31     "internal field".  There are derived classes to store constraint values
32     e.g. fixedValuePointPatchField derived from the generic
33     valuePointPatchField which ensures the values in the "internal field"
34     are reset to the fixed-values by applying the stored values.
36 SourceFiles
37     pointPatchField.C
38     newPointPatchField.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef pointPatchField_H
43 #define pointPatchField_H
45 #include "pointPatch.H"
46 #include "DimensionedField.H"
47 #include "autoPtr.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 // Forward declaration of classes
56 class objectRegistry;
57 class dictionary;
58 class pointPatchFieldMapper;
59 class pointMesh;
61 // Forward declaration of friend functions and operators
63 template<class Type>
64 class pointPatchField;
66 template<class Type>
67 Ostream& operator<<
69     Ostream&,
70     const pointPatchField<Type>&
74 /*---------------------------------------------------------------------------*\
75                        Class pointPatchField Declaration
76 \*---------------------------------------------------------------------------*/
78 template<class Type>
79 class pointPatchField
81     // Private data
83         //- Reference to patch
84         const pointPatch& patch_;
86         //- Reference to internal field
87         const DimensionedField<Type, pointMesh>& internalField_;
89         //- Update index used so that updateCoeffs is called only once during
90         //  the construction of the matrix
91         bool updated_;
93         //- Optional patch type, used to allow specified boundary conditions
94         //  to be applied to constraint patches by providing the constraint
95         //  patch type as 'patchType'
96         word patchType_;
99 public:
101     typedef pointPatch Patch;
104     //- Runtime type information
105     TypeName("pointPatchField");
107     //- Debug switch to disallow the use of genericPointPatchField
108     static int disallowGenericPointPatchField;
111     // Declare run-time constructor selection tables
113         declareRunTimeSelectionTable
114         (
115             autoPtr,
116             pointPatchField,
117             pointPatch,
118             (
119                 const pointPatch& p,
120                 const DimensionedField<Type, pointMesh>& iF
121             ),
122             (p, iF)
123         );
125         declareRunTimeSelectionTable
126         (
127             autoPtr,
128             pointPatchField,
129             patchMapper,
130             (
131                 const pointPatchField<Type>& ptf,
132                 const pointPatch& p,
133                 const DimensionedField<Type, pointMesh>& iF,
134                 const pointPatchFieldMapper& m
135             ),
136             (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
137         );
139         declareRunTimeSelectionTable
140         (
141             autoPtr,
142             pointPatchField,
143             dictionary,
144             (
145                 const pointPatch& p,
146                 const DimensionedField<Type, pointMesh>& iF,
147                 const dictionary& dict
148             ),
149             (p, iF, dict)
150         );
153     // Constructors
155         //- Construct from patch and internal field
156         pointPatchField
157         (
158             const pointPatch&,
159             const DimensionedField<Type, pointMesh>&
160         );
162         //- Construct from patch, internal field and dictionary
163         pointPatchField
164         (
165             const pointPatch&,
166             const DimensionedField<Type, pointMesh>&,
167             const dictionary&
168         );
170         //- Construct as copy
171         pointPatchField(const pointPatchField<Type>&);
173         //- Construct and return a clone
174         virtual autoPtr<pointPatchField<Type> > clone() const = 0;
176         //- Construct as copy setting internal field reference
177         pointPatchField
178         (
179             const pointPatchField<Type>&,
180             const DimensionedField<Type, pointMesh>&
181         );
183         //- Construct and return a clone setting internal field reference
184         virtual autoPtr<pointPatchField<Type> > clone
185         (
186             const DimensionedField<Type, pointMesh>& iF
187         ) const = 0;
190     // Selectors
192         //- Return a pointer to a new patchField created on freestore given
193         //  patch and internal field
194         //  (does not set the patch field values)
195         static autoPtr<pointPatchField<Type> > New
196         (
197             const word&,
198             const pointPatch&,
199             const DimensionedField<Type, pointMesh>&
200         );
202         //- Return a pointer to a new patchField created on freestore given
203         //  patch and internal field
204         //  (does not set the patch field values).
205         //  Allows override of constraint type
206         static autoPtr<pointPatchField<Type> > New
207         (
208             const word&,
209             const word& actualPatchType,
210             const pointPatch&,
211             const DimensionedField<Type, pointMesh>&
212         );
214         //- Return a pointer to a new patchField created on freestore from
215         //  a given pointPatchField mapped onto a new patch
216         static autoPtr<pointPatchField<Type> > New
217         (
218             const pointPatchField<Type>&,
219             const pointPatch&,
220             const DimensionedField<Type, pointMesh>&,
221             const pointPatchFieldMapper&
222         );
224         //- Return a pointer to a new patchField created on freestore
225         //  from dictionary
226         static autoPtr<pointPatchField<Type> > New
227         (
228             const pointPatch&,
229             const DimensionedField<Type, pointMesh>&,
230             const dictionary&
231         );
234         //- Return a pointer to a new CalculatedpointPatchField created on
235         //  freestore without setting patchField values
236         template<class Type2>
237         static autoPtr<pointPatchField<Type> >
238         NewCalculatedType
239         (
240             const pointPatchField<Type2>&
241         );
244     //- Destructor
245     virtual ~pointPatchField<Type>()
246     {}
249     // Member functions
251         // Access
253             //- Return local objectRegistry
254             const objectRegistry& db() const;
256             //- Return size
257             label size() const
258             {
259                 return patch().size();
260             }
262             //- Return patch
263             const pointPatch& patch() const
264             {
265                 return patch_;
266             }
268             //- Return dimensioned internal field reference
269             const DimensionedField<Type, pointMesh>&
270             dimensionedInternalField() const
271             {
272                 return internalField_;
273             }
275             //- Return internal field reference
276             const Field<Type>& internalField() const
277             {
278                 return internalField_;
279             }
281             //- Return true if this patch field is coupled
282             virtual bool coupled() const
283             {
284                 return false;
285             }
287             //- Return true if the boundary condition has already been updated
288             bool updated() const
289             {
290                 return updated_;
291             }
293             //- Return field created from appropriate internal field values
294             tmp<Field<Type> > patchInternalField() const;
296             //- Return field created from appropriate internal field values
297             //  given internal field reference
298             template<class Type1>
299             tmp<Field<Type1> > patchInternalField
300             (
301                 const Field<Type1>& iF
302             ) const;
304             //- Return field created from selected internal field values
305             //  given internal field reference
306             template<class Type1>
307             tmp<Field<Type1> > patchInternalField
308             (
309                 const Field<Type1>& iF,
310                 const labelList& meshPoints
311             ) const;
313             //- Given the internal field and a patch field,
314             //  add the patch field to the internal field
315             template<class Type1>
316             void addToInternalField
317             (
318                 Field<Type1>& iF,
319                 const Field<Type1>& pF
320             ) const;
322             //- Given the internal field and a patch field,
323             //  add selected elements of the patch field to the internal field
324             template<class Type1>
325             void addToInternalField
326             (
327                 Field<Type1>& iF,
328                 const Field<Type1>& pF,
329                 const labelList& points
330             ) const;
332             //- Given the internal field and a patch field,
333             //  set the patch field in the internal field
334             template<class Type1>
335             void setInInternalField
336             (
337                 Field<Type1>& iF,
338                 const Field<Type1>& pF,
339                 const labelList& meshPoints
340             ) const;
342             //- Given the internal field and a patch field,
343             //  set the patch field in the internal field
344             template<class Type1>
345             void setInInternalField
346             (
347                 Field<Type1>& iF,
348                 const Field<Type1>& pF
349             ) const;
351             //- Return the type of the calculated form of pointPatchField
352             static const word& calculatedType();
354             //- Return the constraint type this pointPatchField implements.
355             virtual const word& constraintType() const
356             {
357                 return word::null;
358             }
361         // Mapping functions
363             //- Map (and resize as needed) from self given a mapping object
364             virtual void autoMap
365             (
366                 const pointPatchFieldMapper&
367             )
368             {}
370             //- Reverse map the given pointPatchField onto this pointPatchField
371             virtual void rmap
372             (
373                 const pointPatchField<Type>&,
374                 const labelList&
375             )
376             {}
379         // Evaluation functions
381             //- Update the coefficients associated with the patch field
382             //  Sets Updated to true
383             virtual void updateCoeffs()
384             {
385                 updated_ = true;
386             }
388             //- Initialise evaluation of the patch field (do nothing)
389             virtual void initEvaluate
390             (
391                 const Pstream::commsTypes commsType=Pstream::blocking
392             )
393             {}
395             //- Evaluate the patch field
396             virtual void evaluate
397             (
398                 const Pstream::commsTypes commsType=Pstream::blocking
399             );
402         //- Write
403         virtual void write(Ostream&) const;
406     // Member operators
408         virtual void operator=
409         (
410             const pointPatchField<Type>&
411         )
412         {}
414         virtual void operator+=
415         (
416             const pointPatchField<Type>&
417         )
418         {}
420         virtual void operator-=
421         (
422             const pointPatchField<Type>&
423         )
424         {}
426         virtual void operator*=
427         (
428             const pointPatchField<scalar>&
429         )
430         {}
432         virtual void operator/=
433         (
434             const pointPatchField<scalar>&
435         )
436         {}
438         virtual void operator=(const Field<Type>&){}
439         virtual void operator+=(const Field<Type>&){}
440         virtual void operator-=(const Field<Type>&){}
442         virtual void operator*=(const Field<scalar>&){}
443         virtual void operator/=(const Field<scalar>&){}
445         virtual void operator=(const Type&){}
446         virtual void operator+=(const Type&){}
447         virtual void operator-=(const Type&){}
448         virtual void operator*=(const scalar){}
449         virtual void operator/=(const scalar){}
452         // Force an assignment irrespective of form of patch
453         // By generic these do nothing unless the patch actually has boundary
454         // values
456             virtual void operator==
457             (
458                 const pointPatchField<Type>&
459             )
460             {}
462             virtual void operator==(const Field<Type>&){}
463             virtual void operator==(const Type&){}
466     // Ostream operator
468         friend Ostream& operator<< <Type>
469         (
470             Ostream&,
471             const pointPatchField<Type>&
472         );
476 // This function is added as a hack to enable simple backward compatability
477 // with verions using referenceLevel in GeometicField
478 template<class Type>
479 const pointPatchField<Type>& operator+
481     const pointPatchField<Type>& ppf,
482     const Type&
485     return ppf;
489 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 } // End namespace Foam
493 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 #include "pointPatchFieldFunctions.H"
497 #ifdef NoRepository
498 #   include "pointPatchField.C"
499 #   include "calculatedPointPatchField.H"
500 #endif
503 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)      \
504     addToRunTimeSelectionTable                                                \
505     (                                                                         \
506         PatchTypeField,                                                       \
507         typePatchTypeField,                                                   \
508         pointPatch                                                            \
509     );                                                                        \
510     addToRunTimeSelectionTable                                                \
511     (                                                                         \
512         PatchTypeField,                                                       \
513         typePatchTypeField,                                                   \
514         patchMapper                                                           \
515     );                                                                        \
516     addToRunTimeSelectionTable                                                \
517     (                                                                         \
518         PatchTypeField,                                                       \
519         typePatchTypeField,                                                   \
520         dictionary                                                            \
521     );
524 // for non-templated patch fields
525 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField)            \
526     defineTypeNameAndDebug(typePatchTypeField, 0);                            \
527     addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
530 // for templated patch fields
531 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField)   \
532     defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);               \
533     addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
536 #define makePointPatchFields(type)                                            \
537     makeTemplatePointPatchTypeField                                           \
538     (                                                                         \
539         pointPatchScalarField,                                                \
540         type##PointPatchScalarField                                           \
541     );                                                                        \
542     makeTemplatePointPatchTypeField                                           \
543     (                                                                         \
544         pointPatchVectorField,                                                \
545         type##PointPatchVectorField                                           \
546     );                                                                        \
547     makeTemplatePointPatchTypeField                                           \
548     (                                                                         \
549         pointPatchSphericalTensorField,                                       \
550         type##PointPatchSphericalTensorField                                  \
551     );                                                                        \
552     makeTemplatePointPatchTypeField                                           \
553     (                                                                         \
554         pointPatchSymmTensorField,                                            \
555         type##PointPatchSymmTensorField                                       \
556     );                                                                        \
557     makeTemplatePointPatchTypeField                                           \
558     (                                                                         \
559         pointPatchTensorField,                                                \
560         type##PointPatchTensorField                                           \
564 #define makePointPatchFieldsTypeName(type)                                    \
565     defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0);      \
566     defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0);      \
567     defineNamedTemplateTypeNameAndDebug                                       \
568     (                                                                         \
569         type##PointPatchSphericalTensorField, 0                               \
570     );                                                                        \
571     defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0);  \
572     defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
575 #define makePointPatchFieldTypedefs(type)                                     \
576     typedef type##PointPatchField<scalar> type##PointPatchScalarField;        \
577     typedef type##PointPatchField<vector> type##PointPatchVectorField;        \
578     typedef type##PointPatchField<sphericalTensor>                            \
579         type##PointPatchSphericalTensorField;                                 \
580     typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
581     typedef type##PointPatchField<tensor> type##PointPatchTensorField;
584 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 #endif
588 // ************************************************************************* //