Salome HOME
version 5_1_4 HOMARD_SRC
[modules/homard.git] / src / HOMARD_SCRIPTS / test_homard.py
1 import salome
2 salome.salome_init()
3
4 import HOMARD
5
6 #
7 # initialize engine
8 #
9 homard = salome.lcc.FindOrLoadComponent("FactoryServer", "HOMARD")
10
11 def test_save(fname):
12     #
13     # create new study
14     #
15     study = salome.myStudyManager.NewStudy("HOMARD")
16     homard.SetCurrentStudy(study)
17     #
18     # create case
19     #
20     case_1 = homard.CreateCas("Case 1")
21     case_1.SetNomDir("/tmp/homard")
22     case_1.SetTypeConf(12)
23     case_1.SetBoiteEnglobante([1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.10,10.11])
24     #
25     # create hypothesis 1
26     #
27     hypo_1 = homard.CreateHypothese("Hypothesis 1")
28     hypo_1.SetTypeAdapRaffDera(2,3,4)
29     hypo_1.SetField("Field 1", 12, 3.45, 67, 23.343)
30     hypo_1.AjoutComposant("Comp 1")
31     hypo_1.AjoutComposant("Comp 2")
32     hypo_1.AjoutComposant("Comp 3")
33     #
34     # create hypothesis 2
35     #
36     hypo_2 = homard.CreateHypothese("Hypothesis 2")
37     hypo_2.SetTypeAdapRaffDera(20,30,40)
38     hypo_2.SetField("Field 2", 5, 12.67223, 900, 6.5434)
39     hypo_2.AjoutComposant("Comp 123")
40     #
41     # create iteration 1
42     #
43     iter_1 = homard.CreateIteration("Iteration 1")
44     iter_1.SetEtat(True)
45     iter_1.SetNumIter(56)
46     iter_1.SetMeshFile("/aaaa/bbbb/AAAAA.med")
47     iter_1.SetNomMesh("My Mesh")
48     iter_1.SetField("Field 1", 42, 522)
49     #
50     # create iteration 2
51     #
52     iter_2 = homard.CreateIteration("Iteration 2")
53     iter_2.SetEtat(False)
54     iter_2.SetNumIter(57)
55     iter_2.SetMeshFile("/cccc/cccc/asd.med")
56     iter_2.SetNomMesh("MeshXZY")
57     iter_2.SetField("Field 2", 22222, 50000)
58     #
59     # create iteration 3 (not published)
60     #
61     iter_3 = homard.CreateIteration("Iteration 3")
62     iter_3.SetEtat(True)
63     iter_3.SetNumIter(666)
64     iter_3.SetMeshFile("/not/assigned/iteration/file.med")
65     iter_3.SetNomMesh("NOT ASSIGNED")
66     iter_3.SetField("Field XXX", 999, -1)
67     #
68     # create zone 1
69     #
70     zone_1 = homard.CreateZone("Zone 1")
71     zone_1.SetBox(1.,2.,3.,4.,5.,6.)
72     zone_1.SetTypeZone(5454)
73     #
74     # create zone 2
75     #
76     zone_2 = homard.CreateZone("Zone 2")
77     zone_2.SetSphere(12.3, 3.4, .56, 6.5)
78     zone_2.SetTypeZone(6545)
79     #
80     # associate objects
81     #
82     homard.AssocieCasIteration("Case 1", "Iteration 1")
83     homard.AssocieCasIteration("Case 1", "Iteration 2")
84     homard.AssocieHypoIteration("Iteration 1", "Hypothesis 1")
85     homard.AssocieHypoZone("Zone 1", "Hypothesis 1")
86     homard.AssocieHypoIteration("Iteration 2", "Hypothesis 2")
87     homard.AssocieHypoZone("Zone 2", "Hypothesis 2")
88     homard.AssocieIterationIteration("Iteration 1", "Iteration 2")
89     #
90     # save study
91     #
92     salome.myStudyManager.SaveAs(fname, study, 0)
93     #
94     # close study
95     #
96     salome.myStudyManager.Close(study)
97     #
98     pass
99
100 def test_load(fname):
101     #
102     # load study and 
103     #
104     study = salome.myStudyManager.Open(fname)
105     #
106     # load homard data
107     #
108     comp = study.FindComponent("HOMARD")
109     builder = study.NewBuilder()
110     builder.LoadWith(comp, homard)
111     #
112     # dump study id
113     #
114     print homard.GetCurrentStudy()._get_StudyId()
115     #
116     # dump case 1
117     #
118     case_1 = homard.GetCas("Case 1")
119     print "Case: ",          case_1.GetNomCas()
120     print "-> nom dir:",     case_1.GetNomDir()
121     print "-> type conf:",   case_1.GetTypeConf()
122     print "-> boite:",       case_1.GetBoiteEnglobante()
123     print "---"
124     #
125     # dump hypothesis 1
126     #
127     hypo_1 = homard.GetHypothesis("Hypothesis 1")
128     print "Hypothesis: ",    hypo_1.GetNomHypothesis()
129     print "-> type:",        hypo_1.GetTypeAdapRaffDera()
130     print "-> field name:",  hypo_1.GetFieldName()
131     print "-> composants:",  hypo_1.GetComposants()
132     print "-> zones:",       hypo_1.GetZones()
133     print "---"
134     #
135     # dump hypothesis 2
136     #
137     hypo_2 = homard.GetHypothesis("Hypothesis 2")
138     print "Hypothesis: ",    hypo_2.GetNomHypothesis()
139     print "-> type:",        hypo_2.GetTypeAdapRaffDera()
140     print "-> field name:",  hypo_2.GetFieldName()
141     print "-> composants:",  hypo_2.GetComposants()
142     print "-> zones:",       hypo_2.GetZones()
143     print "---"
144     #
145     # dump zone 1
146     #
147     zone_1 = homard.GetZone("Zone 1")
148     print "Zone: ",          zone_1.GetNomZone()
149     print "-> type zone:",   zone_1.GetTypeZone()
150     print "-> shere:",       zone_1.GetSphere()
151     print "-> box:",         zone_1.GetBox()
152     print "-> hypotheses:",  zone_1.GetHypo()
153     print "---"
154     #
155     # dump zone 1
156     #
157     zone_2 = homard.GetZone("Zone 2")
158     print "Zone: ",          zone_2.GetNomZone()
159     print "-> type zone:",   zone_2.GetTypeZone()
160     print "-> shere:",       zone_2.GetSphere()
161     print "-> box:",         zone_2.GetBox()
162     print "-> hypotheses:",  zone_2.GetHypo()
163     print "---"
164     #
165     # dump iteration 1
166     #
167     iter_1 = homard.GetIteration("Iteration 1")
168     print "Iteration: ",     iter_1.GetNomIter()
169     print "-> etat:",        iter_1.GetEtat()
170     print "-> num iter:",    iter_1.GetNumIter()
171     print "-> nom mesh:",    iter_1.GetNomMesh()
172     print "-> mesh file:",   iter_1.GetMeshFile()
173     print "-> field:",       iter_1.GetFieldFileName()
174     print "-> time step:",   iter_1.GetTimeStep()
175     print "-> rank:",        iter_1.GetRank()
176     print "-> parent iter:", iter_1.GetIterParent()
177     print "-> hypothesis:",  iter_1.GetNomHypo()
178     print "-> case:",        iter_1.GetNomCas()
179     print "---"
180     #
181     # dump iteration 2
182     #
183     iter_2 = homard.GetIteration("Iteration 2")
184     print "Iteration: ",     iter_2.GetNomIter()
185     print "-> etat:",        iter_2.GetEtat()
186     print "-> num iter:",    iter_2.GetNumIter()
187     print "-> nom mesh:",    iter_2.GetNomMesh()
188     print "-> mesh file:",   iter_2.GetMeshFile()
189     print "-> field:",       iter_2.GetFieldFileName()
190     print "-> time step:",   iter_2.GetTimeStep()
191     print "-> rank:",        iter_2.GetRank()
192     print "-> parent iter:", iter_2.GetIterParent()
193     print "-> hypothesis:",  iter_2.GetNomHypo()
194     print "-> case:",        iter_2.GetNomCas()
195     print "---"
196     #
197     # dump iteration 3
198     #
199     iter_3 = homard.GetIteration("Iteration 3")
200     print "Iteration: ",     iter_3.GetNomIter()
201     print "-> etat:",        iter_3.GetEtat()
202     print "-> num iter:",    iter_3.GetNumIter()
203     print "-> nom mesh:",    iter_3.GetNomMesh()
204     print "-> mesh file:",   iter_3.GetMeshFile()
205     print "-> field:",       iter_3.GetFieldFileName()
206     print "-> time step:",   iter_3.GetTimeStep()
207     print "-> rank:",        iter_3.GetRank()
208     print "-> parent iter:", iter_3.GetIterParent()
209     print "-> hypothesis:",  iter_3.GetNomHypo()
210     print "-> case:",        iter_3.GetNomCas()
211     print "---"
212
213 # test file name
214 filename = "/tmp/save_homard.hdf"
215
216 # run tests
217 test_save(filename)
218 test_load(filename)