Salome HOME
version 5_1_4 HOMARD_SRC
[modules/homard.git] / tests / test_2.py
1 # -*- coding: iso-8859-1 -*-
2 """
3 Python script for HOMARD
4 Copyright EDF-R&D 2010
5 Test test_2
6 """
7 __revision__ = "V1.2"
8
9 ######################################################################################
10 Test_Name = "test_2"
11 n_iter_test_file = 3
12 ######################################################################################
13 import os
14 import sys
15 import tempfile
16 import HOMARD
17 import salome
18 #
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)
23
24 salome.salome_init()
25 import iparameters
26 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
27 ipar.append("AP_MODULES_LIST", "Homard")
28 ######################################################################################
29 ######################################################################################
30 def homard_exec(theStudy):
31   """
32 Python script for HOMARD
33 Copyright EDF-R&D 2010
34   """
35   homard.SetCurrentStudy(theStudy)
36 #
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')
43 #
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                                                                              ')
51
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                                                                             ')
56 #
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)
62   Case_1.SetConfType(1)
63   Case_1.AddBoundaryGroup( 'internal_boundary', ' ' )
64 #
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)
73
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)
80
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
88
89 ######################################################################################
90
91 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
92 #
93 # Exec of HOMARD-SALOME
94 #
95 try :
96   result=homard_exec(salome.myStudy)
97   if (result != True):
98       raise Exception('Pb in homard_exec')
99 except :
100   raise Exception('Pb in homard_exec')
101   sys.exit(1)
102 #
103 # Test of the result
104 #
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
108 #
109 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
110 try :
111   file = open (test_file, "r")
112   mess_ref = file.readlines()
113   file.close()
114 except :
115   raise Exception('Reference file does not exist.')
116   sys.exit(2)
117 #
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()
122    file.close()
123 else :
124   raise Exception('Result file does not exist.')
125   sys.exit(2)
126
127 nblign = len(mess_ref)
128 if ( len(mess) != nblign ):
129   raise Exception('The number of lines of the files are not the same.')
130   sys.exit(2)
131
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)
138        sys.exit(10)
139 #
140 if salome.sg.hasDesktop():
141   salome.sg.updateObjBrowser(1)
142   iparameters.getSession().restoreVisualState(1)
143