Salome HOME
Merge remote-tracking branch 'origin/V8_3_BR' into gdd/python3_dev
[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__ = "V3.1"
25
26 #========================================================================
27 TEST_NAME = "tutorial_3"
28 DEBUG = False
29 N_ITER_TEST_FILE = 2
30 #========================================================================
31 import os
32 import tempfile
33 import sys
34 import HOMARD
35 import salome
36 #
37 # ==================================
38 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des scripts utilitaires
40 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
41 REP_PYTHON = os.path.normpath(REP_PYTHON)
42 sys.path.append(REP_PYTHON)
43 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des donnees du test
46 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
47 REP_DATA = os.path.normpath(REP_DATA)
48 # Repertoire des resultats
49 if DEBUG :
50   DIRCASE = os.path.join("/tmp", TEST_NAME)
51   if ( os.path.isdir(DIRCASE) ) :
52     remove_dir(DIRCASE)
53   os.mkdir(DIRCASE)
54 else :
55   DIRCASE = tempfile.mkdtemp()
56 # Repertoire des donnees du tutorial
57 DATA_TUTORIAL = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
58 DATA_TUTORIAL = os.path.normpath(DATA_TUTORIAL)
59 sys.path.append(DATA_TUTORIAL)
60 from tutorial_util import gzip_gunzip
61 # ==================================
62 gzip_gunzip(DATA_TUTORIAL, 3, -1)
63 # ==================================
64
65 salome.salome_init()
66 import iparameters
67 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
68 IPAR.append("AP_MODULES_LIST", "Homard")
69 #
70 #========================================================================
71 #========================================================================
72 def homard_exec(theStudy):
73   """
74 Python script for HOMARD
75   """
76   #
77   HOMARD.SetCurrentStudy(theStudy)
78   #
79   # Hypothese "hypo_0vers1"
80   # =======================
81   hypo_0vers1 = HOMARD.CreateHypothesis('hypo_0vers1')
82   # Characterization of the field
83   hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
84   hypo_0vers1.SetUseComp(0)
85   hypo_0vers1.AddComp('ERREST          ')
86   hypo_0vers1.SetRefinThr(3, 1.0)
87   hypo_0vers1.SetTypeFieldInterp(2)
88   hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
89   hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
90   #
91   # Hypothese "hypo_1vers2"
92   # =======================
93   hypo_1vers2 = HOMARD.CreateHypothesis('hypo_1vers2')
94   # Characterization of the field
95   hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
96   hypo_1vers2.SetUseComp(0)
97   hypo_1vers2.AddComp('ERREST          ')
98   hypo_1vers2.SetRefinThr(3, 1.5)
99   hypo_1vers2.SetUnRefThr(3, 6.)
100   hypo_1vers2.SetTypeFieldInterp(2)
101   hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
102   hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
103   #
104   # Hypothese "hypo_1vers2_bis"
105   # ===========================
106   hypo_1vers2_bis = HOMARD.CreateHypothesis('hypo_1vers2_bis')
107   # Characterization of the field
108   hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
109   hypo_1vers2_bis.SetUseComp(1)
110   hypo_1vers2_bis.AddComp('DX')
111   hypo_1vers2_bis.AddComp('DY')
112   hypo_1vers2_bis.AddComp('DZ')
113   hypo_1vers2_bis.SetRefinThr(1, 0.0001)
114   hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
115   hypo_1vers2_bis.SetTypeFieldInterp(0)
116   #
117   # Cas
118   # ===
119   case_3 = HOMARD.CreateCase('case_3', 'G_0', DATA_TUTORIAL+'/tutorial_3.00.med')
120   case_3.SetDirName(DIRCASE)
121   #
122   # Iteration "iter_3_1"
123   # ====================
124   iter_3_1 = case_3.NextIteration('iter_3_1')
125   iter_3_1.SetMeshName('H_1')
126   iter_3_1.SetMeshFile(DIRCASE+'/maill.01.med')
127   iter_3_1.SetFieldFile(DATA_TUTORIAL+'/tutorial_3.00.med')
128   iter_3_1.SetTimeStepRank( 1, 1)
129   iter_3_1.AssociateHypo('hypo_0vers1')
130   error = iter_3_1.Compute(1, 2)
131   #
132   # Iteration "iter_3_2"
133   # ====================
134   iter_3_2 = iter_3_1.NextIteration('iter_3_2')
135   iter_3_2.SetMeshName('H_2')
136   iter_3_2.SetMeshFile(DIRCASE+'/maill.02.med')
137   iter_3_2.SetFieldFile(DATA_TUTORIAL+'/tutorial_3.01.med')
138   iter_3_2.SetTimeStepRank(1, 1)
139   iter_3_2.AssociateHypo('hypo_1vers2')
140   error = iter_3_2.Compute(1, 2)
141   #
142   # Iteration "iter_3_2_bis"
143   # ========================
144   iter_3_2_bis = iter_3_1.NextIteration('iter_3_2_bis')
145   iter_3_2_bis.SetMeshName('H_2_bis')
146   iter_3_2_bis.SetMeshFile(DIRCASE+'/maill.02.bis.med')
147   iter_3_2_bis.SetFieldFile(DATA_TUTORIAL+'/tutorial_3.01.med')
148   iter_3_2_bis.SetTimeStepRank(1, 1)
149   iter_3_2_bis.AssociateHypo('hypo_1vers2_bis')
150   error = iter_3_2_bis.Compute(1, 2)
151   #
152   return error
153
154 #========================================================================
155
156 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
157 assert HOMARD is not None, "Impossible to load HOMARD engine"
158 HOMARD.SetLanguageShort("fr")
159 #
160 # Exec of HOMARD-SALOME
161 #
162 try :
163   ERROR = homard_exec(salome.myStudy)
164   if ERROR :
165     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
166 except Exception as eee:
167   raise Exception('Pb in homard_exec: '+eee.message)
168 #
169 # Test of the results
170 #
171 N_REP_TEST_FILE = 3
172 DESTROY_DIR = not DEBUG
173 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
174 #
175 # ==================================
176 gzip_gunzip(DATA_TUTORIAL, 3, 1)
177 # ==================================
178 #
179 if salome.sg.hasDesktop():
180   salome.sg.updateObjBrowser(True)
181   iparameters.getSession().restoreVisualState(1)
182