Salome HOME
ae4ee930207a5967b8766c223c4a7b9e7f9f689e
[modules/hexablock.git] / src / TEST_PY / test_unit / cut_grille.py
1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2023  CEA, EDF
3 #
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, or (at your option) any later version.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # Francis KLOSS - 2011 - CEA-Saclay, DEN, DM2S, SFME, LGLS, F-91191 Gif-sur-Yvette, France
22 # ========================================================================================
23
24 import hexablock
25 geompy = hexablock.geompy
26
27 # Construire le modèle de blocs
28 # =============================
29
30 nom = "exemple_cut"
31
32 # Créer le document
33 # -----------------
34
35 doc = hexablock.addDocument("default")
36
37 # Construire la grille sphérique
38 # ------------------------------
39
40 centre = doc.addVertex(0, 0, 0)
41
42 vecteur_x = doc.addVector(1, 0, 0)
43 vecteur_y = doc.addVector(0, 1, 0)
44 vecteur_z = doc.addVector(0, 0, 1)
45
46 grille = doc.makeCartesian(centre,  vecteur_x, vecteur_y, vecteur_z,  4, 3, 2)
47
48 # Associer une arête, puis couper cettee arête
49 # --------------------------------------------
50
51 arete = grille.getEdgeJ(0, 1, 0)
52
53 sommet_a = arete.getVertex(0)
54 sommet_b = arete.getVertex(1)
55
56 ax = sommet_a.getX()
57 ay = sommet_a.getY()
58 az = sommet_a.getZ()
59
60 bx = sommet_b.getX()
61 by = sommet_b.getY()
62 bz = sommet_b.getZ()
63
64 mx = (ax+bx)/2.0 - 0.25
65 my = (ay+by)/2.0
66 mz = (az+bz)/2.0
67
68 vertex_d = geompy.MakeVertex(ax, ay, az)
69 vertex_m = geompy.MakeVertex(mx, my, mz)
70 vertex_f = geompy.MakeVertex(bx, by, bz)
71
72 edge = geompy.MakeArc(vertex_d, vertex_m, vertex_f)
73 geompy.addToStudy(edge, "arc")
74 geompy.addToStudy(vertex_d, "debut")
75 geompy.addToStudy(vertex_m, "milieu")
76 geompy.addToStudy(vertex_f, "fin")
77
78 sommet_a.setAssociation(vertex_d)
79 sommet_b.setAssociation(vertex_f)
80
81 arete.addAssociation(edge, 0, 1)
82
83 elements = doc.cut(arete, 4)
84
85 # Définir la loi de maillage sur les propagations
86 # -----------------------------------------------
87
88 l = doc.addLaw("Uniform", 5)
89 n = doc.countPropagation()
90
91 for i in range(n):
92   p = doc.getPropagation(i)
93   p.setLaw(l)
94
95 # Générer le maillage
96 # -------------------
97 maillage = hexablock.mesh (doc)
98
99 # Afficher des informations
100 # -------------------------
101
102 print("Sur le document:")
103 print("nombre de sommets     du modèle de bloc: ", doc.countUsedVertex())
104 print("nombre d'arêtes       du modèle de bloc: ", doc.countUsedEdge())
105 print("nombre de quadrangles du modèle de bloc: ", doc.countUsedQuad())
106 print("nombre de blocs       du modèle de bloc: ", doc.countUsedHexa())
107
108 print("Sur le maillage:")
109 print("  - Nombre de noeuds     : ", maillage.NbNodes())
110 print("  - Nombre de segments   : ", maillage.NbEdges())
111 print("  - Nombre de quadrangles: ", maillage.NbQuadrangles())
112 print("  - Nombre d'hexaèdres   : ", maillage.NbHexas())