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-2025 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 
102 public:
103 
104  //- Debug switch to disallow the use of generic pointPatchField
105  static int disallowGenericPatchField;
106 
107  //- Runtime type information
108  TypeName("pointPatchField");
109 
110 
111  // Constructors
112 
113  //- Construct from patch
114  explicit pointPatchFieldBase(const pointPatch& p);
115 
116  //- Construct from patch and patch type
118 
119  //- Construct from patch and dictionary
121 
122  //- Copy construct with new patch
124 
125  //- Copy construct
127 
128 
129  //- Destructor
130  virtual ~pointPatchFieldBase() = default;
131 
132 
133  // Static Member Functions
134 
135  //- The type name for \c empty patch fields
136  static const word& emptyType() noexcept
137  {
139  }
140 
141  //- The type name for \c calculated patch fields
142  static const word& calculatedType() noexcept
143  {
145  }
146 
147  //- The type name for \c zeroGradient patch fields
148  static const word& zeroGradientType() noexcept
149  {
151  }
152 
153 
154  // Member Functions
155 
156  // Attributes
157 
158  //- True if the value of the patch field is altered by assignment
159  virtual bool assignable() const
160  {
161  return false;
162  }
163 
164  //- True if the patch field fixes a value
165  virtual bool fixesValue() const
166  {
167  return false;
168  }
170  //- True if the patch field is coupled
171  virtual bool coupled() const
172  {
173  return false;
174  }
175 
176  //- The constraint type the pointPatchField implements
177  virtual const word& constraintType() const
178  {
179  return word::null;
180  }
181 
182 
183  // Access
184 
185  //- The associated objectRegistry
186  const objectRegistry& db() const;
187 
188  //- Return the patch
189  const pointPatch& patch() const noexcept
190  {
191  return patch_;
192  }
193 
194  //- The optional patch type
195  const word& patchType() const noexcept
196  {
197  return patchType_;
198  }
199 
200  //- The optional patch type
202  {
203  return patchType_;
204  }
205 
206  //- True if the type does not correspond to the constraint type
207  virtual bool constraintOverride() const
208  {
209  return !patchType_.empty() && patchType_ != type();
210  }
211 
212 
213  // Solution
215  //- True if the boundary condition has already been updated
216  bool updated() const noexcept
217  {
218  return updated_;
219  }
220 
221  //- Set updated state
222  void setUpdated(bool state) noexcept
223  {
224  updated_ = state;
225  }
226 
227  //- True if the matrix has already been manipulated.
228  //- Currently always false for pointPatchField
229  bool manipulatedMatrix() const noexcept
230  {
231  return false;
232  }
233 
234  //- Set matrix manipulated state.
235  //- Currently a no-op for pointPatchField.
236  void setManipulated(bool state) noexcept
237  {}
239 
240  // Check
241 
242  //- Check that patches are identical
243  void checkPatch(const pointPatchFieldBase& rhs) const;
244 };
245 
247 /*---------------------------------------------------------------------------*\
248  Class pointPatchField Declaration
249 \*---------------------------------------------------------------------------*/
250 
251 template<class Type>
252 class pointPatchField
253 :
255 {
256 public:
257 
258  // Public Data Types
259 
260  //- The patch type for the patch field
261  typedef pointPatch Patch;
262 
263  //- The value_type for the patch field
264  typedef Type value_type;
266  //- The component type for patch field
267  typedef typename pTraits<Type>::cmptType cmptType;
268 
269  //- The internal field type associated with the patch field
271 
272  //- Type for a \em calculated patch
274 
275 
276 private:
277 
278  // Private Data
279 
280  //- Reference to internal field
281  const DimensionedField<Type, pointMesh>& internalField_;
283 
284 public:
285 
286  // Declare run-time constructor selection tables
287 
289  (
290  autoPtr,
292  patch,
293  (
294  const pointPatch& p,
296  ),
297  (p, iF)
298  );
299 
301  (
302  autoPtr,
304  patchMapper,
305  (
306  const pointPatchField<Type>& ptf,
307  const pointPatch& p,
309  const pointPatchFieldMapper& m
310  ),
311  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
312  );
313 
315  (
316  autoPtr,
318  dictionary,
319  (
320  const pointPatch& p,
322  const dictionary& dict
323  ),
324  (p, iF, dict)
325  );
326 
327 
328  // Constructors
329 
330  //- Construct from patch and internal field
332  (
333  const pointPatch&,
335  );
336 
337  //- Construct from patch, internal field and dictionary
339  (
340  const pointPatch&,
342  const dictionary&
343  );
344 
345  //- Construct by mapping given patch field onto a new patch
347  (
348  const pointPatchField<Type>&,
349  const pointPatch&,
351  const pointPatchFieldMapper&
352  );
353 
354  //- Construct as copy
356 
357  //- Construct as copy setting internal field reference
359  (
360  const pointPatchField<Type>&,
362  );
363 
364  //- Clone patch field with its own internal field reference
365  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
366 
367  //- Clone patch field with an internal field reference
369  (
371  ) const = 0;
372 
373 
374  // Factory Methods
375 
376  //- Clone a patch field, optionally with internal field reference etc.
377  template<class DerivedPatchField, class... Args>
379  (
380  const DerivedPatchField& pf,
381  Args&&... args
382  )
383  {
385  (
386  new DerivedPatchField(pf, std::forward<Args>(args)...)
387  );
388  }
389 
390  //- Return a pointer to a new patchField created on freestore given
391  // patch and internal field
392  // (does not set the patch field values)
394  (
395  const word& patchFieldType,
396  const pointPatch& p,
398  );
399 
400  //- Return a pointer to a new patchField created on freestore given
401  // patch and internal field
402  // (does not set the patch field values).
403  // Allows override of constraint type
405  (
406  const word& patchFieldType,
407  const word& actualPatchType,
408  const pointPatch& p,
410  );
411 
412  //- Return a pointer to a new patchField created on freestore from
413  // a given pointPatchField mapped onto a new patch
415  (
416  const pointPatchField<Type>&,
417  const pointPatch&,
419  const pointPatchFieldMapper&
420  );
421 
422  //- Return a pointer to a new patchField created on freestore
423  // from dictionary
425  (
426  const pointPatch&,
428  const dictionary&
429  );
430 
431  //- Return a pointer to a new calculatedPointPatchField created on
432  // freestore without setting patchField values
435  (
436  const pointPatch& p
437  );
438 
439  //- Return a pointer to a new calculatedPointPatchField created on
440  // freestore without setting patchField values
441  template<class AnyType>
444  (
445  const pointPatchField<AnyType>& pf
446  );
447 
448 
449  //- Destructor
450  virtual ~pointPatchField() = default;
451 
452 
453  // Member Functions
454 
455  // Access
456 
457  //- Return the patch size
458  label size() const
459  {
460  return patch().size();
461  }
462 
463  //- Return const-reference to the dimensioned internal field
465  {
466  return internalField_;
467  }
468 
469  //- Return const-reference to the internal field values
470  const Field<Type>& primitiveField() const noexcept
471  {
472  return internalField_;
473  }
474 
475 
476  // Evaluation Functions
477 
478  //- Extract field using specified addressing
479  // \param internalData The internal field to extract from
480  // \param addressing Addressing (mesh-points) into internal field
481  // \param [out] pfld The extracted patch field.
482  // Should normally be sized according to the patch size(),
483  // which can be smaller than the addressing size
484  template<class Type1>
485  void patchInternalField
486  (
487  const UList<Type1>& internalData,
488  const labelUList& addressing,
489  UList<Type1>& pfld
490  ) const;
491 
492  //- Return field created from selected internal field values
493  //- given internal field reference
494  // \param internalData The internal field to extract from
495  // \param addressing Addressing (mesh-points) into internal field
496  template<class Type1>
497  [[nodiscard]] tmp<Field<Type1>>
499  (
500  const UList<Type1>& internalData,
501  const labelUList& addressing
502  ) const;
503 
504  //- Return field created from appropriate internal field values
505  //- given internal field reference
506  template<class Type1>
507  [[nodiscard]] tmp<Field<Type1>>
509  (
510  const UList<Type1>& internalData
511  ) const;
512 
513  //- Return field created from appropriate internal field values
514  tmp<Field<Type>> patchInternalField() const;
515 
516 
517  //- Given the internal field and a patch field,
518  //- add the patch field to the internal field
519  template<class Type1>
520  void addToInternalField
521  (
522  Field<Type1>& iF,
523  const Field<Type1>& pF
524  ) const;
525 
526  //- Given the internal field and a patch field,
527  //- add selected elements of the patch field to the internal field
528  template<class Type1>
529  void addToInternalField
530  (
531  Field<Type1>& iF,
532  const Field<Type1>& pF,
533  const labelUList& points
534  ) const;
535 
536  //- Given the internal field and a patch field,
537  //- set the patch field in the internal field
538  template<class Type1>
539  void setInInternalField
540  (
541  Field<Type1>& iF,
542  const Field<Type1>& pF,
543  const labelUList& meshPoints
544  ) const;
545 
546  //- Given the internal field and a patch field,
547  //- set the patch field in the internal field
548  template<class Type1>
549  void setInInternalField
550  (
551  Field<Type1>& iF,
552  const Field<Type1>& pF
553  ) const;
554 
555 
556  // Mapping Functions
557 
558  //- Map (and resize as needed) from self given a mapping object
559  virtual void autoMap
560  (
561  const pointPatchFieldMapper&
562  )
563  {}
564 
565  //- Reverse map the given pointPatchField onto this pointPatchField
566  virtual void rmap
567  (
568  const pointPatchField<Type>&,
569  const labelList&
570  )
571  {}
572 
574  // Evaluation Functions
575 
576  //- Update the coefficients associated with the patch field
577  // Sets Updated to true
578  virtual void updateCoeffs();
579 
580  //- Initialise evaluation of the patch field (do nothing)
581  virtual void initEvaluate
582  (
584  )
585  {}
586 
587  //- Evaluate the patch field, sets updated() to false
588  virtual void evaluate
589  (
591  );
592 
593  //- Initialise the evaluation of the patch field after a local
594  // operation
595  virtual void initEvaluateLocal
596  (
597  const Pstream::commsTypes commsType =
599  )
600  {}
601 
602  //- Evaluate the patch field after a local operation (e.g. *=)
603  virtual void evaluateLocal
604  (
605  const Pstream::commsTypes commsType =
607  )
608  {}
609 
610 
611  // Other
612 
613  //- Write
614  virtual void write(Ostream& os) const;
615 
616 
617  // Member Operators
618 
619  virtual void operator=(const pointPatchField<Type>&){}
620  virtual void operator+=(const pointPatchField<Type>&){}
621  virtual void operator-=(const pointPatchField<Type>&){}
622  virtual void operator*=(const pointPatchField<scalar>&){}
623  virtual void operator/=(const pointPatchField<scalar>&){}
624 
625  virtual void operator=(const Field<Type>&){}
626  virtual void operator+=(const Field<Type>&){}
627  virtual void operator-=(const Field<Type>&){}
628 
629  virtual void operator*=(const Field<scalar>&){}
630  virtual void operator/=(const Field<scalar>&){}
631 
632  virtual void operator=(const Type&){}
633  virtual void operator+=(const Type&){}
634  virtual void operator-=(const Type&){}
635  virtual void operator*=(const scalar){}
636  virtual void operator/=(const scalar){}
637 
638 
639  // Force an assignment irrespective of form of patch
640  // By generic these do nothing unless the patch actually has boundary
641  // values
642 
643  virtual void operator==(const pointPatchField<Type>&) {}
644  virtual void operator==(const Field<Type>&) {}
645  virtual void operator==(const Type&) {}
646 
647  // Prevent automatic comparison rewriting (c++20)
648  bool operator!=(const pointPatchField<Type>&) const = delete;
649  bool operator!=(const Field<Type>&) const = delete;
650  bool operator!=(const Type&) const = delete;
651 
652 
653  // Ostream Operator
654 
655  friend Ostream& operator<< <Type>
656  (
657  Ostream&,
658  const pointPatchField<Type>&
659  );
660 
661 
662  // Other Methods
663 
664  //- Negate the field inplace. Dummy placeholder for FieldField
665  void negate() {}
666 
667  //- Normalise the field inplace. Dummy placeholder for FieldField
668  void normalise() {}
669 };
670 
671 
672 // This function is added as a hack to enable simple backward compatibility
673 // with versions using referenceLevel in GeometricField
674 template<class Type>
675 const pointPatchField<Type>& operator+
676 (
677  const pointPatchField<Type>& ppf,
678  const Type&
679 )
680 {
681  return ppf;
682 }
683 
684 
685 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
686 
687 } // End namespace Foam
688 
689 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
690 
692 
693 #ifdef NoRepository
694  #include "pointPatchField.C"
695  #include "pointPatchFieldNew.C"
696  #include "calculatedPointPatchField.H"
698 #endif
699 
700 // Runtime selection macros
701 #include "pointPatchFieldMacros.H"
702 
703 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
704 
705 #endif
706 
707 // ************************************************************************* //
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.
pTraits< Type >::cmptType cmptType
The component type for patch field.
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.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:61
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:76
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.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:801
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field after a local operation (e.g. *=)
const pointField & points
Generic templated field type.
Definition: Field.H:63
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 > &)
virtual bool constraintOverride() const
True if the type does not correspond to the constraint type.
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: scalarImpl.H:255
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:64
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.
virtual bool assignable() const
True if the value of the patch field is altered by assignment.
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 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.