Salome HOME
Update copyrights
[modules/homard.git] / src / tests / Test / test_5.py
index 07aa93f30da1a45702e5a72544a577c42a0bded4..569666d7aa93f033e535929b86de74ce6d460c72 100755 (executable)
@@ -1,5 +1,5 @@
 # -*- 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
@@ -22,7 +22,7 @@ Python script for HOMARD
 Specific conditions for Code_Saturne
 Test test_5
 """
-__revision__ = "V1.0"
+__revision__ = "V2.04"
 
 #========================================================================
 TEST_NAME = "test_5"
@@ -38,7 +38,6 @@ LG_Z = 160.
 MESH_NAME = "MESH"
 #========================================================================
 import os
-import tempfile
 import sys
 import numpy as np
 import salome
@@ -52,19 +51,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()
@@ -77,7 +68,7 @@ IPAR.append("AP_MODULES_LIST", "Homard")
 #
 #========================================================================
 #========================================================================
-def mesh_exec(theStudy):
+def mesh_exec():
   """
 Python script for MED
   """
@@ -103,11 +94,11 @@ Python script for MED
 #
     coordinates = list()
     coo_z = -0.5*LG_Z
-    for kaux in range(nbno_z) :
+    for _ in range(nbno_z) :
       coo_y = -0.5*LG_Y
-      for jaux in range(nbno_y) :
+      for _ in range(nbno_y) :
         coo_x = -0.5*LG_X
-        for iaux in range(nbno_x) :
+        for _ in range(nbno_x) :
           coordinates.append(coo_x)
           coordinates.append(coo_y)
           coordinates.append(coo_z)
@@ -167,9 +158,9 @@ Python script for MED
       ficmed = os.path.join(DIRCASE, 'maill.00.med')
       #print "Ecriture du maillage dans le fichier", ficmed
       meshMEDFile3D.write(ficmed, 2)
-    except Exception, eee:
+    except IOError as eee:
       error = 2
-      raise Exception('ExportToMEDX() failed. '+eee.message)
+      raise Exception('MEDFileUMesh.write() failed. ' + str(eee))
   #
     break
   #
@@ -178,7 +169,7 @@ Python script for MED
 #========================================================================
 #
 #========================================================================
-def field_exec(theStudy, niter):
+def field_exec(niter):
   """
 Python script for MEDCoupling
   """
@@ -214,7 +205,7 @@ Python script for MEDCoupling
       valeur[num_mail] = 1.e0 / max ( 1.e-5, distance)
     #print ". valeur", valeur
     nparr = valeur.toNumPyArray()
-    print ". mini/maxi", nparr.min(), nparr.max()
+    print(". mini/maxi", nparr.min(), nparr.max())
   #
   # Creation of the field
   # =====================
@@ -233,7 +224,7 @@ Python script for MEDCoupling
 
 #========================================================================
 #========================================================================
-def homard_exec(theStudy):
+def homard_exec():
   """
 Python script for HOMARD
   """
@@ -241,24 +232,24 @@ Python script for HOMARD
 #
   while not error :
   #
-    HOMARD.SetCurrentStudy(theStudy)
+  #  HOMARD.UpdateStudy()
   #
   # Creation of the hypothese DISTANCE INVERSE
   # ==========================================
     hyponame = "DISTANCE INVERSE"
-    print "-------- Creation of the hypothesis", hyponame
+    print("-------- Creation of the hypothesis", hyponame)
     hypo_5 = HOMARD.CreateHypothesis(hyponame)
     hypo_5.SetField('DISTANCE')
     hypo_5.SetUseComp(0)
     hypo_5.SetRefinThr(1, 0.020)
     hypo_5.SetUnRefThr(1, 0.015)
-    print hyponame, " : champ utilisé :", hypo_5.GetFieldName()
-    print ".. caractéristiques de l'adaptation :", hypo_5.GetField()
+    print(hyponame, " : champ utilisé :", hypo_5.GetFieldName())
+    print(".. caractéristiques de l'adaptation :", hypo_5.GetField())
   #
   # 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(DIRCASE, 'maill.00.med')
     case_test_5 = HOMARD.CreateCase(TEST_NAME, 'MESH', mesh_file)
     case_test_5.SetDirName(DIRCASE)
@@ -274,7 +265,7 @@ Python script for HOMARD
     #
     # Creation of the indicator
     #
-      error, ficmed_indic = field_exec(theStudy, niter)
+      error, ficmed_indic = field_exec(niter)
       if error :
         error = 10
         break
@@ -282,7 +273,7 @@ Python script for HOMARD
     # Creation of the iteration
     #
       iter_name = "I_" + TEST_NAME + "_" + s_niterp1
-      print "-------- Creation of the iteration", iter_name
+      print("-------- Creation of the iteration", iter_name)
       if ( niter == 0 ) :
         iter_test_5 = case_test_5.NextIteration(iter_name)
       else :
@@ -305,11 +296,11 @@ Python script for HOMARD
 # Geometry and Mesh
 #
 try :
-  ERROR = mesh_exec(salome.myStudy)
+  ERROR = mesh_exec()
   if ERROR :
     raise Exception('Pb in mesh_exec')
-except Exception, eee:
-  raise Exception('Pb in mesh_exec: '+eee.message)
+except RuntimeError as eee:
+  raise Exception('Pb in mesh_exec: '+str(eee.message))
 
 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
 assert HOMARD is not None, "Impossible to load homard engine"
@@ -318,11 +309,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
 #
@@ -331,6 +322,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(True)
+  salome.sg.updateObjBrowser()
   iparameters.getSession().restoreVisualState(1)