1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : StdMeshers_Hexa_3D.cxx
25 // Moved here from SMESH_Hexa_3D.cxx
26 // Author : Paul RASCLE, EDF
31 #include "StdMeshers_Hexa_3D.hxx"
32 #include "StdMeshers_Quadrangle_2D.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_subMesh.hxx"
37 #include "SMDS_MeshElement.hxx"
38 #include "SMDS_MeshNode.hxx"
39 #include "SMDS_FacePosition.hxx"
42 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
43 #include <TopTools_ListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TColStd_ListIteratorOfListOfInteger.hxx>
47 #include <BRep_Tool.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_Curve.hxx>
50 #include <Geom2d_Curve.hxx>
51 #include <Handle_Geom2d_Curve.hxx>
52 #include <Handle_Geom_Curve.hxx>
53 #include <gp_Pnt2d.hxx>
55 #include "utilities.h"
56 #include "Utils_ExceptHandlers.hxx"
59 //=============================================================================
63 //=============================================================================
65 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
66 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
68 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
70 // _shapeType = TopAbs_SOLID;
71 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
72 // MESSAGE("_shapeType octal " << oct << _shapeType);
73 for (int i = 0; i < 6; i++)
77 //=============================================================================
81 //=============================================================================
83 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
85 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
88 //=============================================================================
92 //=============================================================================
94 bool StdMeshers_Hexa_3D::CheckHypothesis
96 const TopoDS_Shape& aShape,
97 SMESH_Hypothesis::Hypothesis_Status& aStatus)
99 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
102 aStatus = SMESH_Hypothesis::HYP_OK;
109 //=======================================================================
111 //purpose : return i,j of the node
112 //=======================================================================
114 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
117 const SMDS_FacePosition* fpos =
118 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
119 if ( ! fpos ) return false;
120 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
122 double minDist = DBL_MAX;
123 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
124 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
125 for (int i = 1; i < nbhoriz - 1; i++) {
126 for (int j = 1; j < nbvertic - 1; j++) {
127 int ij = j * nbhoriz + i;
128 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
129 double dist = uv.SquareDistance( uv2 );
130 if ( dist < minDist ) {
140 //=============================================================================
142 * Hexahedron mesh on hexaedron like form
143 * -0. - shape and face mesh verification
144 * -1. - identify faces and vertices of the "cube"
145 * -2. - Algorithm from:
146 * "Application de l'interpolation transfinie à la création de maillages
147 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
148 * et hexaedres déformés."
149 * Alain PERONNET - 8 janvier 1999
151 //=============================================================================
153 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
154 const TopoDS_Shape & aShape)throw(SALOME_Exception)
156 Unexpect aCatch(SalomeException);
157 MESSAGE("StdMeshers_Hexa_3D::Compute");
160 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
161 SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
162 //const SMESHDS_SubMesh *& subMeshDS = theSubMesh->GetSubMeshDS();
164 // 0. - shape and face mesh verification
165 // 0.1 - shape must be a solid (or a shell) with 6 faces
168 vector < SMESH_subMesh * >meshFaces;
169 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
171 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
173 meshFaces.push_back(aSubMesh);
175 if (meshFaces.size() != 6)
177 SCRUTE(meshFaces.size());
182 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
185 for (int i = 0; i < 6; i++)
187 TopoDS_Shape aShape = meshFaces[i]->GetSubShape();
188 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aShape);
189 string algoName = algo->GetName();
190 if (algoName != "Quadrangle_2D")
197 StdMeshers_Quadrangle_2D *quadAlgo =
198 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
202 _quads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aShape);
203 // *** to delete after usage
205 catch(SALOME_Exception & S_ex)
208 // *** throw exception
213 // 0.2.1 - number of points on the opposite edges must be the same
214 if (_quads[i]->nbPts[0] != _quads[i]->nbPts[2] ||
215 _quads[i]->nbPts[1] != _quads[i]->nbPts[3])
217 MESSAGE("different number of points on the opposite edges of face " << i);
223 // 1. - identify faces and vertices of the "cube"
224 // 1.1 - ancestor maps vertex->edges in the cube
227 TopTools_IndexedDataMapOfShapeListOfShape MS;
228 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
230 // 1.2 - first face is choosen as face Y=0 of the unit cube
233 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
234 const TopoDS_Face & F = TopoDS::Face(aFace);
236 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
240 TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
242 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
243 TopoDS_Vertex VFirst, VLast;
244 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
246 (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
250 _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
251 _cube.V100 = VLast; // will be (1,0,0) on the unit cube
260 E = _quads[0]->edge[i];
261 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
262 TopExp::Vertices(E, VFirst, VLast);
263 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
265 _cube.V101 = VLast; // will be (1,0,1) on the unit cube
270 E = _quads[0]->edge[i];
271 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
272 TopExp::Vertices(E, VFirst, VLast);
273 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
275 _cube.V001 = VLast; // will be (0,0,1) on the unit cube
279 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
280 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
281 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
282 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
285 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
286 ASSERT(!E_0Y0.IsNull());
288 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
289 ASSERT(!E_1Y0.IsNull());
291 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
292 ASSERT(!E_1Y1.IsNull());
294 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
295 ASSERT(!E_0Y1.IsNull());
297 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
300 TopExp::Vertices(E_0Y0, VFirst, VLast);
301 if (VFirst.IsSame(_cube.V000))
306 TopExp::Vertices(E_1Y0, VFirst, VLast);
307 if (VFirst.IsSame(_cube.V100))
312 TopExp::Vertices(E_1Y1, VFirst, VLast);
313 if (VFirst.IsSame(_cube.V101))
318 TopExp::Vertices(E_0Y1, VFirst, VLast);
319 if (VFirst.IsSame(_cube.V001))
324 // 1.6 - find remaining faces given 4 vertices
328 _cube.quad_Y0 = _quads[_indY0];
330 _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
331 _cube.V010, _cube.V011, _cube.V110, _cube.V111);
332 _cube.quad_Y1 = _quads[_indY1];
334 _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
335 _cube.V000, _cube.V010, _cube.V100, _cube.V110);
336 _cube.quad_Z0 = _quads[_indZ0];
338 _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
339 _cube.V001, _cube.V011, _cube.V101, _cube.V111);
340 _cube.quad_Z1 = _quads[_indZ1];
342 _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
343 _cube.V000, _cube.V001, _cube.V010, _cube.V011);
344 _cube.quad_X0 = _quads[_indX0];
346 _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
347 _cube.V100, _cube.V101, _cube.V110, _cube.V111);
348 _cube.quad_X1 = _quads[_indX1];
352 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
354 Conv2DStruct cx0; // for face X=0
355 Conv2DStruct cx1; // for face X=1
361 GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
362 _cube.V000, _cube.V010, _cube.V011, _cube.V001, cx0);
363 GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
364 _cube.V100, _cube.V110, _cube.V111, _cube.V101, cx1);
365 GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
366 _cube.V000, _cube.V100, _cube.V101, _cube.V001, cy0);
367 GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
368 _cube.V010, _cube.V110, _cube.V111, _cube.V011, cy1);
369 GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
370 _cube.V000, _cube.V100, _cube.V110, _cube.V010, cz0);
371 GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
372 _cube.V001, _cube.V101, _cube.V111, _cube.V011, cz1);
374 // 1.8 - create a 3D structure for normalized values
377 int nbx = _cube.quad_Z0->nbPts[0];
378 if (cz0.a1 == 0.) nbx = _cube.quad_Z0->nbPts[1];
380 int nby = _cube.quad_X0->nbPts[0];
381 if (cx0.a1 == 0.) nby = _cube.quad_X0->nbPts[1];
383 int nbz = _cube.quad_Y0->nbPts[0];
384 if (cy0.a1 != 0.) nbz = _cube.quad_Y0->nbPts[1];
385 // int nbx = _cube.quad_Y0->nbPts[0];
386 // int nby = _cube.quad_Y0->nbPts[1];
389 // nbz = _cube.quad_X0->nbPts[1];
391 // nbz = _cube.quad_X0->nbPts[0];
395 int i1, j1, nbxyz = nbx * nby * nbz;
396 Point3DStruct *np = new Point3DStruct[nbxyz];
398 // 1.9 - store node indexes of faces
401 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
403 faceQuadStruct *quad = _cube.quad_X0;
404 int i = 0; // j = x/face , k = y/face
405 int nbdown = quad->nbPts[0];
406 int nbright = quad->nbPts[1];
409 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
413 const SMDS_MeshNode * node = itf->next();
414 findIJ( node, quad, i1, j1 );
415 int ij1 = j1 * nbdown + i1;
416 quad->uv_grid[ij1].node = node;
419 for (int i1 = 0; i1 < nbdown; i1++)
420 for (int j1 = 0; j1 < nbright; j1++)
422 int ij1 = j1 * nbdown + i1;
423 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
424 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
425 int ijk = k * nbx * nby + j * nbx + i;
426 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
427 np[ijk].node = quad->uv_grid[ij1].node;
428 //SCRUTE(np[ijk].nodeId);
433 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
435 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
437 faceQuadStruct *quad = _cube.quad_X1;
438 int i = nbx - 1; // j = x/face , k = y/face
439 int nbdown = quad->nbPts[0];
440 int nbright = quad->nbPts[1];
444 const SMDS_MeshNode * node = itf->next();
445 findIJ( node, quad, i1, j1 );
446 int ij1 = j1 * nbdown + i1;
447 quad->uv_grid[ij1].node = node;
450 for (int i1 = 0; i1 < nbdown; i1++)
451 for (int j1 = 0; j1 < nbright; j1++)
453 int ij1 = j1 * nbdown + i1;
454 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
455 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
456 int ijk = k * nbx * nby + j * nbx + i;
457 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
458 np[ijk].node = quad->uv_grid[ij1].node;
459 //SCRUTE(np[ijk].nodeId);
464 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
466 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
468 faceQuadStruct *quad = _cube.quad_Y0;
469 int j = 0; // i = x/face , k = y/face
470 int nbdown = quad->nbPts[0];
471 int nbright = quad->nbPts[1];
475 const SMDS_MeshNode * node = itf->next();
476 findIJ( node, quad, i1, j1 );
477 int ij1 = j1 * nbdown + i1;
478 quad->uv_grid[ij1].node = node;
481 for (int i1 = 0; i1 < nbdown; i1++)
482 for (int j1 = 0; j1 < nbright; j1++)
484 int ij1 = j1 * nbdown + i1;
485 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
486 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
487 int ijk = k * nbx * nby + j * nbx + i;
488 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
489 np[ijk].node = quad->uv_grid[ij1].node;
490 //SCRUTE(np[ijk].nodeId);
495 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
497 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
499 faceQuadStruct *quad = _cube.quad_Y1;
500 int j = nby - 1; // i = x/face , k = y/face
501 int nbdown = quad->nbPts[0];
502 int nbright = quad->nbPts[1];
506 const SMDS_MeshNode * node = itf->next();
507 findIJ( node, quad, i1, j1 );
508 int ij1 = j1 * nbdown + i1;
509 quad->uv_grid[ij1].node = node;
512 for (int i1 = 0; i1 < nbdown; i1++)
513 for (int j1 = 0; j1 < nbright; j1++)
515 int ij1 = j1 * nbdown + i1;
516 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
517 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
518 int ijk = k * nbx * nby + j * nbx + i;
519 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
520 np[ijk].node = quad->uv_grid[ij1].node;
521 //SCRUTE(np[ijk].nodeId);
526 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
528 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
530 faceQuadStruct *quad = _cube.quad_Z0;
531 int k = 0; // i = x/face , j = y/face
532 int nbdown = quad->nbPts[0];
533 int nbright = quad->nbPts[1];
537 const SMDS_MeshNode * node = itf->next();
538 findIJ( node, quad, i1, j1 );
539 int ij1 = j1 * nbdown + i1;
540 quad->uv_grid[ij1].node = node;
543 for (int i1 = 0; i1 < nbdown; i1++)
544 for (int j1 = 0; j1 < nbright; j1++)
546 int ij1 = j1 * nbdown + i1;
547 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
548 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
549 int ijk = k * nbx * nby + j * nbx + i;
550 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
551 np[ijk].node = quad->uv_grid[ij1].node;
552 //SCRUTE(np[ijk].nodeId);
557 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
559 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
561 faceQuadStruct *quad = _cube.quad_Z1;
562 int k = nbz - 1; // i = x/face , j = y/face
563 int nbdown = quad->nbPts[0];
564 int nbright = quad->nbPts[1];
568 const SMDS_MeshNode * node = itf->next();
569 findIJ( node, quad, i1, j1 );
570 int ij1 = j1 * nbdown + i1;
571 quad->uv_grid[ij1].node = node;
574 for (int i1 = 0; i1 < nbdown; i1++)
575 for (int j1 = 0; j1 < nbright; j1++)
577 int ij1 = j1 * nbdown + i1;
578 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
579 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
580 int ijk = k * nbx * nby + j * nbx + i;
581 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
582 np[ijk].node = quad->uv_grid[ij1].node;
583 //SCRUTE(np[ijk].nodeId);
587 // 2.0 - for each node of the cube:
588 // - get the 8 points 3D = 8 vertices of the cube
589 // - get the 12 points 3D on the 12 edges of the cube
590 // - get the 6 points 3D on the 6 faces with their ID
591 // - compute the point 3D
592 // - store the point 3D in SMESHDS, store its ID in 3D structure
595 TopExp_Explorer exp(aShape, TopAbs_SHELL);
598 aShell = TopoDS::Shell(exp.Current());
602 MESSAGE("no shell...");
606 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
607 Pt3 px00, px01, px10, px11;
608 Pt3 p0y0, p0y1, p1y0, p1y1;
609 Pt3 p00z, p01z, p10z, p11z;
610 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
612 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
613 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
614 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
615 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
616 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
617 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
618 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
619 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
621 for (int i = 1; i < nbx - 1; i++)
623 for (int j = 1; j < nby - 1; j++)
625 for (int k = 1; k < nbz - 1; k++)
627 // *** seulement maillage regulier
628 // 12 points on edges
629 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
630 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
631 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
632 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
634 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
635 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
636 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
637 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
639 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
640 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
641 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
642 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
644 // 12 points on faces
645 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
646 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
647 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
648 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
649 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
650 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
652 int ijk = k * nbx * nby + j * nbx + i;
653 double x = double (i) / double (nbx - 1); // *** seulement
654 double y = double (j) / double (nby - 1); // *** maillage
655 double z = double (k) / double (nbz - 1); // *** regulier
658 for (int i = 0; i < 3; i++)
661 (1 - x) * p0yz[i] + x * p1yz[i]
662 + (1 - y) * px0z[i] + y * px1z[i]
663 + (1 - z) * pxy0[i] + z * pxy1[i]
664 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
665 - x * ((1 - y) * p10z[i] + y * p11z[i])
666 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
667 - y * ((1 - z) * px10[i] + z * px11[i])
668 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
669 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
670 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
671 + y * ((1 - z) * p010[i] + z * p011[i]))
672 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
673 + y * ((1 - z) * p110[i] + z * p111[i]));
676 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
678 //meshDS->SetNodeInVolume(node, TopoDS::Solid(aShape));
679 meshDS->SetNodeInVolume(node, aShell);
684 //2.1 - for each node of the cube (less 3 *1 Faces):
685 // - store hexahedron in SMESHDS
686 MESSAGE("Storing hexahedron into the DS");
687 for (int i = 0; i < nbx - 1; i++)
688 for (int j = 0; j < nby - 1; j++)
689 for (int k = 0; k < nbz - 1; k++)
691 int n1 = k * nbx * nby + j * nbx + i;
692 int n2 = k * nbx * nby + j * nbx + i + 1;
693 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
694 int n4 = k * nbx * nby + (j + 1) * nbx + i;
695 int n5 = (k + 1) * nbx * nby + j * nbx + i;
696 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
697 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
698 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
700 // MESSAGE(" "<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<" "<<n7<<" "<<n8);
701 //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);
703 SMDS_MeshVolume * elt = meshDS->AddVolume(np[n1].node,
712 meshDS->SetMeshElementOnShape(elt, aShell);
714 // *** 5 tetrahedres ... verifier orientations,
715 // mettre en coherence &vec quadrangles-> triangles
716 // choisir afficher 1 parmi edges, face et volumes
717 // int tetra1 = meshDS->AddVolume(np[n1].nodeId,
721 // int tetra2 = meshDS->AddVolume(np[n2].nodeId,
725 // int tetra3 = meshDS->AddVolume(np[n5].nodeId,
729 // int tetra4 = meshDS->AddVolume(np[n5].nodeId,
733 // int tetra5 = meshDS->AddVolume(np[n5].nodeId,
740 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
744 //=============================================================================
748 //=============================================================================
750 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
751 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
753 int ijk = k * nbx * nby + j * nbx + i;
754 const SMDS_MeshNode * node = np[ijk].node;
758 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
761 //=============================================================================
765 //=============================================================================
767 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
768 const TopoDS_Shape & aShape,
769 const vector < SMESH_subMesh * >&meshFaces,
770 const TopoDS_Vertex & V0,
771 const TopoDS_Vertex & V1,
772 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
774 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
776 for (int i = 1; i < 6; i++)
778 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
779 //const TopoDS_Face& F = TopoDS::Face(aFace);
780 TopTools_IndexedMapOfShape M;
781 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
782 bool verticesInShape = false;
787 verticesInShape = true;
794 ASSERT(faceIndex > 0);
799 //=============================================================================
803 //=============================================================================
806 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
807 const TopoDS_Shape & aShape,
808 const TopoDS_Face & aFace,
809 const TopoDS_Vertex & aVertex,
810 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
812 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
813 TopTools_IndexedDataMapOfShapeListOfShape MF;
814 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
815 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
816 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
817 // SCRUTE(ancestorsInSolid.Extent());
818 // SCRUTE(ancestorsInFace.Extent());
819 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
820 ASSERT(ancestorsInFace.Extent() == 2);
824 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
825 for (; its.More(); its.Next())
827 TopoDS_Shape ancestor = its.Value();
828 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
829 bool isInFace = false;
830 for (; itf.More(); itf.Next())
832 TopoDS_Shape ancestorInFace = itf.Value();
833 if (ancestorInFace.IsSame(ancestor))
841 E = TopoDS::Edge(ancestor);
848 //=============================================================================
852 //=============================================================================
854 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
855 const TopoDS_Shape & aShape,
856 const TopoDS_Vertex & V0,
857 const TopoDS_Vertex & V1,
858 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
860 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
861 const TopoDS_Face & F = TopoDS::Face(aShape);
862 TopoDS_Edge E = quad.edge[0];
864 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
865 TopoDS_Vertex VFirst, VLast;
866 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
867 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
868 TopoDS_Vertex VA, VB;
879 int a1, b1, c1, a2, b2, c2;
892 ASSERT(VB.IsSame(V3));
912 ASSERT(VB.IsSame(V0));
932 ASSERT(VB.IsSame(V1));
952 ASSERT(VB.IsSame(V2));
960 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
961 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
969 int nbdown = quad.nbPts[0];
970 int nbright = quad.nbPts[1];
974 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
978 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
979 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
980 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
983 //=============================================================================
987 //=============================================================================
989 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
994 //=============================================================================
998 //=============================================================================
1000 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1005 //=============================================================================
1009 //=============================================================================
1011 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1013 return hyp.SaveTo( save );
1016 //=============================================================================
1020 //=============================================================================
1022 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1024 return hyp.LoadFrom( load );