From 1858d30c18bfd2d0ccb0648ec8e25c9db70fdfd0 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 24 May 2012 11:48:53 +0100 Subject: [PATCH] ENH: autoLayerDriver: do not disable extrusions around edges --- .../autoHexMeshDriver/autoLayerDriver.C | 134 +++++++++++++++--- .../autoHexMeshDriver/autoLayerDriver.H | 6 +- .../autoHexMeshDriver/autoLayerDriverShrink.C | 64 +++++++-- 3 files changed, 172 insertions(+), 32 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C index c300cc53a7..abe3bc487c 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C @@ -439,6 +439,86 @@ void Foam::autoLayerDriver::handleFeatureAngle } +//Foam::tmp Foam::autoLayerDriver::undistortedEdgeLength +//( +// const indirectPrimitivePatch& pp, +// const bool relativeSizes, +// const bool faceSize +//) +//{ +// const fvMesh& mesh = meshRefiner_.mesh(); +// +// tmp tfld(new scalarField()); +// scalarField& fld = tfld(); +// +// if (faceSize) +// { +// fld.setSize(pp.size()); +// } +// else +// { +// fld.setSize(pp.nPoints()); +// } +// +// +// if (relativeSizes) +// { +// const scalar edge0Len = meshRefiner_.meshCutter().level0EdgeLength(); +// const labelList& cellLevel = meshRefiner_.meshCutter().cellLevel(); +// +// if (faceSize) +// { +// forAll(pp, i) +// { +// label faceI = pp.addressing()[i]; +// label ownLevel = cellLevel[mesh.faceOwner()[faceI]]; +// fld[i] = edge0Len/(1<(), +// labelMin // null value +// ); +// +// +// forAll(maxPointLevel, pointI) +// { +// // Find undistorted edge size for this level. +// fld[i] = edge0Len/(1<(mesh).instance(), mesh.time(), // register with runTime - static_cast(mesh).readOpt(), + IOobject::NO_READ, static_cast(mesh).writeOpt() ), // io params from original mesh but new name mesh, // original mesh diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H index 6bbe54a708..cb720dc64f 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -460,7 +460,8 @@ class autoLayerDriver pointVectorField& dispVec, pointScalarField& medialRatio, - pointScalarField& medialDist + pointScalarField& medialDist, + pointVectorField& medialVec ) const; //- Main routine to shrink mesh @@ -481,6 +482,7 @@ class autoLayerDriver const pointVectorField& dispVec, const pointScalarField& medialRatio, const pointScalarField& medialDist, + const pointVectorField& medialVec, List& extrudeStatus, pointField& patchDisp, diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C index b6a9e338aa..35133f062d 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C @@ -689,7 +689,8 @@ void Foam::autoLayerDriver::medialAxisSmoothingInfo pointVectorField& dispVec, pointScalarField& medialRatio, - pointScalarField& medialDist + pointScalarField& medialDist, + pointVectorField& medialVec ) const { @@ -929,7 +930,7 @@ void Foam::autoLayerDriver::medialAxisSmoothingInfo forAll(pointMedialDist, pointI) { medialDist[pointI] = Foam::sqrt(pointMedialDist[pointI].distSqr()); - //medialVec[pointI] = pointMedialDist[pointI].origin(); + medialVec[pointI] = pointMedialDist[pointI].origin(); } } @@ -966,14 +967,14 @@ void Foam::autoLayerDriver::medialAxisSmoothingInfo << " : normalised direction of nearest displacement" << nl << " " << medialDist.name() << " : distance to medial axis" << nl - //<< " " << medialVec.name() - //<< " : nearest point on medial axis" << nl + << " " << medialVec.name() + << " : nearest point on medial axis" << nl << " " << medialRatio.name() << " : ratio of medial distance to wall distance" << nl << endl; dispVec.write(); medialDist.write(); - //medialVec.write(); + medialVec.write(); medialRatio.write(); } } @@ -996,7 +997,7 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance const pointVectorField& dispVec, const pointScalarField& medialRatio, const pointScalarField& medialDist, - //const pointVectorField& medialVec, + const pointVectorField& medialVec, List& extrudeStatus, pointField& patchDisp, @@ -1066,6 +1067,24 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance << str().name() << endl; } + autoPtr medialVecStr; + label medialVertI = 0; + if (debug) + { + medialVecStr.reset + ( + new OFstream + ( + mesh.time().path() + / "thicknessRatioExcludeMedialVec_" + + meshRefiner_.timeName() + + ".obj" + ) + ); + Info<< "Writing points with too large a extrusion distance to " + << medialVecStr().name() << endl; + } + forAll(meshPoints, patchPointI) { if (extrudeStatus[patchPointI] != NOEXTRUDE) @@ -1082,12 +1101,9 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance vector n = patchDisp[patchPointI] / (mag(patchDisp[patchPointI]) + VSMALL); - //vector mVec = mesh.points()[pointI]-medialVec[pointI]; - //scalar mDist = mag(mVec); - //scalar thicknessRatio = - // (n&mVec) - // *thickness[patchPointI] - // /(mDist+VSMALL); + vector mVec = mesh.points()[pointI]-medialVec[pointI]; + mVec /= mag(mVec)+VSMALL; + thicknessRatio *= (n&mVec); if (thicknessRatio > maxThicknessToMedialRatio) { @@ -1103,8 +1119,9 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance minThickness[patchPointI] +thickness[patchPointI] ) - //<< " since near medial at:" << medialVec[pointI] - //<< " with thicknessRatio:" << thicknessRatio + << " medial direction:" << mVec + << " extrusion direction:" << n + << " with thicknessRatio:" << thicknessRatio << endl; } @@ -1124,6 +1141,16 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance vertI++; str()<< "l " << vertI-1 << ' ' << vertI << nl; } + if (medialVecStr.valid()) + { + const point& pt = mesh.points()[pointI]; + meshTools::writeOBJ(medialVecStr(), pt); + medialVertI++; + meshTools::writeOBJ(medialVecStr(), medialVec[pointI]); + medialVertI++; + medialVecStr()<< "l " << medialVertI-1 + << ' ' << medialVertI << nl; + } } } } @@ -1228,6 +1255,15 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance ) )() ); + + // Above move will have changed the instance only on the points (which + // is correct). + // However the previous mesh written will be the mesh with layers + // (see autoLayerDriver.C) so we now have to force writing all files + // so we can easily step through time steps. Note that if you + // don't write the mesh with layers this is not necessary. + meshRefiner_.mesh().setInstance(meshRefiner_.timeName()); + meshRefiner_.write ( debug,