Salome HOME
Updated copyright comment
[modules/homard.git] / doc / files / tutorial_2.py
old mode 100644 (file)
new mode 100755 (executable)
index 46375f7..89dbd86
@@ -1,12 +1,12 @@
-#!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
 
-# Copyright (C) 2011-2013  CEA/DEN, EDF R&D
+# Copyright (C) 2011-2024  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 """
 Exemple de couplage HOMARD-Salome
-Copyright EDF-R&D 1996, 2010, 2013
+Copyright EDF 1996, 2010, 2019
 """
-__revision__ = "V1.7"
+__revision__ = "V3.03"
 #
 import os
+import sys
 #
 # ==================================
-# Repertoire a personnaliser
-# Ce repertoire contiendra les fichiers de resultats : maill.01.med, maill.02.med
-if os.environ.has_key("LOGNAME") :
-  user = os.environ ["LOGNAME"]
-else :
-  user = "anonymous"
-dircase = os.path.join( os.sep, "tmp", "HOMARD_"+user)
-if not os.path.isdir(dircase) :
-  os.mkdir (dircase)
-dircase = os.path.join( dircase, "tutorial_2" )
-if not os.path.isdir(dircase) :
-  os.mkdir (dircase)
+PATH_HOMARD = os.getenv("HOMARD_ROOT_DIR")
+# 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 creation_dircase
+# ==================================
+DIRCASE = creation_dircase(2)
 # ==================================
-# Ce repertoire contient les fichiers de donnees : tutorial_2.00.med
-pathHomard = os.getenv('HOMARD_ROOT_DIR')
-data_dir = os.path.join(pathHomard, "share/doc/salome/gui/HOMARD/fr/_downloads")
 #
 import salome
 salome.salome_init()
 import HOMARD
 #
 homard = salome.lcc.FindOrLoadComponent("FactoryServer", "HOMARD")
-study_main = salome.myStudyManager.NewStudy("HOMARD")
-homard.SetCurrentStudy(salome.myStudy)
+homard.UpdateStudy()
+#
+#============================= Début des commandes =============================
 #
-# Creation of the zones
-# =====================
+# Creation des zones
+# ==================
 # Box "Zone_0"
 Zone_0 = homard.CreateZoneBox ('Zone_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
 #
@@ -65,40 +60,40 @@ Zone_1 = homard.CreateZoneSphere ('Zone_1', 0., 0., 0., 1.05)
 # Box "Zone_2"
 Zone_2 = homard.CreateZoneBox ('Zone_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
 #
-# Hypothesis "Hypo_2"
-# ===================
-Hypo_2 = homard.CreateHypothesis('Hypo_2')
-Hypo_2.SetAdapRefinUnRef(0, 1, 0)
-Hypo_2.AddZone('Zone_1', 1)
-Hypo_2.AddZone('Zone_0', 1)
-#
-# Hypothesis "Hypo_2_bis"
-# ===================
-Hypo_2_bis = homard.CreateHypothesis('Hypo_2_bis')
-Hypo_2_bis.SetAdapRefinUnRef(0, 1, 0)
-Hypo_2_bis.AddZone('Zone_0', 1)
-Hypo_2_bis.AddZone('Zone_2', 1)
-#
-# Case "Case_2"
-# =============
-Case_2 = homard.CreateCase('Case_2', 'MZERO', data_dir+'/tutorial_2.00.med')
-Case_2.SetDirName(dircase)
-#
-# Iteration "Iter_2_0"
-# ==================
-Iter_2_0 = Case_2.NextIteration('Iter_2_0')
-Iter_2_0.SetMeshName('M_1')
-Iter_2_0.SetMeshFile(dircase+'/maill.01.med')
-Iter_2_0.AssociateHypo('Hypo_2')
-codret = Iter_2_0.Compute(1, 2)
-#
-# Iteration "Iter_2_1"
+# Hypothese "hypo_2"
 # ==================
-Iter_2_1 = Iter_2_0.NextIteration('Iter_2_1')
-Iter_2_1.SetMeshName('M_2')
-Iter_2_1.SetMeshFile(dircase+'/maill.02.med')
-Iter_2_1.AssociateHypo('Hypo_2_bis')
-codret = Iter_2_1.Compute(1, 2)
+l_hypothese = homard.CreateHypothesis('hypo_2')
+l_hypothese.AddZone('Zone_1', 1)
+l_hypothese.AddZone('Zone_0', 1)
+#
+# Hypothese "hypo_2_bis"
+# ======================
+l_hypothese_bis = homard.CreateHypothesis('hypo_2_bis')
+l_hypothese_bis.AddZone('Zone_0', -1)
+l_hypothese_bis.AddZone('Zone_2', 1)
+#
+# Cas
+# ===
+le_cas = homard.CreateCase('Case_2', 'MZERO', os.path.join(DATA_TUTORIAL, "tutorial_2.00.med"))
+le_cas.SetDirName(DIRCASE)
+#
+# Iteration "iter_2_1"
+# ====================
+iter_2_1 = le_cas.NextIteration('iter_2_1')
+iter_2_1.SetMeshName('M_1')
+iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
+iter_2_1.AssociateHypo('hypo_2')
+erreur = iter_2_1.Compute(1, 2)
+#
+# Iteration "iter_2_2"
+# ====================
+iter_2_2 = iter_2_1.NextIteration('iter_2_2')
+iter_2_2.SetMeshName('M_2')
+iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
+iter_2_2.AssociateHypo('hypo_2_bis')
+erreur = iter_2_2.Compute(1, 2)
+#
+#============================== Fin des commandes ==============================
 
 if salome.sg.hasDesktop():
-  salome.sg.updateObjBrowser(1)
+  salome.sg.updateObjBrowser()