Salome HOME
Copyright update 2022
[modules/homard.git] / src / tests / Test / test_1.py
index 6f63614b57bea4684caf919de75f9c1679ef5131..7fbab055f1fd3aaeb8dc0678dfc18a0d3f67ffdb 100755 (executable)
@@ -1,5 +1,5 @@
 # -*- 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
@@ -21,7 +21,7 @@
 Python script for HOMARD
 Test test_1
 """
-__revision__ = "V3.1"
+__revision__ = "V4.05"
 
 #========================================================================
 TEST_NAME = "test_1"
@@ -29,7 +29,6 @@ DEBUG = False
 N_ITER_TEST_FILE = 3
 #========================================================================
 import os
-import tempfile
 import sys
 import HOMARD
 import salome
@@ -40,19 +39,11 @@ 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()
+# ==================================
+# Répertoires pour ce test
+REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
 # ==================================
 
 salome.salome_init()
@@ -62,7 +53,7 @@ IPAR.append("AP_MODULES_LIST", "Homard")
 #
 #========================================================================
 #========================================================================
-def homard_exec(theStudy):
+def homard_exec():
   """
 Python script for HOMARD
   """
@@ -70,7 +61,7 @@ Python script for HOMARD
 #
   while not error :
   #
-    HOMARD.SetCurrentStudy(theStudy)
+  #  HOMARD.UpdateStudy()
   #
   # Creation of the zones
   # =====================
@@ -87,7 +78,7 @@ Python script for HOMARD
     dico["-1"] = "deraffinement"
   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
     hyponame_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
-    print "-------- Creation of the hypothesis", hyponame_1
+    print("-------- Creation of the hypothesis", hyponame_1)
     hypo_1_1 = HOMARD.CreateHypothesis(hyponame_1)
     hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
     hypo_1_1.SetUseComp(0)
@@ -95,32 +86,32 @@ Python script for HOMARD
     hypo_1_1.SetRefinThr(3, 10.1)
     hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
     hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
-    print hyponame_1, " : champ utilisé :", hypo_1_1.GetFieldName()
-    print hyponame_1, " : composantes utilisées :", hypo_1_1.GetComps()
+    print(hyponame_1, " : champ utilisé :", hypo_1_1.GetFieldName())
+    print(hyponame_1, " : composantes utilisées :", hypo_1_1.GetComps())
     if ( len (hypo_1_1.GetFieldName()) > 0 ) :
-      print ".. caractéristiques de l'adaptation :", hypo_1_1.GetField()
-    print hyponame_1, " : champs interpolés :", hypo_1_1.GetFieldInterps()
+      print(".. caractéristiques de l'adaptation :", hypo_1_1.GetField())
+    print(hyponame_1, " : champs interpolés :", hypo_1_1.GetFieldInterps())
   # Creation of the hypothesis Zones_1_et_2
     hyponame_2 = "Zones_1_et_2"
-    print "-------- Creation of the hypothesis", hyponame_2
+    print("-------- Creation of the hypothesis", hyponame_2)
     zones_1_et_2 = HOMARD.CreateHypothesis(hyponame_2)
     zones_1_et_2.AddZone('Zone_1_1', 1)
     zones_1_et_2.AddZone('Zone_1_2', 1)
     laux = zones_1_et_2.GetZones()
-    nbzone = len(laux)/2
-    jaux = 0
-    for iaux in range(nbzone) :
-      print hyponame_2, " : ", dico[laux[jaux+1]], "sur la zone", laux[jaux]
-      jaux += 2
-    print hyponame_2, " : champ utilisé :", zones_1_et_2.GetFieldName()
+    nbzone = len(laux) // 2
+    iaux = 0
+    for _ in range(nbzone) :
+      print(hyponame_2, " : ", dico[laux[iaux+1]], "sur la zone", laux[iaux])
+      iaux += 2
+    print(hyponame_2, " : champ utilisé :", zones_1_et_2.GetFieldName())
     if ( len (zones_1_et_2.GetFieldName()) > 0 ) :
-      print ".. caractéristiques de l'adaptation :", zones_1_et_2.GetField()
-    print hyponame_2, " : champs interpolés :", zones_1_et_2.GetFieldInterps()
+      print(".. caractéristiques de l'adaptation :", zones_1_et_2.GetField())
+    print(hyponame_2, " : champs interpolés :", zones_1_et_2.GetFieldInterps())
   #
   # Creation of the cases
   # =====================
     # Creation of the case
-    print "-------- Creation of the case", TEST_NAME
+    print("-------- Creation of the case", TEST_NAME)
     mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
     case_test_1 = HOMARD.CreateCase(TEST_NAME, 'MAILL', mesh_file)
     case_test_1.SetDirName(DIRCASE)
@@ -129,17 +120,17 @@ Python script for HOMARD
   # ==========================
   # Creation of the iteration 1
     iter_name = "I_" + TEST_NAME + "_1"
-    print "-------- Creation of the iteration", iter_name
+    print("-------- Creation of the iteration", iter_name)
     iter_test_1_1 = case_test_1.NextIteration(iter_name)
     iter_test_1_1.AssociateHypo(hyponame_1)
-    print ". Hypothese :", hyponame_1
+    print(". Hypothese :", hyponame_1)
     iter_test_1_1.SetMeshName('M1')
     iter_test_1_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
     iter_test_1_1.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.00.med'))
     iter_test_1_1.SetTimeStepRank(1, 1)
     iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
     iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
-    print ". Instants d'interpolation :", iter_test_1_1.GetFieldInterpsTimeStepRank()
+    print(". Instants d'interpolation :", iter_test_1_1.GetFieldInterpsTimeStepRank())
     error = iter_test_1_1.Compute(1, 1)
     if error :
       error = 1
@@ -147,17 +138,17 @@ Python script for HOMARD
 
   # Creation of the iteration 2
     iter_name = "I_" + TEST_NAME + "_2"
-    print "-------- Creation of the iteration", iter_name
+    print("-------- Creation of the iteration", iter_name)
     iter_test_1_2 = iter_test_1_1.NextIteration(iter_name)
     iter_test_1_2.AssociateHypo(hyponame_1)
-    print ". Hypothese :", hyponame_1
+    print(". Hypothese :", hyponame_1)
     iter_test_1_2.SetMeshName('M2')
     iter_test_1_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
     iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.01.med'))
     iter_test_1_2.SetTimeStepRank(1, 1)
     iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
     iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
-    print ". Instants d'interpolation :", iter_test_1_2.GetFieldInterpsTimeStepRank()
+    print(". Instants d'interpolation :", iter_test_1_2.GetFieldInterpsTimeStepRank())
     error = iter_test_1_2.Compute(1, 1)
     if error :
       error = 2
@@ -165,14 +156,14 @@ Python script for HOMARD
 
   # Creation of the iteration 3
     iter_name = "I_" + TEST_NAME + "_3"
-    print "-------- Creation of the iteration", iter_name
+    print("-------- Creation of the iteration", iter_name)
     iter_test_1_3 = iter_test_1_2.NextIteration(iter_name)
     iter_test_1_3.AssociateHypo(hyponame_2)
-    print ". Hypothese :", hyponame_2
+    print(". Hypothese :", hyponame_2)
     iter_test_1_3.SetMeshName('M3')
     iter_test_1_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
     iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.02.med'))
-    print ". Instants d'interpolation :", iter_test_1_3.GetFieldInterpsTimeStepRank()
+    print(". Instants d'interpolation :", iter_test_1_3.GetFieldInterpsTimeStepRank())
     error = iter_test_1_3.Compute(1, 1)
     if error :
       error = 3
@@ -184,6 +175,7 @@ Python script for HOMARD
     scriptfile = os.path.normpath(scriptfile)
     dirname = DIRCASE
     yacs_test_1 = case_test_1.CreateYACSSchema("YACS_test_1", scriptfile, dirname, mesh_file)
+    yacs_test_1.SetMaxIter(N_ITER_TEST_FILE)
     error = yacs_test_1.Write()
     if error :
       error = 4
@@ -202,11 +194,11 @@ HOMARD.SetLanguageShort("fr")
 # Exec of HOMARD-SALOME
 #
 try :
-  ERROR = homard_exec(salome.myStudy)
+  ERROR = homard_exec()
   if ERROR :
     raise Exception('Pb in homard_exec at iteration %d' %ERROR )
-except Exception, eee:
-  raise Exception('Pb in homard_exec: '+eee.message)
+except RuntimeError as eee:
+  raise Exception('Pb in homard_exec: '+str(eee.message))
 #
 # Test of the results
 #
@@ -215,6 +207,6 @@ DESTROY_DIR = not DEBUG
 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
 #
 if salome.sg.hasDesktop():
-  salome.sg.updateObjBrowser(1)
+  salome.sg.updateObjBrowser()
   iparameters.getSession().restoreVisualState(1)