1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2022 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 zones
67 # =====================
68 # Creation of the box zone_1_1
69 zone_1_1 = HOMARD.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
71 # Creation of the sphere zone_1_2
72 zone_1_2 = HOMARD.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
74 # Creation of the hypotheses
75 # ==========================
77 dico["1"] = "raffinement"
78 dico["-1"] = "deraffinement"
79 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
80 hyponame_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
81 print("-------- Creation of the hypothesis", hyponame_1)
82 hypo_1_1 = HOMARD.CreateHypothesis(hyponame_1)
83 hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
84 hypo_1_1.SetUseComp(0)
85 hypo_1_1.AddComp('ERREST')
86 hypo_1_1.SetRefinThr(3, 10.1)
87 hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
88 hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
89 print(hyponame_1, " : champ utilisé :", hypo_1_1.GetFieldName())
90 print(hyponame_1, " : composantes utilisées :", hypo_1_1.GetComps())
91 if ( len (hypo_1_1.GetFieldName()) > 0 ) :
92 print(".. caractéristiques de l'adaptation :", hypo_1_1.GetField())
93 print(hyponame_1, " : champs interpolés :", hypo_1_1.GetFieldInterps())
94 # Creation of the hypothesis Zones_1_et_2
95 hyponame_2 = "Zones_1_et_2"
96 print("-------- Creation of the hypothesis", hyponame_2)
97 zones_1_et_2 = HOMARD.CreateHypothesis(hyponame_2)
98 zones_1_et_2.AddZone('Zone_1_1', 1)
99 zones_1_et_2.AddZone('Zone_1_2', 1)
100 laux = zones_1_et_2.GetZones()
101 nbzone = len(laux) // 2
103 for _ in range(nbzone) :
104 print(hyponame_2, " : ", dico[laux[iaux+1]], "sur la zone", laux[iaux])
106 print(hyponame_2, " : champ utilisé :", zones_1_et_2.GetFieldName())
107 if ( len (zones_1_et_2.GetFieldName()) > 0 ) :
108 print(".. caractéristiques de l'adaptation :", zones_1_et_2.GetField())
109 print(hyponame_2, " : champs interpolés :", zones_1_et_2.GetFieldInterps())
111 # Creation of the cases
112 # =====================
113 # Creation of the case
114 print("-------- Creation of the case", TEST_NAME)
115 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
116 case_test_1 = HOMARD.CreateCase(TEST_NAME, 'MAILL', mesh_file)
117 case_test_1.SetDirName(DIRCASE)
119 # Creation of the iterations
120 # ==========================
121 # Creation of the iteration 1
122 iter_name = "I_" + TEST_NAME + "_1"
123 print("-------- Creation of the iteration", iter_name)
124 iter_test_1_1 = case_test_1.NextIteration(iter_name)
125 iter_test_1_1.AssociateHypo(hyponame_1)
126 print(". Hypothese :", hyponame_1)
127 iter_test_1_1.SetMeshName('M1')
128 iter_test_1_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
129 iter_test_1_1.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.00.med'))
130 iter_test_1_1.SetTimeStepRank(1, 1)
131 iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
132 iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
133 print(". Instants d'interpolation :", iter_test_1_1.GetFieldInterpsTimeStepRank())
134 error = iter_test_1_1.Compute(1, 1)
139 # Creation of the iteration 2
140 iter_name = "I_" + TEST_NAME + "_2"
141 print("-------- Creation of the iteration", iter_name)
142 iter_test_1_2 = iter_test_1_1.NextIteration(iter_name)
143 iter_test_1_2.AssociateHypo(hyponame_1)
144 print(". Hypothese :", hyponame_1)
145 iter_test_1_2.SetMeshName('M2')
146 iter_test_1_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
147 iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.01.med'))
148 iter_test_1_2.SetTimeStepRank(1, 1)
149 iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
150 iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
151 print(". Instants d'interpolation :", iter_test_1_2.GetFieldInterpsTimeStepRank())
152 error = iter_test_1_2.Compute(1, 1)
157 # Creation of the iteration 3
158 iter_name = "I_" + TEST_NAME + "_3"
159 print("-------- Creation of the iteration", iter_name)
160 iter_test_1_3 = iter_test_1_2.NextIteration(iter_name)
161 iter_test_1_3.AssociateHypo(hyponame_2)
162 print(". Hypothese :", hyponame_2)
163 iter_test_1_3.SetMeshName('M3')
164 iter_test_1_3.SetMeshFile(os.path.join(DIRCASE, 'maill.03.med'))
165 iter_test_1_2.SetFieldFile(os.path.join(REP_DATA, TEST_NAME + '.02.med'))
166 print(". Instants d'interpolation :", iter_test_1_3.GetFieldInterpsTimeStepRank())
167 error = iter_test_1_3.Compute(1, 1)
172 # Creation of the schema YACS
173 # ===========================
174 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
175 scriptfile = os.path.normpath(scriptfile)
177 yacs_test_1 = case_test_1.CreateYACSSchema("YACS_test_1", scriptfile, dirname, mesh_file)
178 yacs_test_1.SetMaxIter(N_ITER_TEST_FILE)
179 error = yacs_test_1.Write()
188 #========================================================================
190 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
191 assert HOMARD is not None, "Impossible to load homard engine"
192 HOMARD.SetLanguageShort("fr")
194 # Exec of HOMARD-SALOME
197 ERROR = homard_exec()
199 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
200 except RuntimeError as eee:
201 raise Exception('Pb in homard_exec: '+str(eee.message))
203 # Test of the results
205 N_REP_TEST_FILE = N_ITER_TEST_FILE
206 DESTROY_DIR = not DEBUG
207 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
209 if salome.sg.hasDesktop():
210 salome.sg.updateObjBrowser()
211 iparameters.getSession().restoreVisualState(1)