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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::pointPatchField
29 
30 Description
31  Abstract base class for point-mesh patch fields.
32 
33  The base-field does not store values as they are part of the
34  "internal field". There are derived classes to store constraint values
35  e.g. fixedValuePointPatchField derived from the generic
36  valuePointPatchField which ensures the values in the "internal field"
37  are reset to the fixed-values by applying the stored values.
38 
39 SourceFiles
40  pointPatchField.C
41  pointPatchFieldNew.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_pointPatchField_H
46 #define Foam_pointPatchField_H
47 
48 #include "pointPatch.H"
49 #include "DimensionedField.H"
50 #include "autoPtr.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class objectRegistry;
59 class dictionary;
60 class pointPatchFieldMapper;
61 class pointMesh;
62 
63 template<class Type> class pointPatchField;
64 template<class Type> class calculatedPointPatchField;
65 
66 template<class Type>
67 Ostream& operator<<(Ostream&, const pointPatchField<Type>&);
68 
69 /*---------------------------------------------------------------------------*\
70  Class pointPatchFieldBase Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 //- Template invariant parts for pointPatchField
75 {
76  // Private Data
77 
78  //- Reference to patch
79  const pointPatch& patch_;
80 
81  //- Update index used so that updateCoeffs is called only once during
82  //- the construction of the matrix
83  bool updated_;
84 
85  //- Optional patch type
86  // Used to allow specified boundary conditions to be applied
87  // to constraint patches by providing the constraint
88  // patch type as 'patchType'
89  word patchType_;
90 
91 
92 protected:
93 
94  // Protected Member Functions
95 
96  //- Read dictionary entries.
97  // Useful when initially constructed without a dictionary
98  virtual void readDict(const dictionary& dict);
99 
100  //- Set updated state
101  void setUpdated(bool state) noexcept
102  {
103  updated_ = state;
104  }
105 
106 
107 public:
108 
109  //- Debug switch to disallow the use of generic pointPatchField
111 
112  //- Runtime type information
113  TypeName("pointPatchField");
114 
115 
116  // Constructors
117 
118  //- Construct from patch
119  explicit pointPatchFieldBase(const pointPatch& p);
120 
121  //- Construct from patch and patch type
123 
124  //- Construct from patch and dictionary
126 
127  //- Copy construct with new patch
129 
130  //- Copy construct
132 
133 
134  //- Destructor
135  virtual ~pointPatchFieldBase() = default;
136 
137 
138  // Member Functions
139 
140  // Access
141 
142  //- The associated objectRegistry
143  const objectRegistry& db() const;
144 
145  //- Return the patch
146  const pointPatch& patch() const noexcept
147  {
148  return patch_;
149  }
150 
151  //- The optional patch type
152  const word& patchType() const noexcept
153  {
154  return patchType_;
155  }
156 
157  //- The optional patch type
158  word& patchType() noexcept
159  {
160  return patchType_;
161  }
162 
163 
164  // Solution
165 
166  //- True if the boundary condition has already been updated
167  bool updated() const noexcept
168  {
169  return updated_;
170  }
171 
172 
173  // Check
174 
175  //- Check that patches are identical
176  void checkPatch(const pointPatchFieldBase& rhs) const;
177 };
178 
179 
180 /*---------------------------------------------------------------------------*\
181  Class pointPatchField Declaration
182 \*---------------------------------------------------------------------------*/
184 template<class Type>
185 class pointPatchField
186 :
187  public pointPatchFieldBase
188 {
189  // Private Data
190 
191  //- Reference to internal field
192  const DimensionedField<Type, pointMesh>& internalField_;
193 
194 
195 public:
196 
197  //- The Field value_type
198  typedef Type value_type;
199 
200  //- The internal field type associated with the patch field
203  //- The patch type for the patch field
204  typedef pointPatch Patch;
205 
206  //- Type for a \em calculated patch
208 
209 
210  // Declare run-time constructor selection tables
211 
213  (
214  autoPtr,
216  patch,
217  (
218  const pointPatch& p,
220  ),
221  (p, iF)
222  );
223 
225  (
226  autoPtr,
228  patchMapper,
229  (
230  const pointPatchField<Type>& ptf,
231  const pointPatch& p,
233  const pointPatchFieldMapper& m
234  ),
235  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
236  );
237 
239  (
240  autoPtr,
242  dictionary,
243  (
244  const pointPatch& p,
246  const dictionary& dict
247  ),
248  (p, iF, dict)
249  );
250 
251 
252  // Constructors
253 
254  //- Construct from patch and internal field
256  (
257  const pointPatch&,
259  );
260 
261  //- Construct from patch, internal field and dictionary
263  (
264  const pointPatch&,
266  const dictionary&
267  );
268 
269  //- Construct by mapping given patchField<Type> onto a new patch
271  (
272  const pointPatchField<Type>&,
273  const pointPatch&,
275  const pointPatchFieldMapper&
276  );
277 
278  //- Construct as copy
280 
281  //- Construct as copy setting internal field reference
283  (
284  const pointPatchField<Type>&,
286  );
287 
288  //- Construct and return a clone
289  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
290 
291  //- Construct and return a clone setting internal field reference
293  (
295  ) const = 0;
296 
297 
298  // Selectors
299 
300  //- Return a pointer to a new patchField created on freestore given
301  // patch and internal field
302  // (does not set the patch field values)
304  (
305  const word& patchFieldType,
306  const pointPatch& p,
308  );
309 
310  //- Return a pointer to a new patchField created on freestore given
311  // patch and internal field
312  // (does not set the patch field values).
313  // Allows override of constraint type
315  (
316  const word& patchFieldType,
317  const word& actualPatchType,
318  const pointPatch& p,
320  );
321 
322  //- Return a pointer to a new patchField created on freestore from
323  // a given pointPatchField mapped onto a new patch
325  (
326  const pointPatchField<Type>&,
327  const pointPatch&,
329  const pointPatchFieldMapper&
330  );
331 
332  //- Return a pointer to a new patchField created on freestore
333  // from dictionary
335  (
336  const pointPatch&,
338  const dictionary&
339  );
340 
341  //- Return a pointer to a new calculatedPointPatchField created on
342  // freestore without setting patchField values
343  template<class Type2>
346  (
348  );
349 
350 
351  //- Destructor
352  virtual ~pointPatchField() = default;
353 
354 
355  // Member Functions
356 
357  //- The type name for calculated patch fields
358  static const word& calculatedType();
359 
360  //- The type name for zeroGradient patch fields
361  static const word& zeroGradientType();
362 
363 
364  // Attributes
365 
366  //- True if this patch field fixes a value
367  virtual bool fixesValue() const
368  {
369  return false;
370  }
371 
372  //- True if this patch field is coupled
373  virtual bool coupled() const
374  {
375  return false;
376  }
377 
378  //- The constraint type this pointPatchField implements.
379  virtual const word& constraintType() const
380  {
381  return word::null;
382  }
383 
384 
385  // Access
386 
387  //- Return the patch size
388  label size() const
389  {
390  return patch().size();
391  }
392 
393  //- Return dimensioned internal field reference
394  const DimensionedField<Type, pointMesh>& internalField()
395  const noexcept
396  {
397  return internalField_;
398  }
399 
400  //- Return internal field reference
401  const Field<Type>& primitiveField() const noexcept
402  {
403  return internalField_;
404  }
405 
406  //- Return field created from appropriate internal field values
407  tmp<Field<Type>> patchInternalField() const;
408 
409  //- Return field created from appropriate internal field values
410  // given internal field reference
411  template<class Type1>
412  tmp<Field<Type1>> patchInternalField
413  (
414  const Field<Type1>& iF
415  ) const;
416 
417  //- Return field created from selected internal field values
418  // given internal field reference
419  template<class Type1>
420  tmp<Field<Type1>> patchInternalField
421  (
422  const Field<Type1>& iF,
423  const labelList& meshPoints
424  ) const;
425 
426  //- Given the internal field and a patch field,
427  // add the patch field to the internal field
428  template<class Type1>
429  void addToInternalField
430  (
431  Field<Type1>& iF,
432  const Field<Type1>& pF
433  ) const;
434 
435  //- Given the internal field and a patch field,
436  // add selected elements of the patch field to the internal field
437  template<class Type1>
438  void addToInternalField
439  (
440  Field<Type1>& iF,
441  const Field<Type1>& pF,
442  const labelList& points
443  ) const;
444 
445  //- Given the internal field and a patch field,
446  // set the patch field in the internal field
447  template<class Type1>
448  void setInInternalField
449  (
450  Field<Type1>& iF,
451  const Field<Type1>& pF,
452  const labelList& meshPoints
453  ) const;
454 
455  //- Given the internal field and a patch field,
456  // set the patch field in the internal field
457  template<class Type1>
458  void setInInternalField
459  (
460  Field<Type1>& iF,
461  const Field<Type1>& pF
462  ) const;
463 
464 
465  // Mapping Functions
466 
467  //- Map (and resize as needed) from self given a mapping object
468  virtual void autoMap
469  (
470  const pointPatchFieldMapper&
471  )
472  {}
473 
474  //- Reverse map the given pointPatchField onto this pointPatchField
475  virtual void rmap
476  (
477  const pointPatchField<Type>&,
478  const labelList&
479  )
480  {}
481 
482 
483  // Evaluation Functions
484 
485  //- Update the coefficients associated with the patch field
486  // Sets Updated to true
487  virtual void updateCoeffs();
488 
489  //- Initialise evaluation of the patch field (do nothing)
490  virtual void initEvaluate
491  (
492  const Pstream::commsTypes commsType =
494  )
495  {}
496 
497  //- Evaluate the patch field
498  virtual void evaluate
499  (
500  const Pstream::commsTypes commsType =
502  );
503 
504 
505  // I-O
506 
507  //- Write
508  virtual void write(Ostream&) const;
509 
510 
511  // Member Operators
512 
513  virtual void operator=(const pointPatchField<Type>&){}
514  virtual void operator+=(const pointPatchField<Type>&){}
515  virtual void operator-=(const pointPatchField<Type>&){}
516  virtual void operator*=(const pointPatchField<scalar>&){}
517  virtual void operator/=(const pointPatchField<scalar>&){}
518 
519  virtual void operator=(const Field<Type>&){}
520  virtual void operator+=(const Field<Type>&){}
521  virtual void operator-=(const Field<Type>&){}
522 
523  virtual void operator*=(const Field<scalar>&){}
524  virtual void operator/=(const Field<scalar>&){}
525 
526  virtual void operator=(const Type&){}
527  virtual void operator+=(const Type&){}
528  virtual void operator-=(const Type&){}
529  virtual void operator*=(const scalar){}
530  virtual void operator/=(const scalar){}
531 
532 
533  // Force an assignment irrespective of form of patch
534  // By generic these do nothing unless the patch actually has boundary
535  // values
536 
537  virtual void operator==(const pointPatchField<Type>&){}
538  virtual void operator==(const Field<Type>&){}
539  virtual void operator==(const Type&){}
540 
541 
542  // Ostream Operator
543 
544  friend Ostream& operator<< <Type>
545  (
546  Ostream&,
547  const pointPatchField<Type>&
548  );
549 
550 
551  // Other Methods
552 
553  //- Negate the field inplace. Dummy placeholder for FieldField
554  void negate() {}
555 
556  //- Normalise the field inplace. Dummy placeholder for FieldField
557  void normalise() {}
558 };
559 
560 
561 // This function is added as a hack to enable simple backward compatibility
562 // with versions using referenceLevel in GeometricField
563 template<class Type>
564 const pointPatchField<Type>& operator+
565 (
566  const pointPatchField<Type>& ppf,
567  const Type&
568 )
569 {
570  return ppf;
571 }
572 
573 
574 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
575 
576 } // End namespace Foam
577 
578 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
579 
581 
582 #ifdef NoRepository
583  #include "pointPatchField.C"
584  #include "calculatedPointPatchField.H"
586 #endif
587 
588 
589 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
590 // Runtime selection macros
591 
592 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
593  addToRunTimeSelectionTable \
594  ( \
595  PatchTypeField, \
596  typePatchTypeField, \
597  patch \
598  ); \
599  addToRunTimeSelectionTable \
600  ( \
601  PatchTypeField, \
602  typePatchTypeField, \
603  patchMapper \
604  ); \
605  addToRunTimeSelectionTable \
606  ( \
607  PatchTypeField, \
608  typePatchTypeField, \
609  dictionary \
610  );
611 
612 
613 // for non-templated patch fields
614 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField) \
615  defineTypeNameAndDebug(typePatchTypeField, 0); \
616  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
617 
618 
619 // for templated patch fields
620 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField) \
621  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
622  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
623 
624 
625 #define makePointPatchFields(type) \
626  makeTemplatePointPatchTypeField \
627  ( \
628  pointPatchScalarField, \
629  type##PointPatchScalarField \
630  ); \
631  makeTemplatePointPatchTypeField \
632  ( \
633  pointPatchVectorField, \
634  type##PointPatchVectorField \
635  ); \
636  makeTemplatePointPatchTypeField \
637  ( \
638  pointPatchSphericalTensorField, \
639  type##PointPatchSphericalTensorField \
640  ); \
641  makeTemplatePointPatchTypeField \
642  ( \
643  pointPatchSymmTensorField, \
644  type##PointPatchSymmTensorField \
645  ); \
646  makeTemplatePointPatchTypeField \
647  ( \
648  pointPatchTensorField, \
649  type##PointPatchTensorField \
650  );
652 
653 #define makePointPatchFieldsTypeName(type) \
654  defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0); \
655  defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0); \
656  defineNamedTemplateTypeNameAndDebug \
657  ( \
658  type##PointPatchSphericalTensorField, 0 \
659  ); \
660  defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0); \
661  defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
662 
663 
664 #define makePointPatchFieldTypedefs(type) \
665  typedef type##PointPatchField<scalar> type##PointPatchScalarField; \
666  typedef type##PointPatchField<vector> type##PointPatchVectorField; \
667  typedef type##PointPatchField<sphericalTensor> \
668  type##PointPatchSphericalTensorField; \
669  typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
670  typedef type##PointPatchField<tensor> type##PointPatchTensorField;
671 
672 
673 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
674 
675 #endif
676 
677 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
void normalise()
Normalise the field inplace. Dummy placeholder for FieldField.
dictionary dict
static int disallowGenericPatchField
Debug switch to disallow the use of generic pointPatchField.
Template invariant parts for pointPatchField.
virtual ~pointPatchField()=default
Destructor.
"blocking" : (MPI_Bsend, MPI_Recv)
DimensionedField< Type, pointMesh > Internal
The internal field type associated with the patch field.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
const pointPatch & patch() const noexcept
Return the patch.
commsTypes
Types of communications.
Definition: UPstream.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const word & patchType() const noexcept
The optional patch type.
void setUpdated(bool state) noexcept
Set updated state.
declareRunTimeSelectionTable(autoPtr, pointPatchField, patch,(const pointPatch &p, const DimensionedField< Type, pointMesh > &iF),(p, iF))
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.
Abstract base class for point-mesh patch fields.
const Field< Type > & primitiveField() const noexcept
Return internal field reference.
static const word & calculatedType()
The type name for calculated patch fields.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
const pointField & points
Generic templated field type.
Definition: Field.H:61
A class for handling words, derived from Foam::string.
Definition: word.H:63
static autoPtr< pointPatchField< Type > > New(const word &patchFieldType, const pointPatch &p, const DimensionedField< Type, pointMesh > &iF)
Return a pointer to a new patchField created on freestore given.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
static const word null
An empty word.
Definition: word.H:84
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
bool updated() const noexcept
True if the boundary condition has already been updated.
const objectRegistry & db() const
The associated objectRegistry.
virtual autoPtr< pointPatchField< Type > > clone() const =0
Construct and return a clone.
virtual const word & constraintType() const
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.
pointPatch Patch
The patch type for the patch field.
virtual ~pointPatchFieldBase()=default
Destructor.
TypeName("pointPatchField")
Runtime type information.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
virtual void operator=(const pointPatchField< Type > &)
pointPatchFieldBase(const pointPatch &p)
Construct from patch.
calculatedPointPatchField< Type > Calculated
Type for a calculated patch.
virtual void write(Ostream &) const
Write.
Type value_type
The Field value_type.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
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...
Definition: areaFieldsFwd.H:42
virtual void operator/=(const pointPatchField< scalar > &)
label size() const
Return the patch size.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
Registry of regIOobjects.
virtual void operator+=(const pointPatchField< Type > &)
virtual bool coupled() const
True if this patch field is coupled.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
const DimensionedField< Type, pointMesh > & internalField() const noexcept
Return dimensioned internal field reference.
static const word & zeroGradientType()
The type name for zeroGradient patch fields.
Namespace for OpenFOAM.
virtual label size() const =0
Return size.
void negate()
Negate the field inplace. Dummy placeholder for FieldField.
void checkPatch(const pointPatchFieldBase &rhs) const
Check that patches are identical.
virtual bool fixesValue() const
True if this patch field fixes a value.