Salome HOME
Copyright update 2021
[modules/homard.git] / src / tests / Test / tutorial_4.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2011-2021  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 """
23 Python script for HOMARD
24 Test tutorial_4 associe au tutorial 4
25 """
26 __revision__ = "V5.05"
27
28 #========================================================================
29 TEST_NAME = "tutorial_4"
30 DEBUG = False
31 N_ITER_TEST_FILE = 3
32 #========================================================================
33 import os
34 import sys
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 get_dir_tutorial
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 DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
49 # ==================================
50 #
51 import salome
52 salome.salome_init()
53 import HOMARD
54 #
55 import iparameters
56 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
57 IPAR.append("AP_MODULES_LIST", "Homard")
58 #
59 #
60 #========================= Debut de la fonction ==================================
61 #
62 def homard_exec(nom, ficmed, xao_file, verbose=True):
63   """
64 Python script for HOMARD
65   """
66   erreur = 0
67   message = ""
68 #
69   while not erreur :
70     #
71   #  HOMARD.UpdateStudy()
72     #
73     # Frontières
74     # ==========
75     if verbose :
76       print(". Frontières")
77     cao_name = "CAO_" + nom
78     la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
79     #
80     # Hypotheses
81     # ==========
82     if verbose :
83       print(". Hypothèses")
84     # Creation of the hypothesis hypo_0_1
85     l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
86     l_hypothese_0_1.SetUnifRefinUnRef(1)
87     l_hypothese_0_1.AddGroup('IN1')
88     l_hypothese_0_1.AddGroup('IN2')
89     l_hypothese_0_1.AddGroup('T1_INT_I')
90     l_hypothese_0_1.AddGroup('T1_INT_O')
91     l_hypothese_0_1.AddGroup('T2_INT')
92     # Creation of the hypothesis hypo_1_2
93     l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
94     l_hypothese_1_2.SetUnifRefinUnRef(1)
95     l_hypothese_1_2.AddGroup('T1_EXT_I')
96     l_hypothese_1_2.AddGroup('T1_EXT_O')
97     l_hypothese_1_2.AddGroup('T2_EXT')
98     # Creation of the hypothesis hypo_2_3
99     l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
100     l_hypothese_2_3.SetUnifRefinUnRef(1)
101     l_hypothese_2_3.AddGroup('INT_I')
102     l_hypothese_2_3.AddGroup('INT_E')
103     l_hypothese_2_3.AddGroup('IN1')
104     l_hypothese_2_3.AddGroup('IN2')
105     #
106     # Cas
107     # ===
108     if verbose :
109       print(". Cas")
110     le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
111     le_cas.SetDirName(DIRCASE)
112     le_cas.AddBoundary(cao_name)
113     #
114     # Itérations
115     # ==========
116     if verbose :
117       option = 2
118     else :
119       option = 1
120     if verbose :
121       print(". Itérations")
122     # Iteration iter_4_1 : raffinement selon les faces internes
123     iter_4_1 = le_cas.NextIteration('iter_4_1')
124     iter_4_1.SetMeshName('PIQUAGE_1')
125     iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
126     iter_4_1.AssociateHypo('hypo_4_0_1')
127     erreur = iter_4_1.Compute(1, option)
128     print ("erreur = %d" % erreur)
129     if erreur :
130       break
131     # Iteration iter_4_2 : raffinement selon les faces externes
132     iter_4_2 = iter_4_1.NextIteration('iter_4_2')
133     iter_4_2.SetMeshName('PIQUAGE_2')
134     iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
135     iter_4_2.AssociateHypo('hypo_4_1_2')
136     erreur = iter_4_2.Compute(1, option)
137     if erreur :
138       break
139     # Iteration iter_4_3 : second raffinement selon les faces externes
140     iter_4_3 = iter_4_2.NextIteration('iter_4_3')
141     iter_4_3.SetMeshName('PIQUAGE_3')
142     iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
143     iter_4_3.AssociateHypo('hypo_4_2_3')
144     erreur = iter_4_3.Compute(1, option)
145     if erreur :
146       break
147   #
148     break
149   #
150   if erreur :
151     message += "Erreur au calcul de l'itération %d" % erreur
152   #
153   return erreur, message
154 #
155 #==========================  Fin de la fonction ==================================
156 #
157 ERREUR = 0
158 MESSAGE = ""
159 while not ERREUR :
160   #
161   # A. Exec of HOMARD-SALOME
162   #
163   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
164   assert HOMARD is not None, "Impossible to load homard engine"
165   HOMARD.SetLanguageShort("fr")
166 #
167   FICMED = os.path.join(DATA_TUTORIAL, "tutorial_4.00.med")
168   XAO_FILE = os.path.join(DATA_TUTORIAL, TEST_NAME+".xao")
169   try:
170     ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, DEBUG)
171   except RuntimeError as eee:
172     ERREUR = 2
173     MESSAGE = str(eee.message)
174   #
175   if ERREUR :
176     MESSAGE += "Pb in homard_exec"
177     break
178   #
179   # B. Test of the results
180   #
181   N_REP_TEST_FILE = N_ITER_TEST_FILE
182   DESTROY_DIR = not DEBUG
183   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
184   #
185   break
186 #
187 if ERREUR:
188   raise Exception(MESSAGE)
189 #
190
191 if salome.sg.hasDesktop():
192   salome.sg.updateObjBrowser()
193   iparameters.getSession().restoreVisualState(1)
194