2 //=============================================================================
3 // File : SMESH_Hexa_3D.cxx
4 // Created : sam mai 18 23:15:30 CEST 2002
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2002
9 //=============================================================================
12 #include "SMESH_Hexa_3D.hxx"
13 #include "SMESH_Quadrangle_2D.hxx"
14 #include "SMESH_Gen.hxx"
15 #include "SMESH_Mesh.hxx"
17 #include "SMDS_MeshElement.hxx"
18 #include "SMDS_MeshNode.hxx"
19 #include "SMDS_FacePosition.hxx"
22 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
23 #include <TopTools_ListOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
27 #include <BRep_Tool.hxx>
28 #include <Geom_Surface.hxx>
29 #include <Geom_Curve.hxx>
30 #include <Geom2d_Curve.hxx>
31 #include <Handle_Geom2d_Curve.hxx>
32 #include <Handle_Geom_Curve.hxx>
34 #include "utilities.h"
37 //=============================================================================
41 //=============================================================================
43 SMESH_Hexa_3D::SMESH_Hexa_3D(int hypId, int studyId,
45 : SMESH_3D_Algo(hypId, studyId, gen)
47 MESSAGE("SMESH_Hexa_3D::SMESH_Hexa_3D");
49 // _shapeType = TopAbs_SOLID;
50 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
51 // MESSAGE("_shapeType octal " << oct << _shapeType);
52 for (int i=0; i<6; i++) _quads[i] = 0;
55 //=============================================================================
59 //=============================================================================
61 SMESH_Hexa_3D::~SMESH_Hexa_3D()
63 MESSAGE("SMESH_Hexa_3D::~SMESH_Hexa_3D");
66 //=============================================================================
70 //=============================================================================
72 bool SMESH_Hexa_3D::CheckHypothesis(SMESH_Mesh& aMesh,
73 const TopoDS_Shape& aShape)
75 MESSAGE("SMESH_Hexa_3D::CheckHypothesis");
84 //=============================================================================
86 * Hexahedron mesh on hexaedron like form
87 * -0. - shape and face mesh verification
88 * -1. - identify faces and vertices of the "cube"
89 * -2. - Algorithm from:
90 * "Application de l'interpolation transfinie à la création de maillages
91 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
92 * et hexaedres déformés."
93 * Alain PERONNET - 8 janvier 1999
95 //=============================================================================
97 bool SMESH_Hexa_3D::Compute(SMESH_Mesh& aMesh,
98 const TopoDS_Shape& aShape)
99 throw (SALOME_Exception)
101 MESSAGE("SMESH_Hexa_3D::Compute");
104 const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
105 SMESH_subMesh* theSubMesh = aMesh.GetSubMesh(aShape);
106 //const Handle(SMESHDS_SubMesh)& subMeshDS = theSubMesh->GetSubMeshDS();
108 // 0. - shape and face mesh verification
109 // 0.1 - shape must be a solid (or a shell) with 6 faces
112 vector<SMESH_subMesh*> meshFaces;
113 for (TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next())
115 SMESH_subMesh* aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
117 meshFaces.push_back(aSubMesh);
119 if (meshFaces.size() != 6)
121 SCRUTE(meshFaces.size());
126 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
129 for (int i=0; i<6; i++)
131 TopoDS_Shape aShape = meshFaces[i]->GetSubShape();
132 SMESH_Algo* algo = _gen->GetAlgo(aMesh, aShape);
133 string algoName = algo->GetName();
134 if (algoName != "Quadrangle_2D")
141 SMESH_Quadrangle_2D* quadAlgo =dynamic_cast<SMESH_Quadrangle_2D*> (algo);
145 _quads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aShape);
146 // *** to delete after usage
148 catch (SALOME_Exception& S_ex)
151 // *** throw exception
156 // 1. - identify faces and vertices of the "cube"
157 // 1.1 - ancestor maps vertex->edges in the cube
160 TopTools_IndexedDataMapOfShapeListOfShape MS;
161 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
163 // 1.2 - first face is choosen as face Y=0 of the unit cube
166 const TopoDS_Shape& aFace = meshFaces[0]->GetSubShape();
167 const TopoDS_Face& F = TopoDS::Face(aFace);
169 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
173 TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
175 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
176 TopoDS_Vertex VFirst, VLast;
177 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
178 bool isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
182 _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
183 _cube.V100 = VLast; // will be (1,0,0) on the unit cube
192 E = _quads[0]->edge[i];
193 C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
194 TopExp::Vertices(E, VFirst, VLast);
195 isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
196 if (isForward) _cube.V101 = VLast; // will be (1,0,1) on the unit cube
197 else _cube.V101 = VFirst;
200 E = _quads[0]->edge[i];
201 C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
202 TopExp::Vertices(E, VFirst, VLast);
203 isForward = (((l-f)*(_quads[0]->last[i] - _quads[0]->first[i])) > 0);
204 if (isForward) _cube.V001 = VLast; // will be (0,0,1) on the unit cube
205 else _cube.V001 = VFirst;
207 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
208 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
209 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
210 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
213 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
214 ASSERT(! E_0Y0.IsNull());
216 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
217 ASSERT(! E_1Y0.IsNull());
219 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
220 ASSERT(! E_1Y1.IsNull());
222 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
223 ASSERT(! E_0Y1.IsNull());
225 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
228 TopExp::Vertices(E_0Y0, VFirst, VLast);
229 if (VFirst.IsSame(_cube.V000)) _cube.V010 = VLast;
230 else _cube.V010 = VFirst;
232 TopExp::Vertices(E_1Y0, VFirst, VLast);
233 if (VFirst.IsSame(_cube.V100)) _cube.V110 = VLast;
234 else _cube.V110 = VFirst;
236 TopExp::Vertices(E_1Y1, VFirst, VLast);
237 if (VFirst.IsSame(_cube.V101)) _cube.V111 = VLast;
238 else _cube.V111 = VFirst;
240 TopExp::Vertices(E_0Y1, VFirst, VLast);
241 if (VFirst.IsSame(_cube.V001)) _cube.V011 = VLast;
242 else _cube.V011 = VFirst;
244 // 1.6 - find remaining faces given 4 vertices
248 _cube.quad_Y0 = _quads[_indY0];
250 _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
251 _cube.V010,_cube.V011,_cube.V110,_cube.V111);
252 _cube.quad_Y1 = _quads[_indY1];
254 _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
255 _cube.V000,_cube.V010,_cube.V100,_cube.V110);
256 _cube.quad_Z0 = _quads[_indZ0];
258 _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
259 _cube.V001,_cube.V011,_cube.V101,_cube.V111);
260 _cube.quad_Z1 = _quads[_indZ1];
262 _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
263 _cube.V000,_cube.V001,_cube.V010,_cube.V011);
264 _cube.quad_X0 = _quads[_indX0];
266 _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
267 _cube.V100,_cube.V101,_cube.V110,_cube.V111);
268 _cube.quad_X1 = _quads[_indX1];
272 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
274 Conv2DStruct cx0; // for face X=0
275 Conv2DStruct cx1; // for face X=1
281 GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
282 _cube.V000,_cube.V010,_cube.V011,_cube.V001,
284 GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
285 _cube.V100,_cube.V110,_cube.V111,_cube.V101,
287 GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
288 _cube.V000,_cube.V100,_cube.V101,_cube.V001,
290 GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
291 _cube.V010,_cube.V110,_cube.V111,_cube.V011,
293 GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
294 _cube.V000,_cube.V100,_cube.V110,_cube.V010,
296 GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
297 _cube.V001,_cube.V101,_cube.V111,_cube.V011,
300 // 1.8 - create a 3D structure for normalized values
303 int nbx = _cube.quad_Y0->nbPts[0];
304 int nby = _cube.quad_Y0->nbPts[1];
306 if (cx0.a1 != 0) nbz = _cube.quad_X0->nbPts[1];
307 else nbz = _cube.quad_X0->nbPts[0];
311 int nbxyz= nbx*nby*nbz;
312 Point3DStruct* np = new Point3DStruct[nbxyz];
314 // 1.9 - store node indexes of faces
317 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
318 const TColStd_ListOfInteger& indElt
319 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
320 TColStd_ListIteratorOfListOfInteger itf(indElt);
322 faceQuadStruct* quad = _cube.quad_X0;
323 int i=0; // j = x/face , k = y/face
324 int nbdown = quad->nbPts[0];
325 int nbright = quad->nbPts[1];
327 for (; itf.More(); itf.Next())
329 int nodeId = itf.Value();
330 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
331 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
332 Handle (SMDS_FacePosition) fpos
333 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
334 double ri = fpos->GetUParameter();
335 double rj = fpos->GetVParameter();
338 int ij1 = j1*nbdown +i1;
339 quad->uv_grid[ij1].nodeId = nodeId;
342 for (int i1=0; i1<nbdown; i1++)
343 for (int j1=0; j1<nbright; j1++)
345 int ij1 = j1*nbdown +i1;
346 int j = cx0.ia*i1 + cx0.ib*j1 + cx0.ic; // j = x/face
347 int k = cx0.ja*i1 + cx0.jb*j1 + cx0.jc; // k = y/face
348 int ijk = k*nbx*nby + j*nbx + i;
349 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
350 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
351 //SCRUTE(np[ijk].nodeId);
356 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
357 const TColStd_ListOfInteger& indElt
358 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
359 TColStd_ListIteratorOfListOfInteger itf(indElt);
361 faceQuadStruct* quad = _cube.quad_X1;
362 int i=nbx-1; // j = x/face , k = y/face
363 int nbdown = quad->nbPts[0];
364 int nbright = quad->nbPts[1];
366 for (; itf.More(); itf.Next())
368 int nodeId = itf.Value();
369 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
370 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
371 Handle (SMDS_FacePosition) fpos
372 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
373 double ri = fpos->GetUParameter();
374 double rj = fpos->GetVParameter();
377 int ij1 = j1*nbdown +i1;
378 quad->uv_grid[ij1].nodeId = nodeId;
381 for (int i1=0; i1<nbdown; i1++)
382 for (int j1=0; j1<nbright; j1++)
384 int ij1 = j1*nbdown +i1;
385 int j = cx1.ia*i1 + cx1.ib*j1 + cx1.ic; // j = x/face
386 int k = cx1.ja*i1 + cx1.jb*j1 + cx1.jc; // k = y/face
387 int ijk = k*nbx*nby + j*nbx + i;
388 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
389 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
390 //SCRUTE(np[ijk].nodeId);
395 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
396 const TColStd_ListOfInteger& indElt
397 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
398 TColStd_ListIteratorOfListOfInteger itf(indElt);
400 faceQuadStruct* quad = _cube.quad_Y0;
401 int j=0; // i = x/face , k = y/face
402 int nbdown = quad->nbPts[0];
403 int nbright = quad->nbPts[1];
405 for (; itf.More(); itf.Next())
407 int nodeId = itf.Value();
408 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
409 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
410 Handle (SMDS_FacePosition) fpos
411 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
412 double ri = fpos->GetUParameter();
413 double rj = fpos->GetVParameter();
416 int ij1 = j1*nbdown +i1;
417 quad->uv_grid[ij1].nodeId = nodeId;
420 for (int i1=0; i1<nbdown; i1++)
421 for (int j1=0; j1<nbright; j1++)
423 int ij1 = j1*nbdown +i1;
424 int i = cy0.ia*i1 + cy0.ib*j1 + cy0.ic; // i = x/face
425 int k = cy0.ja*i1 + cy0.jb*j1 + cy0.jc; // k = y/face
426 int ijk = k*nbx*nby + j*nbx + i;
427 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
428 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
429 //SCRUTE(np[ijk].nodeId);
434 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
435 const TColStd_ListOfInteger& indElt
436 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
437 TColStd_ListIteratorOfListOfInteger itf(indElt);
439 faceQuadStruct* quad = _cube.quad_Y1;
440 int j=nby-1; // i = x/face , k = y/face
441 int nbdown = quad->nbPts[0];
442 int nbright = quad->nbPts[1];
444 for (; itf.More(); itf.Next())
446 int nodeId = itf.Value();
447 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
448 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
449 Handle (SMDS_FacePosition) fpos
450 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
451 double ri = fpos->GetUParameter();
452 double rj = fpos->GetVParameter();
455 int ij1 = j1*nbdown +i1;
456 quad->uv_grid[ij1].nodeId = nodeId;
459 for (int i1=0; i1<nbdown; i1++)
460 for (int j1=0; j1<nbright; j1++)
462 int ij1 = j1*nbdown +i1;
463 int i = cy1.ia*i1 + cy1.ib*j1 + cy1.ic; // i = x/face
464 int k = cy1.ja*i1 + cy1.jb*j1 + cy1.jc; // k = y/face
465 int ijk = k*nbx*nby + j*nbx + i;
466 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
467 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
468 //SCRUTE(np[ijk].nodeId);
473 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
474 const TColStd_ListOfInteger& indElt
475 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
476 TColStd_ListIteratorOfListOfInteger itf(indElt);
478 faceQuadStruct* quad = _cube.quad_Z0;
479 int k=0; // i = x/face , j = y/face
480 int nbdown = quad->nbPts[0];
481 int nbright = quad->nbPts[1];
483 for (; itf.More(); itf.Next())
485 int nodeId = itf.Value();
486 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
487 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
488 Handle (SMDS_FacePosition) fpos
489 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
490 double ri = fpos->GetUParameter();
491 double rj = fpos->GetVParameter();
494 int ij1 = j1*nbdown +i1;
495 quad->uv_grid[ij1].nodeId = nodeId;
498 for (int i1=0; i1<nbdown; i1++)
499 for (int j1=0; j1<nbright; j1++)
501 int ij1 = j1*nbdown +i1;
502 int i = cz0.ia*i1 + cz0.ib*j1 + cz0.ic; // i = x/face
503 int j = cz0.ja*i1 + cz0.jb*j1 + cz0.jc; // j = y/face
504 int ijk = k*nbx*nby + j*nbx + i;
505 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
506 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
507 //SCRUTE(np[ijk].nodeId);
512 const TopoDS_Face& F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
513 const TColStd_ListOfInteger& indElt
514 = aMesh.GetSubMesh(F)->GetSubMeshDS()->GetIDNodes();
515 TColStd_ListIteratorOfListOfInteger itf(indElt);
517 faceQuadStruct* quad = _cube.quad_Z1;
518 int k=nbz-1; // i = x/face , j = y/face
519 int nbdown = quad->nbPts[0];
520 int nbright = quad->nbPts[1];
522 for (; itf.More(); itf.Next())
524 int nodeId = itf.Value();
525 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
526 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
527 Handle (SMDS_FacePosition) fpos
528 = Handle (SMDS_FacePosition)::DownCast(node->GetPosition());
529 double ri = fpos->GetUParameter();
530 double rj = fpos->GetVParameter();
533 int ij1 = j1*nbdown +i1;
534 quad->uv_grid[ij1].nodeId = nodeId;
537 for (int i1=0; i1<nbdown; i1++)
538 for (int j1=0; j1<nbright; j1++)
540 int ij1 = j1*nbdown +i1;
541 int i = cz1.ia*i1 + cz1.ib*j1 + cz1.ic; // i = x/face
542 int j = cz1.ja*i1 + cz1.jb*j1 + cz1.jc; // j = y/face
543 int ijk = k*nbx*nby + j*nbx + i;
544 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
545 np[ijk].nodeId = quad->uv_grid[ij1].nodeId;
546 //SCRUTE(np[ijk].nodeId);
550 // 2.0 - for each node of the cube:
551 // - get the 8 points 3D = 8 vertices of the cube
552 // - get the 12 points 3D on the 12 edges of the cube
553 // - get the 6 points 3D on the 6 faces with their ID
554 // - compute the point 3D
555 // - store the point 3D in SMESHDS, store its ID in 3D structure
558 TopExp_Explorer exp(aShape,TopAbs_SHELL);
561 aShell = TopoDS::Shell(exp.Current());
565 MESSAGE("no shell...");
570 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
571 Pt3 px00, px01, px10, px11;
572 Pt3 p0y0, p0y1, p1y0, p1y1;
573 Pt3 p00z, p01z, p10z, p11z;
574 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
576 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
577 GetPoint(p001, 0, 0, nbz-1, nbx, nby, nbz, np, meshDS);
578 GetPoint(p010, 0, nby-1, 0, nbx, nby, nbz, np, meshDS);
579 GetPoint(p011, 0, nby-1, nbz-1, nbx, nby, nbz, np, meshDS);
580 GetPoint(p100, nbx-1, 0, 0, nbx, nby, nbz, np, meshDS);
581 GetPoint(p101, nbx-1, 0, nbz-1, nbx, nby, nbz, np, meshDS);
582 GetPoint(p110, nbx-1, nby-1, 0, nbx, nby, nbz, np, meshDS);
583 GetPoint(p111, nbx-1, nby-1, nbz-1, nbx, nby, nbz, np, meshDS);
585 for (int i=1; i<nbx-1; i++)
587 for (int j=1; j<nby-1; j++)
589 for (int k=1; k<nbz-1; k++)
591 // *** seulement maillage regulier
592 // 12 points on edges
593 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
594 GetPoint(px01, i, 0, nbz-1, nbx, nby, nbz, np, meshDS);
595 GetPoint(px10, i, nby-1, 0, nbx, nby, nbz, np, meshDS);
596 GetPoint(px11, i, nby-1, nbz-1, nbx, nby, nbz, np, meshDS);
598 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
599 GetPoint(p0y1, 0, j, nbz-1, nbx, nby, nbz, np, meshDS);
600 GetPoint(p1y0, nbx-1, j, 0, nbx, nby, nbz, np, meshDS);
601 GetPoint(p1y1, nbx-1, j, nbz-1, nbx, nby, nbz, np, meshDS);
603 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
604 GetPoint(p01z, 0, nby-1, k, nbx, nby, nbz, np, meshDS);
605 GetPoint(p10z, nbx-1, 0, k, nbx, nby, nbz, np, meshDS);
606 GetPoint(p11z, nbx-1, nby-1, k, nbx, nby, nbz, np, meshDS);
608 // 12 points on faces
609 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
610 GetPoint(pxy1, i, j, nbz-1, nbx, nby, nbz, np, meshDS);
611 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
612 GetPoint(px1z, i, nby-1, k, nbx, nby, nbz, np, meshDS);
613 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
614 GetPoint(p1yz, nbx-1, j, k, nbx, nby, nbz, np, meshDS);
616 int ijk = k*nbx*nby + j*nbx + i;
617 double x = double(i)/double(nbx-1); // *** seulement
618 double y = double(j)/double(nby-1); // *** maillage
619 double z = double(k)/double(nbz-1); // *** regulier
622 for (int i=0; i<3; i++)
625 (1-x)*p0yz[i] + x*p1yz[i]
626 +(1-y)*px0z[i] + y*px1z[i]
627 +(1-z)*pxy0[i] + z*pxy1[i]
628 -(1-x)*((1-y)*p00z[i] + y*p01z[i])
629 - x *((1-y)*p10z[i] + y*p11z[i])
630 -(1-y)*((1-z)*px00[i] + z*px01[i])
631 - y *((1-z)*px10[i] + z*px11[i])
632 -(1-z)*((1-x)*p0y0[i] + x*p1y0[i])
633 - z *((1-x)*p0y1[i] + x*p1y1[i])
634 +(1-x)*( (1-y)*((1-z)*p000[i] + z*p001[i])
635 + y *((1-z)*p010[i] + z*p011[i]))
636 + x *( (1-y)*((1-z)*p100[i] + z*p101[i])
637 + y *((1-z)*p110[i] + z*p111[i]));
641 int myNodeId = meshDS->AddNode(X[0],X[1],X[2]);
642 //MESSAGE("point "<<myNodeId<<" "<<X[0]<<" "<<X[1]<<" "<<X[2]);
643 np[ijk].nodeId = myNodeId;
644 Handle (SMDS_MeshElement) elt = meshDS->FindNode(myNodeId);
645 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
647 //meshDS->SetNodeInVolume(node, TopoDS::Solid(aShape));
648 meshDS->SetNodeInVolume(node, aShell);
653 //2.1 - for each node of the cube (less 3 *1 Faces):
654 // - store hexahedron in SMESHDS
656 for (int i=0; i<nbx-1; i++)
657 for (int j=0; j<nby-1; j++)
658 for (int k=0; k<nbz-1; k++)
660 int n1 = k *nbx*nby + j *nbx + i;
661 int n2 = k *nbx*nby + j *nbx + i+1;
662 int n3 = k *nbx*nby + (j+1)*nbx + i+1;
663 int n4 = k *nbx*nby + (j+1)*nbx + i;
664 int n5 = (k+1)*nbx*nby + j *nbx + i;
665 int n6 = (k+1)*nbx*nby + j *nbx + i+1;
666 int n7 = (k+1)*nbx*nby + (j+1)*nbx + i+1;
667 int n8 = (k+1)*nbx*nby + (j+1)*nbx + i;
669 // MESSAGE(" "<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<" "<<n7<<" "<<n8);
670 //MESSAGE(" "<<np[n1].nodeId<<" "<<np[n2].nodeId<<" "<<np[n3].nodeId<<" "<<np[n4].nodeId<<" "<<np[n5].nodeId<<" "<<np[n6].nodeId<<" "<<np[n7].nodeId<<" "<<np[n8].nodeId);
672 int hexa = meshDS->AddVolume(np[n1].nodeId,
680 Handle (SMDS_MeshElement) elt = meshDS->FindElement(hexa);
681 meshDS->SetMeshElementOnShape(elt, aShell);
683 // *** 5 tetrahedres ... verifier orientations,
684 // mettre en coherence &vec quadrangles-> triangles
685 // choisir afficher 1 parmi edges, face et volumes
686 // int tetra1 = meshDS->AddVolume(np[n1].nodeId,
690 // int tetra2 = meshDS->AddVolume(np[n2].nodeId,
694 // int tetra3 = meshDS->AddVolume(np[n5].nodeId,
698 // int tetra4 = meshDS->AddVolume(np[n5].nodeId,
702 // int tetra5 = meshDS->AddVolume(np[n5].nodeId,
712 //=============================================================================
716 //=============================================================================
718 void SMESH_Hexa_3D::GetPoint(Pt3 p,
720 int nbx, int nby, int nbz,
722 const Handle(SMESHDS_Mesh)& meshDS)
724 int ijk = k*nbx*nby + j*nbx + i;
725 int nodeId = np[ijk].nodeId;
726 Handle (SMDS_MeshElement) elt = meshDS->FindNode(nodeId);
727 Handle (SMDS_MeshNode) node = meshDS->GetNode(1, elt);
731 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
734 //=============================================================================
738 //=============================================================================
740 int SMESH_Hexa_3D::GetFaceIndex(SMESH_Mesh& aMesh,
741 const TopoDS_Shape& aShape,
742 const vector<SMESH_subMesh*>& meshFaces,
743 const TopoDS_Vertex& V0,
744 const TopoDS_Vertex& V1,
745 const TopoDS_Vertex& V2,
746 const TopoDS_Vertex& V3)
748 MESSAGE("SMESH_Hexa_3D::GetFaceIndex");
750 for (int i=1; i<6; i++)
752 const TopoDS_Shape& aFace = meshFaces[i]->GetSubShape();
753 //const TopoDS_Face& F = TopoDS::Face(aFace);
754 TopTools_IndexedMapOfShape M;
755 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
756 bool verticesInShape = false;
760 if (M.Contains(V3)) verticesInShape = true;
772 //=============================================================================
776 //=============================================================================
779 SMESH_Hexa_3D::EdgeNotInFace(SMESH_Mesh& aMesh,
780 const TopoDS_Shape& aShape,
781 const TopoDS_Face& aFace,
782 const TopoDS_Vertex& aVertex,
783 const TopTools_IndexedDataMapOfShapeListOfShape& MS)
785 MESSAGE("SMESH_Hexa_3D::EdgeNotInFace");
786 TopTools_IndexedDataMapOfShapeListOfShape MF;
787 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
788 const TopTools_ListOfShape& ancestorsInSolid = MS.FindFromKey(aVertex);
789 const TopTools_ListOfShape& ancestorsInFace = MF.FindFromKey(aVertex);
790 SCRUTE(ancestorsInSolid.Extent());
791 SCRUTE(ancestorsInFace.Extent());
792 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
793 ASSERT(ancestorsInFace.Extent() == 2);
797 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
798 for ( ; its.More();its.Next())
800 TopoDS_Shape ancestor = its.Value();
801 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
802 bool isInFace = false;
803 for ( ; itf.More();itf.Next())
805 TopoDS_Shape ancestorInFace = itf.Value();
806 if (ancestorInFace.IsSame(ancestor))
814 E = TopoDS::Edge(ancestor);
821 //=============================================================================
825 //=============================================================================
827 void SMESH_Hexa_3D::GetConv2DCoefs(const faceQuadStruct& quad,
828 const TopoDS_Shape& aShape,
829 const TopoDS_Vertex& V0,
830 const TopoDS_Vertex& V1,
831 const TopoDS_Vertex& V2,
832 const TopoDS_Vertex& V3,
835 MESSAGE("SMESH_Hexa_3D::GetConv2DCoefs");
836 const TopoDS_Face& F = TopoDS::Face(aShape);
837 TopoDS_Edge E = quad.edge[0];
839 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
840 TopoDS_Vertex VFirst, VLast;
841 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
842 bool isForward = (((l-f)*(quad.last[0] - quad.first[0])) > 0);
843 TopoDS_Vertex VA, VB;
846 VA = VFirst; VB = VLast;
850 VA = VLast; VB = VFirst;
852 int a1,b1,c1,a2,b2,c2;
856 a1= 1; b1= 0; c1= 0; // x
857 a2= 0; b2= 1; c2= 0; // y
861 ASSERT(VB.IsSame(V3));
862 a1= 0; b1= 1; c1= 0; // y
863 a2= 1; b2= 0; c2= 0; // x
868 a1= 0; b1=-1; c1= 1; // 1-y
869 a2= 1; b2= 0; c2= 0; // x
873 ASSERT(VB.IsSame(V0));
874 a1=-1; b1= 0; c1= 1; // 1-x
875 a2= 0; b2= 1; c2= 0; // y
880 a1=-1; b1= 0; c1= 1; // 1-x
881 a2= 0; b2=-1; c2= 1; // 1-y
885 ASSERT(VB.IsSame(V1));
886 a1= 0; b1=-1; c1= 1; // 1-y
887 a2=-1; b2= 0; c2= 1; // 1-x
892 a1= 0; b1= 1; c1= 0; // y
893 a2=-1; b2= 0; c2= 1; // 1-x
897 ASSERT(VB.IsSame(V2));
898 a1= 1; b1= 0; c1= 0; // x
899 a2= 0; b2=-1; c2= 1; // 1-y
901 MESSAGE("X = "<<c1<<"+ "<<a1<<"*x + "<<b1<<"*y");
902 MESSAGE("Y = "<<c2<<"+ "<<a2<<"*x + "<<b2<<"*y");
903 conv.a1=a1; conv.b1=b1; conv.c1=c1;
904 conv.a2=a2; conv.b2=b2; conv.c2=c2;
906 int nbdown = quad.nbPts[0];
907 int nbright = quad.nbPts[1];
910 conv.ic = int(c1*a1*a1)*(nbdown-1) + int(c1*b1*b1)*(nbright-1);
913 conv.jc = int(c2*a2*a2)*(nbdown-1) + int(c2*b2*b2)*(nbright-1);
914 MESSAGE("I "<<conv.ia<<" "<<conv.ib<<" "<<conv.ic);
915 MESSAGE("J "<<conv.ja<<" "<<conv.jb<<" "<<conv.jc);
918 //=============================================================================
922 //=============================================================================
924 ostream & SMESH_Hexa_3D::SaveTo(ostream & save)
929 //=============================================================================
933 //=============================================================================
935 istream & SMESH_Hexa_3D::LoadFrom(istream & load)
937 return load >> (*this);
940 //=============================================================================
944 //=============================================================================
946 ostream & operator << (ostream & save, SMESH_Hexa_3D & hyp)
951 //=============================================================================
955 //=============================================================================
957 istream & operator >> (istream & load, SMESH_Hexa_3D & hyp)