ENH: Add edgeCollapser utility and libraries.

edgeCollapser collapses small edges and faces.
Works in parallel by using PointEdgeWave.
This commit is contained in:
laurence
2012-12-11 17:12:27 +00:00
parent a2c8736f23
commit e81813a9c2
15 changed files with 3428 additions and 1826 deletions

View File

@ -1,4 +1,3 @@
collapseEdges.C
pointEdgeCollapse/pointEdgeCollapse.C
EXE = $(FOAM_APPBIN)/collapseEdges

View File

@ -1,8 +1,7 @@
EXE_INC = \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-IpointEdgeCollapse
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-ldynamicMesh \

View File

@ -0,0 +1,85 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
root "";
case "";
instance "";
local "";
class dictionary;
object collapseDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
collapseEdgesCoeffs
{
// Edges shorter than this absolute value will be merged
minimumEdgeLength 1e-8;
// The maximum angle between two edges that share a point attached to
// no other edges
maximumMergeAngle 30;
// The amount that minimumEdgeLength will be reduced by for each
// edge if that edge's collapse generates a poor quality face
reductionFactor 0.5;
}
collapseFacesCoeffs
{
// The initial face length factor
initialFaceLengthFactor 0.5;
// The amount that initialFaceLengthFactor will be reduced by for each
// face if its collapse generates a poor quality face
reductionFactor $initialFaceLengthFactor;
// If the face can't be collapsed to an edge, and it has a span less than
// the target face length multiplied by this coefficient, collapse it
// to a point.
maxCollapseFaceToPointSideLengthCoeff 0.3;
// Allow early collapse of edges to a point
allowEarlyCollapseToPoint on;
// Fraction to premultiply maxCollapseFaceToPointSideLengthCoeff by if
// allowEarlyCollapseToPoint is enabled
allowEarlyCollapseCoeff 0.2;
// Defining how close to the midpoint (M) of the projected
// vertices line a projected vertex (X) can be before making this
// an invalid edge collapse
//
// X---X-g----------------M----X-----------g----X--X
//
// Only allow a collapse if all projected vertices are outwith
// guardFraction (g) of the distance form the face centre to the
// furthest vertex in the considered direction
guardFraction 0.1;
}
meshQualityCoeffs
{
// Name of the dictionary that has the mesh quality coefficients used
// by motionSmoother::checkMesh
meshQualityCoeffDict meshQualityDict;
// Maximum number of outer iterations is mesh quality checking is enabled
maximumIterations 30;
}
// ************************************************************************* //

View File

@ -1,51 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pointEdgeCollapse.H"
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::pointEdgeCollapse& wDist
)
{
return os
<< wDist.collapsePoint_ << wDist.collapseIndex_;
}
Foam::Istream& Foam::operator>>
(
Foam::Istream& is,
Foam::pointEdgeCollapse& wDist
)
{
return is
>> wDist.collapsePoint_ >> wDist.collapseIndex_;
}
// ************************************************************************* //

View File

@ -1,227 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::pointEdgeCollapse
Description
Determines length of string of edges walked to point.
SourceFiles
pointEdgeCollapseI.H
pointEdgeCollapse.C
\*---------------------------------------------------------------------------*/
#ifndef pointEdgeCollapse_H
#define pointEdgeCollapse_H
#include "point.H"
#include "tensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyPatch;
class polyMesh;
/*---------------------------------------------------------------------------*\
Class pointEdgeCollapse Declaration
\*---------------------------------------------------------------------------*/
class pointEdgeCollapse
{
// Private data
//- Collapse location
point collapsePoint_;
//- Collapse string index
label collapseIndex_;
// Private Member Functions
//- Evaluate distance to point.
template<class TrackingData>
inline bool update
(
const pointEdgeCollapse& w2,
const scalar tol,
TrackingData& td
);
//- Check for same coordinate
inline bool samePoint(const point& pt) const;
public:
// Constructors
//- Construct null
inline pointEdgeCollapse();
//- Construct from components
inline pointEdgeCollapse
(
const point& collapsePoint,
const label collapseIndex
);
// Member Functions
// Access
inline const point& collapsePoint() const;
inline label collapseIndex() const;
// Needed by meshWave
//- Check whether origin has been changed at all or
// still contains original (invalid) value.
template<class TrackingData>
inline bool valid(TrackingData& td) const;
//- Convert origin to relative vector to leaving point
// (= point coordinate)
template<class TrackingData>
inline void leaveDomain
(
const polyPatch& patch,
const label patchPointI,
const point& pos,
TrackingData& td
);
//- Convert relative origin to absolute by adding entering point
template<class TrackingData>
inline void enterDomain
(
const polyPatch& patch,
const label patchPointI,
const point& pos,
TrackingData& td
);
//- Apply rotation matrix to origin
template<class TrackingData>
inline void transform
(
const tensor& rotTensor,
TrackingData& td
);
//- Influence of edge on point
template<class TrackingData>
inline bool updatePoint
(
const polyMesh& mesh,
const label pointI,
const label edgeI,
const pointEdgeCollapse& edgeInfo,
const scalar tol,
TrackingData& td
);
//- Influence of different value on same point.
// Merge new and old info.
template<class TrackingData>
inline bool updatePoint
(
const polyMesh& mesh,
const label pointI,
const pointEdgeCollapse& newPointInfo,
const scalar tol,
TrackingData& td
);
//- Influence of different value on same point.
// No information about current position whatsoever.
template<class TrackingData>
inline bool updatePoint
(
const pointEdgeCollapse& newPointInfo,
const scalar tol,
TrackingData& td
);
//- Influence of point on edge.
template<class TrackingData>
inline bool updateEdge
(
const polyMesh& mesh,
const label edgeI,
const label pointI,
const pointEdgeCollapse& pointInfo,
const scalar tol,
TrackingData& td
);
//- Same (like operator==)
template<class TrackingData>
inline bool equal(const pointEdgeCollapse&, TrackingData&)
const;
// Member Operators
//Note: Used to determine whether to call update.
inline bool operator==(const pointEdgeCollapse&) const;
inline bool operator!=(const pointEdgeCollapse&) const;
// IOstream Operators
friend Ostream& operator<<(Ostream&, const pointEdgeCollapse&);
friend Istream& operator>>(Istream&, pointEdgeCollapse&);
};
//- Data associated with pointEdgeCollapse type are contiguous
template<>
inline bool contiguous<pointEdgeCollapse>()
{
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pointEdgeCollapseI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,284 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "polyMesh.H"
#include "transform.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Update this with w2.
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::update
(
const pointEdgeCollapse& w2,
const scalar tol,
TrackingData& td
)
{
if (!w2.valid(td))
{
FatalErrorIn("pointEdgeCollapse::update(..)")
<< "problem." << abort(FatalError);
}
if (w2.collapseIndex_ == -1 || collapseIndex_ == -1)
{
// Not marked for collapse; only happens on edges.
return false;
}
if (!valid(td))
{
operator=(w2);
return true;
}
else
{
// Take over w2 if it is 'better'
if (w2.collapseIndex_ < collapseIndex_)
{
// Take over string index and coordinate from w2
operator=(w2);
return true;
}
else if (w2.collapseIndex_ == collapseIndex_)
{
bool identicalPoint = samePoint(w2.collapsePoint_);
bool nearer = magSqr(w2.collapsePoint_) < magSqr(collapsePoint_);
if (nearer)
{
operator=(w2);
}
if (identicalPoint)
{
return false;
}
else
{
return nearer;
}
}
else
{
return false;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Null constructor
inline Foam::pointEdgeCollapse::pointEdgeCollapse()
:
collapsePoint_(GREAT, GREAT, GREAT),
collapseIndex_(-2)
{}
// Construct from origin, distance
inline Foam::pointEdgeCollapse::pointEdgeCollapse
(
const point& collapsePoint,
const label collapseIndex
)
:
collapsePoint_(collapsePoint),
collapseIndex_(collapseIndex)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::point& Foam::pointEdgeCollapse::collapsePoint() const
{
return collapsePoint_;
}
inline Foam::label Foam::pointEdgeCollapse::collapseIndex() const
{
return collapseIndex_;
}
inline bool Foam::pointEdgeCollapse::samePoint(const point& pt) const
{
bool isLegal1 = (cmptMin(collapsePoint_) < 0.5*GREAT);
bool isLegal2 = (cmptMin(pt) < 0.5*GREAT);
if (isLegal1 && isLegal2)
{
return mag(collapsePoint_ - pt) < 1e-9;//SMALL;
}
else
{
return isLegal1 == isLegal2;
}
}
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::valid(TrackingData& td) const
{
return collapseIndex_ != -2;
}
template<class TrackingData>
inline void Foam::pointEdgeCollapse::leaveDomain
(
const polyPatch& patch,
const label patchPointI,
const point& coord,
TrackingData& td
)
{
collapsePoint_ -= coord;
}
template<class TrackingData>
inline void Foam::pointEdgeCollapse::transform
(
const tensor& rotTensor,
TrackingData& td
)
{
collapsePoint_ = Foam::transform(rotTensor, collapsePoint_);
}
// Update absolute geometric quantities. Note that distance (dist_)
// is not affected by leaving/entering domain.
template<class TrackingData>
inline void Foam::pointEdgeCollapse::enterDomain
(
const polyPatch& patch,
const label patchPointI,
const point& coord,
TrackingData& td
)
{
// back to absolute form
collapsePoint_ += coord;
}
// Update this with information from connected edge
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::updatePoint
(
const polyMesh& mesh,
const label pointI,
const label edgeI,
const pointEdgeCollapse& edgeInfo,
const scalar tol,
TrackingData& td
)
{
return update(edgeInfo, tol, td);
}
// Update this with new information on same point
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::updatePoint
(
const polyMesh& mesh,
const label pointI,
const pointEdgeCollapse& newPointInfo,
const scalar tol,
TrackingData& td
)
{
return update(newPointInfo, tol, td);
}
// Update this with new information on same point. No extra information.
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::updatePoint
(
const pointEdgeCollapse& newPointInfo,
const scalar tol,
TrackingData& td
)
{
return update(newPointInfo, tol, td);
}
// Update this with information from connected point
template<class TrackingData>
inline bool Foam::pointEdgeCollapse::updateEdge
(
const polyMesh& mesh,
const label edgeI,
const label pointI,
const pointEdgeCollapse& pointInfo,
const scalar tol,
TrackingData& td
)
{
return update(pointInfo, tol, td);
}
template <class TrackingData>
inline bool Foam::pointEdgeCollapse::equal
(
const pointEdgeCollapse& rhs,
TrackingData& td
) const
{
return operator==(rhs);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::pointEdgeCollapse::operator==
(
const Foam::pointEdgeCollapse& rhs
) const
{
return
collapseIndex_ == rhs.collapseIndex_
&& samePoint(rhs.collapsePoint_);
}
inline bool Foam::pointEdgeCollapse::operator!=
(
const Foam::pointEdgeCollapse& rhs
) const
{
return !(*this == rhs);
}
// ************************************************************************* //