1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Python script for HOMARD
22 Copyright EDF-R&D 2010, 2014
23 Test test_11 associe au tutorial 3
27 #========================================================================
30 #========================================================================
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 test_results
44 # Repertoire des resultats
45 dircase = tempfile.mkdtemp()
46 # Repertoire des donnees du tutorial
47 data_dir = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
48 data_dir = os.path.normpath(data_dir)
49 sys.path.append(data_dir)
50 from tutorial_util import gzip_gunzip
51 # ==================================
52 gzip_gunzip(data_dir, 3, -1)
53 # ==================================
57 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
58 ipar.append("AP_MODULES_LIST", "Homard")
60 #========================================================================
61 #========================================================================
62 def homard_exec(theStudy):
64 Python script for HOMARD
67 homard.SetCurrentStudy(theStudy)
69 # Hypothese "Hypo_0vers1"
70 # =======================
71 Hypo_0vers1 = homard.CreateHypothesis('Hypo_0vers1')
72 # Characterization of the field
73 Hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
74 Hypo_0vers1.SetUseComp(0)
75 Hypo_0vers1.AddComp('ERREST ')
76 Hypo_0vers1.SetRefinThr(3, 1.0)
77 Hypo_0vers1.SetTypeFieldInterp(2)
78 Hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
79 Hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
81 # Hypothese "Hypo_1vers2"
82 # =======================
83 Hypo_1vers2 = homard.CreateHypothesis('Hypo_1vers2')
84 # Characterization of the field
85 Hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
86 Hypo_1vers2.SetUseComp(0)
87 Hypo_1vers2.AddComp('ERREST ')
88 Hypo_1vers2.SetRefinThr(3, 1.5)
89 Hypo_1vers2.SetUnRefThr(3, 6.)
90 Hypo_1vers2.SetTypeFieldInterp(2)
91 Hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
92 Hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
94 # Hypothese "Hypo_1vers2_bis"
95 # ===========================
96 Hypo_1vers2_bis = homard.CreateHypothesis('Hypo_1vers2_bis')
97 # Characterization of the field
98 Hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
99 Hypo_1vers2_bis.SetUseComp(1)
100 Hypo_1vers2_bis.AddComp('DX')
101 Hypo_1vers2_bis.AddComp('DY')
102 Hypo_1vers2_bis.AddComp('DZ')
103 Hypo_1vers2_bis.SetRefinThr(1, 0.0001)
104 Hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
105 Hypo_1vers2_bis.SetTypeFieldInterp(0)
109 Case_3 = homard.CreateCase('Case_3', 'G_0', data_dir+'/tutorial_3.00.med')
110 Case_3.SetDirName(dircase)
112 # Iteration "Iter_3_1"
113 # ====================
114 Iter_3_1 = Case_3.NextIteration('Iter_3_1')
115 Iter_3_1.SetMeshName('H_1')
116 Iter_3_1.SetMeshFile(dircase+'/maill.01.med')
117 Iter_3_1.SetFieldFile(data_dir+'/tutorial_3.00.med')
118 Iter_3_1.SetTimeStepRank( 1, 1)
119 Iter_3_1.AssociateHypo('Hypo_0vers1')
120 error = Iter_3_1.Compute(1, 2)
122 # Iteration "Iter_3_2"
123 # ====================
124 Iter_3_2 = Iter_3_1.NextIteration('Iter_3_2')
125 Iter_3_2.SetMeshName('H_2')
126 Iter_3_2.SetMeshFile(dircase+'/maill.02.med')
127 Iter_3_2.SetFieldFile(data_dir+'/tutorial_3.01.med')
128 Iter_3_2.SetTimeStepRank(1, 1)
129 Iter_3_2.AssociateHypo('Hypo_1vers2')
130 error = Iter_3_2.Compute(1, 2)
132 # Iteration "Iter_3_2_bis"
133 # ========================
134 Iter_3_2_bis = Iter_3_1.NextIteration('Iter_3_2_bis')
135 Iter_3_2_bis.SetMeshName('H_2_bis')
136 Iter_3_2_bis.SetMeshFile(dircase+'/maill.02.bis.med')
137 Iter_3_2_bis.SetFieldFile(data_dir+'/tutorial_3.01.med')
138 Iter_3_2_bis.SetTimeStepRank(1, 1)
139 Iter_3_2_bis.AssociateHypo('Hypo_1vers2_bis')
140 error = Iter_3_2_bis.Compute(1, 2)
144 #========================================================================
146 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
147 assert homard is not None, "Impossible to load homard engine"
148 homard.SetLanguageShort("fr")
150 # Exec of HOMARD-SALOME
153 error_main = homard_exec(salome.myStudy)
155 raise Exception('Pb in homard_exec at iteration %d' %error_main )
157 raise Exception('Pb in homard_exec: '+e.message)
159 # Test of the results
162 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file)
164 # ==================================
165 gzip_gunzip(data_dir, 3, 1)
166 # ==================================
168 if salome.sg.hasDesktop():
169 salome.sg.updateObjBrowser(1)
170 iparameters.getSession().restoreVisualState(1)