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-2022 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>
71 Ostream& operator<<(Ostream&, const pointPatchField<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,
113  pointPatchField,
114  pointPatch,
115  (
116  const pointPatch& p,
118  ),
119  (p, iF)
120  );
121 
123  (
124  autoPtr,
125  pointPatchField,
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,
139  pointPatchField,
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 patchField<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 (and resize as needed) from self given a mapping object
402  // Used to update fields following mesh topology change
403  virtual void autoMap(const pointPatchFieldMapper&)
404  {}
405 
406  //- Reverse map the given pointPatchField onto this pointPatchField
407  // Used to reconstruct fields
408  virtual void rmap(const pointPatchField<Type>&, const labelList&)
409  {}
410 
411  //- Reset the pointPatchField to the given pointPatchField
412  // Used for mesh to mesh mapping
413  virtual void reset(const pointPatchField<Type>&)
414  {}
415 
416 
417  // Evaluation functions
418 
419  //- Update the coefficients associated with the patch field
420  // Sets Updated to true
421  virtual void updateCoeffs()
422  {
423  updated_ = true;
424  }
425 
426  //- Initialise evaluation of the patch field (do nothing)
427  virtual void initEvaluate
428  (
429  const Pstream::commsTypes commsType =
431  )
432  {}
433 
434  //- Evaluate the patch field
435  virtual void evaluate
436  (
437  const Pstream::commsTypes commsType =
439  );
440 
441 
442  // I-O
443 
444  //- Write
445  virtual void write(Ostream&) const;
446 
447 
448  // Member Operators
450  virtual void operator=(const 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>&){}
457  virtual void operator=(const Field<Type>&){}
458  virtual void operator+=(const Field<Type>&){}
459  virtual void operator-=(const Field<Type>&){}
461  virtual void operator*=(const Field<scalar>&){}
462  virtual void operator/=(const Field<scalar>&){}
464  virtual void operator=(const Type&){}
465  virtual void operator+=(const Type&){}
466  virtual void operator-=(const Type&){}
467  virtual void operator*=(const scalar){}
468  virtual void operator/=(const scalar){}
469 
470 
471  // Force an assignment irrespective of form of patch
472  // By generic these do nothing unless the patch actually has boundary
473  // values
475  virtual void operator==(const pointPatchField<Type>&){}
476  virtual void operator==(const Field<Type>&){}
477  virtual void operator==(const Type&){}
478 
479 
480  // Ostream operator
481 
482  friend Ostream& operator<< <Type>
483  (
484  Ostream&,
485  const pointPatchField<Type>&
486  );
487 };
488 
489 
490 // This function is added as a hack to enable simple backward compatibility
491 // with versions using referenceLevel in GeometicField
492 template<class Type>
493 const pointPatchField<Type>& operator+
494 (
495  const pointPatchField<Type>& ppf,
496  const Type&
497 )
498 {
499  return ppf;
500 }
501 
502 
503 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
504 
505 } // End namespace Foam
506 
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
508 
510 
511 #ifdef NoRepository
512  #include "pointPatchField.C"
513  #include "calculatedPointPatchField.H"
514 #endif
515 
517 #define makePointPatchField(pointPatchTypeField) \
518  defineNamedTemplateTypeNameAndDebug(pointPatchTypeField, 0); \
519  template<> \
520  int pointPatchTypeField::disallowGenericPointPatchField \
521  ( \
522  debug::debugSwitch("disallowGenericPointPatchField", 0) \
523  ); \
524  defineTemplateRunTimeSelectionTable(pointPatchTypeField, pointPatch); \
525  defineTemplateRunTimeSelectionTable(pointPatchTypeField, patchMapper); \
526  defineTemplateRunTimeSelectionTable(pointPatchTypeField, dictionary);
527 
528 
530 #define addToPointPatchFieldRunTimeSelection(PatchTypeField,typePatchTypeField)\
531  addToRunTimeSelectionTable \
532  ( \
533  PatchTypeField, \
534  typePatchTypeField, \
535  pointPatch \
536  ); \
537  addToRunTimeSelectionTable \
538  ( \
539  PatchTypeField, \
540  typePatchTypeField, \
541  patchMapper \
542  ); \
543  addToRunTimeSelectionTable \
544  ( \
545  PatchTypeField, \
546  typePatchTypeField, \
547  dictionary \
548  );
549 
550 
551 // For non-templated patch fields
552 #define makePointPatchTypeField(PatchTypeField, typePatchTypeField) \
553  defineTypeNameAndDebug(typePatchTypeField, 0); \
554  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
555 
556 
557 // For templated patch fields
558 #define makeTemplatePointPatchTypeField(fieldType, type) \
559  defineNamedTemplateTypeNameAndDebug \
560  ( \
561  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
562  0 \
563  ); \
564  addToPointPatchFieldRunTimeSelection \
565  ( \
566  CAT3(pointPatch, CAPITALIZE(fieldType), Field), \
567  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field) \
568  )
569 
571 #define makePointPatchFields(type) \
572  FOR_ALL_FIELD_TYPES(makeTemplatePointPatchTypeField, type)
573 
575 #define makePointPatchFieldTypeName(fieldType, type) \
576  defineNamedTemplateTypeNameAndDebug \
577  ( \
578  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field), \
579  0 \
580  );
581 
583 #define makePointPatchFieldTypeNames(type) \
584  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypeName, type)
585 
587 #define makePointPatchFieldTypedef(fieldType, type) \
588  typedef type##PointPatchField<fieldType> \
589  CAT4(type, PointPatch, CAPITALIZE(fieldType), Field);
590 
592 #define makePointPatchFieldTypedefs(type) \
593  FOR_ALL_FIELD_TYPES(makePointPatchFieldTypedef, type)
594 
595 
596 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
597 
598 #endif
599 
600 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
commsTypes
Types of communications.
Definition: UPstream.H:64
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 operator==(const pointPatchField< Type > &)
A calculated boundary condition for pointField.
virtual void operator=(pointPatchField< Type > &&)
const Field< Type > & primitiveField() const
Return internal field reference.
static int disallowGenericPointPatchField
Debug switch to disallow the use of genericPointPatchField.
Abstract base class for point-mesh patch fields.
static const word & calculatedType()
Return the type of the calculated form of pointPatchField.
const objectRegistry & db() const
Return local objectRegistry.
static autoPtr< pointPatchField< Type > > NewCalculatedType(const pointPatchField< Type2 > &)
Return a pointer to a new calculatedPointPatchField created on.
const pointField & points
Include the header files for all the primitive types that Fields are instantiated for...
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
const pointPatch & patch() const
Return patch.
virtual void operator*=(const pointPatchField< scalar > &)
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
virtual void reset(const pointPatchField< Type > &)
Reset the pointPatchField to the given pointPatchField.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void operator=(const pointPatchField< Type > &)
declareRunTimeSelectionTable(autoPtr, pointPatchField, pointPatch,(const pointPatch &p, const DimensionedField< Type, pointMesh > &iF),(p, iF))
virtual void operator==(const Field< Type > &)
const DimensionedField< Type, pointMesh > & internalField() const
Return dimensioned internal field reference.
calculatedPointPatchField< Type > Calculated
virtual void write(Ostream &) const
Write.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
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,.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void operator/=(const pointPatchField< scalar > &)
bool updated() const
Return true if the boundary condition has already been updated.
TypeName("pointPatchField")
Runtime type information.
virtual void operator==(const Type &)
void setInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
label size() const
Return size.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
static autoPtr< pointPatchField< Type > > New(const word &, const pointPatch &, const DimensionedField< Type, pointMesh > &)
Return a pointer to a new patchField created on freestore given.
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
virtual void operator+=(const pointPatchField< Type > &)
virtual bool coupled() const
Return true if this patch field is coupled.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
autoPtr< pointPatchField< Type > > clone() const
Disallow clone without setting internal field reference.
Namespace for OpenFOAM.
virtual label size() const =0
Return size.
virtual bool fixesValue() const
Return true if this patch field fixes a value.