]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_1.py
Salome HOME
Passage de l'exécutable HOMARD à MED 3.1 : impact dans les tests
[modules/homard.git] / tests / 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 Copyright EDF-R&D 2010, 2015
23 Test test_1
24 """
25 __revision__ = "V2.5"
26
27 #========================================================================
28 Test_Name = "test_1"
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 test_results
44 # Repertoire des resultats
45 dircase = tempfile.mkdtemp()
46 # ==================================
47
48 salome.salome_init()
49 import iparameters
50 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
51 ipar.append("AP_MODULES_LIST", "Homard")
52 #
53 #========================================================================
54 #========================================================================
55 def homard_exec(theStudy):
56   """
57 Python script for HOMARD
58   """
59   error = 0
60 #
61   while not error :
62   #
63     homard.SetCurrentStudy(theStudy)
64   #
65   # Creation of the zones
66   # =====================
67   # Creation of the box Zone_1_1
68     Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
69
70   # Creation of the sphere Zone_1_2
71     Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
72   #
73   # Creation of the hypotheses
74   # ==========================
75     dico = {}
76     dico["1"] = "raffinement"
77     dico["-1"] = "deraffinement"
78   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
79     HypoName_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
80     print "-------- Creation of the hypothesis", HypoName_1
81     Hypo_1_1 = homard.CreateHypothesis(HypoName_1)
82     Hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
83     Hypo_1_1.SetUseComp(0)
84     Hypo_1_1.AddComp('ERREST')
85     Hypo_1_1.SetRefinThr(3, 10.1)
86     Hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
87     Hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
88     print HypoName_1, " : champ utilisé :", Hypo_1_1.GetFieldName()
89     print HypoName_1, " : composantes utilisées :", Hypo_1_1.GetComps()
90     if ( len (Hypo_1_1.GetFieldName()) > 0 ) :
91       print ".. caractéristiques de l'adaptation :", Hypo_1_1.GetField()
92     print HypoName_1, " : champs interpolés :", Hypo_1_1.GetFieldInterps()
93   # Creation of the hypothesis Zones_1_et_2
94     HypoName_2 = "Zones_1_et_2"
95     print "-------- Creation of the hypothesis", HypoName_2
96     Zones_1_et_2 = homard.CreateHypothesis(HypoName_2)
97     Zones_1_et_2.AddZone('Zone_1_1', 1)
98     Zones_1_et_2.AddZone('Zone_1_2', 1)
99     laux = Zones_1_et_2.GetZones()
100     nbzone = len(laux)/2
101     jaux = 0
102     for iaux in range(nbzone) :
103       print HypoName_2, " : ", dico[laux[jaux+1]], "sur la zone", laux[jaux]
104       jaux += 2
105     print HypoName_2, " : champ utilisé :", Zones_1_et_2.GetFieldName()
106     if ( len (Zones_1_et_2.GetFieldName()) > 0 ) :
107       print ".. caractéristiques de l'adaptation :", Zones_1_et_2.GetField()
108     print HypoName_2, " : champs interpolés :", Zones_1_et_2.GetFieldInterps()
109   #
110   # Creation of the cases
111   # =====================
112     # Creation of the case
113     CaseName = "Case_" + Test_Name
114     print "-------- Creation of the case", CaseName
115     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
116     Case_test_1 = homard.CreateCase(CaseName, 'MAILL', MeshFile)
117     Case_test_1.SetDirName(dircase)
118     Case_test_1.SetConfType(1)
119   #
120   # Creation of the iterations
121   # ==========================
122   # Creation of the iteration 1
123     IterName = "I_" + Test_Name + "_1"
124     print "-------- Creation of the iteration", IterName
125     Iter_test_1_1 = Case_test_1.NextIteration(IterName)
126     Iter_test_1_1.AssociateHypo(HypoName_1)
127     print ". Hypothese :", HypoName_1
128     Iter_test_1_1.SetMeshName('M1')
129     Iter_test_1_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
130     Iter_test_1_1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
131     Iter_test_1_1.SetTimeStepRank(1, 1)
132     Iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
133     Iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
134     print ". Instants d'interpolation :", Iter_test_1_1.GetFieldInterpsTimeStepRank()
135     error = Iter_test_1_1.Compute(1, 1)
136     if error :
137       error = 1
138       break
139
140   # Creation of the iteration 2
141     IterName = "I_" + Test_Name + "_2"
142     print "-------- Creation of the iteration", IterName
143     Iter_test_1_2 = Iter_test_1_1.NextIteration(IterName)
144     Iter_test_1_2.AssociateHypo(HypoName_1)
145     print ". Hypothese :", HypoName_1
146     Iter_test_1_2.SetMeshName('M2')
147     Iter_test_1_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
148     Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
149     Iter_test_1_2.SetTimeStepRank(1, 1)
150     Iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
151     Iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
152     print ". Instants d'interpolation :", Iter_test_1_2.GetFieldInterpsTimeStepRank()
153     error = Iter_test_1_2.Compute(1, 1)
154     if error :
155       error = 2
156       break
157
158   # Creation of the iteration 3
159     IterName = "I_" + Test_Name + "_3"
160     print "-------- Creation of the iteration", IterName
161     Iter_test_1_3 = Iter_test_1_2.NextIteration(IterName)
162     Iter_test_1_3.AssociateHypo(HypoName_2)
163     print ". Hypothese :", HypoName_2
164     Iter_test_1_3.SetMeshName('M3')
165     Iter_test_1_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
166     Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.02.med'))
167     print ". Instants d'interpolation :", Iter_test_1_3.GetFieldInterpsTimeStepRank()
168     error = Iter_test_1_3.Compute(1, 1)
169     if error :
170       error = 3
171       break
172   #
173   # Creation of the schema YACS
174   # ===========================
175     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
176     ScriptFile = os.path.normpath(ScriptFile)
177     DirName = dircase
178     YACS_test_1 = Case_test_1.CreateYACSSchema("YACS_test_1", ScriptFile, DirName, MeshFile)
179     error = YACS_test_1.Write()
180     if error :
181       error = 4
182       break
183   #
184     break
185   #
186   return error
187
188 #========================================================================
189
190 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
191 assert homard is not None, "Impossible to load homard engine"
192 homard.SetLanguageShort("fr")
193 #
194 # Exec of HOMARD-SALOME
195 #
196 try :
197   error_main = homard_exec(salome.myStudy)
198   if error_main :
199     raise Exception('Pb in homard_exec at iteration %d' %error_main )
200 except Exception, e:
201   raise Exception('Pb in homard_exec: '+e.message)
202 #
203 # Test of the results
204 #
205 n_rep_test_file = n_iter_test_file
206 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file)
207 #
208 if salome.sg.hasDesktop():
209   salome.sg.updateObjBrowser(1)
210   iparameters.getSession().restoreVisualState(1)
211