1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2023 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Python script for HOMARD
24 __revision__ = "V4.05"
26 #========================================================================
30 #========================================================================
36 # ==================================
37 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
38 # Repertoire des scripts utilitaires
39 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
40 REP_PYTHON = os.path.normpath(REP_PYTHON)
41 sys.path.append(REP_PYTHON)
42 from test_util import get_dir
43 from test_util import test_results
44 # ==================================
45 # Répertoires pour ce test
46 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
47 # ==================================
49 salome.salome_init_without_session()
51 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
52 IPAR.append("AP_MODULES_LIST", "Homard")
54 #========================================================================
55 #========================================================================
58 Python script for HOMARD
64 # HOMARD.UpdateStudy()
66 # Creation of the boundaries
67 # ==========================
68 # Creation of the discrete boundary boundary_1
69 boundary_1 = HOMARD.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
71 # Creation of the hypotheses
72 # ==========================
73 # Creation of the hypothesis 1
74 hyponame_1 = "hypo_" + TEST_NAME + "_1"
75 print("-------- Creation of the hypothesis", hyponame_1)
76 hypo_test_2_1 = HOMARD.CreateHypothesis(hyponame_1)
77 hypo_test_2_1.SetUnifRefinUnRef(1)
78 hypo_test_2_1.AddGroup('EG')
79 hypo_test_2_1.AddGroup('BANDE')
80 print(hyponame_1, " : zones utilisées :", hypo_test_2_1.GetZones())
81 print(hyponame_1, " : champ utilisé :", hypo_test_2_1.GetFieldName())
82 print(hyponame_1, " : composantes utilisées :", hypo_test_2_1.GetComps())
83 if ( len (hypo_test_2_1.GetFieldName()) > 0 ) :
84 print(".. caractéristiques de l'adaptation :", hypo_test_2_1.GetField())
86 # Creation of the hypothesis 2
87 hyponame_2 = "hypo_" + TEST_NAME + "_2"
88 print("-------- Creation of the hypothesis", hyponame_2)
89 hypo_test_2_2 = HOMARD.CreateHypothesis(hyponame_2)
90 hypo_test_2_2.SetUnifRefinUnRef(1)
91 hypo_test_2_2.AddGroup('M_D')
92 print(hyponame_2, " : zones utilisées :", hypo_test_2_2.GetZones())
93 print(hyponame_2, " : champ utilisé :", hypo_test_2_2.GetFieldName())
94 print(hyponame_2, " : composantes utilisées :", hypo_test_2_2.GetComps())
95 if ( len (hypo_test_2_2.GetFieldName()) > 0 ) :
96 print(".. caractéristiques de l'adaptation :", hypo_test_2_2.GetField())
98 # Creation of the cases
99 # =====================
100 # Creation of the case
101 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
102 case_test_2 = HOMARD.CreateCase(TEST_NAME, 'PLAQUE_0', mesh_file)
103 case_test_2.SetDirName(DIRCASE)
104 case_test_2.AddBoundaryGroup('internal_boundary', '')
106 # Creation of the iterations
107 # ==========================
108 # Creation of the iteration 1
109 iter_name = "I_" + TEST_NAME + "_1"
110 iter_test_2_1 = case_test_2.NextIteration(iter_name)
111 iter_test_2_1.SetMeshName('PLAQUE_1')
112 iter_test_2_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
113 iter_test_2_1.AssociateHypo(hyponame_1)
114 error = iter_test_2_1.Compute(1, 1)
119 # Creation of the iteration 2
120 iter_name = "I_" + TEST_NAME + "_2"
121 iter_test_2_2 = iter_test_2_1.NextIteration(iter_name)
122 iter_test_2_2.SetMeshName('PLAQUE_2')
123 iter_test_2_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
124 iter_test_2_2.AssociateHypo(hyponame_1)
125 error = iter_test_2_2.Compute(1, 1)
130 # Creation of the iteration 3
131 iter_name = "I_" + TEST_NAME + "_3"
132 iter_test_2_3 = iter_test_2_2.NextIteration(iter_name)
133 iter_test_2_3.SetMeshName('PLAQUE_3')
134 iter_test_2_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
135 iter_test_2_3.AssociateHypo(hyponame_2)
136 error = iter_test_2_3.Compute(1, 1)
141 # Creation of the schema YACS
142 # ===========================
143 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
144 scriptfile = os.path.normpath(scriptfile)
146 yacs_test_2 = case_test_2.CreateYACSSchema("YACS_test_2", scriptfile, dirname, mesh_file)
147 yacs_test_2.SetMaxIter(N_ITER_TEST_FILE+1)
148 yacs_test_2.SetType(1)
149 filexml = os.path.join(DIRCASE, 'yacs_test_2.xml')
150 error = yacs_test_2.WriteOnFile(filexml)
159 #========================================================================
161 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
162 assert HOMARD is not None, "Impossible to load homard engine"
163 HOMARD.SetLanguageShort("fr")
165 # Exec of HOMARD-SALOME
168 ERROR = homard_exec()
170 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
171 except RuntimeError as eee:
172 raise Exception('Pb in homard_exec: '+str(eee.message))
174 # Test of the results
176 N_REP_TEST_FILE = N_ITER_TEST_FILE
177 DESTROY_DIR = not DEBUG
178 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
180 if salome.sg.hasDesktop():
181 salome.sg.updateObjBrowser()
182 iparameters.getSession().restoreVisualState(1)