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-2018 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  //- Optional patch type, used to allow specified boundary conditions
97  // to be applied to constraint patches by providing the constraint
98  // patch type as 'patchType'
99  word patchType_;
100 
101 
102 public:
104  typedef pointPatch Patch;
106 
107 
108  //- Runtime type information
109  TypeName("pointPatchField");
110 
111  //- Debug switch to disallow the use of genericPointPatchField
113 
114 
115  // Declare run-time constructor selection tables
116 
118  (
119  autoPtr,
121  pointPatch,
122  (
123  const pointPatch& p,
125  ),
126  (p, iF)
127  );
128 
130  (
131  autoPtr,
133  patchMapper,
134  (
135  const pointPatchField<Type>& ptf,
136  const pointPatch& p,
138  const pointPatchFieldMapper& m
139  ),
140  (dynamic_cast<const pointPatchFieldType&>(ptf), p, iF, m)
141  );
142 
144  (
145  autoPtr,
147  dictionary,
148  (
149  const pointPatch& p,
151  const dictionary& dict
152  ),
153  (p, iF, dict)
154  );
155 
156 
157  // Constructors
158 
159  //- Construct from patch and internal field
161  (
162  const pointPatch&,
164  );
165 
166  //- Construct from patch, internal field and dictionary
168  (
169  const pointPatch&,
171  const dictionary&
172  );
173 
174  //- Construct by mapping given patchField<Type> onto a new patch
176  (
177  const pointPatchField<Type>&,
178  const pointPatch&,
180  const pointPatchFieldMapper&
181  );
182 
183  //- Construct as copy
185 
186  //- Construct and return a clone
187  virtual autoPtr<pointPatchField<Type>> clone() const = 0;
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  // Access
264 
265  //- Return local objectRegistry
266  const objectRegistry& db() const;
267 
268  //- Return size
269  label size() const
270  {
271  return patch().size();
272  }
273 
274  //- Return patch
275  const pointPatch& patch() const
276  {
277  return patch_;
278  }
279 
280  //- Return dimensioned internal field reference
282  internalField() const
283  {
284  return internalField_;
285  }
286 
287  //- Return internal field reference
288  const Field<Type>& primitiveField() const
289  {
290  return internalField_;
291  }
292 
293  //- Optional patch type
294  const word& patchType() const
295  {
296  return patchType_;
297  }
298 
299  //- Optional patch type
300  word& patchType()
301  {
302  return patchType_;
303  }
304 
305  //- Return true if this patch field fixes a value
306  virtual bool fixesValue() const
307  {
308  return false;
309  }
310 
311  //- Return true if this patch field is coupled
312  virtual bool coupled() const
313  {
314  return false;
315  }
316 
317  //- Return true if the boundary condition has already been updated
318  bool updated() const
319  {
320  return updated_;
321  }
322 
323  //- Return field created from appropriate internal field values
325 
326  //- Return field created from appropriate internal field values
327  // given internal field reference
328  template<class Type1>
330  (
331  const Field<Type1>& iF
332  ) const;
333 
334  //- Return field created from selected internal field values
335  // given internal field reference
336  template<class Type1>
338  (
339  const Field<Type1>& iF,
340  const labelList& meshPoints
341  ) const;
342 
343  //- Given the internal field and a patch field,
344  // add the patch field to the internal field
345  template<class Type1>
346  void addToInternalField
347  (
348  Field<Type1>& iF,
349  const Field<Type1>& pF
350  ) const;
351 
352  //- Given the internal field and a patch field,
353  // add selected elements of 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 labelList& points
360  ) const;
361 
362  //- Given the internal field and a patch field,
363  // set the patch field in the internal field
364  template<class Type1>
365  void setInInternalField
366  (
367  Field<Type1>& iF,
368  const Field<Type1>& pF,
369  const labelList& meshPoints
370  ) const;
371 
372  //- Given the internal field and a patch field,
373  // set the patch field in the internal field
374  template<class Type1>
375  void setInInternalField
376  (
377  Field<Type1>& iF,
378  const Field<Type1>& pF
379  ) const;
380 
381  //- Return the type of the calculated form of pointPatchField
382  static const word& calculatedType();
383 
384  //- Return the constraint type this pointPatchField implements.
385  virtual const word& constraintType() const
386  {
387  return word::null;
388  }
389 
390 
391  // Mapping functions
392 
393  //- Map (and resize as needed) from self given a mapping object
394  virtual void autoMap
395  (
396  const pointPatchFieldMapper&
397  )
398  {}
399 
400  //- Reverse map the given pointPatchField onto this pointPatchField
401  virtual void rmap
402  (
403  const pointPatchField<Type>&,
404  const labelList&
405  )
406  {}
407 
408 
409  // Evaluation functions
410 
411  //- Update the coefficients associated with the patch field
412  // Sets Updated to true
413  virtual void updateCoeffs()
414  {
415  updated_ = true;
416  }
417 
418  //- Initialise evaluation of the patch field (do nothing)
419  virtual void initEvaluate
420  (
421  const Pstream::commsTypes commsType =
423  )
424  {}
425 
426  //- Evaluate the patch field
427  virtual void evaluate
428  (
429  const Pstream::commsTypes commsType =
431  );
432 
433 
434  // I-O
435 
436  //- Write
437  virtual void write(Ostream&) const;
438 
439  //- Helper function to write the keyword and entry only if the
440  // values are not equal. The value is then output as value2
441  template<class EntryType>
443  (
444  Ostream& os,
445  const word& entryName,
446  const EntryType& value1,
447  const EntryType& value2
448  ) const;
449 
450 
451  // Member operators
453  virtual void operator=(const pointPatchField<Type>&){}
454  virtual void operator+=(const pointPatchField<Type>&){}
455  virtual void operator-=(const pointPatchField<Type>&){}
456  virtual void operator*=(const pointPatchField<scalar>&){}
457  virtual void operator/=(const pointPatchField<scalar>&){}
459  virtual void operator=(const Field<Type>&){}
460  virtual void operator+=(const Field<Type>&){}
461  virtual void operator-=(const Field<Type>&){}
463  virtual void operator*=(const Field<scalar>&){}
464  virtual void operator/=(const Field<scalar>&){}
466  virtual void operator=(const Type&){}
467  virtual void operator+=(const Type&){}
468  virtual void operator-=(const Type&){}
469  virtual void operator*=(const scalar){}
470  virtual void operator/=(const scalar){}
471 
472 
473  // Force an assignment irrespective of form of patch
474  // By generic these do nothing unless the patch actually has boundary
475  // values
477  virtual void operator==(const pointPatchField<Type>&){}
478  virtual void operator==(const Field<Type>&){}
479  virtual void operator==(const Type&){}
480 
481 
482  // Ostream operator
483 
484  friend Ostream& operator<< <Type>
485  (
486  Ostream&,
487  const pointPatchField<Type>&
488  );
489 };
490 
491 
492 // This function is added as a hack to enable simple backward compatibility
493 // with versions using referenceLevel in GeometicField
494 template<class Type>
495 const pointPatchField<Type>& operator+
496 (
497  const pointPatchField<Type>& ppf,
498  const Type&
499 )
500 {
501  return ppf;
502 }
503 
504 
505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
506 
507 } // End namespace Foam
508 
509 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
510 
512 
513 #ifdef NoRepository
514  #include "pointPatchField.C"
515  #include "calculatedPointPatchField.H"
516 #endif
517 
519 #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
520  addToRunTimeSelectionTable \
521  ( \
522  PatchTypeField, \
523  typePatchTypeField, \
524  pointPatch \
525  ); \
526  addToRunTimeSelectionTable \
527  ( \
528  PatchTypeField, \
529  typePatchTypeField, \
530  patchMapper \
531  ); \
532  addToRunTimeSelectionTable \
533  ( \
534  PatchTypeField, \
535  typePatchTypeField, \
536  dictionary \
537  );
538 
539 
540 // for non-templated patch fields
541 #define makePointPatchTypeField(PatchTypeField,typePatchTypeField) \
542  defineTypeNameAndDebug(typePatchTypeField, 0); \
543  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
544 
545 
546 // for templated patch fields
547 #define makeTemplatePointPatchTypeField(PatchTypeField, typePatchTypeField) \
548  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
549  addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
550 
552 #define makePointPatchFields(type) \
553  makeTemplatePointPatchTypeField \
554  ( \
555  pointPatchScalarField, \
556  type##PointPatchScalarField \
557  ); \
558  makeTemplatePointPatchTypeField \
559  ( \
560  pointPatchVectorField, \
561  type##PointPatchVectorField \
562  ); \
563  makeTemplatePointPatchTypeField \
564  ( \
565  pointPatchSphericalTensorField, \
566  type##PointPatchSphericalTensorField \
567  ); \
568  makeTemplatePointPatchTypeField \
569  ( \
570  pointPatchSymmTensorField, \
571  type##PointPatchSymmTensorField \
572  ); \
573  makeTemplatePointPatchTypeField \
574  ( \
575  pointPatchTensorField, \
576  type##PointPatchTensorField \
577 );
578 
580 #define makePointPatchFieldsTypeName(type) \
581  defineNamedTemplateTypeNameAndDebug(type##PointPatchScalarField, 0); \
582  defineNamedTemplateTypeNameAndDebug(type##PointPatchVectorField, 0); \
583  defineNamedTemplateTypeNameAndDebug \
584  ( \
585  type##PointPatchSphericalTensorField, 0 \
586  ); \
587  defineNamedTemplateTypeNameAndDebug(type##PointPatchSymmTensorField, 0); \
588  defineNamedTemplateTypeNameAndDebug(type##PointPatchTensorField, 0)
589 
591 #define makePointPatchFieldTypedefs(type) \
592  typedef type##PointPatchField<scalar> type##PointPatchScalarField; \
593  typedef type##PointPatchField<vector> type##PointPatchVectorField; \
594  typedef type##PointPatchField<sphericalTensor> \
595  type##PointPatchSphericalTensorField; \
596  typedef type##PointPatchField<symmTensor> type##PointPatchSymmTensorField;\
597  typedef type##PointPatchField<tensor> type##PointPatchTensorField;
598 
599 
600 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
601 
602 #endif
603 
604 // ************************************************************************* //
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
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
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2) const
Helper function to write the keyword and entry only if the.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
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:137
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.
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.
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
const pointPatch & patch() const
Return patch.
static const word null
An empty word.
Definition: word.H:77
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
virtual autoPtr< pointPatchField< Type > > clone() const =0
Construct and return a clone.
virtual const word & constraintType() const
Return the constraint type this pointPatchField implements.
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))
const word & patchType() const
Optional patch type.
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,.
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.
Namespace for OpenFOAM.
virtual label size() const =0
Return size.
virtual bool fixesValue() const
Return true if this patch field fixes a value.