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 boundaries
76 # ==========================
77 # Creation of the discrete boundary boundary_1
78 boundary_1 = HOMARD.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
80 # Creation of the hypotheses
81 # ==========================
82 # Creation of the hypothesis 1
83 hyponame_1 = "hypo_" + TEST_NAME + "_1"
84 print "-------- Creation of the hypothesis", hyponame_1
85 hypo_test_2_1 = HOMARD.CreateHypothesis(hyponame_1)
86 hypo_test_2_1.SetUnifRefinUnRef(1)
87 hypo_test_2_1.AddGroup('EG')
88 hypo_test_2_1.AddGroup('BANDE')
89 print hyponame_1, " : zones utilisées :", hypo_test_2_1.GetZones()
90 print hyponame_1, " : champ utilisé :", hypo_test_2_1.GetFieldName()
91 print hyponame_1, " : composantes utilisées :", hypo_test_2_1.GetComps()
92 if ( len (hypo_test_2_1.GetFieldName()) > 0 ) :
93 print ".. caractéristiques de l'adaptation :", hypo_test_2_1.GetField()
95 # Creation of the hypothesis 2
96 hyponame_2 = "hypo_" + TEST_NAME + "_2"
97 print "-------- Creation of the hypothesis", hyponame_2
98 hypo_test_2_2 = HOMARD.CreateHypothesis(hyponame_2)
99 hypo_test_2_2.SetUnifRefinUnRef(1)
100 hypo_test_2_2.AddGroup('M_D')
101 print hyponame_2, " : zones utilisées :", hypo_test_2_2.GetZones()
102 print hyponame_2, " : champ utilisé :", hypo_test_2_2.GetFieldName()
103 print hyponame_2, " : composantes utilisées :", hypo_test_2_2.GetComps()
104 if ( len (hypo_test_2_2.GetFieldName()) > 0 ) :
105 print ".. caractéristiques de l'adaptation :", hypo_test_2_2.GetField()
107 # Creation of the cases
108 # =====================
109 # Creation of the case
110 casename = "case_" + TEST_NAME
111 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
112 case_test_2 = HOMARD.CreateCase(casename, 'PLAQUE_0', mesh_file)
113 case_test_2.SetDirName(DIRCASE)
114 case_test_2.AddBoundaryGroup('internal_boundary', '')
116 # Creation of the iterations
117 # ==========================
118 # Creation of the iteration 1
119 iter_name = "I_" + TEST_NAME + "_1"
120 iter_test_2_1 = case_test_2.NextIteration(iter_name)
121 iter_test_2_1.SetMeshName('PLAQUE_1')
122 iter_test_2_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
123 iter_test_2_1.AssociateHypo(hyponame_1)
124 error = iter_test_2_1.Compute(1, 1)
129 # Creation of the iteration 2
130 iter_name = "I_" + TEST_NAME + "_2"
131 iter_test_2_2 = iter_test_2_1.NextIteration(iter_name)
132 iter_test_2_2.SetMeshName('PLAQUE_2')
133 iter_test_2_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
134 iter_test_2_2.AssociateHypo(hyponame_1)
135 error = iter_test_2_2.Compute(1, 1)
140 # Creation of the iteration 3
141 iter_name = "I_" + TEST_NAME + "_3"
142 iter_test_2_3 = iter_test_2_2.NextIteration(iter_name)
143 iter_test_2_3.SetMeshName('PLAQUE_3')
144 iter_test_2_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
145 iter_test_2_3.AssociateHypo(hyponame_2)
146 error = iter_test_2_3.Compute(1, 1)
151 # Creation of the schema YACS
152 # ===========================
153 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
154 scriptfile = os.path.normpath(scriptfile)
156 yacs_test_2 = case_test_2.CreateYACSSchema("YACS_test_2", scriptfile, dirname, mesh_file)
157 yacs_test_2.SetMaxIter(4)
158 yacs_test_2.SetType(1)
159 filexml = os.path.join(DIRCASE, 'yacs_test_2.xml')
160 error = yacs_test_2.WriteOnFile(filexml)
169 #========================================================================
171 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
172 assert HOMARD is not None, "Impossible to load homard engine"
173 HOMARD.SetLanguageShort("fr")
175 # Exec of HOMARD-SALOME
178 ERROR = homard_exec(salome.myStudy)
180 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
181 except Exception, eee:
182 raise Exception('Pb in homard_exec: '+eee.message)
184 # Test of the results
186 N_REP_TEST_FILE = N_ITER_TEST_FILE
187 DESTROY_DIR = not DEBUG
188 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
190 if salome.sg.hasDesktop():
191 salome.sg.updateObjBrowser(1)
192 iparameters.getSession().restoreVisualState(1)