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-2023 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  // Private Data
245  //- Reference to internal field
246  const DimensionedField<Type, pointMesh>& internalField_;
247 
248 
249 public:
250 
251  //- The Field value_type
252  typedef Type value_type;
253 
254  //- The internal field type associated with the patch field
256 
257  //- The patch type for the patch field
258  typedef pointPatch Patch;
259 
260  //- Type for a \em calculated patch
262 
264  // Declare run-time constructor selection tables
265 
267  (
268  autoPtr,
270  patch,
271  (
272  const pointPatch& p,
274  ),
275  (p, iF)
276  );
277 
279  (
280  autoPtr,
282  patchMapper,
283  (
284  const pointPatchField<Type>& ptf,
285  const pointPatch& p,
287  const pointPatchFieldMapper& m
288  ),
289  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
290  );
291 
293  (
294  autoPtr,
296  dictionary,
297  (
298  const pointPatch& p,
300  const dictionary& dict
301  ),
302  (p, iF, dict)
303  );
304 
305 
306  // Constructors
307 
308  //- Construct from patch and internal field
310  (
311  const pointPatch&,
313  );
315  //- Construct from patch, internal field and dictionary
317  (
318  const pointPatch&,
320  const dictionary&
321  );
322 
323  //- Construct by mapping given patch field onto a new patch
325  (
326  const pointPatchField<Type>&,
327  const pointPatch&,
329  const pointPatchFieldMapper&
330  );
331 
332  //- Construct as copy
334 
335  //- Construct as copy setting internal field reference
337  (
338  const pointPatchField<Type>&,
340  );
341 
342  //- Construct and return a clone
343  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
344 
345  //- Construct and return a clone setting internal field reference
347  (
349  ) const = 0;
350 
351 
352  // Selectors
353 
354  //- Return a pointer to a new patchField created on freestore given
355  // patch and internal field
356  // (does not set the patch field values)
358  (
359  const word& patchFieldType,
360  const pointPatch& p,
362  );
363 
364  //- Return a pointer to a new patchField created on freestore given
365  // patch and internal field
366  // (does not set the patch field values).
367  // Allows override of constraint type
369  (
370  const word& patchFieldType,
371  const word& actualPatchType,
372  const pointPatch& p,
374  );
375 
376  //- Return a pointer to a new patchField created on freestore from
377  // a given pointPatchField mapped onto a new patch
379  (
380  const pointPatchField<Type>&,
381  const pointPatch&,
383  const pointPatchFieldMapper&
384  );
385 
386  //- Return a pointer to a new patchField created on freestore
387  // from dictionary
389  (
390  const pointPatch&,
392  const dictionary&
393  );
394 
395  //- Return a pointer to a new calculatedPointPatchField created on
396  // freestore without setting patchField values
397  template<class Type2>
400  (
402  );
403 
404 
405  //- Destructor
406  virtual ~pointPatchField() = default;
407 
408 
409  // Member Functions
410 
411  // Access
412 
413  //- Return the patch size
414  label size() const
415  {
416  return patch().size();
417  }
418 
419  //- Return const-reference to the dimensioned internal field
421  {
422  return internalField_;
423  }
424 
425  //- Return const-reference to the internal field values
426  const Field<Type>& primitiveField() const noexcept
427  {
428  return internalField_;
429  }
430 
431 
432  // Evaluation Functions
433 
434  //- Return field created from appropriate internal field values
435  tmp<Field<Type>> patchInternalField() const;
436 
437  //- Return field created from appropriate internal field values
438  //- given internal field reference
439  template<class Type1>
440  tmp<Field<Type1>> patchInternalField
441  (
442  const Field<Type1>& iF
443  ) const;
444 
445  //- Return field created from selected internal field values
446  //- given internal field reference
447  template<class Type1>
448  tmp<Field<Type1>> patchInternalField
449  (
450  const Field<Type1>& iF,
451  const labelUList& meshPoints
452  ) const;
453 
454  //- Given the internal field and a patch field,
455  //- add the patch field to the internal field
456  template<class Type1>
457  void addToInternalField
458  (
459  Field<Type1>& iF,
460  const Field<Type1>& pF
461  ) const;
462 
463  //- Given the internal field and a patch field,
464  //- add selected elements of the patch field to the internal field
465  template<class Type1>
466  void addToInternalField
467  (
468  Field<Type1>& iF,
469  const Field<Type1>& pF,
470  const labelUList& points
471  ) const;
472 
473  //- Given the internal field and a patch field,
474  //- set the patch field in the internal field
475  template<class Type1>
476  void setInInternalField
477  (
478  Field<Type1>& iF,
479  const Field<Type1>& pF,
480  const labelUList& meshPoints
481  ) const;
482 
483  //- Given the internal field and a patch field,
484  //- set the patch field in the internal field
485  template<class Type1>
486  void setInInternalField
487  (
488  Field<Type1>& iF,
489  const Field<Type1>& pF
490  ) const;
491 
492 
493  // Mapping Functions
494 
495  //- Map (and resize as needed) from self given a mapping object
496  virtual void autoMap
497  (
498  const pointPatchFieldMapper&
499  )
500  {}
501 
502  //- Reverse map the given pointPatchField onto this pointPatchField
503  virtual void rmap
504  (
505  const pointPatchField<Type>&,
506  const labelList&
507  )
508  {}
509 
511  // Evaluation Functions
512 
513  //- Update the coefficients associated with the patch field
514  // Sets Updated to true
515  virtual void updateCoeffs();
516 
517  //- Initialise evaluation of the patch field (do nothing)
518  virtual void initEvaluate
519  (
521  )
522  {}
523 
524  //- Evaluate the patch field, sets updated() to false
525  virtual void evaluate
526  (
528  );
529 
530  //- Initialise the evaluation of the patch field after a local
531  // operation
532  virtual void initEvaluateLocal
533  (
534  const Pstream::commsTypes commsType =
536  )
537  {}
538 
539  //- Evaluate the patch field after a local operation (e.g. *=)
540  virtual void evaluateLocal
541  (
542  const Pstream::commsTypes commsType =
544  )
545  {}
546 
547 
548  // Other
549 
550  //- Write
551  virtual void write(Ostream& os) const;
552 
553 
554  // Member Operators
555 
556  virtual void operator=(const pointPatchField<Type>&){}
557  virtual void operator+=(const pointPatchField<Type>&){}
558  virtual void operator-=(const pointPatchField<Type>&){}
559  virtual void operator*=(const pointPatchField<scalar>&){}
560  virtual void operator/=(const pointPatchField<scalar>&){}
561 
562  virtual void operator=(const Field<Type>&){}
563  virtual void operator+=(const Field<Type>&){}
564  virtual void operator-=(const Field<Type>&){}
565 
566  virtual void operator*=(const Field<scalar>&){}
567  virtual void operator/=(const Field<scalar>&){}
568 
569  virtual void operator=(const Type&){}
570  virtual void operator+=(const Type&){}
571  virtual void operator-=(const Type&){}
572  virtual void operator*=(const scalar){}
573  virtual void operator/=(const scalar){}
574 
575 
576  // Force an assignment irrespective of form of patch
577  // By generic these do nothing unless the patch actually has boundary
578  // values
579 
580  virtual void operator==(const pointPatchField<Type>&) {}
581  virtual void operator==(const Field<Type>&) {}
582  virtual void operator==(const Type&) {}
583 
584  // Prevent automatic comparison rewriting (c++20)
585  bool operator!=(const pointPatchField<Type>&) const = delete;
586  bool operator!=(const Field<Type>&) const = delete;
587  bool operator!=(const Type&) const = delete;
588 
589 
590  // Ostream Operator
591 
592  friend Ostream& operator<< <Type>
593  (
594  Ostream&,
595  const pointPatchField<Type>&
596  );
597 
598 
599  // Other Methods
600 
601  //- Negate the field inplace. Dummy placeholder for FieldField
602  void negate() {}
603 
604  //- Normalise the field inplace. Dummy placeholder for FieldField
605  void normalise() {}
606 };
607 
608 
609 // This function is added as a hack to enable simple backward compatibility
610 // with versions using referenceLevel in GeometricField
611 template<class Type>
612 const pointPatchField<Type>& operator+
613 (
614  const pointPatchField<Type>& ppf,
615  const Type&
616 )
617 {
618  return ppf;
619 }
620 
621 
622 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
623 
624 } // End namespace Foam
625 
626 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
627 
629 
630 #ifdef NoRepository
631  #include "pointPatchField.C"
632  #include "pointPatchFieldNew.C"
633  #include "calculatedPointPatchField.H"
635 #endif
636 
637 // Runtime selection macros
638 #include "pointPatchFieldMacros.H"
639 
640 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641 
642 #endif
643 
644 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
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.
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:72
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 initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field after a local.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
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 void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field after a local operation (e.g. *=)
virtual bool fixesValue() const
True if the patch field fixes a value.
static const word null
An empty word.
Definition: word.H:84
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 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)
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.
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 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, 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...
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.
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...
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.