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-2024 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 tmp<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 patch
318  const pointPatch& patch() const
319  {
320  return patch_;
321  }
322 
323  //- Return dimensioned internal field reference
325  {
326  return internalField_;
327  }
328 
329  //- Return internal field reference
330  const Field<Type>& primitiveField() const
331  {
332  return internalField_;
333  }
334 
335  //- Return true if the boundary condition has already been updated
336  bool updated() const
337  {
338  return updated_;
339  }
340 
341  //- Return field created from appropriate internal field values
343 
344  //- Return field created from appropriate internal field values
345  // given internal field reference
346  template<class Type1>
348  (
349  const Field<Type1>& iF
350  ) const;
351 
352  //- Return field created from selected internal field values
353  // given internal field reference
354  template<class Type1>
356  (
357  const Field<Type1>& iF,
358  const labelList& meshPoints
359  ) const;
360 
361  //- Given the internal field and a patch field,
362  // add the patch field to the internal field
363  template<class Type1>
364  void addToInternalField
365  (
366  Field<Type1>& iF,
367  const Field<Type1>& pF
368  ) const;
369 
370  //- Given the internal field and a patch field,
371  // add selected elements of the patch field to the internal field
372  template<class Type1>
373  void addToInternalField
374  (
375  Field<Type1>& iF,
376  const Field<Type1>& pF,
377  const labelList& points
378  ) const;
379 
380  //- Given the internal field and a patch field,
381  // set the patch field in the internal field
382  template<class Type1>
383  void setInternalField
384  (
385  Field<Type1>& iF,
386  const Field<Type1>& pF,
387  const labelList& meshPoints
388  ) const;
389 
390  //- Given the internal field and a patch field,
391  // set the patch field in the internal field
392  template<class Type1>
393  void setInternalField
394  (
395  Field<Type1>& iF,
396  const Field<Type1>& pF
397  ) const;
398 
399 
400  // Mapping functions
401 
402  //- Map the given pointPatchField onto this pointPatchField
403  virtual void map(const pointPatchField<Type>&, const fieldMapper&)
404  {}
405 
406  //- Reset the pointPatchField to the given pointPatchField
407  // Used for mesh to mesh mapping
408  virtual void reset(const pointPatchField<Type>&)
409  {}
410 
411 
412  // Evaluation functions
413 
414  //- Update the coefficients associated with the patch field
415  // Sets Updated to true
416  virtual void updateCoeffs()
417  {
418  updated_ = true;
419  }
420 
421  //- Initialise evaluation of the patch field (do nothing)
422  virtual void initEvaluate
423  (
424  const Pstream::commsTypes commsType =
426  )
427  {}
428 
429  //- Evaluate the patch field
430  virtual void evaluate
431  (
432  const Pstream::commsTypes commsType =
434  );
435 
436 
437  // I-O
438 
439  //- Write
440  virtual void write(Ostream&) const;
441 
442 
443  // Member Operators
444 
445  virtual void operator=(const pointPatchField<Type>&){}
447  virtual void operator+=(const pointPatchField<Type>&){}
448  virtual void operator-=(const pointPatchField<Type>&){}
449  virtual void operator*=(const pointPatchField<scalar>&){}
450  virtual void operator/=(const pointPatchField<scalar>&){}
451 
452  virtual void operator=(const Field<Type>&){}
453  virtual void operator+=(const Field<Type>&){}
454  virtual void operator-=(const Field<Type>&){}
455 
456  virtual void operator*=(const Field<scalar>&){}
457  virtual void operator/=(const Field<scalar>&){}
458 
459  virtual void operator=(const Type&){}
460  virtual void operator+=(const Type&){}
461  virtual void operator-=(const Type&){}
462  virtual void operator*=(const scalar){}
463  virtual void operator/=(const scalar){}
464 
465 
466  // Force an assignment irrespective of form of patch
467  // By generic these do nothing unless the patch actually has boundary
468  // values
469 
470  virtual void operator==(const pointPatchField<Type>&){}
471  virtual void operator==(const Field<Type>&){}
472  virtual void operator==(const Type&){}
473 
474 
475  // Ostream operator
476 
477  friend Ostream& operator<< <Type>
478  (
479  Ostream&,
480  const pointPatchField<Type>&
481  );
482 };
483 
484 
485 // This function is added as a hack to enable simple backward compatibility
486 // with versions using referenceLevel in GeometicField
487 template<class Type>
488 const pointPatchField<Type>& operator+
489 (
490  const pointPatchField<Type>& ppf,
491  const Type&
492 )
493 {
494  return ppf;
495 }
496 
497 
498 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
499 
500 } // End namespace Foam
501 
502 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
503 
505 
506 #ifdef NoRepository
507  #include "pointPatchField.C"
508  #include "calculatedPointPatchField.H"
509 #endif
510 
511 
512 #define makePointPatchField(pointPatchTypeField) \
513  defineNamedTemplateTypeNameAndDebug(pointPatchTypeField, 0); \
514  template<> \
515  int pointPatchTypeField::disallowGenericPointPatchField \
516  ( \
517  debug::debugSwitch("disallowGenericPointPatchField", 0) \
518  ); \
519  defineTemplateRunTimeSelectionTable(pointPatchTypeField, pointPatch); \
520  defineTemplateRunTimeSelectionTable(pointPatchTypeField, patchMapper); \
521  defineTemplateRunTimeSelectionTable(pointPatchTypeField, dictionary);
522 
523 
524 #define addToPointPatchFieldRunTimeSelection(PatchTypeField,typePatchTypeField)\
525  addToRunTimeSelectionTable \
526  ( \
527  PatchTypeField, \
528  typePatchTypeField, \
529  patchMapper \
530  ); \
531  addToRunTimeSelectionTable \
532  ( \
533  PatchTypeField, \
534  typePatchTypeField, \
535  dictionary \
536  );
537 
538 
539 #define addToNullConstructablePointPatchFieldRunTimeSelection( \
540  PatchTypeField, typePatchTypeField) \
541  \
542  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
543  \
544  addToRunTimeSelectionTable \
545  ( \
546  PatchTypeField, \
547  typePatchTypeField, \
548  pointPatch \
549  );
550 
551 
552 // For non-templated patch fields
553 #define makePointPatchTypeField(PatchTypeField, typePatchTypeField) \
554  defineTypeNameAndDebug(typePatchTypeField, 0); \
555  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
556 
557 
558 // For non-templated patch fields
559 #define makeNullConstructablePointPatchTypeField( \
560  PatchTypeField, typePatchTypeField) \
561  \
562  defineTypeNameAndDebug(typePatchTypeField, 0); \
563  addToNullConstructablePointPatchFieldRunTimeSelection \
564  ( \
565  PatchTypeField, \
566  typePatchTypeField \
567  )
568 
569 
570 // For templated patch fields
571 #define makeTemplatePointPatchTypeField(fieldType, type) \
572  defineNamedTemplateTypeNameAndDebug \
573  ( \
574  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
575  0 \
576  ); \
577  addToPointPatchFieldRunTimeSelection \
578  ( \
579  CAT3(pointPatch, CAPITALIZE(fieldType), Field), \
580  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field) \
581  )
582 
583 
584 // For templated patch fields
585 #define makeNullConstructableTemplatePointPatchTypeField(fieldType, type) \
586  defineNamedTemplateTypeNameAndDebug \
587  ( \
588  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
589  0 \
590  ); \
591  addToNullConstructablePointPatchFieldRunTimeSelection \
592  ( \
593  CAT3(pointPatch, CAPITALIZE(fieldType), Field), \
594  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field) \
595  )
596 
597 
598 #define makePointPatchFields(type) \
599  FOR_ALL_FIELD_TYPES(makeTemplatePointPatchTypeField, type)
600 
601 
602 #define makeNullConstructablePointPatchFields(type) \
603  FOR_ALL_FIELD_TYPES(makeNullConstructableTemplatePointPatchTypeField, type)
604 
605 
606 #define makePointPatchFieldTypeName(fieldType, type) \
607  defineNamedTemplateTypeNameAndDebug \
608  ( \
609  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
610  0 \
611  );
612 
613 
614 #define makePointPatchFieldTypeNames(type) \
615  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypeName, type)
616 
617 
618 #define makePointPatchFieldTypedef(fieldType, type) \
619  typedef type##PointPatchField<fieldType> \
620  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field);
621 
622 
623 #define makePointPatchFieldTypedefs(type) \
624  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypedef, type)
625 
626 
627 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
628 
629 #endif
630 
631 // ************************************************************************* //
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
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 keyword definitions, which are a keyword followed by any number of values (e....
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.
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 void operator=(const pointPatchField< 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 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:57
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:62
#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