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
26 #========================================================================
30 #========================================================================
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
50 DIRCASE = os.path.join("/tmp", TEST_NAME)
51 if ( os.path.isdir(DIRCASE) ) :
55 DIRCASE = tempfile.mkdtemp()
56 # ==================================
60 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
61 IPAR.append("AP_MODULES_LIST", "Homard")
63 #========================================================================
64 #========================================================================
65 def homard_exec(theStudy):
67 Python script for HOMARD
73 HOMARD.SetCurrentStudy(theStudy)
75 # Creation of the zones
76 # =====================
77 # Creation of the box zone_1_1
78 zone_1_1 = HOMARD.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
80 # Creation of the sphere zone_1_2
81 zone_1_2 = HOMARD.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
83 # Creation of the hypotheses
84 # ==========================
86 dico["1"] = "raffinement"
87 dico["-1"] = "deraffinement"
88 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
89 hyponame_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
90 print "-------- Creation of the hypothesis", hyponame_1
91 hypo_1_1 = HOMARD.CreateHypothesis(hyponame_1)
92 hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
93 hypo_1_1.SetUseComp(0)
94 hypo_1_1.AddComp('ERREST')
95 hypo_1_1.SetRefinThr(3, 10.1)
96 hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
97 hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
98 print hyponame_1, " : champ utilisé :", hypo_1_1.GetFieldName()
99 print hyponame_1, " : composantes utilisées :", hypo_1_1.GetComps()
100 if ( len (hypo_1_1.GetFieldName()) > 0 ) :
101 print ".. caractéristiques de l'adaptation :", hypo_1_1.GetField()
102 print hyponame_1, " : champs interpolés :", hypo_1_1.GetFieldInterps()
103 # Creation of the hypothesis Zones_1_et_2
104 hyponame_2 = "Zones_1_et_2"
105 print "-------- Creation of the hypothesis", hyponame_2
106 zones_1_et_2 = HOMARD.CreateHypothesis(hyponame_2)
107 zones_1_et_2.AddZone('Zone_1_1', 1)
108 zones_1_et_2.AddZone('Zone_1_2', 1)
109 laux = zones_1_et_2.GetZones()
112 for iaux in range(nbzone) :
113 print hyponame_2, " : ", dico[laux[jaux+1]], "sur la zone", laux[jaux]
115 print hyponame_2, " : champ utilisé :", zones_1_et_2.GetFieldName()
116 if ( len (zones_1_et_2.GetFieldName()) > 0 ) :
117 print ".. caractéristiques de l'adaptation :", zones_1_et_2.GetField()
118 print hyponame_2, " : champs interpolés :", zones_1_et_2.GetFieldInterps()
120 # Creation of the cases
121 # =====================
122 # Creation of the case
123 print "-------- Creation of the case", TEST_NAME
124 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
125 case_test_1 = HOMARD.CreateCase(TEST_NAME, 'MAILL', mesh_file)
126 case_test_1.SetDirName(DIRCASE)
128 # Creation of the iterations
129 # ==========================
130 # Creation of the iteration 1
131 iter_name = "I_" + TEST_NAME + "_1"
132 print "-------- Creation of the iteration", iter_name
133 iter_test_1_1 = case_test_1.NextIteration(iter_name)
134 iter_test_1_1.AssociateHypo(hyponame_1)
135 print ". Hypothese :", hyponame_1
136 iter_test_1_1.SetMeshName('M1')
137 iter_test_1_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
138 iter_test_1_1.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.00.med'))
139 iter_test_1_1.SetTimeStepRank(1, 1)
140 iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
141 iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
142 print ". Instants d'interpolation :", iter_test_1_1.GetFieldInterpsTimeStepRank()
143 error = iter_test_1_1.Compute(1, 1)
148 # Creation of the iteration 2
149 iter_name = "I_" + TEST_NAME + "_2"
150 print "-------- Creation of the iteration", iter_name
151 iter_test_1_2 = iter_test_1_1.NextIteration(iter_name)
152 iter_test_1_2.AssociateHypo(hyponame_1)
153 print ". Hypothese :", hyponame_1
154 iter_test_1_2.SetMeshName('M2')
155 iter_test_1_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
156 iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.01.med'))
157 iter_test_1_2.SetTimeStepRank(1, 1)
158 iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
159 iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
160 print ". Instants d'interpolation :", iter_test_1_2.GetFieldInterpsTimeStepRank()
161 error = iter_test_1_2.Compute(1, 1)
166 # Creation of the iteration 3
167 iter_name = "I_" + TEST_NAME + "_3"
168 print "-------- Creation of the iteration", iter_name
169 iter_test_1_3 = iter_test_1_2.NextIteration(iter_name)
170 iter_test_1_3.AssociateHypo(hyponame_2)
171 print ". Hypothese :", hyponame_2
172 iter_test_1_3.SetMeshName('M3')
173 iter_test_1_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
174 iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.02.med'))
175 print ". Instants d'interpolation :", iter_test_1_3.GetFieldInterpsTimeStepRank()
176 error = iter_test_1_3.Compute(1, 1)
181 # Creation of the schema YACS
182 # ===========================
183 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
184 scriptfile = os.path.normpath(scriptfile)
186 yacs_test_1 = case_test_1.CreateYACSSchema("YACS_test_1", scriptfile, dirname, mesh_file)
187 error = yacs_test_1.Write()
196 #========================================================================
198 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
199 assert HOMARD is not None, "Impossible to load homard engine"
200 HOMARD.SetLanguageShort("fr")
202 # Exec of HOMARD-SALOME
205 ERROR = homard_exec(salome.myStudy)
207 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
208 except Exception, eee:
209 raise Exception('Pb in homard_exec: '+eee.message)
211 # Test of the results
213 N_REP_TEST_FILE = N_ITER_TEST_FILE
214 DESTROY_DIR = not DEBUG
215 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
217 if salome.sg.hasDesktop():
218 salome.sg.updateObjBrowser(1)
219 iparameters.getSession().restoreVisualState(1)