mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: motionSmoother: use weighted smoothing
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -271,9 +271,28 @@ Foam::labelHashSet Foam::motionSmoother::getPoints
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::tmp<Foam::scalarField> Foam::motionSmoother::calcEdgeWeights
|
||||||
|
(
|
||||||
|
const pointField& points
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const edgeList& edges = mesh_.edges();
|
||||||
|
|
||||||
|
tmp<scalarField> twght(new scalarField(edges.size()));
|
||||||
|
scalarField& wght = twght();
|
||||||
|
|
||||||
|
forAll(edges, edgeI)
|
||||||
|
{
|
||||||
|
wght[edgeI] = min(GREAT, 1.0/edges[edgeI].mag(points));
|
||||||
|
}
|
||||||
|
return twght;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Smooth on selected points (usually patch points)
|
// Smooth on selected points (usually patch points)
|
||||||
void Foam::motionSmoother::minSmooth
|
void Foam::motionSmoother::minSmooth
|
||||||
(
|
(
|
||||||
|
const scalarField& edgeWeights,
|
||||||
const PackedBoolList& isAffectedPoint,
|
const PackedBoolList& isAffectedPoint,
|
||||||
const labelList& meshPoints,
|
const labelList& meshPoints,
|
||||||
const pointScalarField& fld,
|
const pointScalarField& fld,
|
||||||
@ -283,7 +302,7 @@ void Foam::motionSmoother::minSmooth
|
|||||||
tmp<pointScalarField> tavgFld = avg
|
tmp<pointScalarField> tavgFld = avg
|
||||||
(
|
(
|
||||||
fld,
|
fld,
|
||||||
scalarField(mesh_.nEdges(), 1.0) // uniform weighting
|
edgeWeights //scalarField(mesh_.nEdges(), 1.0) // uniform weighting
|
||||||
);
|
);
|
||||||
const pointScalarField& avgFld = tavgFld();
|
const pointScalarField& avgFld = tavgFld();
|
||||||
|
|
||||||
@ -308,6 +327,7 @@ void Foam::motionSmoother::minSmooth
|
|||||||
// Smooth on all internal points
|
// Smooth on all internal points
|
||||||
void Foam::motionSmoother::minSmooth
|
void Foam::motionSmoother::minSmooth
|
||||||
(
|
(
|
||||||
|
const scalarField& edgeWeights,
|
||||||
const PackedBoolList& isAffectedPoint,
|
const PackedBoolList& isAffectedPoint,
|
||||||
const pointScalarField& fld,
|
const pointScalarField& fld,
|
||||||
pointScalarField& newFld
|
pointScalarField& newFld
|
||||||
@ -316,7 +336,7 @@ void Foam::motionSmoother::minSmooth
|
|||||||
tmp<pointScalarField> tavgFld = avg
|
tmp<pointScalarField> tavgFld = avg
|
||||||
(
|
(
|
||||||
fld,
|
fld,
|
||||||
scalarField(mesh_.nEdges(), 1.0) // uniform weighting
|
edgeWeights //scalarField(mesh_.nEdges(), 1.0) // uniform weighting
|
||||||
);
|
);
|
||||||
const pointScalarField& avgFld = tavgFld();
|
const pointScalarField& avgFld = tavgFld();
|
||||||
|
|
||||||
@ -337,7 +357,7 @@ void Foam::motionSmoother::minSmooth
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Scale on selected points
|
// Scale on all internal points
|
||||||
void Foam::motionSmoother::scaleField
|
void Foam::motionSmoother::scaleField
|
||||||
(
|
(
|
||||||
const labelHashSet& pointLabels,
|
const labelHashSet& pointLabels,
|
||||||
@ -378,6 +398,47 @@ void Foam::motionSmoother::scaleField
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Lower on internal points
|
||||||
|
void Foam::motionSmoother::subtractField
|
||||||
|
(
|
||||||
|
const labelHashSet& pointLabels,
|
||||||
|
const scalar f,
|
||||||
|
pointScalarField& fld
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
forAllConstIter(labelHashSet, pointLabels, iter)
|
||||||
|
{
|
||||||
|
if (isInternalPoint(iter.key()))
|
||||||
|
{
|
||||||
|
fld[iter.key()] = max(0.0, fld[iter.key()]-f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fld.correctBoundaryConditions();
|
||||||
|
applyCornerConstraints(fld);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Scale on selected points (usually patch points)
|
||||||
|
void Foam::motionSmoother::subtractField
|
||||||
|
(
|
||||||
|
const labelList& meshPoints,
|
||||||
|
const labelHashSet& pointLabels,
|
||||||
|
const scalar f,
|
||||||
|
pointScalarField& fld
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
forAll(meshPoints, i)
|
||||||
|
{
|
||||||
|
label pointI = meshPoints[i];
|
||||||
|
|
||||||
|
if (pointLabels.found(pointI))
|
||||||
|
{
|
||||||
|
fld[pointI] = max(0.0, fld[pointI]-f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::motionSmoother::isInternalPoint(const label pointI) const
|
bool Foam::motionSmoother::isInternalPoint(const label pointI) const
|
||||||
{
|
{
|
||||||
return isInternalPoint_.get(pointI) == 1;
|
return isInternalPoint_.get(pointI) == 1;
|
||||||
@ -1081,13 +1142,17 @@ bool Foam::motionSmoother::scaleMesh
|
|||||||
{
|
{
|
||||||
// Scale conflicting patch points
|
// Scale conflicting patch points
|
||||||
scaleField(pp_.meshPoints(), usedPoints, errorReduction, scale_);
|
scaleField(pp_.meshPoints(), usedPoints, errorReduction, scale_);
|
||||||
|
//subtractField(pp_.meshPoints(), usedPoints, 0.1, scale_);
|
||||||
}
|
}
|
||||||
if (smoothMesh)
|
if (smoothMesh)
|
||||||
{
|
{
|
||||||
// Scale conflicting internal points
|
// Scale conflicting internal points
|
||||||
scaleField(usedPoints, errorReduction, scale_);
|
scaleField(usedPoints, errorReduction, scale_);
|
||||||
|
//subtractField(usedPoints, 0.1, scale_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scalarField eWeights(calcEdgeWeights(oldPoints_));
|
||||||
|
|
||||||
for (label i = 0; i < nSmoothScale; i++)
|
for (label i = 0; i < nSmoothScale; i++)
|
||||||
{
|
{
|
||||||
if (adaptPatchIDs_.size())
|
if (adaptPatchIDs_.size())
|
||||||
@ -1096,6 +1161,7 @@ bool Foam::motionSmoother::scaleMesh
|
|||||||
pointScalarField oldScale(scale_);
|
pointScalarField oldScale(scale_);
|
||||||
minSmooth
|
minSmooth
|
||||||
(
|
(
|
||||||
|
eWeights,
|
||||||
isAffectedPoint,
|
isAffectedPoint,
|
||||||
pp_.meshPoints(),
|
pp_.meshPoints(),
|
||||||
oldScale,
|
oldScale,
|
||||||
@ -1107,7 +1173,7 @@ bool Foam::motionSmoother::scaleMesh
|
|||||||
{
|
{
|
||||||
// Smooth internal values
|
// Smooth internal values
|
||||||
pointScalarField oldScale(scale_);
|
pointScalarField oldScale(scale_);
|
||||||
minSmooth(isAffectedPoint, oldScale, scale_);
|
minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
|
||||||
checkFld(scale_);
|
checkFld(scale_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -229,9 +229,13 @@ class motionSmoother
|
|||||||
//- Get points used by given faces
|
//- Get points used by given faces
|
||||||
labelHashSet getPoints(const labelHashSet&) const;
|
labelHashSet getPoints(const labelHashSet&) const;
|
||||||
|
|
||||||
|
//- Calculate per-edge weight
|
||||||
|
tmp<scalarField> calcEdgeWeights(const pointField&) const;
|
||||||
|
|
||||||
//- explicit smoothing and min on all affected internal points
|
//- explicit smoothing and min on all affected internal points
|
||||||
void minSmooth
|
void minSmooth
|
||||||
(
|
(
|
||||||
|
const scalarField& edgeWeights,
|
||||||
const PackedBoolList& isAffectedPoint,
|
const PackedBoolList& isAffectedPoint,
|
||||||
const pointScalarField& fld,
|
const pointScalarField& fld,
|
||||||
pointScalarField& newFld
|
pointScalarField& newFld
|
||||||
@ -240,6 +244,7 @@ class motionSmoother
|
|||||||
//- same but only on selected points (usually patch points)
|
//- same but only on selected points (usually patch points)
|
||||||
void minSmooth
|
void minSmooth
|
||||||
(
|
(
|
||||||
|
const scalarField& edgeWeights,
|
||||||
const PackedBoolList& isAffectedPoint,
|
const PackedBoolList& isAffectedPoint,
|
||||||
const labelList& meshPoints,
|
const labelList& meshPoints,
|
||||||
const pointScalarField& fld,
|
const pointScalarField& fld,
|
||||||
@ -264,6 +269,24 @@ class motionSmoother
|
|||||||
pointScalarField&
|
pointScalarField&
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
//- Lower on internal points
|
||||||
|
void subtractField
|
||||||
|
(
|
||||||
|
const labelHashSet& pointLabels,
|
||||||
|
const scalar f,
|
||||||
|
pointScalarField&
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- As above but points have to be in meshPoints as well
|
||||||
|
// (usually to scale patch points)
|
||||||
|
void subtractField
|
||||||
|
(
|
||||||
|
const labelList& meshPoints,
|
||||||
|
const labelHashSet& pointLabels,
|
||||||
|
const scalar scale,
|
||||||
|
pointScalarField&
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Helper function. Is point internal?
|
//- Helper function. Is point internal?
|
||||||
bool isInternalPoint(const label pointI) const;
|
bool isInternalPoint(const label pointI) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user