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