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-2019 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  //- Optional patch type, used to allow specified boundary conditions
105  // to be applied to constraint patches by providing the constraint
106  // patch type as 'patchType'
107  word patchType_;
108 
109 
110 public:
112  typedef fvPatch Patch;
114 
115 
116  //- Runtime type information
117  TypeName("fvPatchField");
118 
119  //- Debug switch to disallow the use of genericFvPatchField
120  static int disallowGenericFvPatchField;
121 
122 
123  // Declare run-time constructor selection tables
124 
126  (
127  tmp,
128  fvPatchField,
129  patch,
130  (
131  const fvPatch& p,
133  ),
134  (p, iF)
135  );
136 
138  (
139  tmp,
140  fvPatchField,
141  patchMapper,
142  (
143  const fvPatchField<Type>& ptf,
144  const fvPatch& p,
146  const fvPatchFieldMapper& m
147  ),
148  (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
149  );
150 
152  (
153  tmp,
154  fvPatchField,
155  dictionary,
156  (
157  const fvPatch& p,
159  const dictionary& dict
160  ),
161  (p, iF, dict)
162  );
163 
164 
165  // Constructors
166 
167  //- Construct from patch and internal field
169  (
170  const fvPatch&,
172  );
173 
174  //- Construct from patch and internal field and patch field
176  (
177  const fvPatch&,
179  const Field<Type>&
180  );
181 
182  //- Construct from patch, internal field and dictionary
184  (
185  const fvPatch&,
187  const dictionary&,
188  const bool valueRequired=true
189  );
190 
191  //- Construct by mapping the given fvPatchField onto a new patch
193  (
194  const fvPatchField<Type>&,
195  const fvPatch&,
197  const fvPatchFieldMapper&,
198  const bool mappingRequired=true
199  );
200 
201  //- Copy constructor
203 
204  //- Construct and return a clone
205  virtual tmp<fvPatchField<Type>> clone() const
206  {
207  return tmp<fvPatchField<Type>>(new fvPatchField<Type>(*this));
208  }
209 
210  //- Copy constructor setting internal field reference
212  (
213  const fvPatchField<Type>&,
215  );
216 
217  //- Construct and return a clone setting internal field reference
219  (
221  ) const
222  {
223  return tmp<fvPatchField<Type>>(new fvPatchField<Type>(*this, iF));
224  }
225 
226 
227  // Selectors
228 
229  //- Return a pointer to a new patchField created on freestore given
230  // patch and internal field
231  // (does not set the patch field values)
233  (
234  const word&,
235  const fvPatch&,
237  );
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).
242  // Allows override of constraint type
244  (
245  const word&,
246  const word& actualPatchType,
247  const fvPatch&,
249  );
250 
251  //- Return a pointer to a new patchField created on freestore from
252  // a given fvPatchField mapped onto a new patch
254  (
255  const fvPatchField<Type>&,
256  const fvPatch&,
258  const fvPatchFieldMapper&
259  );
260 
261  //- Return a pointer to a new patchField created on freestore
262  // from dictionary
264  (
265  const fvPatch&,
267  const dictionary&
268  );
269 
270  //- Return a pointer to a new calculatedFvPatchField created on
271  // freestore without setting patchField values
273  (
274  const fvPatch&
275  );
276 
277  //- Return a pointer to a new calculatedFvPatchField created on
278  // freestore without setting patchField values
279  template<class Type2>
281  (
282  const fvPatchField<Type2>&
283  );
284 
285 
286  //- Destructor
287  virtual ~fvPatchField<Type>()
288  {}
289 
290 
291  // Member Functions
292 
293  // Attributes
294 
295  //- Return the type of the calculated for of fvPatchField
296  static const word& calculatedType();
297 
298  //- Return true if this patch field fixes a value.
299  // Needed to check if a level has to be specified while solving
300  // Poissons equations.
301  virtual bool fixesValue() const
302  {
303  return false;
304  }
305 
306  //- Return true if the value of the patch field
307  // is altered by assignment (the default)
308  virtual bool assignable() const
309  {
310  return true;
311  }
312 
313  //- Return true if this patch field is coupled
314  virtual bool coupled() const
315  {
316  return false;
317  }
318 
319 
320  // Access
321 
322  //- Return local objectRegistry
323  const objectRegistry& db() const;
324 
325  //- Return patch
326  const fvPatch& patch() const
327  {
328  return patch_;
329  }
330 
331  //- Return dimensioned internal field reference
333  internalField() const
334  {
335  return internalField_;
336  }
337 
338  //- Return internal field reference
339  const Field<Type>& primitiveField() const
340  {
341  return internalField_;
342  }
343 
344  //- Optional patch type
345  const word& patchType() const
346  {
347  return patchType_;
348  }
349 
350  //- Optional patch type
351  word& patchType()
352  {
353  return patchType_;
354  }
355 
356  //- Return true if the boundary condition has already been updated
357  bool updated() const
358  {
359  return updated_;
360  }
361 
362  //- Return true if the matrix has already been manipulated
363  bool manipulatedMatrix() const
364  {
365  return manipulatedMatrix_;
366  }
367 
368 
369  // Mapping functions
370 
371  //- Map (and resize as needed) from self given a mapping object
372  // Used to update fields following mesh topology change
373  virtual void autoMap(const fvPatchFieldMapper&);
374 
375  //- Reverse map the given fvPatchField onto this fvPatchField
376  // Used to reconstruct fields
377  virtual void rmap(const fvPatchField<Type>&, const labelList&);
378 
379 
380  // Evaluation functions
381 
382  //- Return patch-normal gradient
383  virtual tmp<Field<Type>> snGrad() const;
384 
385  //- Return patch-normal gradient for coupled-patches
386  // using the deltaCoeffs provided
388  (
389  const scalarField& deltaCoeffs
390  ) const
391  {
393  return *this;
394  }
395 
396  //- Update the coefficients associated with the patch field
397  // Sets Updated to true
398  virtual void updateCoeffs();
399 
400  //- Update the coefficients associated with the patch field
401  // with a weight field (0..1). This weight field is usually
402  // provided as the amount of geometric overlap for 'duplicate'
403  // patches. Sets Updated to true
404  virtual void updateWeightedCoeffs(const scalarField& weights);
405 
406  //- Return internal field next to patch as patch field
407  virtual tmp<Field<Type>> patchInternalField() const;
408 
409  //- Return internal field next to patch as patch field
410  virtual void patchInternalField(Field<Type>&) const;
411 
412  //- Return patchField on the opposite patch of a coupled patch
413  virtual tmp<Field<Type>> patchNeighbourField() const
414  {
416  return *this;
417  }
418 
419  //- Initialise the evaluation of the patch field
420  virtual void initEvaluate
421  (
422  const Pstream::commsTypes commsType =
424  )
425  {}
426 
427  //- Evaluate the patch field, sets Updated to false
428  virtual void evaluate
429  (
430  const Pstream::commsTypes commsType =
432  );
433 
434 
435  //- Return the matrix diagonal coefficients corresponding to the
436  // evaluation of the value of this patchField with given weights
438  (
439  const tmp<Field<scalar>>&
440  ) const
441  {
443  return *this;
444  }
445 
446  //- Return the matrix source coefficients corresponding to the
447  // evaluation of the value of this patchField with given weights
449  (
450  const tmp<Field<scalar>>&
451  ) const
452  {
454  return *this;
455  }
456 
457  //- Return the matrix diagonal coefficients corresponding to the
458  // evaluation of the gradient of this patchField
459  virtual tmp<Field<Type>> gradientInternalCoeffs() const
460  {
462  return *this;
463  }
464 
465  //- Return the matrix diagonal coefficients corresponding to the
466  // evaluation of the gradient of this coupled patchField
467  // using the deltaCoeffs provided
469  (
470  const scalarField& deltaCoeffs
471  ) const
472  {
474  return *this;
475  }
476 
477  //- Return the matrix source coefficients corresponding to the
478  // evaluation of the gradient of this patchField
479  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
480  {
482  return *this;
483  }
484 
485  //- Return the matrix source coefficients corresponding to the
486  // evaluation of the gradient of this coupled patchField
487  // using the deltaCoeffs provided
489  (
490  const scalarField& deltaCoeffs
491  ) const
492  {
494  return *this;
495  }
496 
497 
498  //- Manipulate matrix
499  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
500 
501  //- Manipulate matrix with given weights
502  virtual void manipulateMatrix
503  (
504  fvMatrix<Type>& matrix,
505  const scalarField& weights
506  );
507 
508 
509  // I-O
510 
511  //- Write
512  virtual void write(Ostream&) const;
513 
514 
515  // Check
516 
517  //- Check fvPatchField<Type> against given fvPatchField<Type>
518  void check(const fvPatchField<Type>&) const;
519 
520 
521  // Member Operators
522 
523  virtual void operator=(const UList<Type>&);
524 
525  virtual void operator=(const fvPatchField<Type>&);
526  virtual void operator+=(const fvPatchField<Type>&);
527  virtual void operator-=(const fvPatchField<Type>&);
528  virtual void operator*=(const fvPatchField<scalar>&);
529  virtual void operator/=(const fvPatchField<scalar>&);
530 
531  virtual void operator+=(const Field<Type>&);
532  virtual void operator-=(const Field<Type>&);
533 
534  virtual void operator*=(const Field<scalar>&);
535  virtual void operator/=(const Field<scalar>&);
536 
537  virtual void operator=(const Type&);
538  virtual void operator+=(const Type&);
539  virtual void operator-=(const Type&);
540  virtual void operator*=(const scalar);
541  virtual void operator/=(const scalar);
542 
543 
544  // Force an assignment irrespective of form of patch
545 
546  virtual void operator==(const fvPatchField<Type>&);
547  virtual void operator==(const Field<Type>&);
548  virtual void operator==(const Type&);
549 
550 
551  // Ostream operator
552 
553  friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
554 };
555 
556 
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
558 
559 } // End namespace Foam
560 
561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
562 
563 #ifdef NoRepository
564  #include "fvPatchField.C"
565  #include "calculatedFvPatchField.H"
566 #endif
567 
569 #define makeFvPatchField(fvPatchTypeField) \
570  \
571 defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \
572 template<> \
573 int fvPatchTypeField::disallowGenericFvPatchField \
574 ( \
575  debug::debugSwitch("disallowGenericFvPatchField", 0) \
576 ); \
577 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \
578 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \
579 defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
580 
582 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
583  addToRunTimeSelectionTable \
584  ( \
585  PatchTypeField, \
586  typePatchTypeField, \
587  patch \
588  ); \
589  addToRunTimeSelectionTable \
590  ( \
591  PatchTypeField, \
592  typePatchTypeField, \
593  patchMapper \
594  ); \
595  addToRunTimeSelectionTable \
596  ( \
597  PatchTypeField, \
598  typePatchTypeField, \
599  dictionary \
600  );
601 
602 
603 // Use with caution
604 #define addRemovableToPatchFieldRunTimeSelection\
605 (PatchTypeField, typePatchTypeField) \
606  \
607  addRemovableToRunTimeSelectionTable \
608  ( \
609  PatchTypeField, \
610  typePatchTypeField, \
611  patch \
612  ); \
613  addRemovableToRunTimeSelectionTable \
614  ( \
615  PatchTypeField, \
616  typePatchTypeField, \
617  patchMapper \
618  ); \
619  addRemovableToRunTimeSelectionTable \
620  ( \
621  PatchTypeField, \
622  typePatchTypeField, \
623  dictionary \
624  );
625 
626 
627 // For non-templated patch fields
628 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
629  defineTypeNameAndDebug(typePatchTypeField, 0); \
630  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
631 
632 // For non-templated patch fields - use with caution
633 #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
634  defineTypeNameAndDebug(typePatchTypeField, 0); \
635  addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
636 
637 // For templated patch fields
638 #define makeTemplatePatchTypeField(fieldType, type) \
639  defineNamedTemplateTypeNameAndDebug \
640  ( \
641  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
642  0 \
643  ); \
644  addToPatchFieldRunTimeSelection \
645  ( \
646  CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
647  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
648  )
650 #define makePatchFields(type) \
651  FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
653 #define makePatchFieldTypeName(fieldType, type) \
654  defineNamedTemplateTypeNameAndDebug \
655  ( \
656  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
657  0 \
658  );
660 #define makePatchFieldTypeNames(type) \
661  FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
663 #define makePatchTypeFieldTypedef(fieldType, type) \
664  typedef type##FvPatchField<fieldType> \
665  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
667 #define makePatchTypeFieldTypedefs(type) \
668  FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
669 
670 
671 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
672 
673 #endif
674 
675 // ************************************************************************* //
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fvPatchField.C:209
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:186
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:300
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
static int disallowGenericFvPatchField
Debug switch to disallow the use of genericFvPatchField.
Definition: fvPatchField.H:119
bool updated() const
Return true if the boundary condition has already been updated.
Definition: fvPatchField.H:356
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator*=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:338
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
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:420
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:448
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:280
bool manipulatedMatrix() const
Return true if the matrix has already been manipulated.
Definition: fvPatchField.H:362
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:338
virtual void operator==(const fvPatchField< Type > &)
Definition: fvPatchField.C:461
virtual bool assignable() const
Return true if the value of the patch field.
Definition: fvPatchField.H:307
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:412
virtual void operator/=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:355
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:458
Foam::fvPatchFieldMapper.
This boundary condition is not designed to be evaluated; it is assmued that the value is assigned via...
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:313
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:219
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:262
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:437
void check(const fvPatchField< Type > &) const
Check fvPatchField<Type> against given fvPatchField<Type>
Definition: fvPatchField.C:174
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:325
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void operator-=(const fvPatchField< Type > &)
Definition: fvPatchField.C:327
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: fvPatchField.C:194
virtual void operator+=(const fvPatchField< Type > &)
Definition: fvPatchField.C:316
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:249
calculatedFvPatchField< Type > Calculated
Definition: fvPatchField.H:112
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:229
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:478
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:295
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:167
virtual void updateWeightedCoeffs(const scalarField &weights)
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:236
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:366
fvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: fvPatchField.C:36
const word & patchType() const
Optional patch type.
Definition: fvPatchField.H:344
Namespace for OpenFOAM.
virtual tmp< fvPatchField< Type > > clone() const
Construct and return a clone.
Definition: fvPatchField.H:204
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:332