ENH: motionSmoother: encapsulate point calculation like motionSolver

This commit is contained in:
mattijs
2013-11-18 10:48:17 +00:00
parent 867d5088a7
commit ae41b74b57
5 changed files with 117 additions and 81 deletions

View File

@ -872,10 +872,8 @@ void Foam::motionSmoother::correctBoundaryConditions
} }
Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
( void Foam::motionSmoother::modifyMotionPoints(pointField& newPoints) const
pointField& newPoints
)
{ {
// Correct for 2-D motion // Correct for 2-D motion
if (twoDCorrector_.required()) if (twoDCorrector_.required())
@ -892,8 +890,8 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
const pointField& oldPoints = mesh_.points(); const pointField& oldPoints = mesh_.points();
const edgeList& edges = mesh_.edges(); const edgeList& edges = mesh_.edges();
const labelList& neIndices = twoDCorrector().normalEdgeIndices(); const labelList& neIndices = twoDCorrector_.normalEdgeIndices();
const vector& pn = twoDCorrector().planeNormal(); const vector& pn = twoDCorrector_.planeNormal();
forAll(neIndices, i) forAll(neIndices, i)
{ {
@ -915,19 +913,19 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
if (debug) if (debug)
{ {
Pout<< "motionSmoother::movePoints : testing sync of newPoints." Pout<< "motionSmoother::modifyMotionPoints : testing sync of newPoints."
<< endl; << endl;
testSyncPositions(newPoints, 1e-6*mesh_.bounds().mag()); testSyncPositions(newPoints, 1e-6*mesh_.bounds().mag());
} }
}
// Move actual mesh points. Make sure to delete tetBasePtIs so it
// gets rebuilt. void Foam::motionSmoother::movePoints()
{
// Make sure to clear out tetPtIs since used in checks (sometimes, should
// really check)
mesh_.clearAdditionalGeom(); mesh_.clearAdditionalGeom();
tmp<scalarField> tsweptVol = mesh_.movePoints(newPoints);
pp_.movePoints(mesh_.points()); pp_.movePoints(mesh_.points());
return tsweptVol;
} }
@ -983,6 +981,79 @@ bool Foam::motionSmoother::scaleMesh
} }
Foam::tmp<Foam::pointField> Foam::motionSmoother::curPoints() const
{
// Set newPoints as old + scale*displacement
// Create overall displacement with same b.c.s as displacement_
wordList actualPatchTypes;
{
const pointBoundaryMesh& pbm = displacement_.mesh().boundary();
actualPatchTypes.setSize(pbm.size());
forAll(pbm, patchI)
{
actualPatchTypes[patchI] = pbm[patchI].type();
}
}
wordList actualPatchFieldTypes;
{
const pointVectorField::GeometricBoundaryField& pfld =
displacement_.boundaryField();
actualPatchFieldTypes.setSize(pfld.size());
forAll(pfld, patchI)
{
if (isA<fixedValuePointPatchField<vector> >(pfld[patchI]))
{
// Get rid of funny
actualPatchFieldTypes[patchI] =
fixedValuePointPatchField<vector>::typeName;
}
else
{
actualPatchFieldTypes[patchI] = pfld[patchI].type();
}
}
}
pointVectorField totalDisplacement
(
IOobject
(
"totalDisplacement",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
scale_*displacement_,
actualPatchFieldTypes,
actualPatchTypes
);
correctBoundaryConditions(totalDisplacement);
if (debug)
{
Pout<< "scaleMesh : testing sync of totalDisplacement" << endl;
testSyncField
(
totalDisplacement,
maxMagEqOp(),
vector::zero, // null value
1e-6*mesh_.bounds().mag()
);
}
tmp<pointField> tnewPoints(oldPoints_ + totalDisplacement.internalField());
// Correct for 2-D motion
modifyMotionPoints(tnewPoints());
return tnewPoints;
}
bool Foam::motionSmoother::scaleMesh bool Foam::motionSmoother::scaleMesh
( (
labelList& checkFaces, labelList& checkFaces,
@ -1052,60 +1123,18 @@ bool Foam::motionSmoother::scaleMesh
vector::zero // null value vector::zero // null value
); );
// Set newPoints as old + scale*displacement
pointField newPoints;
{
// Create overall displacement with same b.c.s as displacement_
wordList actualPatchTypes;
{
const pointBoundaryMesh& pbm = displacement_.mesh().boundary();
actualPatchTypes.setSize(pbm.size());
forAll(pbm, patchI)
{
actualPatchTypes[patchI] = pbm[patchI].type();
}
}
pointVectorField totalDisplacement
(
IOobject
(
"totalDisplacement",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
scale_*displacement_,
displacement_.boundaryField().types(),
actualPatchTypes
);
correctBoundaryConditions(totalDisplacement);
if (debug)
{
Pout<< "scaleMesh : testing sync of totalDisplacement" << endl;
testSyncField
(
totalDisplacement,
maxMagEqOp(),
vector::zero, // null value
1e-6*mesh_.bounds().mag()
);
}
newPoints = oldPoints_ + totalDisplacement.internalField();
}
Info<< "Moving mesh using displacement scaling :" Info<< "Moving mesh using displacement scaling :"
<< " min:" << gMin(scale_.internalField()) << " min:" << gMin(scale_.internalField())
<< " max:" << gMax(scale_.internalField()) << " max:" << gMax(scale_.internalField())
<< endl; << endl;
// Get points using current displacement and scale. Optionally 2D corrected.
pointField newPoints(curPoints());
// Move. No need to do 2D correction since curPoints already done that.
mesh_.movePoints(newPoints);
movePoints();
// Move
movePoints(newPoints);
// Check. Returns parallel number of incorrect faces. // Check. Returns parallel number of incorrect faces.
faceSet wrongFaces(mesh_, "wrongFaces", mesh_.nFaces()/100+100); faceSet wrongFaces(mesh_, "wrongFaces", mesh_.nFaces()/100+100);

View File

@ -403,9 +403,11 @@ public:
// bc's. // bc's.
void correctBoundaryConditions(pointVectorField&) const; void correctBoundaryConditions(pointVectorField&) const;
//- Move mesh. Does 2D correction (modifies passed pointField) and //- Apply optional point constraint (2d correction)
// polyMesh::movePoints. Returns swept volumes. void modifyMotionPoints(pointField& newPoints) const;
tmp<scalarField> movePoints(pointField&);
//- Get the current points (oldPoints+scale*displacement)
tmp<pointField> curPoints() const;
//- Set the errorReduction (by how much to scale the displacement //- Set the errorReduction (by how much to scale the displacement
// at error locations) parameter. Returns the old value. // at error locations) parameter. Returns the old value.
@ -446,9 +448,14 @@ public:
const label nAllow = 0 const label nAllow = 0
); );
//- Update topology
//- Update for new mesh geometry
void movePoints();
//- Update for new mesh topology
void updateMesh(); void updateMesh();
//- Check mesh with mesh settings in dict. Collects incorrect faces //- Check mesh with mesh settings in dict. Collects incorrect faces
// in set. Returns true if one or more faces in error. // in set. Returns true if one or more faces in error.
// Parallel ok. // Parallel ok.

View File

@ -3522,7 +3522,9 @@ void Foam::autoLayerDriver::addLayers
} }
// Reset mesh points and start again // Reset mesh points and start again
meshMover().movePoints(oldPoints); mesh.movePoints(oldPoints);
// Update meshmover for change of mesh geometry
meshMover().movePoints();
meshMover().correct(); meshMover().correct();

View File

@ -58,7 +58,9 @@ class layerParameters;
class autoLayerDriver class autoLayerDriver
{ {
// Static data members public:
// Public data types
//- Extrusion controls //- Extrusion controls
enum extrudeMode enum extrudeMode
@ -69,6 +71,7 @@ class autoLayerDriver
/*!< faces locally */ /*!< faces locally */
}; };
private:
// Private classes // Private classes

View File

@ -1756,19 +1756,10 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance
Info<< "Writing wanted-displacement mesh (possibly illegal) to " Info<< "Writing wanted-displacement mesh (possibly illegal) to "
<< meshRefiner_.timeName() << endl; << meshRefiner_.timeName() << endl;
pointField oldPoints(mesh.points()); pointField oldPoints(mesh.points());
vectorField totalDisp
( meshRefiner_.mesh().movePoints(meshMover.curPoints());
meshMover.scale().internalField() // Warn meshMover for changed geometry
* displacement.internalField() meshMover.movePoints();
);
syncTools::syncPointList
(
mesh,
totalDisp,
minMagSqrEqOp<point>(),
vector(GREAT, GREAT, GREAT)
);
meshMover.movePoints((mesh.points()+totalDisp)());
// Above move will have changed the instance only on the points (which // Above move will have changed the instance only on the points (which
// is correct). // is correct).
@ -1791,7 +1782,11 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance
dispVec.write(); dispVec.write();
medialDist.write(); medialDist.write();
medialRatio.write(); medialRatio.write();
meshMover.movePoints(oldPoints);
// Move mesh back
meshRefiner_.mesh().movePoints(oldPoints);
// Warn meshMover for changed geometry
meshMover.movePoints();
} }