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