From 55fd1ac9fd8ef0311fc84a97e3adfa9d7adcdd26 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 30 May 2013 10:39:33 +0100 Subject: [PATCH 01/24] ENH: snappyHexMeshDict: commented new options --- .../snappyHexMesh/snappyHexMeshDict | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index ca4a9dc6b5..791de6ec44 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -152,6 +152,10 @@ castellatedMeshControls inGroups (meshedPatches); } + + //- Optional increment (on top of max level) in small gaps. + //gapLevelIncrement 2; + //- Optional angle to detect small-large cell situation // perpendicular to the surface. Is the angle of face w.r.t. // the local surface normal. Use on flat(ish) surfaces only. @@ -180,11 +184,14 @@ castellatedMeshControls // - used if feature snapping (see snapControls below) is used resolveFeatureAngle 30; + // Planar angle: - // - used to determine if neighbouring surface normals - // are roughly the same so e.g. free-standing baffles can be merged + // - used to determine if surface normals + // are roughly the same or opposite. Used e.g. in gap refinement + // and to decide when to merge free-standing baffles + // // If not specified same as resolveFeatureAngle - //planarAngle 30; + planarAngle 15; // Region-wise refinement @@ -228,11 +235,6 @@ castellatedMeshControls // are only on the boundary of corresponding cellZones or also allow // free-standing zone faces. Not used if there are no faceZones. allowFreeStandingZoneFaces true; - - - // Optional: whether all baffles get eroded away. WIP. Used for - // surface simplification. - //allowFreeStandingBaffles false; } // Settings for the snapping. @@ -462,16 +464,17 @@ meshQualityControls // 1 = hex, <= 0 = folded or flattened illegal cell minDeterminant 0.001; - // minFaceWeight (0 -> 0.5) + // Relative position of face in relation to cell centres (0.5 for orthogonal + // mesh) (0 -> 0.5) minFaceWeight 0.05; - // minVolRatio (0 -> 1) + // Volume ratio of neighbouring cells (0 -> 1) minVolRatio 0.01; // must be >0 for Fluent compatibility minTriangleTwist -1; - //- if >0 : preserve single cells with all points on the surface if the + //- if >0 : preserve cells with all points on the surface if the // resulting volume after snapping (by approximation) is larger than // minVolCollapseRatio times old volume (i.e. not collapsed to flat cell). // If <0 : delete always. From fa2ed51f6b13c96446f8d151b4f8e74eca23448a Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 31 May 2013 14:39:23 +0100 Subject: [PATCH 02/24] ENH: Added variants of updateCoeffs and manipulateMatrix to receive weight field --- .../fvPatchFields/fvPatchField/fvPatchField.C | 42 ++++++++++++++++++- .../fvPatchFields/fvPatchField/fvPatchField.H | 27 ++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index fa3d6d7a31..7fd83f41b1 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -42,6 +42,7 @@ Foam::fvPatchField::fvPatchField patch_(p), internalField_(iF), updated_(false), + manipulatedMatrix_(false), patchType_(word::null) {} @@ -58,6 +59,7 @@ Foam::fvPatchField::fvPatchField patch_(p), internalField_(iF), updated_(false), + manipulatedMatrix_(false), patchType_(word::null) {} @@ -75,6 +77,7 @@ Foam::fvPatchField::fvPatchField patch_(p), internalField_(iF), updated_(false), + manipulatedMatrix_(false), patchType_(ptf.patchType_) {} @@ -92,6 +95,7 @@ Foam::fvPatchField::fvPatchField patch_(p), internalField_(iF), updated_(false), + manipulatedMatrix_(false), patchType_(dict.lookupOrDefault("patchType", word::null)) { if (dict.found("value")) @@ -133,6 +137,7 @@ Foam::fvPatchField::fvPatchField patch_(ptf.patch_), internalField_(ptf.internalField_), updated_(false), + manipulatedMatrix_(false), patchType_(ptf.patchType_) {} @@ -148,6 +153,7 @@ Foam::fvPatchField::fvPatchField patch_(ptf.patch_), internalField_(iF), updated_(false), + manipulatedMatrix_(false), patchType_(ptf.patchType_) {} @@ -267,6 +273,28 @@ void Foam::fvPatchField::rmap } +template +void Foam::fvPatchField::updateCoeffs() +{ + updated_ = true; +} + + +template +void Foam::fvPatchField::updateCoeffs(const scalarField& weights) +{ + if (!updated_) + { + updateCoeffs(); + + Field& fld = *this; + fld *= weights; + + updated_ = true; + } +} + + template void Foam::fvPatchField::evaluate(const Pstream::commsTypes) { @@ -276,13 +304,25 @@ void Foam::fvPatchField::evaluate(const Pstream::commsTypes) } updated_ = false; + manipulatedMatrix_ = false; } template void Foam::fvPatchField::manipulateMatrix(fvMatrix& matrix) { - // do nothing + manipulatedMatrix_ = true; +} + + +template +void Foam::fvPatchField::manipulateMatrix +( + fvMatrix& matrix, + const scalarField& weights +) +{ + manipulatedMatrix_ = true; } diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H index 6047f1e4af..d3b2ed4e70 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H @@ -93,6 +93,10 @@ class fvPatchField // the construction of the matrix bool updated_; + //- Update index used so that manipulateMatrix is called only once + // during the construction of the matrix + bool manipulatedMatrix_; + //- Optional patch type, used to allow specified boundary conditions // to be applied to constraint patches by providing the constraint // patch type as 'patchType' @@ -327,6 +331,12 @@ public: return updated_; } + //- Return true if the matrix has already been manipulated + bool manipulatedMatrix() const + { + return manipulatedMatrix_; + } + // Mapping functions @@ -365,10 +375,12 @@ public: //- Update the coefficients associated with the patch field // Sets Updated to true - virtual void updateCoeffs() - { - updated_ = true; - } + virtual void updateCoeffs(); + + //- Update the coefficients associated with the patch field + // and apply weight field + // Sets Updated to true + virtual void updateCoeffs(const scalarField& weights); //- Return internal field next to patch as patch field virtual tmp > patchInternalField() const; @@ -479,6 +491,13 @@ public: //- Manipulate matrix virtual void manipulateMatrix(fvMatrix& matrix); + //- Manipulate matrix with given weights + virtual void manipulateMatrix + ( + fvMatrix& matrix, + const scalarField& weights + ); + // I-O From a0d2760809cd94d323997cad8b097e75f52d322a Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 31 May 2013 14:40:25 +0100 Subject: [PATCH 03/24] ENH: Added updateCoeffs and manipulateMatrix functions --- .../cyclicACMI/cyclicACMIFvPatchField.C | 24 +++++++++++ .../cyclicACMI/cyclicACMIFvPatchField.H | 42 +++++++++++-------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C index bc3bab534d..905a565b0a 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C @@ -284,6 +284,16 @@ Foam::tmp > Foam::cyclicACMIFvPatchField::snGrad } +template +void Foam::cyclicACMIFvPatchField::updateCoeffs() +{ + const scalarField& mask = cyclicACMIPatch_.cyclicACMIPatch().mask(); + + const fvPatchField& npf = nonOverlapPatchField(); + const_cast&>(npf).updateCoeffs(mask); +} + + template void Foam::cyclicACMIFvPatchField::evaluate ( @@ -376,6 +386,20 @@ Foam::cyclicACMIFvPatchField::gradientBoundaryCoeffs() const } +template +void Foam::cyclicACMIFvPatchField::manipulateMatrix +( + fvMatrix& matrix +) +{ + // blend contrubutions from the coupled and non-overlap patches + const fvPatchField& npf = nonOverlapPatchField(); + + const scalarField& mask = cyclicACMIPatch_.cyclicACMIPatch().mask(); + const_cast&>(npf).manipulateMatrix(matrix, mask); +} + + template void Foam::cyclicACMIFvPatchField::write(Ostream& os) const { diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.H index 9848505be1..91f414d321 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.H @@ -178,12 +178,34 @@ public: //- Return reference to non-overlapping patchField const fvPatchField& nonOverlapPatchField() const; + //- Update result field based on interface functionality + virtual void updateInterfaceMatrix + ( + scalarField& result, + const scalarField& psiInternal, + const scalarField& coeffs, + const direction cmpt, + const Pstream::commsTypes commsType + ) const; + + //- Update result field based on interface functionality + virtual void updateInterfaceMatrix + ( + Field&, + const Field&, + const scalarField&, + const Pstream::commsTypes commsType + ) const; + //- Return patch-normal gradient virtual tmp > snGrad ( const scalarField& deltaCoeffs ) const; + //- Update the coefficients associated with the patch field + void updateCoeffs(); + //- Evaluate the patch field virtual void evaluate ( @@ -226,24 +248,8 @@ public: // evaluation of the gradient of this patchField virtual tmp > gradientBoundaryCoeffs() const; - //- Update result field based on interface functionality - virtual void updateInterfaceMatrix - ( - scalarField& result, - const scalarField& psiInternal, - const scalarField& coeffs, - const direction cmpt, - const Pstream::commsTypes commsType - ) const; - - //- Update result field based on interface functionality - virtual void updateInterfaceMatrix - ( - Field&, - const Field&, - const scalarField&, - const Pstream::commsTypes commsType - ) const; + //- Manipulate matrix + virtual void manipulateMatrix(fvMatrix& matrix); // Cyclic AMI coupled interface functions From 79801cb194c57379f152ae49f3a35ae654f8bd09 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 31 May 2013 14:54:46 +0100 Subject: [PATCH 04/24] ENH: Updated incompressible epsilon wall functions to include averaging and to handle ACMI patches --- ...silonLowReWallFunctionFvPatchScalarField.C | 133 ++-- ...silonLowReWallFunctionFvPatchScalarField.H | 22 +- .../epsilonWallFunctionFvPatchScalarField.C | 571 ++++++++++++++---- .../epsilonWallFunctionFvPatchScalarField.H | 88 ++- 4 files changed, 608 insertions(+), 206 deletions(-) diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.C index 0191a90a8c..d9898beda1 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.C @@ -55,6 +55,64 @@ scalar epsilonLowReWallFunctionFvPatchScalarField::yPlusLam } +void epsilonLowReWallFunctionFvPatchScalarField::calculate +( + const turbulenceModel& turbulence, + const List& cornerWeights, + const fvPatch& patch, + scalarField& G, + scalarField& epsilon +) +{ + const label patchI = patch.index(); + + const scalarField& y = turbulence.y()[patchI]; + + const scalar Cmu25 = pow025(Cmu_); + const scalar Cmu75 = pow(Cmu_, 0.75); + + const tmp tk = turbulence.k(); + const volScalarField& k = tk(); + + const tmp tnu = turbulence.nu(); + const scalarField& nuw = tnu().boundaryField()[patchI]; + + const tmp tnut = turbulence.nut(); + const volScalarField& nut = tnut(); + const scalarField& nutw = nut.boundaryField()[patchI]; + + const fvPatchVectorField& Uw = turbulence.U().boundaryField()[patchI]; + + const scalarField magGradUw(mag(Uw.snGrad())); + + // Set epsilon and G + forAll(nutw, faceI) + { + label cellI = patch.faceCells()[faceI]; + + scalar yPlus = Cmu25*sqrt(k[cellI])*y[faceI]/nuw[faceI]; + + scalar w = cornerWeights[faceI]; + + if (yPlus > yPlusLam_) + { + epsilon[cellI] = w*Cmu75*pow(k[cellI], 1.5)/(kappa_*y[faceI]); + } + else + { + epsilon[cellI] = w*2.0*k[cellI]*nuw[faceI]/sqr(y[faceI]); + } + + G[cellI] = + w + *(nutw[faceI] + nuw[faceI]) + *magGradUw[faceI] + *Cmu25*sqrt(k[cellI]) + /(kappa_*y[faceI]); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // epsilonLowReWallFunctionFvPatchScalarField:: @@ -119,81 +177,6 @@ epsilonLowReWallFunctionFvPatchScalarField {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void epsilonLowReWallFunctionFvPatchScalarField::updateCoeffs() -{ - if (updated()) - { - return; - } - - const label patchI = patch().index(); - - const turbulenceModel& turbulence = - db().lookupObject("turbulenceModel"); - const scalarField& y = turbulence.y()[patchI]; - - volScalarField& G = - const_cast - ( - db().lookupObject - ( - turbulence.GName() - ) - ); - - DimensionedField& epsilon = - const_cast&> - ( - dimensionedInternalField() - ); - - const tmp tk = turbulence.k(); - const volScalarField& k = tk(); - - const tmp tnu = turbulence.nu(); - const scalarField& nuw = tnu().boundaryField()[patchI]; - - const tmp tnut = turbulence.nut(); - const volScalarField& nut = tnut(); - const scalarField& nutw = nut.boundaryField()[patchI]; - - const fvPatchVectorField& Uw = turbulence.U().boundaryField()[patchI]; - const scalarField magGradUw(mag(Uw.snGrad())); - - const scalar Cmu25 = pow025(Cmu_); - const scalar Cmu75 = pow(Cmu_, 0.75); - - // Set epsilon and G - forAll(nutw, faceI) - { - label faceCellI = patch().faceCells()[faceI]; - - scalar yPlus = Cmu25*sqrt(k[faceCellI])*y[faceI]/nuw[faceI]; - - if (yPlus > yPlusLam_) - { - epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]); - } - else - { - epsilon[faceCellI] = 2.0*k[faceCellI]*nuw[faceI]/sqr(y[faceI]); - } - - G[faceCellI] = - (nutw[faceI] + nuw[faceI]) - *magGradUw[faceI] - *Cmu25*sqrt(k[faceCellI]) - /(kappa_*y[faceI]); - } - - fixedInternalValueFvPatchField::updateCoeffs(); - - // TODO: perform averaging for cells sharing more than one boundary face -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // makePatchTypeField diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.H index b8cf09f0b7..778fffcfd7 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonLowReWallFunction/epsilonLowReWallFunctionFvPatchScalarField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -97,6 +97,16 @@ protected: //- Calculate the Y+ at the edge of the laminar sublayer scalar yPlusLam(const scalar kappa, const scalar E); + //- Calculate the epsilon and G + virtual void calculate + ( + const turbulenceModel& turbulence, + const List& cornerWeights, + const fvPatch& patch, + scalarField& G, + scalarField& epsilon + ); + public: @@ -166,13 +176,9 @@ public: ); } - - // Member functions - - // Evaluation functions - - //- Update the coefficients associated with the patch field - virtual void updateCoeffs(); + //- Destructor + virtual ~epsilonLowReWallFunctionFvPatchScalarField() + {} }; diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C index 9435962e6a..7fb6fcfb96 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C @@ -26,11 +26,10 @@ License #include "epsilonWallFunctionFvPatchScalarField.H" #include "incompressible/turbulenceModel/turbulenceModel.H" #include "fvPatchFieldMapper.H" +#include "fvMatrix.H" #include "volFields.H" -#include "addToRunTimeSelectionTable.H" #include "wallFvPatch.H" -#include "nutkWallFunctionFvPatchScalarField.H" - +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -39,7 +38,7 @@ namespace Foam namespace incompressible { -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // void epsilonWallFunctionFvPatchScalarField::checkType() { @@ -63,118 +62,160 @@ void epsilonWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField -( - const fvPatch& p, - const DimensionedField& iF -) -: - fixedInternalValueFvPatchField(p, iF), - Cmu_(0.09), - kappa_(0.41), - E_(9.8) +void epsilonWallFunctionFvPatchScalarField::setMaster() { - checkType(); -} - - -epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField -( - const epsilonWallFunctionFvPatchScalarField& ptf, - const fvPatch& p, - const DimensionedField& iF, - const fvPatchFieldMapper& mapper -) -: - fixedInternalValueFvPatchField(ptf, p, iF, mapper), - Cmu_(ptf.Cmu_), - kappa_(ptf.kappa_), - E_(ptf.E_) -{ - checkType(); -} - - -epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField -( - const fvPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - fixedInternalValueFvPatchField(p, iF, dict), - Cmu_(dict.lookupOrDefault("Cmu", 0.09)), - kappa_(dict.lookupOrDefault("kappa", 0.41)), - E_(dict.lookupOrDefault("E", 9.8)) -{ - checkType(); -} - - -epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField -( - const epsilonWallFunctionFvPatchScalarField& ewfpsf -) -: - fixedInternalValueFvPatchField(ewfpsf), - Cmu_(ewfpsf.Cmu_), - kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) -{ - checkType(); -} - - -epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField -( - const epsilonWallFunctionFvPatchScalarField& ewfpsf, - const DimensionedField& iF -) -: - fixedInternalValueFvPatchField(ewfpsf, iF), - Cmu_(ewfpsf.Cmu_), - kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) -{ - checkType(); -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void epsilonWallFunctionFvPatchScalarField::updateCoeffs() -{ - if (updated()) + if (master_ != -1) { return; } - const label patchI = patch().index(); + const volScalarField& epsilon = + static_cast(this->dimensionedInternalField()); + + const volScalarField::GeometricBoundaryField& bf = epsilon.boundaryField(); + + label master = -1; + forAll(bf, patchI) + { + if (isA(bf[patchI])) + { + epsilonWallFunctionFvPatchScalarField& epf = epsilonPatch(patchI); + + if (master == -1) + { + master = patchI; + } + + epf.master() = master; + } + } +} + + +void epsilonWallFunctionFvPatchScalarField::createAveragingWeights() +{ + if (initialised_) + { + return; + } + + const volScalarField& epsilon = + static_cast(this->dimensionedInternalField()); + + const volScalarField::GeometricBoundaryField& bf = epsilon.boundaryField(); + + const fvMesh& mesh = epsilon.mesh(); + + volScalarField weights + ( + IOobject + ( + "weights", + mesh.time().timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE, + false // do not register + ), + mesh, + dimensionedScalar("zero", dimless, 0.0) + ); + + DynamicList