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_4 associe au tutorial 4
24 __revision__ = "V5.03"
26 #========================================================================
27 TEST_NAME = "tutorial_4"
30 #========================================================================
36 # ==================================
37 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
38 # Repertoire des scripts utilitaires
39 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
40 REP_PYTHON = os.path.normpath(REP_PYTHON)
41 sys.path.append(REP_PYTHON)
42 from test_util import get_dir
43 from test_util import get_dir_tutorial
44 from test_util import test_results
45 # ==================================
46 # Répertoires pour ce test
47 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
48 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
49 # ==================================
50 sys.path.append(DATA_TUTORIAL)
51 from tutorial_util import gzip_gunzip
52 # ==================================
53 gzip_gunzip(DATA_TUTORIAL, 4, -1)
54 # ==================================
58 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
59 IPAR.append("AP_MODULES_LIST", "Homard")
62 #========================= Debut de la fonction ==================================
64 def homard_exec(nom, ficmed, xao_file, verbose=True):
66 Python script for HOMARD
73 HOMARD.SetCurrentStudy(salome.myStudy)
79 cao_name = "CAO_" + nom
80 la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
86 # Creation of the hypothesis hypo_0_1
87 l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
88 l_hypothese_0_1.SetUnifRefinUnRef(1)
89 l_hypothese_0_1.AddGroup('IN1')
90 l_hypothese_0_1.AddGroup('IN2')
91 l_hypothese_0_1.AddGroup('T1_INT_I')
92 l_hypothese_0_1.AddGroup('T1_INT_O')
93 l_hypothese_0_1.AddGroup('T2_INT')
94 # Creation of the hypothesis hypo_1_2
95 l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
96 l_hypothese_1_2.SetUnifRefinUnRef(1)
97 l_hypothese_1_2.AddGroup('T1_EXT_I')
98 l_hypothese_1_2.AddGroup('T1_EXT_O')
99 l_hypothese_1_2.AddGroup('T2_EXT')
100 # Creation of the hypothesis hypo_2_3
101 l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
102 l_hypothese_2_3.SetUnifRefinUnRef(1)
103 l_hypothese_2_3.AddGroup('INT_I')
104 l_hypothese_2_3.AddGroup('INT_E')
105 l_hypothese_2_3.AddGroup('IN1')
106 l_hypothese_2_3.AddGroup('IN2')
112 le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
113 le_cas.SetDirName(DIRCASE)
114 le_cas.AddBoundary(cao_name)
123 print(". Itérations")
124 # Iteration iter_4_1 : raffinement selon les faces internes
125 iter_4_1 = le_cas.NextIteration('iter_4_1')
126 iter_4_1.SetMeshName('PIQUAGE_1')
127 iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
128 iter_4_1.AssociateHypo('hypo_4_0_1')
129 erreur = iter_4_1.Compute(1, option)
130 print ("erreur = %d" % erreur)
133 # Iteration iter_4_2 : raffinement selon les faces externes
134 iter_4_2 = iter_4_1.NextIteration('iter_4_2')
135 iter_4_2.SetMeshName('PIQUAGE_2')
136 iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
137 iter_4_2.AssociateHypo('hypo_4_1_2')
138 erreur = iter_4_2.Compute(1, option)
141 # Iteration iter_4_3 : second raffinement selon les faces externes
142 iter_4_3 = iter_4_2.NextIteration('iter_4_3')
143 iter_4_3.SetMeshName('PIQUAGE_3')
144 iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
145 iter_4_3.AssociateHypo('hypo_4_2_3')
146 erreur = iter_4_3.Compute(1, option)
153 message += "Erreur au calcul de l'itération %d" % erreur
155 return erreur, message
157 #========================== Fin de la fonction ==================================
163 # A. Exec of HOMARD-SALOME
165 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
166 assert HOMARD is not None, "Impossible to load homard engine"
167 HOMARD.SetLanguageShort("fr")
169 FICMED = os.path.join(DATA_TUTORIAL, "tutorial_4.00.med")
170 XAO_FILE = os.path.join(DATA_TUTORIAL, TEST_NAME+".xao")
172 ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, DEBUG)
173 except RuntimeError as eee:
175 MESSAGE = str(eee.message)
178 MESSAGE += "Pb in homard_exec"
181 # B. Test of the results
183 N_REP_TEST_FILE = N_ITER_TEST_FILE
184 DESTROY_DIR = not DEBUG
185 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
190 raise Exception(MESSAGE)
192 # ==================================
193 gzip_gunzip(DATA_TUTORIAL, 4, 1)
194 # ==================================
196 if salome.sg.hasDesktop():
197 salome.sg.updateObjBrowser(True)
198 iparameters.getSession().restoreVisualState(1)