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