Salome HOME
gunzip of med files for SciMotors tests
[modules/homard.git] / src / tests / Test / tutorial_1.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2019  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_1 associe au tutorial 1
23 """
24 __revision__ = "V4.06"
25
26 #========================================================================
27 TEST_NAME = "tutorial_1"
28 DEBUG = False
29 N_ITER_TEST_FILE = 3
30 #========================================================================
31 import os
32 import sys
33 #
34 # ==================================
35 PATH_HOMARD = os.getenv("HOMARD_ROOT_DIR")
36 # Repertoire des scripts utilitaires
37 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
38 REP_PYTHON = os.path.normpath(REP_PYTHON)
39 sys.path.append(REP_PYTHON)
40 from test_util import get_dir
41 from test_util import get_dir_tutorial
42 from test_util import test_results
43 # ==================================
44 # Répertoires pour ce test
45 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
46 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
47 # ==================================
48 #
49 import salome
50 salome.salome_init()
51 import HOMARD
52 import iparameters
53 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
54 IPAR.append("AP_MODULES_LIST", "Homard")
55 #
56 #
57 #========================= Debut de la fonction ==================================
58 #
59 def homard_exec(nom, ficmed, verbose=False):
60   """
61 Python script for HOMARD
62   """
63   erreur = 0
64   message = ""
65   #
66   while not erreur :
67   #
68   #  HOMARD.UpdateStudy()
69     #
70     # Hypotheses
71     # ==========
72     if verbose :
73       print(". Hypothèses")
74     hypo_1 = HOMARD.CreateHypothesis('hypo_1')
75     hypo_1.SetUnifRefinUnRef(1)
76     #
77     # Cas
78     # ===
79     if verbose :
80       print(". Cas")
81     le_cas = HOMARD.CreateCase('case_1', nom, ficmed)
82     le_cas.SetDirName(DIRCASE)
83     #
84     # Itérations
85     # ==========
86     if verbose :
87       option = 2
88     else :
89       option = 1
90     if verbose :
91       print(". Itérations")
92     # Iteration "iter_1_1"
93     iter_1_1 = le_cas.NextIteration('iter_1_1')
94     iter_1_1.SetMeshName('MESH')
95     iter_1_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
96     iter_1_1.AssociateHypo('hypo_1')
97     erreur = iter_1_1.Compute(1, option)
98     if erreur :
99       break
100
101     # Iteration "iter_1_2"
102     iter_1_2 = iter_1_1.NextIteration('iter_1_2')
103     iter_1_2.SetMeshName('MESH')
104     iter_1_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
105     iter_1_2.AssociateHypo('hypo_1')
106     erreur = iter_1_2.Compute(1, option)
107     if erreur :
108       break
109
110     # Iteration "iter_1_3"
111     iter_1_3 = iter_1_2.NextIteration('iter_1_3')
112     iter_1_3.SetMeshName('MESH')
113     iter_1_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
114     iter_1_3.AssociateHypo('hypo_1')
115     erreur = iter_1_3.Compute(1, option)
116     if erreur :
117       break
118   #
119     break
120   #
121   if erreur :
122     message += "Erreur au calcul de l'itération %d" % erreur
123   #
124   return erreur, message
125 #
126 #==========================  Fin de la fonction ==================================
127 #
128 ERREUR = 0
129 MESSAGE = ""
130 while not ERREUR :
131   #
132   # A. Exec of HOMARD-SALOME
133   #
134   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
135   assert HOMARD is not None, "Impossible to load homard engine"
136   HOMARD.SetLanguageShort("fr")
137 #
138   FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
139   try:
140     ERREUR, MESSAGE = homard_exec("MAILL", FICMED, DEBUG)
141   except RuntimeError as eee:
142     ERREUR = 2
143     MESSAGE = str(eee.message)
144   #
145   if ERREUR :
146     MESSAGE += "Pb in homard_exec"
147     break
148   #
149   # B. Test of the results
150   #
151   N_REP_TEST_FILE = N_ITER_TEST_FILE
152   DESTROY_DIR = not DEBUG
153   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
154   #
155   break
156 #
157 if ERREUR:
158   raise Exception(MESSAGE)
159 #
160 #
161 if salome.sg.hasDesktop():
162   salome.sg.updateObjBrowser()
163   iparameters.getSession().restoreVisualState(1)
164