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-2013 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 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of classes
56 
57 class objectRegistry;
58 class dictionary;
59 class fvPatchFieldMapper;
60 class volMesh;
61 
62 
63 // Forward declaration of friend functions and operators
64 
65 template<class Type>
67 
68 template<class Type>
69 class fvMatrix;
70 
71 template<class Type>
72 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class fvPatchField Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class fvPatchField
81 :
82  public Field<Type>
83 {
84  // Private data
85 
86  //- Reference to patch
87  const fvPatch& patch_;
88 
89  //- Reference to internal field
90  const DimensionedField<Type, volMesh>& internalField_;
91 
92  //- Update index used so that updateCoeffs is called only once during
93  // the construction of the matrix
94  bool updated_;
95 
96  //- Update index used so that manipulateMatrix is called only once
97  // during the construction of the matrix
98  bool manipulatedMatrix_;
99 
100  //- Optional patch type, used to allow specified boundary conditions
101  // to be applied to constraint patches by providing the constraint
102  // patch type as 'patchType'
103  word patchType_;
104 
105 
106 public:
107 
108  typedef fvPatch Patch;
109 
110 
111  //- Runtime type information
112  TypeName("fvPatchField");
113 
114  //- Debug switch to disallow the use of genericFvPatchField
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 type
171  (
172  const fvPatch&,
174  const word& patchType
175  );
176 
177  //- Construct from patch and internal field and patch field
179  (
180  const fvPatch&,
182  const Field<Type>&
183  );
184 
185  //- Construct from patch, internal field and dictionary
187  (
188  const fvPatch&,
190  const dictionary&,
191  const bool valueRequired=false
192  );
193 
194  //- Construct by mapping the given fvPatchField onto a new patch
196  (
197  const fvPatchField<Type>&,
198  const fvPatch&,
200  const fvPatchFieldMapper&
201  );
202 
203  //- Construct as copy
205 
206  //- Construct and return a clone
207  virtual tmp<fvPatchField<Type> > clone() const
208  {
209  return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
210  }
211 
212  //- Construct as copy setting internal field reference
214  (
215  const fvPatchField<Type>&,
217  );
218 
219  //- Construct and return a clone setting internal field reference
220  virtual tmp<fvPatchField<Type> > clone
221  (
223  ) const
224  {
225  return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
226  }
227 
228 
229  // Selectors
230 
231  //- Return a pointer to a new patchField created on freestore given
232  // patch and internal field
233  // (does not set the patch field values)
234  static tmp<fvPatchField<Type> > New
235  (
236  const word&,
237  const fvPatch&,
239  );
240 
241  //- Return a pointer to a new patchField created on freestore given
242  // patch and internal field
243  // (does not set the patch field values).
244  // Allows override of constraint type
245  static tmp<fvPatchField<Type> > New
246  (
247  const word&,
248  const word& actualPatchType,
249  const fvPatch&,
251  );
252 
253  //- Return a pointer to a new patchField created on freestore from
254  // a given fvPatchField mapped onto a new patch
255  static tmp<fvPatchField<Type> > New
256  (
257  const fvPatchField<Type>&,
258  const fvPatch&,
260  const fvPatchFieldMapper&
261  );
262 
263  //- Return a pointer to a new patchField created on freestore
264  // from dictionary
265  static tmp<fvPatchField<Type> > New
266  (
267  const fvPatch&,
269  const dictionary&
270  );
271 
272  //- Return a pointer to a new calculatedFvPatchField created on
273  // freestore without setting patchField values
274  static tmp<fvPatchField<Type> > NewCalculatedType
275  (
276  const fvPatch&
277  );
278 
279  //- Return a pointer to a new calculatedFvPatchField created on
280  // freestore without setting patchField values
281  template<class Type2>
282  static tmp<fvPatchField<Type> > NewCalculatedType
283  (
284  const fvPatchField<Type2>&
285  );
286 
287 
288  //- Destructor
290  {}
291 
292 
293  // Member functions
294 
295  // Access
296 
297  //- Return local objectRegistry
298  const objectRegistry& db() const;
299 
300  //- Return patch
301  const fvPatch& patch() const
302  {
303  return patch_;
304  }
305 
306  //- Return dimensioned internal field reference
309  {
310  return internalField_;
311  }
312 
313  //- Return internal field reference
314  const Field<Type>& internalField() const
315  {
316  return internalField_;
317  }
318 
319  //- Optional patch type
320  const word& patchType() const
321  {
322  return patchType_;
323  }
324 
325  //- Optional patch type
327  {
328  return patchType_;
329  }
330 
331  //- Return the type of the calculated for of fvPatchField
332  static const word& calculatedType();
333 
334  //- Return true if this patch field fixes a value.
335  // Needed to check if a level has to be specified while solving
336  // Poissons equations.
337  virtual bool fixesValue() const
338  {
339  return false;
340  }
341 
342  //- Return true if this patch field is coupled
343  virtual bool coupled() const
344  {
345  return false;
346  }
347 
348  //- Return true if the boundary condition has already been updated
349  bool updated() const
350  {
351  return updated_;
352  }
353 
354  //- Return true if the matrix has already been manipulated
355  bool manipulatedMatrix() const
356  {
357  return manipulatedMatrix_;
358  }
359 
360 
361  // Mapping functions
362 
363  //- Map (and resize as needed) from self given a mapping object
364  virtual void autoMap
365  (
366  const fvPatchFieldMapper&
367  );
368 
369  //- Reverse map the given fvPatchField onto this fvPatchField
370  virtual void rmap
371  (
372  const fvPatchField<Type>&,
373  const labelList&
374  );
375 
376 
377  // Evaluation functions
378 
379  //- Return patch-normal gradient
380  virtual tmp<Field<Type> > snGrad() const;
381 
382  //- Return patch-normal gradient for coupled-patches
383  // using the deltaCoeffs provided
384  virtual tmp<Field<Type> > snGrad
385  (
386  const scalarField& deltaCoeffs
387  ) const
388  {
390  (
391  type() + "::snGrad(const scalarField& deltaCoeffs)"
392  );
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  // and apply weight field
402  // Sets Updated to true
403  virtual void updateCoeffs(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
413  {
414  notImplemented(type() + "patchNeighbourField()");
415  return *this;
416  }
417 
418  //- Initialise the evaluation of the patch field
419  virtual void initEvaluate
420  (
421  const Pstream::commsTypes commsType=Pstream::blocking
422  )
423  {}
424 
425  //- Evaluate the patch field, sets Updated to false
426  virtual void evaluate
427  (
428  const Pstream::commsTypes commsType=Pstream::blocking
429  );
430 
431 
432  //- Return the matrix diagonal coefficients corresponding to the
433  // evaluation of the value of this patchField with given weights
434  virtual tmp<Field<Type> > valueInternalCoeffs
435  (
436  const tmp<Field<scalar> >&
437  ) const
438  {
440  (
441  type()
442  + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
443  );
444  return *this;
445  }
446 
447  //- Return the matrix source coefficients corresponding to the
448  // evaluation of the value of this patchField with given weights
449  virtual tmp<Field<Type> > valueBoundaryCoeffs
450  (
451  const tmp<Field<scalar> >&
452  ) const
453  {
455  (
456  type()
457  + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
458  );
459  return *this;
460  }
461 
462  //- Return the matrix diagonal coefficients corresponding to the
463  // evaluation of the gradient of this patchField
465  {
466  notImplemented(type() + "::gradientInternalCoeffs()");
467  return *this;
468  }
469 
470  //- Return the matrix diagonal coefficients corresponding to the
471  // evaluation of the gradient of this coupled patchField
472  // using the deltaCoeffs provided
473  virtual tmp<Field<Type> > gradientInternalCoeffs
474  (
475  const scalarField& deltaCoeffs
476  ) const
477  {
479  (
480  type()
481  + "::gradientInternalCoeffs(const scalarField& deltaCoeffs)"
482  );
483  return *this;
484  }
485 
486  //- Return the matrix source coefficients corresponding to the
487  // evaluation of the gradient of this patchField
489  {
490  notImplemented(type() + "::gradientBoundaryCoeffs()");
491  return *this;
492  }
493 
494  //- Return the matrix source coefficients corresponding to the
495  // evaluation of the gradient of this coupled patchField
496  // using the deltaCoeffs provided
497  virtual tmp<Field<Type> > gradientBoundaryCoeffs
498  (
499  const scalarField& deltaCoeffs
500  ) const
501  {
503  (
504  type()
505  + "::gradientBoundaryCoeffs(const scalarField& deltaCoeffs)"
506  );
507  return *this;
508  }
509 
510 
511  //- Manipulate matrix
512  virtual void manipulateMatrix(fvMatrix<Type>& matrix);
513 
514  //- Manipulate matrix with given weights
515  virtual void manipulateMatrix
516  (
517  fvMatrix<Type>& matrix,
518  const scalarField& weights
519  );
520 
521 
522  // I-O
523 
524  //- Write
525  virtual void write(Ostream&) const;
526 
527  //- Helper function to write the keyword and entry only if the
528  // values are not equal. The value is then output as value2
529  template<class EntryType>
530  void writeEntryIfDifferent
531  (
532  Ostream& os,
533  const word& entryName,
534  const EntryType& value1,
535  const EntryType& value2
536  ) const;
537 
538 
539  // Check
540 
541  //- Check fvPatchField<Type> against given fvPatchField<Type>
542  void check(const fvPatchField<Type>&) const;
543 
544 
545  // Member operators
546 
547  virtual void operator=(const UList<Type>&);
548 
549  virtual void operator=(const fvPatchField<Type>&);
550  virtual void operator+=(const fvPatchField<Type>&);
551  virtual void operator-=(const fvPatchField<Type>&);
552  virtual void operator*=(const fvPatchField<scalar>&);
553  virtual void operator/=(const fvPatchField<scalar>&);
554 
555  virtual void operator+=(const Field<Type>&);
556  virtual void operator-=(const Field<Type>&);
557 
558  virtual void operator*=(const Field<scalar>&);
559  virtual void operator/=(const Field<scalar>&);
560 
561  virtual void operator=(const Type&);
562  virtual void operator+=(const Type&);
563  virtual void operator-=(const Type&);
564  virtual void operator*=(const scalar);
565  virtual void operator/=(const scalar);
566 
567 
568  // Force an assignment irrespective of form of patch
569 
570  virtual void operator==(const fvPatchField<Type>&);
571  virtual void operator==(const Field<Type>&);
572  virtual void operator==(const Type&);
573 
574 
575  // Ostream operator
576 
577  friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
578 };
579 
580 
581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
582 
583 } // End namespace Foam
584 
585 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 
587 #ifdef NoRepository
588 # include "fvPatchField.C"
589 # include "calculatedFvPatchField.H"
590 #endif
591 
592 
593 #define makeFvPatchField(fvPatchTypeField) \
594  \
595 defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \
596 template<> \
597 int fvPatchTypeField::disallowGenericFvPatchField \
598 ( \
599  debug::debugSwitch("disallowGenericFvPatchField", 0) \
600 ); \
601 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \
602 defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \
603 defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary);
604 
605 
606 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
607  addToRunTimeSelectionTable \
608  ( \
609  PatchTypeField, \
610  typePatchTypeField, \
611  patch \
612  ); \
613  addToRunTimeSelectionTable \
614  ( \
615  PatchTypeField, \
616  typePatchTypeField, \
617  patchMapper \
618  ); \
619  addToRunTimeSelectionTable \
620  ( \
621  PatchTypeField, \
622  typePatchTypeField, \
623  dictionary \
624  );
625 
626 
627 // use with caution
628 #define addRemovableToPatchFieldRunTimeSelection\
629 (PatchTypeField, typePatchTypeField) \
630  \
631  addRemovableToRunTimeSelectionTable \
632  ( \
633  PatchTypeField, \
634  typePatchTypeField, \
635  patch \
636  ); \
637  addRemovableToRunTimeSelectionTable \
638  ( \
639  PatchTypeField, \
640  typePatchTypeField, \
641  patchMapper \
642  ); \
643  addRemovableToRunTimeSelectionTable \
644  ( \
645  PatchTypeField, \
646  typePatchTypeField, \
647  dictionary \
648  );
649 
650 
651 // for non-templated patch fields
652 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
653  defineTypeNameAndDebug(typePatchTypeField, 0); \
654  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
655 
656 // for non-templated patch fields - use with caution
657 #define makeRemovablePatchTypeField(PatchTypeField, typePatchTypeField) \
658  defineTypeNameAndDebug(typePatchTypeField, 0); \
659  addRemovableToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
660 
661 
662 // for templated patch fields
663 #define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \
664  defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
665  addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
666 
667 
668 #define makePatchFields(type) \
669  makeTemplatePatchTypeField \
670  ( \
671  fvPatchScalarField, \
672  type##FvPatchScalarField \
673  ); \
674  makeTemplatePatchTypeField \
675  ( \
676  fvPatchVectorField, \
677  type##FvPatchVectorField \
678  ); \
679  makeTemplatePatchTypeField \
680  ( \
681  fvPatchSphericalTensorField, \
682  type##FvPatchSphericalTensorField \
683  ); \
684  makeTemplatePatchTypeField \
685  ( \
686  fvPatchSymmTensorField, \
687  type##FvPatchSymmTensorField \
688  ); \
689  makeTemplatePatchTypeField \
690  ( \
691  fvPatchTensorField, \
692  type##FvPatchTensorField \
693  );
694 
695 
696 #define makePatchFieldsTypeName(type) \
697  defineNamedTemplateTypeNameAndDebug(type##FvPatchScalarField, 0); \
698  defineNamedTemplateTypeNameAndDebug(type##FvPatchVectorField, 0); \
699  defineNamedTemplateTypeNameAndDebug(type##FvPatchSphericalTensorField, 0);\
700  defineNamedTemplateTypeNameAndDebug(type##FvPatchSymmTensorField, 0); \
701  defineNamedTemplateTypeNameAndDebug(type##FvPatchTensorField, 0)
702 
703 
704 #define makePatchTypeFieldTypedefs(type) \
705  typedef type##FvPatchField<scalar> type##FvPatchScalarField; \
706  typedef type##FvPatchField<vector> type##FvPatchVectorField; \
707  typedef type##FvPatchField<sphericalTensor> \
708  type##FvPatchSphericalTensorField; \
709  typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField; \
710  typedef type##FvPatchField<tensor> type##FvPatchTensorField;
711 
712 
713 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
714 
715 #endif
716 
717 // ************************************************************************* //