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-2026 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"
48 #include "fieldTypes.H"
49 #include "autoPtr.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 
58 class objectRegistry;
59 class dictionary;
60 class fieldMapper;
61 class pointMesh;
62 
63 // Forward declaration of friend functions and operators
64 
65 template<class Type>
66 class pointPatchField;
67 
68 template<class Type>
69 class calculatedPointPatchField;
70 
71 template<class Type>
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class pointPatchField Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class pointPatchField
81 {
82  // Private Data
83 
84  //- Reference to patch
85  const pointPatch& patch_;
86 
87  //- Reference to internal field
88  const DimensionedField<Type, pointMesh>& internalField_;
89 
90  //- Update index used so that updateCoeffs is called only once during
91  // the construction of the matrix
92  bool updated_;
93 
94 
95 public:
96 
97  typedef Type value_type;
98  typedef pointPatch Patch;
100 
101 
102  //- Runtime type information
103  TypeName("pointPatchField");
104 
105  //- Debug switch to disallow the use of genericPointPatchField
107 
108 
109  // Declare run-time constructor selection tables
110 
112  (
113  autoPtr,
115  pointPatch,
116  (
117  const pointPatch& p,
119  ),
120  (p, iF)
121  );
122 
124  (
125  autoPtr,
127  patchMapper,
128  (
129  const pointPatchField<Type>& ptf,
130  const pointPatch& p,
132  const fieldMapper& m
133  ),
134  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
135  );
136 
138  (
139  autoPtr,
141  dictionary,
142  (
143  const pointPatch& p,
145  const dictionary& dict
146  ),
147  (p, iF, dict)
148  );
149 
150 
151  // Constructors
152 
153  //- Construct from patch and internal field
155  (
156  const pointPatch&,
158  );
159 
160  //- Construct from patch, internal field and dictionary
162  (
163  const pointPatch&,
165  const dictionary&
166  );
167 
168  //- Construct by mapping given pointPatchField<Type> onto a new patch
170  (
171  const pointPatchField<Type>&,
172  const pointPatch&,
174  const fieldMapper&
175  );
176 
177  //- Disallow copy without setting internal field reference
178  pointPatchField(const pointPatchField<Type>&) = delete;
179 
180  //- Disallow clone without setting internal field reference
182  {
184  return autoPtr<pointPatchField<Type>>(nullptr);
185  }
186 
187  //- Construct as copy setting internal field reference
189  (
190  const pointPatchField<Type>&,
192  );
193 
194  //- Construct and return a clone setting internal field reference
196  (
198  ) const = 0;
199 
200  //- Construct and return a clone setting internal field reference
202  (
203  const pointPatch& patch,
205  ) const
206  {
208  return autoPtr<pointPatchField<Type>>(nullptr);
209  }
210 
211 
212  // Selectors
213 
214  //- Return a pointer to a new patchField created on freestore given
215  // patch and internal field
216  // (does not set the patch field values)
218  (
219  const word&,
220  const pointPatch&,
222  );
223 
224  //- Return a pointer to a new patchField created on freestore given
225  // patch and internal field
226  // (does not set the patch field values).
227  // Allows override of constraint type
229  (
230  const word&,
231  const word& actualPatchType,
232  const pointPatch&,
234  );
235 
236  //- Return a pointer to a new patchField created on freestore from
237  // a given pointPatchField mapped onto a new patch
239  (
240  const pointPatchField<Type>&,
241  const pointPatch&,
243  const fieldMapper&
244  );
245 
246  //- Return a pointer to a new patchField created on freestore
247  // from dictionary
249  (
250  const pointPatch&,
252  const dictionary&
253  );
254 
255  //- Return a pointer to a new calculatedPointPatchField created on
256  // freestore without setting patchField values
257  template<class Type2>
260  (
262  );
263 
264 
265  //- Destructor
266  virtual ~pointPatchField()
267  {}
268 
269 
270  // Member Functions
271 
272  // Attributes
273 
274  //- Return the type of the calculated form of pointPatchField
275  static const word& calculatedType();
276 
277  //- Return size
278  label size() const
279  {
280  return patch().size();
281  }
282 
283  //- Return true if this patch field fixes a value
284  virtual bool fixesValue() const
285  {
286  return false;
287  }
288 
289  //- Return true if this patch field is coupled
290  virtual bool coupled() const
291  {
292  return false;
293  }
294 
295  //- Return true if this overrides the underlying constraint type
296  bool overridesConstraint() const
297  {
298  if (type() == patch_.type())
299  {
300  return false;
301  }
302 
303  typename pointPatchConstructorTable::iterator patchTypeCstrIter
304  = pointPatchConstructorTablePtr_->find(patch_.type());
305 
306  return
307  patchTypeCstrIter
308  != pointPatchConstructorTablePtr_->end();
309  }
310 
311 
312  // Access
313 
314  //- Return local objectRegistry
315  const objectRegistry& db() const;
316 
317  //- Return time
318  const Time& time() const;
319 
320  //- Return patch
321  const pointPatch& patch() const
322  {
323  return patch_;
324  }
325 
326  //- Return dimensioned internal field reference
328  {
329  return internalField_;
330  }
331 
332  //- Return internal field reference
333  const Field<Type>& primitiveField() const
334  {
335  return internalField_;
336  }
337 
338  //- Return true if the boundary condition has already been updated
339  bool updated() const
340  {
341  return updated_;
342  }
343 
344  //- Return field created from appropriate internal field values
346 
347  //- Return field created from appropriate internal field values
348  // given internal field reference
349  template<class Type1>
351  (
352  const Field<Type1>& iF
353  ) const;
354 
355  //- Return field created from selected internal field values
356  // given internal field reference
357  template<class Type1>
359  (
360  const Field<Type1>& iF,
361  const labelList& meshPoints
362  ) const;
363 
364  //- Given the internal field and a patch field,
365  // add the patch field to the internal field
366  template<class Type1>
367  void addToInternalField
368  (
369  Field<Type1>& iF,
370  const Field<Type1>& pF
371  ) const;
372 
373  //- Given the internal field and a patch field,
374  // add selected elements of the patch field to the internal field
375  template<class Type1>
376  void addToInternalField
377  (
378  Field<Type1>& iF,
379  const Field<Type1>& pF,
380  const labelList& points
381  ) const;
382 
383  //- Given the internal field and a patch field,
384  // set the patch field in the internal field
385  template<class Type1>
386  void setInternalField
387  (
388  Field<Type1>& iF,
389  const Field<Type1>& pF,
390  const labelList& meshPoints
391  ) const;
392 
393  //- Given the internal field and a patch field,
394  // set the patch field in the internal field
395  template<class Type1>
396  void setInternalField
397  (
398  Field<Type1>& iF,
399  const Field<Type1>& pF
400  ) const;
401 
402 
403  // Mapping functions
404 
405  //- Map the given pointPatchField onto this pointPatchField
406  virtual void map(const pointPatchField<Type>&, const fieldMapper&)
407  {}
408 
409  //- Reset the pointPatchField to the given pointPatchField
410  // Used for mesh to mesh mapping
411  virtual void reset(const pointPatchField<Type>&)
412  {}
413 
414 
415  // Evaluation functions
416 
417  //- Update the coefficients associated with the patch field
418  // Sets Updated to true
419  virtual void updateCoeffs()
420  {
421  updated_ = true;
422  }
423 
424  //- Initialise evaluation of the patch field (do nothing)
425  virtual void initEvaluate
426  (
427  const Pstream::commsTypes commsType =
429  )
430  {}
431 
432  //- Evaluate the patch field
433  virtual void evaluate
434  (
435  const Pstream::commsTypes commsType =
437  );
438 
439 
440  // I-O
441 
442  //- Write
443  virtual void write(Ostream&) const;
444 
445 
446  // Member Operators
447 
448  virtual void operator=(const UList<Type>&) {}
449 
450  virtual void operator=(const pointPatchField<Type>&) {}
451  virtual void operator=(pointPatchField<Type>&&) {}
452  virtual void operator+=(const pointPatchField<Type>&) {}
453  virtual void operator-=(const pointPatchField<Type>&) {}
454  virtual void operator*=(const pointPatchField<scalar>&) {}
455  virtual void operator/=(const pointPatchField<scalar>&) {}
456 
457  virtual void operator+=(const Field<Type>&) {}
458  virtual void operator-=(const Field<Type>&) {}
459 
460  virtual void operator*=(const Field<scalar>&) {}
461  virtual void operator/=(const Field<scalar>&) {}
462 
463  virtual void operator=(const Type&) {}
464  virtual void operator+=(const Type&) {}
465  virtual void operator-=(const Type&) {}
466  virtual void operator*=(const scalar) {}
467  virtual void operator/=(const scalar) {}
468 
469 
470  // Force an assignment irrespective of form of patch. These do nothing
471  // unless the patch actually has boundary values.
472 
473  virtual void operator==(const pointPatchField<Type>&) {}
474  virtual void operator==(const Field<Type>&) {}
475  virtual void operator==(const Type&) {}
476 
477 
478  // Ostream operator
479 
480  friend Ostream& operator<< <Type>
481  (
482  Ostream&,
483  const pointPatchField<Type>&
484  );
485 };
486 
487 
488 // This function is added as a hack to enable simple backward compatibility
489 // with versions using referenceLevel in GeometicField
490 template<class Type>
491 const pointPatchField<Type>& operator+
492 (
493  const pointPatchField<Type>& ppf,
494  const Type&
495 )
496 {
497  return ppf;
498 }
499 
500 
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
502 
503 } // End namespace Foam
504 
505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
506 
508 
509 #ifdef NoRepository
510  #include "pointPatchField.C"
511  #include "calculatedPointPatchField.H"
512 #endif
513 
514 
515 #define makePointPatchField(pointPatchTypeField) \
516  defineNamedTemplateTypeNameAndDebug(pointPatchTypeField, 0); \
517  template<> \
518  int pointPatchTypeField::disallowGenericPointPatchField \
519  ( \
520  debug::debugSwitch("disallowGenericPointPatchField", 0) \
521  ); \
522  defineTemplateRunTimeSelectionTable(pointPatchTypeField, pointPatch); \
523  defineTemplateRunTimeSelectionTable(pointPatchTypeField, patchMapper); \
524  defineTemplateRunTimeSelectionTable(pointPatchTypeField, dictionary);
525 
526 
527 #define addToPointPatchFieldRunTimeSelection(PatchTypeField,typePatchTypeField)\
528  addToRunTimeSelectionTable \
529  ( \
530  PatchTypeField, \
531  typePatchTypeField, \
532  patchMapper \
533  ); \
534  addToRunTimeSelectionTable \
535  ( \
536  PatchTypeField, \
537  typePatchTypeField, \
538  dictionary \
539  );
540 
541 
542 #define addToNullConstructablePointPatchFieldRunTimeSelection( \
543  PatchTypeField, typePatchTypeField) \
544  \
545  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
546  \
547  addToRunTimeSelectionTable \
548  ( \
549  PatchTypeField, \
550  typePatchTypeField, \
551  pointPatch \
552  );
553 
554 
555 // For non-templated patch fields
556 #define makePointPatchTypeField(PatchTypeField, typePatchTypeField) \
557  defineTypeNameAndDebug(typePatchTypeField, 0); \
558  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
559 
560 
561 // For non-templated patch fields
562 #define makeNullConstructablePointPatchTypeField( \
563  PatchTypeField, typePatchTypeField) \
564  \
565  defineTypeNameAndDebug(typePatchTypeField, 0); \
566  addToNullConstructablePointPatchFieldRunTimeSelection \
567  ( \
568  PatchTypeField, \
569  typePatchTypeField \
570  )
571 
572 
573 // For templated patch fields
574 #define makeTemplatePointPatchTypeField(fieldType, type) \
575  defineNamedTemplateTypeNameAndDebug \
576  ( \
577  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
578  0 \
579  ); \
580  addToPointPatchFieldRunTimeSelection \
581  ( \
582  CAT3(pointPatch, CAPITALIZE(fieldType), Field), \
583  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field) \
584  )
585 
586 
587 // For templated patch fields
588 #define makeNullConstructableTemplatePointPatchTypeField(fieldType, type) \
589  defineNamedTemplateTypeNameAndDebug \
590  ( \
591  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
592  0 \
593  ); \
594  addToNullConstructablePointPatchFieldRunTimeSelection \
595  ( \
596  CAT3(pointPatch, CAPITALIZE(fieldType), Field), \
597  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field) \
598  )
599 
600 
601 #define makePointPatchFields(type) \
602  FOR_ALL_FIELD_TYPES(makeTemplatePointPatchTypeField, type)
603 
604 
605 #define makeNullConstructablePointPatchFields(type) \
606  FOR_ALL_FIELD_TYPES(makeNullConstructableTemplatePointPatchTypeField, type)
607 
608 
609 #define makePointPatchFieldTypeName(fieldType, type) \
610  defineNamedTemplateTypeNameAndDebug \
611  ( \
612  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
613  0 \
614  );
615 
616 
617 #define makePointPatchFieldTypeNames(type) \
618  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypeName, type)
619 
620 
621 #define makePointPatchFieldTypedef(fieldType, type) \
622  typedef type##PointPatchField<fieldType> \
623  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field);
624 
625 
626 #define makePointPatchFieldTypedefs(type) \
627  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypedef, type)
628 
629 
630 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
631 
632 #endif
633 
634 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
commsTypes
Types of communications.
Definition: UPstream.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A calculated boundary condition for pointField.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Registry of regIOobjects.
Abstract base class for point-mesh patch fields.
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise evaluation of the patch field (do nothing)
virtual bool fixesValue() const
Return true if this patch field fixes a value.
TypeName("pointPatchField")
Runtime type information.
virtual void operator==(const pointPatchField< Type > &)
static int disallowGenericPointPatchField
Debug switch to disallow the use of genericPointPatchField.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
const Time & time() const
Return time.
virtual ~pointPatchField()
Destructor.
virtual void write(Ostream &) const
Write.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
virtual void operator==(const Type &)
virtual bool coupled() const
Return true if this patch field is coupled.
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
virtual void operator/=(const pointPatchField< scalar > &)
const DimensionedField< Type, pointMesh > & internalField() const
Return dimensioned internal field reference.
calculatedPointPatchField< Type > Calculated
const Field< Type > & primitiveField() const
Return internal field reference.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void operator+=(const pointPatchField< Type > &)
autoPtr< pointPatchField< Type > > clone() const
Disallow clone without setting internal field reference.
const objectRegistry & db() const
Return local objectRegistry.
static autoPtr< pointPatchField< Type > > New(const word &, const pointPatch &, const DimensionedField< Type, pointMesh > &)
Return a pointer to a new patchField created on freestore given.
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
virtual void operator-=(const pointPatchField< Type > &)
virtual void operator=(const UList< Type > &)
virtual void operator==(const Field< Type > &)
virtual void reset(const pointPatchField< Type > &)
Reset the pointPatchField to the given pointPatchField.
virtual void operator*=(const pointPatchField< scalar > &)
const pointPatch & patch() const
Return patch.
label size() const
Return size.
void setInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
virtual void map(const pointPatchField< Type > &, const fieldMapper &)
Map the given pointPatchField onto this pointPatchField.
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
declareRunTimeSelectionTable(autoPtr, pointPatchField, pointPatch,(const pointPatch &p, const DimensionedField< Type, pointMesh > &iF),(p, iF))
bool updated() const
Return true if the boundary condition has already been updated.
virtual void operator=(pointPatchField< Type > &&)
static const word & calculatedType()
Return the type of the calculated form of pointPatchField.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
virtual label size() const =0
Return size.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Include the header files for all the primitive types that Fields are instantiated for.
const pointField & points
Namespace for OpenFOAM.
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
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p