]> SALOME platform Git repositories - modules/homard.git/blob - src/tests/Test/test_2.py
Salome HOME
Mise à jour des cas-tests pour tenir compte des déplacements
[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__ = "V3.1"
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 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des scripts utilitaires
40 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
41 REP_PYTHON = os.path.normpath(REP_PYTHON)
42 sys.path.append(REP_PYTHON)
43 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des donnees du test
46 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
47 REP_DATA = os.path.normpath(REP_DATA)
48 # Repertoire des resultats
49 if DEBUG :
50   DIRCASE = os.path.join("/tmp", TEST_NAME)
51   if ( os.path.isdir(DIRCASE) ) :
52     remove_dir(DIRCASE)
53   os.mkdir(DIRCASE)
54 else :
55   DIRCASE = tempfile.mkdtemp()
56 # ==================================
57
58 salome.salome_init()
59 import iparameters
60 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
61 IPAR.append("AP_MODULES_LIST", "Homard")
62 #
63 #========================================================================
64 #========================================================================
65 def homard_exec(theStudy):
66   """
67 Python script for HOMARD
68   """
69   error = 0
70 #
71   while not error :
72   #
73     HOMARD.SetCurrentStudy(theStudy)
74   #
75   # Creation of the boundaries
76   # ==========================
77   # Creation of the discrete boundary boundary_1
78     boundary_1 = HOMARD.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
79   #
80   # Creation of the hypotheses
81   # ==========================
82   # Creation of the hypothesis 1
83     hyponame_1 = "hypo_" + TEST_NAME + "_1"
84     print "-------- Creation of the hypothesis", hyponame_1
85     hypo_test_2_1 = HOMARD.CreateHypothesis(hyponame_1)
86     hypo_test_2_1.SetUnifRefinUnRef(1)
87     hypo_test_2_1.AddGroup('EG')
88     hypo_test_2_1.AddGroup('BANDE')
89     print hyponame_1, " : zones utilisées :", hypo_test_2_1.GetZones()
90     print hyponame_1, " : champ utilisé :", hypo_test_2_1.GetFieldName()
91     print hyponame_1, " : composantes utilisées :", hypo_test_2_1.GetComps()
92     if ( len (hypo_test_2_1.GetFieldName()) > 0 ) :
93       print ".. caractéristiques de l'adaptation :", hypo_test_2_1.GetField()
94
95   # Creation of the hypothesis 2
96     hyponame_2 = "hypo_" + TEST_NAME + "_2"
97     print "-------- Creation of the hypothesis", hyponame_2
98     hypo_test_2_2 = HOMARD.CreateHypothesis(hyponame_2)
99     hypo_test_2_2.SetUnifRefinUnRef(1)
100     hypo_test_2_2.AddGroup('M_D')
101     print hyponame_2, " : zones utilisées :", hypo_test_2_2.GetZones()
102     print hyponame_2, " : champ utilisé :", hypo_test_2_2.GetFieldName()
103     print hyponame_2, " : composantes utilisées :", hypo_test_2_2.GetComps()
104     if ( len (hypo_test_2_2.GetFieldName()) > 0 ) :
105       print ".. caractéristiques de l'adaptation :", hypo_test_2_2.GetField()
106   #
107   # Creation of the cases
108   # =====================
109     # Creation of the case
110     casename = "case_" + TEST_NAME
111     mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
112     case_test_2 = HOMARD.CreateCase(casename, 'PLAQUE_0', mesh_file)
113     case_test_2.SetDirName(DIRCASE)
114     case_test_2.AddBoundaryGroup('internal_boundary', '')
115   #
116   # Creation of the iterations
117   # ==========================
118   # Creation of the iteration 1
119     iter_name = "I_" + TEST_NAME + "_1"
120     iter_test_2_1 = case_test_2.NextIteration(iter_name)
121     iter_test_2_1.SetMeshName('PLAQUE_1')
122     iter_test_2_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
123     iter_test_2_1.AssociateHypo(hyponame_1)
124     error = iter_test_2_1.Compute(1, 1)
125     if error :
126       error = 1
127       break
128
129   # Creation of the iteration 2
130     iter_name = "I_" + TEST_NAME + "_2"
131     iter_test_2_2 = iter_test_2_1.NextIteration(iter_name)
132     iter_test_2_2.SetMeshName('PLAQUE_2')
133     iter_test_2_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
134     iter_test_2_2.AssociateHypo(hyponame_1)
135     error = iter_test_2_2.Compute(1, 1)
136     if error :
137       error = 2
138       break
139
140   # Creation of the iteration 3
141     iter_name = "I_" + TEST_NAME + "_3"
142     iter_test_2_3 = iter_test_2_2.NextIteration(iter_name)
143     iter_test_2_3.SetMeshName('PLAQUE_3')
144     iter_test_2_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
145     iter_test_2_3.AssociateHypo(hyponame_2)
146     error = iter_test_2_3.Compute(1, 1)
147     if error :
148       error = 3
149       break
150   #
151   # Creation of the schema YACS
152   # ===========================
153     scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
154     scriptfile = os.path.normpath(scriptfile)
155     dirname = DIRCASE
156     yacs_test_2 = case_test_2.CreateYACSSchema("YACS_test_2", scriptfile, dirname, mesh_file)
157     yacs_test_2.SetMaxIter(4)
158     yacs_test_2.SetType(1)
159     filexml = os.path.join(DIRCASE, 'yacs_test_2.xml')
160     error = yacs_test_2.WriteOnFile(filexml)
161     if error :
162       error = 4
163       break
164   #
165     break
166   #
167   return error
168
169 #========================================================================
170
171 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
172 assert HOMARD is not None, "Impossible to load homard engine"
173 HOMARD.SetLanguageShort("fr")
174 #
175 # Exec of HOMARD-SALOME
176 #
177 try :
178   ERROR = homard_exec(salome.myStudy)
179   if ERROR :
180     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
181 except Exception, eee:
182   raise Exception('Pb in homard_exec: '+eee.message)
183 #
184 # Test of the results
185 #
186 N_REP_TEST_FILE = N_ITER_TEST_FILE
187 DESTROY_DIR = not DEBUG
188 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
189 #
190 if salome.sg.hasDesktop():
191   salome.sg.updateObjBrowser(1)
192   iparameters.getSession().restoreVisualState(1)
193