1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016 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 #========================================================================
67 Python script for HOMARD
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 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
111 case_test_2 = HOMARD.CreateCase(TEST_NAME, 'PLAQUE_0', mesh_file)
112 case_test_2.SetDirName(DIRCASE)
113 case_test_2.AddBoundaryGroup('internal_boundary', '')
115 # Creation of the iterations
116 # ==========================
117 # Creation of the iteration 1
118 iter_name = "I_" + TEST_NAME + "_1"
119 iter_test_2_1 = case_test_2.NextIteration(iter_name)
120 iter_test_2_1.SetMeshName('PLAQUE_1')
121 iter_test_2_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
122 iter_test_2_1.AssociateHypo(hyponame_1)
123 error = iter_test_2_1.Compute(1, 1)
128 # Creation of the iteration 2
129 iter_name = "I_" + TEST_NAME + "_2"
130 iter_test_2_2 = iter_test_2_1.NextIteration(iter_name)
131 iter_test_2_2.SetMeshName('PLAQUE_2')
132 iter_test_2_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
133 iter_test_2_2.AssociateHypo(hyponame_1)
134 error = iter_test_2_2.Compute(1, 1)
139 # Creation of the iteration 3
140 iter_name = "I_" + TEST_NAME + "_3"
141 iter_test_2_3 = iter_test_2_2.NextIteration(iter_name)
142 iter_test_2_3.SetMeshName('PLAQUE_3')
143 iter_test_2_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
144 iter_test_2_3.AssociateHypo(hyponame_2)
145 error = iter_test_2_3.Compute(1, 1)
150 # Creation of the schema YACS
151 # ===========================
152 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
153 scriptfile = os.path.normpath(scriptfile)
155 yacs_test_2 = case_test_2.CreateYACSSchema("YACS_test_2", scriptfile, dirname, mesh_file)
156 yacs_test_2.SetMaxIter(4)
157 yacs_test_2.SetType(1)
158 filexml = os.path.join(DIRCASE, 'yacs_test_2.xml')
159 error = yacs_test_2.WriteOnFile(filexml)
168 #========================================================================
170 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
171 assert HOMARD is not None, "Impossible to load homard engine"
172 HOMARD.SetLanguageShort("fr")
174 # Exec of HOMARD-SALOME
177 ERROR = homard_exec()
179 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
180 except Exception, eee:
181 raise Exception('Pb in homard_exec: '+eee.message)
183 # Test of the results
185 N_REP_TEST_FILE = N_ITER_TEST_FILE
186 DESTROY_DIR = not DEBUG
187 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
189 if salome.sg.hasDesktop():
190 salome.sg.updateObjBrowser()
191 iparameters.getSession().restoreVisualState(1)