Salome HOME
automatisation FronTrack - tests
[modules/homard.git] / src / tests / Test / tutorial_5.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_5 associe au tutorial 5
23 """
24 __revision__ = "V4.02"
25
26 #========================================================================
27 TEST_NAME = "tutorial_5"
28 DEBUG = False
29 N_ITER_TEST_FILE = 2
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, 5, -1)
63 # ==================================
64
65 salome.salome_init()
66 import iparameters
67 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
68 IPAR.append("AP_MODULES_LIST", "Homard")
69 #
70 #
71 #========================= Debut de la fonction ==================================
72 #
73 def homard_exec(nom, ficmed, nomfr, ficfrmed, verbose=False):
74   """
75 Python script for HOMARD
76   """
77   erreur = 0
78   message = ""
79 #
80   while not erreur :
81     #
82     HOMARD.SetCurrentStudy(salome.myStudy)
83     #
84     # Frontiere
85     # =========
86     if verbose :
87       print(". Frontière")
88     # Creation of the discrete boundary Boun_5_1
89     boun_5_1 = HOMARD.CreateBoundaryDi('Boun_5_1', nomfr, ficfrmed)
90     #
91     # Creation des zones
92     # ==================
93     if verbose :
94       print(". Zones")
95     # Creation of the disk with hole enveloppe
96     enveloppe = HOMARD.CreateZoneDiskWithHole( 'enveloppe', 0., 0., 250., 193., 1 )
97     # Creation of the rectangle quart_sup
98     quart_sup = HOMARD.CreateZoneBox2D( 'quart_sup', 0., 250., 0., 250., 1 )
99     #
100     # Hypotheses
101     # ==========
102     if verbose :
103       print(". Hypothèses")
104     # Creation of the hypothesis hypo_5
105     hypo_5 = HOMARD.CreateHypothesis('hypo_5')
106     hypo_5.AddZone('enveloppe', 1)
107     # Creation of the hypothesis hypo_5_bis
108     hypo_5_bis = HOMARD.CreateHypothesis('hypo_5_bis')
109     hypo_5_bis.AddZone('quart_sup', 1)
110     #
111     # Cas
112     # ===
113     if verbose :
114       print(". Cas")
115     le_cas = HOMARD.CreateCase('case_5', nom, ficmed)
116     le_cas.SetDirName(DIRCASE)
117     le_cas.SetConfType(1)
118     le_cas.AddBoundary('Boun_5_1')
119     #
120     # Itérations
121     # ==========
122     if verbose :
123       option = 2
124     else :
125       option = 1
126     if verbose :
127       print(". Itérations")
128     #
129     # Iteration "iter_5_1"
130     # ====================
131     iter_5_1 = le_cas.NextIteration('iter_5_1')
132     iter_5_1.SetMeshName('COEUR_2D_01')
133     iter_5_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
134     iter_5_1.AssociateHypo('hypo_5')
135     erreur = iter_5_1.Compute(1, option)
136     if erreur :
137       break
138     #
139     # Iteration "iter_5_2"
140     # ====================
141     iter_5_2 = iter_5_1.NextIteration('iter_5_2')
142     iter_5_2.SetMeshName('COEUR_2D_02')
143     iter_5_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
144     iter_5_2.AssociateHypo('hypo_5_bis')
145     erreur = iter_5_2.Compute(1, option)
146     if erreur :
147       break
148   #
149     break
150   #
151   if erreur :
152     message += "Erreur au calcul de l'itération %d" % erreur
153   #
154   return erreur, message
155
156 #==========================  Fin de la fonction ==================================
157 #
158 ERREUR = 0
159 MESSAGE = ""
160 while not ERREUR :
161   #
162   # A. Exec of HOMARD-SALOME
163   #
164   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
165   assert HOMARD is not None, "Impossible to load homard engine"
166   HOMARD.SetLanguageShort("fr")
167 #
168   FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
169   FICFRMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".fr.med")
170   try:
171     ERREUR, MESSAGE = homard_exec("COEUR_2D", FICMED, "MAIL_EXT", FICFRMED, DEBUG)
172   except Exception, eee:
173     ERREUR = 2
174     MESSAGE = eee.message
175   #
176   if ERREUR :
177     MESSAGE += "Pb in homard_exec"
178     break
179   #
180   # B. Test of the results
181   #
182   N_REP_TEST_FILE = N_ITER_TEST_FILE
183   DESTROY_DIR = not DEBUG
184   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
185   #
186   break
187 #
188 if ERREUR:
189   raise Exception(MESSAGE)
190 #
191 # ==================================
192 gzip_gunzip(DATA_TUTORIAL, 5, 1)
193 # ==================================
194 #
195 if salome.sg.hasDesktop():
196   salome.sg.updateObjBrowser(True)
197   iparameters.getSession().restoreVisualState(1)
198