Salome HOME
2515543aafbac5a51c3a6696be161a2569b0f34b
[modules/smesh.git] / doc / examples / creating_parallel_2D_mesh.py
1 # contains function to compute a mesh in parallel
2 import salome
3
4 salome.salome_init()
5 import salome_notebook
6 notebook = salome_notebook.NoteBook()
7
8 ###
9 ### GEOM component
10 ###
11
12 import GEOM
13 from salome.geom import geomBuilder
14 from salome.smesh import smeshBuilder
15 import SALOMEDS
16
17 import numpy as np
18
19 geompy = geomBuilder.New()
20
21
22 nbox = 2
23 boxsize = 100
24 offset = 0
25 # Create 3D faces
26 boxes = []
27 # First creating all the boxes
28 # for i in range(nbox):
29 #     for j in range(nbox):
30 #         for k in range(nbox):
31
32 #             x_orig = i*(boxsize+offset)
33 #             y_orig = j*(boxsize+offset)
34 #             z_orig = k*(boxsize+offset)
35
36 #             tmp_box = geompy.MakeBoxDXDYDZ(boxsize, boxsize, boxsize)
37
38 #             if not i == j == k == 0:
39 #                 box = geompy.MakeTranslation(tmp_box, x_orig,
40 #                                              y_orig, z_orig)
41 #             else:
42 #                 box = tmp_box
43
44 #             geompy.addToStudy(box, 'box_{}:{}:{}'.format(i, j, k))
45
46 #             boxes.append(box)
47
48 #With 6 boxes works
49 #But simplify for 2 boxes to also Test possibility of rewritting the
50 # input mesh from other parallel tests. In that case this test will break
51 # because the input mesh will not match the exported/imported box geometry.
52 for i in range(nbox):
53     for j in range(1):
54         for k in range(1):
55
56             x_orig = i*(boxsize+offset)
57             y_orig = j*(boxsize+offset)
58             z_orig = k*(boxsize+offset)
59
60             tmp_box = geompy.MakeBoxDXDYDZ(boxsize, boxsize, boxsize)
61
62             if not i == j == k == 0:
63                 box = geompy.MakeTranslation(tmp_box, x_orig,
64                                              y_orig, z_orig)
65             else:
66                 box = tmp_box
67
68             geompy.addToStudy(box, 'box_{}:{}:{}'.format(i, j, k))
69
70             boxes.append(box)
71
72 # Create fuse of all boxes
73 all_boxes = geompy.MakeCompound(boxes)
74 geompy.addToStudy(all_boxes, 'Compound_1')
75
76 # Removing duplicates faces and edges
77 all_boxes = geompy.MakeGlueFaces(all_boxes, 1e-07)
78 geompy.addToStudy(all_boxes, 'Glued_Faces_1')
79
80 rubik_cube = geompy.MakeGlueEdges(all_boxes, 1e-07)
81 geompy.addToStudy(rubik_cube, 'rubik_cube')
82
83
84 smesh = smeshBuilder.New()
85 print("Creating Parallel Mesh")
86 par_mesh = smesh.ParallelMesh(rubik_cube, name="par_mesh")
87
88 print("Creating hypoehtesis for netgen")
89 NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters_2D',
90                                          'NETGENEngine', 34.641, 0 )
91
92 print("Adding hypothesis")
93 par_mesh.Add2DGlobalHypothesis(NETGEN_2D_Parameters_1)
94
95 print("Setting parallelism method")
96 par_mesh.SetParallelismMethod(smeshBuilder.MULTITHREAD)
97
98 print("Setting parallelism options")
99 param = par_mesh.GetParallelismSettings()
100 param.SetNbThreads(6)
101
102 print("Starting parallel compute")
103 is_done = par_mesh.Compute()
104 if not is_done:
105     raise Exception("Error when computing Mesh")
106
107 print("  Triangle: ", par_mesh.NbTriangles())
108 print("  edge: ", par_mesh.NbEdges())
109
110 assert  par_mesh.NbTetras() == 0
111 assert  par_mesh.NbTriangles() > 0
112 assert  par_mesh.NbEdges() > 0