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
(
pointField& newPoints
)
void Foam::motionSmoother::modifyMotionPoints(pointField& newPoints) const
{
// Correct for 2-D motion
if (twoDCorrector_.required())
@ -892,8 +890,8 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
const pointField& oldPoints = mesh_.points();
const edgeList& edges = mesh_.edges();
const labelList& neIndices = twoDCorrector().normalEdgeIndices();
const vector& pn = twoDCorrector().planeNormal();
const labelList& neIndices = twoDCorrector_.normalEdgeIndices();
const vector& pn = twoDCorrector_.planeNormal();
forAll(neIndices, i)
{
@ -915,19 +913,19 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
if (debug)
{
Pout<< "motionSmoother::movePoints : testing sync of newPoints."
Pout<< "motionSmoother::modifyMotionPoints : testing sync of newPoints."
<< endl;
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();
tmp<scalarField> tsweptVol = mesh_.movePoints(newPoints);
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
(
labelList& checkFaces,
@ -1052,60 +1123,18 @@ bool Foam::motionSmoother::scaleMesh
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 :"
<< " min:" << gMin(scale_.internalField())
<< " max:" << gMax(scale_.internalField())
<< 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.
faceSet wrongFaces(mesh_, "wrongFaces", mesh_.nFaces()/100+100);

View File

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

View File

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

View File

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

View File

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