Salome HOME
Merge branch 'V9_2_2_BR'
[modules/homard.git] / src / tests / Test / tutorial_4.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_4 associe au tutorial 4
25 """
26 __revision__ = "V5.04"
27
28 #========================================================================
29 TEST_NAME = "tutorial_4"
30 DEBUG = False
31 N_ITER_TEST_FILE = 3
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, 4, -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, xao_file, verbose=True):
68   """
69 Python script for HOMARD
70   """
71   erreur = 0
72   message = ""
73 #
74   while not erreur :
75     #
76   #  HOMARD.UpdateStudy()
77     #
78     # Frontières
79     # ==========
80     if verbose :
81       print(". Frontières")
82     cao_name = "CAO_" + nom
83     la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
84     #
85     # Hypotheses
86     # ==========
87     if verbose :
88       print(". Hypothèses")
89     # Creation of the hypothesis hypo_0_1
90     l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
91     l_hypothese_0_1.SetUnifRefinUnRef(1)
92     l_hypothese_0_1.AddGroup('IN1')
93     l_hypothese_0_1.AddGroup('IN2')
94     l_hypothese_0_1.AddGroup('T1_INT_I')
95     l_hypothese_0_1.AddGroup('T1_INT_O')
96     l_hypothese_0_1.AddGroup('T2_INT')
97     # Creation of the hypothesis hypo_1_2
98     l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
99     l_hypothese_1_2.SetUnifRefinUnRef(1)
100     l_hypothese_1_2.AddGroup('T1_EXT_I')
101     l_hypothese_1_2.AddGroup('T1_EXT_O')
102     l_hypothese_1_2.AddGroup('T2_EXT')
103     # Creation of the hypothesis hypo_2_3
104     l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
105     l_hypothese_2_3.SetUnifRefinUnRef(1)
106     l_hypothese_2_3.AddGroup('INT_I')
107     l_hypothese_2_3.AddGroup('INT_E')
108     l_hypothese_2_3.AddGroup('IN1')
109     l_hypothese_2_3.AddGroup('IN2')
110     #
111     # Cas
112     # ===
113     if verbose :
114       print(". Cas")
115     le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
116     le_cas.SetDirName(DIRCASE)
117     le_cas.AddBoundary(cao_name)
118     #
119     # Itérations
120     # ==========
121     if verbose :
122       option = 2
123     else :
124       option = 1
125     if verbose :
126       print(". Itérations")
127     # Iteration iter_4_1 : raffinement selon les faces internes
128     iter_4_1 = le_cas.NextIteration('iter_4_1')
129     iter_4_1.SetMeshName('PIQUAGE_1')
130     iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
131     iter_4_1.AssociateHypo('hypo_4_0_1')
132     erreur = iter_4_1.Compute(1, option)
133     print ("erreur = %d" % erreur)
134     if erreur :
135       break
136     # Iteration iter_4_2 : raffinement selon les faces externes
137     iter_4_2 = iter_4_1.NextIteration('iter_4_2')
138     iter_4_2.SetMeshName('PIQUAGE_2')
139     iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
140     iter_4_2.AssociateHypo('hypo_4_1_2')
141     erreur = iter_4_2.Compute(1, option)
142     if erreur :
143       break
144     # Iteration iter_4_3 : second raffinement selon les faces externes
145     iter_4_3 = iter_4_2.NextIteration('iter_4_3')
146     iter_4_3.SetMeshName('PIQUAGE_3')
147     iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
148     iter_4_3.AssociateHypo('hypo_4_2_3')
149     erreur = iter_4_3.Compute(1, option)
150     if erreur :
151       break
152   #
153     break
154   #
155   if erreur :
156     message += "Erreur au calcul de l'itération %d" % erreur
157   #
158   return erreur, message
159 #
160 #==========================  Fin de la fonction ==================================
161 #
162 ERREUR = 0
163 MESSAGE = ""
164 while not ERREUR :
165   #
166   # A. Exec of HOMARD-SALOME
167   #
168   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
169   assert HOMARD is not None, "Impossible to load homard engine"
170   HOMARD.SetLanguageShort("fr")
171 #
172   FICMED = os.path.join(DATA_TUTORIAL, "tutorial_4.00.med")
173   XAO_FILE = os.path.join(DATA_TUTORIAL, TEST_NAME+".xao")
174   try:
175     ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, DEBUG)
176   except RuntimeError as eee:
177     ERREUR = 2
178     MESSAGE = str(eee.message)
179   #
180   if ERREUR :
181     MESSAGE += "Pb in homard_exec"
182     break
183   #
184   # B. Test of the results
185   #
186   N_REP_TEST_FILE = N_ITER_TEST_FILE
187   DESTROY_DIR = not DEBUG
188   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
189   #
190   break
191 #
192 if ERREUR:
193   raise Exception(MESSAGE)
194 #
195 # ==================================
196 gzip_gunzip(DATA_TUTORIAL, 4, 1)
197 # ==================================
198
199 if salome.sg.hasDesktop():
200   salome.sg.updateObjBrowser()
201   iparameters.getSession().restoreVisualState(1)
202