Salome HOME
29595c1aa6b586bd32f2d56ab702ea862495b099
[modules/homard.git] / src / tests / Test / tutorial_2.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_2 associe au tutorial 2
23 """
24 __revision__ = "V4.04"
25
26 #========================================================================
27 TEST_NAME = "tutorial_2"
28 DEBUG = False
29 N_ITER_TEST_FILE = 2
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, 2, -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, verbose=False):
65   """
66 Python script for HOMARD
67   """
68   erreur = 0
69   message = ""
70   #
71   while not erreur :
72     #
73     HOMARD.SetCurrentStudy(salome.myStudy)
74     #
75     # Creation des zones
76     # ==================
77     if verbose :
78       print(". Zones")
79     # Box "Zone_12_0"
80     zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
81     #
82     # Sphere "Zone_12_1"
83     zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
84     #
85     # Box "Zone_12_2"
86     zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
87     #
88     # Hypotheses
89     # ==========
90     if verbose :
91       print(". Hypothèses")
92     # Hypothese "hypo_2"
93     # ==================
94     hypo_2 = HOMARD.CreateHypothesis('hypo_2')
95     hypo_2.AddZone('Zone_12_1', 1)
96     hypo_2.AddZone('Zone_12_0', 1)
97     #
98     # Hypothese "hypo_2_bis"
99     # ======================
100     hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
101     hypo_2_bis.AddZone('Zone_12_0', -1)
102     hypo_2_bis.AddZone('Zone_12_2', 1)
103     #
104     # Cas
105     # ===
106     if verbose :
107       print(". Cas")
108     le_cas = HOMARD.CreateCase('case_2', nom, ficmed)
109     le_cas.SetDirName(DIRCASE)
110     #
111     # Itérations
112     # ==========
113     if verbose :
114       option = 2
115     else :
116       option = 1
117     if verbose :
118       print(". Itérations")
119     #
120     # Iteration "iter_2_1"
121     # ====================
122     iter_2_1 = le_cas.NextIteration('iter_2_1')
123     iter_2_1.SetMeshName('M_1')
124     iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
125     iter_2_1.AssociateHypo('hypo_2')
126     erreur = iter_2_1.Compute(1, option)
127     if erreur :
128       break
129     #
130     # Iteration "iter_2_2"
131     # ====================
132     iter_2_2 = iter_2_1.NextIteration('iter_2_2')
133     iter_2_2.SetMeshName('M_2')
134     iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
135     iter_2_2.AssociateHypo('hypo_2_bis')
136     erreur = iter_2_2.Compute(1, option)
137     if erreur :
138       break
139   #
140     break
141   #
142   if erreur :
143     message += "Erreur au calcul de l'itération %d" % erreur
144   #
145   return erreur, message
146 #
147 #==========================  Fin de la fonction ==================================
148 #
149 ERREUR = 0
150 MESSAGE = ""
151 while not ERREUR :
152   #
153   # A. Exec of HOMARD-SALOME
154   #
155   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
156   assert HOMARD is not None, "Impossible to load homard engine"
157   HOMARD.SetLanguageShort("fr")
158 #
159   FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
160   try:
161     ERREUR, MESSAGE = homard_exec("MZERO", FICMED, DEBUG)
162   except RuntimeError as eee:
163     ERREUR = 2
164     MESSAGE = str(eee.message)
165   #
166   if ERREUR :
167     MESSAGE += "Pb in homard_exec"
168     break
169   #
170   # B. Test of the results
171   #
172   N_REP_TEST_FILE = N_ITER_TEST_FILE
173   DESTROY_DIR = not DEBUG
174   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
175   #
176   break
177 #
178 if ERREUR:
179   raise Exception(MESSAGE)
180 #
181 # ==================================
182 gzip_gunzip(DATA_TUTORIAL, 2, 1)
183 # ==================================
184 #
185 if salome.sg.hasDesktop():
186   salome.sg.updateObjBrowser(True)
187   iparameters.getSession().restoreVisualState(1)
188