]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_13.py
Salome HOME
Changement des noms de zones et commentaires
[modules/homard.git] / tests / test_13.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015  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 test_13 associe au tutorial 3
23 """
24 __revision__ = "V2.3"
25
26 #========================================================================
27 Test_Name = "test_13"
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 pathHomard = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des donnees du test
40 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
41 Rep_Test = os.path.normpath(Rep_Test)
42 sys.path.append(Rep_Test)
43 from test_util import remove_dir
44 from test_util import test_results
45 # Repertoire des resultats
46 if debug :
47   dircase = os.path.join("/tmp", Test_Name)
48   if ( os.path.isdir(dircase) ) :
49     remove_dir(dircase)
50   os.mkdir(dircase)
51 else :
52   dircase = tempfile.mkdtemp()
53 # Repertoire des donnees du tutorial
54 data_dir = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
55 data_dir = os.path.normpath(data_dir)
56 sys.path.append(data_dir)
57 from tutorial_util import gzip_gunzip
58 # ==================================
59 gzip_gunzip(data_dir, 3, -1)
60 # ==================================
61
62 salome.salome_init()
63 import iparameters
64 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
65 ipar.append("AP_MODULES_LIST", "Homard")
66 #
67 #========================================================================
68 #========================================================================
69 def homard_exec(theStudy):
70   """
71 Python script for HOMARD
72   """
73   #
74   homard.SetCurrentStudy(theStudy)
75   #
76   # Hypothese "Hypo_0vers1"
77   # =======================
78   Hypo_0vers1 = homard.CreateHypothesis('Hypo_0vers1')
79   # Characterization of the field
80   Hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
81   Hypo_0vers1.SetUseComp(0)
82   Hypo_0vers1.AddComp('ERREST          ')
83   Hypo_0vers1.SetRefinThr(3, 1.0)
84   Hypo_0vers1.SetTypeFieldInterp(2)
85   Hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
86   Hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
87   #
88   # Hypothese "Hypo_1vers2"
89   # =======================
90   Hypo_1vers2 = homard.CreateHypothesis('Hypo_1vers2')
91   # Characterization of the field
92   Hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
93   Hypo_1vers2.SetUseComp(0)
94   Hypo_1vers2.AddComp('ERREST          ')
95   Hypo_1vers2.SetRefinThr(3, 1.5)
96   Hypo_1vers2.SetUnRefThr(3, 6.)
97   Hypo_1vers2.SetTypeFieldInterp(2)
98   Hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
99   Hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
100   #
101   # Hypothese "Hypo_1vers2_bis"
102   # ===========================
103   Hypo_1vers2_bis = homard.CreateHypothesis('Hypo_1vers2_bis')
104   # Characterization of the field
105   Hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
106   Hypo_1vers2_bis.SetUseComp(1)
107   Hypo_1vers2_bis.AddComp('DX')
108   Hypo_1vers2_bis.AddComp('DY')
109   Hypo_1vers2_bis.AddComp('DZ')
110   Hypo_1vers2_bis.SetRefinThr(1, 0.0001)
111   Hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
112   Hypo_1vers2_bis.SetTypeFieldInterp(0)
113   #
114   # Cas
115   # ===
116   Case_3 = homard.CreateCase('Case_3', 'G_0', data_dir+'/tutorial_3.00.med')
117   Case_3.SetDirName(dircase)
118   #
119   # Iteration "Iter_3_1"
120   # ====================
121   Iter_3_1 = Case_3.NextIteration('Iter_3_1')
122   Iter_3_1.SetMeshName('H_1')
123   Iter_3_1.SetMeshFile(dircase+'/maill.01.med')
124   Iter_3_1.SetFieldFile(data_dir+'/tutorial_3.00.med')
125   Iter_3_1.SetTimeStepRank( 1, 1)
126   Iter_3_1.AssociateHypo('Hypo_0vers1')
127   error = Iter_3_1.Compute(1, 2)
128   #
129   # Iteration "Iter_3_2"
130   # ====================
131   Iter_3_2 = Iter_3_1.NextIteration('Iter_3_2')
132   Iter_3_2.SetMeshName('H_2')
133   Iter_3_2.SetMeshFile(dircase+'/maill.02.med')
134   Iter_3_2.SetFieldFile(data_dir+'/tutorial_3.01.med')
135   Iter_3_2.SetTimeStepRank(1, 1)
136   Iter_3_2.AssociateHypo('Hypo_1vers2')
137   error = Iter_3_2.Compute(1, 2)
138   #
139   # Iteration "Iter_3_2_bis"
140   # ========================
141   Iter_3_2_bis = Iter_3_1.NextIteration('Iter_3_2_bis')
142   Iter_3_2_bis.SetMeshName('H_2_bis')
143   Iter_3_2_bis.SetMeshFile(dircase+'/maill.02.bis.med')
144   Iter_3_2_bis.SetFieldFile(data_dir+'/tutorial_3.01.med')
145   Iter_3_2_bis.SetTimeStepRank(1, 1)
146   Iter_3_2_bis.AssociateHypo('Hypo_1vers2_bis')
147   error = Iter_3_2_bis.Compute(1, 2)
148   #
149   return error
150
151 #========================================================================
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 # Exec of HOMARD-SALOME
158 #
159 try :
160   error_main = homard_exec(salome.myStudy)
161   if error_main :
162     raise Exception('Pb in homard_exec at iteration %d' %error_main )
163 except Exception, e:
164   raise Exception('Pb in homard_exec: '+e.message)
165 #
166 # Test of the results
167 #
168 n_rep_test_file = 3
169 destroy_dir = not debug
170 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
171 #
172 # ==================================
173 gzip_gunzip(data_dir, 3, 1)
174 # ==================================
175 #
176 if salome.sg.hasDesktop():
177   salome.sg.updateObjBrowser(1)
178   iparameters.getSession().restoreVisualState(1)
179