Merge branch 'collapseEdgesParallel'

This commit is contained in:
laurence
2012-05-02 17:23:01 +01:00
8 changed files with 1918 additions and 363 deletions

View File

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

View File

@ -1,6 +1,10 @@
EXE_INC = \
-I$(LIB_SRC)/dynamicMesh/lnInclude
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-IpointEdgeCollapse
EXE_LIBS = \
-ldynamicMesh \
-lmeshTools
-lmeshTools \
-lfiniteVolume

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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

@ -0,0 +1,227 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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

@ -0,0 +1,313 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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)
{
// Not marked for collapse; only happens on edges.
return false;
}
if (!valid(td))
{
operator=(w2);
return true;
}
else
{
// Same coordinate. Same string?
if (w2.collapseIndex_ < collapseIndex_)
{
// Take over string index from w2 (and also coordinate but this
// was same)
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;
}
// if (samePoint(w2.collapsePoint_))
// {
// // Same coordinate. Same string?
// if (w2.collapseIndex_ < collapseIndex_)
// {
// // Take over string index from w2 (and also coordinate but this
// // was same)
// operator=(w2);
// return true;
// }
// else
// {
// return false;
// }
// }
// else
// {
// // Find nearest coordinate
// if (magSqr(w2.collapsePoint_) < magSqr(collapsePoint_))
// {
// operator=(w2);
// return true;
// }
// 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);
}
// ************************************************************************* //

View File

@ -27,6 +27,10 @@ License
#include "polyMesh.H"
#include "polyTopoChange.H"
#include "ListOps.H"
#include "globalMeshData.H"
#include "OFstream.H"
#include "meshTools.H"
#include "syncTools.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -121,6 +125,7 @@ void Foam::edgeCollapser::filterFace(const label faceI, face& f) const
}
}
// Check for pinched face. Tries to correct
// - consecutive duplicate vertex. Removes duplicate vertex.
// - duplicate vertex with one other vertex in between (spike).
@ -190,15 +195,15 @@ void Foam::edgeCollapser::printRegions() const
if (master != -1)
{
Info<< "Region:" << regionI << nl
Pout<< "Region:" << regionI << nl
<< " master:" << master
<< ' ' << mesh_.points()[master] << nl;
<< ' ' << pointRegionMasterLocation_[regionI] << nl;
forAll(pointRegion_, pointI)
{
if (pointRegion_[pointI] == regionI && pointI != master)
{
Info<< " slave:" << pointI
Pout<< " slave:" << pointI
<< ' ' << mesh_.points()[pointI] << nl;
}
}
@ -272,6 +277,7 @@ Foam::edgeCollapser::edgeCollapser(const polyMesh& mesh)
:
mesh_(mesh),
pointRegion_(mesh.nPoints(), -1),
pointRegionMasterLocation_(mesh.nPoints() / 100),
pointRegionMaster_(mesh.nPoints() / 100),
freeRegions_()
{}
@ -289,6 +295,8 @@ bool Foam::edgeCollapser::unaffectedEdge(const label edgeI) const
bool Foam::edgeCollapser::collapseEdge(const label edgeI, const label master)
{
const pointField& points = mesh_.points();
const edge& e = mesh_.edges()[edgeI];
label pointRegion0 = pointRegion_[e[0]];
@ -310,7 +318,7 @@ bool Foam::edgeCollapser::collapseEdge(const label edgeI, const label master)
{
FatalErrorIn
("edgeCollapser::collapseEdge(const label, const label)")
<< "Problem : freeed region :" << freeRegion
<< "Problem : freed region :" << freeRegion
<< " has already master "
<< pointRegionMaster_[freeRegion]
<< abort(FatalError);
@ -327,13 +335,22 @@ bool Foam::edgeCollapser::collapseEdge(const label edgeI, const label master)
pointRegion_[e[1]] = freeRegion;
pointRegionMaster_(freeRegion) = master;
pointRegionMasterLocation_(freeRegion) = points[master];
}
else
{
// e[1] is part of collapse network, e[0] not. Add e0 to e1 region.
pointRegion_[e[0]] = pointRegion1;
if
(
pointRegionMaster_[pointRegion1] == e[0]
|| pointRegionMaster_[pointRegion1] == e[1]
)
{
pointRegionMaster_[pointRegion1] = master;
pointRegionMasterLocation_[pointRegion1] = points[master];
}
}
}
else
@ -343,7 +360,15 @@ bool Foam::edgeCollapser::collapseEdge(const label edgeI, const label master)
// e[0] is part of collapse network. Add e1 to e0 region
pointRegion_[e[1]] = pointRegion0;
if
(
pointRegionMaster_[pointRegion0] == e[0]
|| pointRegionMaster_[pointRegion0] == e[1]
)
{
pointRegionMaster_[pointRegion0] = master;
pointRegionMasterLocation_[pointRegion0] = points[master];
}
}
else if (pointRegion0 != pointRegion1)
{
@ -356,6 +381,9 @@ bool Foam::edgeCollapser::collapseEdge(const label edgeI, const label master)
// Use minRegion as region for combined net, free maxRegion.
pointRegionMaster_[minRegion] = master;
pointRegionMaster_[maxRegion] = -1;
pointRegionMasterLocation_[minRegion] = points[master];
pointRegionMasterLocation_[maxRegion] = point(0, 0, 0);
freeRegions_.insert(maxRegion);
if (minRegion != pointRegion0)
@ -380,12 +408,61 @@ bool Foam::edgeCollapser::setRefinement(polyTopoChange& meshMod)
const labelList& faceNeighbour = mesh_.faceNeighbour();
const labelListList& pointFaces = mesh_.pointFaces();
const labelListList& cellEdges = mesh_.cellEdges();
const pointZoneMesh& pointZones = mesh_.pointZones();
// Print regions:
//printRegions()
bool meshChanged = false;
// Synchronise pointRegionMasterLocation_
const globalMeshData& globalData = mesh_.globalData();
const mapDistribute& map = globalData.globalPointSlavesMap();
const indirectPrimitivePatch& coupledPatch = globalData.coupledPatch();
const labelList& meshPoints = coupledPatch.meshPoints();
const Map<label>& meshPointMap = coupledPatch.meshPointMap();
List<point> newPoints = coupledPatch.localPoints();
for (label pI = 0; pI < coupledPatch.nPoints(); ++pI)
{
const label pointRegionMaster = pointRegion_[meshPoints[pI]];
if (pointRegionMaster != -1)
{
newPoints[pI]
= pointRegionMasterLocation_[pointRegionMaster];
}
}
globalData.syncData
(
newPoints,
globalData.globalPointSlaves(),
globalData.globalPointTransformedSlaves(),
map,
minMagSqrEqOp<point>()
);
OFstream str1("newPoints_" + name(Pstream::myProcNo()) + ".obj");
forAll(pointRegion_, pI)
{
if (meshPointMap.found(pI))
{
meshTools::writeOBJ(str1, newPoints[meshPointMap[pI]]);
}
}
for (label pI = 0; pI < coupledPatch.nPoints(); ++pI)
{
const label pointRegionMaster = pointRegion_[meshPoints[pI]];
if (pointRegionMaster != -1)
{
pointRegionMasterLocation_[pointRegionMaster]
= newPoints[pI];
}
}
// Current faces (is also collapseStatus: f.size() < 3)
faceList newFaces(mesh_.faces());
@ -393,7 +470,6 @@ bool Foam::edgeCollapser::setRefinement(polyTopoChange& meshMod)
// Current cellCollapse status
boolList cellRemoved(mesh_.nCells(), false);
do
{
// Update face collapse from edge collapses
@ -521,12 +597,49 @@ bool Foam::edgeCollapser::setRefinement(polyTopoChange& meshMod)
}
}
// Modify the point location of the remaining points
forAll(pointRegion_, pointI)
{
const label pointRegion = pointRegion_[pointI];
if
(
!pointRemoved(pointI)
&& meshPointMap.found(pointI)
)
{
meshMod.modifyPoint
(
pointI,
newPoints[meshPointMap[pointI]],
pointZones.whichZone(pointI),
false
);
}
else if
(
pointRegion != -1
&& !pointRemoved(pointI)
&& !meshPointMap.found(pointI)
)
{
const point& collapsePoint
= pointRegionMasterLocation_[pointRegion];
meshMod.modifyPoint
(
pointI,
collapsePoint,
pointZones.whichZone(pointI),
false
);
}
}
const polyBoundaryMesh& boundaryMesh = mesh_.boundaryMesh();
const faceZoneMesh& faceZones = mesh_.faceZones();
// Renumber faces that use points
forAll(pointRegion_, pointI)
{
@ -585,6 +698,9 @@ bool Foam::edgeCollapser::setRefinement(polyTopoChange& meshMod)
}
}
// Print regions:
// printRegions();
return meshChanged;
}
@ -593,8 +709,10 @@ void Foam::edgeCollapser::updateMesh(const mapPolyMesh& map)
{
pointRegion_.setSize(mesh_.nPoints());
pointRegion_ = -1;
// Reset count, do not remove underlying storage
pointRegionMaster_.clear();
pointRegionMasterLocation_.clear();
freeRegions_.clear();
}

View File

@ -39,6 +39,7 @@ SourceFiles
#include "labelList.H"
#include "DynamicList.H"
#include "point.H"
#include "typeInfo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,6 +67,10 @@ class edgeCollapser
//- For every point -1 or region number
labelList pointRegion_;
//- Actual location of the point to collapse to for every region master
// point. This will be forced to be consistent across processors
DynamicList<point> pointRegionMasterLocation_;
//- -1 or master vertex for region number
DynamicList<label> pointRegionMaster_;