1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Abstract base class with a fat-interface to all derived classes
29 covering all possible ways in which they might be used.
31 The first level of derivation is to basic patchFields which cover
32 zero-gradient, fixed-gradient, fixed-value and mixed conditions.
34 The next level of derivation covers all the specialised types with
35 specific evaluation proceedures, particularly with respect to specific
42 \*---------------------------------------------------------------------------*/
44 #ifndef fvPatchField_H
45 #define fvPatchField_H
48 #include "DimensionedField.H"
49 #include "debugSwitch.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // Forward declaration of classes
60 class fvPatchFieldMapper;
64 // Forward declaration of friend functions and operators
72 template<class Type, template<class> class PatchField, class GeoMesh>
79 Ostream& operator<<(Ostream&, const fvPatchField<Type>&);
82 /*---------------------------------------------------------------------------*\
83 Class fvPatchField Declaration
84 \*---------------------------------------------------------------------------*/
93 //- Reference to patch
94 const fvPatch& patch_;
96 //- Reference to internal field
97 const DimensionedField<Type, volMesh>& internalField_;
99 //- Update index used so that updateCoeffs is called only once during
100 // the construction of the matrix
103 //- Optional patch type, used to allow specified boundary conditions
104 // to be applied to constraint patches by providing the constraint
105 // patch type as 'patchType'
111 typedef fvPatch Patch;
113 //- Runtime type information
114 TypeName("fvPatchField");
116 //- Debug switch to disallow the use of genericFvPatchField
117 static debug::debugSwitch disallowGenericFvPatchField;
120 // Declare run-time constructor selection tables
123 declareRunTimeSelectionTable
130 const DimensionedField<Type, volMesh>& iF
135 declareRunTimeSelectionTable
141 const fvPatchField<Type>& ptf,
143 const DimensionedField<Type, volMesh>& iF,
144 const fvPatchFieldMapper& m
146 (dynamic_cast<const fvPatchFieldType&>(ptf), p, iF, m)
149 declareRunTimeSelectionTable
156 const DimensionedField<Type, volMesh>& iF,
157 const dictionary& dict
165 //- Construct from patch and internal field
169 const DimensionedField<Type, volMesh>&
172 //- Construct from patch and internal field and patch field
176 const DimensionedField<Type, volMesh>&,
180 //- Construct from patch, internal field and dictionary
184 const DimensionedField<Type, volMesh>&,
186 const bool valueRequired = false
189 //- Construct by mapping the given fvPatchField onto a new patch
192 const fvPatchField<Type>&,
194 const DimensionedField<Type, volMesh>&,
195 const fvPatchFieldMapper&
198 //- Construct as copy
199 fvPatchField(const fvPatchField<Type>&);
201 //- Construct and return a clone
202 virtual tmp<fvPatchField<Type> > clone() const
204 return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this));
207 //- Construct as copy setting internal field reference
210 const fvPatchField<Type>&,
211 const DimensionedField<Type, volMesh>&
214 //- Construct and return a clone setting internal field reference
215 virtual tmp<fvPatchField<Type> > clone
217 const DimensionedField<Type, volMesh>& iF
220 return tmp<fvPatchField<Type> >(new fvPatchField<Type>(*this, iF));
226 //- Return a pointer to a new patchField created on freestore given
227 // patch and internal field
228 // (does not set the patch field values)
229 static tmp<fvPatchField<Type> > New
233 const DimensionedField<Type, volMesh>&
236 //- Return a pointer to a new patchField created on freestore from
237 // a given fvPatchField mapped onto a new patch
238 static tmp<fvPatchField<Type> > New
240 const fvPatchField<Type>&,
242 const DimensionedField<Type, volMesh>&,
243 const fvPatchFieldMapper&
246 //- Return a pointer to a new patchField created on freestore
248 static tmp<fvPatchField<Type> > New
251 const DimensionedField<Type, volMesh>&,
255 //- Return a pointer to a new calculatedFvPatchField created on
256 // freestore without setting patchField values
257 template<class Type2>
258 static tmp<fvPatchField<Type> > NewCalculatedType
260 const fvPatchField<Type2>&
266 virtual ~fvPatchField<Type>()
274 //- Return local objectRegistry
275 const objectRegistry& db() const;
277 //- Lookup and return the patchField of the named field from the
278 // field's objectRegistry.
279 // N.B. The dummy pointer arguments are used if this function is
280 // instantiated within a templated function to avoid a bug in gcc.
281 // See inletOutletFvPatchField.C and outletInletFvPatchField.C
282 template<class GeometricField, class Type2>
283 const typename GeometricField::PatchFieldType& lookupPatchField
286 const GeometricField* = NULL,
291 const fvPatch& patch() const
296 //- Return dimensioned internal field reference
297 const DimensionedField<Type, volMesh>&
298 dimensionedInternalField() const
300 return internalField_;
303 //- Return internal field reference
304 const Field<Type>& internalField() const
306 return internalField_;
309 //- Return the type of the calculated for type of fvPatchField
310 static const word& calculatedType();
312 //- Return patch type (optional on read)
313 const word& patchType() const
318 //- Return true if this patch field fixes a value.
319 // Needed to check if a level has to be specified while solving
320 // Poissons equations.
321 virtual bool fixesValue() const
326 //- Return true if this patch field is coupled
327 virtual bool coupled() const
332 //- Return true if the boundary condition has already been updated
341 //- Map (and resize as needed) from self given a mapping object
344 const fvPatchFieldMapper&
347 //- Reverse map the given fvPatchField onto this fvPatchField
350 const fvPatchField<Type>&,
355 // Evaluation functions
357 //- Return patch-normal gradient
358 virtual tmp<Field<Type> > snGrad() const;
360 //- Update the coefficients associated with the patch field
361 // Sets Updated to true
362 virtual void updateCoeffs()
367 //- Return internal field next to patch as patch field
368 virtual tmp<Field<Type> > patchInternalField() const;
370 //- Return patchField on the opposite patch of a coupled patch
371 virtual tmp<Field<Type> > patchNeighbourField() const
373 notImplemented(type() + "patchNeighbourField()");
377 //- Initialise the evaluation of the patch field
378 virtual void initEvaluate
380 const Pstream::commsTypes commsType = Pstream::blocking
384 //- Evaluate the patch field, sets Updated to false
385 virtual void evaluate
387 const Pstream::commsTypes commsType = Pstream::blocking
391 //- Return the matrix diagonal coefficients corresponding to the
392 // evaluation of the value of this patchField with given weights
393 virtual tmp<Field<Type> > valueInternalCoeffs
395 const tmp<Field<scalar> >&
401 + "::valueInternalCoeffs(const tmp<Field<scalar> >&)"
406 //- Return the matrix source coefficients corresponding to the
407 // evaluation of the value of this patchField with given weights
408 virtual tmp<Field<Type> > valueBoundaryCoeffs
410 const tmp<Field<scalar> >&
416 + "::valueBoundaryCoeffs(const tmp<Field<scalar> >&)"
421 //- Return the matrix diagonal coefficients corresponding to the
422 // evaluation of the gradient of this patchField
423 virtual tmp<Field<Type> > gradientInternalCoeffs() const
425 notImplemented(type() + "::gradientInternalCoeffs()");
429 //- Return the matrix source coefficients corresponding to the
430 // evaluation of the gradient of this patchField
431 virtual tmp<Field<Type> > gradientBoundaryCoeffs() const
433 notImplemented(type() + "::gradientBoundaryCoeffs()");
438 // Patch interpolation and patch flux
440 //- Calculate patch face interpolate given weighting factors
441 virtual void patchInterpolate
443 GeometricField<Type, fvsPatchField, surfaceMesh>& fField,
444 const scalarField& pL
447 //- Calculate patch face interpolate given two weighting factors
448 virtual void patchInterpolate
450 GeometricField<Type, fvsPatchField, surfaceMesh>& fField,
451 const scalarField& pL,
452 const scalarField& pY
455 //- Calculate patch flux
456 virtual void patchFlux
458 GeometricField<Type, fvsPatchField, surfaceMesh>& flux,
459 const fvMatrix<Type>& matrix
463 // Matrix manipulation
465 //- Manipulate matrix
466 virtual void manipulateMatrix(fvMatrix<Type>& matrix);
472 virtual void write(Ostream&) const;
474 //- Helper function to write the keyword and entry only if the
475 // values are not equal. The value is then output as value2
476 template<class EntryType>
477 void writeEntryIfDifferent
480 const word& entryName,
481 const EntryType& value1,
482 const EntryType& value2
488 //- Check fvPatchField<Type> against given fvPatchField<Type>
489 void check(const fvPatchField<Type>&) const;
494 virtual void operator=(const UList<Type>&);
496 virtual void operator=(const fvPatchField<Type>&);
497 virtual void operator+=(const fvPatchField<Type>&);
498 virtual void operator-=(const fvPatchField<Type>&);
499 virtual void operator*=(const fvPatchField<scalar>&);
500 virtual void operator/=(const fvPatchField<scalar>&);
502 virtual void operator+=(const Field<Type>&);
503 virtual void operator-=(const Field<Type>&);
505 virtual void operator*=(const Field<scalar>&);
506 virtual void operator/=(const Field<scalar>&);
508 virtual void operator=(const Type&);
509 virtual void operator+=(const Type&);
510 virtual void operator-=(const Type&);
511 virtual void operator*=(const scalar);
512 virtual void operator/=(const scalar);
515 // Force an assignment irrespective of form of patch
517 virtual void operator==(const fvPatchField<Type>&);
518 virtual void operator==(const Field<Type>&);
519 virtual void operator==(const Type&);
525 friend Ostream& operator<< <Type>(Ostream&, const fvPatchField<Type>&);
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
532 } // End namespace Foam
534 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
537 # include "fvPatchField.C"
538 # include "calculatedFvPatchField.H"
542 #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
544 addToRunTimeSelectionTable \
546 PatchTypeField, typePatchTypeField, patch \
549 addToRunTimeSelectionTable \
552 typePatchTypeField, \
556 addToRunTimeSelectionTable \
558 PatchTypeField, typePatchTypeField, dictionary \
562 #define makePatchTypeFieldTypeName(type) \
564 defineNamedTemplateTypeNameAndDebug(type, 0);
567 #define makePatchFieldsTypeName(type) \
569 makePatchTypeFieldTypeName(type##FvPatchScalarField); \
570 makePatchTypeFieldTypeName(type##FvPatchVectorField); \
571 makePatchTypeFieldTypeName(type##FvPatchSphericalTensorField); \
572 makePatchTypeFieldTypeName(type##FvPatchSymmTensorField); \
573 makePatchTypeFieldTypeName(type##FvPatchSymmTensor4thOrderField); \
574 makePatchTypeFieldTypeName(type##FvPatchDiagTensorField); \
575 makePatchTypeFieldTypeName(type##FvPatchTensorField);
578 #define makePatchTypeField(PatchTypeField, typePatchTypeField) \
580 defineTypeNameAndDebug(typePatchTypeField, 0); \
582 addToPatchFieldRunTimeSelection \
584 PatchTypeField, typePatchTypeField \
588 #define makeTemplatePatchTypeField(PatchTypeField, typePatchTypeField) \
590 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
592 addToPatchFieldRunTimeSelection \
594 PatchTypeField, typePatchTypeField \
598 #define makePatchFields(type) \
600 makeTemplatePatchTypeField(fvPatchScalarField, type##FvPatchScalarField); \
601 makeTemplatePatchTypeField(fvPatchVectorField, type##FvPatchVectorField); \
602 makeTemplatePatchTypeField \
604 fvPatchSphericalTensorField, \
605 type##FvPatchSphericalTensorField \
607 makeTemplatePatchTypeField \
609 fvPatchSymmTensorField, \
610 type##FvPatchSymmTensorField \
612 makeTemplatePatchTypeField \
614 fvPatchSymmTensor4thOrderField, \
615 type##FvPatchSymmTensor4thOrderField \
617 makeTemplatePatchTypeField \
619 fvPatchDiagTensorField, \
620 type##FvPatchDiagTensorField \
622 makeTemplatePatchTypeField(fvPatchTensorField, type##FvPatchTensorField);
625 #define makePatchTypeFieldTypedefs(type) \
627 typedef type##FvPatchField<scalar> type##FvPatchScalarField; \
628 typedef type##FvPatchField<vector> type##FvPatchVectorField; \
629 typedef type##FvPatchField<sphericalTensor> \
630 type##FvPatchSphericalTensorField; \
631 typedef type##FvPatchField<symmTensor> type##FvPatchSymmTensorField; \
632 typedef type##FvPatchField<symmTensor4thOrder> \
633 type##FvPatchSymmTensor4thOrderField; \
634 typedef type##FvPatchField<diagTensor> \
635 type##FvPatchDiagTensorField; \
636 typedef type##FvPatchField<tensor> type##FvPatchTensorField;
639 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
643 // ************************************************************************* //