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-2023 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"
47 #include "fieldTypes.H"
48 #include "autoPtr.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of classes
56 
57 class objectRegistry;
58 class dictionary;
59 class pointPatchFieldMapper;
60 class pointMesh;
61 
62 // Forward declaration of friend functions and operators
63 
64 template<class Type>
65 class pointPatchField;
66 
67 template<class Type>
68 class calculatedPointPatchField;
69 
70 template<class Type>
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class pointPatchField Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type>
79 class pointPatchField
80 {
81  // Private Data
82 
83  //- Reference to patch
84  const pointPatch& patch_;
85 
86  //- Reference to internal field
87  const DimensionedField<Type, pointMesh>& internalField_;
88 
89  //- Update index used so that updateCoeffs is called only once during
90  // the construction of the matrix
91  bool updated_;
92 
93 
94 public:
95 
96  typedef Type value_type;
97  typedef pointPatch Patch;
99 
100 
101  //- Runtime type information
102  TypeName("pointPatchField");
103 
104  //- Debug switch to disallow the use of genericPointPatchField
106 
107 
108  // Declare run-time constructor selection tables
109 
111  (
112  autoPtr,
114  pointPatch,
115  (
116  const pointPatch& p,
118  ),
119  (p, iF)
120  );
121 
123  (
124  autoPtr,
126  patchMapper,
127  (
128  const pointPatchField<Type>& ptf,
129  const pointPatch& p,
131  const pointPatchFieldMapper& m
132  ),
133  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
134  );
135 
137  (
138  autoPtr,
140  dictionary,
141  (
142  const pointPatch& p,
144  const dictionary& dict
145  ),
146  (p, iF, dict)
147  );
148 
149 
150  // Constructors
151 
152  //- Construct from patch and internal field
154  (
155  const pointPatch&,
157  );
158 
159  //- Construct from patch, internal field and dictionary
161  (
162  const pointPatch&,
164  const dictionary&
165  );
166 
167  //- Construct by mapping given pointPatchField<Type> onto a new patch
169  (
170  const pointPatchField<Type>&,
171  const pointPatch&,
173  const pointPatchFieldMapper&
174  );
175 
176  //- Disallow copy without setting internal field reference
177  pointPatchField(const pointPatchField<Type>&) = delete;
178 
179  //- Disallow clone without setting internal field reference
181  {
183  return tmp<pointPatchField<Type>>(nullptr);
184  }
185 
186  //- Construct as copy setting internal field reference
188  (
189  const pointPatchField<Type>&,
191  );
192 
193  //- Construct and return a clone setting internal field reference
195  (
197  ) const = 0;
198 
199  //- Construct and return a clone setting internal field reference
201  (
202  const pointPatch& patch,
204  ) const
205  {
207  return autoPtr<pointPatchField<Type>>(nullptr);
208  }
209 
210 
211  // Selectors
212 
213  //- Return a pointer to a new patchField created on freestore given
214  // patch and internal field
215  // (does not set the patch field values)
217  (
218  const word&,
219  const pointPatch&,
221  );
222 
223  //- Return a pointer to a new patchField created on freestore given
224  // patch and internal field
225  // (does not set the patch field values).
226  // Allows override of constraint type
228  (
229  const word&,
230  const word& actualPatchType,
231  const pointPatch&,
233  );
234 
235  //- Return a pointer to a new patchField created on freestore from
236  // a given pointPatchField mapped onto a new patch
238  (
239  const pointPatchField<Type>&,
240  const pointPatch&,
242  const pointPatchFieldMapper&
243  );
244 
245  //- Return a pointer to a new patchField created on freestore
246  // from dictionary
248  (
249  const pointPatch&,
251  const dictionary&
252  );
253 
254  //- Return a pointer to a new calculatedPointPatchField created on
255  // freestore without setting patchField values
256  template<class Type2>
259  (
261  );
262 
263 
264  //- Destructor
265  virtual ~pointPatchField<Type>()
266  {}
267 
268 
269  // Member Functions
270 
271  // Attributes
272 
273  //- Return the type of the calculated form of pointPatchField
274  static const word& calculatedType();
275 
276  //- Return size
277  label size() const
278  {
279  return patch().size();
280  }
281 
282  //- Return true if this patch field fixes a value
283  virtual bool fixesValue() const
284  {
285  return false;
286  }
287 
288  //- Return true if this patch field is coupled
289  virtual bool coupled() const
290  {
291  return false;
292  }
293 
294  //- Return true if this overrides the underlying constraint type
295  bool overridesConstraint() const
296  {
297  if (type() == patch_.type())
298  {
299  return false;
300  }
301 
302  typename pointPatchConstructorTable::iterator patchTypeCstrIter
303  = pointPatchConstructorTablePtr_->find(patch_.type());
304 
305  return
306  patchTypeCstrIter
307  != pointPatchConstructorTablePtr_->end();
308  }
309 
310 
311  // Access
312 
313  //- Return local objectRegistry
314  const objectRegistry& db() const;
315 
316  //- Return patch
317  const pointPatch& patch() const
318  {
319  return patch_;
320  }
321 
322  //- Return dimensioned internal field reference
324  {
325  return internalField_;
326  }
327 
328  //- Return internal field reference
329  const Field<Type>& primitiveField() const
330  {
331  return internalField_;
332  }
333 
334  //- Return true if the boundary condition has already been updated
335  bool updated() const
336  {
337  return updated_;
338  }
339 
340  //- Return field created from appropriate internal field values
342 
343  //- Return field created from appropriate internal field values
344  // given internal field reference
345  template<class Type1>
347  (
348  const Field<Type1>& iF
349  ) const;
350 
351  //- Return field created from selected internal field values
352  // given internal field reference
353  template<class Type1>
355  (
356  const Field<Type1>& iF,
357  const labelList& meshPoints
358  ) const;
359 
360  //- Given the internal field and a patch field,
361  // add the patch field to the internal field
362  template<class Type1>
363  void addToInternalField
364  (
365  Field<Type1>& iF,
366  const Field<Type1>& pF
367  ) const;
368 
369  //- Given the internal field and a patch field,
370  // add selected elements of the patch field to the internal field
371  template<class Type1>
372  void addToInternalField
373  (
374  Field<Type1>& iF,
375  const Field<Type1>& pF,
376  const labelList& points
377  ) const;
378 
379  //- Given the internal field and a patch field,
380  // set the patch field in the internal field
381  template<class Type1>
382  void setInternalField
383  (
384  Field<Type1>& iF,
385  const Field<Type1>& pF,
386  const labelList& meshPoints
387  ) const;
388 
389  //- Given the internal field and a patch field,
390  // set the patch field in the internal field
391  template<class Type1>
392  void setInternalField
393  (
394  Field<Type1>& iF,
395  const Field<Type1>& pF
396  ) const;
397 
398 
399  // Mapping functions
400 
401  //- Map the given pointPatchField onto this pointPatchField
402  virtual void map
403  (
404  const pointPatchField<Type>&,
405  const pointPatchFieldMapper&
406  )
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 pointPatchField<Type>&){}
450  virtual void operator+=(const pointPatchField<Type>&){}
451  virtual void operator-=(const pointPatchField<Type>&){}
452  virtual void operator*=(const pointPatchField<scalar>&){}
453  virtual void operator/=(const pointPatchField<scalar>&){}
454 
455  virtual void operator=(const Field<Type>&){}
456  virtual void operator+=(const Field<Type>&){}
457  virtual void operator-=(const Field<Type>&){}
458 
459  virtual void operator*=(const Field<scalar>&){}
460  virtual void operator/=(const Field<scalar>&){}
461 
462  virtual void operator=(const Type&){}
463  virtual void operator+=(const Type&){}
464  virtual void operator-=(const Type&){}
465  virtual void operator*=(const scalar){}
466  virtual void operator/=(const scalar){}
467 
468 
469  // Force an assignment irrespective of form of patch
470  // By generic these do nothing unless the patch actually has boundary
471  // 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:82
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:160
Registry of regIOobjects.
Foam::pointPatchFieldMapper.
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 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 map(const pointPatchField< Type > &, const pointPatchFieldMapper &)
Map the given pointPatchField onto this 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,.
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:353
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 &, const ensightPart &)
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