void TriangleWrapper::transformMeshToTriangle_(const Mesh & mesh, triangulateio & trimesh){ #if USE_LIBTRIANGLE //! node section int nVerts = mesh.nodeCount(); trimesh.numberofpoints = nVerts; trimesh.numberofpointattributes = 0; // only one Parameter trimesh.pointlist = new double[2 * nVerts]; trimesh.pointmarkerlist = new int[nVerts]; for (int i = 0; i < nVerts; i ++){ trimesh.pointlist[i * 2] = mesh.node(i).x(); trimesh.pointlist[i * 2 + 1] = mesh.node(i).y(); trimesh.pointmarkerlist[i] = mesh.node(i).marker(); } //! edge section; int nEdges = mesh.boundaryCount(); int edgeCounter = 0; trimesh.numberofsegments = nEdges; trimesh.segmentlist = new int[2 * nEdges]; trimesh.segmentmarkerlist = new int[nEdges]; for (int i = 0; i < nEdges; i ++){ Boundary * edge = &mesh.boundary(i); trimesh.segmentlist[edgeCounter * 2] = edge->node(0).id(); trimesh.segmentlist[edgeCounter * 2 + 1] = edge->node(1).id(); trimesh.segmentmarkerlist[edgeCounter] = edge->marker(); edgeCounter++; } //! Holes; uint nHoles = mesh.holeMarker().size();//domain.holeCount(); trimesh.numberofholes = nHoles; trimesh.holelist = new double[2 * nHoles + 1]; for (uint i = 0; i < nHoles; i ++){ trimesh.holelist[i * 2] = mesh.holeMarker()[i].x(); trimesh.holelist[i * 2 + 1] = mesh.holeMarker()[i].y(); } //! Regions; int nRegions = mesh.regionMarker().size();//domain.regionCount(); trimesh.numberofregions = nRegions; trimesh.regionlist = new double[4 * nRegions + 1]; uint count = 0; for (Mesh::RegionMarkerList::const_iterator it = mesh.regionMarker().begin(); it != mesh.regionMarker().end(); it ++){ // std::cout << it->pos().x() << " " << it->pos().y() << " " // << it->marker() << " " // << it->area() << std::endl; trimesh.regionlist[count * 4] = it->x(); trimesh.regionlist[count * 4 + 1] = it->y(); trimesh.regionlist[count * 4 + 2] = it->marker(); trimesh.regionlist[count * 4 + 3] = it->area(); count ++; } #else std::cerr << WHERE_AM_I << " Triangle not installed" << std::endl; #endif }
bool addTriangleBoundary(Mesh & mesh, double xBoundary, double yBoundary, int cellMarker, bool save){ int boundMarker = -5; mesh.createNeighbourInfos(true); Boundary *b = NULL; for (std::vector < Boundary * >::const_iterator it = mesh.boundaries().begin(); it != mesh.boundaries().end(); it ++){ b = (*it); if (! b->leftCell() || ! b->rightCell()) { if (b->marker() != MARKER_BOUND_HOMOGEN_NEUMANN){ b->setMarker(boundMarker); } } } std::vector < Boundary * > markedBoundaries(mesh.findBoundaryByMarker(boundMarker)); Boundary *start(markedBoundaries.front()); std::list < Node * > boundNodes; boundNodes.push_back(& start->node(0)); Boundary * thisBoundary = start; while (thisBoundary != NULL){ Node * thisNode = boundNodes.back(); Boundary * nextBoundary = NULL; for (std::set < Boundary * >::iterator it = thisNode->boundSet().begin(); it != thisNode->boundSet().end(); it++){ if ((*it)->marker() == boundMarker && (*it) != thisBoundary){ nextBoundary = (*it); break; } } if (nextBoundary){ Node * nextNode = NULL; if (&nextBoundary->node(0) != thisNode){ nextNode = &nextBoundary->node(0); } else { nextNode = &nextBoundary->node(1); } //** Check closed polygones here if (find(boundNodes.begin(), boundNodes.end(), nextNode) == boundNodes.end()) { boundNodes.push_back(nextNode); } else { break; } } thisBoundary = nextBoundary; } boundNodes.push_front(& start->node(1)); thisBoundary = start; while (thisBoundary != NULL){ Node * thisNode = boundNodes.front(); Boundary * nextBoundary = NULL; for (std::set < Boundary * >::iterator it = thisNode->boundSet().begin(); it != thisNode->boundSet().end(); it++){ if ((*it)->marker() == boundMarker && (*it) != thisBoundary){ nextBoundary = (*it); break; } } if (nextBoundary){ Node * nextNode = NULL; if (& nextBoundary->node(0) != thisNode){ nextNode = & nextBoundary->node(0); } else { nextNode = & nextBoundary->node(1); } //** Check closed polygones here if (find(boundNodes.begin(), boundNodes.end(), nextNode) == boundNodes.end()) { boundNodes.push_front(nextNode); } else { break; } } thisBoundary = nextBoundary; } Mesh poly; std::vector < Node * > innerBound; for (std::list < Node * >::iterator it = boundNodes.begin(); it != boundNodes.end(); it ++){ innerBound.push_back(poly.createNode((*it)->pos())); } //** looking for polygon ends Node * upperLeftSurface = innerBound.front(); Node * upperRightSurface = innerBound.back(); if (upperLeftSurface->pos()[0] > upperRightSurface->pos()[0]){ upperLeftSurface = innerBound.back(); upperRightSurface = innerBound.front(); } std::vector < Node * > outerBound; outerBound.push_back(upperLeftSurface); Node *n1 = poly.createNode(upperLeftSurface->pos() - RVector3(xBoundary, 0.0)); Node *n2 = poly.createNode(upperLeftSurface->pos() - RVector3(xBoundary, - mesh.ymin() + yBoundary)); Node *n3 = poly.createNode(upperRightSurface->pos() - RVector3(-xBoundary, - mesh.ymin() + yBoundary)); Node *n4 = poly.createNode(upperRightSurface->pos() - RVector3(-xBoundary, 0.0)); outerBound.push_back(upperLeftSurface); RVector dx(increasingRange(4.0, xBoundary, 20)); for (uint i = 1; i < dx.size()-1; i ++) { outerBound.push_back(poly.createNode(upperLeftSurface->pos() + RVector3(-dx[i], 0))); } outerBound.push_back(n1); for (uint i = 0; i < 9; i ++) { outerBound.push_back(poly.createNode(n1->pos() + (n2->pos() - n1->pos()) / 10 * (i + 1))); } outerBound.push_back(n2); for (uint i = 0; i < 9; i ++) { outerBound.push_back(poly.createNode(n2->pos() + (n3->pos() - n2->pos()) / 10 * (i + 1))); } outerBound.push_back(n3); for (uint i = 0; i < 9; i ++) { outerBound.push_back(poly.createNode(n3->pos() + (n4->pos() - n3->pos()) / 10 * (i + 1))); } outerBound.push_back(n4); for (uint i = dx.size()-2; i > 0; i --) { outerBound.push_back(poly.createNode(upperRightSurface->pos() + RVector3(dx[i], 0))); } outerBound.push_back(upperRightSurface); for (uint i = 0; i < outerBound.size() -1; i ++){ poly.createEdge(*outerBound[i], *outerBound[i + 1], -1); } for (uint i = 0; i < innerBound.size() -1; i ++){ poly.createEdge(*innerBound[i], *innerBound[i + 1], boundMarker); } Mesh boundaryMesh; TriangleWrapper(poly, boundaryMesh, "-YpzeAfaq" + str(33)); std::vector < Boundary * > markedBoundaries2(boundaryMesh.findBoundaryByMarker(boundMarker)); if (markedBoundaries.size() == markedBoundaries2.size()){ for (std::vector < Cell * >::const_iterator it = boundaryMesh.cells().begin(); it != boundaryMesh.cells().end(); it ++){ mesh.copyCell(*(*it))->setMarker(cellMarker); } } else { return false; mesh.save("inMesh"); boundaryMesh.save("boundaryMesh"); throwError(1, WHERE_AM_I + " Sorry!! Boundary mesh is not consistent to input mesh boundary. " + toStr(markedBoundaries.size()) + " != " + toStr(markedBoundaries2.size())); } if (save){ mesh.save("shortFOPinMesh"); boundaryMesh.save("shortFOPboundaryMesh"); } //** Fix boundary marker mesh.createNeighbourInfos(true); b = NULL; for (std::vector < Boundary * >::const_iterator it = mesh.boundaries().begin(); it != mesh.boundaries().end(); it ++){ b = (*it); if (! b->leftCell() || ! b->rightCell()) { if (b->center().y() == mesh.ymax()){ b->setMarker(MARKER_BOUND_HOMOGEN_NEUMANN); } else { b->setMarker(MARKER_BOUND_MIXED); } } } return true; }