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-2021 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 "autoPtr.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration of classes
55 
56 class objectRegistry;
57 class dictionary;
58 class pointPatchFieldMapper;
59 class pointMesh;
60 
61 // Forward declaration of friend functions and operators
62 
63 template<class Type>
64 class pointPatchField;
65 
66 template<class Type>
67 class calculatedPointPatchField;
68 
69 template<class Type>
70 Ostream& operator<<
71 (
72  Ostream&,
73  const pointPatchField<Type>&
74 );
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class pointPatchField Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Type>
82 class pointPatchField
83 {
84  // Private Data
85 
86  //- Reference to patch
87  const pointPatch& patch_;
88 
89  //- Reference to internal field
90  const DimensionedField<Type, pointMesh>& internalField_;
91 
92  //- Update index used so that updateCoeffs is called only once during
93  // the construction of the matrix
94  bool updated_;
95 
96 
97 public:
98 
99  typedef Type value_type;
100  typedef pointPatch Patch;
102 
103 
104  //- Runtime type information
105  TypeName("pointPatchField");
106 
107  //- Debug switch to disallow the use of genericPointPatchField
109 
110 
111  // Declare run-time constructor selection tables
112 
114  (
115  autoPtr,
117  pointPatch,
118  (
119  const pointPatch& p,
121  ),
122  (p, iF)
123  );
124 
126  (
127  autoPtr,
129  patchMapper,
130  (
131  const pointPatchField<Type>& ptf,
132  const pointPatch& p,
134  const pointPatchFieldMapper& m
135  ),
136  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
137  );
138 
140  (
141  autoPtr,
143  dictionary,
144  (
145  const pointPatch& p,
147  const dictionary& dict
148  ),
149  (p, iF, dict)
150  );
151 
152 
153  // Constructors
154 
155  //- Construct from patch and internal field
157  (
158  const pointPatch&,
160  );
161 
162  //- Construct from patch, internal field and dictionary
164  (
165  const pointPatch&,
167  const dictionary&
168  );
169 
170  //- Construct by mapping given patchField<Type> onto a new patch
172  (
173  const pointPatchField<Type>&,
174  const pointPatch&,
176  const pointPatchFieldMapper&
177  );
178 
179  //- Disallow copy without setting internal field reference
180  pointPatchField(const pointPatchField<Type>&) = delete;
181 
182  //- Disallow clone without setting internal field reference
184  {
186  return tmp<pointPatchField<Type>>(nullptr);
187  }
188 
189  //- Construct as copy setting internal field reference
191  (
192  const pointPatchField<Type>&,
194  );
195 
196  //- Construct and return a clone setting internal field reference
198  (
200  ) const = 0;
201 
202 
203  // Selectors
204 
205  //- Return a pointer to a new patchField created on freestore given
206  // patch and internal field
207  // (does not set the patch field values)
209  (
210  const word&,
211  const pointPatch&,
213  );
214 
215  //- Return a pointer to a new patchField created on freestore given
216  // patch and internal field
217  // (does not set the patch field values).
218  // Allows override of constraint type
220  (
221  const word&,
222  const word& actualPatchType,
223  const pointPatch&,
225  );
226 
227  //- Return a pointer to a new patchField created on freestore from
228  // a given pointPatchField mapped onto a new patch
230  (
231  const pointPatchField<Type>&,
232  const pointPatch&,
234  const pointPatchFieldMapper&
235  );
236 
237  //- Return a pointer to a new patchField created on freestore
238  // from dictionary
240  (
241  const pointPatch&,
243  const dictionary&
244  );
245 
246  //- Return a pointer to a new calculatedPointPatchField created on
247  // freestore without setting patchField values
248  template<class Type2>
251  (
253  );
254 
255 
256  //- Destructor
257  virtual ~pointPatchField<Type>()
258  {}
259 
260 
261  // Member Functions
262 
263  // Attributes
264 
265  //- Return the type of the calculated form of pointPatchField
266  static const word& calculatedType();
267 
268  //- Return size
269  label size() const
270  {
271  return patch().size();
272  }
273 
274  //- Return true if this patch field fixes a value
275  virtual bool fixesValue() const
276  {
277  return false;
278  }
279 
280  //- Return true if this patch field is coupled
281  virtual bool coupled() const
282  {
283  return false;
284  }
285 
286  //- Return true if this overrides the underlying constraint type
287  bool overridesConstraint() const
288  {
289  if (type() == patch_.type())
290  {
291  return false;
292  }
293 
294  typename pointPatchConstructorTable::iterator patchTypeCstrIter
295  = pointPatchConstructorTablePtr_->find(patch_.type());
296 
297  return
298  patchTypeCstrIter
299  != pointPatchConstructorTablePtr_->end();
300  }
301 
302 
303  // Access
304 
305  //- Return local objectRegistry
306  const objectRegistry& db() const;
307 
308  //- Return patch
309  const pointPatch& patch() const
310  {
311  return patch_;
312  }
313 
314  //- Return dimensioned internal field reference
316  {
317  return internalField_;
318  }
319 
320  //- Return internal field reference
321  const Field<Type>& primitiveField() const
322  {
323  return internalField_;
324  }
325 
326  //- Return true if the boundary condition has already been updated
327  bool updated() const
328  {
329  return updated_;
330  }
331 
332  //- Return field created from appropriate internal field values
334 
335  //- Return field created from appropriate internal field values
336  // given internal field reference
337  template<class Type1>
339  (
340  const Field<Type1>& iF
341  ) const;
342 
343  //- Return field created from selected internal field values
344  // given internal field reference
345  template<class Type1>
347  (
348  const Field<Type1>& iF,
349  const labelList& meshPoints
350  ) const;
351 
352  //- Given the internal field and a patch field,
353  // add the patch field to the internal field
354  template<class Type1>
355  void addToInternalField
356  (
357  Field<Type1>& iF,
358  const Field<Type1>& pF
359  ) const;
360 
361  //- Given the internal field and a patch field,
362  // add selected elements of 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 labelList& points
369  ) const;
370 
371  //- Given the internal field and a patch field,
372  // set the patch field in the internal field
373  template<class Type1>
374  void setInInternalField
375  (
376  Field<Type1>& iF,
377  const Field<Type1>& pF,
378  const labelList& meshPoints
379  ) const;
380 
381  //- Given the internal field and a patch field,
382  // set the patch field in the internal field
383  template<class Type1>
384  void setInInternalField
385  (
386  Field<Type1>& iF,
387  const Field<Type1>& pF
388  ) const;
389 
390 
391  // Mapping functions
392 
393  //- Map (and resize as needed) from self given a mapping object
394  // Used to update fields following mesh topology change
395  virtual void autoMap(const pointPatchFieldMapper&)
396  {}
397 
398  //- Reverse map the given pointPatchField onto this pointPatchField
399  // Used to reconstruct fields
400  virtual void rmap(const pointPatchField<Type>&, const labelList&)
401  {}
402 
403 
404  // Evaluation functions
405 
406  //- Update the coefficients associated with the patch field
407  // Sets Updated to true
408  virtual void updateCoeffs()
409  {
410  updated_ = true;
411  }
412 
413  //- Initialise evaluation of the patch field (do nothing)
414  virtual void initEvaluate
415  (
416  const Pstream::commsTypes commsType =
418  )
419  {}
420 
421  //- Evaluate the patch field
422  virtual void evaluate
423  (
424  const Pstream::commsTypes commsType =
426  );
427 
428 
429  // I-O
430 
431  //- Write
432  virtual void write(Ostream&) const;
433 
434 
435  // Member Operators
437  virtual void operator=(const pointPatchField<Type>&){}
439  virtual void operator+=(const pointPatchField<Type>&){}
440  virtual void operator-=(const pointPatchField<Type>&){}
441  virtual void operator*=(const pointPatchField<scalar>&){}
442  virtual void operator/=(const pointPatchField<scalar>&){}
444  virtual void operator=(const Field<Type>&){}
445  virtual void operator+=(const Field<Type>&){}
446  virtual void operator-=(const Field<Type>&){}
448  virtual void operator*=(const Field<scalar>&){}
449  virtual void operator/=(const Field<scalar>&){}
451  virtual void operator=(const Type&){}
452  virtual void operator+=(const Type&){}
453  virtual void operator-=(const Type&){}
454  virtual void operator*=(const scalar){}
455  virtual void operator/=(const scalar){}
456 
457 
458  // Force an assignment irrespective of form of patch
459  // By generic these do nothing unless the patch actually has boundary
460  // values
462  virtual void operator==(const pointPatchField<Type>&){}
463  virtual void operator==(const Field<Type>&){}
464  virtual void operator==(const Type&){}
465 
466 
467  // Ostream operator
468 
469  friend Ostream& operator<< <Type>
470  (
471  Ostream&,
472  const pointPatchField<Type>&
473  );
474 };
475 
476 
477 // This function is added as a hack to enable simple backward compatibility
478 // with versions using referenceLevel in GeometicField
479 template<class Type>
480 const pointPatchField<Type>& operator+
481 (
482  const pointPatchField<Type>& ppf,
483  const Type&
484 )
485 {
486  return ppf;
487 }
488 
489 
490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 
492 } // End namespace Foam
493 
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 
497 
498 #ifdef NoRepository
499  #include "pointPatchField.C"
500  #include "calculatedPointPatchField.H"
501 #endif
502 
504 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
505  addToRunTimeSelectionTable \
506  ( \
507  PatchTypeField, \
508  typePatchTypeField, \
509  pointPatch \
510  ); \
511  addToRunTimeSelectionTable \
512  ( \
513  PatchTypeField, \
514  typePatchTypeField, \
515  patchMapper \
516  ); \
517  addToRunTimeSelectionTable \
518  ( \
519  PatchTypeField, \
520  typePatchTypeField, \
521  dictionary \
522  );
523 
524 
525 // for non-templated patch fields
526 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField) \
527  defineTypeNameAndDebug(typePatchTypeField, 0); \
528  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
529 
530 
531 // for templated patch fields
532 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField) \
533  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
534  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
535 
537 #define makePointPatchFields(type) \
538  makeTemplatePointPatchTypeField \
539  ( \
540  pointPatchScalarField, \
541  type##PointPatchScalarField \
542  ); \
543  makeTemplatePointPatchTypeField \
544  ( \
545  pointPatchVectorField, \
546  type##PointPatchVectorField \
547  ); \
548  makeTemplatePointPatchTypeField \
549  ( \
550  pointPatchSphericalTensorField, \
551  type##PointPatchSphericalTensorField \
552  ); \
553  makeTemplatePointPatchTypeField \
554  ( \
555  pointPatchSymmTensorField, \
556  type##PointPatchSymmTensorField \
557  ); \
558  makeTemplatePointPatchTypeField \
559  ( \
560  pointPatchTensorField, \
561  type##PointPatchTensorField \
562 );
563 
565 #define makePointPatchFieldsTypeName(type) \
566  defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0); \
567  defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0); \
568  defineNamedTemplateTypeNameAndDebug \
569  ( \
570  type##PointPatchSphericalTensorField, 0 \
571  ); \
572  defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0); \
573  defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
574 
576 #define makePointPatchFieldTypedefs(type) \
577  typedef type##PointPatchField<scalar> type##PointPatchScalarField; \
578  typedef type##PointPatchField<vector> type##PointPatchVectorField; \
579  typedef type##PointPatchField<sphericalTensor> \
580  type##PointPatchSphericalTensorField; \
581  typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
582  typedef type##PointPatchField<tensor> type##PointPatchTensorField;
583 
584 
585 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 
587 #endif
588 
589 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
dictionary dict
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
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
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.
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
virtual void operator*=(const pointPatchField< scalar > &)
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
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 &)
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:370
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.