]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_2.py
Salome HOME
4d9dd18da87eea061a93788c74779eb159583d59
[modules/homard.git] / tests / test_2.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014  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, 2014
23 Test test_2
24 """
25 __revision__ = "V2.3"
26
27 #========================================================================
28 Test_Name = "test_2"
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.mktemp()
46 os.mkdir(dircase)
47 # ==================================
48
49
50 salome.salome_init()
51 import iparameters
52 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
53 ipar.append("AP_MODULES_LIST", "Homard")
54 #
55 #========================================================================
56 #========================================================================
57 def homard_exec(theStudy):
58   """
59 Python script for HOMARD
60   """
61   error = 0
62 #
63   while not error :
64   #
65     homard.SetCurrentStudy(theStudy)
66   #
67   # Creation of the boundaries
68   # ==========================
69   # Creation of the discrete boundary Boundary_1
70     Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
71   #
72   # Creation of the hypotheses
73   # ==========================
74   # Creation of the hypothesis 1
75     HypoName_1 = "Hypo_" + Test_Name + "_1"
76     print "-------- Creation of the hypothesis", HypoName_1
77     Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
78     Hypo_test_2_1.SetUnifRefinUnRef(1)
79     Hypo_test_2_1.AddGroup('EG')
80     Hypo_test_2_1.AddGroup('BANDE')
81     print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
82     print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
83     print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
84     if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
85       print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
86
87   # Creation of the hypothesis 2
88     HypoName_2 = "Hypo_" + Test_Name + "_2"
89     print "-------- Creation of the hypothesis", HypoName_2
90     Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
91     Hypo_test_2_2.SetUnifRefinUnRef(1)
92     Hypo_test_2_2.AddGroup('M_D')
93     print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
94     print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
95     print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
96     if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
97       print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
98   #
99   # Creation of the cases
100   # =====================
101     # Creation of the case
102     CaseName = "Case_" + Test_Name
103     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
104     Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
105     Case_test_2.SetDirName(dircase)
106     Case_test_2.SetConfType(1)
107     Case_test_2.AddBoundaryGroup('internal_boundary', '')
108   #
109   # Creation of the iterations
110   # ==========================
111   # Creation of the iteration 1
112     IterName = "I_" + Test_Name + "_1"
113     Iter_test_2_1 = Case_test_2.NextIteration(IterName)
114     Iter_test_2_1.SetMeshName('PLAQUE_1')
115     Iter_test_2_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
116     Iter_test_2_1.AssociateHypo(HypoName_1)
117     error = Iter_test_2_1.Compute(1, 1)
118     if error :
119       error = 1
120       break
121
122   # Creation of the iteration 2
123     IterName = "I_" + Test_Name + "_2"
124     Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
125     Iter_test_2_2.SetMeshName('PLAQUE_2')
126     Iter_test_2_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
127     Iter_test_2_2.AssociateHypo(HypoName_1)
128     error = Iter_test_2_2.Compute(1, 1)
129     if error :
130       error = 2
131       break
132
133   # Creation of the iteration 3
134     IterName = "I_" + Test_Name + "_3"
135     Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
136     Iter_test_2_3.SetMeshName('PLAQUE_3')
137     Iter_test_2_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
138     Iter_test_2_3.AssociateHypo(HypoName_2)
139     error = Iter_test_2_3.Compute(1, 1)
140     if error :
141       error = 3
142       break
143   #
144   # Creation of the schema YACS
145   # ===========================
146     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
147     ScriptFile = os.path.normpath(ScriptFile)
148     DirName = dircase
149     YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
150     YACS_test_2.SetType(1)
151     filexml = os.path.join(dircase, 'YACS_test_2.xml')
152     error = YACS_test_2.WriteOnFile(filexml)
153     if error :
154       error = 4
155       break
156   #
157     break
158   #
159   return error
160
161 #========================================================================
162
163 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
164 assert homard is not None, "Impossible to load homard engine"
165 homard.SetLanguageShort("fr")
166 #
167 # Exec of HOMARD-SALOME
168 #
169 try :
170   error_main = homard_exec(salome.myStudy)
171   if error_main :
172     raise Exception('Pb in homard_exec at iteration %d' %error_main )
173 except Exception, e:
174   raise Exception('Pb in homard_exec: '+e.message)
175 #
176 # Test of the results
177 #
178 n_rep_test_file = n_iter_test_file
179 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, True)
180 #
181 if salome.sg.hasDesktop():
182   salome.sg.updateObjBrowser(1)
183   iparameters.getSession().restoreVisualState(1)
184