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