Salome HOME
Update of CheckDone
[modules/smesh.git] / doc / examples / test_uniform_refinement.py
1 import inspect
2 import os
3 import os.path as osp
4 import shutil
5 import tempfile
6
7 import salome
8 salome.salome_init_without_session()
9
10 from salome.smesh import smeshBuilder
11 import SMESHHOMARD
12
13 smesh = smeshBuilder.New()
14
15 data_dir = osp.abspath(osp.join(osp.dirname(inspect.getfile(lambda: None)), 'data'))
16 working_dir = tempfile.mkdtemp()
17
18 input_med_1 = osp.join(data_dir, "tutorial_4.00.med")
19 input_xao_1 = osp.join(data_dir, "tutorial_4.xao")
20 output_med_1 = osp.join(working_dir, "tutorial_4.00_Uniform_R.med")
21 log_file_1 = osp.join(working_dir, "tutorial_4.00_Uniform_R.log")
22
23 # Case 1: input: med file
24 #         output: med file, log file, published mesh
25 if osp.isfile(output_med_1):
26   os.remove(output_med_1)
27 if osp.isfile(log_file_1):
28   os.remove(log_file_1)
29
30 cao_name = "CAO_PIQUAGE"
31 smeshhomard = smesh.Adaptation("Uniform")
32 smeshhomard.CreateBoundaryCAO(cao_name, input_xao_1)
33 smeshhomard.CreateCase("PIQUAGE", input_med_1, working_dir)
34 smeshhomard.AddBoundary(cao_name)
35 smeshhomard.SetConfType(0)
36 smeshhomard.SetKeepMedOUT(True)
37 smeshhomard.SetPublishMeshOUT(True)
38 smeshhomard.SetMeshNameOUT("PIQUAGE_Uniform_R_01")
39 smeshhomard.SetMeshFileOUT(output_med_1)
40 smeshhomard.SetKeepWorkingFiles(False)
41 smeshhomard.SetLogInFile(True)
42 smeshhomard.SetLogFile(log_file_1)
43 smeshhomard.SetRemoveLogOnSuccess(False)
44 smeshhomard.SetVerboseLevel(3)
45 if smeshhomard.Compute() != 0: raise Exception("Error when computing Mesh")
46
47 if osp.isfile(output_med_1):
48   os.remove(output_med_1)
49 else:
50   print("Test Uniform refinement Case 1: Error: no output med file")
51   assert(False)
52
53 if osp.isfile(log_file_1):
54   os.remove(log_file_1)
55 else:
56   print("Test Uniform refinement Case 1: Error: no log file")
57   assert(False)
58
59 # Case 2: input: mesh, boundaries
60 #         output: published mesh
61 input_med_2 = osp.join(data_dir, "tutorial_5.00.med")
62 input_fr    = osp.join(data_dir, "tutorial_5.fr.med")
63 output_med_2 = osp.join(working_dir, "tutorial_5.00_Uniform_R.med")
64 log_file_2 = osp.join(working_dir, "tutorial_5.00_Uniform_R.log")
65
66 if osp.isfile(output_med_2):
67   os.remove(output_med_2)
68 if osp.isfile(log_file_2):
69   os.remove(log_file_2)
70
71 # prepare input mesh
72 ([MAILL], status) = smesh.CreateMeshesFromMED( input_med_2 )
73
74 smeshhomard = smesh.Adaptation("Uniform")
75 smeshhomard.CreateBoundaryDi("Boun_5_1", "MAIL_EXT", input_fr)
76 smeshhomard.CreateCaseOnMesh("COEUR_2D", MAILL.GetMesh(), working_dir)
77 smeshhomard.AddBoundary("Boun_5_1")
78 smeshhomard.SetConfType(1)
79 smeshhomard.SetKeepMedOUT(False)
80 smeshhomard.SetPublishMeshOUT(True)
81 smeshhomard.SetMeshNameOUT("COEUR_2D_Uniform_R")
82 smeshhomard.SetMeshFileOUT(output_med_2)
83 smeshhomard.SetKeepWorkingFiles(False)
84 smeshhomard.SetLogInFile(True)
85 smeshhomard.SetLogFile(log_file_2)
86 smeshhomard.SetRemoveLogOnSuccess(True)
87 smeshhomard.SetVerboseLevel(0)
88 if smeshhomard.Compute() != 0: raise Exception("Error when computing Mesh")
89
90 if osp.isfile(output_med_2):
91   print("Test Uniform refinement Case 2: Error: output med file has not been removed")
92   assert(False)
93
94 if osp.isfile(log_file_2):
95   print("Test Uniform refinement Case 2: Error: log file has not been removed")
96   assert(False)
97
98 shutil.rmtree(working_dir)
99
100 if salome.sg.hasDesktop():
101   salome.sg.updateObjBrowser()