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-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::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  //- Construct and return a clone onto a new patch
223  // setting internal field reference
225  (
226  const fvPatch& patch,
228  ) const
229  {
230  return tmp<fvPatchField<Type>>
231  (
232  new fvPatchField<Type>(patch, iF, *this)
233  );
234  }
235 
236 
237  // Selectors
238 
239  //- Return a pointer to a new patchField created on freestore given
240  // patch and internal field
241  // (does not set the patch field values)
243  (
244  const word&,
245  const fvPatch&,
247  );
248 
249  //- Return a pointer to a new patchField created on freestore given
250  // patch and internal field
251  // (does not set the patch field values).
252  // Allows override of constraint type
254  (
255  const word&,
256  const word& actualPatchType,
257  const fvPatch&,
259  );
260 
261  //- Return a pointer to a new patchField created on freestore from
262  // a given fvPatchField mapped onto a new patch
264  (
265  const fvPatchField<Type>&,
266  const fvPatch&,
268  const fvPatchFieldMapper&
269  );
270 
271  //- Return a pointer to a new patchField created on freestore
272  // from dictionary
274  (
275  const fvPatch&,
277  const dictionary&
278  );
279 
280  //- Return a pointer to a new calculatedFvPatchField created on
281  // freestore without setting patchField values
283  (
284  const fvPatch&
285  );
286 
287  //- Return a pointer to a new calculatedFvPatchField created on
288  // freestore without setting patchField values
289  template<class Type2>
291  (
292  const fvPatchField<Type2>&
293  );
294 
295 
296  //- Destructor
297  virtual ~fvPatchField<Type>()
298  {}
299 
300 
301  // Member Functions
302 
303  // Attributes
304 
305  //- Return the type of the calculated for of fvPatchField
306  static const word& calculatedType();
307 
308  //- Return true if this patch field fixes a value.
309  // Needed to check if a level has to be specified while solving
310  // Poissons equations.
311  virtual bool fixesValue() const
312  {
313  return false;
314  }
315 
316  //- Return true if the value of the patch field
317  // is altered by assignment (the default)
318  virtual bool assignable() const
319  {
320  return true;
321  }
322 
323  //- Return true if this patch field is coupled
324  virtual bool coupled() const
325  {
326  return false;
327  }
328 
329  //- Return true if this overrides the underlying constraint type
330  bool overridesConstraint() const
331  {
332  if (type() == patch_.type())
333  {
334  return false;
335  }
336 
337  typename patchConstructorTable::iterator patchTypeCstrIter
338  = patchConstructorTablePtr_->find(patch_.type());
339 
340  return
341  patchTypeCstrIter
342  != patchConstructorTablePtr_->end();
343  }
344 
345 
346  // Access
347 
348  //- Return local objectRegistry
349  const objectRegistry& db() const;
350 
351  //- Return patch
352  const fvPatch& patch() const
353  {
354  return patch_;
355  }
356 
357  //- Return dimensioned internal field reference
359  {
360  return internalField_;
361  }
362 
363  //- Return internal field reference
364  const Field<Type>& primitiveField() const
365  {
366  return internalField_;
367  }
368 
369  //- Return true if the boundary condition has already been updated
370  bool updated() const
371  {
372  return updated_;
373  }
374 
375  //- Return true if the matrix has already been manipulated
376  bool manipulatedMatrix() const
377  {
378  return manipulatedMatrix_;
379  }
380 
381 
382  // Mapping functions
383 
384  //- Map (and resize as needed) from self given a mapping object
385  // Used to update fields following mesh topology change
386  virtual void autoMap(const fvPatchFieldMapper&);
387 
388  //- Reverse map the given fvPatchField onto this fvPatchField
389  // Used to reconstruct fields
390  virtual void rmap(const fvPatchField<Type>&, const labelList&);
391 
392  //- Reset the fvPatchField to the given fvPatchField
393  // Used for mesh to mesh mapping
394  virtual void reset(const fvPatchField<Type>&);
395 
396 
397  // Evaluation functions
398 
399  //- Return patch-normal gradient
400  virtual tmp<Field<Type>> snGrad() const;
401 
402  //- Return patch-normal gradient for coupled-patches
403  // using the deltaCoeffs provided
405  (
406  const scalarField& deltaCoeffs
407  ) const
408  {
410  return *this;
411  }
412 
413  //- Update the coefficients associated with the patch field
414  // Sets Updated to true
415  virtual void updateCoeffs();
416 
417  //- Return internal field next to patch as patch field
418  virtual tmp<Field<Type>> patchInternalField() const;
419 
420  //- Return internal field next to patch as patch field
421  virtual void patchInternalField(Field<Type>&) const;
422 
423  //- Initialise return of the patchField on the opposite patch of a
424  // coupled patch
426  (
427  const Pstream::commsTypes commsType =
429  ) const
430  {}
431 
432  //- Return patchField on the opposite patch of a coupled patch
434  (
435  const Pstream::commsTypes commsType =
437  ) const
438  {
440  return *this;
441  }
442 
443  //- Initialise the evaluation of the patch field
444  virtual void initEvaluate
445  (
446  const Pstream::commsTypes commsType =
448  )
449  {}
450 
451  //- Evaluate the patch field, sets Updated to false
452  virtual void evaluate
453  (
454  const Pstream::commsTypes commsType =
456  );
457 
458 
459  //- Return the matrix diagonal coefficients corresponding to the
460  // evaluation of the value of this patchField with given weights
462  (
463  const tmp<Field<scalar>>&
464  ) const
465  {
467  return *this;
468  }
469 
470  //- Return the matrix source coefficients corresponding to the
471  // evaluation of the value of this patchField with given weights
473  (
474  const tmp<Field<scalar>>&
475  ) const
476  {
478  return *this;
479  }
480 
481  //- Return the matrix diagonal coefficients corresponding to the
482  // evaluation of the gradient of this patchField
483  virtual tmp<Field<Type>> gradientInternalCoeffs() const
484  {
486  return *this;
487  }
488 
489  //- Return the matrix diagonal coefficients corresponding to the
490  // evaluation of the gradient of this coupled patchField
491  // using the deltaCoeffs provided
493  (
494  const scalarField& deltaCoeffs
495  ) const
496  {
498  return *this;
499  }
500 
501  //- Return the matrix source coefficients corresponding to the
502  // evaluation of the gradient of this patchField
503  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
504  {
506  return *this;
507  }
508 
509  //- Return the matrix source coefficients corresponding to the
510  // evaluation of the gradient of this coupled patchField
511  // using the deltaCoeffs provided
513  (
514  const scalarField& deltaCoeffs
515  ) const
516  {
518  return *this;
519  }
520 
521  //- Manipulate matrix
522  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
523 
524 
525  // I-O
526 
527  //- Write
528  virtual void write(Ostream&) const;
529 
530 
531  // Check
532 
533  //- Check fvPatchField<Type> against given fvPatchField<Type>
534  void check(const fvPatchField<Type>&) const;
535 
536 
537  // Member Operators
538 
539  virtual void operator=(const UList<Type>&);
540 
541  virtual void operator=(const fvPatchField<Type>&);
542  virtual void operator+=(const fvPatchField<Type>&);
543  virtual void operator-=(const fvPatchField<Type>&);
544  virtual void operator*=(const fvPatchField<scalar>&);
545  virtual void operator/=(const fvPatchField<scalar>&);
546 
547  virtual void operator+=(const Field<Type>&);
548  virtual void operator-=(const Field<Type>&);
549 
550  virtual void operator*=(const Field<scalar>&);
551  virtual void operator/=(const Field<scalar>&);
552 
553  virtual void operator=(const Type&);
554  virtual void operator+=(const Type&);
555  virtual void operator-=(const Type&);
556  virtual void operator*=(const scalar);
557  virtual void operator/=(const scalar);
558 
559 
560  // Force an assignment irrespective of form of patch
561 
562  virtual void operator==(const fvPatchField<Type>&);
563  virtual void operator==(const Field<Type>&);
564  virtual void operator==(const Type&);
565 
566 
567  // Ostream operator
568 
569  friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
570 };
571 
572 
573 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
574 
575 } // End namespace Foam
576 
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
578 
579 #ifdef NoRepository
580  #include "fvPatchField.C"
581  #include "calculatedFvPatchField.H"
582 #endif
583 
585 #define makeFvPatchField(fvPatchTypeField) \
586  defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \
587  template<> \
588  int fvPatchTypeField::disallowGenericFvPatchField \
589  ( \
590  debug::debugSwitch("disallowGenericFvPatchField", 0) \
591  ); \
592  defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \
593  defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \
594  defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
595 
597 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
598  addToRunTimeSelectionTable \
599  ( \
600  PatchTypeField, \
601  typePatchTypeField, \
602  patch \
603  ); \
604  addToRunTimeSelectionTable \
605  ( \
606  PatchTypeField, \
607  typePatchTypeField, \
608  patchMapper \
609  ); \
610  addToRunTimeSelectionTable \
611  ( \
612  PatchTypeField, \
613  typePatchTypeField, \
614  dictionary \
615  );
616 
617 
618 // Use with caution
619 #define addRemovableToPatchFieldRunTimeSelection( \
620  PatchTypeField, typePatchTypeField) \
621  \
622  addRemovableToRunTimeSelectionTable \
623  ( \
624  PatchTypeField, \
625  typePatchTypeField, \
626  patch \
627  ); \
628  addRemovableToRunTimeSelectionTable \
629  ( \
630  PatchTypeField, \
631  typePatchTypeField, \
632  patchMapper \
633  ); \
634  addRemovableToRunTimeSelectionTable \
635  ( \
636  PatchTypeField, \
637  typePatchTypeField, \
638  dictionary \
639  );
640 
641 
642 // For non-templated patch fields
643 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
644  defineTypeNameAndDebug(typePatchTypeField, 0); \
645  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
646 
647 
648 // For non-templated patch fields - use with caution
649 #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
650  defineTypeNameAndDebug(typePatchTypeField, 0); \
651  addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
652 
653 
654 // For templated patch fields
655 #define makeTemplatePatchTypeField(fieldType, type) \
656  defineNamedTemplateTypeNameAndDebug \
657  ( \
658  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
659  0 \
660  ); \
661  addToPatchFieldRunTimeSelection \
662  ( \
663  CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
664  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
665  )
666 
668 #define makePatchFields(type) \
669  FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
670 
672 #define makePatchFieldTypeName(fieldType, type) \
673  defineNamedTemplateTypeNameAndDebug \
674  ( \
675  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
676  0 \
677  );
678 
680 #define makePatchFieldTypeNames(type) \
681  FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
682 
684 #define makePatchTypeFieldTypedef(fieldType, type) \
685  typedef type##FvPatchField<fieldType> \
686  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
687 
689 #define makePatchTypeFieldTypedefs(type) \
690  FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
691 
692 
693 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
694 
695 #endif
696 
697 // ************************************************************************* //
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:310
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:369
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator*=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:301
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
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:444
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:472
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:243
bool manipulatedMatrix() const
Return true if the matrix has already been manipulated.
Definition: fvPatchField.H:375
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:363
virtual void operator==(const fvPatchField< Type > &)
Definition: fvPatchField.C:424
virtual bool assignable() const
Return true if the value of the patch field.
Definition: fvPatchField.H:317
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:209
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 void operator/=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:318
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:482
Foam::fvPatchFieldMapper.
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
Definition: fvPatchField.H:329
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
virtual void initPatchNeighbourField(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking) const
Initialise return of the patchField on the opposite patch of a.
Definition: fvPatchField.H:425
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:323
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:236
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:461
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:351
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:290
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:279
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:223
calculatedFvPatchField< Type > Calculated
Definition: fvPatchField.H:107
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:216
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:502
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:258
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
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking) const
Return patchField on the opposite patch of a coupled patch.
Definition: fvPatchField.H:433
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
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:357