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
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.mkdtemp()
46 # ==================================
50 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
51 ipar.append("AP_MODULES_LIST", "Homard")
53 #========================================================================
54 #========================================================================
55 def homard_exec(theStudy):
57 Python script for HOMARD
63 homard.SetCurrentStudy(theStudy)
65 # Creation of the boundaries
66 # ==========================
67 # Creation of the discrete boundary Boundary_1
68 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
70 # Creation of the hypotheses
71 # ==========================
72 # Creation of the hypothesis 1
73 HypoName_1 = "Hypo_" + Test_Name + "_1"
74 print "-------- Creation of the hypothesis", HypoName_1
75 Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
76 Hypo_test_2_1.SetUnifRefinUnRef(1)
77 Hypo_test_2_1.AddGroup('EG')
78 Hypo_test_2_1.AddGroup('BANDE')
79 print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
80 print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
81 print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
82 if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
83 print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
85 # Creation of the hypothesis 2
86 HypoName_2 = "Hypo_" + Test_Name + "_2"
87 print "-------- Creation of the hypothesis", HypoName_2
88 Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
89 Hypo_test_2_2.SetUnifRefinUnRef(1)
90 Hypo_test_2_2.AddGroup('M_D')
91 print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
92 print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
93 print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
94 if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
95 print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
97 # Creation of the cases
98 # =====================
99 # Creation of the case
100 CaseName = "Case_" + Test_Name
101 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
102 Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
103 Case_test_2.SetDirName(dircase)
104 Case_test_2.SetConfType(1)
105 Case_test_2.AddBoundaryGroup('internal_boundary', '')
107 # Creation of the iterations
108 # ==========================
109 # Creation of the iteration 1
110 IterName = "I_" + Test_Name + "_1"
111 Iter_test_2_1 = Case_test_2.NextIteration(IterName)
112 Iter_test_2_1.SetMeshName('PLAQUE_1')
113 Iter_test_2_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
114 Iter_test_2_1.AssociateHypo(HypoName_1)
115 error = Iter_test_2_1.Compute(1, 1)
120 # Creation of the iteration 2
121 IterName = "I_" + Test_Name + "_2"
122 Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
123 Iter_test_2_2.SetMeshName('PLAQUE_2')
124 Iter_test_2_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
125 Iter_test_2_2.AssociateHypo(HypoName_1)
126 error = Iter_test_2_2.Compute(1, 1)
131 # Creation of the iteration 3
132 IterName = "I_" + Test_Name + "_3"
133 Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
134 Iter_test_2_3.SetMeshName('PLAQUE_3')
135 Iter_test_2_3.SetMeshFile(os.path.join(dircase, 'maill.03.med'))
136 Iter_test_2_3.AssociateHypo(HypoName_2)
137 error = Iter_test_2_3.Compute(1, 1)
142 # Creation of the schema YACS
143 # ===========================
144 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
145 ScriptFile = os.path.normpath(ScriptFile)
147 YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
148 YACS_test_2.SetMaxIter(4)
149 YACS_test_2.SetType(1)
150 filexml = os.path.join(dircase, 'YACS_test_2.xml')
151 error = YACS_test_2.WriteOnFile(filexml)
160 #========================================================================
162 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
163 assert homard is not None, "Impossible to load homard engine"
164 homard.SetLanguageShort("fr")
166 # Exec of HOMARD-SALOME
169 error_main = homard_exec(salome.myStudy)
171 raise Exception('Pb in homard_exec at iteration %d' %error_main )
173 raise Exception('Pb in homard_exec: '+e.message)
175 # Test of the results
177 n_rep_test_file = n_iter_test_file
178 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, True)
180 if salome.sg.hasDesktop():
181 salome.sg.updateObjBrowser(1)
182 iparameters.getSession().restoreVisualState(1)