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