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"
36 #include "SMDS_MeshElement.hxx"
37 #include "SMDS_MeshNode.hxx"
38 #include "SMDS_FacePosition.hxx"
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Geom_Surface.hxx>
48 #include <Geom_Curve.hxx>
49 #include <Geom2d_Curve.hxx>
50 #include <Handle_Geom2d_Curve.hxx>
51 #include <Handle_Geom_Curve.hxx>
52 #include <gp_Pnt2d.hxx>
54 #include "utilities.h"
55 #include "Utils_ExceptHandlers.hxx"
58 //=============================================================================
62 //=============================================================================
64 StdMeshers_Hexa_3D::StdMeshers_Hexa_3D(int hypId, int studyId,
65 SMESH_Gen * gen):SMESH_3D_Algo(hypId, studyId, gen)
67 MESSAGE("StdMeshers_Hexa_3D::StdMeshers_Hexa_3D");
69 // _shapeType = TopAbs_SOLID;
70 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
71 // MESSAGE("_shapeType octal " << oct << _shapeType);
72 for (int i = 0; i < 6; i++)
76 //=============================================================================
80 //=============================================================================
82 StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D()
84 MESSAGE("StdMeshers_Hexa_3D::~StdMeshers_Hexa_3D");
87 //=============================================================================
91 //=============================================================================
93 bool StdMeshers_Hexa_3D::CheckHypothesis
95 const TopoDS_Shape& aShape,
96 SMESH_Hypothesis::Hypothesis_Status& aStatus)
98 //MESSAGE("StdMeshers_Hexa_3D::CheckHypothesis");
101 aStatus = SMESH_Hypothesis::HYP_OK;
108 //=======================================================================
110 //purpose : return i,j of the node
111 //=======================================================================
113 static bool findIJ (const SMDS_MeshNode* node, const FaceQuadStruct * quad, int& I, int& J)
116 const SMDS_FacePosition* fpos =
117 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
118 if ( ! fpos ) return false;
119 gp_Pnt2d uv( fpos->GetUParameter(), fpos->GetVParameter() );
121 double minDist = DBL_MAX;
122 int nbhoriz = Min(quad->nbPts[0], quad->nbPts[2]);
123 int nbvertic = Min(quad->nbPts[1], quad->nbPts[3]);
124 for (int i = 1; i < nbhoriz - 1; i++) {
125 for (int j = 1; j < nbvertic - 1; j++) {
126 int ij = j * nbhoriz + i;
127 gp_Pnt2d uv2( quad->uv_grid[ij].u, quad->uv_grid[ij].v );
128 double dist = uv.SquareDistance( uv2 );
129 if ( dist < minDist ) {
139 //=============================================================================
141 * Hexahedron mesh on hexaedron like form
142 * -0. - shape and face mesh verification
143 * -1. - identify faces and vertices of the "cube"
144 * -2. - Algorithm from:
145 * "Application de l'interpolation transfinie à la création de maillages
146 * C0 ou G1 continus sur des triangles, quadrangles, tetraedres, pentaedres
147 * et hexaedres déformés."
148 * Alain PERONNET - 8 janvier 1999
150 //=============================================================================
152 bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
153 const TopoDS_Shape & aShape)throw(SALOME_Exception)
155 Unexpect aCatch(SalomeException);
156 MESSAGE("StdMeshers_Hexa_3D::Compute");
159 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
160 SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
161 //const SMESHDS_SubMesh *& subMeshDS = theSubMesh->GetSubMeshDS();
163 // 0. - shape and face mesh verification
164 // 0.1 - shape must be a solid (or a shell) with 6 faces
167 vector < SMESH_subMesh * >meshFaces;
168 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next())
170 SMESH_subMesh *aSubMesh = aMesh.GetSubMeshContaining(exp.Current());
172 meshFaces.push_back(aSubMesh);
174 if (meshFaces.size() != 6)
176 SCRUTE(meshFaces.size());
181 // 0.2 - is each face meshed with Quadrangle_2D? (so, with a wire of 4 edges)
184 for (int i = 0; i < 6; i++)
186 TopoDS_Shape aShape = meshFaces[i]->GetSubShape();
187 SMESH_Algo *algo = _gen->GetAlgo(aMesh, aShape);
188 string algoName = algo->GetName();
189 if (algoName != "Quadrangle_2D")
196 StdMeshers_Quadrangle_2D *quadAlgo =
197 dynamic_cast < StdMeshers_Quadrangle_2D * >(algo);
201 _quads[i] = quadAlgo->CheckAnd2Dcompute(aMesh, aShape);
202 // *** to delete after usage
204 catch(SALOME_Exception & S_ex)
207 // *** throw exception
212 // 0.2.1 - number of points on the opposite edges must be the same
213 if (_quads[i]->nbPts[0] != _quads[i]->nbPts[2] ||
214 _quads[i]->nbPts[1] != _quads[i]->nbPts[3])
216 MESSAGE("different number of points on the opposite edges of face " << i);
222 // 1. - identify faces and vertices of the "cube"
223 // 1.1 - ancestor maps vertex->edges in the cube
226 TopTools_IndexedDataMapOfShapeListOfShape MS;
227 TopExp::MapShapesAndAncestors(aShape, TopAbs_VERTEX, TopAbs_EDGE, MS);
229 // 1.2 - first face is choosen as face Y=0 of the unit cube
232 const TopoDS_Shape & aFace = meshFaces[0]->GetSubShape();
233 const TopoDS_Face & F = TopoDS::Face(aFace);
235 // 1.3 - identify the 4 vertices of the face Y=0: V000, V100, V101, V001
239 TopoDS_Edge E = _quads[0]->edge[i]; //edge will be Y=0,Z=0 on unit cube
241 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
242 TopoDS_Vertex VFirst, VLast;
243 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
245 (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
249 _cube.V000 = VFirst; // will be (0,0,0) on the unit cube
250 _cube.V100 = VLast; // will be (1,0,0) on the unit cube
259 E = _quads[0]->edge[i];
260 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
261 TopExp::Vertices(E, VFirst, VLast);
262 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
264 _cube.V101 = VLast; // will be (1,0,1) on the unit cube
269 E = _quads[0]->edge[i];
270 C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
271 TopExp::Vertices(E, VFirst, VLast);
272 isForward = (((l - f) * (_quads[0]->last[i] - _quads[0]->first[i])) > 0);
274 _cube.V001 = VLast; // will be (0,0,1) on the unit cube
278 // 1.4 - find edge X=0, Z=0 (ancestor of V000 not in face Y=0)
279 // - find edge X=1, Z=0 (ancestor of V100 not in face Y=0)
280 // - find edge X=1, Z=1 (ancestor of V101 not in face Y=0)
281 // - find edge X=0, Z=1 (ancestor of V001 not in face Y=0)
284 TopoDS_Edge E_0Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V000, MS);
285 ASSERT(!E_0Y0.IsNull());
287 TopoDS_Edge E_1Y0 = EdgeNotInFace(aMesh, aShape, F, _cube.V100, MS);
288 ASSERT(!E_1Y0.IsNull());
290 TopoDS_Edge E_1Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V101, MS);
291 ASSERT(!E_1Y1.IsNull());
293 TopoDS_Edge E_0Y1 = EdgeNotInFace(aMesh, aShape, F, _cube.V001, MS);
294 ASSERT(!E_0Y1.IsNull());
296 // 1.5 - identify the 4 vertices in face Y=1: V010, V110, V111, V011
299 TopExp::Vertices(E_0Y0, VFirst, VLast);
300 if (VFirst.IsSame(_cube.V000))
305 TopExp::Vertices(E_1Y0, VFirst, VLast);
306 if (VFirst.IsSame(_cube.V100))
311 TopExp::Vertices(E_1Y1, VFirst, VLast);
312 if (VFirst.IsSame(_cube.V101))
317 TopExp::Vertices(E_0Y1, VFirst, VLast);
318 if (VFirst.IsSame(_cube.V001))
323 // 1.6 - find remaining faces given 4 vertices
327 _cube.quad_Y0 = _quads[_indY0];
329 _indY1 = GetFaceIndex(aMesh, aShape, meshFaces,
330 _cube.V010, _cube.V011, _cube.V110, _cube.V111);
331 _cube.quad_Y1 = _quads[_indY1];
333 _indZ0 = GetFaceIndex(aMesh, aShape, meshFaces,
334 _cube.V000, _cube.V010, _cube.V100, _cube.V110);
335 _cube.quad_Z0 = _quads[_indZ0];
337 _indZ1 = GetFaceIndex(aMesh, aShape, meshFaces,
338 _cube.V001, _cube.V011, _cube.V101, _cube.V111);
339 _cube.quad_Z1 = _quads[_indZ1];
341 _indX0 = GetFaceIndex(aMesh, aShape, meshFaces,
342 _cube.V000, _cube.V001, _cube.V010, _cube.V011);
343 _cube.quad_X0 = _quads[_indX0];
345 _indX1 = GetFaceIndex(aMesh, aShape, meshFaces,
346 _cube.V100, _cube.V101, _cube.V110, _cube.V111);
347 _cube.quad_X1 = _quads[_indX1];
351 // 1.7 - get convertion coefs from face 2D normalized to 3D normalized
353 Conv2DStruct cx0; // for face X=0
354 Conv2DStruct cx1; // for face X=1
360 GetConv2DCoefs(*_cube.quad_X0, meshFaces[_indX0]->GetSubShape(),
361 _cube.V000, _cube.V010, _cube.V011, _cube.V001, cx0);
362 GetConv2DCoefs(*_cube.quad_X1, meshFaces[_indX1]->GetSubShape(),
363 _cube.V100, _cube.V110, _cube.V111, _cube.V101, cx1);
364 GetConv2DCoefs(*_cube.quad_Y0, meshFaces[_indY0]->GetSubShape(),
365 _cube.V000, _cube.V100, _cube.V101, _cube.V001, cy0);
366 GetConv2DCoefs(*_cube.quad_Y1, meshFaces[_indY1]->GetSubShape(),
367 _cube.V010, _cube.V110, _cube.V111, _cube.V011, cy1);
368 GetConv2DCoefs(*_cube.quad_Z0, meshFaces[_indZ0]->GetSubShape(),
369 _cube.V000, _cube.V100, _cube.V110, _cube.V010, cz0);
370 GetConv2DCoefs(*_cube.quad_Z1, meshFaces[_indZ1]->GetSubShape(),
371 _cube.V001, _cube.V101, _cube.V111, _cube.V011, cz1);
373 // 1.8 - create a 3D structure for normalized values
376 int nbx = _cube.quad_Z0->nbPts[0];
377 if (cz0.a1 == 0.) nbx = _cube.quad_Z0->nbPts[1];
379 int nby = _cube.quad_X0->nbPts[0];
380 if (cx0.a1 == 0.) nby = _cube.quad_X0->nbPts[1];
382 int nbz = _cube.quad_Y0->nbPts[0];
383 if (cy0.a1 != 0.) nbz = _cube.quad_Y0->nbPts[1];
384 // int nbx = _cube.quad_Y0->nbPts[0];
385 // int nby = _cube.quad_Y0->nbPts[1];
388 // nbz = _cube.quad_X0->nbPts[1];
390 // nbz = _cube.quad_X0->nbPts[0];
394 int i1, j1, nbxyz = nbx * nby * nbz;
395 Point3DStruct *np = new Point3DStruct[nbxyz];
397 // 1.9 - store node indexes of faces
400 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX0]->GetSubShape());
402 faceQuadStruct *quad = _cube.quad_X0;
403 int i = 0; // j = x/face , k = y/face
404 int nbdown = quad->nbPts[0];
405 int nbright = quad->nbPts[1];
408 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
412 const SMDS_MeshNode * node = itf->next();
413 findIJ( node, quad, i1, j1 );
414 int ij1 = j1 * nbdown + i1;
415 quad->uv_grid[ij1].node = node;
418 for (int i1 = 0; i1 < nbdown; i1++)
419 for (int j1 = 0; j1 < nbright; j1++)
421 int ij1 = j1 * nbdown + i1;
422 int j = cx0.ia * i1 + cx0.ib * j1 + cx0.ic; // j = x/face
423 int k = cx0.ja * i1 + cx0.jb * j1 + cx0.jc; // k = y/face
424 int ijk = k * nbx * nby + j * nbx + i;
425 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
426 np[ijk].node = quad->uv_grid[ij1].node;
427 //SCRUTE(np[ijk].nodeId);
432 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indX1]->GetSubShape());
434 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
436 faceQuadStruct *quad = _cube.quad_X1;
437 int i = nbx - 1; // j = x/face , k = y/face
438 int nbdown = quad->nbPts[0];
439 int nbright = quad->nbPts[1];
443 const SMDS_MeshNode * node = itf->next();
444 findIJ( node, quad, i1, j1 );
445 int ij1 = j1 * nbdown + i1;
446 quad->uv_grid[ij1].node = node;
449 for (int i1 = 0; i1 < nbdown; i1++)
450 for (int j1 = 0; j1 < nbright; j1++)
452 int ij1 = j1 * nbdown + i1;
453 int j = cx1.ia * i1 + cx1.ib * j1 + cx1.ic; // j = x/face
454 int k = cx1.ja * i1 + cx1.jb * j1 + cx1.jc; // k = y/face
455 int ijk = k * nbx * nby + j * nbx + i;
456 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
457 np[ijk].node = quad->uv_grid[ij1].node;
458 //SCRUTE(np[ijk].nodeId);
463 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY0]->GetSubShape());
465 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
467 faceQuadStruct *quad = _cube.quad_Y0;
468 int j = 0; // i = x/face , k = y/face
469 int nbdown = quad->nbPts[0];
470 int nbright = quad->nbPts[1];
474 const SMDS_MeshNode * node = itf->next();
475 findIJ( node, quad, i1, j1 );
476 int ij1 = j1 * nbdown + i1;
477 quad->uv_grid[ij1].node = node;
480 for (int i1 = 0; i1 < nbdown; i1++)
481 for (int j1 = 0; j1 < nbright; j1++)
483 int ij1 = j1 * nbdown + i1;
484 int i = cy0.ia * i1 + cy0.ib * j1 + cy0.ic; // i = x/face
485 int k = cy0.ja * i1 + cy0.jb * j1 + cy0.jc; // k = y/face
486 int ijk = k * nbx * nby + j * nbx + i;
487 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
488 np[ijk].node = quad->uv_grid[ij1].node;
489 //SCRUTE(np[ijk].nodeId);
494 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indY1]->GetSubShape());
496 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
498 faceQuadStruct *quad = _cube.quad_Y1;
499 int j = nby - 1; // i = x/face , k = y/face
500 int nbdown = quad->nbPts[0];
501 int nbright = quad->nbPts[1];
505 const SMDS_MeshNode * node = itf->next();
506 findIJ( node, quad, i1, j1 );
507 int ij1 = j1 * nbdown + i1;
508 quad->uv_grid[ij1].node = node;
511 for (int i1 = 0; i1 < nbdown; i1++)
512 for (int j1 = 0; j1 < nbright; j1++)
514 int ij1 = j1 * nbdown + i1;
515 int i = cy1.ia * i1 + cy1.ib * j1 + cy1.ic; // i = x/face
516 int k = cy1.ja * i1 + cy1.jb * j1 + cy1.jc; // k = y/face
517 int ijk = k * nbx * nby + j * nbx + i;
518 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
519 np[ijk].node = quad->uv_grid[ij1].node;
520 //SCRUTE(np[ijk].nodeId);
525 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ0]->GetSubShape());
527 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
529 faceQuadStruct *quad = _cube.quad_Z0;
530 int k = 0; // i = x/face , j = y/face
531 int nbdown = quad->nbPts[0];
532 int nbright = quad->nbPts[1];
536 const SMDS_MeshNode * node = itf->next();
537 findIJ( node, quad, i1, j1 );
538 int ij1 = j1 * nbdown + i1;
539 quad->uv_grid[ij1].node = node;
542 for (int i1 = 0; i1 < nbdown; i1++)
543 for (int j1 = 0; j1 < nbright; j1++)
545 int ij1 = j1 * nbdown + i1;
546 int i = cz0.ia * i1 + cz0.ib * j1 + cz0.ic; // i = x/face
547 int j = cz0.ja * i1 + cz0.jb * j1 + cz0.jc; // j = y/face
548 int ijk = k * nbx * nby + j * nbx + i;
549 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
550 np[ijk].node = quad->uv_grid[ij1].node;
551 //SCRUTE(np[ijk].nodeId);
556 const TopoDS_Face & F = TopoDS::Face(meshFaces[_indZ1]->GetSubShape());
558 SMDS_NodeIteratorPtr itf= aMesh.GetSubMesh(F)->GetSubMeshDS()->GetNodes();
560 faceQuadStruct *quad = _cube.quad_Z1;
561 int k = nbz - 1; // i = x/face , j = y/face
562 int nbdown = quad->nbPts[0];
563 int nbright = quad->nbPts[1];
567 const SMDS_MeshNode * node = itf->next();
568 findIJ( node, quad, i1, j1 );
569 int ij1 = j1 * nbdown + i1;
570 quad->uv_grid[ij1].node = node;
573 for (int i1 = 0; i1 < nbdown; i1++)
574 for (int j1 = 0; j1 < nbright; j1++)
576 int ij1 = j1 * nbdown + i1;
577 int i = cz1.ia * i1 + cz1.ib * j1 + cz1.ic; // i = x/face
578 int j = cz1.ja * i1 + cz1.jb * j1 + cz1.jc; // j = y/face
579 int ijk = k * nbx * nby + j * nbx + i;
580 //MESSAGE(" "<<ij1<<" "<<i<<" "<<j<<" "<<ijk);
581 np[ijk].node = quad->uv_grid[ij1].node;
582 //SCRUTE(np[ijk].nodeId);
586 // 2.0 - for each node of the cube:
587 // - get the 8 points 3D = 8 vertices of the cube
588 // - get the 12 points 3D on the 12 edges of the cube
589 // - get the 6 points 3D on the 6 faces with their ID
590 // - compute the point 3D
591 // - store the point 3D in SMESHDS, store its ID in 3D structure
594 TopExp_Explorer exp(aShape, TopAbs_SHELL);
597 aShell = TopoDS::Shell(exp.Current());
601 MESSAGE("no shell...");
605 Pt3 p000, p001, p010, p011, p100, p101, p110, p111;
606 Pt3 px00, px01, px10, px11;
607 Pt3 p0y0, p0y1, p1y0, p1y1;
608 Pt3 p00z, p01z, p10z, p11z;
609 Pt3 pxy0, pxy1, px0z, px1z, p0yz, p1yz;
611 GetPoint(p000, 0, 0, 0, nbx, nby, nbz, np, meshDS);
612 GetPoint(p001, 0, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
613 GetPoint(p010, 0, nby - 1, 0, nbx, nby, nbz, np, meshDS);
614 GetPoint(p011, 0, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
615 GetPoint(p100, nbx - 1, 0, 0, nbx, nby, nbz, np, meshDS);
616 GetPoint(p101, nbx - 1, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
617 GetPoint(p110, nbx - 1, nby - 1, 0, nbx, nby, nbz, np, meshDS);
618 GetPoint(p111, nbx - 1, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
620 for (int i = 1; i < nbx - 1; i++)
622 for (int j = 1; j < nby - 1; j++)
624 for (int k = 1; k < nbz - 1; k++)
626 // *** seulement maillage regulier
627 // 12 points on edges
628 GetPoint(px00, i, 0, 0, nbx, nby, nbz, np, meshDS);
629 GetPoint(px01, i, 0, nbz - 1, nbx, nby, nbz, np, meshDS);
630 GetPoint(px10, i, nby - 1, 0, nbx, nby, nbz, np, meshDS);
631 GetPoint(px11, i, nby - 1, nbz - 1, nbx, nby, nbz, np, meshDS);
633 GetPoint(p0y0, 0, j, 0, nbx, nby, nbz, np, meshDS);
634 GetPoint(p0y1, 0, j, nbz - 1, nbx, nby, nbz, np, meshDS);
635 GetPoint(p1y0, nbx - 1, j, 0, nbx, nby, nbz, np, meshDS);
636 GetPoint(p1y1, nbx - 1, j, nbz - 1, nbx, nby, nbz, np, meshDS);
638 GetPoint(p00z, 0, 0, k, nbx, nby, nbz, np, meshDS);
639 GetPoint(p01z, 0, nby - 1, k, nbx, nby, nbz, np, meshDS);
640 GetPoint(p10z, nbx - 1, 0, k, nbx, nby, nbz, np, meshDS);
641 GetPoint(p11z, nbx - 1, nby - 1, k, nbx, nby, nbz, np, meshDS);
643 // 12 points on faces
644 GetPoint(pxy0, i, j, 0, nbx, nby, nbz, np, meshDS);
645 GetPoint(pxy1, i, j, nbz - 1, nbx, nby, nbz, np, meshDS);
646 GetPoint(px0z, i, 0, k, nbx, nby, nbz, np, meshDS);
647 GetPoint(px1z, i, nby - 1, k, nbx, nby, nbz, np, meshDS);
648 GetPoint(p0yz, 0, j, k, nbx, nby, nbz, np, meshDS);
649 GetPoint(p1yz, nbx - 1, j, k, nbx, nby, nbz, np, meshDS);
651 int ijk = k * nbx * nby + j * nbx + i;
652 double x = double (i) / double (nbx - 1); // *** seulement
653 double y = double (j) / double (nby - 1); // *** maillage
654 double z = double (k) / double (nbz - 1); // *** regulier
657 for (int i = 0; i < 3; i++)
660 (1 - x) * p0yz[i] + x * p1yz[i]
661 + (1 - y) * px0z[i] + y * px1z[i]
662 + (1 - z) * pxy0[i] + z * pxy1[i]
663 - (1 - x) * ((1 - y) * p00z[i] + y * p01z[i])
664 - x * ((1 - y) * p10z[i] + y * p11z[i])
665 - (1 - y) * ((1 - z) * px00[i] + z * px01[i])
666 - y * ((1 - z) * px10[i] + z * px11[i])
667 - (1 - z) * ((1 - x) * p0y0[i] + x * p1y0[i])
668 - z * ((1 - x) * p0y1[i] + x * p1y1[i])
669 + (1 - x) * ((1 - y) * ((1 - z) * p000[i] + z * p001[i])
670 + y * ((1 - z) * p010[i] + z * p011[i]))
671 + x * ((1 - y) * ((1 - z) * p100[i] + z * p101[i])
672 + y * ((1 - z) * p110[i] + z * p111[i]));
675 SMDS_MeshNode * node = meshDS->AddNode(X[0], X[1], X[2]);
677 //meshDS->SetNodeInVolume(node, TopoDS::Solid(aShape));
678 meshDS->SetNodeInVolume(node, aShell);
683 //2.1 - for each node of the cube (less 3 *1 Faces):
684 // - store hexahedron in SMESHDS
685 MESSAGE("Storing hexahedron into the DS");
686 for (int i = 0; i < nbx - 1; i++)
687 for (int j = 0; j < nby - 1; j++)
688 for (int k = 0; k < nbz - 1; k++)
690 int n1 = k * nbx * nby + j * nbx + i;
691 int n2 = k * nbx * nby + j * nbx + i + 1;
692 int n3 = k * nbx * nby + (j + 1) * nbx + i + 1;
693 int n4 = k * nbx * nby + (j + 1) * nbx + i;
694 int n5 = (k + 1) * nbx * nby + j * nbx + i;
695 int n6 = (k + 1) * nbx * nby + j * nbx + i + 1;
696 int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
697 int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
699 // MESSAGE(" "<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<" "<<n7<<" "<<n8);
700 //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);
702 SMDS_MeshVolume * elt = meshDS->AddVolume(np[n1].node,
711 meshDS->SetMeshElementOnShape(elt, aShell);
713 // *** 5 tetrahedres ... verifier orientations,
714 // mettre en coherence &vec quadrangles-> triangles
715 // choisir afficher 1 parmi edges, face et volumes
716 // int tetra1 = meshDS->AddVolume(np[n1].nodeId,
720 // int tetra2 = meshDS->AddVolume(np[n2].nodeId,
724 // int tetra3 = meshDS->AddVolume(np[n5].nodeId,
728 // int tetra4 = meshDS->AddVolume(np[n5].nodeId,
732 // int tetra5 = meshDS->AddVolume(np[n5].nodeId,
739 //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
743 //=============================================================================
747 //=============================================================================
749 void StdMeshers_Hexa_3D::GetPoint(Pt3 p, int i, int j, int k, int nbx, int nby,
750 int nbz, Point3DStruct * np, const SMESHDS_Mesh * meshDS)
752 int ijk = k * nbx * nby + j * nbx + i;
753 const SMDS_MeshNode * node = np[ijk].node;
757 //MESSAGE(" "<<i<<" "<<j<<" "<<k<<" "<<p[0]<<" "<<p[1]<<" "<<p[2]);
760 //=============================================================================
764 //=============================================================================
766 int StdMeshers_Hexa_3D::GetFaceIndex(SMESH_Mesh & aMesh,
767 const TopoDS_Shape & aShape,
768 const vector < SMESH_subMesh * >&meshFaces,
769 const TopoDS_Vertex & V0,
770 const TopoDS_Vertex & V1,
771 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3)
773 //MESSAGE("StdMeshers_Hexa_3D::GetFaceIndex");
775 for (int i = 1; i < 6; i++)
777 const TopoDS_Shape & aFace = meshFaces[i]->GetSubShape();
778 //const TopoDS_Face& F = TopoDS::Face(aFace);
779 TopTools_IndexedMapOfShape M;
780 TopExp::MapShapes(aFace, TopAbs_VERTEX, M);
781 bool verticesInShape = false;
786 verticesInShape = true;
793 ASSERT(faceIndex > 0);
798 //=============================================================================
802 //=============================================================================
805 StdMeshers_Hexa_3D::EdgeNotInFace(SMESH_Mesh & aMesh,
806 const TopoDS_Shape & aShape,
807 const TopoDS_Face & aFace,
808 const TopoDS_Vertex & aVertex,
809 const TopTools_IndexedDataMapOfShapeListOfShape & MS)
811 //MESSAGE("StdMeshers_Hexa_3D::EdgeNotInFace");
812 TopTools_IndexedDataMapOfShapeListOfShape MF;
813 TopExp::MapShapesAndAncestors(aFace, TopAbs_VERTEX, TopAbs_EDGE, MF);
814 const TopTools_ListOfShape & ancestorsInSolid = MS.FindFromKey(aVertex);
815 const TopTools_ListOfShape & ancestorsInFace = MF.FindFromKey(aVertex);
816 // SCRUTE(ancestorsInSolid.Extent());
817 // SCRUTE(ancestorsInFace.Extent());
818 ASSERT(ancestorsInSolid.Extent() == 6); // 6 (edges doublees)
819 ASSERT(ancestorsInFace.Extent() == 2);
823 TopTools_ListIteratorOfListOfShape its(ancestorsInSolid);
824 for (; its.More(); its.Next())
826 TopoDS_Shape ancestor = its.Value();
827 TopTools_ListIteratorOfListOfShape itf(ancestorsInFace);
828 bool isInFace = false;
829 for (; itf.More(); itf.Next())
831 TopoDS_Shape ancestorInFace = itf.Value();
832 if (ancestorInFace.IsSame(ancestor))
840 E = TopoDS::Edge(ancestor);
847 //=============================================================================
851 //=============================================================================
853 void StdMeshers_Hexa_3D::GetConv2DCoefs(const faceQuadStruct & quad,
854 const TopoDS_Shape & aShape,
855 const TopoDS_Vertex & V0,
856 const TopoDS_Vertex & V1,
857 const TopoDS_Vertex & V2, const TopoDS_Vertex & V3, Conv2DStruct & conv)
859 // MESSAGE("StdMeshers_Hexa_3D::GetConv2DCoefs");
860 const TopoDS_Face & F = TopoDS::Face(aShape);
861 TopoDS_Edge E = quad.edge[0];
863 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
864 TopoDS_Vertex VFirst, VLast;
865 TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l
866 bool isForward = (((l - f) * (quad.last[0] - quad.first[0])) > 0);
867 TopoDS_Vertex VA, VB;
878 int a1, b1, c1, a2, b2, c2;
891 ASSERT(VB.IsSame(V3));
911 ASSERT(VB.IsSame(V0));
931 ASSERT(VB.IsSame(V1));
951 ASSERT(VB.IsSame(V2));
959 // MESSAGE("X = " << c1 << "+ " << a1 << "*x + " << b1 << "*y");
960 // MESSAGE("Y = " << c2 << "+ " << a2 << "*x + " << b2 << "*y");
968 int nbdown = quad.nbPts[0];
969 int nbright = quad.nbPts[1];
973 int (c1 * a1 * a1) * (nbdown - 1) + int (c1 * b1 * b1) * (nbright - 1);
977 int (c2 * a2 * a2) * (nbdown - 1) + int (c2 * b2 * b2) * (nbright - 1);
978 // MESSAGE("I " << conv.ia << " " << conv.ib << " " << conv.ic);
979 // MESSAGE("J " << conv.ja << " " << conv.jb << " " << conv.jc);
982 //=============================================================================
986 //=============================================================================
988 ostream & StdMeshers_Hexa_3D::SaveTo(ostream & save)
993 //=============================================================================
997 //=============================================================================
999 istream & StdMeshers_Hexa_3D::LoadFrom(istream & load)
1004 //=============================================================================
1008 //=============================================================================
1010 ostream & operator <<(ostream & save, StdMeshers_Hexa_3D & hyp)
1012 return hyp.SaveTo( save );
1015 //=============================================================================
1019 //=============================================================================
1021 istream & operator >>(istream & load, StdMeshers_Hexa_3D & hyp)
1023 return hyp.LoadFrom( load );