]> SALOME platform Git repositories - modules/smesh.git/blob - doc/salome/examples/test_cdc_uniform_01.py
Salome HOME
Call FrontTrack via its python interface
[modules/smesh.git] / doc / salome / examples / test_cdc_uniform_01.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """Raffinement uniforme d'un maillage en triangles
4
5 Copyright 2021 EDF
6 Gérald NICOLAS
7 +33.1.78.19.43.52
8 """
9 __revision__ = "V02.04"
10
11 import os
12 import tempfile
13
14 import salome
15
16 #=============== Options ====================
17 # REPDATA = répertoire du cas-test
18 REPDATA = tempfile.mkdtemp()
19 LONG = 36.
20 LARG = 24.
21 NOM_MAILLAGE = "Maillage"
22 #============================================
23
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28
29 ### Create Part
30 Part_1 = model.addPart(partSet)
31 Part_1_doc = Part_1.document()
32 model.addParameter(Part_1_doc, "Long", "{}".format(LONG))
33 model.addParameter(Part_1_doc, "Larg", "{}".format(LARG))
34
35 ### Create Sketch
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37
38 ### Create SketchLine
39 SketchLine_1 = Sketch_1.addLine(36, 0, 0, 0)
40
41 ### Create SketchProjection
42 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
43 SketchPoint_1 = SketchProjection_1.createdFeature()
44 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
45
46 ### Create SketchLine
47 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 24)
48
49 ### Create SketchLine
50 SketchLine_3 = Sketch_1.addLine(0, 24, 36, 24)
51
52 ### Create SketchLine
53 SketchLine_4 = Sketch_1.addLine(36, 24, 36, 0)
54 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
55 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
56 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
57 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
58 Sketch_1.setHorizontal(SketchLine_1.result())
59 Sketch_1.setVertical(SketchLine_2.result())
60 Sketch_1.setHorizontal(SketchLine_3.result())
61 Sketch_1.setVertical(SketchLine_4.result())
62 Sketch_1.setLength(SketchLine_3.result(), "Long")
63 Sketch_1.setLength(SketchLine_2.result(), "Larg")
64 model.do()
65
66 ### Create Face
67 Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")])
68
69 ### Create Symmetry
70 Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Face_1")], model.selection("EDGE", "PartSet/OY"), keepOriginal = True, keepSubResults = True)
71
72 ### Create Symmetry
73 Symmetry_2 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], model.selection("EDGE", "PartSet/OX"), keepOriginal = True, keepSubResults = True)
74
75 ### Create Rotation
76 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_2")], axis = model.selection("EDGE", "PartSet/OX"), angle = 90, keepSubResults = True)
77
78 ### Create Recover
79 Recover_1 = model.addRecover(Part_1_doc, Rotation_1, [Symmetry_2.result()])
80
81 ### Create Partition
82 Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPOUND", "all-in-Rotation_1"), model.selection("COMPOUND", "all-in-Recover_1")], keepSubResults = True)
83
84 ### Create Group
85 for IAUX in range(1,9):
86   _ = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Partition_1_1_{}".format(IAUX))])
87
88 model.end()
89
90 ###
91 ### SHAPERSTUDY component
92 ###
93
94 model.publishToShaperStudy()
95 import SHAPERSTUDY
96 l_aux = SHAPERSTUDY.shape(model.featureStringId(Partition_1))
97
98 ###
99 ### SMESH component
100 ###
101
102 import  SMESH
103 from salome.smesh import smeshBuilder
104
105 smesh = smeshBuilder.New()
106
107 Maillage_1 = smesh.Mesh(l_aux[0])
108 Maillage_1.SetName(NOM_MAILLAGE)
109
110 L_MAILLE = min(LARG,LONG)/5.
111 NETGEN_1D_2D = Maillage_1.Triangle(algo=smeshBuilder.NETGEN_1D2D)
112 NETGEN_2D_Parameters_1 = NETGEN_1D_2D.Parameters()
113 NETGEN_2D_Parameters_1.SetMaxSize( L_MAILLE )
114 NETGEN_2D_Parameters_1.SetMinSize( L_MAILLE/10. )
115 for groupe in l_aux[1:]:
116   groupe_nom = groupe.GetName()
117   _ = Maillage_1.GroupOnGeom(groupe,groupe_nom,SMESH.FACE)
118
119 _ = Maillage_1.Compute()
120
121 FIC_MAIL = os.path.join(REPDATA, "Uniform_01.med")
122 Maillage_1.ExportMED(FIC_MAIL)
123
124 # Uniform refinement
125 import SMESHHOMARD
126 smeshhomard = smesh.Adaptation("Uniform")
127 Case_1 = smeshhomard.CreateCase(NOM_MAILLAGE, FIC_MAIL, REPDATA)
128 Case_1.SetConfType(0)
129 smeshhomard.SetKeepMedOUT(True)
130 smeshhomard.SetPublishMeshOUT(True)
131 smeshhomard.SetMeshNameOUT("{}_R".format(NOM_MAILLAGE))
132 FIC_MAIL = os.path.join(REPDATA, "Uniform_01_R.med")
133 smeshhomard.SetMeshFileOUT(FIC_MAIL)
134 smeshhomard.SetKeepWorkingFiles(False)
135 codret = smeshhomard.Compute()
136
137 # Check
138 if os.path.isfile(FIC_MAIL):
139   os.remove(FIC_MAIL)
140 else:
141   print("Test Uniform refinement: Error: no output med file")
142   assert(False)
143
144 # Ménage
145 os.rmdir(REPDATA)
146
147 if salome.sg.hasDesktop():
148   salome.sg.updateObjBrowser()