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 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 remove_dir
44 from test_util import test_results
45 # Repertoire des resultats
47 dircase = os.path.join("/tmp", Test_Name)
48 if ( os.path.isdir(dircase) ) :
52 dircase = tempfile.mkdtemp()
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
70 homard.SetCurrentStudy(theStudy)
72 # Creation of the boundaries
73 # ==========================
74 # Creation of the discrete boundary Boundary_1
75 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
77 # Creation of the hypotheses
78 # ==========================
79 # Creation of the hypothesis 1
80 HypoName_1 = "Hypo_" + Test_Name + "_1"
81 print "-------- Creation of the hypothesis", HypoName_1
82 Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
83 Hypo_test_2_1.SetUnifRefinUnRef(1)
84 Hypo_test_2_1.AddGroup('EG')
85 Hypo_test_2_1.AddGroup('BANDE')
86 print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
87 print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
88 print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
89 if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
90 print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
92 # Creation of the hypothesis 2
93 HypoName_2 = "Hypo_" + Test_Name + "_2"
94 print "-------- Creation of the hypothesis", HypoName_2
95 Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
96 Hypo_test_2_2.SetUnifRefinUnRef(1)
97 Hypo_test_2_2.AddGroup('M_D')
98 print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
99 print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
100 print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
101 if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
102 print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
104 # Creation of the cases
105 # =====================
106 # Creation of the case
107 CaseName = "Case_" + Test_Name
108 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
109 Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
110 Case_test_2.SetDirName(dircase)
111 Case_test_2.AddBoundaryGroup('internal_boundary', '')
113 # Creation of the iterations
114 # ==========================
115 # Creation of the iteration 1
116 IterName = "I_" + Test_Name + "_1"
117 Iter_test_2_1 = Case_test_2.NextIteration(IterName)
118 Iter_test_2_1.SetMeshName('PLAQUE_1')
119 Iter_test_2_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
120 Iter_test_2_1.AssociateHypo(HypoName_1)
121 error = Iter_test_2_1.Compute(1, 1)
126 # Creation of the iteration 2
127 IterName = "I_" + Test_Name + "_2"
128 Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
129 Iter_test_2_2.SetMeshName('PLAQUE_2')
130 Iter_test_2_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
131 Iter_test_2_2.AssociateHypo(HypoName_1)
132 error = Iter_test_2_2.Compute(1, 1)
137 # Creation of the iteration 3
138 IterName = "I_" + Test_Name + "_3"
139 Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
140 Iter_test_2_3.SetMeshName('PLAQUE_3')
141 Iter_test_2_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
142 Iter_test_2_3.AssociateHypo(HypoName_2)
143 error = Iter_test_2_3.Compute(1, 1)
148 # Creation of the schema YACS
149 # ===========================
150 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
151 ScriptFile = os.path.normpath(ScriptFile)
153 YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
154 YACS_test_2.SetMaxIter(4)
155 YACS_test_2.SetType(1)
156 filexml = os.path.join(dircase, 'YACS_test_2.xml')
157 error = YACS_test_2.WriteOnFile(filexml)
166 #========================================================================
168 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
169 assert homard is not None, "Impossible to load homard engine"
170 homard.SetLanguageShort("fr")
172 # Exec of HOMARD-SALOME
175 error_main = homard_exec(salome.myStudy)
177 raise Exception('Pb in homard_exec at iteration %d' %error_main )
179 raise Exception('Pb in homard_exec: '+e.message)
181 # Test of the results
183 n_rep_test_file = n_iter_test_file
184 destroy_dir = not debug
185 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
187 if salome.sg.hasDesktop():
188 salome.sg.updateObjBrowser(1)
189 iparameters.getSession().restoreVisualState(1)