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 boundaries
68 # ==========================
69 # Creation of the discrete boundary Boundary_1
70 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
72 # Creation of the hypotheses
73 # ==========================
74 # Creation of the hypothesis 1
75 HypoName_1 = "Hypo_" + Test_Name + "_1"
76 print "-------- Creation of the hypothesis", HypoName_1
77 Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
78 Hypo_test_2_1.SetUnifRefinUnRef(1)
79 Hypo_test_2_1.AddGroup('EG')
80 Hypo_test_2_1.AddGroup('BANDE')
81 print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
82 print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
83 print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
84 if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
85 print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
87 # Creation of the hypothesis 2
88 HypoName_2 = "Hypo_" + Test_Name + "_2"
89 print "-------- Creation of the hypothesis", HypoName_2
90 Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
91 Hypo_test_2_2.SetUnifRefinUnRef(1)
92 Hypo_test_2_2.AddGroup('M_D')
93 print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
94 print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
95 print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
96 if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
97 print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
99 # Creation of the cases
100 # =====================
101 # Creation of the case
102 CaseName = "Case_" + Test_Name
103 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
104 Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
105 Case_test_2.SetDirName(dircase)
106 Case_test_2.SetConfType(1)
107 Case_test_2.AddBoundaryGroup('internal_boundary', '')
109 # Creation of the iterations
110 # ==========================
111 # Creation of the iteration 1
112 IterName = "I_" + Test_Name + "_1"
113 Iter_test_2_1 = Case_test_2.NextIteration(IterName)
114 Iter_test_2_1.SetMeshName('PLAQUE_1')
115 Iter_test_2_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
116 Iter_test_2_1.AssociateHypo(HypoName_1)
117 error = Iter_test_2_1.Compute(1, 1)
122 # Creation of the iteration 2
123 IterName = "I_" + Test_Name + "_2"
124 Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
125 Iter_test_2_2.SetMeshName('PLAQUE_2')
126 Iter_test_2_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
127 Iter_test_2_2.AssociateHypo(HypoName_1)
128 error = Iter_test_2_2.Compute(1, 1)
133 # Creation of the iteration 3
134 IterName = "I_" + Test_Name + "_3"
135 Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
136 Iter_test_2_3.SetMeshName('PLAQUE_3')
137 Iter_test_2_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
138 Iter_test_2_3.AssociateHypo(HypoName_2)
139 error = Iter_test_2_3.Compute(1, 1)
144 # Creation of the schema YACS
145 # ===========================
146 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
147 ScriptFile = os.path.normpath(ScriptFile)
149 YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
150 YACS_test_2.SetType(1)
151 filexml = os.path.join(dircase, 'YACS_test_2.xml')
152 error = YACS_test_2.WriteOnFile(filexml)
161 #========================================================================
163 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
164 assert homard is not None, "Impossible to load homard engine"
165 homard.SetLanguageShort("fr")
167 # Exec of HOMARD-SALOME
170 error_main = homard_exec(salome.myStudy)
172 raise Exception('Pb in homard_exec at iteration %d' %error_main )
174 raise Exception('Pb in homard_exec: '+e.message)
176 # Test of the results
178 n_rep_test_file = n_iter_test_file
179 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, True)
181 if salome.sg.hasDesktop():
182 salome.sg.updateObjBrowser(1)
183 iparameters.getSession().restoreVisualState(1)