Salome HOME
Séparation entre les pythons et les données des tests
[modules/homard.git] / src / tests / Test / test_15.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_15 associe au tutorial 5
23 """
24 __revision__ = "V2.3"
25
26 #========================================================================
27 Test_Name = "test_15"
28 debug=False
29 n_iter_test_file = 2
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 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 # Repertoire des donnees du tutorial
55 data_dir = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
56 data_dir = os.path.normpath(data_dir)
57 sys.path.append(data_dir)
58 from tutorial_util import gzip_gunzip
59 # ==================================
60 gzip_gunzip(data_dir, 5, -1)
61 # ==================================
62
63 salome.salome_init()
64 import iparameters
65 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
66 ipar.append("AP_MODULES_LIST", "Homard")
67 #
68 #========================================================================
69 #========================================================================
70 def homard_exec(theStudy):
71   """
72 Python script for HOMARD
73   """
74   #
75   homard.SetCurrentStudy(theStudy)
76 #
77   # Frontiere
78   # =========
79   # Creation of the discrete boundary Boun_5_1
80   Boun_5_1 = homard.CreateBoundaryDi('Boun_5_1', 'MAIL_EXT', data_dir+'/tutorial_5.fr.med')
81   #
82   # Creation des zones
83   # ==================
84   # Creation of the disk with hole enveloppe
85   enveloppe = homard.CreateZoneDiskWithHole( 'enveloppe', 0., 0., 250., 193., 1 )
86   # Creation of the rectangle quart_sup
87   quart_sup = homard.CreateZoneBox2D( 'quart_sup', 0., 250., 0., 250., 1 )
88   #
89   # Hypotheses
90   # ==========
91   # Creation of the hypothesis Hypo_5
92   Hypo_5 = homard.CreateHypothesis('Hypo_5')
93   Hypo_5.AddZone('enveloppe', 1)
94   # Creation of the hypothesis Hypo_5_bis
95   Hypo_5_bis = homard.CreateHypothesis('Hypo_5_bis')
96   Hypo_5_bis.AddZone('quart_sup', 1)
97   #
98   # Cas
99   # ===
100   Case_5 = homard.CreateCase('Case_5', 'COEUR_2D', data_dir+'/tutorial_5.00.med')
101   Case_5.SetDirName(dircase)
102   Case_5.SetConfType(1)
103   Case_5.AddBoundaryGroup('Boun_5_1', '')
104   #
105   # Iteration "Iter_5_1"
106   # ====================
107   Iter_5_1 = Case_5.NextIteration('Iter_5_1')
108   Iter_5_1.SetMeshName('COEUR_2D_01')
109   Iter_5_1.SetMeshFile(dircase+'/maill.01.med')
110   Iter_5_1.AssociateHypo('Hypo_5')
111   error = Iter_5_1.Compute(1, 2)
112   #
113   # Iteration "Iter_5_2"
114   # ====================
115   Iter_5_2 = Iter_5_1.NextIteration('Iter_5_2')
116   Iter_5_2.SetMeshName('COEUR_2D_02')
117   Iter_5_2.SetMeshFile(dircase+'/maill.02.med')
118   Iter_5_2.AssociateHypo('Hypo_5_bis')
119   error = Iter_5_2.Compute(1, 2)
120   #
121   return error
122
123 #========================================================================
124
125 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
126 assert homard is not None, "Impossible to load homard engine"
127 homard.SetLanguageShort("fr")
128 #
129 # Exec of HOMARD-SALOME
130 #
131 try :
132   error_main = homard_exec(salome.myStudy)
133   if error_main :
134     raise Exception('Pb in homard_exec at iteration %d' %error_main )
135 except Exception, e:
136   raise Exception('Pb in homard_exec: '+e.message)
137 #
138 # Test of the results
139 #
140 n_rep_test_file = n_iter_test_file
141 destroy_dir = not debug
142 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
143 #
144 # ==================================
145 gzip_gunzip(data_dir, 5, 1)
146 # ==================================
147 #
148 if salome.sg.hasDesktop():
149   salome.sg.updateObjBrowser(1)
150   iparameters.getSession().restoreVisualState(1)
151