]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARD_SCRIPTS/test_homard.py
Salome HOME
Merge from V6_main 01/04/2013
[modules/homard.git] / src / HOMARD_SCRIPTS / test_homard.py
1 # Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 #  File   : Makefile.in
20 #  Author : Nicolas REJNERI, Paul RASCLE
21 #  Modified by : Alexander BORODIN (OCN) - autotools usage
22 #  Module : HOMARD
23
24 import salome
25 salome.salome_init()
26
27 import HOMARD
28
29 #
30 # initialize engine
31 #
32 homard = salome.lcc.FindOrLoadComponent("FactoryServer", "HOMARD")
33
34 def test_save(fname):
35     #
36     # create new study
37     #
38     study = salome.myStudyManager.NewStudy("HOMARD")
39     homard.SetCurrentStudy(study)
40     #
41     # create case
42     #
43     case_1 = homard.CreateCas("Case 1")
44     case_1.SetNomDir("/tmp/homard")
45     case_1.SetTypeConf(12)
46     case_1.SetBoiteEnglobante([1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.10,10.11])
47     #
48     # create hypothesis 1
49     #
50     hypo_1 = homard.CreateHypothese("Hypothesis 1")
51     hypo_1.SetTypeAdapRaffDera(2,3,4)
52     hypo_1.SetField("Field 1", 12, 3.45, 67, 23.343)
53     hypo_1.AjoutComposant("Comp 1")
54     hypo_1.AjoutComposant("Comp 2")
55     hypo_1.AjoutComposant("Comp 3")
56     #
57     # create hypothesis 2
58     #
59     hypo_2 = homard.CreateHypothese("Hypothesis 2")
60     hypo_2.SetTypeAdapRaffDera(20,30,40)
61     hypo_2.SetField("Field 2", 5, 12.67223, 900, 6.5434)
62     hypo_2.AjoutComposant("Comp 123")
63     #
64     # create iteration 1
65     #
66     iter_1 = homard.CreateIteration("Iteration 1")
67     iter_1.SetEtat(True)
68     iter_1.SetNumIter(56)
69     iter_1.SetMeshFile("/aaaa/bbbb/AAAAA.med")
70     iter_1.SetNomMesh("My Mesh")
71     iter_1.SetField("Field 1", 42, 522)
72     #
73     # create iteration 2
74     #
75     iter_2 = homard.CreateIteration("Iteration 2")
76     iter_2.SetEtat(False)
77     iter_2.SetNumIter(57)
78     iter_2.SetMeshFile("/cccc/cccc/asd.med")
79     iter_2.SetNomMesh("MeshXZY")
80     iter_2.SetField("Field 2", 22222, 50000)
81     #
82     # create iteration 3 (not published)
83     #
84     iter_3 = homard.CreateIteration("Iteration 3")
85     iter_3.SetEtat(True)
86     iter_3.SetNumIter(666)
87     iter_3.SetMeshFile("/not/assigned/iteration/file.med")
88     iter_3.SetNomMesh("NOT ASSIGNED")
89     iter_3.SetField("Field XXX", 999, -1)
90     #
91     # create zone 1
92     #
93     zone_1 = homard.CreateZone("Zone 1")
94     zone_1.SetBox(1.,2.,3.,4.,5.,6.)
95     zone_1.SetTypeZone(5454)
96     #
97     # create zone 2
98     #
99     zone_2 = homard.CreateZone("Zone 2")
100     zone_2.SetSphere(12.3, 3.4, .56, 6.5)
101     zone_2.SetTypeZone(6545)
102     #
103     # associate objects
104     #
105     homard.AssocieCasIteration("Case 1", "Iteration 1")
106     homard.AssocieCasIteration("Case 1", "Iteration 2")
107     homard.AssocieHypoIteration("Iteration 1", "Hypothesis 1")
108     homard.AssocieHypoZone("Zone 1", "Hypothesis 1")
109     homard.AssocieHypoIteration("Iteration 2", "Hypothesis 2")
110     homard.AssocieHypoZone("Zone 2", "Hypothesis 2")
111     homard.AssocieIterationIteration("Iteration 1", "Iteration 2")
112     #
113     # save study
114     #
115     salome.myStudyManager.SaveAs(fname, study, 0)
116     #
117     # close study
118     #
119     salome.myStudyManager.Close(study)
120     #
121     pass
122
123 def test_load(fname):
124     #
125     # load study and 
126     #
127     study = salome.myStudyManager.Open(fname)
128     #
129     # load homard data
130     #
131     comp = study.FindComponent("HOMARD")
132     builder = study.NewBuilder()
133     builder.LoadWith(comp, homard)
134     #
135     # dump study id
136     #
137     print homard.GetCurrentStudy()._get_StudyId()
138     #
139     # dump case 1
140     #
141     case_1 = homard.GetCas("Case 1")
142     print "Case: ",          case_1.GetNomCas()
143     print "-> nom dir:",     case_1.GetNomDir()
144     print "-> type conf:",   case_1.GetTypeConf()
145     print "-> boite:",       case_1.GetBoiteEnglobante()
146     print "---"
147     #
148     # dump hypothesis 1
149     #
150     hypo_1 = homard.GetHypothesis("Hypothesis 1")
151     print "Hypothesis: ",    hypo_1.GetNomHypothesis()
152     print "-> type:",        hypo_1.GetTypeAdapRaffDera()
153     print "-> field name:",  hypo_1.GetFieldName()
154     print "-> composants:",  hypo_1.GetComposants()
155     print "-> zones:",       hypo_1.GetZones()
156     print "---"
157     #
158     # dump hypothesis 2
159     #
160     hypo_2 = homard.GetHypothesis("Hypothesis 2")
161     print "Hypothesis: ",    hypo_2.GetNomHypothesis()
162     print "-> type:",        hypo_2.GetTypeAdapRaffDera()
163     print "-> field name:",  hypo_2.GetFieldName()
164     print "-> composants:",  hypo_2.GetComposants()
165     print "-> zones:",       hypo_2.GetZones()
166     print "---"
167     #
168     # dump zone 1
169     #
170     zone_1 = homard.GetZone("Zone 1")
171     print "Zone: ",          zone_1.GetNomZone()
172     print "-> type zone:",   zone_1.GetTypeZone()
173     print "-> shere:",       zone_1.GetSphere()
174     print "-> box:",         zone_1.GetBox()
175     print "-> hypotheses:",  zone_1.GetHypo()
176     print "---"
177     #
178     # dump zone 1
179     #
180     zone_2 = homard.GetZone("Zone 2")
181     print "Zone: ",          zone_2.GetNomZone()
182     print "-> type zone:",   zone_2.GetTypeZone()
183     print "-> shere:",       zone_2.GetSphere()
184     print "-> box:",         zone_2.GetBox()
185     print "-> hypotheses:",  zone_2.GetHypo()
186     print "---"
187     #
188     # dump iteration 1
189     #
190     iter_1 = homard.GetIteration("Iteration 1")
191     print "Iteration: ",     iter_1.GetNomIter()
192     print "-> etat:",        iter_1.GetEtat()
193     print "-> num iter:",    iter_1.GetNumIter()
194     print "-> nom mesh:",    iter_1.GetNomMesh()
195     print "-> mesh file:",   iter_1.GetMeshFile()
196     print "-> field:",       iter_1.GetFieldFileName()
197     print "-> time step:",   iter_1.GetTimeStep()
198     print "-> rank:",        iter_1.GetRank()
199     print "-> parent iter:", iter_1.GetIterParent()
200     print "-> hypothesis:",  iter_1.GetNomHypo()
201     print "-> case:",        iter_1.GetNomCas()
202     print "---"
203     #
204     # dump iteration 2
205     #
206     iter_2 = homard.GetIteration("Iteration 2")
207     print "Iteration: ",     iter_2.GetNomIter()
208     print "-> etat:",        iter_2.GetEtat()
209     print "-> num iter:",    iter_2.GetNumIter()
210     print "-> nom mesh:",    iter_2.GetNomMesh()
211     print "-> mesh file:",   iter_2.GetMeshFile()
212     print "-> field:",       iter_2.GetFieldFileName()
213     print "-> time step:",   iter_2.GetTimeStep()
214     print "-> rank:",        iter_2.GetRank()
215     print "-> parent iter:", iter_2.GetIterParent()
216     print "-> hypothesis:",  iter_2.GetNomHypo()
217     print "-> case:",        iter_2.GetNomCas()
218     print "---"
219     #
220     # dump iteration 3
221     #
222     iter_3 = homard.GetIteration("Iteration 3")
223     print "Iteration: ",     iter_3.GetNomIter()
224     print "-> etat:",        iter_3.GetEtat()
225     print "-> num iter:",    iter_3.GetNumIter()
226     print "-> nom mesh:",    iter_3.GetNomMesh()
227     print "-> mesh file:",   iter_3.GetMeshFile()
228     print "-> field:",       iter_3.GetFieldFileName()
229     print "-> time step:",   iter_3.GetTimeStep()
230     print "-> rank:",        iter_3.GetRank()
231     print "-> parent iter:", iter_3.GetIterParent()
232     print "-> hypothesis:",  iter_3.GetNomHypo()
233     print "-> case:",        iter_3.GetNomCas()
234     print "---"
235
236 # test file name
237 filename = "/tmp/save_homard.hdf"
238
239 # run tests
240 test_save(filename)
241 test_load(filename)