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