]> SALOME platform Git repositories - modules/homard.git/blob - src/tests/Test/test_2.py
Salome HOME
Séparation entre les pythons et les données des tests
[modules/homard.git] / src / tests / Test / test_2.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21 Python script for HOMARD
22 Test test_2
23 """
24 __revision__ = "V2.5"
25
26 #========================================================================
27 Test_Name = "test_2"
28 debug=False
29 n_iter_test_file = 3
30 #========================================================================
31 import os
32 import tempfile
33 import sys
34 import HOMARD
35 import salome
36 #
37 # ==================================
38 pathHomard = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des donnees du test
40 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
41 Rep_Test = os.path.normpath(Rep_Test)
42 sys.path.append(Rep_Test)
43 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des resultats
46 if debug :
47   dircase = os.path.join("/tmp", Test_Name)
48   if ( os.path.isdir(dircase) ) :
49     remove_dir(dircase)
50   os.mkdir(dircase)
51 else :
52   dircase = tempfile.mkdtemp()
53 # ==================================
54
55 salome.salome_init()
56 import iparameters
57 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
58 ipar.append("AP_MODULES_LIST", "Homard")
59 #
60 #========================================================================
61 #========================================================================
62 def homard_exec(theStudy):
63   """
64 Python script for HOMARD
65   """
66   error = 0
67 #
68   while not error :
69   #
70     homard.SetCurrentStudy(theStudy)
71   #
72   # Creation of the boundaries
73   # ==========================
74   # Creation of the discrete boundary Boundary_1
75     Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
76   #
77   # Creation of the hypotheses
78   # ==========================
79   # Creation of the hypothesis 1
80     HypoName_1 = "Hypo_" + Test_Name + "_1"
81     print "-------- Creation of the hypothesis", HypoName_1
82     Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
83     Hypo_test_2_1.SetUnifRefinUnRef(1)
84     Hypo_test_2_1.AddGroup('EG')
85     Hypo_test_2_1.AddGroup('BANDE')
86     print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
87     print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
88     print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
89     if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
90       print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
91
92   # Creation of the hypothesis 2
93     HypoName_2 = "Hypo_" + Test_Name + "_2"
94     print "-------- Creation of the hypothesis", HypoName_2
95     Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
96     Hypo_test_2_2.SetUnifRefinUnRef(1)
97     Hypo_test_2_2.AddGroup('M_D')
98     print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
99     print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
100     print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
101     if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
102       print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
103   #
104   # Creation of the cases
105   # =====================
106     # Creation of the case
107     CaseName = "Case_" + Test_Name
108     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
109     Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
110     Case_test_2.SetDirName(dircase)
111     Case_test_2.AddBoundaryGroup('internal_boundary', '')
112   #
113   # Creation of the iterations
114   # ==========================
115   # Creation of the iteration 1
116     IterName = "I_" + Test_Name + "_1"
117     Iter_test_2_1 = Case_test_2.NextIteration(IterName)
118     Iter_test_2_1.SetMeshName('PLAQUE_1')
119     Iter_test_2_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
120     Iter_test_2_1.AssociateHypo(HypoName_1)
121     error = Iter_test_2_1.Compute(1, 1)
122     if error :
123       error = 1
124       break
125
126   # Creation of the iteration 2
127     IterName = "I_" + Test_Name + "_2"
128     Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
129     Iter_test_2_2.SetMeshName('PLAQUE_2')
130     Iter_test_2_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
131     Iter_test_2_2.AssociateHypo(HypoName_1)
132     error = Iter_test_2_2.Compute(1, 1)
133     if error :
134       error = 2
135       break
136
137   # Creation of the iteration 3
138     IterName = "I_" + Test_Name + "_3"
139     Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
140     Iter_test_2_3.SetMeshName('PLAQUE_3')
141     Iter_test_2_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
142     Iter_test_2_3.AssociateHypo(HypoName_2)
143     error = Iter_test_2_3.Compute(1, 1)
144     if error :
145       error = 3
146       break
147   #
148   # Creation of the schema YACS
149   # ===========================
150     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
151     ScriptFile = os.path.normpath(ScriptFile)
152     DirName = dircase
153     YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
154     YACS_test_2.SetMaxIter(4)
155     YACS_test_2.SetType(1)
156     filexml = os.path.join(dircase, 'YACS_test_2.xml')
157     error = YACS_test_2.WriteOnFile(filexml)
158     if error :
159       error = 4
160       break
161   #
162     break
163   #
164   return error
165
166 #========================================================================
167
168 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
169 assert homard is not None, "Impossible to load homard engine"
170 homard.SetLanguageShort("fr")
171 #
172 # Exec of HOMARD-SALOME
173 #
174 try :
175   error_main = homard_exec(salome.myStudy)
176   if error_main :
177     raise Exception('Pb in homard_exec at iteration %d' %error_main )
178 except Exception, e:
179   raise Exception('Pb in homard_exec: '+e.message)
180 #
181 # Test of the results
182 #
183 n_rep_test_file = n_iter_test_file
184 destroy_dir = not debug
185 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
186 #
187 if salome.sg.hasDesktop():
188   salome.sg.updateObjBrowser(1)
189   iparameters.getSession().restoreVisualState(1)
190