# -*- coding: utf-8 -*-
-# Copyright (C) 2011-2016 CEA/DEN, EDF R&D
+# Copyright (C) 2011-2022 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Python script for HOMARD
Test tutorial_2 associe au tutorial 2
"""
-__revision__ = "V3.1"
+__revision__ = "V4.07"
#========================================================================
TEST_NAME = "tutorial_2"
N_ITER_TEST_FILE = 2
#========================================================================
import os
-import tempfile
import sys
-import HOMARD
-import salome
#
# ==================================
PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
REP_PYTHON = os.path.normpath(REP_PYTHON)
sys.path.append(REP_PYTHON)
-from test_util import remove_dir
+from test_util import get_dir
from test_util import test_results
-# Repertoire des donnees du test
-REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
-REP_DATA = os.path.normpath(REP_DATA)
-# Repertoire des resultats
-if DEBUG :
- DIRCASE = os.path.join("/tmp", TEST_NAME)
- if ( os.path.isdir(DIRCASE) ) :
- remove_dir(DIRCASE)
- os.mkdir(DIRCASE)
-else :
- DIRCASE = tempfile.mkdtemp()
-# Repertoire des donnees du tutorial
-DATA_TUTORIAL = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "fr", "_downloads")
-DATA_TUTORIAL = os.path.normpath(DATA_TUTORIAL)
-sys.path.append(DATA_TUTORIAL)
-from tutorial_util import gzip_gunzip
# ==================================
-gzip_gunzip(DATA_TUTORIAL, 2, -1)
+# Répertoires pour ce test
+REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
# ==================================
-
-salome.salome_init()
+#
+import salome
+salome.salome_init_without_session()
+import HOMARD
+#
import iparameters
IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
IPAR.append("AP_MODULES_LIST", "Homard")
#
-#========================================================================
-#========================================================================
-def homard_exec(theStudy):
+#
+#========================= Debut de la fonction ==================================
+#
+def homard_exec(nom, ficmed, verbose=False):
"""
Python script for HOMARD
"""
+ erreur = 0
+ message = ""
#
- HOMARD.SetCurrentStudy(theStudy)
+ while not erreur :
+ #
+ # HOMARD.UpdateStudy()
+ #
+ # Creation des zones
+ # ==================
+ if verbose :
+ print(". Zones")
+ # Box "Zone_12_0"
+ zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
+ #
+ # Sphere "Zone_12_1"
+ zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
+ #
+ # Box "Zone_12_2"
+ zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
+ #
+ # Hypotheses
+ # ==========
+ if verbose :
+ print(". Hypothèses")
+ # Hypothese "hypo_2"
+ # ==================
+ hypo_2 = HOMARD.CreateHypothesis('hypo_2')
+ hypo_2.AddZone('Zone_12_1', 1)
+ hypo_2.AddZone('Zone_12_0', 1)
+ #
+ # Hypothese "hypo_2_bis"
+ # ======================
+ hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
+ hypo_2_bis.AddZone('Zone_12_0', -1)
+ hypo_2_bis.AddZone('Zone_12_2', 1)
+ #
+ # Cas
+ # ===
+ if verbose :
+ print(". Cas")
+ le_cas = HOMARD.CreateCase('case_2', nom, ficmed)
+ le_cas.SetDirName(DIRCASE)
+ #
+ # Itérations
+ # ==========
+ if verbose :
+ option = 2
+ else :
+ option = 1
+ if verbose :
+ print(". Itérations")
+ #
+ # Iteration "iter_2_1"
+ # ====================
+ iter_2_1 = le_cas.NextIteration('iter_2_1')
+ iter_2_1.SetMeshName('M_1')
+ iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
+ iter_2_1.AssociateHypo('hypo_2')
+ erreur = iter_2_1.Compute(1, option)
+ if erreur :
+ break
+ #
+ # Iteration "iter_2_2"
+ # ====================
+ iter_2_2 = iter_2_1.NextIteration('iter_2_2')
+ iter_2_2.SetMeshName('M_2')
+ iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
+ iter_2_2.AssociateHypo('hypo_2_bis')
+ erreur = iter_2_2.Compute(1, option)
+ if erreur :
+ break
#
- # Creation des zones
- # ==================
- # Box "Zone_12_0"
- zone_12_0 = HOMARD.CreateZoneBox ('Zone_12_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
+ break
#
- # Sphere "Zone_12_1"
- zone_12_1 = HOMARD.CreateZoneSphere ('Zone_12_1', 0., 0., 0., 1.05)
+ if erreur :
+ message += "Erreur au calcul de l'itération %d" % erreur
#
- # Box "Zone_12_2"
- zone_12_2 = HOMARD.CreateZoneBox ('Zone_12_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
+ return erreur, message
+#
+#========================== Fin de la fonction ==================================
+#
+ERREUR = 0
+MESSAGE = ""
+while not ERREUR :
#
- # Hypothese "hypo_2"
- # ==================
- hypo_2 = HOMARD.CreateHypothesis('hypo_2')
- hypo_2.AddZone('Zone_12_1', 1)
- hypo_2.AddZone('Zone_12_0', 1)
+ # A. Exec of HOMARD-SALOME
#
- # Hypothese "hypo_2_bis"
- # ======================
- hypo_2_bis = HOMARD.CreateHypothesis('hypo_2_bis')
- hypo_2_bis.AddZone('Zone_12_0', -1)
- hypo_2_bis.AddZone('Zone_12_2', 1)
+ HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
+ assert HOMARD is not None, "Impossible to load homard engine"
+ HOMARD.SetLanguageShort("fr")
+#
+ FICMED = os.path.join(REP_DATA, TEST_NAME+".00.med")
+ try:
+ ERREUR, MESSAGE = homard_exec("MZERO", FICMED, DEBUG)
+ except RuntimeError as eee:
+ ERREUR = 2
+ MESSAGE = str(eee.message)
#
- # Cas
- # ===
- case_2 = HOMARD.CreateCase('case_2', 'MZERO', DATA_TUTORIAL+'/tutorial_2.00.med')
- case_2.SetDirName(DIRCASE)
+ if ERREUR :
+ MESSAGE += "Pb in homard_exec"
+ break
#
- # Iteration "iter_2_1"
- # ====================
- iter_2_1 = case_2.NextIteration('iter_2_1')
- iter_2_1.SetMeshName('M_1')
- iter_2_1.SetMeshFile(DIRCASE+'/maill.01.med')
- iter_2_1.AssociateHypo('hypo_2')
- error = iter_2_1.Compute(1, 2)
+ # B. Test of the results
#
- # Iteration "iter_2_2"
- # ====================
- iter_2_2 = iter_2_1.NextIteration('iter_2_2')
- iter_2_2.SetMeshName('M_2')
- iter_2_2.SetMeshFile(DIRCASE+'/maill.02.med')
- iter_2_2.AssociateHypo('hypo_2_bis')
- error = iter_2_2.Compute(1, 2)
+ N_REP_TEST_FILE = N_ITER_TEST_FILE
+ DESTROY_DIR = not DEBUG
+ test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
#
- return error
-
-#========================================================================
-
-HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
-assert HOMARD is not None, "Impossible to load HOMARD engine"
-HOMARD.SetLanguageShort("fr")
-#
-# Exec of HOMARD-SALOME
+ break
#
-try :
- ERROR = homard_exec(salome.myStudy)
- if ERROR :
- raise Exception('Pb in homard_exec at iteration %d' %ERROR )
-except Exception as eee:
- raise Exception('Pb in homard_exec: '+eee.message)
-#
-# Test of the results
-#
-N_REP_TEST_FILE = N_ITER_TEST_FILE
-DESTROY_DIR = not DEBUG
-test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
-#
-# ==================================
-gzip_gunzip(DATA_TUTORIAL, 2, 1)
-# ==================================
+if ERREUR:
+ raise Exception(MESSAGE)
#
if salome.sg.hasDesktop():
- salome.sg.updateObjBrowser(True)
+ salome.sg.updateObjBrowser()
iparameters.getSession().restoreVisualState(1)