Salome HOME
358a17fd20a3b9636f9057daa7b69b9785b90090
[modules/homard.git] / src / tests / test_3.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_3
23 """
24 __revision__ = "V2.4"
25
26 #========================================================================
27 Test_Name = "test_3"
28 debug=False
29 n_boucle = 2
30 n_iter_test_file = 2
31 #========================================================================
32 import os
33 import tempfile
34 import sys
35 import HOMARD
36 import salome
37 #
38 # ==================================
39 pathHomard = os.getenv('HOMARD_ROOT_DIR')
40 # Repertoire des donnees du test
41 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
42 Rep_Test = os.path.normpath(Rep_Test)
43 sys.path.append(Rep_Test)
44 from test_util import remove_dir
45 from test_util import test_results
46 # Repertoire des resultats
47 if debug :
48   dircase = os.path.join("/tmp", Test_Name)
49   if ( os.path.isdir(dircase) ) :
50     remove_dir(dircase)
51   os.mkdir(dircase)
52 else :
53   dircase = tempfile.mkdtemp()
54 # ==================================
55
56 salome.salome_init()
57 import iparameters
58 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
59 ipar.append("AP_MODULES_LIST", "Homard")
60 #
61 #========================================================================
62 #========================================================================
63 def homard_exec(theStudy):
64   """
65 Python script for HOMARD
66   """
67   error = 0
68 #
69   while not error :
70 #
71     homard.SetCurrentStudy(theStudy)
72   #
73   # Creation of the boundaries
74   # ==========================
75   # Creation of the discrete boundary
76     Boundary_3_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
77   #
78   # Creation of the external cylinder
79     Boundary_3_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
80   #
81   # Creation of the internal cylinder
82     Boundary_3_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
83   #
84   # Creation of the first sphere
85     Boundary_3_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
86   #
87   # Creation of the second sphere
88     Boundary_3_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
89   #
90   # Creation of the hypotheses
91   # ==========================
92   # Uniform refinement
93     HypoName = "Hypo_" + Test_Name
94     print "-------- Creation of the hypothesis", HypoName
95     Hypo_test_3 = homard.CreateHypothesis(HypoName)
96     Hypo_test_3.SetUnifRefinUnRef(1)
97     print HypoName, " : zones utilisées :", Hypo_test_3.GetZones()
98     print HypoName, " : champ utilisé :", Hypo_test_3.GetFieldName()
99     print HypoName, " : composantes utilisées :", Hypo_test_3.GetComps()
100   #
101     for num in range (n_boucle+1) :
102   #
103       print "-------- num =", num, "--------"
104   #
105   # Creation of the case Case_test_3
106   # ===========================
107       if ( num <= 1 ) :
108         CaseName = "Case_" + Test_Name
109         print "-------- Creation of the case", CaseName
110         MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
111         Case_test_3 = homard.CreateCase(CaseName, 'MOYEU', MeshFile)
112         Case_test_3.SetDirName(dircase)
113         Case_test_3.AddBoundaryGroup('courbes', '')
114         Case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
115         Case_test_3.AddBoundaryGroup('cyl_int', 'INT')
116         Case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
117         Case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
118   #
119   # Creation of the iterations
120   # ==========================
121   # Creation of the iteration 1
122       IterName = "I_" + Test_Name + "_1"
123       print "-------- Creation of the iteration", IterName
124       Iter_test_3_1 = Case_test_3.NextIteration(IterName)
125       Iter_test_3_1.SetMeshName('MOYEU_1')
126       Iter_test_3_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
127       Iter_test_3_1.AssociateHypo('Hypo_test_3')
128       error = Iter_test_3_1.Compute(1, 1)
129       if error :
130         error = 10*num + 1
131         break
132
133   # Creation of the iteration 2
134       IterName = "I_" + Test_Name + "_2"
135       print "-------- Creation of the iteration", IterName
136       Iter_test_3_2 = Iter_test_3_1.NextIteration(IterName)
137       Iter_test_3_2.SetMeshName('MOYEU_2')
138       Iter_test_3_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
139       Iter_test_3_2.AssociateHypo('Hypo_test_3')
140       error = Iter_test_3_2.Compute(1, 1)
141       if error :
142         error = 10*num + 2
143         break
144   #
145   # Creation of the schema YACS
146   # ===========================
147       ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
148       ScriptFile = os.path.normpath(ScriptFile)
149       DirName = dircase
150       YACSName = "YACS_" + Test_Name
151       print "-------- Creation of the schema", YACSName
152       YACS_test_3 = Case_test_3.CreateYACSSchema(YACSName, ScriptFile, DirName, MeshFile)
153       YACS_test_3.SetType(2)
154       YACS_test_3.SetMaxIter(2)
155       error = YACS_test_3.Write()
156       if error :
157         error = 10*num + 5
158         break
159
160   # Destructions
161   # ============
162   # Destruction of the schema, sauf a la fin
163       if ( num < n_boucle ) :
164         print "-------- Destruction of the schema", YACS_test_3.GetName()
165         error = YACS_test_3.Delete(1)
166         if error :
167           error = 10*num + 6
168           break
169   # After the first loop, the case is deleted, except the final mesh files
170   # All the iterations are deleted
171       if ( num == 0 ) :
172         print "-------- Destruction of the case", Case_test_3.GetName()
173         error = Case_test_3.Delete(0)
174         if error :
175           break
176   # After the second loop, the iterations are deleted, with the final mesh files
177       elif ( num == 1 ) :
178   # Recursive destruction of the iterations
179         print "-------- Recursive destruction of the iteration", Iter_test_3_1.GetName()
180         error = Iter_test_3_1.Delete(1)
181         if error :
182           error = 10*num + 3
183           break
184   # Destruction and creation of the hypothese
185         if ( num == 1 ) :
186           print "-------- Destruction of the hypothese", Hypo_test_3.GetName()
187           error = Hypo_test_3.Delete()
188           if error :
189             error = 10*num + 4
190             break
191           HypoName = "Hypo_test_3"
192           print "-------- Creation of the hypothesis", HypoName
193           Hypo_test_3 = homard.CreateHypothesis(HypoName)
194           Hypo_test_3.SetUnifRefinUnRef(1)
195   #
196     break
197   #
198   return error
199
200 #========================================================================
201
202 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
203 assert homard is not None, "Impossible to load homard engine"
204 homard.SetLanguageShort("fr")
205 #
206 # Exec of HOMARD-SALOME
207 #
208 try :
209   error_main = homard_exec(salome.myStudy)
210   if error_main :
211     raise Exception('Pb in homard_exec at iteration %d' %error_main )
212 except Exception, e:
213   raise Exception('Pb in homard_exec: '+e.message)
214 #
215 # Test of the results
216 #
217 n_rep_test_file = n_iter_test_file*n_boucle
218 destroy_dir = not debug
219 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
220 #
221 if salome.sg.hasDesktop():
222   salome.sg.updateObjBrowser(1)
223   iparameters.getSession().restoreVisualState(1)
224