Salome HOME
gunzip of med files for SciMotors tests
[modules/homard.git] / src / tests / Test / tutorial_6.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2011-2019  CEA/DEN, EDF R&D
4 #
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.
9 #
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.
14 #
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
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 """
23 Python script for HOMARD
24 Test tutorial_6 associe au tutorial 6
25 """
26 __revision__ = "V4.06"
27
28 #========================================================================
29 TEST_NAME = "tutorial_6"
30 DEBUG = False
31 N_ITER_TEST_FILE = 3
32 #========================================================================
33 import os
34 import sys
35 import HOMARD
36 import salome
37 #
38 # ==================================
39 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
40 # Repertoire des scripts utilitaires
41 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
42 REP_PYTHON = os.path.normpath(REP_PYTHON)
43 sys.path.append(REP_PYTHON)
44 from test_util import get_dir
45 from test_util import get_dir_tutorial
46 from test_util import test_results
47 # ==================================
48 # Répertoires pour ce test
49 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
50 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
51 # ==================================
52 #
53 import salome
54 salome.salome_init()
55 import HOMARD
56 #
57 import iparameters
58 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
59 IPAR.append("AP_MODULES_LIST", "Homard")
60 #
61 #
62 #========================= Debut de la fonction ==================================
63 #
64 def homard_exec(nom, ficmed, nomfr, ficfrmed, verbose=False):
65   """
66 Python script for HOMARD
67   """
68   erreur = 0
69   message = ""
70 #
71   while not erreur :
72     #
73   #  HOMARD.UpdateStudy()
74     #
75     # Frontières
76     # ==========
77     if verbose :
78       print(". Frontières")
79     boun_6_1 = HOMARD.CreateBoundaryDi('intersection', nomfr, ficfrmed)
80     #
81     boun_6_2 = HOMARD.CreateBoundaryCylinder('cyl_1_ext', 0.0, 25., -25., 25., 50., 75., 100.)
82     #
83     boun_6_3 = HOMARD.CreateBoundaryCylinder('cyl_2_ext', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
84     #
85     boun_6_6 = HOMARD.CreateBoundaryCylinder('cyl_1_int', 0.0, 25., -25., 25., 50., 75., 75.)
86     #
87     boun_6_5 = HOMARD.CreateBoundaryCylinder('cyl_2_int', 17.5, -2.5, -12.5, -100., -75., -25., 25.)
88     #
89     # Hypotheses
90     # ==========
91     if verbose :
92       print(". Hypothèses")
93     # Creation of the hypothesis hypo_0_1
94     l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_6_0_1')
95     l_hypothese_0_1.SetUnifRefinUnRef(1)
96     l_hypothese_0_1.AddGroup('IN1')
97     l_hypothese_0_1.AddGroup('IN2')
98     l_hypothese_0_1.AddGroup('T1_INT_I')
99     l_hypothese_0_1.AddGroup('T1_INT_O')
100     l_hypothese_0_1.AddGroup('T2_INT')
101     # Creation of the hypothesis hypo_1_2
102     l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_6_1_2')
103     l_hypothese_1_2.SetUnifRefinUnRef(1)
104     l_hypothese_1_2.AddGroup('T1_EXT_I')
105     l_hypothese_1_2.AddGroup('T1_EXT_O')
106     l_hypothese_1_2.AddGroup('T2_EXT')
107     # Creation of the hypothesis hypo_2_3
108     l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_6_2_3')
109     l_hypothese_2_3.SetUnifRefinUnRef(1)
110     l_hypothese_2_3.AddGroup('INT_I')
111     l_hypothese_2_3.AddGroup('INT_E')
112     l_hypothese_2_3.AddGroup('IN1')
113     l_hypothese_2_3.AddGroup('IN2')
114     #
115     # Cas
116     # ===
117     if verbose :
118       print(". Cas")
119     le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
120     le_cas.SetDirName(DIRCASE)
121     le_cas.AddBoundary( 'intersection' )
122     le_cas.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_I' )
123     le_cas.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_I' )
124     le_cas.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_O' )
125     le_cas.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_O' )
126     le_cas.AddBoundaryGroup( 'cyl_2_int', 'T2_INT' )
127     le_cas.AddBoundaryGroup( 'cyl_2_ext', 'T2_EXT' )
128     #
129     # Itérations
130     # ==========
131     if verbose :
132       option = 2
133     else :
134       option = 1
135     if verbose :
136       print(". Itérations")
137     # Iteration iter_6_1 : raffinement selon les faces internes
138     iter_6_1 = le_cas.NextIteration('iter_6_1')
139     iter_6_1.SetMeshName('PIQUAGE_1')
140     iter_6_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
141     iter_6_1.AssociateHypo('hypo_6_0_1')
142     erreur = iter_6_1.Compute(1, option)
143     print ("erreur = %d" % erreur)
144     if erreur :
145       break
146     # Iteration iter_6_2 : raffinement selon les faces externes
147     iter_6_2 = iter_6_1.NextIteration('iter_6_2')
148     iter_6_2.SetMeshName('PIQUAGE_2')
149     iter_6_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
150     iter_6_2.AssociateHypo('hypo_6_1_2')
151     erreur = iter_6_2.Compute(1, option)
152     if erreur :
153       break
154     # Iteration iter_6_3 : second raffinement selon les faces externes
155     iter_6_3 = iter_6_2.NextIteration('iter_6_3')
156     iter_6_3.SetMeshName('PIQUAGE_3')
157     iter_6_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
158     iter_6_3.AssociateHypo('hypo_6_2_3')
159     erreur = iter_6_3.Compute(1, option)
160     if erreur :
161       break
162   #
163     break
164   #
165   if erreur :
166     message += "Erreur au calcul de l'itération %d" % erreur
167   #
168   return erreur, message
169 #
170 #==========================  Fin de la fonction ==================================
171 #
172 ERREUR = 0
173 MESSAGE = ""
174 while not ERREUR :
175   #
176   # A. Exec of HOMARD-SALOME
177   #
178   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
179   assert HOMARD is not None, "Impossible to load homard engine"
180   HOMARD.SetLanguageShort("fr")
181 #
182   FICMED = os.path.join(DATA_TUTORIAL, "tutorial_4.00.med")
183   FICFRMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".fr.med")
184   try:
185     ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, "COURBES", FICFRMED, DEBUG)
186   except RuntimeError as eee:
187     ERREUR = 2
188     MESSAGE = str(eee.message)
189   #
190   if ERREUR :
191     MESSAGE += "Pb in homard_exec"
192     break
193   #
194   # B. Test of the results
195   #
196   N_REP_TEST_FILE = N_ITER_TEST_FILE
197   DESTROY_DIR = not DEBUG
198   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
199   #
200   break
201 #
202 if ERREUR:
203   raise Exception(MESSAGE)
204 #
205 if salome.sg.hasDesktop():
206   salome.sg.updateObjBrowser()
207   iparameters.getSession().restoreVisualState(1)
208