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.05"
26 #========================================================================
27 TEST_NAME = "tutorial_2"
30 #========================================================================
34 # ==================================
35 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
36 # Repertoire des scripts utilitaires
37 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
38 REP_PYTHON = os.path.normpath(REP_PYTHON)
39 sys.path.append(REP_PYTHON)
40 from test_util import get_dir
41 from test_util import get_dir_tutorial
42 from test_util import test_results
43 # ==================================
44 # Répertoires pour ce test
45 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
46 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
47 # ==================================
48 sys.path.append(DATA_TUTORIAL)
49 from tutorial_util import gzip_gunzip
50 # ==================================
51 gzip_gunzip(DATA_TUTORIAL, 2, -1)
52 # ==================================
59 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
60 IPAR.append("AP_MODULES_LIST", "Homard")
63 #========================= Debut de la fonction ==================================
65 def homard_exec(nom, ficmed, verbose=False):
67 Python script for HOMARD
74 # HOMARD.UpdateStudy()
81 zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
84 zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
87 zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
95 hypo_2 = HOMARD.CreateHypothesis('hypo_2')
96 hypo_2.AddZone('Zone_12_1', 1)
97 hypo_2.AddZone('Zone_12_0', 1)
99 # Hypothese "hypo_2_bis"
100 # ======================
101 hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
102 hypo_2_bis.AddZone('Zone_12_0', -1)
103 hypo_2_bis.AddZone('Zone_12_2', 1)
109 le_cas = HOMARD.CreateCase('case_2', nom, ficmed)
110 le_cas.SetDirName(DIRCASE)
119 print(". Itérations")
121 # Iteration "iter_2_1"
122 # ====================
123 iter_2_1 = le_cas.NextIteration('iter_2_1')
124 iter_2_1.SetMeshName('M_1')
125 iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
126 iter_2_1.AssociateHypo('hypo_2')
127 erreur = iter_2_1.Compute(1, option)
131 # Iteration "iter_2_2"
132 # ====================
133 iter_2_2 = iter_2_1.NextIteration('iter_2_2')
134 iter_2_2.SetMeshName('M_2')
135 iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
136 iter_2_2.AssociateHypo('hypo_2_bis')
137 erreur = iter_2_2.Compute(1, option)
144 message += "Erreur au calcul de l'itération %d" % erreur
146 return erreur, message
148 #========================== Fin de la fonction ==================================
154 # A. Exec of HOMARD-SALOME
156 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
157 assert HOMARD is not None, "Impossible to load homard engine"
158 HOMARD.SetLanguageShort("fr")
160 FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
162 ERREUR, MESSAGE = homard_exec("MZERO", FICMED, DEBUG)
163 except RuntimeError as eee:
165 MESSAGE = str(eee.message)
168 MESSAGE += "Pb in homard_exec"
171 # B. Test of the results
173 N_REP_TEST_FILE = N_ITER_TEST_FILE
174 DESTROY_DIR = not DEBUG
175 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
180 raise Exception(MESSAGE)
182 # ==================================
183 gzip_gunzip(DATA_TUTORIAL, 2, 1)
184 # ==================================
186 if salome.sg.hasDesktop():
187 salome.sg.updateObjBrowser()
188 iparameters.getSession().restoreVisualState(1)