Salome HOME
98ec51b79ef255117b049feea285aaf53279258e
[modules/homard.git] / src / tests / Test / tutorial_2.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2021  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.07"
25
26 #========================================================================
27 TEST_NAME = "tutorial_2"
28 DEBUG = False
29 N_ITER_TEST_FILE = 2
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 test_results
42 # ==================================
43 # Répertoires pour ce test
44 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
45 # ==================================
46 #
47 import salome
48 salome.salome_init()
49 import HOMARD
50 #
51 import iparameters
52 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
53 IPAR.append("AP_MODULES_LIST", "Homard")
54 #
55 #
56 #========================= Debut de la fonction ==================================
57 #
58 def homard_exec(nom, ficmed, verbose=False):
59   """
60 Python script for HOMARD
61   """
62   erreur = 0
63   message = ""
64   #
65   while not erreur :
66     #
67   #  HOMARD.UpdateStudy()
68     #
69     # Creation des zones
70     # ==================
71     if verbose :
72       print(". Zones")
73     # Box "Zone_12_0"
74     zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
75     #
76     # Sphere "Zone_12_1"
77     zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
78     #
79     # Box "Zone_12_2"
80     zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
81     #
82     # Hypotheses
83     # ==========
84     if verbose :
85       print(". Hypothèses")
86     # Hypothese "hypo_2"
87     # ==================
88     hypo_2 = HOMARD.CreateHypothesis('hypo_2')
89     hypo_2.AddZone('Zone_12_1', 1)
90     hypo_2.AddZone('Zone_12_0', 1)
91     #
92     # Hypothese "hypo_2_bis"
93     # ======================
94     hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
95     hypo_2_bis.AddZone('Zone_12_0', -1)
96     hypo_2_bis.AddZone('Zone_12_2', 1)
97     #
98     # Cas
99     # ===
100     if verbose :
101       print(". Cas")
102     le_cas = HOMARD.CreateCase('case_2', nom, ficmed)
103     le_cas.SetDirName(DIRCASE)
104     #
105     # Itérations
106     # ==========
107     if verbose :
108       option = 2
109     else :
110       option = 1
111     if verbose :
112       print(". Itérations")
113     #
114     # Iteration "iter_2_1"
115     # ====================
116     iter_2_1 = le_cas.NextIteration('iter_2_1')
117     iter_2_1.SetMeshName('M_1')
118     iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
119     iter_2_1.AssociateHypo('hypo_2')
120     erreur = iter_2_1.Compute(1, option)
121     if erreur :
122       break
123     #
124     # Iteration "iter_2_2"
125     # ====================
126     iter_2_2 = iter_2_1.NextIteration('iter_2_2')
127     iter_2_2.SetMeshName('M_2')
128     iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
129     iter_2_2.AssociateHypo('hypo_2_bis')
130     erreur = iter_2_2.Compute(1, option)
131     if erreur :
132       break
133   #
134     break
135   #
136   if erreur :
137     message += "Erreur au calcul de l'itération %d" % erreur
138   #
139   return erreur, message
140 #
141 #==========================  Fin de la fonction ==================================
142 #
143 ERREUR = 0
144 MESSAGE = ""
145 while not ERREUR :
146   #
147   # A. Exec of HOMARD-SALOME
148   #
149   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
150   assert HOMARD is not None, "Impossible to load homard engine"
151   HOMARD.SetLanguageShort("fr")
152 #
153   FICMED = os.path.join(REP_DATA, TEST_NAME+".00.med")
154   try:
155     ERREUR, MESSAGE = homard_exec("MZERO", FICMED, DEBUG)
156   except RuntimeError as eee:
157     ERREUR = 2
158     MESSAGE = str(eee.message)
159   #
160   if ERREUR :
161     MESSAGE += "Pb in homard_exec"
162     break
163   #
164   # B. Test of the results
165   #
166   N_REP_TEST_FILE = N_ITER_TEST_FILE
167   DESTROY_DIR = not DEBUG
168   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
169   #
170   break
171 #
172 if ERREUR:
173   raise Exception(MESSAGE)
174 #
175 if salome.sg.hasDesktop():
176   salome.sg.updateObjBrowser()
177   iparameters.getSession().restoreVisualState(1)
178