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