Salome HOME
bos #29171 Refactor testing procedure
[modules/smesh.git] / doc / examples / test_homard_adapt.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 = osp.join (data_dir, "test_homard_adapt.med")
19 output_med_1 = osp.join (working_dir, "test_1.00_Uniform_R_01.med")
20 output_med_2 = osp.join (working_dir, "test_1.00_Uniform_R_02.med")
21 log_file_1 = osp.join (working_dir, "test_1.00_Uniform_R_01.med.log")
22 log_file_2 = osp.join (working_dir, "test_1.00_Uniform_R_02.med.log")
23
24 # Case 1: input: med file
25 #         output: med file, log file, published mesh
26 if osp.isfile(output_med_1):
27   os.remove(output_med_1)
28 if osp.isfile(log_file_1):
29   os.remove(log_file_1)
30
31 smeshhomard = smesh.Adaptation("Uniform")
32 smeshhomard.CreateCase("MAILL", input_med, working_dir)
33 smeshhomard.SetConfType(0)
34 smeshhomard.SetKeepMedOUT(True)
35 smeshhomard.SetPublishMeshOUT(True)
36 smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_01")
37 smeshhomard.SetMeshFileOUT(output_med_1)
38 smeshhomard.SetKeepWorkingFiles(False)
39 smeshhomard.SetLogInFile(True)
40 smeshhomard.SetLogFile(log_file_1)
41 smeshhomard.SetRemoveLogOnSuccess(False)
42 smeshhomard.SetVerboseLevel(3)
43 smeshhomard.Compute()
44
45 if osp.isfile(output_med_1):
46   os.remove(output_med_1)
47 else:
48   print("Test Uniform refinement Case 1: Error: no output med file")
49   assert(False)
50
51 if osp.isfile(log_file_1):
52   os.remove(log_file_1)
53 else:
54   print("Test Uniform refinement Case 1: Error: no log file")
55   assert(False)
56
57 # Case 2: input: mesh, boundaries
58 #         output: published mesh
59 if osp.isfile(output_med_2):
60   os.remove(output_med_2)
61 if osp.isfile(log_file_2):
62   os.remove(log_file_2)
63
64 # prepare input mesh
65 ([MAILL], status) = smesh.CreateMeshesFromMED( input_med )
66
67 #smeshhomard = smesh.Adaptation("Uniform")
68 Boun_1 = smeshhomard.CreateBoundaryCylinder("Boun_1", 0.5, 0.5, 0.5, 0, 0, 1, 0.25)
69 smeshhomard.CreateCaseOnMesh("MAILL", MAILL.GetMesh(), working_dir)
70 smeshhomard.SetConfType(0)
71 smeshhomard.AddBoundaryGroup("Boun_1", "BORD_EXT")
72 smeshhomard.AddBoundaryGroup("Boun_1", "MOITIE1")
73 smeshhomard.SetKeepMedOUT(False)
74 smeshhomard.SetPublishMeshOUT(True)
75 smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_02")
76 smeshhomard.SetMeshFileOUT(output_med_2)
77 smeshhomard.SetKeepWorkingFiles(False)
78 smeshhomard.SetLogInFile(True)
79 smeshhomard.SetLogFile(log_file_2)
80 smeshhomard.SetRemoveLogOnSuccess(True)
81 smeshhomard.SetVerboseLevel(0)
82 smeshhomard.Compute()
83
84 if osp.isfile(output_med_2):
85   print("Test Uniform refinement Case 2: Error: output med file has not been removed")
86   assert(False)
87
88 if osp.isfile(log_file_2):
89   print("Test Uniform refinement Case 2: Error: log file has not been removed")
90   assert(False)
91
92 shutil.rmtree(working_dir)
93
94 if salome.sg.hasDesktop():
95   salome.sg.updateObjBrowser()