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