1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Python script for HOMARD
22 Test tutorial_2 associe au tutorial 2
24 __revision__ = "V4.02"
26 #========================================================================
27 TEST_NAME = "tutorial_2"
30 #========================================================================
37 # ==================================
38 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des scripts utilitaires
40 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
41 REP_PYTHON = os.path.normpath(REP_PYTHON)
42 sys.path.append(REP_PYTHON)
43 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des donnees du test
46 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
47 REP_DATA = os.path.normpath(REP_DATA)
48 # Repertoire des resultats
50 DIRCASE = os.path.join("/tmp", TEST_NAME)
51 if ( os.path.isdir(DIRCASE) ) :
55 DIRCASE = tempfile.mkdtemp(prefix=TEST_NAME)
56 # Repertoire des donnees du tutorial
57 DATA_TUTORIAL = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
58 DATA_TUTORIAL = os.path.normpath(DATA_TUTORIAL)
59 sys.path.append(DATA_TUTORIAL)
60 from tutorial_util import gzip_gunzip
61 # ==================================
62 gzip_gunzip(DATA_TUTORIAL, 2, -1)
63 # ==================================
67 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
68 IPAR.append("AP_MODULES_LIST", "Homard")
71 #========================= Debut de la fonction ==================================
73 def homard_exec(nom, ficmed, verbose=False):
75 Python script for HOMARD
82 HOMARD.SetCurrentStudy(salome.myStudy)
89 zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
92 zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
95 zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
100 print(". Hypothèses")
103 hypo_2 = HOMARD.CreateHypothesis('hypo_2')
104 hypo_2.AddZone('Zone_12_1', 1)
105 hypo_2.AddZone('Zone_12_0', 1)
107 # Hypothese "hypo_2_bis"
108 # ======================
109 hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
110 hypo_2_bis.AddZone('Zone_12_0', -1)
111 hypo_2_bis.AddZone('Zone_12_2', 1)
117 le_cas = HOMARD.CreateCase('case_2', nom, ficmed)
118 le_cas.SetDirName(DIRCASE)
127 print(". Itérations")
129 # Iteration "iter_2_1"
130 # ====================
131 iter_2_1 = le_cas.NextIteration('iter_2_1')
132 iter_2_1.SetMeshName('M_1')
133 iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
134 iter_2_1.AssociateHypo('hypo_2')
135 erreur = iter_2_1.Compute(1, option)
139 # Iteration "iter_2_2"
140 # ====================
141 iter_2_2 = iter_2_1.NextIteration('iter_2_2')
142 iter_2_2.SetMeshName('M_2')
143 iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
144 iter_2_2.AssociateHypo('hypo_2_bis')
145 erreur = iter_2_2.Compute(1, option)
152 message += "Erreur au calcul de l'itération %d" % erreur
154 return erreur, message
156 #========================== Fin de la fonction ==================================
162 # A. Exec of HOMARD-SALOME
164 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
165 assert HOMARD is not None, "Impossible to load homard engine"
166 HOMARD.SetLanguageShort("fr")
168 FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
170 ERREUR, MESSAGE = homard_exec("MZERO", FICMED, DEBUG)
171 except Exception, eee:
173 MESSAGE = eee.message
176 MESSAGE += "Pb in homard_exec"
179 # B. Test of the results
181 N_REP_TEST_FILE = N_ITER_TEST_FILE
182 DESTROY_DIR = not DEBUG
183 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
188 raise Exception(MESSAGE)
190 # ==================================
191 gzip_gunzip(DATA_TUTORIAL, 2, 1)
192 # ==================================
194 if salome.sg.hasDesktop():
195 salome.sg.updateObjBrowser(True)
196 iparameters.getSession().restoreVisualState(1)