From 0180a47666d2b9d331c4e8e4a7859b101f180e4c Mon Sep 17 00:00:00 2001 From: graham Date: Wed, 5 Nov 2008 11:34:56 +0000 Subject: [PATCH] Adding patch information from surface. Changing dualMesh.obj writing to use points and faces derived during polyMesh calculation rather than recalculating. --- .../mesh/generation/CV3DMesher/CV3D.C | 1 - .../mesh/generation/CV3DMesher/CV3D.H | 7 +- .../mesh/generation/CV3DMesher/CV3DIO.C | 89 +++++-------------- .../mesh/generation/CV3DMesher/CV3DMesher.C | 2 +- .../mesh/generation/CV3DMesher/calcDualMesh.C | 47 ++++++++-- 5 files changed, 68 insertions(+), 78 deletions(-) diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3D.C b/applications/utilities/mesh/generation/CV3DMesher/CV3D.C index 9fe105c97c..860f40a28a 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3D.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3D.C @@ -527,7 +527,6 @@ void Foam::CV3D::write() writePoints("points.obj", true); writeTriangles("allTriangles.obj", false); writeTriangles("triangles.obj", true); - writeDual("dualMesh.obj"); } writeMesh(); diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H index 52c7f868ab..2448d3b093 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H @@ -422,7 +422,12 @@ public: void writeTriangles(const fileName& fName, bool internalOnly) const; //- Write dual points and faces as .obj file - void writeDual(const fileName& fName) const; + void writeDual + ( + const pointField& points, + const faceList& faces, + const fileName& fName + ) const; //- Write polyMesh void writeMesh(bool writeToTimestep = false); diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C b/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C index 58a77bcc0d..1c070842aa 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C @@ -31,7 +31,7 @@ License void Foam::CV3D::writePoints(const fileName& fName, bool internalOnly) const { - Info << "Writing points to " << fName << nl << endl; + Info<< nl << "Writing points to " << fName << nl << endl; OFstream str(fName); for @@ -49,86 +49,41 @@ void Foam::CV3D::writePoints(const fileName& fName, bool internalOnly) const } -void Foam::CV3D::writeDual(const fileName& fName) const +void Foam::CV3D::writeDual +( + const pointField& points, + const faceList& faces, + const fileName& fName +) const { - Info << "Writing dual points and faces to " << fName << nl << endl; + Info<< nl << "Writing dual points and faces to " << fName << nl << endl; + OFstream str(fName); - label dualVerti = 0; - - for - ( - Triangulation::Finite_cells_iterator cit = finite_cells_begin(); - cit != finite_cells_end(); - ++cit - ) + forAll(points, p) { - cit->cellIndex() = -1; - - if - ( - cit->vertex(0)->internalOrBoundaryPoint() - || cit->vertex(1)->internalOrBoundaryPoint() - || cit->vertex(2)->internalOrBoundaryPoint() - || cit->vertex(3)->internalOrBoundaryPoint() - ) - { - cit->cellIndex() = dualVerti; - meshTools::writeOBJ(str, topoint(dual(cit))); - dualVerti++; - } - // else - // { - // cit->cellIndex() = -1; - // } + meshTools::writeOBJ(str, points[p]); } - for - ( - Triangulation::Finite_edges_iterator eit = finite_edges_begin(); - eit != finite_edges_end(); - ++eit - ) + forAll (faces, f) { - if - ( - eit->first->vertex(eit->second)->internalOrBoundaryPoint() - || eit->first->vertex(eit->third)->internalOrBoundaryPoint() - ) + str<< 'f'; + + const face& fP = faces[f]; + + forAll(fP, p) { - Cell_circulator ccStart = incident_cells(*eit); - Cell_circulator cc = ccStart; - - str<< 'f'; - - do - { - if (!is_infinite(cc)) - { - if (cc->cellIndex() < 0) - { - FatalErrorIn - ( - "Foam::CV3D::writeDual(const fileName& fName)" - ) - << "Dual face uses circumcenter defined by a Delaunay " - "tetrahedron with no internal or boundary points." - << exit(FatalError); - } - - str<< ' ' << cc->cellIndex() + 1; - } - } while (++cc != ccStart); - - str<< nl; + str<< ' ' << fP[p] + 1; } + + str<< nl; } } void Foam::CV3D::writeTriangles(const fileName& fName, bool internalOnly) const { - Info << "Writing triangles to " << fName << nl << endl; + Info<< nl << "Writing triangles to " << fName << nl << endl; OFstream str(fName); labelList vertexMap(number_of_vertices()); @@ -271,6 +226,8 @@ void Foam::CV3D::writeMesh(bool writeToTimestep) << "Failed writing polyMesh." << exit(FatalError); } + + writeDual(points, faces, "dualMesh.obj"); } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C b/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C index 60a60bb545..0139f6cd17 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) << "Read surface with " << surf.size() << " triangles from file " << args.args()[1] << nl << endl; - // Read and triangulation + // Read and triangulation // ~~~~~~~~~~~~~~~~~~~~~~ CV3D mesh(runTime, surf); diff --git a/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C b/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C index d1e7eb0d6d..3e3ceae247 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C +++ b/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C @@ -278,11 +278,20 @@ void Foam::CV3D::calcDualMesh // ~~~~~~~~~~~~ dual face and owner neighbour construction ~~~~~~~~~~~~~~~~~ - label nPatches = 1; + label nPatches = qSurf_.patches().size() + 1; + + label defaultPatchIndex = qSurf_.patches().size(); patchNames.setSize(nPatches); - patchNames[0] = "CV3D_default_patch"; + const geometricSurfacePatchList& surfacePatches = qSurf_.patches(); + + forAll(surfacePatches, sP) + { + patchNames[sP] = surfacePatches[sP].name(); + } + + patchNames[defaultPatchIndex] = "CV3D_default_patch"; patchSizes.setSize(nPatches); @@ -399,8 +408,28 @@ void Foam::CV3D::calcDualMesh dcOwn = dcA; } - // find which patch this face is on; Hardcoded for now. - label patchIndex = 0; + // Find which patch this face is on by finding the + // intersection with the surface of the Delaunay edge + // generating the face and identify the region of the + // intersection. + + point ptA = topoint(vA->point()); + + point ptB = topoint(vB->point()); + + pointIndexHit pHit = qSurf_.tree().findLineAny(ptA, ptB); + + label patchIndex = qSurf_[pHit.index()].region(); + + if (patchIndex == -1) + { + patchIndex = defaultPatchIndex; + + WarningIn("Foam::CV3D::calcDualMesh.C") + << "Dual face found that is not on a surface " + << "patch. Adding to CV3D_default_patch." + << endl; + } patchFaces[patchIndex].append(newDualFace); patchOwners[patchIndex].append(dcOwn); @@ -432,11 +461,11 @@ void Foam::CV3D::calcDualMesh dualFacei++; } } - else - { - Info<< verticesOnFace.size() - << " size face not created." << endl; - } + // else + // { + // Info<< verticesOnFace.size() + // << " size face not created." << endl; + // } } }