Salome HOME
gunzip of med files for SciMotors tests
[modules/homard.git] / src / tests / Test / tutorial_4.py
index 8d22a0ea75c58b2fc02ce342276deb0146ad3925..a3f97badbf5240ccdbc080082ea0912790f79cb3 100755 (executable)
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
-# Copyright (C) 2011-2016  CEA/DEN, EDF R&D
+
+# Copyright (C) 2011-2019  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
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
+
 """
 Python script for HOMARD
 Test tutorial_4 associe au tutorial 4
 """
-__revision__ = "V3.1"
+__revision__ = "V5.05"
 
 #========================================================================
 TEST_NAME = "tutorial_4"
@@ -29,10 +31,7 @@ DEBUG = False
 N_ITER_TEST_FILE = 3
 #========================================================================
 import os
-import tempfile
 import sys
-import HOMARD
-import salome
 #
 # ==================================
 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
@@ -40,129 +39,155 @@ 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 get_dir_tutorial
 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, 4, -1)
+# Répertoires pour ce test
+REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
+DATA_TUTORIAL = get_dir_tutorial(PATH_HOMARD)
 # ==================================
-
+#
+import salome
 salome.salome_init()
+import HOMARD
+#
 import iparameters
 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
 IPAR.append("AP_MODULES_LIST", "Homard")
 #
-#========================================================================
-#========================================================================
-def homard_exec():
+#
+#========================= Debut de la fonction ==================================
+#
+def homard_exec(nom, ficmed, xao_file, verbose=True):
   """
 Python script for HOMARD
   """
-  #
-  HOMARD.UpdateStudy()
+  erreur = 0
+  message = ""
 #
-  # Frontieres
-  # ==========
-  boun_4_1 = HOMARD.CreateBoundaryDi('intersection', 'PIQUAGE', DATA_TUTORIAL+'/tutorial_4.fr.med')
+  while not erreur :
+    #
+  #  HOMARD.UpdateStudy()
+    #
+    # Frontières
+    # ==========
+    if verbose :
+      print(". Frontières")
+    cao_name = "CAO_" + nom
+    la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
+    #
+    # Hypotheses
+    # ==========
+    if verbose :
+      print(". Hypothèses")
+    # Creation of the hypothesis hypo_0_1
+    l_hypothese_0_1 = HOMARD.CreateHypothesis('hypo_4_0_1')
+    l_hypothese_0_1.SetUnifRefinUnRef(1)
+    l_hypothese_0_1.AddGroup('IN1')
+    l_hypothese_0_1.AddGroup('IN2')
+    l_hypothese_0_1.AddGroup('T1_INT_I')
+    l_hypothese_0_1.AddGroup('T1_INT_O')
+    l_hypothese_0_1.AddGroup('T2_INT')
+    # Creation of the hypothesis hypo_1_2
+    l_hypothese_1_2 = HOMARD.CreateHypothesis('hypo_4_1_2')
+    l_hypothese_1_2.SetUnifRefinUnRef(1)
+    l_hypothese_1_2.AddGroup('T1_EXT_I')
+    l_hypothese_1_2.AddGroup('T1_EXT_O')
+    l_hypothese_1_2.AddGroup('T2_EXT')
+    # Creation of the hypothesis hypo_2_3
+    l_hypothese_2_3 = HOMARD.CreateHypothesis('hypo_4_2_3')
+    l_hypothese_2_3.SetUnifRefinUnRef(1)
+    l_hypothese_2_3.AddGroup('INT_I')
+    l_hypothese_2_3.AddGroup('INT_E')
+    l_hypothese_2_3.AddGroup('IN1')
+    l_hypothese_2_3.AddGroup('IN2')
+    #
+    # Cas
+    # ===
+    if verbose :
+      print(". Cas")
+    le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
+    le_cas.SetDirName(DIRCASE)
+    le_cas.AddBoundary(cao_name)
+    #
+    # Itérations
+    # ==========
+    if verbose :
+      option = 2
+    else :
+      option = 1
+    if verbose :
+      print(". Itérations")
+    # Iteration iter_4_1 : raffinement selon les faces internes
+    iter_4_1 = le_cas.NextIteration('iter_4_1')
+    iter_4_1.SetMeshName('PIQUAGE_1')
+    iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
+    iter_4_1.AssociateHypo('hypo_4_0_1')
+    erreur = iter_4_1.Compute(1, option)
+    print ("erreur = %d" % erreur)
+    if erreur :
+      break
+    # Iteration iter_4_2 : raffinement selon les faces externes
+    iter_4_2 = iter_4_1.NextIteration('iter_4_2')
+    iter_4_2.SetMeshName('PIQUAGE_2')
+    iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
+    iter_4_2.AssociateHypo('hypo_4_1_2')
+    erreur = iter_4_2.Compute(1, option)
+    if erreur :
+      break
+    # Iteration iter_4_3 : second raffinement selon les faces externes
+    iter_4_3 = iter_4_2.NextIteration('iter_4_3')
+    iter_4_3.SetMeshName('PIQUAGE_3')
+    iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
+    iter_4_3.AssociateHypo('hypo_4_2_3')
+    erreur = iter_4_3.Compute(1, option)
+    if erreur :
+      break
   #
-  boun_4_2 = HOMARD.CreateBoundaryCylinder('cyl_1_ext', 0.0, 25., -25., 25., 50., 75., 100.)
+    break
   #
-  boun_4_3 = HOMARD.CreateBoundaryCylinder('cyl_2_ext', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
+  if erreur :
+    message += "Erreur au calcul de l'itération %d" % erreur
   #
-  boun_4_4 = HOMARD.CreateBoundaryCylinder('cyl_1_int', 0.0, 25., -25., 25., 50., 75., 75.)
+  return erreur, message
+#
+#==========================  Fin de la fonction ==================================
+#
+ERREUR = 0
+MESSAGE = ""
+while not ERREUR :
   #
-  boun_4_5 = HOMARD.CreateBoundaryCylinder('cyl_2_int', 17.5, -2.5, -12.5, -100., -75., -25., 25.)
+  # A. Exec of HOMARD-SALOME
   #
-  # Hypotheses
-  # ==========
-  # Creation of the hypothesis hypo_4
-  hypo_4 = HOMARD.CreateHypothesis('hypo_4')
-  hypo_4.SetUnifRefinUnRef(1)
-  hypo_4.AddGroup('T1_INT_I')
-  hypo_4.AddGroup('T1_INT_O')
-  hypo_4.AddGroup('T2_INT')
-  # Creation of the hypothesis hypo_4_bis
-  hypo_4_bis = HOMARD.CreateHypothesis('hypo_4_bis')
-  hypo_4_bis.SetUnifRefinUnRef(1)
-  hypo_4_bis.AddGroup('T1_EXT_I')
-  hypo_4_bis.AddGroup('T1_EXT_O')
-  hypo_4_bis.AddGroup('T2_EXT')
+  HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
+  assert HOMARD is not None, "Impossible to load homard engine"
+  HOMARD.SetLanguageShort("fr")
+#
+  FICMED = os.path.join(DATA_TUTORIAL, "tutorial_4.00.med")
+  XAO_FILE = os.path.join(DATA_TUTORIAL, TEST_NAME+".xao")
+  try:
+    ERREUR, MESSAGE = homard_exec("PIQUAGE", FICMED, XAO_FILE, DEBUG)
+  except RuntimeError as eee:
+    ERREUR = 2
+    MESSAGE = str(eee.message)
   #
-  # Cas
-  # ===
-  case_4 = HOMARD.CreateCase('case_4', 'PIQUAGE', DATA_TUTORIAL+'/tutorial_4.00.med')
-  case_4.SetDirName(DIRCASE)
-  case_4.AddBoundaryGroup( 'intersection', '' )
-  case_4.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_I' )
-  case_4.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_I' )
-  case_4.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_O' )
-  case_4.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_O' )
-  case_4.AddBoundaryGroup( 'cyl_2_int', 'T2_INT' )
-  case_4.AddBoundaryGroup( 'cyl_2_ext', 'T2_EXT' )
+  if ERREUR :
+    MESSAGE += "Pb in homard_exec"
+    break
   #
-  # Iterations
-  # ==========
-  # Iteration iter_4_1 : raffinement selon les faces internes
-  iter_4_1 = case_4.NextIteration('iter_4_1')
-  iter_4_1.SetMeshName('PIQUAGE_1')
-  iter_4_1.SetMeshFile(DIRCASE+'/maill.01.med')
-  iter_4_1.AssociateHypo('hypo_4')
-  error = iter_4_1.Compute(1, 2)
-  # Iteration iter_4_2 : raffinement selon les faces externes
-  iter_4_2 = iter_4_1.NextIteration('iter_4_2')
-  iter_4_2.SetMeshName('PIQUAGE_2')
-  iter_4_2.SetMeshFile(DIRCASE+'/maill.02.med')
-  iter_4_2.AssociateHypo('hypo_4_bis')
-  error = iter_4_2.Compute(1, 2)
-  # Iteration iter_4_3 : second raffinement selon les faces externes
-  iter_4_3 = iter_4_2.NextIteration('iter_4_3')
-  iter_4_3.SetMeshName('PIQUAGE_3')
-  iter_4_3.SetMeshFile(DIRCASE+'/maill.03.med')
-  iter_4_3.AssociateHypo('hypo_4_bis')
-  error = iter_4_3.Compute(1, 2)
+  # B. Test of the results
   #
-  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
-#
-try :
-  ERROR = homard_exec()
-  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)
+  #
+  break
 #
-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, 4, 1)
-# ==================================
+if ERREUR:
+  raise Exception(MESSAGE)
 #
+
 if salome.sg.hasDesktop():
   salome.sg.updateObjBrowser()
   iparameters.getSession().restoreVisualState(1)