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-2024 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 "fieldTypes.H"
51 #include "autoPtr.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward Declarations
59 class dictionary;
60 class objectRegistry;
61 class pointPatchFieldMapper;
62 class pointMesh;
63 
64 template<class Type> class pointPatchField;
65 template<class Type> class calculatedPointPatchField;
66 
67 template<class Type>
68 Ostream& operator<<(Ostream&, const pointPatchField<Type>&);
69 
70 /*---------------------------------------------------------------------------*\
71  Class pointPatchFieldBase Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 //- Template invariant parts for pointPatchField
76 {
77  // Private Data
78 
79  //- Reference to patch
80  const pointPatch& patch_;
81 
82  //- Update index used so that updateCoeffs is called only once during
83  //- the construction of the matrix
84  bool updated_;
85 
86  //- Optional patch type
87  // Used to allow specified boundary conditions to be applied
88  // to constraint patches by providing the constraint
89  // patch type as 'patchType'
90  word patchType_;
91 
92 
93 protected:
94 
95  // Protected Member Functions
96 
97  //- Read dictionary entries.
98  // Useful when initially constructed without a dictionary
99  virtual void readDict(const dictionary& dict);
100 
101  //- Set updated state
102  void setUpdated(bool state) noexcept
103  {
104  updated_ = state;
105  }
106 
107  //- Set matrix manipulated state. Currently a no-op for pointPatchField.
108  void setManipulated(bool state) noexcept
109  {}
110 
112 public:
113 
114  //- Debug switch to disallow the use of generic pointPatchField
115  static int disallowGenericPatchField;
116 
117  //- Runtime type information
118  TypeName("pointPatchField");
120 
121  // Constructors
122 
123  //- Construct from patch
124  explicit pointPatchFieldBase(const pointPatch& p);
125 
126  //- Construct from patch and patch type
129  //- Construct from patch and dictionary
131 
132  //- Copy construct with new patch
134 
135  //- Copy construct
137 
138 
139  //- Destructor
140  virtual ~pointPatchFieldBase() = default;
141 
142 
143  // Static Member Functions
144 
145  //- The type name for \c empty patch fields
146  static const word& emptyType() noexcept
147  {
149  }
150 
151  //- The type name for \c calculated patch fields
152  static const word& calculatedType() noexcept
153  {
155  }
156 
157  //- The type name for \c zeroGradient patch fields
158  static const word& zeroGradientType() noexcept
159  {
161  }
162 
163 
164  // Member Functions
165 
166  // Attributes
167 
168  //- True if the patch field fixes a value
169  virtual bool fixesValue() const
170  {
171  return false;
172  }
173 
174  //- True if the patch field is coupled
175  virtual bool coupled() const
176  {
177  return false;
178  }
179 
180  //- The constraint type the pointPatchField implements
181  virtual const word& constraintType() const
182  {
183  return word::null;
184  }
185 
186 
187  // Access
188 
189  //- The associated objectRegistry
190  const objectRegistry& db() const;
192  //- Return the patch
193  const pointPatch& patch() const noexcept
194  {
195  return patch_;
196  }
197 
198  //- The optional patch type
199  const word& patchType() const noexcept
200  {
201  return patchType_;
202  }
203 
204  //- The optional patch type
206  {
207  return patchType_;
208  }
209 
210 
211  // Solution
213  //- True if the boundary condition has already been updated
214  bool updated() const noexcept
215  {
216  return updated_;
217  }
218 
219  //- True if the matrix has already been manipulated.
220  //- Currently ignored (always false) for pointPatchField
221  bool manipulatedMatrix() const noexcept
222  {
223  return false;
224  }
225 
226 
227  // Check
228 
229  //- Check that patches are identical
230  void checkPatch(const pointPatchFieldBase& rhs) const;
231 };
232 
233 
234 /*---------------------------------------------------------------------------*\
235  Class pointPatchField Declaration
236 \*---------------------------------------------------------------------------*/
237 
238 template<class Type>
239 class pointPatchField
240 :
241  public pointPatchFieldBase
242 {
243 public:
245  // Public Data Types
246 
247  //- The patch type for the patch field
248  typedef pointPatch Patch;
249 
250  //- The value_type for the patch field
251  typedef Type value_type;
253  //- The internal field type associated with the patch field
255 
256  //- Type for a \em calculated patch
258 
259 
260 private:
261 
262  // Private Data
264  //- Reference to internal field
265  const DimensionedField<Type, pointMesh>& internalField_;
266 
267 
268 public:
269 
270  // Declare run-time constructor selection tables
271 
273  (
274  autoPtr,
276  patch,
277  (
278  const pointPatch& p,
280  ),
281  (p, iF)
282  );
283 
285  (
286  autoPtr,
288  patchMapper,
289  (
290  const pointPatchField<Type>& ptf,
291  const pointPatch& p,
293  const pointPatchFieldMapper& m
294  ),
295  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
296  );
297 
299  (
300  autoPtr,
302  dictionary,
303  (
304  const pointPatch& p,
306  const dictionary& dict
307  ),
308  (p, iF, dict)
309  );
310 
311 
312  // Constructors
314  //- Construct from patch and internal field
316  (
317  const pointPatch&,
319  );
320 
321  //- Construct from patch, internal field and dictionary
323  (
324  const pointPatch&,
326  const dictionary&
327  );
328 
329  //- Construct by mapping given patch field onto a new patch
331  (
332  const pointPatchField<Type>&,
333  const pointPatch&,
335  const pointPatchFieldMapper&
336  );
337 
338  //- Construct as copy
340 
341  //- Construct as copy setting internal field reference
343  (
344  const pointPatchField<Type>&,
346  );
347 
348  //- Clone patch field with its own internal field reference
349  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
350 
351  //- Clone patch field with an internal field reference
353  (
355  ) const = 0;
356 
357 
358  // Factory Methods
359 
360  //- Clone a patch field, optionally with internal field reference etc.
361  template<class DerivedPatchField, class... Args>
363  (
364  const DerivedPatchField& pf,
365  Args&&... args
366  )
367  {
369  (
370  new DerivedPatchField(pf, std::forward<Args>(args)...)
371  );
372  }
373 
374  //- Return a pointer to a new patchField created on freestore given
375  // patch and internal field
376  // (does not set the patch field values)
378  (
379  const word& patchFieldType,
380  const pointPatch& p,
382  );
383 
384  //- Return a pointer to a new patchField created on freestore given
385  // patch and internal field
386  // (does not set the patch field values).
387  // Allows override of constraint type
389  (
390  const word& patchFieldType,
391  const word& actualPatchType,
392  const pointPatch& p,
394  );
395 
396  //- Return a pointer to a new patchField created on freestore from
397  // a given pointPatchField mapped onto a new patch
399  (
400  const pointPatchField<Type>&,
401  const pointPatch&,
403  const pointPatchFieldMapper&
404  );
405 
406  //- Return a pointer to a new patchField created on freestore
407  // from dictionary
409  (
410  const pointPatch&,
412  const dictionary&
413  );
414 
415  //- Return a pointer to a new calculatedPointPatchField created on
416  // freestore without setting patchField values
419  (
420  const pointPatch& p
421  );
422 
423  //- Return a pointer to a new calculatedPointPatchField created on
424  // freestore without setting patchField values
425  template<class AnyType>
428  (
429  const pointPatchField<AnyType>& pf
430  );
431 
432 
433  //- Destructor
434  virtual ~pointPatchField() = default;
435 
436 
437  // Member Functions
438 
439  // Access
440 
441  //- Return the patch size
442  label size() const
443  {
444  return patch().size();
445  }
446 
447  //- Return const-reference to the dimensioned internal field
449  {
450  return internalField_;
451  }
452 
453  //- Return const-reference to the internal field values
454  const Field<Type>& primitiveField() const noexcept
455  {
456  return internalField_;
457  }
458 
459 
460  // Evaluation Functions
461 
462  //- Extract field using specified addressing
463  // \param internalData The internal field to extract from
464  // \param addressing Addressing (mesh-points) into internal field
465  // \param [out] pfld The extracted patch field.
466  // It is always resized according to the patch size(),
467  // which can be smaller than the addressing size
468  template<class Type1>
469  void patchInternalField
470  (
471  const UList<Type1>& internalData,
472  const labelUList& addressing,
473  Field<Type1>& pfld
474  ) const;
475 
476  //- Return field created from selected internal field values
477  //- given internal field reference
478  // \param internalData The internal field to extract from
479  // \param addressing Addressing (mesh-points) into internal field
480  template<class Type1>
481  tmp<Field<Type1>> patchInternalField
482  (
483  const UList<Type1>& internalData,
484  const labelUList& addressing
485  ) const;
486 
487  //- Return field created from appropriate internal field values
488  //- given internal field reference
489  template<class Type1>
490  tmp<Field<Type1>> patchInternalField
491  (
492  const UList<Type1>& internalData
493  ) const;
494 
495  //- Return field created from appropriate internal field values
496  tmp<Field<Type>> patchInternalField() const;
497 
498 
499  //- Given the internal field and a patch field,
500  //- add the patch field to the internal field
501  template<class Type1>
502  void addToInternalField
503  (
504  Field<Type1>& iF,
505  const Field<Type1>& pF
506  ) const;
507 
508  //- Given the internal field and a patch field,
509  //- add selected elements of the patch field to the internal field
510  template<class Type1>
511  void addToInternalField
512  (
513  Field<Type1>& iF,
514  const Field<Type1>& pF,
515  const labelUList& points
516  ) const;
517 
518  //- Given the internal field and a patch field,
519  //- set the patch field in the internal field
520  template<class Type1>
521  void setInInternalField
522  (
523  Field<Type1>& iF,
524  const Field<Type1>& pF,
525  const labelUList& meshPoints
526  ) const;
527 
528  //- Given the internal field and a patch field,
529  //- set the patch field in the internal field
530  template<class Type1>
531  void setInInternalField
532  (
533  Field<Type1>& iF,
534  const Field<Type1>& pF
535  ) const;
536 
537 
538  // Mapping Functions
539 
540  //- Map (and resize as needed) from self given a mapping object
541  virtual void autoMap
542  (
544  )
545  {}
546 
547  //- Reverse map the given pointPatchField onto this pointPatchField
548  virtual void rmap
549  (
550  const pointPatchField<Type>&,
551  const labelList&
552  )
553  {}
554 
555 
556  // Evaluation Functions
557 
558  //- Update the coefficients associated with the patch field
559  // Sets Updated to true
560  virtual void updateCoeffs();
561 
562  //- Initialise evaluation of the patch field (do nothing)
563  virtual void initEvaluate
564  (
566  )
567  {}
568 
569  //- Evaluate the patch field, sets updated() to false
570  virtual void evaluate
571  (
573  );
574 
575  //- Initialise the evaluation of the patch field after a local
576  // operation
577  virtual void initEvaluateLocal
578  (
579  const Pstream::commsTypes commsType =
581  )
582  {}
583 
584  //- Evaluate the patch field after a local operation (e.g. *=)
585  virtual void evaluateLocal
586  (
587  const Pstream::commsTypes commsType =
589  )
590  {}
591 
592 
593  // Other
594 
595  //- Write
596  virtual void write(Ostream& os) const;
597 
598 
599  // Member Operators
600 
601  virtual void operator=(const pointPatchField<Type>&){}
602  virtual void operator+=(const pointPatchField<Type>&){}
603  virtual void operator-=(const pointPatchField<Type>&){}
604  virtual void operator*=(const pointPatchField<scalar>&){}
605  virtual void operator/=(const pointPatchField<scalar>&){}
606 
607  virtual void operator=(const Field<Type>&){}
608  virtual void operator+=(const Field<Type>&){}
609  virtual void operator-=(const Field<Type>&){}
610 
611  virtual void operator*=(const Field<scalar>&){}
612  virtual void operator/=(const Field<scalar>&){}
613 
614  virtual void operator=(const Type&){}
615  virtual void operator+=(const Type&){}
616  virtual void operator-=(const Type&){}
617  virtual void operator*=(const scalar){}
618  virtual void operator/=(const scalar){}
619 
620 
621  // Force an assignment irrespective of form of patch
622  // By generic these do nothing unless the patch actually has boundary
623  // values
624 
625  virtual void operator==(const pointPatchField<Type>&) {}
626  virtual void operator==(const Field<Type>&) {}
627  virtual void operator==(const Type&) {}
628 
629  // Prevent automatic comparison rewriting (c++20)
630  bool operator!=(const pointPatchField<Type>&) const = delete;
631  bool operator!=(const Field<Type>&) const = delete;
632  bool operator!=(const Type&) const = delete;
633 
634 
635  // Ostream Operator
636 
637  friend Ostream& operator<< <Type>
638  (
639  Ostream&,
640  const pointPatchField<Type>&
641  );
642 
643 
644  // Other Methods
645 
646  //- Negate the field inplace. Dummy placeholder for FieldField
647  void negate() {}
648 
649  //- Normalise the field inplace. Dummy placeholder for FieldField
650  void normalise() {}
651 };
652 
653 
654 // This function is added as a hack to enable simple backward compatibility
655 // with versions using referenceLevel in GeometricField
656 template<class Type>
657 const pointPatchField<Type>& operator+
658 (
659  const pointPatchField<Type>& ppf,
660  const Type&
661 )
662 {
663  return ppf;
664 }
665 
666 
667 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
668 
669 } // End namespace Foam
670 
671 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
672 
674 
675 #ifdef NoRepository
676  #include "pointPatchField.C"
677  #include "pointPatchFieldNew.C"
678  #include "calculatedPointPatchField.H"
680 #endif
681 
682 // Runtime selection macros
683 #include "pointPatchFieldMacros.H"
684 
685 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
686 
687 #endif
688 
689 // ************************************************************************* //
void normalise()
Normalise the field inplace. Dummy placeholder for FieldField.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatch &p)
Return a pointer to a new calculatedPointPatchField created on.
dictionary dict
static int disallowGenericPatchField
Debug switch to disallow the use of generic pointPatchField.
Template invariant parts for pointPatchField.
virtual ~pointPatchField()=default
Destructor.
DimensionedField< Type, pointMesh > Internal
The internal field type associated with the patch field.
const word zeroGradientType
A zeroGradient patch field type.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
const pointPatch & patch() const noexcept
Return the patch.
commsTypes
Communications types.
Definition: UPstream.H:77
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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 write(Ostream &os) const
Write.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
virtual void operator==(const pointPatchField< Type > &)
static const word & emptyType() noexcept
The type name for empty patch fields.
A calculated boundary condition for pointField.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Abstract base class for point-mesh patch fields.
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
const word calculatedType
A calculated patch field type.
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field after a local operation (e.g. *=)
const pointField & points
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.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Macros for creating pointPatchField types.
virtual const word & constraintType() const
The constraint type the pointPatchField implements.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual bool fixesValue() const
True if the patch field fixes a value.
static const word null
An empty word.
Definition: word.H:84
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise evaluation of the patch field (do nothing)
static autoPtr< pointPatchField< Type > > Clone(const DerivedPatchField &pf, Args &&... args)
Clone a patch field, optionally with internal field reference etc.
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
Clone patch field with its own internal field reference.
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.
const direction noexcept
Definition: Scalar.H:258
virtual void operator=(const pointPatchField< Type > &)
const word emptyType
An empty patch field type.
OBJstream os(runTime.globalPath()/outputName)
virtual void initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise the evaluation of the patch field after a local.
pointPatchFieldBase(const pointPatch &p)
Construct from patch.
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelUList &meshPoints) const
Given the internal field and a patch field, set the patch field in the internal field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, sets updated() to false.
calculatedPointPatchField< Type > Calculated
Type for a calculated patch.
void setManipulated(bool state) noexcept
Set matrix manipulated state. Currently a no-op for pointPatchField.
Type value_type
The value_type for the patch field.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field, add the patch field to the internal 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 > &)
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
volScalarField & p
Registry of regIOobjects.
"buffered" : (MPI_Bsend, MPI_Recv)
bool operator!=(const pointPatchField< Type > &) const =delete
virtual void operator+=(const pointPatchField< Type > &)
virtual bool coupled() const
True if the patch field is coupled.
bool manipulatedMatrix() const noexcept
True if the matrix has already been manipulated. Currently ignored (always false) for pointPatchField...
Foam::argList args(argc, argv)
virtual void readDict(const dictionary &dict)
Read dictionary entries.
const DimensionedField< Type, pointMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
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.