2013-10-11 13:31:14 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2013-10-11 13:31:14 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2013-10-11 13:31:14 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2013-10-11 13:31:14 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2013-10-11 13:31:14 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2013-10-11 13:31:14 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2013-10-11 13:31:14 +00:00
|
|
|
|
|
|
|
Application
|
|
|
|
smoothMesh
|
|
|
|
|
|
|
|
Description
|
|
|
|
Smoothing mesh using Laplacian smoothing
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
|
|
|
#include "timeSelector.H"
|
2013-11-04 14:10:04 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2013-10-11 13:31:14 +00:00
|
|
|
#include "fvMesh.H"
|
|
|
|
#include "boolList.H"
|
|
|
|
#include "emptyPolyPatch.H"
|
|
|
|
#include "twoDPointCorrector.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
timeSelector::addOptions();
|
|
|
|
|
|
|
|
Foam::argList::validOptions.insert("smoothPatches", "");
|
|
|
|
|
|
|
|
# include "setRootCase.H"
|
|
|
|
# include "createTime.H"
|
|
|
|
instantList timeDirs = timeSelector::select0(runTime, args);
|
|
|
|
# include "createMesh.H"
|
|
|
|
|
|
|
|
// bool smoothPatches = args.optionFound("smoothPatches");
|
|
|
|
// if(smoothPatches)
|
|
|
|
// Info << "Smoothing patches" << nl << endl;
|
|
|
|
|
|
|
|
// Smooth internal points
|
|
|
|
|
|
|
|
const vectorField& oldPoints = mesh.points();
|
|
|
|
|
|
|
|
vectorField newPoints = oldPoints;
|
|
|
|
|
|
|
|
if (mesh.nGeometricD() == 3)
|
|
|
|
{
|
|
|
|
Info << "3-D mesh" << endl;
|
|
|
|
|
|
|
|
const labelListList& pointEdges = mesh.pointEdges();
|
|
|
|
const edgeList& edges = mesh.edges();
|
|
|
|
|
|
|
|
boolList fixedPoints(newPoints.size(), false);
|
|
|
|
|
|
|
|
forAll(mesh.boundaryMesh(), patchI)
|
|
|
|
{
|
|
|
|
const labelList& meshPoints =
|
|
|
|
mesh.boundaryMesh()[patchI].meshPoints();
|
|
|
|
|
|
|
|
forAll(meshPoints, pointI)
|
|
|
|
{
|
|
|
|
fixedPoints[meshPoints[pointI]] = true;
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
scalarField residual(newPoints.size(), 0);
|
|
|
|
label counter = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
forAll(newPoints, pointI)
|
|
|
|
{
|
|
|
|
if (!fixedPoints[pointI])
|
|
|
|
{
|
|
|
|
vector curNewPoint = vector::zero;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
scalar sumW = 0;
|
|
|
|
|
|
|
|
forAll(pointEdges[pointI], eI)
|
|
|
|
{
|
|
|
|
label curEdgeIndex = pointEdges[pointI][eI];
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
const edge& curEdge = edges[curEdgeIndex];
|
|
|
|
|
|
|
|
vector d =
|
|
|
|
newPoints[curEdge.otherVertex(pointI)]
|
|
|
|
- newPoints[pointI];
|
|
|
|
|
|
|
|
scalar w = 1.0;
|
|
|
|
|
|
|
|
curNewPoint += w*d;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
sumW += w;
|
|
|
|
}
|
|
|
|
|
|
|
|
curNewPoint /= sumW;
|
|
|
|
|
|
|
|
curNewPoint += newPoints[pointI];
|
|
|
|
|
|
|
|
residual[pointI] = mag(curNewPoint - newPoints[pointI]);
|
|
|
|
|
|
|
|
newPoints[pointI] = curNewPoint;
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 20:22:30 +00:00
|
|
|
|
|
|
|
// smoothed patch points independently
|
|
|
|
// but we do not smooth points on the boundary of the patch
|
|
|
|
// we reset these points
|
|
|
|
// problem: we need to smooth feature edges separately
|
|
|
|
// if(smoothPatches)
|
|
|
|
// {
|
|
|
|
// forAll(mesh.boundaryMesh(), patchI)
|
|
|
|
// {
|
|
|
|
// const labelList& meshPoints =
|
|
|
|
// mesh.boundaryMesh()[patchI].meshPoints();
|
|
|
|
|
|
|
|
// forAll(meshPoints, pointI)
|
|
|
|
// {
|
|
|
|
// label pointID = meshPoints[pointI];
|
|
|
|
// vector curNewPoint = vector::zero;
|
|
|
|
// scalar sumW = 0;
|
|
|
|
|
|
|
|
// forAll(pointEdges[pointID], eI)
|
|
|
|
// {
|
|
|
|
// label curEdgeIndex = pointEdges[pointID][eI];
|
|
|
|
// const edge& curEdge = edges[curEdgeIndex];
|
|
|
|
|
|
|
|
// // use only boundary points
|
|
|
|
// label otherPointID = curEdge.otherVertex(pointID);
|
|
|
|
// if(fixedPoints[otherPointID])
|
|
|
|
// {
|
|
|
|
// vector d =
|
|
|
|
// newPoints[otherPointID]
|
|
|
|
// - newPoints[pointID];
|
|
|
|
|
|
|
|
// scalar w = 1.0;
|
|
|
|
// curNewPoint += w*d;
|
|
|
|
// sumW += w;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// curNewPoint /= sumW;
|
|
|
|
// curNewPoint += newPoints[pointID];
|
|
|
|
// residual[pointID] = mag(curNewPoint - newPoints[pointID]);
|
|
|
|
// newPoints[pointID] = curNewPoint;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // reset boundary points
|
|
|
|
// const labelList& boundaryPoints =
|
|
|
|
// mesh.boundaryMesh()[patchI].boundaryPoints();
|
|
|
|
// forAll(boundaryPoints, bpi)
|
|
|
|
// {
|
|
|
|
// label boundaryPointID = meshPoints[boundaryPoints[bpi]];
|
|
|
|
// newPoints[boundaryPointID] = oldPoints[boundaryPointID];
|
|
|
|
// residual[boundaryPointID] = 0.0;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2013-10-11 13:31:14 +00:00
|
|
|
|
|
|
|
residual /= max(mag(newPoints - oldPoints) + SMALL);
|
|
|
|
}
|
|
|
|
while(max(residual) > 1e-3);
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
Info << "Internal points, max residual: " << max(residual)
|
2013-10-11 13:31:14 +00:00
|
|
|
<< ", num of iterations: " << counter << endl;
|
|
|
|
|
|
|
|
twoDPointCorrector twoDCorrector(mesh);
|
|
|
|
twoDCorrector.correctPoints(newPoints);
|
|
|
|
}
|
|
|
|
else // 2-D
|
|
|
|
{
|
|
|
|
Info << "2-D mesh" << endl;
|
|
|
|
|
|
|
|
forAll(mesh.boundaryMesh(), patchI)
|
|
|
|
{
|
|
|
|
if
|
|
|
|
(
|
|
|
|
mesh.boundaryMesh()[patchI].type()
|
|
|
|
== emptyPolyPatch::typeName
|
|
|
|
)
|
|
|
|
{
|
2013-11-07 20:22:30 +00:00
|
|
|
const labelList& bPoints =
|
2013-10-11 13:31:14 +00:00
|
|
|
mesh.boundaryMesh()[patchI].boundaryPoints();
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
const vectorField& oldPatchPoints =
|
2013-10-11 13:31:14 +00:00
|
|
|
mesh.boundaryMesh()[patchI].localPoints();
|
|
|
|
|
|
|
|
vectorField newPatchPoints = oldPatchPoints;
|
|
|
|
|
|
|
|
const labelListList& patchPointEdges =
|
|
|
|
mesh.boundaryMesh()[patchI].pointEdges();
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
const edgeList& patchEdges =
|
2013-10-11 13:31:14 +00:00
|
|
|
mesh.boundaryMesh()[patchI].edges();
|
|
|
|
|
|
|
|
boolList fixedPoints(newPatchPoints.size(), false);
|
|
|
|
|
|
|
|
forAll(bPoints, pointI)
|
|
|
|
{
|
|
|
|
fixedPoints[bPoints[pointI]] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
scalarField residual(newPatchPoints.size(), 0);
|
|
|
|
label counter = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
counter++;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
forAll(newPatchPoints, pointI)
|
|
|
|
{
|
|
|
|
if (!fixedPoints[pointI])
|
|
|
|
{
|
|
|
|
vector curNewPatchPoint = vector::zero;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
scalar sumW = 0;
|
|
|
|
|
|
|
|
forAll(patchPointEdges[pointI], eI)
|
|
|
|
{
|
2013-11-07 20:22:30 +00:00
|
|
|
label curEdgeIndex =
|
2013-10-11 13:31:14 +00:00
|
|
|
patchPointEdges[pointI][eI];
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
const edge& curEdge = patchEdges[curEdgeIndex];
|
|
|
|
|
|
|
|
vector d =
|
|
|
|
newPatchPoints[curEdge.otherVertex(pointI)]
|
|
|
|
- newPatchPoints[pointI];
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
scalar w = 1.0;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
curNewPatchPoint += w*d;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
sumW += w;
|
|
|
|
}
|
|
|
|
|
|
|
|
curNewPatchPoint /= sumW;
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
curNewPatchPoint += newPatchPoints[pointI];
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
residual[pointI] =
|
2013-10-11 13:31:14 +00:00
|
|
|
mag(curNewPatchPoint - newPatchPoints[pointI]);
|
|
|
|
|
|
|
|
newPatchPoints[pointI] = curNewPatchPoint;
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 20:22:30 +00:00
|
|
|
|
|
|
|
residual /=
|
2013-10-11 13:31:14 +00:00
|
|
|
max(mag(newPatchPoints - oldPatchPoints) + SMALL);
|
|
|
|
}
|
|
|
|
while(max(residual) > 1e-6);
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
Info << "Empty points, max residual: " << max(residual)
|
2013-10-11 13:31:14 +00:00
|
|
|
<< ", num of iterations: " << counter << endl;
|
|
|
|
|
2013-11-07 20:22:30 +00:00
|
|
|
const labelList& meshPoints =
|
2013-10-11 13:31:14 +00:00
|
|
|
mesh.boundaryMesh()[patchI].meshPoints();
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
forAll(meshPoints, pointI)
|
|
|
|
{
|
|
|
|
newPoints[meshPoints[pointI]] = newPatchPoints[pointI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
twoDPointCorrector twoDCorrector(mesh);
|
|
|
|
twoDCorrector.correctPoints(newPoints);
|
|
|
|
|
|
|
|
mesh.movePoints(newPoints);
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
runTime++;
|
|
|
|
|
|
|
|
runTime.write();
|
2013-11-07 20:22:30 +00:00
|
|
|
|
2013-10-11 13:31:14 +00:00
|
|
|
Info<< "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|