1 # -*- coding: iso-8859-1 -*-
3 Python script for HOMARD
9 ######################################################################################
12 ######################################################################################
19 pathHomard=os.getenv('HOMARD_ROOT_DIR')
20 Rep_Test = os.path.join(pathHomard,"share/salome/resources/homard")
21 Rep_Test_Resu = tempfile.mktemp()
22 os.mkdir(Rep_Test_Resu)
26 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
27 ipar.append("AP_MODULES_LIST", "Homard")
28 ######################################################################################
29 ######################################################################################
30 def homard_exec(theStudy):
32 Python script for HOMARD
33 Copyright EDF-R&D 2010
35 homard.SetCurrentStudy(theStudy)
37 # Creation of the boundaries
38 # ==========================
39 # Creation of the boundaries Boundary_1
40 Boundary_1 = homard.CreateBoundary('internal_boundary', 0)
41 Boundary_1.SetMeshFile(os.path.join(Rep_Test, Test_Name + '.fr.med'))
42 Boundary_1.SetMeshName('plaque')
44 # Creation of the hypotheses
45 # ==========================
46 # Creation of the hypothesis Hypo_1
47 Hypo_1 = homard.CreateHypothesis('Hypo_1')
48 Hypo_1.SetAdapRefinUnRef(-1, 1, 0)
49 Hypo_1.AddGroup('BANDE ')
50 Hypo_1.AddGroup('EG ')
52 # Creation of the hypothesis Hypo_2
53 Hypo_2 = homard.CreateHypothesis('Hypo_2')
54 Hypo_2.SetAdapRefinUnRef(-1, 1, 0)
55 Hypo_2.AddGroup('M_D ')
57 # Creation of the cases
58 # =====================
59 # Creation of the case Case_1
60 Case_1 = homard.CreateCase('Case_1', 'PLAQUE_0', os.path.join(Rep_Test, Test_Name + '.00.med'))
61 Case_1.SetDirName(Rep_Test_Resu)
63 Case_1.AddBoundaryGroup( 'internal_boundary', ' ' )
65 # Creation of the iterations
66 # ==========================
67 # Creation of the iteration Iter_1
68 Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
69 Iter_1.SetMeshName('PLAQUE_1')
70 Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
71 homard.AssociateIterHypo('Iter_1', 'Hypo_1')
72 result1 = homard.Compute('Iter_1', 1)
74 # Creation of the iteration Iter_2
75 Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
76 Iter_2.SetMeshName('PLAQUE_2')
77 Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
78 homard.AssociateIterHypo('Iter_2', 'Hypo_1')
79 result2 = homard.Compute('Iter_2', 1)
81 # Creation of the iteration Iter_3
82 Iter_3 = homard.CreateIteration('Iter_3', 'Iter_2')
83 Iter_3.SetMeshName('PLAQUE_3')
84 Iter_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
85 homard.AssociateIterHypo('Iter_3', 'Hypo_2')
86 result3 = homard.Compute('Iter_3', 1)
87 return result1*result2*result3
89 ######################################################################################
91 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
93 # Exec of HOMARD-SALOME
96 result=homard_exec(salome.myStudy)
98 raise Exception('Pb in homard_exec')
100 raise Exception('Pb in homard_exec')
105 s_iter_test_file = str(n_iter_test_file)
106 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
107 rep_test_file = "I0" + s_iter_test_file
109 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
111 file = open (test_file, "r")
112 mess_ref = file.readlines()
115 raise Exception('Reference file does not exist.')
118 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
119 if os.path.isfile (test_file) :
120 file = open (test_file, "r")
121 mess = file.readlines()
124 raise Exception('Result file does not exist.')
127 nblign = len(mess_ref)
128 if ( len(mess) != nblign ):
129 raise Exception('The number of lines of the files are not the same.')
132 for num in range(nblign) :
133 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
134 message_erreur = "\nRefe : " + mess_ref[num]
135 message_erreur += "Test : " + mess[num][:-1]
136 message_erreur += "\nThe test is different from the reference."
137 raise Exception(message_erreur)
140 if salome.sg.hasDesktop():
141 salome.sg.updateObjBrowser(1)
142 iparameters.getSession().restoreVisualState(1)