pointPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::pointPatchField
26 
27 Description
28  Abstract base class for point-mesh patch fields.
29 
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.
35 
36 SourceFiles
37  pointPatchField.C
38  newPointPatchField.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef pointPatchField_H
43 #define pointPatchField_H
44 
45 #include "pointPatch.H"
46 #include "DimensionedField.H"
47 #include "autoPtr.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration of classes
55 
56 class objectRegistry;
57 class dictionary;
58 class pointPatchFieldMapper;
59 class pointMesh;
60 
61 // Forward declaration of friend functions and operators
62 
63 template<class Type>
64 class pointPatchField;
65 
66 template<class Type>
67 class calculatedPointPatchField;
68 
69 template<class Type>
70 Ostream& operator<<
71 (
72  Ostream&,
73  const pointPatchField<Type>&
74 );
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class pointPatchField Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Type>
82 class pointPatchField
83 {
84  // Private data
85 
86  //- Reference to patch
87  const pointPatch& patch_;
88 
89  //- Reference to internal field
90  const DimensionedField<Type, pointMesh>& internalField_;
91 
92  //- Update index used so that updateCoeffs is called only once during
93  // the construction of the matrix
94  bool updated_;
95 
96  //- Optional patch type, used to allow specified boundary conditions
97  // to be applied to constraint patches by providing the constraint
98  // patch type as 'patchType'
99  word patchType_;
100 
101 
102 public:
104  typedef pointPatch Patch;
106 
107 
108  //- Runtime type information
109  TypeName("pointPatchField");
110 
111  //- Debug switch to disallow the use of genericPointPatchField
113 
114 
115  // Declare run-time constructor selection tables
116 
118  (
119  autoPtr,
121  pointPatch,
122  (
123  const pointPatch& p,
125  ),
126  (p, iF)
127  );
128 
130  (
131  autoPtr,
133  patchMapper,
134  (
135  const pointPatchField<Type>& ptf,
136  const pointPatch& p,
138  const pointPatchFieldMapper& m
139  ),
140  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
141  );
142 
144  (
145  autoPtr,
147  dictionary,
148  (
149  const pointPatch& p,
151  const dictionary& dict
152  ),
153  (p, iF, dict)
154  );
155 
156 
157  // Constructors
158 
159  //- Construct from patch and internal field
161  (
162  const pointPatch&,
164  );
165 
166  //- Construct from patch, internal field and dictionary
168  (
169  const pointPatch&,
171  const dictionary&
172  );
173 
174  //- Construct by mapping given patchField<Type> onto a new patch
176  (
177  const pointPatchField<Type>&,
178  const pointPatch&,
180  const pointPatchFieldMapper&
181  );
182 
183  //- Construct as copy
185 
186  //- Construct and return a clone
187  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
188 
189  //- Construct as copy setting internal field reference
191  (
192  const pointPatchField<Type>&,
194  );
195 
196  //- Construct and return a clone setting internal field reference
198  (
200  ) const = 0;
201 
202 
203  // Selectors
204 
205  //- Return a pointer to a new patchField created on freestore given
206  // patch and internal field
207  // (does not set the patch field values)
209  (
210  const word&,
211  const pointPatch&,
213  );
214 
215  //- Return a pointer to a new patchField created on freestore given
216  // patch and internal field
217  // (does not set the patch field values).
218  // Allows override of constraint type
220  (
221  const word&,
222  const word& actualPatchType,
223  const pointPatch&,
225  );
226 
227  //- Return a pointer to a new patchField created on freestore from
228  // a given pointPatchField mapped onto a new patch
230  (
231  const pointPatchField<Type>&,
232  const pointPatch&,
234  const pointPatchFieldMapper&
235  );
236 
237  //- Return a pointer to a new patchField created on freestore
238  // from dictionary
240  (
241  const pointPatch&,
243  const dictionary&
244  );
245 
246  //- Return a pointer to a new calculatedPointPatchField created on
247  // freestore without setting patchField values
248  template<class Type2>
251  (
253  );
254 
255 
256  //- Destructor
257  virtual ~pointPatchField<Type>()
258  {}
259 
260 
261  // Member functions
262 
263  // Access
264 
265  //- Return local objectRegistry
266  const objectRegistry& db() const;
267 
268  //- Return size
269  label size() const
270  {
271  return patch().size();
272  }
273 
274  //- Return patch
275  const pointPatch& patch() const
276  {
277  return patch_;
278  }
279 
280  //- Return dimensioned internal field reference
282  internalField() const
283  {
284  return internalField_;
285  }
286 
287  //- Return internal field reference
288  const Field<Type>& primitiveField() const
289  {
290  return internalField_;
291  }
292 
293  //- Optional patch type
294  const word& patchType() const
295  {
296  return patchType_;
297  }
298 
299  //- Optional patch type
300  word& patchType()
301  {
302  return patchType_;
303  }
304 
305  //- Return true if this patch field fixes a value
306  virtual bool fixesValue() const
307  {
308  return false;
309  }
310 
311  //- Return true if this patch field is coupled
312  virtual bool coupled() const
313  {
314  return false;
315  }
316 
317  //- Return true if the boundary condition has already been updated
318  bool updated() const
319  {
320  return updated_;
321  }
322 
323  //- Return field created from appropriate internal field values
325 
326  //- Return field created from appropriate internal field values
327  // given internal field reference
328  template<class Type1>
330  (
331  const Field<Type1>& iF
332  ) const;
333 
334  //- Return field created from selected internal field values
335  // given internal field reference
336  template<class Type1>
338  (
339  const Field<Type1>& iF,
340  const labelList& meshPoints
341  ) const;
342 
343  //- Given the internal field and a patch field,
344  // add the patch field to the internal field
345  template<class Type1>
346  void addToInternalField
347  (
348  Field<Type1>& iF,
349  const Field<Type1>& pF
350  ) const;
351 
352  //- Given the internal field and a patch field,
353  // add selected elements of the patch field to the internal field
354  template<class Type1>
355  void addToInternalField
356  (
357  Field<Type1>& iF,
358  const Field<Type1>& pF,
359  const labelList& points
360  ) const;
361 
362  //- Given the internal field and a patch field,
363  // set the patch field in the internal field
364  template<class Type1>
365  void setInInternalField
366  (
367  Field<Type1>& iF,
368  const Field<Type1>& pF,
369  const labelList& meshPoints
370  ) const;
371 
372  //- Given the internal field and a patch field,
373  // set the patch field in the internal field
374  template<class Type1>
375  void setInInternalField
376  (
377  Field<Type1>& iF,
378  const Field<Type1>& pF
379  ) const;
380 
381  //- Return the type of the calculated form of pointPatchField
382  static const word& calculatedType();
383 
384  //- Return the constraint type this pointPatchField implements.
385  virtual const word& constraintType() const
386  {
387  return word::null;
388  }
389 
390 
391  // Mapping functions
392 
393  //- Map (and resize as needed) from self given a mapping object
394  virtual void autoMap
395  (
396  const pointPatchFieldMapper&
397  )
398  {}
399 
400  //- Reverse map the given pointPatchField onto this pointPatchField
401  virtual void rmap
402  (
403  const pointPatchField<Type>&,
404  const labelList&
405  )
406  {}
407 
408 
409  // Evaluation functions
410 
411  //- Update the coefficients associated with the patch field
412  // Sets Updated to true
413  virtual void updateCoeffs()
414  {
415  updated_ = true;
416  }
417 
418  //- Initialise evaluation of the patch field (do nothing)
419  virtual void initEvaluate
420  (
421  const Pstream::commsTypes commsType=Pstream::blocking
422  )
423  {}
424 
425  //- Evaluate the patch field
426  virtual void evaluate
427  (
428  const Pstream::commsTypes commsType=Pstream::blocking
429  );
430 
431 
432  //- Write
433  virtual void write(Ostream&) const;
434 
435 
436  // Member operators
438  virtual void operator=(const pointPatchField<Type>&){}
439  virtual void operator+=(const pointPatchField<Type>&){}
440  virtual void operator-=(const pointPatchField<Type>&){}
441  virtual void operator*=(const pointPatchField<scalar>&){}
442  virtual void operator/=(const pointPatchField<scalar>&){}
444  virtual void operator=(const Field<Type>&){}
445  virtual void operator+=(const Field<Type>&){}
446  virtual void operator-=(const Field<Type>&){}
448  virtual void operator*=(const Field<scalar>&){}
449  virtual void operator/=(const Field<scalar>&){}
451  virtual void operator=(const Type&){}
452  virtual void operator+=(const Type&){}
453  virtual void operator-=(const Type&){}
454  virtual void operator*=(const scalar){}
455  virtual void operator/=(const scalar){}
456 
457 
458  // Force an assignment irrespective of form of patch
459  // By generic these do nothing unless the patch actually has boundary
460  // values
462  virtual void operator==(const pointPatchField<Type>&){}
463  virtual void operator==(const Field<Type>&){}
464  virtual void operator==(const Type&){}
465 
466 
467  // Ostream operator
468 
469  friend Ostream& operator<< <Type>
470  (
471  Ostream&,
472  const pointPatchField<Type>&
473  );
474 };
475 
476 
477 // This function is added as a hack to enable simple backward compatability
478 // with verions using referenceLevel in GeometicField
479 template<class Type>
480 const pointPatchField<Type>& operator+
481 (
482  const pointPatchField<Type>& ppf,
483  const Type&
484 )
485 {
486  return ppf;
487 }
488 
489 
490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 
492 } // End namespace Foam
493 
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 
497 
498 #ifdef NoRepository
499  #include "pointPatchField.C"
500  #include "calculatedPointPatchField.H"
501 #endif
502 
504 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
505  addToRunTimeSelectionTable \
506  ( \
507  PatchTypeField, \
508  typePatchTypeField, \
509  pointPatch \
510  ); \
511  addToRunTimeSelectionTable \
512  ( \
513  PatchTypeField, \
514  typePatchTypeField, \
515  patchMapper \
516  ); \
517  addToRunTimeSelectionTable \
518  ( \
519  PatchTypeField, \
520  typePatchTypeField, \
521  dictionary \
522  );
523 
524 
525 // for non-templated patch fields
526 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField) \
527  defineTypeNameAndDebug(typePatchTypeField, 0); \
528  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
529 
530 
531 // for templated patch fields
532 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField) \
533  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
534  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
535 
537 #define makePointPatchFields(type) \
538  makeTemplatePointPatchTypeField \
539  ( \
540  pointPatchScalarField, \
541  type##PointPatchScalarField \
542  ); \
543  makeTemplatePointPatchTypeField \
544  ( \
545  pointPatchVectorField, \
546  type##PointPatchVectorField \
547  ); \
548  makeTemplatePointPatchTypeField \
549  ( \
550  pointPatchSphericalTensorField, \
551  type##PointPatchSphericalTensorField \
552  ); \
553  makeTemplatePointPatchTypeField \
554  ( \
555  pointPatchSymmTensorField, \
556  type##PointPatchSymmTensorField \
557  ); \
558  makeTemplatePointPatchTypeField \
559  ( \
560  pointPatchTensorField, \
561  type##PointPatchTensorField \
562 );
563 
565 #define makePointPatchFieldsTypeName(type) \
566  defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0); \
567  defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0); \
568  defineNamedTemplateTypeNameAndDebug \
569  ( \
570  type##PointPatchSphericalTensorField, 0 \
571  ); \
572  defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0); \
573  defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
574 
576 #define makePointPatchFieldTypedefs(type) \
577  typedef type##PointPatchField<scalar> type##PointPatchScalarField; \
578  typedef type##PointPatchField<vector> type##PointPatchVectorField; \
579  typedef type##PointPatchField<sphericalTensor> \
580  type##PointPatchSphericalTensorField; \
581  typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
582  typedef type##PointPatchField<tensor> type##PointPatchTensorField;
583 
584 
585 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 
587 #endif
588 
589 // ************************************************************************* //
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
bool updated() const
Return true if the boundary condition has already been updated.
virtual const word & constraintType() const
Return the constraint type this pointPatchField implements.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator-=(const pointPatchField< Type > &)
Foam::pointPatchFieldMapper.
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given pointPatchField onto this pointPatchField.
virtual void operator==(const pointPatchField< Type > &)
A calculated boundary condition for pointField.
virtual bool coupled() const
Return true if this patch field is coupled.
static int disallowGenericPointPatchField
Debug switch to disallow the use of genericPointPatchField.
const objectRegistry & db() const
Return local objectRegistry.
Abstract base class for point-mesh patch fields.
static const word & calculatedType()
Return the type of the calculated form of pointPatchField.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
static const word null
An empty word.
Definition: word.H:77
virtual autoPtr< pointPatchField< Type > > clone() const =0
Construct and return a clone.
virtual void operator*=(const pointPatchField< scalar > &)
virtual void operator=(const pointPatchField< Type > &)
virtual bool fixesValue() const
Return true if this patch field fixes a value.
declareRunTimeSelectionTable(autoPtr, pointPatchField, pointPatch,(const pointPatch &p, const DimensionedField< Type, pointMesh > &iF),(p, iF))
label size() const
Return size.
virtual void operator==(const Field< Type > &)
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Initialise evaluation of the patch field (do nothing)
calculatedPointPatchField< Type > Calculated
const pointPatch & patch() const
Return patch.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void operator/=(const pointPatchField< scalar > &)
TypeName("pointPatchField")
Runtime type information.
virtual void operator==(const Type &)
const Field< Type > & primitiveField() const
Return internal field reference.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
const DimensionedField< Type, pointMesh > & internalField() const
Return dimensioned internal field reference.
const word & patchType() const
Optional patch type.
virtual void write(Ostream &) const
Write.
static autoPtr< pointPatchField< Type > > New(const word &, const pointPatch &, const DimensionedField< Type, pointMesh > &)
Return a pointer to a new patchField created on freestore given.
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
virtual void operator+=(const pointPatchField< Type > &)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field.
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
Namespace for OpenFOAM.
virtual label size() const =0
Return size.