Salome HOME
Updated copyright comment
[modules/homard.git] / src / tests / Test / tutorial_4.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2011-2024  CEA, EDF
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.07"
27
28 #========================================================================
29 TEST_NAME = "tutorial_4"
30 DEBUG = False
31 VERBOSE = False
32 N_ITER_TEST_FILE = 3
33 #========================================================================
34 import os
35 import sys
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 import salome
51 salome.salome_init_without_session()
52 import HOMARD
53 #
54 import iparameters
55 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
56 IPAR.append("AP_MODULES_LIST", "Homard")
57 #
58 #
59 #========================= Debut de la fonction ==================================
60 #
61 def homard_exec(nom, ficmed, xao_file, verbose=True):
62   """
63 Python script for HOMARD
64   """
65   erreur = 0
66   message = ""
67 #
68   while not erreur :
69     #
70   #  HOMARD.UpdateStudy()
71     #
72     # Frontières
73     # ==========
74     if verbose :
75       print(". Frontières")
76     cao_name = "CAO_" + nom
77     la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
78     #
79     # Hypotheses
80     # ==========
81     if verbose :
82       print(". Hypothèses")
83     # Creation of the hypothesis hypo_0_1
84     l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
85     l_hypothese_0_1.SetUnifRefinUnRef(1)
86     l_hypothese_0_1.AddGroup('IN1')
87     l_hypothese_0_1.AddGroup('IN2')
88     l_hypothese_0_1.AddGroup('T1_INT_I')
89     l_hypothese_0_1.AddGroup('T1_INT_O')
90     l_hypothese_0_1.AddGroup('T2_INT')
91     # Creation of the hypothesis hypo_1_2
92     l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
93     l_hypothese_1_2.SetUnifRefinUnRef(1)
94     l_hypothese_1_2.AddGroup('T1_EXT_I')
95     l_hypothese_1_2.AddGroup('T1_EXT_O')
96     l_hypothese_1_2.AddGroup('T2_EXT')
97     # Creation of the hypothesis hypo_2_3
98     l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
99     l_hypothese_2_3.SetUnifRefinUnRef(1)
100     l_hypothese_2_3.AddGroup('INT_I')
101     l_hypothese_2_3.AddGroup('INT_E')
102     l_hypothese_2_3.AddGroup('IN1')
103     l_hypothese_2_3.AddGroup('IN2')
104     #
105     # Cas
106     # ===
107     if verbose :
108       print(". Cas")
109     le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
110     le_cas.SetDirName(DIRCASE)
111     le_cas.AddBoundary(cao_name)
112     #
113     # Itérations
114     # ==========
115     if verbose :
116       option = 2
117     else :
118       option = 1
119     if verbose :
120       print(". Itérations")
121     # Iteration iter_4_1 : raffinement selon les faces internes
122     iter_4_1 = le_cas.NextIteration('iter_4_1')
123     iter_4_1.SetMeshName('PIQUAGE_1')
124     iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
125     iter_4_1.AssociateHypo('hypo_4_0_1')
126     erreur = iter_4_1.Compute(1, option)
127     print ("erreur = %d" % erreur)
128     if erreur :
129       break
130     # Iteration iter_4_2 : raffinement selon les faces externes
131     iter_4_2 = iter_4_1.NextIteration('iter_4_2')
132     iter_4_2.SetMeshName('PIQUAGE_2')
133     iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
134     iter_4_2.AssociateHypo('hypo_4_1_2')
135     erreur = iter_4_2.Compute(1, option)
136     if erreur :
137       break
138     # Iteration iter_4_3 : second raffinement selon les faces externes
139     iter_4_3 = iter_4_2.NextIteration('iter_4_3')
140     iter_4_3.SetMeshName('PIQUAGE_3')
141     iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
142     iter_4_3.AssociateHypo('hypo_4_2_3')
143     erreur = iter_4_3.Compute(1, option)
144     if erreur :
145       break
146   #
147     break
148   #
149   if erreur :
150     message += "Erreur au calcul de l'itération %d" % erreur
151   #
152   return erreur, message
153 #
154 #==========================  Fin de la fonction ==================================
155 #
156 ERREUR = 0
157 MESSAGE = ""
158 while not ERREUR :
159   #
160   # A. Exec of HOMARD-SALOME
161   #
162   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
163   assert HOMARD is not None, "Impossible to load homard engine"
164   HOMARD.SetLanguageShort("fr")
165 #
166   FICMED = os.path.join(REP_DATA, "tutorial_4.00.med")
167   XAO_FILE = os.path.join(REP_DATA, TEST_NAME+".xao")
168   try:
169     ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, VERBOSE)
170   except RuntimeError as eee:
171     ERREUR = 2
172     MESSAGE = str(eee.message)
173   #
174   if ERREUR :
175     MESSAGE += "Pb in homard_exec"
176     break
177   #
178   # B. Test of the results
179   #
180   N_REP_TEST_FILE = N_ITER_TEST_FILE
181   DESTROY_DIR = not DEBUG
182   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
183   #
184   break
185 #
186 if ERREUR:
187   raise Exception(MESSAGE)
188 #
189
190 if salome.sg.hasDesktop():
191   salome.sg.updateObjBrowser()
192   iparameters.getSession().restoreVisualState(1)
193