Salome HOME
Mise à jour des cas-tests pour tenir compte des déplacements
[modules/homard.git] / src / tests / Test / test_1.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_1
23 """
24 __revision__ = "V3.1"
25
26 #========================================================================
27 TEST_NAME = "test_1"
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 zones
76   # =====================
77   # Creation of the box zone_1_1
78     zone_1_1 = HOMARD.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
79
80   # Creation of the sphere zone_1_2
81     zone_1_2 = HOMARD.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
82   #
83   # Creation of the hypotheses
84   # ==========================
85     dico = {}
86     dico["1"] = "raffinement"
87     dico["-1"] = "deraffinement"
88   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
89     hyponame_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
90     print "-------- Creation of the hypothesis", hyponame_1
91     hypo_1_1 = HOMARD.CreateHypothesis(hyponame_1)
92     hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
93     hypo_1_1.SetUseComp(0)
94     hypo_1_1.AddComp('ERREST')
95     hypo_1_1.SetRefinThr(3, 10.1)
96     hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
97     hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
98     print hyponame_1, " : champ utilisé :", hypo_1_1.GetFieldName()
99     print hyponame_1, " : composantes utilisées :", hypo_1_1.GetComps()
100     if ( len (hypo_1_1.GetFieldName()) > 0 ) :
101       print ".. caractéristiques de l'adaptation :", hypo_1_1.GetField()
102     print hyponame_1, " : champs interpolés :", hypo_1_1.GetFieldInterps()
103   # Creation of the hypothesis Zones_1_et_2
104     hyponame_2 = "Zones_1_et_2"
105     print "-------- Creation of the hypothesis", hyponame_2
106     zones_1_et_2 = HOMARD.CreateHypothesis(hyponame_2)
107     zones_1_et_2.AddZone('Zone_1_1', 1)
108     zones_1_et_2.AddZone('Zone_1_2', 1)
109     laux = zones_1_et_2.GetZones()
110     nbzone = len(laux)/2
111     jaux = 0
112     for iaux in range(nbzone) :
113       print hyponame_2, " : ", dico[laux[jaux+1]], "sur la zone", laux[jaux]
114       jaux += 2
115     print hyponame_2, " : champ utilisé :", zones_1_et_2.GetFieldName()
116     if ( len (zones_1_et_2.GetFieldName()) > 0 ) :
117       print ".. caractéristiques de l'adaptation :", zones_1_et_2.GetField()
118     print hyponame_2, " : champs interpolés :", zones_1_et_2.GetFieldInterps()
119   #
120   # Creation of the cases
121   # =====================
122     # Creation of the case
123     casename = "Case_" + TEST_NAME
124     print "-------- Creation of the case", casename
125     mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
126     case_test_1 = HOMARD.CreateCase(casename, 'MAILL', mesh_file)
127     case_test_1.SetDirName(DIRCASE)
128   #
129   # Creation of the iterations
130   # ==========================
131   # Creation of the iteration 1
132     iter_name = "I_" + TEST_NAME + "_1"
133     print "-------- Creation of the iteration", iter_name
134     iter_test_1_1 = case_test_1.NextIteration(iter_name)
135     iter_test_1_1.AssociateHypo(hyponame_1)
136     print ". Hypothese :", hyponame_1
137     iter_test_1_1.SetMeshName('M1')
138     iter_test_1_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
139     iter_test_1_1.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.00.med'))
140     iter_test_1_1.SetTimeStepRank(1, 1)
141     iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
142     iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
143     print ". Instants d'interpolation :", iter_test_1_1.GetFieldInterpsTimeStepRank()
144     error = iter_test_1_1.Compute(1, 1)
145     if error :
146       error = 1
147       break
148
149   # Creation of the iteration 2
150     iter_name = "I_" + TEST_NAME + "_2"
151     print "-------- Creation of the iteration", iter_name
152     iter_test_1_2 = iter_test_1_1.NextIteration(iter_name)
153     iter_test_1_2.AssociateHypo(hyponame_1)
154     print ". Hypothese :", hyponame_1
155     iter_test_1_2.SetMeshName('M2')
156     iter_test_1_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
157     iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.01.med'))
158     iter_test_1_2.SetTimeStepRank(1, 1)
159     iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
160     iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
161     print ". Instants d'interpolation :", iter_test_1_2.GetFieldInterpsTimeStepRank()
162     error = iter_test_1_2.Compute(1, 1)
163     if error :
164       error = 2
165       break
166
167   # Creation of the iteration 3
168     iter_name = "I_" + TEST_NAME + "_3"
169     print "-------- Creation of the iteration", iter_name
170     iter_test_1_3 = iter_test_1_2.NextIteration(iter_name)
171     iter_test_1_3.AssociateHypo(hyponame_2)
172     print ". Hypothese :", hyponame_2
173     iter_test_1_3.SetMeshName('M3')
174     iter_test_1_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
175     iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.02.med'))
176     print ". Instants d'interpolation :", iter_test_1_3.GetFieldInterpsTimeStepRank()
177     error = iter_test_1_3.Compute(1, 1)
178     if error :
179       error = 3
180       break
181   #
182   # Creation of the schema YACS
183   # ===========================
184     scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
185     scriptfile = os.path.normpath(scriptfile)
186     dirname = DIRCASE
187     yacs_test_1 = case_test_1.CreateYACSSchema("YACS_test_1", scriptfile, dirname, mesh_file)
188     error = yacs_test_1.Write()
189     if error :
190       error = 4
191       break
192   #
193     break
194   #
195   return error
196
197 #========================================================================
198
199 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
200 assert HOMARD is not None, "Impossible to load homard engine"
201 HOMARD.SetLanguageShort("fr")
202 #
203 # Exec of HOMARD-SALOME
204 #
205 try :
206   ERROR = homard_exec(salome.myStudy)
207   if ERROR :
208     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
209 except Exception, eee:
210   raise Exception('Pb in homard_exec: '+eee.message)
211 #
212 # Test of the results
213 #
214 N_REP_TEST_FILE = N_ITER_TEST_FILE
215 DESTROY_DIR = not DEBUG
216 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
217 #
218 if salome.sg.hasDesktop():
219   salome.sg.updateObjBrowser(1)
220   iparameters.getSession().restoreVisualState(1)
221