Salome HOME
Update copyrights
[modules/homard.git] / src / tests / Test / tutorial_3.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2019  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.05"
25
26 #========================================================================
27 TEST_NAME = "tutorial_3"
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 get_dir_tutorial
42 from test_util import test_results
43 # ==================================
44 # Répertoires pour ce test
45 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
46 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
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 import salome
55 salome.salome_init()
56 import HOMARD
57 #
58 import iparameters
59 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
60 IPAR.append("AP_MODULES_LIST", "Homard")
61 #
62 #
63 #========================= Debut de la fonction ==================================
64 #
65 def homard_exec(nom, ficmed, verbose=False):
66   """
67 Python script for HOMARD
68   """
69   erreur = 0
70   message = ""
71   #
72   while not erreur :
73     #
74   #  HOMARD.UpdateStudy()
75     #
76     # Hypotheses
77     # ==========
78     if verbose :
79       print(". Hypothèses")
80     # Hypothese "hypo_0vers1"
81     # =======================
82     hypo_0vers1 = HOMARD.CreateHypothesis('hypo_0vers1')
83     # Characterization of the field
84     hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
85     hypo_0vers1.SetUseComp(0)
86     hypo_0vers1.AddComp('ERREST          ')
87     hypo_0vers1.SetRefinThr(3, 1.0)
88     hypo_0vers1.SetTypeFieldInterp(2)
89     hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
90     hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
91     #
92     # Hypothese "hypo_1vers2"
93     # =======================
94     hypo_1vers2 = HOMARD.CreateHypothesis('hypo_1vers2')
95     # Characterization of the field
96     hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
97     hypo_1vers2.SetUseComp(0)
98     hypo_1vers2.AddComp('ERREST          ')
99     hypo_1vers2.SetRefinThr(3, 1.5)
100     hypo_1vers2.SetUnRefThr(3, 6.)
101     hypo_1vers2.SetTypeFieldInterp(2)
102     hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
103     hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
104     #
105     # Hypothese "hypo_1vers2_bis"
106     # ===========================
107     hypo_1vers2_bis = HOMARD.CreateHypothesis('hypo_1vers2_bis')
108     # Characterization of the field
109     hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
110     hypo_1vers2_bis.SetUseComp(1)
111     hypo_1vers2_bis.AddComp('DX')
112     hypo_1vers2_bis.AddComp('DY')
113     hypo_1vers2_bis.AddComp('DZ')
114     hypo_1vers2_bis.SetRefinThr(1, 0.0001)
115     hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
116     hypo_1vers2_bis.SetTypeFieldInterp(0)
117     #
118     # Cas
119     # ===
120     if verbose :
121       print(". Cas")
122     le_cas = HOMARD.CreateCase('case_3', nom, ficmed)
123     le_cas.SetDirName(DIRCASE)
124     #
125     # Itérations
126     # ==========
127     if verbose :
128       option = 2
129     else :
130       option = 1
131     if verbose :
132       print(". Itérations")
133     # Iteration "iter_3_1"
134     # ====================
135     iter_3_1 = le_cas.NextIteration('iter_3_1')
136     iter_3_1.SetMeshName('H_1')
137     iter_3_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
138     iter_3_1.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.00.med"))
139     iter_3_1.SetTimeStepRank( 1, 1)
140     iter_3_1.AssociateHypo('hypo_0vers1')
141     erreur = iter_3_1.Compute(1, option)
142     if erreur :
143       break
144     #
145     # Iteration "iter_3_2"
146     # ====================
147     iter_3_2 = iter_3_1.NextIteration('iter_3_2')
148     iter_3_2.SetMeshName('H_2')
149     iter_3_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
150     iter_3_2.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
151     iter_3_2.SetTimeStepRank(1, 1)
152     iter_3_2.AssociateHypo('hypo_1vers2')
153     erreur = iter_3_2.Compute(1, option)
154     if erreur :
155       break
156     #
157     # Iteration "iter_3_2_bis"
158     # ========================
159     iter_3_2_bis = iter_3_1.NextIteration('iter_3_2_bis')
160     iter_3_2_bis.SetMeshName('H_2_bis')
161     iter_3_2_bis.SetMeshFile(os.path.join(DIRCASE, "maill.02.bis.med"))
162     iter_3_2_bis.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
163     iter_3_2_bis.SetTimeStepRank(1, 1)
164     iter_3_2_bis.AssociateHypo('hypo_1vers2_bis')
165     erreur = iter_3_2_bis.Compute(1, option)
166     if erreur :
167       break
168   #
169     break
170   #
171   if erreur :
172     message += "Erreur au calcul de l'itération %d" % erreur
173   #
174   return erreur, message
175 #
176 #==========================  Fin de la fonction ==================================
177 #
178 ERREUR = 0
179 MESSAGE = ""
180 while not ERREUR :
181   #
182   # A. Exec of HOMARD-SALOME
183   #
184   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
185   assert HOMARD is not None, "Impossible to load homard engine"
186   HOMARD.SetLanguageShort("fr")
187 #
188   FICMED = os.path.join(DATA_TUTORIAL, TEST_NAME+".00.med")
189   try:
190     ERREUR, MESSAGE = homard_exec("G_0", FICMED, DEBUG)
191   except RuntimeError as eee:
192     ERREUR = 2
193     MESSAGE = str(eee.message)
194   #
195   if ERREUR :
196     MESSAGE += "Pb in homard_exec"
197     break
198   #
199   # B. Test of the results
200   #
201   N_REP_TEST_FILE = 3
202   DESTROY_DIR = not DEBUG
203   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
204   #
205   break
206 #
207 if ERREUR:
208   raise Exception(MESSAGE)
209 #
210 # ==================================
211 gzip_gunzip(DATA_TUTORIAL, 3, 1)
212 # ==================================
213
214 if salome.sg.hasDesktop():
215   salome.sg.updateObjBrowser()
216   iparameters.getSession().restoreVisualState(1)
217