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