FEATURE: cfMesh library structure cleanup. Author: Dominik Christ. Merge: Dominik Christ.

This commit is contained in:
Dominik Christ 2015-05-15 11:28:36 +01:00
parent a90076f1c7
commit a9fefbe25b
9 changed files with 0 additions and 1216 deletions

View file

@ -1,251 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "demandDrivenData.H"
#include "symmetryPlaneOptimisation.H"
#include "polyMeshGenAddressing.H"
#include "helperFunctions.H"
#include "polyMeshGenChecks.H"
#include "meshOptimizer.H"
// #define DEBUGSearch
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void symmetryPlaneOptimisation::detectSymmetryPlanes()
{
const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
const pointFieldPMG& points = mesh_.points();
const faceListPMG& faces = mesh_.faces();
symmetryPlanes_.clear();
typedef std::map<label, std::pair<vector, label> > mapType;
mapType centreSum, normalSum;
forAll(boundaries, patchI)
{
if( boundaries[patchI].patchType() == "symmetryPlane" )
{
std::pair<vector, label>& cs = centreSum[patchI];
cs = std::pair<vector, label>(vector::zero, 0);
std::pair<vector, label>& ns = normalSum[patchI];
ns = std::pair<vector, label>(vector::zero, 0);
const label start = boundaries[patchI].patchStart();
const label end = start + boundaries[patchI].patchSize();
for(label faceI=start;faceI<end;++faceI)
{
cs.first += faces[faceI].centre(points);
ns.first += faces[faceI].normal(points);
}
cs.second = ns.second = boundaries[patchI].patchSize();
}
}
if( Pstream::parRun() )
{
//- sum up all normals and centres of all processors
//- every symmetry plane patch must be present on all processors
forAllIter(mapType, centreSum, pIter)
{
std::pair<vector, label>& cs = pIter->second;
reduce(cs.second, sumOp<label>());
reduce(cs.first, sumOp<vector>());
std::pair<vector, label>& ns = normalSum[pIter->first];
reduce(ns.first, sumOp<vector>());
ns.second = cs.second;
}
}
//- create planes corresponding to each symmetry plane
forAllConstIter(mapType, centreSum, it)
{
const point c = it->second.first / it->second.second;
const std::pair<vector, label>& ns = normalSum[it->first];
const point n = ns.first / ns.second;
symmetryPlanes_.insert(std::make_pair(it->first, plane(c, n)));
}
}
void symmetryPlaneOptimisation::pointInPlanes(VRWGraph& pointInPlanes) const
{
const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
const pointFieldPMG& points = mesh_.points();
const faceListPMG& faces = mesh_.faces();
pointInPlanes.clear();
pointInPlanes.setSize(points.size());
forAll(boundaries, patchI)
{
if( boundaries[patchI].patchType() == "symmetryPlane" )
{
const label start = boundaries[patchI].patchStart();
const label end = start + boundaries[patchI].patchSize();
for(label faceI=start;faceI<end;++faceI)
{
const face& f = faces[faceI];
forAll(f, pI)
pointInPlanes.appendIfNotIn(f[pI], patchI);
}
}
}
if( Pstream::parRun() )
{
const Map<label>& globalToLocal =
mesh_.addressingData().globalToLocalPointAddressing();
const VRWGraph& pointAtProcs = mesh_.addressingData().pointAtProcs();
const DynList<label>& neiProcs =
mesh_.addressingData().pointNeiProcs();
std::map<label, labelLongList> exchangeData;
forAll(neiProcs, i)
exchangeData[neiProcs[i]].clear();
forAllConstIter(Map<label>, globalToLocal, it)
{
const label pointI = it();
if( pointInPlanes.sizeOfRow(pointI) == 0 )
continue;
forAllRow(pointAtProcs, pointI, i)
{
const label neiProc = pointAtProcs(pointI, i);
if( neiProc == Pstream::myProcNo() )
continue;
labelLongList& dataToSend = exchangeData[neiProc];
dataToSend.append(it.key());
dataToSend.append(pointInPlanes.sizeOfRow(pointI));
forAllRow(pointInPlanes, pointI, pipI)
dataToSend.append(pointInPlanes(pointI, pipI));
}
}
labelLongList receivedData;
help::exchangeMap(exchangeData, receivedData);
for(label counter=0;counter<receivedData.size();)
{
const label pointI = globalToLocal[receivedData[counter++]];
const label size = receivedData[counter++];
for(label i=0;i<size;++i)
pointInPlanes.appendIfNotIn(pointI, receivedData[counter++]);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from mesh
symmetryPlaneOptimisation::symmetryPlaneOptimisation(polyMeshGen& mesh)
:
mesh_(mesh)
{
detectSymmetryPlanes();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
symmetryPlaneOptimisation::~symmetryPlaneOptimisation()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void symmetryPlaneOptimisation::optimizeSymmetryPlanes()
{
pointFieldPMG& points = mesh_.points();
VRWGraph pointInPlane;
pointInPlanes(pointInPlane);
forAll(pointInPlane, pointI)
{
const label nPlanes = pointInPlane.sizeOfRow(pointI);
if( nPlanes > 3 )
{
WarningIn
(
"void symmetryPlaneOptimisation::optimizeSymmetryPlanes()"
) << "Point " << pointI << " is in more than three symmetry"
<< " planes. Cannot move it" << endl;
}
point& p = points[pointI];
vector disp(vector::zero);
for(label plI=0;plI<nPlanes;++plI)
{
//- point is in a plane
std::map<label, plane>::const_iterator it =
symmetryPlanes_.find(pointInPlane(pointI, 0));
const point newP = it->second.nearestPoint(points[pointI]);
disp += newP - p;
}
p += disp;
}
labelHashSet badFaces;
polyMeshGenChecks::checkFacePyramids(mesh_, false, VSMALL, &badFaces);
if( badFaces.size() )
{
WarningIn
(
"void symmetryPlaneOptimisation::optimizeSymmetryPlanes()"
) << "Bad quality or inverted faces found in the mesh" << endl;
const label badFacesId = mesh_.addFaceSubset("invalidFaces");
forAllConstIter(labelHashSet, badFaces, it)
mesh_.addFaceToSubset(badFacesId, it.key());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -1,99 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Class
symmetryPlaneOptimisation
Description
Smoothing of symmetry planes in the mesh such that all points
are in the plane.
SourceFiles
symmetryPlaneOptimisation.C
\*---------------------------------------------------------------------------*/
#ifndef symmetryPlaneOptimisation_H
#define symmetryPlaneOptimisation_H
#include "DynList.H"
#include "polyMeshGenModifier.H"
#include "boundBox.H"
#include "labelLongList.H"
#include "boolList.H"
#include "plane.H"
#include <map>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class symmetryPlaneOptimisation Declaration
\*---------------------------------------------------------------------------*/
class symmetryPlaneOptimisation
{
// Private data
//- reference to the mesh
polyMeshGen& mesh_;
//- symmetry planes in the mesh
std::map<label, plane> symmetryPlanes_;
// Private member functions
//- detect symmetry planes
void detectSymmetryPlanes();
//- point-planes addressing
void pointInPlanes(VRWGraph&) const;
public:
// Constructors
//- Construct from mesh
symmetryPlaneOptimisation(polyMeshGen& mesh);
// Destructor
~symmetryPlaneOptimisation();
// Member Functions
//- move vertices to the symmetry planes
void optimizeSymmetryPlanes();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,171 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "triSurface2DCheck.H"
#include "triSurfModifier.H"
#include "boundBox.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurface2DCheck::createCovarianceMatrix()
{
const vectorField& fNormals = surf_.facetNormals();
//- find the normal vector of the best-fitting plane
covarianceMatrix_ = symmTensor::zero;
forAll(fNormals, tI)
{
vector fn = fNormals[tI];
fn /= (mag(fn) + VSMALL);
covarianceMatrix_ += symm(fn * fn);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
triSurface2DCheck::triSurface2DCheck(const triSurf& surface)
:
surf_(surface),
covarianceMatrix_(symmTensor::zero)
{
createCovarianceMatrix();
}
triSurface2DCheck::~triSurface2DCheck()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool triSurface2DCheck::is2DSurface() const
{
const pointField& points = surf_.points();
const vector eigenVal = eigenValues(covarianceMatrix_);
//- the smallest eigenvalue must be zero in case all face normals
//- lie in a plane
if( mag(eigenVal[0]) > SMALL )
{
WarningIn("bool triSurface2DCheck::is2DSurface() const")
<< "Surface mesh is in 3D space!"
<< " This may result in an invalid mesh!" << endl;
return false;
}
//- calculate the plane normal as a cross prduct of the two
//- eigenVectors spanning the plane
const vector n
(
eigenVector(covarianceMatrix_, eigenVal[1]) ^
eigenVector(covarianceMatrix_, eigenVal[2])
);
//- check if the plane is in the x-y plane of the coordinate system
if( mag(n.x()) > SMALL || mag(n.y()) > SMALL )
{
//- this could be a 2D surface, but it is not in the x-y plane
WarningIn("bool triSurface2DCheck::is2DSurface() const")
<< "The surface mesh IS NOT IN THE X-Y PLANE!!!!"
<< " This will result in a mesh without any cells" << endl;
return false;
}
//- check if the points in the 2D surface have uniform z coordinates
boundBox bb(points);
forAll(points, pI)
{
const point& p = points[pI];
if
(
mag(p.z() - bb.max().z()) > SMALL &&
mag(p.z() - bb.min().z()) > SMALL
)
{
WarningIn("bool triSurface2DCheck::is2DSurface() const")
<< "z coordinates of the 2D surface are not uniform" << endl;
return false;
}
}
Info << "Detected a 2D surface in the x-y plane" << endl;
return true;
}
void triSurface2DCheck::createSubsets()
{
const pointField& points = surf_.points();
const vectorField& fNormals = surf_.facetNormals();
//- create a subset containing faces having non-zero z coordinate
//- of the normals
triSurf& surf = const_cast<triSurf&>(surf_);
const label badFacetsId = surf.addFacetSubset("badFacets");
forAll(fNormals, triI)
{
vector fn = fNormals[triI];
fn /= (mag(fn) + VSMALL);
if( mag(fn.z()) > SMALL )
surf.addFacetToSubset(badFacetsId, triI);
}
//- create a subset containing points which are not
//- in z-min and z-max planes
const label badPointsId = surf.addPointSubset("badPointsId");
boundBox bb(points);
forAll(points, pI)
{
const point& p = points[pI];
if
(
mag(p.z() - bb.max().z()) > SMALL &&
mag(p.z() - bb.min().z()) > SMALL
)
{
surf.addPointToSubset(badPointsId, pI);
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -1,98 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Class
triSurface2DCheck
Description
SourceFiles
triSurface2DCheck.C
\*---------------------------------------------------------------------------*/
#ifndef triSurface2DCheck_H
#define triSurface2DCheck_H
#include "triSurf.H"
#include "symmTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class triSurface2DCheck Declaration
\*---------------------------------------------------------------------------*/
class triSurface2DCheck
{
// Private data
//- reference to triSurf
const triSurf& surf_;
//- covariance matrix
symmTensor covarianceMatrix_;
// Private member functions
//- create covariance matrix
void createCovarianceMatrix();
//- Disallow default bitwise copy construct
triSurface2DCheck(const triSurface2DCheck&);
//- Disallow default bitwise assignment
void operator=(const triSurface2DCheck&);
public:
// Constructors
//- Construct from octree
triSurface2DCheck(const triSurf& surface);
// Destructor
~triSurface2DCheck();
// Member Functions
//- checks if the surface is a 2D triangulation
bool is2DSurface() const;
//- create subset containing invalid facets
void createSubsets();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,56 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "triSurfaceCleanupDuplicateTriangles.H"
#include "triSurf.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
triSurfaceCleanupDuplicateTriangles::triSurfaceCleanupDuplicateTriangles
(
triSurf& surf
)
:
surf_(surf),
newTriangleLabel_()
{
checkDuplicateTriangles();
}
triSurfaceCleanupDuplicateTriangles::~triSurfaceCleanupDuplicateTriangles()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -1,98 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Class
triSurfaceCleanupDuplicates
Description
Removes duplicate triangles from the surface.
SourceFiles
triSurfaceCleanupDuplicateTriangles.C
triSurfaceCleanupDuplicateTrianglesFunctions.C
\*---------------------------------------------------------------------------*/
#ifndef triSurfaceCleanupDuplicateTriangles_H
#define triSurfaceCleanupDuplicateTriangles_H
#include "VRWGraph.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class triSurf;
/*---------------------------------------------------------------------------*\
Class triSurfaceCleanupDuplicateTriangles Declaration
\*---------------------------------------------------------------------------*/
class triSurfaceCleanupDuplicateTriangles
{
// Private data
//- reference to triSurf
triSurf& surf_;
//- new triangle labels in case some of them is removed
labelLongList newTriangleLabel_;
// Private member functions
//- Check duplicate triangles
void checkDuplicateTriangles();
//- Disallow default bitwise copy construct
triSurfaceCleanupDuplicateTriangles
(
const triSurfaceCleanupDuplicateTriangles&
);
//- Disallow default bitwise assignment
void operator=(const triSurfaceCleanupDuplicateTriangles&);
public:
// Constructors
//- Construct from triSurf
triSurfaceCleanupDuplicateTriangles(triSurf&);
// Destructor
~triSurfaceCleanupDuplicateTriangles();
// Member Functions
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -1,100 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "triSurfaceCleanupDuplicateTriangles.H"
#include "triSurfModifier.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurfaceCleanupDuplicateTriangles::checkDuplicateTriangles()
{
labelLongList newTriangleLabel(surf_.size(), -1);
const VRWGraph& pointTriangles = surf_.pointFacets();
//- check if there exist duplicate triangles
label counter(0);
forAll(surf_, triI)
{
if( newTriangleLabel[triI] != -1 )
continue;
newTriangleLabel[triI] = counter;
++counter;
const labelledTri& tri = surf_[triI];
forAll(pointTriangles[tri[0]], ptI)
{
const label triJ = pointTriangles(tri[0], ptI);
if( triJ <= triI )
continue;
const labelledTri& otherTri = surf_[triJ];
if( tri == otherTri )
newTriangleLabel[triJ] = newTriangleLabel[triI];
}
}
Info << "Found " << (newTriangleLabel.size()-counter)
<< " duplicate triangles" << endl;
//- return if there exist no duplicate triangles
if( counter == newTriangleLabel.size() )
return;
Info << "Current number of triangles" << surf_.size() << endl;
Info << "New number of triangles " << counter << endl;
//- create new list of triangles and store it in the surface mesh
LongList<labelledTri> newTriangles(counter);
forAll(newTriangleLabel, triI)
{
newTriangles[newTriangleLabel[triI]] = surf_[triI];
}
triSurfModifier(surf_).facetsAccess().transfer(newTriangles);
surf_.updateFacetsSubsets(newTriangleLabel);
surf_.clearAddressing();
surf_.clearGeometry();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -1,240 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "triSurfaceImportSurfaceAsSubset.H"
#include "meshOctree.H"
#include "meshOctreeCreator.H"
#include "helperFunctions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurfaceImportSurfaceAsSubset::createOctree
(
const triSurf& surf,
meshOctree& octree
)
{
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
triSurfaceImportSurfaceAsSubset::triSurfaceImportSurfaceAsSubset(triSurf& surface)
:
surf_(surface),
octreePtr_(NULL)
{}
triSurfaceImportSurfaceAsSubset::~triSurfaceImportSurfaceAsSubset()
{
deleteDemandDrivenData(octreePtr_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void triSurfaceImportSurfaceAsSubset::addSurfaceAsSubset
(
const triSurf& importSurf,
const word& subsetName,
const scalar angleTol
)
{
if( !octreePtr_ )
{
octreePtr_ = new meshOctree(surf_);
meshOctreeCreator(*octreePtr_).createOctreeWithRefinedBoundary
(
direction(20),
15
);
}
const pointField& points = surf_.points();
const vectorField& fNornals = surf_.facetNormals();
const vectorField& fCentres = surf_.facetCentres();
labelList nearestTriangle(importSurf.size(), -1);
//- check which triangles in the surface fit best to the centres of the
//- triangles in the import surface
const pointField& importSurfPoints = importSurf.points();
const vectorField& importFaceCentres = importSurf.facetCentres();
const vectorField& importFaceNormals = importSurf.facetNormals();
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 40)
# endif
forAll(nearestTriangle, triI)
{
point np;
scalar dSq;
label nt, patch;
octreePtr_->findNearestSurfacePoint
(
np,
dSq,
nt,
patch,
importFaceCentres[triI]
);
//- find the longest edge distance
scalar maxEdgeDSq(0.);
const labelledTri& tri = importSurf[triI];
forAll(tri, pI)
{
const point& s = importSurfPoints[tri[pI]];
const point& e = importSurfPoints[tri[(pI+1)%3]];
maxEdgeDSq = max(maxEdgeDSq, magSqr(e - s));
}
//- check if the triangle has been found
if( (nt < 0) || (dSq > 0.09 * maxEdgeDSq) )
{
Warning << "Could not find a matching triangle " << endl;
Warning << "It seems that your surface meshes do not overlap" << endl;
continue;
}
vector nTri = importFaceNormals[triI];
const scalar magSqrTri = magSqr(nTri);
//- skip sliver triangles
if( magSqrTri < VSMALL )
continue;
vector normal = fNornals[nt];
const scalar dSqNormal = magSqr(normal);
//- skip sliver triangles
if( dSqNormal < VSMALL )
continue;
if( ((nTri & normal) / (magSqrTri * dSqNormal)) > angleTol )
nearestTriangle[triI] = nt;
}
meshOctree otherSurfOctree(importSurf);
meshOctreeCreator(otherSurfOctree).createOctreeWithRefinedBoundary(20, 15);
//- search for nearest facets in the import surface
DynList<label> containedTriangles;
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 40) private(containedTriangles)
# endif
forAll(surf_, triI)
{
//- find the bounding box and the ize of the triangle
boundBox bb(fCentres[triI], fCentres[triI]);
scalar maxEdgeDSq(0.);
const labelledTri& tri = surf_[triI];
forAll(tri, pI)
{
//- bounding box of the surface triangle
bb.min() = min(bb.min(), points[tri[pI]]);
bb.max() = max(bb.max(), points[tri[pI]]);
const point& s = points[tri[pI]];
const point& e = points[tri[(pI+1)%3]];
maxEdgeDSq = max(maxEdgeDSq, magSqr(e - s));
}
//- find the nearest triangle in the surface which shall be imported
otherSurfOctree.findTrianglesInBox(bb, containedTriangles);
label nt(-1);
scalar dSq(VGREAT);
forAll(containedTriangles, ctI)
{
const point p =
help::nearestPointOnTheTriangle
(
containedTriangles[ctI],
importSurf,
fCentres[triI]
);
const scalar distSq = magSqr(p - fCentres[triI]);
if( distSq < dSq )
{
nt = containedTriangles[ctI];
dSq = distSq;
}
}
//- check if the triangle has been found
if( (nt < 0) || (dSq > 0.09 * maxEdgeDSq) )
continue;
//- skip firther checkes f it has found the same triangle
if( nearestTriangle[nt] == triI )
continue;
vector nTri = fNornals[triI];
const scalar magSqrTri = magSqr(nTri);
//- skip sliver triangles
if( magSqrTri < VSMALL )
continue;
vector normal = importFaceNormals[nt];
const scalar dSqNormal = magSqr(normal);
//- skip sliver triangles
if( dSqNormal < VSMALL )
continue;
if( ((nTri & normal) / (magSqrTri * dSqNormal)) > angleTol )
nearestTriangle[nt] = triI;
}
//- create a facet subset in the surface mesh and add the facets into it
const label subsetId = surf_.addFacetSubset(subsetName);
forAll(nearestTriangle, triI)
{
if( nearestTriangle[triI] < 0 )
continue;
surf_.addFacetToSubset(subsetId, nearestTriangle[triI]);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -1,103 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | cfMesh: A library for mesh generation
\\ / O peration |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
This file is part of cfMesh.
cfMesh 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.
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Class
triSurfaceImportSurfaceAsSubset
Description
Creates a subset in the master surface consisting of facets which are
near the other surface
SourceFiles
triSurfaceImportSurfaceAsSubset.C
\*---------------------------------------------------------------------------*/
#ifndef triSurfaceImportSurfaceAsSubset_H
#define triSurfaceImportSurfaceAsSubset_H
#include "triSurf.H"
#include "boolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class meshOctree;
/*---------------------------------------------------------------------------*\
Class triSurfaceImportSurfaceAsSubset Declaration
\*---------------------------------------------------------------------------*/
class triSurfaceImportSurfaceAsSubset
{
// Private data
//- reference to triSurf
triSurf& surf_;
//- pointer to meshOctree, needed for searching on the master surface
meshOctree* octreePtr_;
// Private member functions
void createOctree(const triSurf&, meshOctree&);
//- Disallow default bitwise copy construct
triSurfaceImportSurfaceAsSubset(const triSurfaceImportSurfaceAsSubset&);
//- Disallow default bitwise assignment
void operator=(const triSurfaceImportSurfaceAsSubset&);
public:
// Constructors
//- Construct from triSurf
triSurfaceImportSurfaceAsSubset(triSurf& surface);
// Destructor
~triSurfaceImportSurfaceAsSubset();
// Member Functions
//- finds the nearest faces in the surface to the import surf
//- and creates a subset
void addSurfaceAsSubset
(
const triSurf& importSurf,
const word& subsetName,
const scalar angleTol = 5.*M_PI/180.
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //