Commit c2de3fa7 authored by franjo_j@hotmail.com's avatar franjo_j@hotmail.com
Browse files

Added an utility for copying of mesh parts (subset or patch) into a new

surface mesh + improvement in finding intersections


git-svn-id: https://pl5.projectlocker.com/igui/meshGeneration/svn@26 fdcce57e-7e00-11e2-b579-49867b4cea03
parent 55165eaf
......@@ -73,6 +73,7 @@ checkIrregularSurfaceConnections = $(topology)/checkIrregularSurfaceConnections
checkNonMappableCellConnections = $(topology)/checkNonMappableCellConnections
triSurfaceCleanupDuplicates = utilities/triSurfaceTools/triSurfaceCleanupDuplicates
triSurfaceCopyParts = utilities/triSurfaceTools/triSurfaceCopyParts
triSurfaceCurvatureEstimator = utilities/triSurfaceTools/triSurfaceCurvatureEstimator
triSurfacePartitioner = utilities/triSurfaceTools/triSurfacePartitioner
triSurfaceDetectMaterials = utilities/triSurfaceTools/triSurfaceDetectMaterials
......@@ -409,6 +410,8 @@ $(surfaceIntersectionsOctree)/surfaceIntersectionsOctreeIntersections.C
$(triSurfaceCleanupDuplicates)/triSurfaceCleanupDuplicates.C
$(triSurfaceCleanupDuplicates)/triSurfaceCleanupDuplicatesFunctions.C
$(triSurfaceCopyParts)/triSurfaceCopyParts.C
$(triSurfacePartitioner)/triSurfacePartitioner.C
$(triSurfacePartitioner)/triSurfacePartitionerCreateAddressing.C
......
......@@ -121,23 +121,16 @@ void cartesianMeshGenerator::surfacePreparation()
rCells.removeCells();
mesh_.write();
::exit(1);
//mesh_.write();
//::exit(1);
}
//- removes unnecessary cells and morph the boundary
//- such that there is only one boundary face per cell
//- It also checks topology of cells after morphing is performed
/* do
{
surfaceMorpherCells* cmPtr = new surfaceMorpherCells(mesh_);
cmPtr->morphMesh();
deleteDemandDrivenData(cmPtr);
} while( topologicalCleaner(mesh_).cleanTopology() );
*/
bool changed;
do
{
changed = false;
......
......@@ -525,37 +525,6 @@ inline bool triLineIntersection
const pointField& pts = surface.points();
const labelledTri& tri = surface[tI];
scalar tolSq = SMALL * tri.mag(pts);
point nearest = nearestPointOnTheTriangle(tI, surface, s);
if( magSqr(nearest - s) < tolSq )
{
intersection = nearest;
return true;
}
nearest = nearestPointOnTheTriangle(tI, surface, e);
if( magSqr(nearest - e) < tolSq )
{
intersection = nearest;
return true;
}
forAll(tri, eI)
{
const point& ep = pts[tri[eI]];
const point& ee = pts[tri[(eI+1)%3]];
point inter1, inter2;
nearestEdgePointToTheLine(s, e, ep, ee, inter1, inter2);
if( magSqr(inter1 - inter2) < tolSq )
{
intersection = inter1;
return true;
}
}
const triangle<point, point> tria
(
pts[tri[0]],
......
......@@ -36,7 +36,9 @@ Description
#include "meshOctreeCreator.H"
#include "HashSet.H"
# ifdef USE_OMP
#include <omp.h>
# endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -34,6 +34,10 @@ Description
#include "helperFunctions.H"
# ifdef USE_OMP
#include <omp.h>
# endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......@@ -142,8 +146,6 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
const VRWGraph& facetsIntersectingCell = cellsIntersectedBySurfaceFacets();
Info << "1.Here" << endl;
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 40)
# endif
......@@ -158,6 +160,7 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
}
}
# ifdef DEBUGRemoveDomains
labelList domainIds(domains_.size());
forAll(domainIds, i)
{
......@@ -171,12 +174,8 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
forAll(doms, j)
mesh_.addCellToSubset(domainIds[doms[j]], i);
}
// const label cId = mesh_.addCellSubset("domainIntersected");
// forAll(intersectedCells, cI)
// if( intersectedCells[cI].size() )
// mesh_.addCellToSubset(cId, cI);
};
# endif
//- TODO: implement the group marking algorithm properly using templates
//- find islands of cells which are not intersected by the selected domains
......@@ -187,8 +186,6 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
labelListPMG findCellGroups(intersectedCells.size(), -1);
label nGroups(0);
Info << "2. Here" << endl;
forAll(findCellGroups, cellI)
{
if( findCellGroups[cellI] != -1 )
......@@ -241,6 +238,7 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
++nGroups;
}
# ifdef DEBUGRemoveDomains
Info << "Number of groups " << nGroups << endl;
Info << "2.1 Here" << endl;
labelList groupToId(nGroups);
......@@ -252,10 +250,10 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
if( findCellGroups[i] != -1 )
mesh_.addCellToSubset(groupToId[findCellGroups[i]], i);
}
# endif
//- collect which domains are assigned to facets neighbouring
//- groups
Info << "3.Here" << endl;
List<DynList<label> > neiDomains(nGroups);
for(label faceI=0;faceI<mesh_.nInternalFaces();++faceI)
{
......@@ -280,7 +278,9 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
}
}
# ifdef DEBUGRemoveDomains
Info << "1. Nei domains " << neiDomains << endl;
# endif
//- find a common group for all cell neighbours of a group
for(label faceI=0;faceI<mesh_.nInternalFaces();++faceI)
......@@ -298,13 +298,24 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
neiDomains[groupI].removeElement(domainI);
}
}
else if( intersectedCells[nei].size() && (findCellGroups[own] != -1) )
{
const label groupI = findCellGroups[own];
forAllReverse(neiDomains[groupI], domainI)
{
const label neiDomain = neiDomains[groupI][domainI];
if( !intersectedCells[nei].contains(neiDomain) )
neiDomains[groupI].removeElement(domainI);
}
}
}
# ifdef DEBUGRemoveDomains
Info << "2. Nei domains " << neiDomains << endl;
# endif
//- check which islands of cells correspond to octree boxes
//- marked as internal boxes
Info << "4. Here" << endl;
boolList internalCells(intersectedCells.size(), false);
forAll(findCellGroups, cellI)
......@@ -315,6 +326,10 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
if( groupI < 0 )
continue;
//- do not remove cells intersected by the selected surface elements
if( intersectedCells[cellI].size() )
continue;
//- remove domains surrounded by facets in a single user-selected domain
if( neiDomains[groupI].size() != 1 )
continue;
......@@ -324,7 +339,6 @@ void removeCellsInSelectedDomains::findAndRemoveCells()
}
//- remove cells inside the selected domains
Info << "5. Here" << endl;
polyMeshGenModifier(mesh_).removeCells(internalCells);
}
......@@ -370,8 +384,6 @@ void removeCellsInSelectedDomains::removeCells()
//findLeavesInsideRegions();
Info << "Finding and removing cells" << endl;
findAndRemoveCells();
Info << "Finished removing cells in user-selected domains" << endl;
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2005-2007 Franjo Juretic
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
\*---------------------------------------------------------------------------*/
#include "triSurfaceCopyParts.H"
#include "triSurfModifier.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurfaceCopyParts::markFacetsForCopying
(
const wordList& parts,
boolList& copyFacets
) const
{
copyFacets.setSize(surf_.size());
copyFacets = false;
const geometricSurfacePatchList& patches = surf_.patches();
//- mark patches which will be removed
boolList removePatch(patches.size(), false);
forAll(patches, patchI)
{
const word name = patches[patchI].name();
forAll(parts, partI)
{
if( parts[partI] == name )
{
removePatch[patchI] = true;
break;
}
}
}
//- select facets affected by the deletion of a patch
forAll(surf_, triI)
{
if( removePatch[surf_[triI].region()] )
copyFacets[triI] = true;
}
//- mark facets contained in selected subsets
DynList<label> facetSubsetsIDs;
surf_.facetSubsetIndices(facetSubsetsIDs);
forAll(facetSubsetsIDs, i)
{
const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);
forAll(parts, partI)
{
if( parts[partI] == fsName )
{
labelListPMG containedFacets;
surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);
forAll(containedFacets, cfI)
copyFacets[containedFacets[cfI]] = true;
break;
}
}
}
}
void triSurfaceCopyParts::copySurfaceMesh
(
const boolList& copyFacets,
triSurf& s
) const
{
Info << "Starting copying surface parts" << endl;
const pointField& pts = surf_.points();
labelListPMG newPointLabel(pts.size(), -1);
label nPoints(0);
//- create the modifier and delete data if there is any
triSurfModifier sm(s);
LongList<labelledTri>& newTriangles = sm.facetsAccess();
newTriangles.clear();
sm.featureEdgesAccess().clear();
sm.patchesAccess().setSize(1);
sm.patchesAccess()[0] = geometricSurfacePatch("patch0", "patch", 0);
//- copy selected patches
forAll(copyFacets, triI)
{
if( !copyFacets[triI] )
continue;
const labelledTri& tri = surf_[triI];
labelledTri newTri;
newTri.region() = 0;
forAll(tri, pI)
{
if( newPointLabel[tri[pI]] == -1 )
{
newPointLabel[tri[pI]] = nPoints;
++nPoints;
}
newTri[pI] = newPointLabel[tri[pI]];
}
newTriangles.append(newTri);
}
Info << "Copied triangles " << newTriangles.size() << endl;
Info << "Number of vertices " << nPoints << endl;
//- copy vertices
pointField& newPts = sm.pointsAccess();
newPts.setSize(nPoints);
forAll(newPointLabel, i)
{
if( newPointLabel[i] < 0 )
continue;
newPts[newPointLabel[i]] = pts[i];
}
Info << "Finished copying surface parts" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
triSurfaceCopyParts::triSurfaceCopyParts(const triSurf& surface)
:
surf_(surface)
{}
triSurfaceCopyParts::~triSurfaceCopyParts()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurfaceCopyParts::copySurface(const wordList& patches, triSurf& s) const
{
boolList copyFacets(surf_.size(), false);
markFacetsForCopying(patches, copyFacets);
copySurfaceMesh(copyFacets, s);
}
triSurf* triSurfaceCopyParts::copySurface(const wordList& patches) const
{
boolList copyFacets(surf_.size(), false);
markFacetsForCopying(patches, copyFacets);
triSurf* sPtr = new triSurf();
copySurfaceMesh(copyFacets, *sPtr);
return sPtr;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2005-2007 Franjo Juretic
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
triSurfaceCopyParts
Description
Copies user-selected surface parts into a new surface mesh
SourceFiles
triSurfaceCopyParts.C
\*---------------------------------------------------------------------------*/
#ifndef triSurfaceCopyParts_H
#define triSurfaceCopyParts_H
#include "triSurf.H"
#include "boolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class triSurfaceCopyParts Declaration
\*---------------------------------------------------------------------------*/
class triSurfaceCopyParts
{
// Private data
//- reference to triSurf
const triSurf& surf_;
// Private member functions
//- mark facets which shall be copied
void markFacetsForCopying(const wordList&, boolList&) const;
//- copies data to a new surface mesh
void copySurfaceMesh(const boolList&, triSurf&) const;
//- Disallow default bitwise copy construct
triSurfaceCopyParts(const triSurfaceCopyParts&);
//- Disallow default bitwise assignment
void operator=(const triSurfaceCopyParts&);
public:
// Constructors
//- Construct from octree
triSurfaceCopyParts(const triSurf& surface);
// Destructor
~triSurfaceCopyParts();
// Member Functions
//- copies selected patches/subsets to an already created mesh
void copySurface(const wordList&, triSurf&) const;
//- creates a new surface mesh and copies selected patches/subsets
triSurf* copySurface(const wordList&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
copySurfaceParts.C
EXE = $(FOAM_APPBIN)/copySurfaceParts
EXE_INC = -I../../meshLibrary/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = -ltriSurface -lMeshLibrary -lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2005-2007 Franjo Juretic
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Finds feature edges and corners of a triangulated surface
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IFstream.H"
#include "fileName.H"
#include "triSurf.H"
#include "demandDrivenData.H"
#include "triSurfaceCopyParts.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
using namespace Foam;
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.clear();
argList::validArgs.append("input surface file");
argList::validArgs.append("output surface file");
argList::validArgs.append("patch/subset name");
argList args(argc, argv);
const fileName inFileName(args.args()[1]);
const fileName outFileName(args.args()[2]);