From f4109dc68b3ac67356605ce0bfe775b752714e36 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 26 Oct 2012 16:18:45 +0100 Subject: [PATCH 01/10] ENH: Further updates to fan and jump BCs --- .../derived/fan/fanFvPatchField.C | 9 ++++ .../derived/fan/fanFvPatchField.H | 7 +++ .../derived/fan/fanFvPatchFields.C | 53 +++++++++++-------- .../derived/fixedJump/fixedJumpFvPatchField.C | 5 +- .../fixedJumpAMI/fixedJumpAMIFvPatchField.C | 3 +- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C index 3a150c6f70..18d5b33242 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.C @@ -84,4 +84,13 @@ Foam::fanFvPatchField::fanFvPatchField {} +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::tmp > Foam::fanFvPatchField::jump() const +{ + return uniformJumpFvPatchField::jump(); +} + + // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H index 463ebeb543..bf0762f478 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H @@ -172,6 +172,9 @@ public: // Evaluation functions + //- Return the "jump" across the patch + tmp > jump() const; + //- Update the coefficients associated with the patch field virtual void updateCoeffs(); }; @@ -185,6 +188,10 @@ fanFvPatchField::fanFvPatchField const DimensionedField&, const dictionary& ); + +template<> +tmp > fanFvPatchField::jump() const; + template<> void fanFvPatchField::updateCoeffs(); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C index 668d43483d..7922b66fe3 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C @@ -30,18 +30,16 @@ License #include "Tuple2.H" #include "polynomial.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeTemplatePatchTypeField -( - fvPatchScalarField, - fanFvPatchScalarField -); + makeTemplatePatchTypeField + ( + fvPatchScalarField, + fanFvPatchScalarField + ); +} // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -115,15 +113,10 @@ Foam::fanFvPatchField::fanFvPatchField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -//- Specialisation of the jump-condition for the pressure template<> -void Foam::fanFvPatchField::updateCoeffs() +Foam::tmp > +Foam::fanFvPatchField::jump() const { - if (this->updated()) - { - return; - } - if (this->cyclicPatch().owner()) { const surfaceScalarField& phi = @@ -139,15 +132,33 @@ void Foam::fanFvPatchField::updateCoeffs() Un /= patch().lookupPatchField("rho"); } - this->jump_ = this->jumpTable_->value(Un); + return this->jumpTable_->value(Un); + } + else + { + return refCast > + ( + this->neighbourPatchField() + ).jump(); + } +} + + +template<> +void Foam::fanFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + if (this->cyclicPatch().owner()) + { + this->jump_ = jump(); } uniformJumpFvPatchField::updateCoeffs(); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C index e58270ec63..9ef4be21a4 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C @@ -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 @@ -138,7 +138,8 @@ template void Foam::fixedJumpFvPatchField::write(Ostream& os) const { fvPatchField::write(os); - os.writeKeyword("patchType") << "cyclic" << token::END_STATEMENT << nl; + os.writeKeyword("patchType") << this->interfaceFieldType() + << token::END_STATEMENT << nl; jump_.writeEntry("jump", os); this->writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedJumpAMI/fixedJumpAMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedJumpAMI/fixedJumpAMIFvPatchField.C index d9cdc383a3..4c3290cf2d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJumpAMI/fixedJumpAMIFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJumpAMI/fixedJumpAMIFvPatchField.C @@ -141,7 +141,8 @@ template void Foam::fixedJumpAMIFvPatchField::write(Ostream& os) const { fvPatchField::write(os); - os.writeKeyword("patchType") << "cyclicAMI" << token::END_STATEMENT << nl; + os.writeKeyword("patchType") << this->interfaceFieldType() + << token::END_STATEMENT << nl; jump_.writeEntry("jump", os); this->writeEntry("value", os); } From 725a1b3eb03759fefbd2fceae1a3b68edb19b4fd Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 26 Oct 2012 16:47:04 +0100 Subject: [PATCH 02/10] BUG: snappyHexMesh: multi-patch from surrounding regions, not raw patchIDs --- .../autoHexMeshDriver/autoSnapDriver.C | 11 +- .../autoHexMeshDriver/autoSnapDriver.H | 26 +- .../autoHexMeshDriver/autoSnapDriverFeature.C | 510 +++++++++--------- .../snapParameters/snapParameters.C | 6 +- .../snapParameters/snapParameters.H | 7 + 5 files changed, 283 insertions(+), 277 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index e358ba4ffa..54a78f477c 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -1406,9 +1406,10 @@ void Foam::autoSnapDriver::doSnap adaptPatchIDs ) ); + indirectPrimitivePatch& pp = ppPtr(); // Distance to attract to nearest feature on surface - const scalarField snapDist(calcSnapDistance(snapParams, ppPtr())); + const scalarField snapDist(calcSnapDistance(snapParams, pp)); // Construct iterative mesh mover. @@ -1420,7 +1421,7 @@ void Foam::autoSnapDriver::doSnap motionSmoother meshMover ( mesh, - ppPtr(), + pp, adaptPatchIDs, meshRefinement::makeDisplacementField(pMesh, adaptPatchIDs), motionDict @@ -1475,7 +1476,7 @@ void Foam::autoSnapDriver::doSnap } // Check for displacement being outwards. - outwardsDisplacement(ppPtr(), disp); + outwardsDisplacement(pp, disp); // Set initial distribution of displacement field (on patches) // from patchDisp and make displacement consistent with b.c. @@ -1489,8 +1490,8 @@ void Foam::autoSnapDriver::doSnap ( mesh.time().path() / "patchDisplacement_" + name(iter) + ".obj", - ppPtr().localPoints(), - ppPtr().localPoints() + disp + pp.localPoints(), + pp.localPoints() + disp ); } diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H index bd5dd86188..7cf1e79f61 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H @@ -141,14 +141,6 @@ class autoSnapDriver vectorField& pointSurfaceNormal, vectorField& pointRotation ) const; - //void calcNearestFace - //( - // const label iter, - // const indirectPrimitivePatch& pp, - // vectorField& faceDisp, - // vectorField& faceSurfaceNormal, - // vectorField& faceRotation - //) const; void calcNearestFace ( const label iter, @@ -158,15 +150,19 @@ class autoSnapDriver labelList& faceSurfaceRegion, vectorField& faceRotation ) const; - void interpolateFaceToPoint + void calcNearestFacePointProperties ( const label iter, const indirectPrimitivePatch& pp, - const List >& pointFaceDisp, - const List >& pointFaceRotation, - const List >& pointFaceCentres, - vectorField& patchDisp - //vectorField& patchRotationDisp + + const vectorField& faceDisp, + const vectorField& faceSurfaceNormal, + const labelList& faceSurfaceRegion, + + List >& pointFaceSurfNormals, + List >& pointFaceDisp, + List >& pointFaceCentres, + List& pointFacePatchID ) const; void correctAttraction ( @@ -276,6 +272,7 @@ class autoSnapDriver ( const label iter, const scalar featureCos, + const bool multiRegionFeatureSnap, const indirectPrimitivePatch&, const scalarField&, @@ -339,6 +336,7 @@ class autoSnapDriver ( const label iter, const scalar featureCos, + const bool multiRegionFeatureSnap, const indirectPrimitivePatch& pp, const scalarField& snapDist, diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C index 8bcd9c6270..f32d9ce4bd 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C @@ -321,7 +321,7 @@ void Foam::autoSnapDriver::calcNearestFace const indirectPrimitivePatch& pp, vectorField& faceDisp, vectorField& faceSurfaceNormal, - labelList& faceSurfaceRegion, + labelList& faceSurfaceGlobalRegion, vectorField& faceRotation ) const { @@ -333,8 +333,8 @@ void Foam::autoSnapDriver::calcNearestFace faceDisp = vector::zero; faceSurfaceNormal.setSize(pp.size()); faceSurfaceNormal = vector::zero; - faceSurfaceRegion.setSize(pp.size()); - faceSurfaceRegion = -1; + faceSurfaceGlobalRegion.setSize(pp.size()); + faceSurfaceGlobalRegion = -1; // Divide surfaces into zoned and unzoned labelList zonedSurfaces = surfaces.getNamedSurfaces(); @@ -419,7 +419,7 @@ void Foam::autoSnapDriver::calcNearestFace label faceI = ppFaces[hitI]; faceDisp[faceI] = hitInfo[hitI].hitPoint() - fc[hitI]; faceSurfaceNormal[faceI] = hitNormal[hitI]; - faceSurfaceRegion[faceI] = surfaces.globalRegion + faceSurfaceGlobalRegion[faceI] = surfaces.globalRegion ( hitSurface[hitI], hitRegion[hitI] @@ -477,7 +477,11 @@ void Foam::autoSnapDriver::calcNearestFace label faceI = ppFaces[hitI]; faceDisp[faceI] = hitInfo[hitI].hitPoint() - fc[hitI]; faceSurfaceNormal[faceI] = hitNormal[hitI]; - faceSurfaceRegion[faceI] = hitRegion[hitI]; + faceSurfaceGlobalRegion[faceI] = surfaces.globalRegion + ( + hitSurface[hitI], + hitRegion[hitI] + ); } } @@ -517,6 +521,169 @@ void Foam::autoSnapDriver::calcNearestFace } +// Collect (possibly remote) per point data of all surrounding faces +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// - faceSurfaceNormal +// - faceDisp +// - faceCentres&faceNormal +void Foam::autoSnapDriver::calcNearestFacePointProperties +( + const label iter, + const indirectPrimitivePatch& pp, + + const vectorField& faceDisp, + const vectorField& faceSurfaceNormal, + const labelList& faceSurfaceGlobalRegion, + + List >& pointFaceSurfNormals, + List >& pointFaceDisp, + List >& pointFaceCentres, + List& pointFacePatchID +) const +{ + const fvMesh& mesh = meshRefiner_.mesh(); + + // For now just get all surrounding face data. Expensive - should just + // store and sync data on coupled points only + // (see e.g PatchToolsNormals.C) + + pointFaceSurfNormals.setSize(pp.nPoints()); + pointFaceDisp.setSize(pp.nPoints()); + pointFaceCentres.setSize(pp.nPoints()); + pointFacePatchID.setSize(pp.nPoints()); + + // Fill local data + forAll(pp.pointFaces(), pointI) + { + const labelList& pFaces = pp.pointFaces()[pointI]; + List& pNormals = pointFaceSurfNormals[pointI]; + pNormals.setSize(pFaces.size()); + List& pDisp = pointFaceDisp[pointI]; + pDisp.setSize(pFaces.size()); + List& pFc = pointFaceCentres[pointI]; + pFc.setSize(pFaces.size()); + labelList& pFid = pointFacePatchID[pointI]; + pFid.setSize(pFaces.size()); + + forAll(pFaces, i) + { + label faceI = pFaces[i]; + pNormals[i] = faceSurfaceNormal[faceI]; + pDisp[i] = faceDisp[faceI]; + pFc[i] = pp.faceCentres()[faceI]; + //label meshFaceI = pp.addressing()[faceI]; + //pFid[i] = mesh.boundaryMesh().whichPatch(meshFaceI); + pFid[i] = globalToPatch_[faceSurfaceGlobalRegion[faceI]]; + } + } + + + // Collect additionally 'normal' boundary faces for boundaryPoints of pp + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // points on the boundary of pp should pick up non-pp normals + // as well for the feature-reconstruction to behave correctly. + // (the movement is already constrained outside correctly so it + // is only that the unconstrained attraction vector is calculated + // correctly) + { + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); + labelList patchID(pbm.patchID()); + + // Unmark all non-coupled boundary faces + forAll(pbm, patchI) + { + const polyPatch& pp = pbm[patchI]; + + if (pp.coupled() || isA(pp)) + { + forAll(pp, i) + { + label meshFaceI = pp.start()+i; + patchID[meshFaceI-mesh.nInternalFaces()] = -1; + } + } + } + + // Remove any meshed faces + forAll(pp.addressing(), i) + { + label meshFaceI = pp.addressing()[i]; + patchID[meshFaceI-mesh.nInternalFaces()] = -1; + } + + // See if pp point uses any non-meshed boundary faces + + const labelList& boundaryPoints = pp.boundaryPoints(); + forAll(boundaryPoints, i) + { + label pointI = boundaryPoints[i]; + label meshPointI = pp.meshPoints()[pointI]; + const point& pt = mesh.points()[meshPointI]; + const labelList& pFaces = mesh.pointFaces()[meshPointI]; + + List& pNormals = pointFaceSurfNormals[pointI]; + List& pDisp = pointFaceDisp[pointI]; + List& pFc = pointFaceCentres[pointI]; + labelList& pFid = pointFacePatchID[pointI]; + + forAll(pFaces, i) + { + label meshFaceI = pFaces[i]; + if (!mesh.isInternalFace(meshFaceI)) + { + label patchI = patchID[meshFaceI-mesh.nInternalFaces()]; + + if (patchI != -1) + { + vector fn = mesh.faceAreas()[meshFaceI]; + pNormals.append(fn/mag(fn)); + pDisp.append(mesh.faceCentres()[meshFaceI]-pt); + pFc.append(mesh.faceCentres()[meshFaceI]); + pFid.append(patchI); + } + } + } + } + } + + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceSurfNormals, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceDisp, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceCentres, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFacePatchID, + listPlusEqOp