Salome HOME
3318dd52f05a510e73988458a50748d043634a85
[modules/homard.git] / src / tests / Test / test_3.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21 Python script for HOMARD
22 Test test_3
23 """
24 __revision__ = "V4.02"
25
26 #========================================================================
27 TEST_NAME = "test_3"
28 DEBUG = False
29 N_BOUCLE = 2
30 N_ITER_TEST_FILE = 2
31 #========================================================================
32 import os
33 import tempfile
34 import sys
35 import HOMARD
36 import salome
37 #
38 # ==================================
39 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
40 # Repertoire des scripts utilitaires
41 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
42 REP_PYTHON = os.path.normpath(REP_PYTHON)
43 sys.path.append(REP_PYTHON)
44 from test_util import remove_dir
45 from test_util import test_results
46 # Repertoire des donnees du test
47 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
48 REP_DATA = os.path.normpath(REP_DATA)
49 # Repertoire des resultats
50 if DEBUG :
51   DIRCASE = os.path.join("/tmp", TEST_NAME)
52   if ( os.path.isdir(DIRCASE) ) :
53     remove_dir(DIRCASE)
54   os.mkdir(DIRCASE)
55 else :
56   DIRCASE = tempfile.mkdtemp(prefix=TEST_NAME)
57 # ==================================
58
59 salome.salome_init()
60 import iparameters
61 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
62 IPAR.append("AP_MODULES_LIST", "Homard")
63 #
64 #========================================================================
65 #========================================================================
66 def homard_exec(theStudy):
67   """
68 Python script for HOMARD
69   """
70   error = 0
71 #
72   while not error :
73   #
74     HOMARD.SetCurrentStudy(theStudy)
75   #
76   # Creation of the boundaries
77   # ==========================
78   # Creation of the discrete boundary
79     boundary_3_1 = HOMARD.CreateBoundaryDi('courbes', 'COURBES', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
80   #
81   # Creation of the external cylinder
82     boundary_3_2 = HOMARD.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
83   #
84   # Creation of the internal cylinder
85     boundary_3_3 = HOMARD.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
86   #
87   # Creation of the first sphere
88     boundary_3_4 = HOMARD.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
89   #
90   # Creation of the second sphere
91     boundary_3_5 = HOMARD.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
92   #
93   # Creation of the hypotheses
94   # ==========================
95   # Uniform refinement
96     hyponame = "hypo_" + TEST_NAME
97     print("-------- Creation of the hypothesis", hyponame)
98     hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
99     hypo_test_3.SetUnifRefinUnRef(1)
100     print(hyponame, " : zones utilisées :", hypo_test_3.GetZones())
101     print(hyponame, " : champ utilisé :", hypo_test_3.GetFieldName())
102     print(hyponame, " : composantes utilisées :", hypo_test_3.GetComps())
103   #
104     for num in range (N_BOUCLE+1) :
105   #
106       print("-------- num =", num, "--------")
107   #
108   # Creation of the case case_test_3
109   # ===========================
110       if ( num <= 1 ) :
111         print("-------- Creation of the case", TEST_NAME)
112         mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
113         case_test_3 = HOMARD.CreateCase(TEST_NAME, 'MOYEU', mesh_file)
114         case_test_3.SetDirName(DIRCASE)
115         case_test_3.AddBoundary('courbes')
116         case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
117         case_test_3.AddBoundaryGroup('cyl_int', 'INT')
118         case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
119         case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
120   #
121   # Creation of the iterations
122   # ==========================
123   # Creation of the iteration 1
124       iter_name = "I_" + TEST_NAME + "_1"
125       print("-------- Creation of the iteration", iter_name)
126       iter_test_3_1 = case_test_3.NextIteration(iter_name)
127       iter_test_3_1.SetMeshName('MOYEU_1')
128       iter_test_3_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
129       iter_test_3_1.AssociateHypo('hypo_test_3')
130       error = iter_test_3_1.Compute(1, 1)
131       if error :
132         error = 10*num + 1
133         break
134
135   # Creation of the iteration 2
136       iter_name = "I_" + TEST_NAME + "_2"
137       print("-------- Creation of the iteration", iter_name)
138       iter_test_3_2 = iter_test_3_1.NextIteration(iter_name)
139       iter_test_3_2.SetMeshName('MOYEU_2')
140       iter_test_3_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
141       iter_test_3_2.AssociateHypo('hypo_test_3')
142       error = iter_test_3_2.Compute(1, 1)
143       if error :
144         error = 10*num + 2
145         break
146   #
147   # Creation of the schema YACS
148   # ===========================
149       scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
150       scriptfile = os.path.normpath(scriptfile)
151       dirname = DIRCASE
152       yacsname = "YACS_" + TEST_NAME
153       print("-------- Creation of the schema", yacsname)
154       yacs_test_3 = case_test_3.CreateYACSSchema(yacsname, scriptfile, dirname, mesh_file)
155       yacs_test_3.SetType(2)
156       yacs_test_3.SetMaxIter(2)
157       error = yacs_test_3.Write()
158       if error :
159         error = 10*num + 5
160         break
161
162   # Destructions
163   # ============
164   # Destruction of the schema, sauf a la fin
165       if ( num < N_BOUCLE ) :
166         print("-------- Destruction of the schema", yacs_test_3.GetName())
167         error = yacs_test_3.Delete(1)
168         if error :
169           error = 10*num + 6
170           break
171   # After the first loop, the case is deleted, except the final mesh files
172   # All the iterations are deleted
173       if ( num == 0 ) :
174         print("-------- Destruction of the case", case_test_3.GetName())
175         error = case_test_3.Delete(0)
176         if error :
177           break
178   # After the second loop, the iterations are deleted, with the final mesh files
179       elif ( num == 1 ) :
180   # Recursive destruction of the iterations
181         print("-------- Recursive destruction of the iteration", iter_test_3_1.GetName())
182         error = iter_test_3_1.Delete(1)
183         if error :
184           error = 10*num + 3
185           break
186   # Destruction and creation of the hypothese
187         if ( num == 1 ) :
188           print("-------- Destruction of the hypothese", hypo_test_3.GetName())
189           error = hypo_test_3.Delete()
190           if error :
191             error = 10*num + 4
192             break
193           hyponame = "hypo_test_3"
194           print("-------- Creation of the hypothesis", hyponame)
195           hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
196           hypo_test_3.SetUnifRefinUnRef(1)
197   #
198     break
199   #
200   return error
201
202 #========================================================================
203
204 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
205 assert HOMARD is not None, "Impossible to load homard engine"
206 HOMARD.SetLanguageShort("fr")
207 #
208 # Exec of HOMARD-SALOME
209 #
210 try :
211   ERROR = homard_exec(salome.myStudy)
212   if ERROR :
213     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
214 except Exception as eee:
215   raise Exception('Pb in homard_exec: '+eee.message)
216 #
217 # Test of the results
218 #
219 N_REP_TEST_FILE = N_ITER_TEST_FILE*N_BOUCLE
220 DESTROY_DIR = not DEBUG
221 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
222 #
223 if salome.sg.hasDesktop():
224   salome.sg.updateObjBrowser(True)
225   iparameters.getSession().restoreVisualState(1)
226