Salome HOME
f938775b8d9a57166a4a1724cd46cf3a64eaa142
[modules/homard.git] / src / tests / test_12.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_12 associe au tutorial 2
23 """
24 __revision__ = "V2.3"
25
26 #========================================================================
27 Test_Name = "test_12"
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 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des resultats
46 if debug :
47   dircase = os.path.join("/tmp", Test_Name)
48   if ( os.path.isdir(dircase) ) :
49     remove_dir(dircase)
50   os.mkdir(dircase)
51 else :
52   dircase = tempfile.mkdtemp()
53 # Repertoire des donnees du tutorial
54 data_dir = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
55 data_dir = os.path.normpath(data_dir)
56 sys.path.append(data_dir)
57 from tutorial_util import gzip_gunzip
58 # ==================================
59 gzip_gunzip(data_dir, 2, -1)
60 # ==================================
61
62 salome.salome_init()
63 import iparameters
64 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
65 ipar.append("AP_MODULES_LIST", "Homard")
66 #
67 #========================================================================
68 #========================================================================
69 def homard_exec(theStudy):
70   """
71 Python script for HOMARD
72   """
73   #
74   homard.SetCurrentStudy(theStudy)
75   #
76   # Creation des zones
77   # ==================
78   # Box "Zone_12_0"
79   Zone_12_0 = homard.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
80   #
81   # Sphere "Zone_12_1"
82   Zone_12_1 = homard.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
83   #
84   # Box "Zone_12_2"
85   Zone_12_2 = homard.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
86   #
87   # Hypothese "Hypo_2"
88   # ==================
89   Hypo_2 = homard.CreateHypothesis('Hypo_2')
90   Hypo_2.AddZone('Zone_12_1', 1)
91   Hypo_2.AddZone('Zone_12_0', 1)
92   #
93   # Hypothese "Hypo_2_bis"
94   # ======================
95   Hypo_2_bis = homard.CreateHypothesis('Hypo_2_bis')
96   Hypo_2_bis.AddZone('Zone_12_0', -1)
97   Hypo_2_bis.AddZone('Zone_12_2', 1)
98   #
99   # Cas
100   # ===
101   Case_2 = homard.CreateCase('Case_2', 'MZERO', data_dir+'/tutorial_2.00.med')
102   Case_2.SetDirName(dircase)
103   #
104   # Iteration "Iter_2_1"
105   # ====================
106   Iter_2_1 = Case_2.NextIteration('Iter_2_1')
107   Iter_2_1.SetMeshName('M_1')
108   Iter_2_1.SetMeshFile(dircase+'/maill.01.med')
109   Iter_2_1.AssociateHypo('Hypo_2')
110   error = Iter_2_1.Compute(1, 2)
111   #
112   # Iteration "Iter_2_2"
113   # ====================
114   Iter_2_2 = Iter_2_1.NextIteration('Iter_2_2')
115   Iter_2_2.SetMeshName('M_2')
116   Iter_2_2.SetMeshFile(dircase+'/maill.02.med')
117   Iter_2_2.AssociateHypo('Hypo_2_bis')
118   error = Iter_2_2.Compute(1, 2)
119   #
120   return error
121
122 #========================================================================
123
124 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
125 assert homard is not None, "Impossible to load homard engine"
126 homard.SetLanguageShort("fr")
127 #
128 # Exec of HOMARD-SALOME
129 #
130 try :
131   error_main = homard_exec(salome.myStudy)
132   if error_main :
133     raise Exception('Pb in homard_exec at iteration %d' %error_main )
134 except Exception, e:
135   raise Exception('Pb in homard_exec: '+e.message)
136 #
137 # Test of the results
138 #
139 n_rep_test_file = n_iter_test_file
140 destroy_dir = not debug
141 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
142 #
143 # ==================================
144 gzip_gunzip(data_dir, 2, 1)
145 # ==================================
146 #
147 if salome.sg.hasDesktop():
148   salome.sg.updateObjBrowser(1)
149   iparameters.getSession().restoreVisualState(1)
150