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 zones
38 # =====================
39 # Creation of the box Zone_1
40 Zone_1 = homard.CreateZone('Zone_1', 2)
41 Zone_1.SetBox(-0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
43 # Creation of the sphere Zone_2
44 Zone_2 = homard.CreateZone('Zone_2', 4)
45 Zone_2.SetSphere(0.5, 0.6, 0.7, 0.75)
47 # Creation of the hypotheses
48 # ==========================
49 # Creation of the hypothesis Zones_1_et_2
50 Zones_1_et_2 = homard.CreateHypothesis('Zones_1_et_2')
51 Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
52 homard.AssociateHypoZone('Zone_1', 'Zones_1_et_2')
53 homard.AssociateHypoZone('Zone_2', 'Zones_1_et_2')
55 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
56 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM = homard.CreateHypothesis('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
57 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetAdapRefinUnRef(1, 1, 0)
58 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetField('RESU____ERRE_ELEM_SIGM__________')
59 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetUseComp(0)
60 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddComp('ERREST')
61 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetRefinThr(3, 10.1)
63 # Creation of the cases
64 # =====================
65 # Creation of the case zzzz121b
66 Case_1 = homard.CreateCase('zzzz121b', 'MAILL', os.path.join(Rep_Test, Test_Name + '.00.med'))
67 Case_1.SetDirName(Rep_Test_Resu)
70 # Creation of the iterations
71 # ==========================
72 # Creation of the iteration I1
73 I1 = homard.CreateIteration('I1', Case_1.GetIter0Name() )
75 I1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
76 I1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
77 I1.SetTimeStepRank( 1, 1)
78 homard.AssociateIterHypo('I1', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
79 result1 = homard.Compute('I1', 1)
81 # Creation of the iteration I2
82 I2 = homard.CreateIteration('I2', 'I1')
84 I2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
85 I2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
86 I2.SetTimeStepRank( 1, 1)
87 homard.AssociateIterHypo('I2', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
88 result2 = homard.Compute('I2', 1)
90 # Creation of the iteration I3
91 I3 = homard.CreateIteration('I3', 'I2')
93 I3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
94 homard.AssociateIterHypo('I3', 'Zones_1_et_2')
95 result3 = homard.Compute('I3', 1)
96 return result1*result2*result3
98 ######################################################################################
100 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
102 # Exec of HOMARD-SALOME
105 result=homard_exec(salome.myStudy)
107 raise Exception('Pb in homard_exec')
109 raise Exception('Pb in homard_exec')
114 s_iter_test_file = str(n_iter_test_file)
115 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
116 rep_test_file = "I0" + s_iter_test_file
118 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
120 file = open (test_file, "r")
121 mess_ref = file.readlines()
124 raise Exception('Reference file does not exist.')
127 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
128 if os.path.isfile (test_file) :
129 file = open (test_file, "r")
130 mess = file.readlines()
133 raise Exception('Result file does not exist.')
136 nblign = len(mess_ref)
137 if ( len(mess) != nblign ):
138 raise Exception('The number of lines of the files are not the same.')
141 for num in range(nblign) :
142 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
143 message_erreur = "\nRefe : " + mess_ref[num]
144 message_erreur += "Test : " + mess[num][:-1]
145 message_erreur += "\nThe test is different from the reference."
146 raise Exception(message_erreur)
149 if salome.sg.hasDesktop():
150 salome.sg.updateObjBrowser(1)
151 iparameters.getSession().restoreVisualState(1)