2 # -*- coding: utf-8 -*-
3 """Raffinement uniforme d'un maillage en triangles
9 __revision__ = "V02.04"
16 #=============== Options ====================
17 # REPDATA = répertoire du cas-test
18 REPDATA = tempfile.mkdtemp()
21 NOM_MAILLAGE = "Maillage"
22 #============================================
24 from salome.shaper import model
27 partSet = model.moduleDocument()
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))
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
39 SketchLine_1 = Sketch_1.addLine(36, 0, 0, 0)
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())
47 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 24)
50 SketchLine_3 = Sketch_1.addLine(0, 24, 36, 24)
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")
67 Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")])
70 Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Face_1")], model.selection("EDGE", "PartSet/OY"), keepOriginal = True, keepSubResults = True)
73 Symmetry_2 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], model.selection("EDGE", "PartSet/OX"), keepOriginal = True, keepSubResults = True)
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)
79 Recover_1 = model.addRecover(Part_1_doc, Rotation_1, [Symmetry_2.result()])
82 Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPOUND", "all-in-Rotation_1"), model.selection("COMPOUND", "all-in-Recover_1")], keepSubResults = True)
85 for IAUX in range(1,9):
86 _ = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Partition_1_1_{}".format(IAUX))])
91 ### SHAPERSTUDY component
94 model.publishToShaperStudy()
96 l_aux = SHAPERSTUDY.shape(model.featureStringId(Partition_1))
103 from salome.smesh import smeshBuilder
105 smesh = smeshBuilder.New()
107 Maillage_1 = smesh.Mesh(l_aux[0])
108 Maillage_1.SetName(NOM_MAILLAGE)
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)
119 _ = Maillage_1.Compute()
121 FIC_MAIL = os.path.join(REPDATA, "Uniform_01.med")
122 Maillage_1.ExportMED(FIC_MAIL)
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()
138 if os.path.isfile(FIC_MAIL):
141 print("Test Uniform refinement: Error: no output med file")
147 if salome.sg.hasDesktop():
148 salome.sg.updateObjBrowser()