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