Salome HOME
Porting HOMARD SALOME module on WIN32 platform.
[modules/homard.git] / tests / test_1.py
index 71e7dac82df85ca95f1d81807dec9cf930514e8d..17e5eb1b15f29f88a129be779dbe9acba351078f 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
@@ -22,20 +22,20 @@ Python script for HOMARD
 Copyright EDF-R&D 2010, 2013
 Test test_1
 """
-__revision__ = "V1.7"
+__revision__ = "V1.13"
 
 #========================================================================
 Test_Name = "test_1"
 n_iter_test_file = 3
 #========================================================================
 import os
-import sys
 import tempfile
 import HOMARD
 import salome
 #
-pathHomard=os.getenv('HOMARD_ROOT_DIR')
-Rep_Test = os.path.join(pathHomard,"share/salome/resources/homard")
+pathHomard = os.getenv('HOMARD_ROOT_DIR')
+Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
+Rep_Test = os.path.normpath(Rep_Test)
 Rep_Test_Resu = tempfile.mktemp()
 os.mkdir(Rep_Test_Resu)
 
@@ -77,76 +77,121 @@ Copyright EDF-R&D 2010, 2013
   #
   # Creation of the zones
   # =====================
-  # Creation of the box Zone_1
-    Zone_1 = homard.CreateZoneBox('Zone_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
+  # Creation of the box Zone_1_1
+    Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
 
-  # Creation of the sphere Zone_2
-    Zone_2 = homard.CreateZoneSphere('Zone_2', 0.5, 0.6, 0.7, 0.75)
+  # Creation of the sphere Zone_1_2
+    Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
   #
   # Creation of the hypotheses
   # ==========================
   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM = homard.CreateHypothesis('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetAdapRefinUnRef(1, 1, 0)
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetField('RESU____ERRE_ELEM_SIGM__________')
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetUseComp(0)
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddComp('ERREST')
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetRefinThr(3, 10.1)
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetTypeFieldInterp(2)
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____DEPL____________________')
-    a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
+    HypoName_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
+    print "-------- Creation of the hypothesis", HypoName_1
+    Hypo_1_1 = homard.CreateHypothesis(HypoName_1)
+    Hypo_1_1.SetAdapRefinUnRef(1, 1, 0)
+    Hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
+    Hypo_1_1.SetUseComp(0)
+    Hypo_1_1.AddComp('ERREST')
+    Hypo_1_1.SetRefinThr(3, 10.1)
+    Hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
+    Hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
+    print HypoName_1, " : zones utilisées :", Hypo_1_1.GetZones()
+    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()
   # Creation of the hypothesis Zones_1_et_2
-    Zones_1_et_2 = homard.CreateHypothesis('Zones_1_et_2')
+    HypoName_2 = "Zones_1_et_2"
+    print "-------- Creation of the hypothesis", HypoName_2
+    Zones_1_et_2 = homard.CreateHypothesis(HypoName_2)
     Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
-    Zones_1_et_2.AddZone('Zone_1', 1)
-    Zones_1_et_2.AddZone('Zone_2', 1)
+    Zones_1_et_2.AddZone('Zone_1_1', 1)
+    Zones_1_et_2.AddZone('Zone_1_2', 1)
+    print HypoName_2, " : zones utilisées :", Zones_1_et_2.GetZones()
+    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()
   #
   # Creation of the cases
   # =====================
-    # Creation of the case zzzz121b
-    Case_1 = homard.CreateCase('zzzz121b', 'MAILL', os.path.join(Rep_Test, Test_Name + '.00.med'))
-    Case_1.SetDirName(Rep_Test_Resu)
-    Case_1.SetConfType(1)
+    # Creation of the case
+    CaseName = "Case_" + Test_Name
+    print "-------- Creation of the case", CaseName
+    MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
+    Case_test_1 = homard.CreateCase(CaseName, 'MAILL', MeshFile)
+    Case_test_1.SetDirName(Rep_Test_Resu)
+    Case_test_1.SetConfType(1)
   #
   # Creation of the iterations
   # ==========================
-  # Creation of the iteration I1
-    I1 = Case_1.NextIteration('I1')
-    I1.SetMeshName('M1')
-    I1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
-    I1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
-    I1.SetTimeStepRank(1, 1)
-    I1.AssociateHypo('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
-    error = I1.Compute(1)
+  # Creation of the iteration 1
+    IterName = "I_" + Test_Name + "_1"
+    print "-------- Creation of the iteration", IterName
+    Iter_test_1_1 = Case_test_1.NextIteration(IterName)
+    Iter_test_1_1.AssociateHypo(HypoName_1)
+    print ". Hypothese :", HypoName_1
+    Iter_test_1_1.SetMeshName('M1')
+    Iter_test_1_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
+    Iter_test_1_1.SetFieldFile(os.path.join(Rep_Test, 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()
+    error = Iter_test_1_1.Compute(1, 1)
     if error :
       error = 1
       break
 
-  # Creation of the iteration I2
-    I2 = I1.NextIteration('I2')
-    I2.SetMeshName('M2')
-    I2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
-    I2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
-    I2.SetTimeStepRank(1, 1)
-    I2.AssociateHypo('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
-    error = I2.Compute(1)
+  # Creation of the iteration 2
+    IterName = "I_" + Test_Name + "_2"
+    print "-------- Creation of the iteration", IterName
+    Iter_test_1_2 = Iter_test_1_1.NextIteration(IterName)
+    Iter_test_1_2.AssociateHypo(HypoName_1)
+    print ". Hypothese :", HypoName_1
+    Iter_test_1_2.SetMeshName('M2')
+    Iter_test_1_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
+    Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, 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()
+    error = Iter_test_1_2.Compute(1, 1)
     if error :
       error = 2
       break
 
-  # Creation of the iteration I3
-    I3 = I2.NextIteration('I3')
-    I3.SetMeshName('M3')
-    I3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
-    I3.AssociateHypo('Zones_1_et_2')
-    error = I3.Compute(1)
+  # Creation of the iteration 3
+    IterName = "I_" + Test_Name + "_3"
+    print "-------- Creation of the iteration", IterName
+    Iter_test_1_3 = Iter_test_1_2.NextIteration(IterName)
+    Iter_test_1_3.AssociateHypo(HypoName_2)
+    print ". Hypothese :", HypoName_2
+    Iter_test_1_3.SetMeshName('M3')
+    Iter_test_1_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
+    Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.02.med'))
+    print ". Instants d'interpolation :", Iter_test_1_3.GetFieldInterpsTimeStepRank()
+    error = Iter_test_1_3.Compute(1, 1)
     if error :
       error = 3
       break
+  #
+  # Creation of the schema YACS
+  # ===========================
+    ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
+    ScriptFile = os.path.normpath(ScriptFile)
+    DirName = Rep_Test_Resu
+    YACS_test_1 = Case_test_1.CreateYACSSchema("YACS_test_1", ScriptFile, DirName, MeshFile)
+    error = YACS_test_1.Write()
+    if error :
+      error = 4
+      break
   #
     break
   #
-    return error
+  return error
 
 #========================================================================
 
@@ -162,13 +207,11 @@ try :
     raise Exception('Pb in homard_exec at iteration %d' %error_main )
 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
 #
 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
 mess_error_ref = "\nReference file: " + test_file
@@ -179,33 +222,29 @@ try :
 except :
   mess_error = mess_error_ref + "\nThis file does not exist.\n"
   raise Exception(mess_error)
-  sys.exit(2)
 #
 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
 if os.path.isfile (test_file) :
-   file = open (test_file, "r")
-   mess = file.readlines()
-   file.close()
+  file = open (test_file, "r")
+  mess = file.readlines()
+  file.close()
 else :
   mess_error  = "\nResult file: " + test_file
   mess_error += "\nThis file does not exist.\n"
   raise Exception(mess_error)
-  sys.exit(2)
 
 nblign = len(mess_ref)
 if ( len(mess) != nblign ):
   mess_error = mess_error_ref +  "\nResult file: " + test_file
   mess_error += "\nThe number of lines of the files are not the same.\n"
   raise Exception(mess_error)
-  sys.exit(2)
 
 for num in range(nblign) :
-   if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
-       message_erreur = "\nRefe : " + mess_ref[num]
-       message_erreur += "Test : " + mess[num][:-1]
-       message_erreur += "\nThe test is different from the reference."
-       raise Exception(message_erreur)
-       sys.exit(10)
+  if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
+    message_erreur = "\nRefe : " + mess_ref[num]
+    message_erreur += "Test : " + mess[num][:-1]
+    message_erreur += "\nThe test is different from the reference."
+    raise Exception(message_erreur)
 #
 remove_dir(Rep_Test_Resu)
 #