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