faPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 Wikki Ltd
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::faPatchField
29 
30 Description
31  faPatchField<Type> abstract base class. This class gives a fat-interface
32  to all derived classes covering all possible ways in which they might be
33  used. The first level of derivation is to basic patchFields which cover
34  zero-gradient, fixed-gradient, fixed-value and mixed conditions. The next
35  level of derivation covers all the specialised typed with specific
36  evaluation procedures, particularly with respect to specific fields.
37 
38 Author
39  Zeljko Tukovic, FMENA
40  Hrvoje Jasak, Wikki Ltd.
41 
42 SourceFiles
43  faPatchField.C
44  faPatchFieldBase.C
45  faPatchFieldNew.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef Foam_faPatchField_H
50 #define Foam_faPatchField_H
51 
52 #include "faPatch.H"
53 #include "DimensionedField.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class objectRegistry;
62 class dictionary;
63 class faPatchFieldMapper;
64 class areaMesh;
65 
66 template<class Type> class faPatchField;
67 template<class Type> class calculatedFaPatchField;
68 
69 template<class Type>
70 Ostream& operator<<(Ostream&, const faPatchField<Type>&);
71 
72 /*---------------------------------------------------------------------------*\
73  Class faPatchFieldBase Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 //- Template invariant parts for faPatchField
77 class faPatchFieldBase
78 {
79  // Private Data
80 
81  //- Reference to patch
82  const faPatch& patch_;
83 
84  //- Update index used so that updateCoeffs is called only once during
85  //- the construction of the matrix
86  bool updated_;
87 
88  //- Optional patch type
89  // Used to allow specified boundary conditions to be applied
90  // to constraint patches by providing the constraint
91  // patch type as 'patchType'
92  word patchType_;
93 
94 
95 protected:
96 
97  // Protected Member Functions
98 
99  //- Read dictionary entries.
100  // Useful when initially constructed without a dictionary
101  virtual void readDict(const dictionary& dict);
102 
103  //- Set updated state
104  void setUpdated(bool state) noexcept
105  {
106  updated_ = state;
107  }
108 
109 
110 public:
111 
112  //- Debug switch to disallow the use of generic faPatchField
114 
115  //- Runtime type information
116  TypeName("faPatchField");
117 
118 
119  // Constructors
120 
121  //- Construct from patch
122  explicit faPatchFieldBase(const faPatch& p);
123 
124  //- Construct from patch and patch type
125  explicit faPatchFieldBase(const faPatch& p, const word& patchType);
126 
127  //- Construct from patch and dictionary
128  faPatchFieldBase(const faPatch& p, const dictionary& dict);
129 
130  //- Copy construct with new patch
131  faPatchFieldBase(const faPatchFieldBase& rhs, const faPatch& p);
132 
133  //- Copy construct
135 
136 
137  //- Destructor
138  virtual ~faPatchFieldBase() = default;
139 
140 
141  // Member Functions
142 
143  // Access
144 
145  //- The associated objectRegistry
147 
148  //- Return the patch
149  const faPatch& patch() const noexcept
150  {
151  return patch_;
152  }
153 
154  //- The optional patch type
155  const word& patchType() const noexcept
156  {
157  return patchType_;
158  }
159 
160  //- The optional patch type
161  word& patchType() noexcept
162  {
163  return patchType_;
164  }
165 
166 
167  // Solution
168 
169  //- True if the boundary condition has already been updated
170  bool updated() const noexcept
171  {
172  return updated_;
173  }
174 
175 
176  // Check
177 
178  //- Check that patches are identical
179  void checkPatch(const faPatchFieldBase& rhs) const;
180 };
181 
182 
183 /*---------------------------------------------------------------------------*\
184  Class faPatchField Declaration
185 \*---------------------------------------------------------------------------*/
186 
187 template<class Type>
188 class faPatchField
189 :
190  public faPatchFieldBase,
191  public Field<Type>
192 {
193  // Private Data
194 
195  //- Reference to internal field
196  const DimensionedField<Type, areaMesh>& internalField_;
197 
198 
199 public:
200 
201  //- The internal field type associated with the patch field
203 
204  //- The patch type for the patch field
205  typedef faPatch Patch;
207  //- Type for a \em calculated patch
209 
210 
211  // Declare run-time constructor selection tables
212 
214  (
215  tmp,
216  faPatchField,
217  patch,
218  (
219  const faPatch& p,
221  ),
222  (p, iF)
223  );
224 
226  (
227  tmp,
228  faPatchField,
229  patchMapper,
230  (
231  const faPatchField<Type>& ptf,
232  const faPatch& p,
234  const faPatchFieldMapper& m
235  ),
236  (dynamic_cast<const faPatchFieldType&>(ptf), p, iF, m)
237  );
238 
240  (
241  tmp,
242  faPatchField,
243  dictionary,
244  (
245  const faPatch& p,
247  const dictionary& dict
248  ),
249  (p, iF, dict)
250  );
251 
252 
253  // Constructors
255  //- Construct from patch and internal field
257  (
258  const faPatch&,
260  );
261 
262  //- Construct from patch and internal field and patch field
264  (
265  const faPatch&,
267  const Field<Type>&
268  );
269 
270  //- Construct from patch, internal field and dictionary
272  (
273  const faPatch&,
275  const dictionary&,
276  const bool valueRequired=true
277  );
278 
279  //- Construct by mapping the given faPatchField onto a new patch
281  (
282  const faPatchField<Type>&,
283  const faPatch&,
285  const faPatchFieldMapper&
286  );
287 
288  //- Construct as copy
290 
291  //- Construct as copy setting internal field reference
293  (
294  const faPatchField<Type>&,
296  );
297 
298  //- Construct and return a clone
299  virtual tmp<faPatchField<Type>> clone() const
300  {
301  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this));
302  }
303 
304  //- Construct and return a clone setting internal field reference
306  (
308  ) const
309  {
310  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this, iF));
311  }
312 
313 
314  // Selectors
315 
316  //- Return a pointer to a new patchField created on freestore given
317  //- patch and internal field
318  // (does not set the patch field values)
319  static tmp<faPatchField<Type>> New
320  (
321  const word& patchFieldType,
322  const word& actualPatchType,
323  const faPatch&,
324  const DimensionedField<Type, areaMesh>&
325  );
326 
327  //- Return a pointer to a new patchField created on freestore given
328  //- patch and internal field
329  // (does not set the patch field values)
330  static tmp<faPatchField<Type>> New
331  (
332  const word& patchFieldType,
333  const faPatch&,
334  const DimensionedField<Type, areaMesh>&
335  );
336 
337  //- Return a pointer to a new patchField created on freestore from
338  //- a given faPatchField mapped onto a new patch
339  static tmp<faPatchField<Type>> New
340  (
341  const faPatchField<Type>&,
342  const faPatch&,
343  const DimensionedField<Type, areaMesh>&,
344  const faPatchFieldMapper&
345  );
346 
347  //- Return a pointer to a new patchField created on freestore
348  //- from dictionary
349  static tmp<faPatchField<Type>> New
350  (
351  const faPatch&,
352  const DimensionedField<Type, areaMesh>&,
353  const dictionary&
354  );
355 
356  //- Return a pointer to a new calculatedFaPatchField created on
357  //- freestore without setting patchField values
358  template<class Type2>
360  (
361  const faPatchField<Type2>&
362  );
363 
364 
365  //- Destructor
366  virtual ~faPatchField() = default;
367 
369  // Member Functions
370 
371  //- The type name for calculated patch fields
372  static const word& calculatedType();
373 
374  //- The type name for zeroGradient patch fields
375  static const word& zeroGradientType();
376 
377 
378  // Attributes
379 
380  //- True if this patch field fixes a value.
381  // Needed to check if a level has to be specified while solving
382  // Poissons equations.
383  virtual bool fixesValue() const
384  {
385  return false;
386  }
387 
388  //- True if this patch field is coupled
389  virtual bool coupled() const
390  {
391  return false;
392  }
393 
394 
395  // Access
396 
397  //- Return local objectRegistry
398  const objectRegistry& db() const;
399 
400  //- Return dimensioned internal field reference
401  const DimensionedField<Type, areaMesh>&
402  internalField() const noexcept
403  {
404  return internalField_;
405  }
406 
407  //- Return internal field reference
408  const Field<Type>& primitiveField() const noexcept
409  {
410  return internalField_;
411  }
412 
413 
414  // Mapping
415 
416  //- Map (and resize as needed) from self given a mapping object
417  virtual void autoMap
418  (
419  const faPatchFieldMapper&
420  );
421 
422  //- Reverse map the given faPatchField onto this faPatchField
423  virtual void rmap
424  (
425  const faPatchField<Type>&,
426  const labelList&
427  );
428 
429 
430  // Evaluation
431 
432  //- Return patch-normal gradient
433  virtual tmp<Field<Type>> snGrad() const;
434 
435  //- Return internal field next to patch as patch field
436  virtual tmp<Field<Type>> patchInternalField() const;
437 
438  //- Return patchField on the opposite patch of a coupled patch
439  virtual tmp<Field<Type>> patchNeighbourField() const
440  {
442  return *this;
443  }
444 
445  //- Update the coefficients associated with the patch field
446  // Sets Updated to true
447  virtual void updateCoeffs();
448 
449  //- Initialise the evaluation of the patch field
450  virtual void initEvaluate
451  (
452  const Pstream::commsTypes commsType =
454  )
455  {}
456 
457  //- Evaluate the patch field, sets Updated to false
458  virtual void evaluate
459  (
460  const Pstream::commsTypes commsType =
462  );
463 
464  //- Return the matrix diagonal coefficients corresponding to the
465  //- evaluation of the value of this patchField with given weights
467  (
468  const tmp<Field<scalar>>&
469  ) const
470  {
472  return *this;
473  }
475  //- Return the matrix source coefficients corresponding to the
476  //- evaluation of the value of this patchField with given weights
478  (
479  const tmp<Field<scalar>>&
480  ) const
481  {
483  return *this;
484  }
485 
486  //- Return the matrix diagonal coefficients corresponding to the
487  //- evaluation of the gradient of this patchField
488  virtual tmp<Field<Type>> gradientInternalCoeffs() const
489  {
491  return *this;
492  }
493 
494  //- Return the matrix source coefficients corresponding to the
495  //- evaluation of the gradient of this patchField
496  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
497  {
499  return *this;
500  }
501 
502 
503  // IO
504 
505  //- Write
506  virtual void write(Ostream&) const;
507 
508 
509  // Check
510 
511  //- Check faPatchField<Type> against given faPatchField<Type>
512  void check(const faPatchField<Type>&) const;
513 
514 
515  // Member Operators
516 
517  virtual void operator=(const UList<Type>&);
518 
519  virtual void operator=(const faPatchField<Type>&);
520  virtual void operator+=(const faPatchField<Type>&);
521  virtual void operator-=(const faPatchField<Type>&);
522  virtual void operator*=(const faPatchField<scalar>&);
523  virtual void operator/=(const faPatchField<scalar>&);
524 
525  virtual void operator+=(const Field<Type>&);
526  virtual void operator-=(const Field<Type>&);
527 
528  virtual void operator*=(const Field<scalar>&);
529  virtual void operator/=(const Field<scalar>&);
530 
531  virtual void operator=(const Type&);
532  virtual void operator+=(const Type&);
533  virtual void operator-=(const Type&);
534  virtual void operator*=(const scalar);
535  virtual void operator/=(const scalar);
536 
537 
538  // Force an assignment irrespective of form of patch
539 
540  virtual void operator==(const faPatchField<Type>&);
541  virtual void operator==(const Field<Type>&);
542  virtual void operator==(const Type&);
543 
544 
545  // Ostream Operator
546 
547  friend Ostream& operator<< <Type>(Ostream&, const faPatchField<Type>&);
548 };
549 
550 
551 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
552 
553 } // End namespace Foam
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 #ifdef NoRepository
558  #include "faPatchField.C"
559  #include "calculatedFaPatchField.H"
560  #include "zeroGradientFaPatchField.H"
561 #endif
562 
563 
564 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
565 // Runtime selection macros
566 
567 #define addToFaPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
568  \
569 addToRunTimeSelectionTable \
570 ( \
571  PatchTypeField, typePatchTypeField, patch \
572 ); \
573  \
574 addToRunTimeSelectionTable \
575 ( \
576  PatchTypeField, \
577  typePatchTypeField, \
578  patchMapper \
579 ); \
580  \
581 addToRunTimeSelectionTable \
582 ( \
583  PatchTypeField, typePatchTypeField, dictionary \
584 );
585 
586 
587 #define makeFaPatchTypeFieldTypeName(typePatchTypeField) \
588  \
589 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);
591 
592 #define makeFaPatchFieldsTypeName(typePatchField) \
593  \
594 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchScalarField); \
595 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchVectorField); \
596 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchSphericalTensorField); \
597 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchSymmTensorField); \
598 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchTensorField);
599 
600 
601 #define makeFaPatchTypeField(PatchTypeField, typePatchTypeField) \
602  \
603 defineTypeNameAndDebug(typePatchTypeField, 0); \
604  \
605 addToFaPatchFieldRunTimeSelection \
606 ( \
607  PatchTypeField, typePatchTypeField \
608 );
609 
610 #define makeTemplateFaPatchTypeField(PatchTypeField, typePatchTypeField) \
611  \
612 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
613  \
614 addToFaPatchFieldRunTimeSelection \
615 ( \
616  PatchTypeField, typePatchTypeField \
617 );
618 
619 
620 #define makeFaPatchFields(type) \
621  \
622 makeTemplateFaPatchTypeField(faPatchScalarField, type##FaPatchScalarField); \
623 makeTemplateFaPatchTypeField(faPatchVectorField, type##FaPatchVectorField); \
624 makeTemplateFaPatchTypeField \
625 ( \
626  faPatchSphericalTensorField, \
627  type##FaPatchSphericalTensorField \
628 ); \
629 makeTemplateFaPatchTypeField \
630 ( \
631  faPatchSymmTensorField, \
632  type##FaPatchSymmTensorField \
633 ); \
634 makeTemplateFaPatchTypeField \
635 ( \
636  faPatchTensorField, \
637  type##FaPatchTensorField \
638 );
639 
640 
641 #define makeFaPatchTypeFieldTypedefs(type) \
642  \
643 typedef type##FaPatchField<scalar> type##FaPatchScalarField; \
644 typedef type##FaPatchField<vector> type##FaPatchVectorField; \
645 typedef type##FaPatchField<sphericalTensor> \
646  type##FaPatchSphericalTensorField; \
647 typedef type##FaPatchField<symmTensor> type##FaPatchSymmTensorField; \
648 typedef type##FaPatchField<tensor> type##FaPatchTensorField;
649 
650 
651 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
652 
653 #endif
654 
655 // ************************************************************************* //
virtual void operator+=(const faPatchField< Type > &)
Definition: faPatchField.C:228
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: faPatchField.C:155
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Return a pointer to a new patchField created on freestore given patch and internal field...
dictionary dict
faPatchFieldBase(const faPatch &p)
Construct from patch.
TypeName("faPatchField")
Runtime type information.
virtual void operator-=(const faPatchField< Type > &)
Definition: faPatchField.C:239
"blocking" : (MPI_Bsend, MPI_Recv)
const faPatch & patch() const noexcept
The associated objectRegistry.
Definition: faPatchField.H:179
virtual bool fixesValue() const
True if this patch field fixes a value.
Definition: faPatchField.H:466
void check(const faPatchField< Type > &) const
Check faPatchField<Type> against given faPatchField<Type>
Definition: faPatchField.C:133
commsTypes
Types of communications.
Definition: UPstream.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: faPatchField.C:140
virtual tmp< faPatchField< Type > > clone() const
Construct and return a clone.
Definition: faPatchField.H:359
virtual void readDict(const dictionary &dict)
Read dictionary entries.
declareRunTimeSelectionTable(tmp, faPatchField, patch,(const faPatch &p, const DimensionedField< Type, areaMesh > &iF),(p, iF))
const DimensionedField< Type, areaMesh > & internalField() const noexcept
Return dimensioned internal field reference.
Definition: faPatchField.H:491
Template invariant parts for faPatchField.
Definition: faPatchField.H:74
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the evaluation of the value of this patchField...
Definition: faPatchField.H:590
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: faPatchField.H:557
static const word & calculatedType()
The type name for calculated patch fields.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
faPatch Patch
The patch type for the patch field.
Definition: faPatchField.H:249
virtual ~faPatchField()=default
Destructor.
virtual void write(Ostream &) const
Write.
Definition: faPatchField.C:192
void setUpdated(bool state) noexcept
Set updated state.
Definition: faPatchField.H:113
virtual void operator/=(const faPatchField< scalar > &)
Definition: faPatchField.C:261
Generic templated field type.
Definition: Field.H:61
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
Definition: faPatchField.H:540
DimensionedField< Type, areaMesh > Internal
The internal field type associated with the patch field.
Definition: faPatchField.H:244
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
Definition: faPatchField.H:602
const Field< Type > & primitiveField() const noexcept
Return internal field reference.
Definition: faPatchField.H:499
const word & patchType() const noexcept
The optional patch type.
Definition: faPatchField.H:187
virtual bool coupled() const
True if this patch field is coupled.
Definition: faPatchField.H:474
bool updated() const noexcept
True if the boundary condition has already been updated.
Definition: faPatchField.H:206
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the evaluation of the value of this patchFie...
Definition: faPatchField.H:577
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
static int disallowGenericPatchField
Debug switch to disallow the use of generic faPatchField.
Definition: faPatchField.H:124
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: faPatchField.C:148
void checkPatch(const faPatchFieldBase &rhs) const
Check that patches are identical.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
Definition: faPatchField.C:163
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: faPatchField.C:180
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the evaluation of the gradient of this patchFi...
Definition: faPatchField.H:612
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: faPatchField.C:173
virtual void operator=(const UList< Type > &)
Definition: faPatchField.C:207
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual void operator==(const faPatchField< Type > &)
Definition: faPatchField.C:362
static tmp< faPatchField< Type > > NewCalculatedType(const faPatchField< Type2 > &)
Return a pointer to a new calculatedFaPatchField created on freestore without setting patchField valu...
const objectRegistry & db() const
Return local objectRegistry.
Definition: faPatchField.C:125
virtual ~faPatchFieldBase()=default
Destructor.
static const word & zeroGradientType()
The type name for zeroGradient patch fields.
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A FieldMapper for finite-area patch fields.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:666
calculatedFaPatchField< Type > Calculated
Type for a calculated patch.
Definition: faPatchField.H:254
Namespace for OpenFOAM.
faPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
Definition: faPatchField.C:29
virtual void operator*=(const faPatchField< scalar > &)
Definition: faPatchField.C:250