Salome HOME
c207e2777f0a2073416820f8ed654e0e599f1620
[modules/homard.git] / src / tests / Test / tutorial_3.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_3 associe au tutorial 3
23 """
24 __revision__ = "V4.03"
25
26 #========================================================================
27 TEST_NAME = "tutorial_3"
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, 3, -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     # Hypothese "hypo_0vers1"
78     # =======================
79     hypo_0vers1 = HOMARD.CreateHypothesis('hypo_0vers1')
80     # Characterization of the field
81     hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
82     hypo_0vers1.SetUseComp(0)
83     hypo_0vers1.AddComp('ERREST          ')
84     hypo_0vers1.SetRefinThr(3, 1.0)
85     hypo_0vers1.SetTypeFieldInterp(2)
86     hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
87     hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
88     #
89     # Hypothese "hypo_1vers2"
90     # =======================
91     hypo_1vers2 = HOMARD.CreateHypothesis('hypo_1vers2')
92     # Characterization of the field
93     hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
94     hypo_1vers2.SetUseComp(0)
95     hypo_1vers2.AddComp('ERREST          ')
96     hypo_1vers2.SetRefinThr(3, 1.5)
97     hypo_1vers2.SetUnRefThr(3, 6.)
98     hypo_1vers2.SetTypeFieldInterp(2)
99     hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
100     hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
101     #
102     # Hypothese "hypo_1vers2_bis"
103     # ===========================
104     hypo_1vers2_bis = HOMARD.CreateHypothesis('hypo_1vers2_bis')
105     # Characterization of the field
106     hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
107     hypo_1vers2_bis.SetUseComp(1)
108     hypo_1vers2_bis.AddComp('DX')
109     hypo_1vers2_bis.AddComp('DY')
110     hypo_1vers2_bis.AddComp('DZ')
111     hypo_1vers2_bis.SetRefinThr(1, 0.0001)
112     hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
113     hypo_1vers2_bis.SetTypeFieldInterp(0)
114     #
115     # Cas
116     # ===
117     if verbose :
118       print(". Cas")
119     le_cas = HOMARD.CreateCase('case_3', nom, ficmed)
120     le_cas.SetDirName(DIRCASE)
121     #
122     # Itérations
123     # ==========
124     if verbose :
125       option = 2
126     else :
127       option = 1
128     if verbose :
129       print(". Itérations")
130     # Iteration "iter_3_1"
131     # ====================
132     iter_3_1 = le_cas.NextIteration('iter_3_1')
133     iter_3_1.SetMeshName('H_1')
134     iter_3_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
135     iter_3_1.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.00.med"))
136     iter_3_1.SetTimeStepRank( 1, 1)
137     iter_3_1.AssociateHypo('hypo_0vers1')
138     erreur = iter_3_1.Compute(1, option)
139     if erreur :
140       break
141     #
142     # Iteration "iter_3_2"
143     # ====================
144     iter_3_2 = iter_3_1.NextIteration('iter_3_2')
145     iter_3_2.SetMeshName('H_2')
146     iter_3_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
147     iter_3_2.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
148     iter_3_2.SetTimeStepRank(1, 1)
149     iter_3_2.AssociateHypo('hypo_1vers2')
150     erreur = iter_3_2.Compute(1, option)
151     if erreur :
152       break
153     #
154     # Iteration "iter_3_2_bis"
155     # ========================
156     iter_3_2_bis = iter_3_1.NextIteration('iter_3_2_bis')
157     iter_3_2_bis.SetMeshName('H_2_bis')
158     iter_3_2_bis.SetMeshFile(os.path.join(DIRCASE, "maill.02.bis.med"))
159     iter_3_2_bis.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
160     iter_3_2_bis.SetTimeStepRank(1, 1)
161     iter_3_2_bis.AssociateHypo('hypo_1vers2_bis')
162     erreur = iter_3_2_bis.Compute(1, option)
163     if erreur :
164       break
165   #
166     break
167   #
168   if erreur :
169     message += "Erreur au calcul de l'itération %d" % erreur
170   #
171   return erreur, message
172 #
173 #==========================  Fin de la fonction ==================================
174 #
175 ERREUR = 0
176 MESSAGE = ""
177 while not ERREUR :
178   #
179   # A. Exec of HOMARD-SALOME
180   #
181   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
182   assert HOMARD is not None, "Impossible to load homard engine"
183   HOMARD.SetLanguageShort("fr")
184 #
185   FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
186   try:
187     ERREUR, MESSAGE = homard_exec("G_0", FICMED, DEBUG)
188   except RuntimeError as eee:
189     ERREUR = 2
190     MESSAGE = str(eee.message)
191   #
192   if ERREUR :
193     MESSAGE += "Pb in homard_exec"
194     break
195   #
196   # B. Test of the results
197   #
198   N_REP_TEST_FILE = 3
199   DESTROY_DIR = not DEBUG
200   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
201   #
202   break
203 #
204 if ERREUR:
205   raise Exception(MESSAGE)
206 #
207 # ==================================
208 gzip_gunzip(DATA_TUTORIAL, 3, 1)
209 # ==================================
210 #
211 if salome.sg.hasDesktop():
212   salome.sg.updateObjBrowser(True)
213   iparameters.getSession().restoreVisualState(1)
214