Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / doc / salome / examples / test_uniform_refinement.py
1 #!/usr/bin/env python3
2
3 import salome
4 salome.salome_init_without_session()
5
6 import SMESH, SALOMEDS
7 from salome.smesh import smeshBuilder
8 import SMESHHOMARD
9
10 smesh = smeshBuilder.New()
11
12 import os, inspect, tempfile, shutil
13
14 data_dir = os.path.abspath(os.path.dirname(inspect.getfile(lambda: None)))
15 working_dir = tempfile.mkdtemp()
16
17 input_med_1 = os.path.join (data_dir, "tutorial_4.00.med")
18 input_xao_1 = os.path.join (data_dir, "tutorial_4.xao")
19 output_med_1 = os.path.join (working_dir, "tutorial_4.00_Uniform_R.med")
20 log_file_1 = os.path.join (working_dir, "tutorial_4.00_Uniform_R.log")
21
22 # Case 1: input: med file
23 #         output: med file, log file, published mesh
24 if os.path.isfile(output_med_1):
25   os.remove(output_med_1)
26 if os.path.isfile(log_file_1):
27   os.remove(log_file_1)
28
29 cao_name = "CAO_PIQUAGE"
30 smeshhomard = smesh.Adaptation("Uniform")
31 smeshhomard.CreateBoundaryCAO(cao_name, input_xao_1)
32 smeshhomard.CreateCase("PIQUAGE", input_med_1, working_dir)
33 smeshhomard.AddBoundary(cao_name)
34 smeshhomard.SetConfType(0)
35 smeshhomard.SetKeepMedOUT(True)
36 smeshhomard.SetPublishMeshOUT(True)
37 smeshhomard.SetMeshNameOUT("PIQUAGE_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 input_med_2 = os.path.join (data_dir, "tutorial_5.00.med")
61 input_fr    = os.path.join (data_dir, "tutorial_5.fr.med")
62 output_med_2 = os.path.join (working_dir, "tutorial_5.00_Uniform_R.med")
63 log_file_2 = os.path.join (working_dir, "tutorial_5.00_Uniform_R.log")
64
65 if os.path.isfile(output_med_2):
66   os.remove(output_med_2)
67 if os.path.isfile(log_file_2):
68   os.remove(log_file_2)
69
70 # prepare input mesh
71 ([MAILL], status) = smesh.CreateMeshesFromMED( input_med_2 )
72
73 smeshhomard = smesh.Adaptation("Uniform")
74 smeshhomard.CreateBoundaryDi("Boun_5_1", "MAIL_EXT", input_fr)
75 smeshhomard.CreateCaseOnMesh("COEUR_2D", MAILL.GetMesh(), working_dir)
76 smeshhomard.AddBoundary("Boun_5_1")
77 smeshhomard.SetConfType(1)
78 smeshhomard.SetKeepMedOUT(False)
79 smeshhomard.SetPublishMeshOUT(True)
80 smeshhomard.SetMeshNameOUT("COEUR_2D_Uniform_R")
81 smeshhomard.SetMeshFileOUT(output_med_2)
82 smeshhomard.SetKeepWorkingFiles(False)
83 smeshhomard.SetLogInFile(True)
84 smeshhomard.SetLogFile(log_file_2)
85 smeshhomard.SetRemoveLogOnSuccess(True)
86 smeshhomard.SetVerboseLevel(0)
87 smeshhomard.Compute()
88
89 if os.path.isfile(output_med_2):
90   print("Test Uniform refinement Case 2: Error: output med file has not been removed")
91   assert(False)
92
93 if os.path.isfile(log_file_2):
94   print("Test Uniform refinement Case 2: Error: log file has not been removed")
95   assert(False)
96
97 shutil.rmtree(working_dir)
98
99 if salome.sg.hasDesktop():
100   salome.sg.updateObjBrowser()