Salome HOME
bos #26453: SMESH: uniform refinement
[modules/smesh.git] / doc / salome / examples / test_homard_adapt.py
1 #!/usr/bin/env python3
2
3
4
5 import salome
6 salome.salome_init_without_session()
7
8 import SMESH, SALOMEDS
9 from salome.smesh import smeshBuilder
10 import SMESHHOMARD
11
12 smesh = smeshBuilder.New()
13
14 import os, inspect, tempfile, shutil
15
16 data_dir = os.path.abspath(os.path.dirname(inspect.getfile(lambda: None)))
17 working_dir = tempfile.mkdtemp()
18
19 input_med = os.path.join (data_dir, "test_homard_adapt.med")
20 output_med_1 = os.path.join (working_dir, "test_1.00_Uniform_R_01.med")
21 output_med_2 = os.path.join (working_dir, "test_1.00_Uniform_R_02.med")
22 log_file_1 = os.path.join (working_dir, "test_1.00_Uniform_R_01.med.log")
23 log_file_2 = os.path.join (working_dir, "test_1.00_Uniform_R_02.med.log")
24
25 # Case 1: input: med file
26 #         output: med file, log file, published mesh
27 if os.path.isfile(output_med_1):
28   os.remove(output_med_1)
29 if os.path.isfile(log_file_1):
30   os.remove(log_file_1)
31
32 smeshhomard = smesh.Adaptation("Uniform")
33 smeshhomard.CreateCase("MAILL", input_med, working_dir)
34 smeshhomard.SetConfType(0)
35 smeshhomard.SetKeepMedOUT(True)
36 smeshhomard.SetPublishMeshOUT(True)
37 smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_01")
38 smeshhomard.SetMeshFileOUT(output_med_1)
39 smeshhomard.SetKeepWorkingFiles(False)
40 smeshhomard.SetLogInFile(True)
41 smeshhomard.SetLogFile(log_file_1)
42 smeshhomard.SetRemoveLogOnSuccess(False)
43 smeshhomard.SetVerboseLevel(3)
44 smeshhomard.Compute()
45
46 if os.path.isfile(output_med_1):
47   os.remove(output_med_1)
48 else:
49   print("Test Uniform refinement Case 1: Error: no output med file")
50   assert(False)
51
52 if os.path.isfile(log_file_1):
53   os.remove(log_file_1)
54 else:
55   print("Test Uniform refinement Case 1: Error: no log file")
56   assert(False)
57
58 # Case 2: input: mesh, boundaries
59 #         output: published mesh
60 if os.path.isfile(output_med_2):
61   os.remove(output_med_2)
62 if os.path.isfile(log_file_2):
63   os.remove(log_file_2)
64
65 # prepare input mesh
66 ([MAILL], status) = smesh.CreateMeshesFromMED( input_med )
67
68 #smeshhomard = smesh.Adaptation("Uniform")
69 Boun_1 = smeshhomard.CreateBoundaryCylinder("Boun_1", 0.5, 0.5, 0.5, 0, 0, 1, 0.25)
70 smeshhomard.CreateCaseOnMesh("MAILL", MAILL.GetMesh(), working_dir)
71 smeshhomard.SetConfType(0)
72 smeshhomard.AddBoundaryGroup("Boun_1", "BORD_EXT")
73 smeshhomard.AddBoundaryGroup("Boun_1", "MOITIE1")
74 smeshhomard.SetKeepMedOUT(False)
75 smeshhomard.SetPublishMeshOUT(True)
76 smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_02")
77 smeshhomard.SetMeshFileOUT(output_med_2)
78 smeshhomard.SetKeepWorkingFiles(False)
79 smeshhomard.SetLogInFile(True)
80 smeshhomard.SetLogFile(log_file_2)
81 smeshhomard.SetRemoveLogOnSuccess(True)
82 smeshhomard.SetVerboseLevel(0)
83 smeshhomard.Compute()
84
85 if os.path.isfile(output_med_2):
86   print("Test Uniform refinement Case 2: Error: output med file has not been removed")
87   assert(False)
88
89 if os.path.isfile(log_file_2):
90   print("Test Uniform refinement Case 2: Error: log file has not been removed")
91   assert(False)
92
93 shutil.rmtree(working_dir)
94
95 if salome.sg.hasDesktop():
96   salome.sg.updateObjBrowser()