1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2011-2022 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 Python script for HOMARD
24 Test tutorial_4 associe au tutorial 4
26 __revision__ = "V5.07"
28 #========================================================================
29 TEST_NAME = "tutorial_4"
33 #========================================================================
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 get_dir
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 # ==================================
55 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
56 IPAR.append("AP_MODULES_LIST", "Homard")
59 #========================= Debut de la fonction ==================================
61 def homard_exec(nom, ficmed, xao_file, verbose=True):
63 Python script for HOMARD
70 # HOMARD.UpdateStudy()
76 cao_name = "CAO_" + nom
77 la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
83 # Creation of the hypothesis hypo_0_1
84 l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
85 l_hypothese_0_1.SetUnifRefinUnRef(1)
86 l_hypothese_0_1.AddGroup('IN1')
87 l_hypothese_0_1.AddGroup('IN2')
88 l_hypothese_0_1.AddGroup('T1_INT_I')
89 l_hypothese_0_1.AddGroup('T1_INT_O')
90 l_hypothese_0_1.AddGroup('T2_INT')
91 # Creation of the hypothesis hypo_1_2
92 l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
93 l_hypothese_1_2.SetUnifRefinUnRef(1)
94 l_hypothese_1_2.AddGroup('T1_EXT_I')
95 l_hypothese_1_2.AddGroup('T1_EXT_O')
96 l_hypothese_1_2.AddGroup('T2_EXT')
97 # Creation of the hypothesis hypo_2_3
98 l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
99 l_hypothese_2_3.SetUnifRefinUnRef(1)
100 l_hypothese_2_3.AddGroup('INT_I')
101 l_hypothese_2_3.AddGroup('INT_E')
102 l_hypothese_2_3.AddGroup('IN1')
103 l_hypothese_2_3.AddGroup('IN2')
109 le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
110 le_cas.SetDirName(DIRCASE)
111 le_cas.AddBoundary(cao_name)
120 print(". Itérations")
121 # Iteration iter_4_1 : raffinement selon les faces internes
122 iter_4_1 = le_cas.NextIteration('iter_4_1')
123 iter_4_1.SetMeshName('PIQUAGE_1')
124 iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
125 iter_4_1.AssociateHypo('hypo_4_0_1')
126 erreur = iter_4_1.Compute(1, option)
127 print ("erreur = %d" % erreur)
130 # Iteration iter_4_2 : raffinement selon les faces externes
131 iter_4_2 = iter_4_1.NextIteration('iter_4_2')
132 iter_4_2.SetMeshName('PIQUAGE_2')
133 iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
134 iter_4_2.AssociateHypo('hypo_4_1_2')
135 erreur = iter_4_2.Compute(1, option)
138 # Iteration iter_4_3 : second raffinement selon les faces externes
139 iter_4_3 = iter_4_2.NextIteration('iter_4_3')
140 iter_4_3.SetMeshName('PIQUAGE_3')
141 iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
142 iter_4_3.AssociateHypo('hypo_4_2_3')
143 erreur = iter_4_3.Compute(1, option)
150 message += "Erreur au calcul de l'itération %d" % erreur
152 return erreur, message
154 #========================== Fin de la fonction ==================================
160 # A. Exec of HOMARD-SALOME
162 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
163 assert HOMARD is not None, "Impossible to load homard engine"
164 HOMARD.SetLanguageShort("fr")
166 FICMED = os.path.join(REP_DATA, "tutorial_4.00.med")
167 XAO_FILE = os.path.join(REP_DATA, TEST_NAME+".xao")
169 ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, VERBOSE)
170 except RuntimeError as eee:
172 MESSAGE = str(eee.message)
175 MESSAGE += "Pb in homard_exec"
178 # B. Test of the results
180 N_REP_TEST_FILE = N_ITER_TEST_FILE
181 DESTROY_DIR = not DEBUG
182 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
187 raise Exception(MESSAGE)
190 if salome.sg.hasDesktop():
191 salome.sg.updateObjBrowser()
192 iparameters.getSession().restoreVisualState(1)