fvPatchField.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::fvPatchField
26 
27 Description
28  Abstract base class with a fat-interface to all derived classes
29  covering all possible ways in which they might be used.
30 
31  The first level of derivation is to basic patchFields which cover
32  zero-gradient, fixed-gradient, fixed-value and mixed conditions.
33 
34  The next level of derivation covers all the specialised types with
35  specific evaluation procedures, particularly with respect to specific
36  fields.
37 
38 SourceFiles
39  fvPatchField.C
40  fvPatchFieldNew.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef fvPatchField_H
45 #define fvPatchField_H
46 
47 #include "fvPatch.H"
48 #include "DimensionedField.H"
49 #include "fieldTypes.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 
58 class objectRegistry;
59 class dictionary;
60 class fvPatchFieldMapper;
61 class volMesh;
62 
63 
64 // Forward declaration of friend functions and operators
65 
66 template<class Type>
67 class fvPatchField;
68 
69 template<class Type>
71 
72 template<class Type>
73 class fvMatrix;
74 
75 template<class Type>
76 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
77 
78 
79 /*---------------------------------------------------------------------------*\
80  Class fvPatchField Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 template<class Type>
84 class fvPatchField
85 :
86  public Field<Type>
87 {
88  // Private Data
89 
90  //- Reference to patch
91  const fvPatch& patch_;
92 
93  //- Reference to internal field
94  const DimensionedField<Type, volMesh>& internalField_;
95 
96  //- Update index used so that updateCoeffs is called only once during
97  // the construction of the matrix
98  bool updated_;
99 
100  //- Update index used so that manipulateMatrix is called only once
101  // during the construction of the matrix
102  bool manipulatedMatrix_;
103 
104 
105 public:
107  typedef fvPatch Patch;
109 
110 
111  //- Runtime type information
112  TypeName("fvPatchField");
113 
114  //- Debug switch to disallow the use of genericFvPatchField
115  static int disallowGenericFvPatchField;
116 
117 
118  // Declare run-time constructor selection tables
119 
121  (
122  tmp,
123  fvPatchField,
124  patch,
125  (
126  const fvPatch& p,
128  ),
129  (p, iF)
130  );
131 
133  (
134  tmp,
135  fvPatchField,
136  patchMapper,
137  (
138  const fvPatchField<Type>& ptf,
139  const fvPatch& p,
141  const fvPatchFieldMapper& m
142  ),
143  (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
144  );
145 
147  (
148  tmp,
149  fvPatchField,
150  dictionary,
151  (
152  const fvPatch& p,
154  const dictionary& dict
155  ),
156  (p, iF, dict)
157  );
158 
159 
160  // Constructors
161 
162  //- Construct from patch and internal field
164  (
165  const fvPatch&,
167  );
168 
169  //- Construct from patch and internal field and patch field
171  (
172  const fvPatch&,
174  const Field<Type>&
175  );
176 
177  //- Construct from patch, internal field and dictionary
179  (
180  const fvPatch&,
182  const dictionary&,
183  const bool valueRequired=true
184  );
185 
186  //- Construct by mapping the given fvPatchField onto a new patch
188  (
189  const fvPatchField<Type>&,
190  const fvPatch&,
192  const fvPatchFieldMapper&,
193  const bool mappingRequired=true
194  );
195 
196  //- Disallow copy without setting internal field reference
197  fvPatchField(const fvPatchField<Type>&) = delete;
198 
199  //- Disallow clone without setting internal field reference
201  {
203  return tmp<fvPatchField<Type>>(nullptr);
204  }
205 
206  //- Copy constructor setting internal field reference
208  (
209  const fvPatchField<Type>&,
211  );
212 
213  //- Construct and return a clone setting internal field reference
215  (
217  ) const
218  {
219  return tmp<fvPatchField<Type>>(new fvPatchField<Type>(*this, iF));
220  }
221 
222 
223  // Selectors
224 
225  //- Return a pointer to a new patchField created on freestore given
226  // patch and internal field
227  // (does not set the patch field values)
229  (
230  const word&,
231  const fvPatch&,
233  );
234 
235  //- Return a pointer to a new patchField created on freestore given
236  // patch and internal field
237  // (does not set the patch field values).
238  // Allows override of constraint type
240  (
241  const word&,
242  const word& actualPatchType,
243  const fvPatch&,
245  );
246 
247  //- Return a pointer to a new patchField created on freestore from
248  // a given fvPatchField mapped onto a new patch
250  (
251  const fvPatchField<Type>&,
252  const fvPatch&,
254  const fvPatchFieldMapper&
255  );
256 
257  //- Return a pointer to a new patchField created on freestore
258  // from dictionary
260  (
261  const fvPatch&,
263  const dictionary&
264  );
265 
266  //- Return a pointer to a new calculatedFvPatchField created on
267  // freestore without setting patchField values
269  (
270  const fvPatch&
271  );
272 
273  //- Return a pointer to a new calculatedFvPatchField created on
274  // freestore without setting patchField values
275  template<class Type2>
277  (
278  const fvPatchField<Type2>&
279  );
280 
281 
282  //- Destructor
283  virtual ~fvPatchField<Type>()
284  {}
285 
286 
287  // Member Functions
288 
289  // Attributes
290 
291  //- Return the type of the calculated for of fvPatchField
292  static const word& calculatedType();
293 
294  //- Return true if this patch field fixes a value.
295  // Needed to check if a level has to be specified while solving
296  // Poissons equations.
297  virtual bool fixesValue() const
298  {
299  return false;
300  }
301 
302  //- Return true if the value of the patch field
303  // is altered by assignment (the default)
304  virtual bool assignable() const
305  {
306  return true;
307  }
308 
309  //- Return true if this patch field is coupled
310  virtual bool coupled() const
311  {
312  return false;
313  }
314 
315  //- Return true if this overrides the underlying constraint type
316  bool overridesConstraint() const
317  {
318  if (type() == patch_.type())
319  {
320  return false;
321  }
322 
323  typename patchConstructorTable::iterator patchTypeCstrIter
324  = patchConstructorTablePtr_->find(patch_.type());
325 
326  return
327  patchTypeCstrIter
328  != patchConstructorTablePtr_->end();
329  }
330 
331 
332  // Access
333 
334  //- Return local objectRegistry
335  const objectRegistry& db() const;
336 
337  //- Return patch
338  const fvPatch& patch() const
339  {
340  return patch_;
341  }
342 
343  //- Return dimensioned internal field reference
345  {
346  return internalField_;
347  }
348 
349  //- Return internal field reference
350  const Field<Type>& primitiveField() const
351  {
352  return internalField_;
353  }
354 
355  //- Return true if the boundary condition has already been updated
356  bool updated() const
357  {
358  return updated_;
359  }
360 
361  //- Return true if the matrix has already been manipulated
362  bool manipulatedMatrix() const
363  {
364  return manipulatedMatrix_;
365  }
366 
367 
368  // Mapping functions
369 
370  //- Map (and resize as needed) from self given a mapping object
371  // Used to update fields following mesh topology change
372  virtual void autoMap(const fvPatchFieldMapper&);
373 
374  //- Reverse map the given fvPatchField onto this fvPatchField
375  // Used to reconstruct fields
376  virtual void rmap(const fvPatchField<Type>&, const labelList&);
377 
378 
379  // Evaluation functions
380 
381  //- Return patch-normal gradient
382  virtual tmp<Field<Type>> snGrad() const;
383 
384  //- Return patch-normal gradient for coupled-patches
385  // using the deltaCoeffs provided
387  (
388  const scalarField& deltaCoeffs
389  ) const
390  {
392  return *this;
393  }
394 
395  //- Update the coefficients associated with the patch field
396  // Sets Updated to true
397  virtual void updateCoeffs();
398 
399  //- Update the coefficients associated with the patch field
400  // with a weight field (0..1). This weight field is usually
401  // provided as the amount of geometric overlap for 'duplicate'
402  // patches. Sets Updated to true
403  virtual void updateWeightedCoeffs(const scalarField& weights);
404 
405  //- Return internal field next to patch as patch field
406  virtual tmp<Field<Type>> patchInternalField() const;
407 
408  //- Return internal field next to patch as patch field
409  virtual void patchInternalField(Field<Type>&) const;
410 
411  //- Return patchField on the opposite patch of a coupled patch
412  virtual tmp<Field<Type>> patchNeighbourField() const
413  {
415  return *this;
416  }
417 
418  //- Initialise the evaluation of the patch field
419  virtual void initEvaluate
420  (
421  const Pstream::commsTypes commsType =
423  )
424  {}
425 
426  //- Evaluate the patch field, sets Updated to false
427  virtual void evaluate
428  (
429  const Pstream::commsTypes commsType =
431  );
432 
433 
434  //- Return the matrix diagonal coefficients corresponding to the
435  // evaluation of the value of this patchField with given weights
437  (
438  const tmp<Field<scalar>>&
439  ) const
440  {
442  return *this;
443  }
444 
445  //- Return the matrix source coefficients corresponding to the
446  // evaluation of the value of this patchField with given weights
448  (
449  const tmp<Field<scalar>>&
450  ) const
451  {
453  return *this;
454  }
455 
456  //- Return the matrix diagonal coefficients corresponding to the
457  // evaluation of the gradient of this patchField
458  virtual tmp<Field<Type>> gradientInternalCoeffs() const
459  {
461  return *this;
462  }
463 
464  //- Return the matrix diagonal coefficients corresponding to the
465  // evaluation of the gradient of this coupled patchField
466  // using the deltaCoeffs provided
468  (
469  const scalarField& deltaCoeffs
470  ) const
471  {
473  return *this;
474  }
475 
476  //- Return the matrix source coefficients corresponding to the
477  // evaluation of the gradient of this patchField
478  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
479  {
481  return *this;
482  }
483 
484  //- Return the matrix source coefficients corresponding to the
485  // evaluation of the gradient of this coupled patchField
486  // using the deltaCoeffs provided
488  (
489  const scalarField& deltaCoeffs
490  ) const
491  {
493  return *this;
494  }
495 
496 
497  //- Manipulate matrix
498  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
499 
500  //- Manipulate matrix with given weights
501  virtual void manipulateMatrix
502  (
503  fvMatrix<Type>& matrix,
504  const scalarField& weights
505  );
506 
507 
508  // I-O
509 
510  //- Write
511  virtual void write(Ostream&) const;
512 
513 
514  // Check
515 
516  //- Check fvPatchField<Type> against given fvPatchField<Type>
517  void check(const fvPatchField<Type>&) const;
518 
519 
520  // Member Operators
521 
522  virtual void operator=(const UList<Type>&);
523 
524  virtual void operator=(const fvPatchField<Type>&);
525  virtual void operator+=(const fvPatchField<Type>&);
526  virtual void operator-=(const fvPatchField<Type>&);
527  virtual void operator*=(const fvPatchField<scalar>&);
528  virtual void operator/=(const fvPatchField<scalar>&);
529 
530  virtual void operator+=(const Field<Type>&);
531  virtual void operator-=(const Field<Type>&);
532 
533  virtual void operator*=(const Field<scalar>&);
534  virtual void operator/=(const Field<scalar>&);
535 
536  virtual void operator=(const Type&);
537  virtual void operator+=(const Type&);
538  virtual void operator-=(const Type&);
539  virtual void operator*=(const scalar);
540  virtual void operator/=(const scalar);
541 
542 
543  // Force an assignment irrespective of form of patch
544 
545  virtual void operator==(const fvPatchField<Type>&);
546  virtual void operator==(const Field<Type>&);
547  virtual void operator==(const Type&);
548 
549 
550  // Ostream operator
551 
552  friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
553 };
554 
555 
556 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
557 
558 } // End namespace Foam
559 
560 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
561 
562 #ifdef NoRepository
563  #include "fvPatchField.C"
564  #include "calculatedFvPatchField.H"
565 #endif
566 
568 #define makeFvPatchField(fvPatchTypeField) \
569  \
570 defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \
571 template<> \
572 int fvPatchTypeField::disallowGenericFvPatchField \
573 ( \
574  debug::debugSwitch("disallowGenericFvPatchField", 0) \
575 ); \
576 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \
577 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \
578 defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
579 
581 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
582  addToRunTimeSelectionTable \
583  ( \
584  PatchTypeField, \
585  typePatchTypeField, \
586  patch \
587  ); \
588  addToRunTimeSelectionTable \
589  ( \
590  PatchTypeField, \
591  typePatchTypeField, \
592  patchMapper \
593  ); \
594  addToRunTimeSelectionTable \
595  ( \
596  PatchTypeField, \
597  typePatchTypeField, \
598  dictionary \
599  );
600 
601 
602 // Use with caution
603 #define addRemovableToPatchFieldRunTimeSelection\
604 (PatchTypeField, typePatchTypeField) \
605  \
606  addRemovableToRunTimeSelectionTable \
607  ( \
608  PatchTypeField, \
609  typePatchTypeField, \
610  patch \
611  ); \
612  addRemovableToRunTimeSelectionTable \
613  ( \
614  PatchTypeField, \
615  typePatchTypeField, \
616  patchMapper \
617  ); \
618  addRemovableToRunTimeSelectionTable \
619  ( \
620  PatchTypeField, \
621  typePatchTypeField, \
622  dictionary \
623  );
624 
625 
626 // For non-templated patch fields
627 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
628  defineTypeNameAndDebug(typePatchTypeField, 0); \
629  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
630 
631 // For non-templated patch fields - use with caution
632 #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
633  defineTypeNameAndDebug(typePatchTypeField, 0); \
634  addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
635 
636 // For templated patch fields
637 #define makeTemplatePatchTypeField(fieldType, type) \
638  defineNamedTemplateTypeNameAndDebug \
639  ( \
640  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
641  0 \
642  ); \
643  addToPatchFieldRunTimeSelection \
644  ( \
645  CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
646  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
647  )
649 #define makePatchFields(type) \
650  FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
652 #define makePatchFieldTypeName(fieldType, type) \
653  defineNamedTemplateTypeNameAndDebug \
654  ( \
655  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
656  0 \
657  );
659 #define makePatchFieldTypeNames(type) \
660  FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
662 #define makePatchTypeFieldTypedef(fieldType, type) \
663  typedef type##FvPatchField<fieldType> \
664  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
666 #define makePatchTypeFieldTypedefs(type) \
667  FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
668 
669 
670 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
671 
672 #endif
673 
674 // ************************************************************************* //
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fvPatchField.C:189
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:166
declareRunTimeSelectionTable(tmp, fvPatchField, patch,(const fvPatch &p, const DimensionedField< Type, volMesh > &iF),(p, iF))
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:296
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static int disallowGenericFvPatchField
Debug switch to disallow the use of genericFvPatchField.
Definition: fvPatchField.H:114
bool updated() const
Return true if the boundary condition has already been updated.
Definition: fvPatchField.H:355
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator*=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:318
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: fvPatchField.H:419
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:447
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:260
bool manipulatedMatrix() const
Return true if the matrix has already been manipulated.
Definition: fvPatchField.H:361
static const word & calculatedType()
Return the type of the calculated for of fvPatchField.
const Field< Type > & primitiveField() const
Return internal field reference.
Definition: fvPatchField.H:349
virtual void operator==(const fvPatchField< Type > &)
Definition: fvPatchField.C:441
virtual bool assignable() const
Return true if the value of the patch field.
Definition: fvPatchField.H:303
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
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
Definition: fvPatchField.H:411
virtual void operator/=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:335
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:457
Foam::fvPatchFieldMapper.
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
Definition: fvPatchField.H:315
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:309
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:199
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
static tmp< fvPatchField< Type > > New(const word &, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
virtual void manipulateMatrix(fvMatrix< Type > &matrix)
Manipulate matrix.
Definition: fvPatchField.C:242
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:436
void check(const fvPatchField< Type > &) const
Check fvPatchField<Type> against given fvPatchField<Type>
Definition: fvPatchField.C:154
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:337
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void operator-=(const fvPatchField< Type > &)
Definition: fvPatchField.C:307
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: fvPatchField.C:174
virtual void operator+=(const fvPatchField< Type > &)
Definition: fvPatchField.C:296
TypeName("fvPatchField")
Runtime type information.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:229
calculatedFvPatchField< Type > Calculated
Definition: fvPatchField.H:107
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:209
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:477
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:275
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...
static tmp< fvPatchField< Type > > NewCalculatedType(const fvPatch &)
Return a pointer to a new calculatedFvPatchField created on.
const objectRegistry & db() const
Return local objectRegistry.
Definition: fvPatchField.C:147
virtual void updateWeightedCoeffs(const scalarField &weights)
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:216
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
fvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: fvPatchField.C:36
tmp< fvPatchField< Type > > clone() const
Disallow clone without setting internal field reference.
Definition: fvPatchField.H:199
Namespace for OpenFOAM.
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:343