fvPatchField.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 | Copyright (C) 2011-2017 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 proceedures, 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, internal field and value
176  (
177  const fvPatch&,
179  const Type& value
180  );
181 
182  //- Construct from patch and internal field and patch type
184  (
185  const fvPatch&,
187  const word& patchType
188  );
189 
190  //- Construct from patch and internal field and patch field
192  (
193  const fvPatch&,
195  const Field<Type>&
196  );
197 
198  //- Construct from patch, internal field and dictionary
200  (
201  const fvPatch&,
203  const dictionary&,
204  const bool valueRequired=true
205  );
206 
207  //- Construct by mapping the given fvPatchField onto a new patch
209  (
210  const fvPatchField<Type>&,
211  const fvPatch&,
213  const fvPatchFieldMapper&
214  );
215 
216  //- Construct as copy
218 
219  //- Construct and return a clone
220  virtual tmp<fvPatchField<Type>> clone() const
221  {
222  return tmp<fvPatchField<Type>>(new fvPatchField<Type>(*this));
223  }
224 
225  //- Construct as copy setting internal field reference
227  (
228  const fvPatchField<Type>&,
230  );
231 
232  //- Construct and return a clone setting internal field reference
234  (
236  ) const
237  {
238  return tmp<fvPatchField<Type>>(new fvPatchField<Type>(*this, iF));
239  }
240 
241 
242  // Selectors
243 
244  //- Return a pointer to a new patchField created on freestore given
245  // patch and internal field
246  // (does not set the patch field values)
248  (
249  const word&,
250  const fvPatch&,
252  );
253 
254  //- Return a pointer to a new patchField created on freestore given
255  // patch and internal field
256  // (does not set the patch field values).
257  // Allows override of constraint type
259  (
260  const word&,
261  const word& actualPatchType,
262  const fvPatch&,
264  );
265 
266  //- Return a pointer to a new patchField created on freestore from
267  // a given fvPatchField mapped onto a new patch
269  (
270  const fvPatchField<Type>&,
271  const fvPatch&,
273  const fvPatchFieldMapper&
274  );
275 
276  //- Return a pointer to a new patchField created on freestore
277  // from dictionary
279  (
280  const fvPatch&,
282  const dictionary&
283  );
284 
285  //- Return a pointer to a new calculatedFvPatchField created on
286  // freestore without setting patchField values
288  (
289  const fvPatch&
290  );
291 
292  //- Return a pointer to a new calculatedFvPatchField created on
293  // freestore without setting patchField values
294  template<class Type2>
296  (
297  const fvPatchField<Type2>&
298  );
299 
300 
301  //- Destructor
302  virtual ~fvPatchField<Type>()
303  {}
304 
305 
306  // Member functions
307 
308  // Attributes
309 
310  //- Return the type of the calculated for of fvPatchField
311  static const word& calculatedType();
312 
313  //- Return true if this patch field fixes a value.
314  // Needed to check if a level has to be specified while solving
315  // Poissons equations.
316  virtual bool fixesValue() const
317  {
318  return false;
319  }
320 
321  //- Return true if the value of the patch field
322  // is altered by assignment (the default)
323  virtual bool assignable() const
324  {
325  return true;
326  }
327 
328  //- Return true if this patch field is coupled
329  virtual bool coupled() const
330  {
331  return false;
332  }
333 
334 
335  // Access
336 
337  //- Return local objectRegistry
338  const objectRegistry& db() const;
339 
340  //- Return patch
341  const fvPatch& patch() const
342  {
343  return patch_;
344  }
345 
346  //- Return dimensioned internal field reference
348  internalField() const
349  {
350  return internalField_;
351  }
352 
353  //- Return internal field reference
354  const Field<Type>& primitiveField() const
355  {
356  return internalField_;
357  }
358 
359  //- Optional patch type
360  const word& patchType() const
361  {
362  return patchType_;
363  }
364 
365  //- Optional patch type
366  word& patchType()
367  {
368  return patchType_;
369  }
370 
371  //- Return true if the boundary condition has already been updated
372  bool updated() const
373  {
374  return updated_;
375  }
376 
377  //- Return true if the matrix has already been manipulated
378  bool manipulatedMatrix() const
379  {
380  return manipulatedMatrix_;
381  }
382 
383 
384  // Mapping functions
385 
386  //- Map (and resize as needed) from self given a mapping object
387  virtual void autoMap
388  (
389  const fvPatchFieldMapper&
390  );
391 
392  //- Reverse map the given fvPatchField onto this fvPatchField
393  virtual void rmap
394  (
395  const fvPatchField<Type>&,
396  const labelList&
397  );
398 
399 
400  // Evaluation functions
401 
402  //- Return patch-normal gradient
403  virtual tmp<Field<Type>> snGrad() const;
404 
405  //- Return patch-normal gradient for coupled-patches
406  // using the deltaCoeffs provided
408  (
409  const scalarField& deltaCoeffs
410  ) const
411  {
413  return *this;
414  }
415 
416  //- Update the coefficients associated with the patch field
417  // Sets Updated to true
418  virtual void updateCoeffs();
419 
420  //- Update the coefficients associated with the patch field
421  // with a weight field (0..1). This weight field is ususally
422  // provided as the amount of geometric overlap for 'duplicate'
423  // patches. Sets Updated to true
424  virtual void updateWeightedCoeffs(const scalarField& weights);
425 
426  //- Return internal field next to patch as patch field
427  virtual tmp<Field<Type>> patchInternalField() const;
428 
429  //- Return internal field next to patch as patch field
430  virtual void patchInternalField(Field<Type>&) const;
431 
432  //- Return patchField on the opposite patch of a coupled patch
433  virtual tmp<Field<Type>> patchNeighbourField() const
434  {
436  return *this;
437  }
438 
439  //- Initialise the evaluation of the patch field
440  virtual void initEvaluate
441  (
442  const Pstream::commsTypes commsType =
444  )
445  {}
446 
447  //- Evaluate the patch field, sets Updated to false
448  virtual void evaluate
449  (
450  const Pstream::commsTypes commsType =
452  );
453 
454 
455  //- Return the matrix diagonal coefficients corresponding to the
456  // evaluation of the value of this patchField with given weights
458  (
459  const tmp<Field<scalar>>&
460  ) const
461  {
463  return *this;
464  }
465 
466  //- Return the matrix source coefficients corresponding to the
467  // evaluation of the value of this patchField with given weights
469  (
470  const tmp<Field<scalar>>&
471  ) const
472  {
474  return *this;
475  }
476 
477  //- Return the matrix diagonal coefficients corresponding to the
478  // evaluation of the gradient of this patchField
479  virtual tmp<Field<Type>> gradientInternalCoeffs() const
480  {
482  return *this;
483  }
484 
485  //- Return the matrix diagonal 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  //- Return the matrix source coefficients corresponding to the
498  // evaluation of the gradient of this patchField
499  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
500  {
502  return *this;
503  }
504 
505  //- Return the matrix source coefficients corresponding to the
506  // evaluation of the gradient of this coupled patchField
507  // using the deltaCoeffs provided
509  (
510  const scalarField& deltaCoeffs
511  ) const
512  {
514  return *this;
515  }
516 
517 
518  //- Manipulate matrix
519  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
520 
521  //- Manipulate matrix with given weights
522  virtual void manipulateMatrix
523  (
524  fvMatrix<Type>& matrix,
525  const scalarField& weights
526  );
527 
528 
529  // I-O
530 
531  //- Write
532  virtual void write(Ostream&) const;
533 
534  //- Helper function to write the keyword and entry only if the
535  // values are not equal. The value is then output as value2
536  template<class EntryType>
538  (
539  Ostream& os,
540  const word& entryName,
541  const EntryType& value1,
542  const EntryType& value2
543  ) const;
544 
545 
546  // Check
547 
548  //- Check fvPatchField<Type> against given fvPatchField<Type>
549  void check(const fvPatchField<Type>&) const;
550 
551 
552  // Member operators
553 
554  virtual void operator=(const UList<Type>&);
555 
556  virtual void operator=(const fvPatchField<Type>&);
557  virtual void operator+=(const fvPatchField<Type>&);
558  virtual void operator-=(const fvPatchField<Type>&);
559  virtual void operator*=(const fvPatchField<scalar>&);
560  virtual void operator/=(const fvPatchField<scalar>&);
561 
562  virtual void operator+=(const Field<Type>&);
563  virtual void operator-=(const Field<Type>&);
564 
565  virtual void operator*=(const Field<scalar>&);
566  virtual void operator/=(const Field<scalar>&);
567 
568  virtual void operator=(const Type&);
569  virtual void operator+=(const Type&);
570  virtual void operator-=(const Type&);
571  virtual void operator*=(const scalar);
572  virtual void operator/=(const scalar);
573 
574 
575  // Force an assignment irrespective of form of patch
576 
577  virtual void operator==(const fvPatchField<Type>&);
578  virtual void operator==(const Field<Type>&);
579  virtual void operator==(const Type&);
580 
581 
582  // Ostream operator
583 
584  friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
585 };
586 
587 
588 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
589 
590 } // End namespace Foam
591 
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
593 
594 #ifdef NoRepository
595  #include "fvPatchField.C"
596  #include "calculatedFvPatchField.H"
597 #endif
598 
600 #define makeFvPatchField(fvPatchTypeField) \
601  \
602 defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \
603 template<> \
604 int fvPatchTypeField::disallowGenericFvPatchField \
605 ( \
606  debug::debugSwitch("disallowGenericFvPatchField", 0) \
607 ); \
608 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \
609 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \
610 defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
611 
613 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
614  addToRunTimeSelectionTable \
615  ( \
616  PatchTypeField, \
617  typePatchTypeField, \
618  patch \
619  ); \
620  addToRunTimeSelectionTable \
621  ( \
622  PatchTypeField, \
623  typePatchTypeField, \
624  patchMapper \
625  ); \
626  addToRunTimeSelectionTable \
627  ( \
628  PatchTypeField, \
629  typePatchTypeField, \
630  dictionary \
631  );
632 
633 
634 // Use with caution
635 #define addRemovableToPatchFieldRunTimeSelection\
636 (PatchTypeField, typePatchTypeField) \
637  \
638  addRemovableToRunTimeSelectionTable \
639  ( \
640  PatchTypeField, \
641  typePatchTypeField, \
642  patch \
643  ); \
644  addRemovableToRunTimeSelectionTable \
645  ( \
646  PatchTypeField, \
647  typePatchTypeField, \
648  patchMapper \
649  ); \
650  addRemovableToRunTimeSelectionTable \
651  ( \
652  PatchTypeField, \
653  typePatchTypeField, \
654  dictionary \
655  );
656 
657 
658 // For non-templated patch fields
659 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
660  defineTypeNameAndDebug(typePatchTypeField, 0); \
661  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
662 
663 // For non-templated patch fields - use with caution
664 #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
665  defineTypeNameAndDebug(typePatchTypeField, 0); \
666  addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
667 
668 // For templated patch fields
669 #define makeTemplatePatchTypeField(fieldType, type) \
670  defineNamedTemplateTypeNameAndDebug \
671  ( \
672  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
673  0 \
674  ); \
675  addToPatchFieldRunTimeSelection \
676  ( \
677  CAT3(fvPatch, CAPITALIZE(fieldType), Field), \
678  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field) \
679  )
681 #define makePatchFields(type) \
682  FOR_ALL_FIELD_TYPES(makeTemplatePatchTypeField, type)
684 #define makePatchFieldTypeName(fieldType, type) \
685  defineNamedTemplateTypeNameAndDebug \
686  ( \
687  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field), \
688  0 \
689  );
691 #define makePatchFieldTypeNames(type) \
692  FOR_ALL_FIELD_TYPES(makePatchFieldTypeName, type)
694 #define makePatchTypeFieldTypedef(fieldType, type) \
695  typedef type##FvPatchField<fieldType> \
696  CAT4(type, FvPatch, CAPITALIZE(fieldType), Field);
698 #define makePatchTypeFieldTypedefs(type) \
699  FOR_ALL_FIELD_TYPES(makePatchTypeFieldTypedef, type)
700 
701 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
702 
703 #endif
704 
705 // ************************************************************************* //
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fvPatchField.C:239
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:216
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:315
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:371
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator*=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:438
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:440
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:468
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:362
bool manipulatedMatrix() const
Return true if the matrix has already been manipulated.
Definition: fvPatchField.H:377
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:353
virtual void operator==(const fvPatchField< Type > &)
Definition: fvPatchField.C:561
virtual bool assignable() const
Return true if the value of the patch field.
Definition: fvPatchField.H:322
Include the header files for all the primitive types that Fields are instantiated for...
Pre-declare SubField and related Field type.
Definition: Field.H:57
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:432
virtual void operator/=(const fvPatchField< scalar > &)
Definition: fvPatchField.C:455
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:478
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:328
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:301
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:344
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:457
void check(const fvPatchField< Type > &) const
Check fvPatchField<Type> against given fvPatchField<Type>
Definition: fvPatchField.C:204
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:340
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:427
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2) const
Helper function to write the keyword and entry only if the.
Definition: fvPatchField.C:377
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: fvPatchField.C:224
virtual void operator+=(const fvPatchField< Type > &)
Definition: fvPatchField.C:416
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:331
calculatedFvPatchField< Type > Calculated
Definition: fvPatchField.H:112
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:311
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:498
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:395
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:197
virtual void updateWeightedCoeffs(const scalarField &weights)
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:318
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:359
Namespace for OpenFOAM.
virtual tmp< fvPatchField< Type > > clone() const
Construct and return a clone.
Definition: fvPatchField.H:219
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:347