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