Salome HOME
mise a jour pour la poursuite d'iterations
[modules/homard.git] / tests / test_3.py
index 5e7cdcc474e3798fed1567ddb68998a1196b3a8a..0d7bd3d402af66766a473ce1deaa961b247bb334 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: iso-8859-1 -*-
-# Copyright (C) 2011-2012  CEA/DEN, EDF R&D
+# Copyright (C) 2011-2013  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
-Copyright EDF-R&D 2011
+Copyright EDF-R&D 2011, 2013
 Test test_3
 """
-__revision__ = "V1.3"
+__revision__ = "V1.6"
 
-######################################################################################
+#========================================================================
 Test_Name = "test_3"
+n_boucle = 2
 n_iter_test_file = 2
-######################################################################################
+#========================================================================
 import os
 import sys
 import tempfile
@@ -43,12 +44,31 @@ salome.salome_init()
 import iparameters
 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
 ipar.append("AP_MODULES_LIST", "Homard")
-######################################################################################
-######################################################################################
+#========================================================================
+#========================================================================
+def remove_dir(directory) :
+  """
+Empties, then removes a directory.
+Copyright EDF-R&D 2013
+  """
+#
+  l_aux = os.listdir(directory)
+  for fic in l_aux :
+    fic_a = os.path.join(directory, fic)
+    if os.path.isdir(fic_a) :
+      remove_dir(fic_a)
+    else :
+      os.remove(fic_a)
+  os.rmdir(directory)
+#
+  return
+#
+#========================================================================
+#========================================================================
 def homard_exec(theStudy):
   """
 Python script for HOMARD
-Copyright EDF-R&D 2010
+Copyright EDF-R&D 2010, 2013
   """
   error = 0
 #
@@ -91,35 +111,56 @@ Copyright EDF-R&D 2010
     Case_1.AddBoundaryGroup('sphere_1', 'END_1')
     Case_1.AddBoundaryGroup('sphere_2', 'END_2')
 #
-# Creation of the iterations
-# ==========================
-# Creation of the iteration Iter_1
-    Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
-    Iter_1.SetMeshName('MOYEU_1')
-    Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
-    homard.AssociateIterHypo('Iter_1', 'Hypo')
-    error = Iter_1.Compute(1)
-    if error :
-      error = 1
-      break
+# Creation and destruction of the iterations
+# ==========================================
+#
+    for iaux in range (n_boucle+1) :
+#
+  # Creation of the iteration Iter_1
+      Iter_1 = Case_1.NextIteration('Iter_1')
+      Iter_1.SetMeshName('MOYEU_1')
+      Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
+      Iter_1.AssociateHypo('Hypo')
+      error = Iter_1.Compute(1, 1)
+      if error :
+        error = 10*iaux + 1
+        break
 
-# Creation of the iteration Iter_2
-    Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
-    Iter_2.SetMeshName('MOYEU_2')
-    Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
-    homard.AssociateIterHypo('Iter_2', 'Hypo')
-    error = Iter_2.Compute(1)
-    if error :
-      error = 2
-      break
+  # Creation of the iteration Iter_2
+      Iter_2 = Iter_1.NextIteration('Iter_2')
+      Iter_2.SetMeshName('MOYEU_2')
+      Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
+      Iter_2.AssociateHypo('Hypo')
+      error = Iter_2.Compute(1, 1)
+      if error :
+        error = 10*iaux + 2
+        break
+
+  # Destruction
+      if ( iaux < n_boucle ) :
+  # Recursive destruction of the iterations
+        error = Iter_1.Delete(1)
+        if error :
+          error = 10*iaux + 3
+          break
+  # Destruction and creation of the hypothese
+        if ( iaux == 1 ) :
+          error = Hypo.Delete()
+          if error :
+            error = 10*iaux + 4
+            break
+          Hypo = homard.CreateHypothesis('Hypo')
+          Hypo.SetAdapRefinUnRef(-1, 1, 0)
 #
     break
 #
   return error
 
-######################################################################################
+#========================================================================
 
 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
+assert homard is not None, "Impossible to load homard engine"
+
 #
 # Exec of HOMARD-SALOME
 #
@@ -127,16 +168,14 @@ try :
   error_main = homard_exec(salome.myStudy)
   if error_main :
     raise Exception('Pb in homard_exec at iteration %d' %error_main )
-except :
-  if error_main :
-    raise Exception('Pb in homard_exec at iteration %d' %error_main )
-  sys.exit(1)
+except Exception, e:
+  raise Exception('Pb in homard_exec: '+e.message)
+
 #
 # Test of the result
 #
-s_iter_test_file = str(n_iter_test_file)
-test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
-rep_test_file = "I0" + s_iter_test_file
+test_file_suff = "apad.%02d.bilan" % n_iter_test_file
+rep_test_file = "I%02d" % (n_iter_test_file*(n_boucle+1))
 #
 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
 mess_error_ref = "\nReference file: " + test_file
@@ -175,6 +214,8 @@ for num in range(nblign) :
        raise Exception(message_erreur)
        sys.exit(10)
 #
+remove_dir(Rep_Test_Resu)
+#
 if salome.sg.hasDesktop():
   salome.sg.updateObjBrowser(1)
   iparameters.getSession().restoreVisualState(1)