All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pointPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 Type value_type;
105  typedef pointPatch Patch;
107 
108 
109  //- Runtime type information
110  TypeName("pointPatchField");
111 
112  //- Debug switch to disallow the use of genericPointPatchField
114 
115 
116  // Declare run-time constructor selection tables
117 
119  (
120  autoPtr,
122  pointPatch,
123  (
124  const pointPatch& p,
126  ),
127  (p, iF)
128  );
129 
131  (
132  autoPtr,
134  patchMapper,
135  (
136  const pointPatchField<Type>& ptf,
137  const pointPatch& p,
139  const pointPatchFieldMapper& m
140  ),
141  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
142  );
143 
145  (
146  autoPtr,
148  dictionary,
149  (
150  const pointPatch& p,
152  const dictionary& dict
153  ),
154  (p, iF, dict)
155  );
156 
157 
158  // Constructors
159 
160  //- Construct from patch and internal field
162  (
163  const pointPatch&,
165  );
166 
167  //- Construct from patch, internal field and dictionary
169  (
170  const pointPatch&,
172  const dictionary&
173  );
174 
175  //- Construct by mapping given patchField<Type> onto a new patch
177  (
178  const pointPatchField<Type>&,
179  const pointPatch&,
181  const pointPatchFieldMapper&
182  );
183 
184  //- Copy constructor
186 
187  //- Construct and return a clone
188  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
189 
190  //- Construct as copy setting internal field reference
192  (
193  const pointPatchField<Type>&,
195  );
196 
197  //- Construct and return a clone setting internal field reference
199  (
201  ) const = 0;
202 
203 
204  // Selectors
205 
206  //- Return a pointer to a new patchField created on freestore given
207  // patch and internal field
208  // (does not set the patch field values)
210  (
211  const word&,
212  const pointPatch&,
214  );
215 
216  //- Return a pointer to a new patchField created on freestore given
217  // patch and internal field
218  // (does not set the patch field values).
219  // Allows override of constraint type
221  (
222  const word&,
223  const word& actualPatchType,
224  const pointPatch&,
226  );
227 
228  //- Return a pointer to a new patchField created on freestore from
229  // a given pointPatchField mapped onto a new patch
231  (
232  const pointPatchField<Type>&,
233  const pointPatch&,
235  const pointPatchFieldMapper&
236  );
237 
238  //- Return a pointer to a new patchField created on freestore
239  // from dictionary
241  (
242  const pointPatch&,
244  const dictionary&
245  );
246 
247  //- Return a pointer to a new calculatedPointPatchField created on
248  // freestore without setting patchField values
249  template<class Type2>
252  (
254  );
255 
256 
257  //- Destructor
258  virtual ~pointPatchField<Type>()
259  {}
260 
261 
262  // Member Functions
263 
264  // Access
265 
266  //- Return local objectRegistry
267  const objectRegistry& db() const;
268 
269  //- Return size
270  label size() const
271  {
272  return patch().size();
273  }
274 
275  //- Return patch
276  const pointPatch& patch() const
277  {
278  return patch_;
279  }
280 
281  //- Return dimensioned internal field reference
283  internalField() const
284  {
285  return internalField_;
286  }
287 
288  //- Return internal field reference
289  const Field<Type>& primitiveField() const
290  {
291  return internalField_;
292  }
293 
294  //- Optional patch type
295  const word& patchType() const
296  {
297  return patchType_;
298  }
299 
300  //- Optional patch type
301  word& patchType()
302  {
303  return patchType_;
304  }
305 
306  //- Return true if this patch field fixes a value
307  virtual bool fixesValue() const
308  {
309  return false;
310  }
311 
312  //- Return true if this patch field is coupled
313  virtual bool coupled() const
314  {
315  return false;
316  }
317 
318  //- Return true if the boundary condition has already been updated
319  bool updated() const
320  {
321  return updated_;
322  }
323 
324  //- Return field created from appropriate internal field values
326 
327  //- Return field created from appropriate internal field values
328  // given internal field reference
329  template<class Type1>
331  (
332  const Field<Type1>& iF
333  ) const;
334 
335  //- Return field created from selected internal field values
336  // given internal field reference
337  template<class Type1>
339  (
340  const Field<Type1>& iF,
341  const labelList& meshPoints
342  ) const;
343 
344  //- Given the internal field and a patch field,
345  // add the patch field to the internal field
346  template<class Type1>
347  void addToInternalField
348  (
349  Field<Type1>& iF,
350  const Field<Type1>& pF
351  ) const;
352 
353  //- Given the internal field and a patch field,
354  // add selected elements of the patch field to the internal field
355  template<class Type1>
356  void addToInternalField
357  (
358  Field<Type1>& iF,
359  const Field<Type1>& pF,
360  const labelList& points
361  ) const;
362 
363  //- Given the internal field and a patch field,
364  // set the patch field in the internal field
365  template<class Type1>
366  void setInInternalField
367  (
368  Field<Type1>& iF,
369  const Field<Type1>& pF,
370  const labelList& meshPoints
371  ) const;
372 
373  //- Given the internal field and a patch field,
374  // set the patch field in the internal field
375  template<class Type1>
376  void setInInternalField
377  (
378  Field<Type1>& iF,
379  const Field<Type1>& pF
380  ) const;
381 
382  //- Return the type of the calculated form of pointPatchField
383  static const word& calculatedType();
384 
385  //- Return the constraint type this pointPatchField implements.
386  virtual const word& constraintType() const
387  {
388  return word::null;
389  }
390 
391 
392  // Mapping functions
393 
394  //- Map (and resize as needed) from self given a mapping object
395  // Used to update fields following mesh topology change
396  virtual void autoMap(const pointPatchFieldMapper&)
397  {}
398 
399  //- Reverse map the given pointPatchField onto this pointPatchField
400  // Used to reconstruct fields
401  virtual void rmap(const pointPatchField<Type>&, const labelList&)
402  {}
403 
404 
405  // Evaluation functions
406 
407  //- Update the coefficients associated with the patch field
408  // Sets Updated to true
409  virtual void updateCoeffs()
410  {
411  updated_ = true;
412  }
413 
414  //- Initialise evaluation of the patch field (do nothing)
415  virtual void initEvaluate
416  (
417  const Pstream::commsTypes commsType =
419  )
420  {}
421 
422  //- Evaluate the patch field
423  virtual void evaluate
424  (
425  const Pstream::commsTypes commsType =
427  );
428 
429 
430  // I-O
431 
432  //- Write
433  virtual void write(Ostream&) const;
434 
435 
436  // Member Operators
438  virtual void operator=(const pointPatchField<Type>&){}
440  virtual void operator+=(const pointPatchField<Type>&){}
441  virtual void operator-=(const pointPatchField<Type>&){}
442  virtual void operator*=(const pointPatchField<scalar>&){}
443  virtual void operator/=(const pointPatchField<scalar>&){}
445  virtual void operator=(const Field<Type>&){}
446  virtual void operator+=(const Field<Type>&){}
447  virtual void operator-=(const Field<Type>&){}
449  virtual void operator*=(const Field<scalar>&){}
450  virtual void operator/=(const Field<scalar>&){}
452  virtual void operator=(const Type&){}
453  virtual void operator+=(const Type&){}
454  virtual void operator-=(const Type&){}
455  virtual void operator*=(const scalar){}
456  virtual void operator/=(const scalar){}
457 
458 
459  // Force an assignment irrespective of form of patch
460  // By generic these do nothing unless the patch actually has boundary
461  // values
463  virtual void operator==(const pointPatchField<Type>&){}
464  virtual void operator==(const Field<Type>&){}
465  virtual void operator==(const Type&){}
466 
467 
468  // Ostream operator
469 
470  friend Ostream& operator<< <Type>
471  (
472  Ostream&,
473  const pointPatchField<Type>&
474  );
475 };
476 
477 
478 // This function is added as a hack to enable simple backward compatibility
479 // with versions using referenceLevel in GeometicField
480 template<class Type>
481 const pointPatchField<Type>& operator+
482 (
483  const pointPatchField<Type>& ppf,
484  const Type&
485 )
486 {
487  return ppf;
488 }
489 
490 
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 
493 } // End namespace Foam
494 
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 
498 
499 #ifdef NoRepository
500  #include "pointPatchField.C"
501  #include "calculatedPointPatchField.H"
502 #endif
503 
505 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
506  addToRunTimeSelectionTable \
507  ( \
508  PatchTypeField, \
509  typePatchTypeField, \
510  pointPatch \
511  ); \
512  addToRunTimeSelectionTable \
513  ( \
514  PatchTypeField, \
515  typePatchTypeField, \
516  patchMapper \
517  ); \
518  addToRunTimeSelectionTable \
519  ( \
520  PatchTypeField, \
521  typePatchTypeField, \
522  dictionary \
523  );
524 
525 
526 // for non-templated patch fields
527 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField) \
528  defineTypeNameAndDebug(typePatchTypeField, 0); \
529  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
530 
531 
532 // for templated patch fields
533 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField) \
534  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
535  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
536 
538 #define makePointPatchFields(type) \
539  makeTemplatePointPatchTypeField \
540  ( \
541  pointPatchScalarField, \
542  type##PointPatchScalarField \
543  ); \
544  makeTemplatePointPatchTypeField \
545  ( \
546  pointPatchVectorField, \
547  type##PointPatchVectorField \
548  ); \
549  makeTemplatePointPatchTypeField \
550  ( \
551  pointPatchSphericalTensorField, \
552  type##PointPatchSphericalTensorField \
553  ); \
554  makeTemplatePointPatchTypeField \
555  ( \
556  pointPatchSymmTensorField, \
557  type##PointPatchSymmTensorField \
558  ); \
559  makeTemplatePointPatchTypeField \
560  ( \
561  pointPatchTensorField, \
562  type##PointPatchTensorField \
563 );
564 
566 #define makePointPatchFieldsTypeName(type) \
567  defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0); \
568  defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0); \
569  defineNamedTemplateTypeNameAndDebug \
570  ( \
571  type##PointPatchSphericalTensorField, 0 \
572  ); \
573  defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0); \
574  defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
575 
577 #define makePointPatchFieldTypedefs(type) \
578  typedef type##PointPatchField<scalar> type##PointPatchScalarField; \
579  typedef type##PointPatchField<vector> type##PointPatchVectorField; \
580  typedef type##PointPatchField<sphericalTensor> \
581  type##PointPatchSphericalTensorField; \
582  typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
583  typedef type##PointPatchField<tensor> type##PointPatchTensorField;
584 
585 
586 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
587 
588 #endif
589 
590 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
dictionary dict
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.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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.
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 void operator=(pointPatchField< Type > &&)
const Field< Type > & primitiveField() const
Return internal field reference.
static int disallowGenericPointPatchField
Debug switch to disallow the use of genericPointPatchField.
Abstract base class for point-mesh patch fields.
static const word & calculatedType()
Return the type of the calculated form of pointPatchField.
const objectRegistry & db() const
Return local objectRegistry.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
const pointField & points
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
const pointPatch & patch() const
Return patch.
static const word null
An empty word.
Definition: word.H:77
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
virtual autoPtr< pointPatchField< Type > > clone() const =0
Construct and return a clone.
virtual const word & constraintType() const
Return the constraint type this pointPatchField implements.
virtual void operator*=(const pointPatchField< scalar > &)
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
virtual void operator=(const pointPatchField< Type > &)
declareRunTimeSelectionTable(autoPtr, pointPatchField, pointPatch,(const pointPatch &p, const DimensionedField< Type, pointMesh > &iF),(p, iF))
const word & patchType() const
Optional patch type.
virtual void operator==(const Field< Type > &)
const DimensionedField< Type, pointMesh > & internalField() const
Return dimensioned internal field reference.
calculatedPointPatchField< Type > Calculated
virtual void write(Ostream &) const
Write.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise evaluation of the patch field (do nothing)
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void operator/=(const pointPatchField< scalar > &)
bool updated() const
Return true if the boundary condition has already been updated.
TypeName("pointPatchField")
Runtime type information.
virtual void operator==(const Type &)
label size() const
Return size.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
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:53
Registry of regIOobjects.
virtual void operator+=(const pointPatchField< Type > &)
virtual bool coupled() const
Return true if this patch field is coupled.
Namespace for OpenFOAM.
virtual label size() const =0
Return size.
virtual bool fixesValue() const
Return true if this patch field fixes a value.