Salome HOME
Merge branch 'V7_dev'
[modules/homard.git] / src / tests / Test / test_2.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_2
23 """
24 __revision__ = "V3.1"
25
26 #========================================================================
27 TEST_NAME = "test_2"
28 DEBUG = False
29 N_ITER_TEST_FILE = 3
30 #========================================================================
31 import os
32 import tempfile
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 remove_dir
44 from test_util import test_results
45 # Repertoire des donnees du test
46 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
47 REP_DATA = os.path.normpath(REP_DATA)
48 # Repertoire des resultats
49 if DEBUG :
50   DIRCASE = os.path.join("/tmp", TEST_NAME)
51   if ( os.path.isdir(DIRCASE) ) :
52     remove_dir(DIRCASE)
53   os.mkdir(DIRCASE)
54 else :
55   DIRCASE = tempfile.mkdtemp()
56 # ==================================
57
58 salome.salome_init()
59 import iparameters
60 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
61 IPAR.append("AP_MODULES_LIST", "Homard")
62 #
63 #========================================================================
64 #========================================================================
65 def homard_exec(theStudy):
66   """
67 Python script for HOMARD
68   """
69   error = 0
70 #
71   while not error :
72   #
73     HOMARD.SetCurrentStudy(theStudy)
74   #
75   # Creation of the boundaries
76   # ==========================
77   # Creation of the discrete boundary boundary_1
78     boundary_1 = HOMARD.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
79   #
80   # Creation of the hypotheses
81   # ==========================
82   # Creation of the hypothesis 1
83     hyponame_1 = "hypo_" + TEST_NAME + "_1"
84     print "-------- Creation of the hypothesis", hyponame_1
85     hypo_test_2_1 = HOMARD.CreateHypothesis(hyponame_1)
86     hypo_test_2_1.SetUnifRefinUnRef(1)
87     hypo_test_2_1.AddGroup('EG')
88     hypo_test_2_1.AddGroup('BANDE')
89     print hyponame_1, " : zones utilisées :", hypo_test_2_1.GetZones()
90     print hyponame_1, " : champ utilisé :", hypo_test_2_1.GetFieldName()
91     print hyponame_1, " : composantes utilisées :", hypo_test_2_1.GetComps()
92     if ( len (hypo_test_2_1.GetFieldName()) > 0 ) :
93       print ".. caractéristiques de l'adaptation :", hypo_test_2_1.GetField()
94
95   # Creation of the hypothesis 2
96     hyponame_2 = "hypo_" + TEST_NAME + "_2"
97     print "-------- Creation of the hypothesis", hyponame_2
98     hypo_test_2_2 = HOMARD.CreateHypothesis(hyponame_2)
99     hypo_test_2_2.SetUnifRefinUnRef(1)
100     hypo_test_2_2.AddGroup('M_D')
101     print hyponame_2, " : zones utilisées :", hypo_test_2_2.GetZones()
102     print hyponame_2, " : champ utilisé :", hypo_test_2_2.GetFieldName()
103     print hyponame_2, " : composantes utilisées :", hypo_test_2_2.GetComps()
104     if ( len (hypo_test_2_2.GetFieldName()) > 0 ) :
105       print ".. caractéristiques de l'adaptation :", hypo_test_2_2.GetField()
106   #
107   # Creation of the cases
108   # =====================
109     # Creation of the case
110     mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
111     case_test_2 = HOMARD.CreateCase(TEST_NAME, 'PLAQUE_0', mesh_file)
112     case_test_2.SetDirName(DIRCASE)
113     case_test_2.AddBoundaryGroup('internal_boundary', '')
114   #
115   # Creation of the iterations
116   # ==========================
117   # Creation of the iteration 1
118     iter_name = "I_" + TEST_NAME + "_1"
119     iter_test_2_1 = case_test_2.NextIteration(iter_name)
120     iter_test_2_1.SetMeshName('PLAQUE_1')
121     iter_test_2_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
122     iter_test_2_1.AssociateHypo(hyponame_1)
123     error = iter_test_2_1.Compute(1, 1)
124     if error :
125       error = 1
126       break
127
128   # Creation of the iteration 2
129     iter_name = "I_" + TEST_NAME + "_2"
130     iter_test_2_2 = iter_test_2_1.NextIteration(iter_name)
131     iter_test_2_2.SetMeshName('PLAQUE_2')
132     iter_test_2_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
133     iter_test_2_2.AssociateHypo(hyponame_1)
134     error = iter_test_2_2.Compute(1, 1)
135     if error :
136       error = 2
137       break
138
139   # Creation of the iteration 3
140     iter_name = "I_" + TEST_NAME + "_3"
141     iter_test_2_3 = iter_test_2_2.NextIteration(iter_name)
142     iter_test_2_3.SetMeshName('PLAQUE_3')
143     iter_test_2_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
144     iter_test_2_3.AssociateHypo(hyponame_2)
145     error = iter_test_2_3.Compute(1, 1)
146     if error :
147       error = 3
148       break
149   #
150   # Creation of the schema YACS
151   # ===========================
152     scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
153     scriptfile = os.path.normpath(scriptfile)
154     dirname = DIRCASE
155     yacs_test_2 = case_test_2.CreateYACSSchema("YACS_test_2", scriptfile, dirname, mesh_file)
156     yacs_test_2.SetMaxIter(4)
157     yacs_test_2.SetType(1)
158     filexml = os.path.join(DIRCASE, 'yacs_test_2.xml')
159     error = yacs_test_2.WriteOnFile(filexml)
160     if error :
161       error = 4
162       break
163   #
164     break
165   #
166   return error
167
168 #========================================================================
169
170 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
171 assert HOMARD is not None, "Impossible to load homard engine"
172 HOMARD.SetLanguageShort("fr")
173 #
174 # Exec of HOMARD-SALOME
175 #
176 try :
177   ERROR = homard_exec(salome.myStudy)
178   if ERROR :
179     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
180 except Exception, eee:
181   raise Exception('Pb in homard_exec: '+eee.message)
182 #
183 # Test of the results
184 #
185 N_REP_TEST_FILE = N_ITER_TEST_FILE
186 DESTROY_DIR = not DEBUG
187 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
188 #
189 if salome.sg.hasDesktop():
190   salome.sg.updateObjBrowser(1)
191   iparameters.getSession().restoreVisualState(1)
192