1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014 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
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.mktemp()
47 # ==================================
52 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
53 ipar.append("AP_MODULES_LIST", "Homard")
55 #========================================================================
56 #========================================================================
57 def homard_exec(theStudy):
59 Python script for HOMARD
65 homard.SetCurrentStudy(theStudy)
67 # Creation of the zones
68 # =====================
69 # Creation of the box Zone_1_1
70 Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
72 # Creation of the sphere Zone_1_2
73 Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
75 # Creation of the hypotheses
76 # ==========================
77 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
78 HypoName_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
79 print "-------- Creation of the hypothesis", HypoName_1
80 Hypo_1_1 = homard.CreateHypothesis(HypoName_1)
81 Hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
82 Hypo_1_1.SetUseComp(0)
83 Hypo_1_1.AddComp('ERREST')
84 Hypo_1_1.SetRefinThr(3, 10.1)
85 Hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
86 Hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
87 print HypoName_1, " : zones utilisées :", Hypo_1_1.GetZones()
88 print HypoName_1, " : champ utilisé :", Hypo_1_1.GetFieldName()
89 print HypoName_1, " : composantes utilisées :", Hypo_1_1.GetComps()
90 if ( len (Hypo_1_1.GetFieldName()) > 0 ) :
91 print ".. caractéristiques de l'adaptation :", Hypo_1_1.GetField()
92 print HypoName_1, " : champs interpolés :", Hypo_1_1.GetFieldInterps()
93 # Creation of the hypothesis Zones_1_et_2
94 HypoName_2 = "Zones_1_et_2"
95 print "-------- Creation of the hypothesis", HypoName_2
96 Zones_1_et_2 = homard.CreateHypothesis(HypoName_2)
97 Zones_1_et_2.AddZone('Zone_1_1', 1)
98 Zones_1_et_2.AddZone('Zone_1_2', 1)
99 print HypoName_2, " : zones utilisées :", Zones_1_et_2.GetZones()
100 print HypoName_2, " : champ utilisé :", Zones_1_et_2.GetFieldName()
101 if ( len (Zones_1_et_2.GetFieldName()) > 0 ) :
102 print ".. caractéristiques de l'adaptation :", Zones_1_et_2.GetField()
103 print HypoName_2, " : champs interpolés :", Zones_1_et_2.GetFieldInterps()
105 # Creation of the cases
106 # =====================
107 # Creation of the case
108 CaseName = "Case_" + Test_Name
109 print "-------- Creation of the case", CaseName
110 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
111 Case_test_1 = homard.CreateCase(CaseName, 'MAILL', MeshFile)
112 Case_test_1.SetDirName(dircase)
113 Case_test_1.SetConfType(1)
115 # Creation of the iterations
116 # ==========================
117 # Creation of the iteration 1
118 IterName = "I_" + Test_Name + "_1"
119 print "-------- Creation of the iteration", IterName
120 Iter_test_1_1 = Case_test_1.NextIteration(IterName)
121 Iter_test_1_1.AssociateHypo(HypoName_1)
122 print ". Hypothese :", HypoName_1
123 Iter_test_1_1.SetMeshName('M1')
124 Iter_test_1_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
125 Iter_test_1_1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
126 Iter_test_1_1.SetTimeStepRank(1, 1)
127 Iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
128 Iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
129 print ". Instants d'interpolation :", Iter_test_1_1.GetFieldInterpsTimeStepRank()
130 error = Iter_test_1_1.Compute(1, 1)
135 # Creation of the iteration 2
136 IterName = "I_" + Test_Name + "_2"
137 print "-------- Creation of the iteration", IterName
138 Iter_test_1_2 = Iter_test_1_1.NextIteration(IterName)
139 Iter_test_1_2.AssociateHypo(HypoName_1)
140 print ". Hypothese :", HypoName_1
141 Iter_test_1_2.SetMeshName('M2')
142 Iter_test_1_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
143 Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
144 Iter_test_1_2.SetTimeStepRank(1, 1)
145 Iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
146 Iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
147 print ". Instants d'interpolation :", Iter_test_1_2.GetFieldInterpsTimeStepRank()
148 error = Iter_test_1_2.Compute(1, 1)
153 # Creation of the iteration 3
154 IterName = "I_" + Test_Name + "_3"
155 print "-------- Creation of the iteration", IterName
156 Iter_test_1_3 = Iter_test_1_2.NextIteration(IterName)
157 Iter_test_1_3.AssociateHypo(HypoName_2)
158 print ". Hypothese :", HypoName_2
159 Iter_test_1_3.SetMeshName('M3')
160 Iter_test_1_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
161 Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.02.med'))
162 print ". Instants d'interpolation :", Iter_test_1_3.GetFieldInterpsTimeStepRank()
163 error = Iter_test_1_3.Compute(1, 1)
168 # Creation of the schema YACS
169 # ===========================
170 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
171 ScriptFile = os.path.normpath(ScriptFile)
173 YACS_test_1 = Case_test_1.CreateYACSSchema("YACS_test_1", ScriptFile, DirName, MeshFile)
174 error = YACS_test_1.Write()
183 #========================================================================
185 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
186 assert homard is not None, "Impossible to load homard engine"
187 homard.SetLanguageShort("fr")
189 # Exec of HOMARD-SALOME
192 error_main = homard_exec(salome.myStudy)
194 raise Exception('Pb in homard_exec at iteration %d' %error_main )
196 raise Exception('Pb in homard_exec: '+e.message)
198 # Test of the results
200 n_rep_test_file = n_iter_test_file
201 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file)
203 if salome.sg.hasDesktop():
204 salome.sg.updateObjBrowser(1)
205 iparameters.getSession().restoreVisualState(1)