1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : NETGENPlugin_NETGEN_3D.cxx
22 // Moved here from SMESH_NETGEN_3D.cxx
23 // Created : lundi 27 Janvier 2003
24 // Author : Nadir BOUHAMOU (CEA)
26 // Copyright : CEA 2003
28 //=============================================================================
31 #include "NETGENPlugin_NETGEN_3D.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_MeshNode.hxx"
37 #include "SMDS_FacePosition.hxx"
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <BRep_Tool.hxx>
46 #include <Geom_Surface.hxx>
47 #include <Geom_Curve.hxx>
48 #include <Geom2d_Curve.hxx>
50 #include "utilities.h"
58 //=============================================================================
62 //=============================================================================
64 NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D(int hypId, int studyId,
66 : SMESH_3D_Algo(hypId, studyId, gen)
68 MESSAGE("NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D");
70 // _shapeType = TopAbs_SOLID;
71 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
72 // MESSAGE("_shapeType octal " << oct << _shapeType);
73 _compatibleHypothesis.push_back("MaxElementVolume");
75 _maxElementVolume = 0.;
77 _hypMaxElementVolume = NULL;
80 //=============================================================================
84 //=============================================================================
86 NETGENPlugin_NETGEN_3D::~NETGENPlugin_NETGEN_3D()
88 MESSAGE("NETGENPlugin_NETGEN_3D::~NETGENPlugin_NETGEN_3D");
91 //=============================================================================
95 //=============================================================================
97 bool NETGENPlugin_NETGEN_3D::CheckHypothesis
99 const TopoDS_Shape& aShape,
100 SMESH_Hypothesis::Hypothesis_Status& aStatus)
102 MESSAGE("NETGENPlugin_NETGEN_3D::CheckHypothesis");
104 _hypMaxElementVolume = NULL;
106 list<const SMESHDS_Hypothesis*>::const_iterator itl;
107 const SMESHDS_Hypothesis* theHyp;
109 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
110 int nbHyp = hyps.size();
113 aStatus = SMESH_Hypothesis::HYP_MISSING;
114 return false; // can't work with no hypothesis
118 theHyp = (*itl); // use only the first hypothesis
120 string hypName = theHyp->GetName();
121 int hypId = theHyp->GetID();
126 if (hypName == "MaxElementVolume")
128 _hypMaxElementVolume = static_cast<const StdMeshers_MaxElementVolume*> (theHyp);
129 ASSERT(_hypMaxElementVolume);
130 _maxElementVolume = _hypMaxElementVolume->GetMaxVolume();
132 aStatus = SMESH_Hypothesis::HYP_OK;
135 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
140 //=============================================================================
142 *Here we are going to use the NETGEN mesher
144 //=============================================================================
146 bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
147 const TopoDS_Shape& aShape)
149 MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume);
152 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
153 SMESH_subMesh* theSubMesh = aMesh.GetSubMesh(aShape);
154 //const Handle(SMESHDS_SubMesh)& subMeshDS = theSubMesh->GetSubMeshDS();
156 map<int, const SMDS_MeshNode*> netgenToDS;
158 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Checking the mesh Faces");
160 // check if all faces were meshed by a triangle mesher (here MESFISTO_2D)
162 vector<SMESH_subMesh*> meshFaces;
163 vector<TopoDS_Shape> shapeFaces;
165 for (TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next())
167 TopoDS_Shape aShapeFace = exp.Current();
168 SMESH_subMesh* aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
170 int internal_size = meshFaces.size();
172 for (int i = 0;i<internal_size;i++)
174 if (aSubMesh == meshFaces[i]) index = 1;
176 if (index == 0) meshFaces.push_back(aSubMesh);
178 internal_size = shapeFaces.size();
180 for (int i = 0;i<internal_size;i++)
182 if (aShapeFace == shapeFaces[i]) index = 1;
184 if (index == 0) shapeFaces.push_back(aShapeFace);
187 int numberOfFaces = meshFaces.size();
188 int numberOfShapeFaces = shapeFaces.size();
190 SCRUTE(numberOfFaces);
191 SCRUTE(numberOfShapeFaces);
196 int NbTotOfNodesFaces = 0;
198 for (int i=0; i<numberOfFaces; i++)
200 TopoDS_Shape aShapeFace = meshFaces[i]->GetSubShape();
201 TopoDS_Shape aFace = shapeFaces[i];
202 SMESH_Algo* algoFace = _gen->GetAlgo(aMesh, aShapeFace);
203 string algoFaceName = algoFace->GetName();
204 SCRUTE(algoFaceName);
205 if (algoFaceName != "MEFISTO_2D")
207 SCRUTE(algoFaceName);
212 bool orientationMeshFace = (aFace.Orientation() == aShapeFace.Orientation());
214 const SMESHDS_SubMesh* aSubMeshDSFace = meshFaces[i]->GetSubMeshDS();
215 SCRUTE(aSubMeshDSFace);
217 int nbNodes = aSubMeshDSFace->NbNodes();
218 NbTotOfNodesFaces += nbNodes;
219 int nbTria = aSubMeshDSFace->NbElements();
220 NbTotOfTria += nbTria;
223 MESSAGE("NETGENPlugin_NETGEN_3D::Compute The mesh Face " << (i+1) << " has " << nbNodes << " face internal Nodes, " << nbTria << " triangles");
225 SCRUTE(orientationMeshFace);
227 if (orientationMeshFace)
229 MESSAGE("The mesh and face have the same orientation");
233 MESSAGE("The mesh and face have different orientations");
236 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSFace->GetNodes();
239 while(iteratorNodes->more())
242 const SMDS_MeshNode * node = iteratorNodes->next();
243 // int nodeId = node->GetID();
244 // double nodeX = node->X();
245 // double nodeY = node->Y();
246 // double nodeZ = node->Z();
247 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
252 SMDS_ElemIteratorPtr iteratorTriangle = aSubMeshDSFace->GetElements();
256 int numberOfDegeneratedTriangle = 0;
257 while(iteratorTriangle->more())
260 const SMDS_MeshElement * triangle = iteratorTriangle->next();
261 int triangleId = triangle->GetID();
263 SMDS_ElemIteratorPtr triangleNodesIt = triangle->nodesIterator();
265 const SMDS_MeshNode * node1 = static_cast<const SMDS_MeshNode *>(triangleNodesIt->next());
266 double node1X = node1->X();
267 double node1Y = node1->Y();
268 double node1Z = node1->Z();
270 const SMDS_MeshNode * node2 = static_cast<const SMDS_MeshNode *>(triangleNodesIt->next());
271 double node2X = node2->X();
272 double node2Y = node2->Y();
273 double node2Z = node2->Z();
275 const SMDS_MeshNode * node3 = static_cast<const SMDS_MeshNode *>(triangleNodesIt->next());
276 double node3X = node3->X();
277 double node3Y = node3->Y();
278 double node3Z = node3->Z();
280 int triangleNode1 = node1->GetID();
281 int triangleNode2 = node2->GetID();
282 int triangleNode3 = node3->GetID();
284 // Compute the triangle surface
286 double vect1 = ((node2Y - node1Y)*(node3Z - node1Z) - (node2Z - node1Z)*(node3Y - node1Y));
287 double vect2 = - ((node2X - node1X)*(node3Z - node1Z) - (node2Z - node1Z)*(node3X - node1X));
288 double vect3 = ((node2X - node1X)*(node3Y - node1Y) - (node2Y - node1Y)*(node3X - node1X));
289 double epsilon = 1.0e-6;
291 bool triangleIsDegenerated = ((abs(vect1)<epsilon) && (abs(vect2)<epsilon) && (abs(vect3)<epsilon));
293 if (triangleIsDegenerated)
295 // MESSAGE("TRIANGLE -> ID = " << triangleId << " N1 = " << triangleNode1 << " N2 = " << triangleNode2 << " N3 = " << triangleNode3 << " is degenerated");
296 // MESSAGE("NODE -> ID = " << triangleNode1 << " X = " << node1X << " Y = " << node1Y << " Z = " << node1Z);
297 // MESSAGE("NODE -> ID = " << triangleNode2 << " X = " << node2X << " Y = " << node2Y << " Z = " << node2Z);
298 // MESSAGE("NODE -> ID = " << triangleNode3 << " X = " << node3X << " Y = " << node3Y << " Z = " << node3Z);
299 numberOfDegeneratedTriangle++;
303 // MESSAGE("TRIANGLE -> ID = " << triangleId << " N1 = " << triangleNode1 << " N2 = " << triangleNode2 << " N3 = " << triangleNode3 << " is normal");
307 if (numberOfDegeneratedTriangle > 0)
308 MESSAGE("WARNING THERE IS(ARE) " << numberOfDegeneratedTriangle << " degenerated triangle on this face");
316 SCRUTE(NbTotOfNodesFaces);
318 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Checking the mesh Edges");
320 // check if all edges were meshed by a edge mesher (here Regular_1D)
322 vector<SMESH_subMesh*> meshEdges;
323 for (TopExp_Explorer exp(aShape,TopAbs_EDGE);exp.More();exp.Next())
325 SMESH_subMesh* aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
327 int internal_size = meshEdges.size();
329 for (int i = 0;i<internal_size;i++)
331 if (aSubMesh == meshEdges[i]) index = 1;
333 if (index == 0) meshEdges.push_back(aSubMesh);
336 int numberOfEdges = meshEdges.size();
337 SCRUTE(numberOfEdges);
341 int NbTotOfNodesEdges = 0;
344 for (int i=0; i<numberOfEdges; i++)
346 TopoDS_Shape aShapeEdge = meshEdges[i]->GetSubShape();
347 SMESH_Algo* algoEdge = _gen->GetAlgo(aMesh, aShapeEdge);
348 string algoEdgeName = algoEdge->GetName();
349 SCRUTE(algoEdgeName);
350 if (algoEdgeName != "Regular_1D")
352 SCRUTE(algoEdgeName);
357 const SMESHDS_SubMesh* aSubMeshDSEdge = meshEdges[i]->GetSubMeshDS();
358 SCRUTE(aSubMeshDSEdge);
360 int nbNodes = aSubMeshDSEdge->NbNodes();
361 NbTotOfNodesEdges += nbNodes;
362 int nbSegs = aSubMeshDSEdge->NbElements();
363 NbTotOfSegs += nbSegs;
365 MESSAGE("NETGENPlugin_NETGEN_3D::Compute The mesh Edge " << (i+1) << " has " << nbNodes << " edge internal Nodes, " << nbSegs << " segments");
367 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSEdge->GetNodes();
370 while(iteratorNodes->more())
373 const SMDS_MeshNode * node = iteratorNodes->next();
374 // int nodeId = node->GetID();
375 // double nodeX = node->X();
376 // double nodeY = node->Y();
377 // double nodeZ = node->Z();
378 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
384 SCRUTE(NbTotOfNodesEdges);
387 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Checking the mesh Vertices");
389 vector<SMESH_subMesh*> meshVertices;
390 for (TopExp_Explorer exp(aShape,TopAbs_VERTEX);exp.More();exp.Next())
392 SMESH_subMesh* aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
394 int internal_size = meshVertices.size();
396 for (int i = 0;i<internal_size;i++)
398 if (aSubMesh == meshVertices[i]) index = 1;
400 if (index == 0) meshVertices.push_back(aSubMesh);
403 int numberOfVertices = meshVertices.size();
404 SCRUTE(numberOfVertices);
408 int NbTotOfNodesVertices = 0;
410 for (int i=0; i<numberOfVertices; i++)
412 TopoDS_Shape aShapeVertex = meshVertices[i]->GetSubShape();
414 const SMESHDS_SubMesh * aSubMeshDSVertex = meshVertices[i]->GetSubMeshDS();
415 SCRUTE(aSubMeshDSVertex);
417 int nbNodes = aSubMeshDSVertex->NbNodes();
418 NbTotOfNodesVertices += nbNodes;
420 MESSAGE("NETGENPlugin_NETGEN_3D::Compute The mesh Vertex " << (i+1) << " has " << nbNodes << " Nodes");
422 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSVertex->GetNodes();
425 while(iteratorNodes->more())
428 const SMDS_MeshNode * node = iteratorNodes->next();
429 // int nodeId = node->GetID();
430 // double nodeX = node->X();
431 // double nodeY = node->Y();
432 // double nodeZ = node->Z();
433 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
439 SCRUTE(NbTotOfNodesVertices);
441 MESSAGE("NETGENPlugin_NETGEN_3D::Compute --> Analysis of all shell mesh");
443 vector<SMESH_subMesh*> meshShells;
446 for (TopExp_Explorer exp(aShape,TopAbs_SHELL);exp.More();exp.Next())
448 SMESH_subMesh* aSubMesh = aMesh.GetSubMesh(exp.Current());
451 aShell = TopoDS::Shell(exp.Current());
452 meshShells.push_back(aSubMesh);
455 int numberOfShells = meshShells.size();
456 SCRUTE(numberOfShells);
458 if (numberOfShells == 1)
460 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Only one shell --> generation of the mesh using directly Netgen");
463 Prepare the Netgen surface mesh from the SMESHDS
466 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Prepare the Netgen surface mesh from the SMESHDS");
468 int spaceDimension = 3;
469 int nbNodesByTri = 3;
470 int nbNodesByTetra = 4;
472 int Netgen_NbOfNodes = NbTotOfNodesFaces +
474 NbTotOfNodesVertices;
475 int Netgen_NbOfTria = NbTotOfTria;
476 int Netgen_param2ndOrder = 0;
477 double Netgen_paramFine = 1.;
478 double Netgen_paramSize = _maxElementVolume;
480 SCRUTE(Netgen_NbOfNodes);
481 SCRUTE(Netgen_NbOfTria);
483 double * Netgen_Coordinates = new double [spaceDimension*
485 int * listNodeCoresNetgenSmesh = new int [Netgen_NbOfNodes];
486 int * Netgen_Connectivity = new int [nbNodesByTri*Netgen_NbOfTria];
487 double * Netgen_point = new double [spaceDimension];
488 int * Netgen_triangle = new int [nbNodesByTri];
489 int * Netgen_tetrahedron = new int [nbNodesByTetra];
491 for (int i=0; i<Netgen_NbOfTria; i++)
493 for (int j=0; j<nbNodesByTri; j++)
494 Netgen_Connectivity[i*nbNodesByTri+j] = 0;
497 double bigNumber = 1.e20;
499 for (int i=0; i<Netgen_NbOfNodes; i++)
501 listNodeCoresNetgenSmesh[i] = 0;
502 for (int j=0; j<spaceDimension; j++)
503 Netgen_Coordinates[i*spaceDimension+j] = bigNumber;
507 for (int i=0; i<numberOfVertices; i++)
509 const SMESHDS_SubMesh * aSubMeshDSVertex =
510 meshVertices[i]->GetSubMeshDS();
512 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSVertex->GetNodes();
514 while(iteratorNodes->more())
516 const SMDS_MeshNode * node = iteratorNodes->next();
517 int nodeId = node->GetID();
518 double nodeX = node->X();
519 double nodeY = node->Y();
520 double nodeZ = node->Z();
521 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
522 listNodeCoresNetgenSmesh[indexNodes] = nodeId;
523 int index = indexNodes*spaceDimension;
524 Netgen_Coordinates[index] = nodeX;
525 Netgen_Coordinates[index+1] = nodeY;
526 Netgen_Coordinates[index+2] = nodeZ;
527 netgenToDS[indexNodes] = node;
532 for (int i=0; i<numberOfEdges; i++)
534 const SMESHDS_SubMesh * aSubMeshDSEdge =
535 meshEdges[i]->GetSubMeshDS();
537 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSEdge->GetNodes();
539 while(iteratorNodes->more())
541 const SMDS_MeshNode * node = iteratorNodes->next();
542 int nodeId = node->GetID();
543 double nodeX = node->X();
544 double nodeY = node->Y();
545 double nodeZ = node->Z();
546 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
547 listNodeCoresNetgenSmesh[indexNodes] = node->GetID();
548 int index = indexNodes*spaceDimension;
549 Netgen_Coordinates[index] = node->X();
550 Netgen_Coordinates[index+1] = node->Y();
551 Netgen_Coordinates[index+2] = node->Z();
552 netgenToDS[indexNodes] = node;
557 for (int i=0; i<numberOfFaces; i++)
559 const SMESHDS_SubMesh * aSubMeshDSFace =
560 meshFaces[i]->GetSubMeshDS();
562 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSFace->GetNodes();
564 while(iteratorNodes->more())
566 const SMDS_MeshNode * node = iteratorNodes->next();
567 int nodeId = node->GetID();
568 double nodeX = node->X();
569 double nodeY = node->Y();
570 double nodeZ = node->Z();
571 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
572 listNodeCoresNetgenSmesh[indexNodes] = nodeId;
573 int index = indexNodes*spaceDimension;
574 Netgen_Coordinates[index] = nodeX;
575 Netgen_Coordinates[index+1] = nodeY;
576 Netgen_Coordinates[index+2] = nodeZ;
577 netgenToDS[indexNodes] = node;
584 for (int i=0; i<Netgen_NbOfNodes; i++)
586 ASSERT(listNodeCoresNetgenSmesh[i] != 0);
588 for (int j=0; j<Netgen_NbOfNodes && j!=i; j++)
589 ASSERT(listNodeCoresNetgenSmesh[i] != listNodeCoresNetgenSmesh[j]);
591 for (int j=0; j<spaceDimension; j++)
592 ASSERT(Netgen_Coordinates[i*spaceDimension+j] != bigNumber);
596 for (int i=0; i<numberOfFaces; i++)
598 const SMESHDS_SubMesh * aSubMeshDSFace =
599 meshFaces[i]->GetSubMeshDS();
601 TopoDS_Shape aFace = shapeFaces[i];
603 SMDS_ElemIteratorPtr iteratorTriangle = aSubMeshDSFace->GetElements();
605 TopoDS_Shape aShapeFace = meshFaces[i]->GetSubShape();
607 bool orientationMeshFace = (aFace.Orientation() == aShapeFace.Orientation());
609 SCRUTE(orientationMeshFace);
611 if (orientationMeshFace)
613 MESSAGE("The mesh and face have the same orientation");
615 while(iteratorTriangle->more())
617 const SMDS_MeshElement * triangle = iteratorTriangle->next();
618 int triangleId = triangle->GetID();
620 SMDS_ElemIteratorPtr triangleNodesIt = triangle->nodesIterator();
622 int triangleNode1 = (triangleNodesIt->next())->GetID();
623 int triangleNode2 = (triangleNodesIt->next())->GetID();
624 int triangleNode3 = (triangleNodesIt->next())->GetID();
626 // MESSAGE("TRIANGLE -> ID = " << triangleId << " N1 = " << triangleNode1 << " N2 = " << triangleNode2 << " N3 = " << triangleNode3);
631 int index = indexTrias*nbNodesByTri;
633 for (int j=0; j<Netgen_NbOfNodes; j++)
637 if (triangleNode1 == listNodeCoresNetgenSmesh[j])
639 else if (triangleNode2 == listNodeCoresNetgenSmesh[j])
641 else if (triangleNode3 == listNodeCoresNetgenSmesh[j])
645 triangleNode1 = N1New;
646 triangleNode2 = N2New;
647 triangleNode3 = N3New;
649 Netgen_Connectivity[index] = triangleNode1;
650 Netgen_Connectivity[index+1] = triangleNode2;
651 Netgen_Connectivity[index+2] = triangleNode3;
658 MESSAGE("The mesh and face have different orientations");
660 while(iteratorTriangle->more())
662 const SMDS_MeshElement * triangle = iteratorTriangle->next();
663 int triangleId = triangle->GetID();
665 SMDS_ElemIteratorPtr triangleNodesIt = triangle->nodesIterator();
667 int triangleNode1 = (triangleNodesIt->next())->GetID();
668 int triangleNode3 = (triangleNodesIt->next())->GetID();
669 int triangleNode2 = (triangleNodesIt->next())->GetID();
671 // MESSAGE("TRIANGLE -> ID = " << triangleId << " N1 = " << triangleNode1 << " N2 = " << triangleNode2 << " N3 = " << triangleNode3);
676 int index = indexTrias*nbNodesByTri;
678 for (int j=0; j<Netgen_NbOfNodes; j++)
682 if (triangleNode1 == listNodeCoresNetgenSmesh[j])
684 else if (triangleNode2 == listNodeCoresNetgenSmesh[j])
686 else if (triangleNode3 == listNodeCoresNetgenSmesh[j])
690 triangleNode1 = N1New;
691 triangleNode2 = N2New;
692 triangleNode3 = N3New;
694 Netgen_Connectivity[index] = triangleNode1;
695 Netgen_Connectivity[index+1] = triangleNode2;
696 Netgen_Connectivity[index+2] = triangleNode3;
705 int * nodesUsed = new int[Netgen_NbOfNodes];
707 for (int i=0; i<Netgen_NbOfNodes; i++) nodesUsed[i] = 0;
709 for (int i=0; i<Netgen_NbOfTria; i++)
710 for (int j=0; j<nbNodesByTri; j++)
712 int Nij = Netgen_Connectivity[i*nbNodesByTri+j];
714 ASSERT((Nij>=1) && (Nij<=Netgen_NbOfNodes));
716 nodesUsed[Nij-1] = 1;
717 Netgen_Connectivity[i*nbNodesByTri+j] = Nij;
720 for (int i=0; i<Netgen_NbOfNodes; i++)
722 ASSERT(nodesUsed[i] != 0);
728 Feed the Netgen surface mesh
731 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Feed the Netgen surface mesh");
733 Ng_Mesh * Netgen_mesh;
737 Netgen_mesh = Ng_NewMesh();
739 Ng_Meshing_Parameters Netgen_param;
741 for (int i=0; i<Netgen_NbOfNodes; i++)
743 for (int j=0; j<spaceDimension; j++)
744 Netgen_point[j] = Netgen_Coordinates[i*spaceDimension+j];
746 Ng_AddPoint(Netgen_mesh, Netgen_point);
749 for (int i=0; i<Netgen_NbOfTria; i++)
751 for (int j=0; j<nbNodesByTri; j++)
752 Netgen_triangle[j] = Netgen_Connectivity[i*nbNodesByTri+j];
754 Ng_AddSurfaceElement(Netgen_mesh, NG_TRIG, Netgen_triangle);
757 SCRUTE(Netgen_paramSize);
759 Netgen_param.secondorder = Netgen_param2ndOrder;
760 Netgen_param.fineness = Netgen_paramFine;
761 Netgen_param.maxh = Netgen_paramSize;
764 Generate the volume mesh
767 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Generate the volume mesh");
769 SCRUTE(Netgen_NbOfNodes);
770 SCRUTE(Netgen_NbOfTria);
772 SCRUTE(Ng_GetNP(Netgen_mesh));
773 SCRUTE(Ng_GetNE(Netgen_mesh));
774 SCRUTE(Ng_GetNSE(Netgen_mesh));
776 ASSERT(Netgen_NbOfNodes == Ng_GetNP(Netgen_mesh));
777 ASSERT(Ng_GetNE(Netgen_mesh) == 0);
778 ASSERT(Netgen_NbOfTria == Ng_GetNSE(Netgen_mesh));
782 status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param);
786 int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh);
788 int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh);
790 SCRUTE(Netgen_NbOfNodesNew);
792 SCRUTE(Netgen_NbOfTetra);
794 if ((status != NG_OK) ||
795 (Netgen_NbOfNodesNew <= Netgen_NbOfNodes) ||
796 (Netgen_NbOfTetra <= 0))
798 MESSAGE("NETGENPlugin_NETGEN_3D::Compute The Volume Mesh Generation has failed ...");
802 Free the memory needed by to generate the Netgen Mesh
805 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Free the memory needed by to generate the Netgen Mesh");
807 delete [] Netgen_Coordinates;
808 delete [] Netgen_Connectivity;
809 delete [] Netgen_point;
810 delete [] Netgen_triangle;
811 delete [] Netgen_tetrahedron;
813 delete [] listNodeCoresNetgenSmesh;
815 Ng_DeleteMesh(Netgen_mesh);
821 MESSAGE("NETGENPlugin_NETGEN_3D::Compute End of Volume Mesh Generation");
824 double * Netgen_CoordinatesNew = new double [spaceDimension*Netgen_NbOfNodesNew];
825 int * Netgen_ConnectivityNew = new int [nbNodesByTetra*Netgen_NbOfTetra];
827 for (int i=0; i<Netgen_NbOfNodesNew; i++)
829 Ng_GetPoint(Netgen_mesh, (i+1), Netgen_point);
831 for (int j=0; j<spaceDimension; j++)
832 Netgen_CoordinatesNew[i*spaceDimension+j] = Netgen_point[j];
835 for (int i=0; i<Netgen_NbOfNodes; i++)
836 for (int j=0; j<spaceDimension; j++)
837 ASSERT(Netgen_CoordinatesNew[i*spaceDimension+j] == Netgen_Coordinates[i*spaceDimension+j])
839 for (int i=0; i<Netgen_NbOfTetra; i++)
841 Ng_GetVolumeElement(Netgen_mesh, (i+1), Netgen_tetrahedron);
843 for (int j=0; j<nbNodesByTetra; j++)
844 Netgen_ConnectivityNew[i*nbNodesByTetra+j] = Netgen_tetrahedron[j];
848 Feed back the SMESHDS with the generated Nodes and Volume Elements
851 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Feed back the SMESHDS with the generated Nodes and Volume Elements");
853 int NbTotOfNodesShell = Netgen_NbOfNodesNew - Netgen_NbOfNodes;
855 SCRUTE(NbTotOfNodesShell);
857 int * listNodeShellCoresNetgenSmesh = new int [NbTotOfNodesShell];
859 for (int i=0; i<NbTotOfNodesShell; i++)
860 listNodeShellCoresNetgenSmesh[i] = 0;
862 MESSAGE("NETGENPlugin_NETGEN_3D::Compute --> Adding the New Nodes to SMESHDS");
864 for (int i=0; i<NbTotOfNodesShell; i++)
866 int index = (i+Netgen_NbOfNodes)*spaceDimension;
868 SMDS_MeshNode * node =
869 meshDS->AddNode(Netgen_CoordinatesNew[index],
870 Netgen_CoordinatesNew[index+1],
871 Netgen_CoordinatesNew[index+2]);
873 meshDS->SetNodeInVolume(node, aShell);
875 index = i+Netgen_NbOfNodes;
876 netgenToDS[index] = node;
878 listNodeShellCoresNetgenSmesh[i] = node->GetID();
881 SCRUTE(Netgen_NbOfNodesNew);
883 SCRUTE(netgenToDS.size());
885 for (int i=0; i<NbTotOfNodesShell; i++)
887 ASSERT(listNodeShellCoresNetgenSmesh[i] != 0);
889 for (int j=0; j<NbTotOfNodesShell && j!=i; j++)
890 ASSERT(listNodeShellCoresNetgenSmesh[i] != listNodeShellCoresNetgenSmesh[j]);
893 MESSAGE("NETGENPlugin_NETGEN_3D::Compute --> Adding the New elements (Tetrahedrons) to the SMESHDS");
895 for (int i=0; i<Netgen_NbOfTetra; i++)
897 int index = i*nbNodesByTetra;
898 int tetraNode1 = Netgen_ConnectivityNew[index];
899 int tetraNode2 = Netgen_ConnectivityNew[index+1];
900 int tetraNode3 = Netgen_ConnectivityNew[index+2];
901 int tetraNode4 = Netgen_ConnectivityNew[index+3];
903 const SMDS_MeshNode * node1 = netgenToDS[tetraNode1-1];
904 const SMDS_MeshNode * node2 = netgenToDS[tetraNode2-1];
905 const SMDS_MeshNode * node3 = netgenToDS[tetraNode3-1];
906 const SMDS_MeshNode * node4 = netgenToDS[tetraNode4-1];
909 if (index <= Netgen_NbOfNodes)
910 tetraNode1 = listNodeCoresNetgenSmesh[index-1];
912 tetraNode1 = listNodeShellCoresNetgenSmesh[index-Netgen_NbOfNodes-1];
915 if (index <= Netgen_NbOfNodes)
916 tetraNode2 = listNodeCoresNetgenSmesh[index-1];
918 tetraNode2 = listNodeShellCoresNetgenSmesh[index-Netgen_NbOfNodes-1];
921 if (index <= Netgen_NbOfNodes)
922 tetraNode3 = listNodeCoresNetgenSmesh[index-1];
924 tetraNode3 = listNodeShellCoresNetgenSmesh[index-Netgen_NbOfNodes-1];
927 if (index <= Netgen_NbOfNodes)
928 tetraNode4 = listNodeCoresNetgenSmesh[index-1];
930 tetraNode4 = listNodeShellCoresNetgenSmesh[index-Netgen_NbOfNodes-1];
932 SMDS_MeshVolume * elt =
933 meshDS->AddVolume(node1,node2,node3,node4);
935 meshDS->SetMeshElementOnShape(elt, aShell);
939 Free the memory needed by to generate the Netgen Mesh
942 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Free the memory needed by to generate the Netgen Mesh");
944 delete [] Netgen_Coordinates;
945 delete [] Netgen_Connectivity;
946 delete [] Netgen_CoordinatesNew;
947 delete [] Netgen_ConnectivityNew;
948 delete [] Netgen_point;
949 delete [] Netgen_triangle;
950 delete [] Netgen_tetrahedron;
952 delete [] listNodeCoresNetgenSmesh;
953 delete [] listNodeShellCoresNetgenSmesh;
955 Ng_DeleteMesh(Netgen_mesh);
963 MESSAGE("NETGENPlugin_NETGEN_3D::Compute Verification of the Shell mesh");
965 TopoDS_Shape aShapeShell = meshShells[0]->GetSubShape();
966 SMESH_Algo* algoShell = _gen->GetAlgo(aMesh, aShapeShell);
967 string algoShellName = algoShell->GetName();
968 SCRUTE(algoShellName);
969 if (algoShellName != "NETGEN_3D")
971 SCRUTE(algoShellName);
976 const SMESHDS_SubMesh * aSubMeshDSShell = meshShells[0]->GetSubMeshDS();
977 SCRUTE(&aSubMeshDSShell);
979 int nbNodes = aSubMeshDSShell->NbNodes();
980 int nbTetra = aSubMeshDSShell->NbElements();
982 MESSAGE("NETGENPlugin_NETGEN_3D::Compute The mesh Shell has " << nbNodes << " shell internal Nodes, " << nbTetra << " tetrahedrons");
984 SMDS_NodeIteratorPtr iteratorNodes = aSubMeshDSShell->GetNodes();
992 while(iteratorNodes->more())
995 const SMDS_MeshNode * node = iteratorNodes->next();
996 int nodeId = node->GetID();
997 double nodeX = node->X();
998 double nodeY = node->Y();
999 double nodeZ = node->Z();
1000 // MESSAGE("NODE -> ID = " << nodeId << " X = " << nodeX << " Y = " << nodeY << " Z = " << nodeZ);
1005 SMDS_ElemIteratorPtr iteratorTetra = aSubMeshDSShell->GetElements();
1010 while(iteratorTetra->more())
1013 const SMDS_MeshElement * tetra = iteratorTetra->next();
1014 int tetraId = tetra->GetID();
1016 SMDS_ElemIteratorPtr tetraNodesIt = tetra->nodesIterator();
1018 int tetraNode1 = (tetraNodesIt->next())->GetID();
1019 int tetraNode2 = (tetraNodesIt->next())->GetID();
1020 int tetraNode3 = (tetraNodesIt->next())->GetID();
1021 int tetraNode4 = (tetraNodesIt->next())->GetID();
1023 // MESSAGE("TETRAHEDRON -> ID = " << tetraId << " N1 = " << tetraNode1 << " N2 = " << tetraNode2 << " N3 = " << tetraNode3 << " N4 = " << tetraNode4);
1032 SCRUTE(numberOfShells);
1033 MESSAGE("NETGENPlugin_NETGEN_3D::Compute ERROR More than one shell ????? ");
1041 //=============================================================================
1045 //=============================================================================
1047 ostream & NETGENPlugin_NETGEN_3D::SaveTo(ostream & save)
1052 //=============================================================================
1056 //=============================================================================
1058 istream & NETGENPlugin_NETGEN_3D::LoadFrom(istream & load)
1063 //=============================================================================
1067 //=============================================================================
1069 ostream & operator << (ostream & save, NETGENPlugin_NETGEN_3D & hyp)
1071 return hyp.SaveTo( save );
1074 //=============================================================================
1078 //=============================================================================
1080 istream & operator >> (istream & load, NETGENPlugin_NETGEN_3D & hyp)
1082 return hyp.LoadFrom( load );