Salome HOME
Copyright update 2022
[modules/homard.git] / src / tests / Test / tutorial_1.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 tutorial_1 associe au tutorial 1
23 """
24 __revision__ = "V4.07"
25
26 #========================================================================
27 TEST_NAME = "tutorial_1"
28 DEBUG = False
29 N_ITER_TEST_FILE = 3
30 #========================================================================
31 import os
32 import sys
33 #
34 # ==================================
35 PATH_HOMARD = os.getenv("HOMARD_ROOT_DIR")
36 # Repertoire des scripts utilitaires
37 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
38 REP_PYTHON = os.path.normpath(REP_PYTHON)
39 sys.path.append(REP_PYTHON)
40 from test_util import get_dir
41 from test_util import test_results
42 # ==================================
43 # Répertoires pour ce test
44 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
45 # ==================================
46 #
47 import salome
48 salome.salome_init()
49 import HOMARD
50 import iparameters
51 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
52 IPAR.append("AP_MODULES_LIST", "Homard")
53 #
54 #
55 #========================= Debut de la fonction ==================================
56 #
57 def homard_exec(nom, ficmed, verbose=False):
58   """
59 Python script for HOMARD
60   """
61   erreur = 0
62   message = ""
63   #
64   while not erreur :
65   #
66   #  HOMARD.UpdateStudy()
67     #
68     # Hypotheses
69     # ==========
70     if verbose :
71       print(". Hypothèses")
72     hypo_1 = HOMARD.CreateHypothesis('hypo_1')
73     hypo_1.SetUnifRefinUnRef(1)
74     #
75     # Cas
76     # ===
77     if verbose :
78       print(". Cas")
79     le_cas = HOMARD.CreateCase('case_1', nom, ficmed)
80     le_cas.SetDirName(DIRCASE)
81     #
82     # Itérations
83     # ==========
84     if verbose :
85       option = 2
86     else :
87       option = 1
88     if verbose :
89       print(". Itérations")
90     # Iteration "iter_1_1"
91     iter_1_1 = le_cas.NextIteration('iter_1_1')
92     iter_1_1.SetMeshName('MESH')
93     iter_1_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
94     iter_1_1.AssociateHypo('hypo_1')
95     erreur = iter_1_1.Compute(1, option)
96     if erreur :
97       break
98
99     # Iteration "iter_1_2"
100     iter_1_2 = iter_1_1.NextIteration('iter_1_2')
101     iter_1_2.SetMeshName('MESH')
102     iter_1_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
103     iter_1_2.AssociateHypo('hypo_1')
104     erreur = iter_1_2.Compute(1, option)
105     if erreur :
106       break
107
108     # Iteration "iter_1_3"
109     iter_1_3 = iter_1_2.NextIteration('iter_1_3')
110     iter_1_3.SetMeshName('MESH')
111     iter_1_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
112     iter_1_3.AssociateHypo('hypo_1')
113     erreur = iter_1_3.Compute(1, option)
114     if erreur :
115       break
116   #
117     break
118   #
119   if erreur :
120     message += "Erreur au calcul de l'itération %d" % erreur
121   #
122   return erreur, message
123 #
124 #==========================  Fin de la fonction ==================================
125 #
126 ERREUR = 0
127 MESSAGE = ""
128 while not ERREUR :
129   #
130   # A. Exec of HOMARD-SALOME
131   #
132   HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
133   assert HOMARD is not None, "Impossible to load homard engine"
134   HOMARD.SetLanguageShort("fr")
135 #
136   FICMED = os.path.join(REP_DATA, TEST_NAME+".00.med")
137   try:
138     ERREUR, MESSAGE = homard_exec("MAILL", FICMED, DEBUG)
139   except RuntimeError as eee:
140     ERREUR = 2
141     MESSAGE = str(eee.message)
142   #
143   if ERREUR :
144     MESSAGE += "Pb in homard_exec"
145     break
146   #
147   # B. Test of the results
148   #
149   N_REP_TEST_FILE = N_ITER_TEST_FILE
150   DESTROY_DIR = not DEBUG
151   test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
152   #
153   break
154 #
155 if ERREUR:
156   raise Exception(MESSAGE)
157 #
158 #
159 if salome.sg.hasDesktop():
160   salome.sg.updateObjBrowser()
161   iparameters.getSession().restoreVisualState(1)
162