1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2016 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 # Author(s): Guillaume Boulant (23/03/2011)
24 # This script illustrates the standard use case of the component
25 # MeshJobManager from within a SALOME script. It could be used as a
26 # unit test of the component. The typical procedure is:
27 # $ <appli>/runAppli -t
28 # $ <appli>/runSession </path/to>/usecase_meshJobManager.py
31 # =======================================================================
32 # Preparing the configuration parameters
33 # =======================================================================
38 from salome.smesh.spadder.configreader import ConfigReader, printConfig, getPadderTestDir
40 configReader = ConfigReader()
41 defaultConfig = configReader.getDefaultConfig()
42 printConfig(defaultConfig)
44 from salome.smesh import spadder
50 # Setup the configuration in the component. We first have to load the
51 # catalog of SPADDER components, then load the component
52 # MeshJobManager, and finally configure this component.
54 spadder.loadSpadderCatalog()
57 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
58 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
59 binpath=defaultConfig.binpath,
60 envpath=defaultConfig.envpath)
62 configId = "localhost"
63 component.configure(configId,config)
67 # =======================================================================
68 # Define several datasets for the different use cases
69 # =======================================================================
72 # We define several functions that create each a dataset of med files
73 # for testing the component. The test function number corresponds to
74 # the number of the test defined in the SpherePadder installation
76 PADDERTESTDIR = getPadderTestDir(defaultConfig)
77 #PADDERTESTDIR = spadder.getTestPadderDataDir()
79 # WARN: the above instruction (spadder.getTestPadderDataDir())
80 # localizes the PADDERTEST DIR using the PADDERDIR shell variable,
81 # while the previous one (getPadderTestDir) localizes this directory
82 # from data of the config (read from the configuration file
85 def test00_parameters():
86 """Test using a concrete mesh and a single steelbar mesh"""
87 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
88 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
90 meshJobParameterList = []
91 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
92 file_type=MESHJOB.MED_CONCRETE,
93 group_name="concrete")
94 meshJobParameterList.append(param)
96 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
97 file_type=MESHJOB.MED_STEELBAR,
98 group_name="steelbar")
99 meshJobParameterList.append(param)
100 return meshJobParameterList
102 def test01_parameters():
103 """One concrete mesh and two steelbar meshes"""
104 datadir = os.path.join(PADDERTESTDIR,"test01")
105 meshJobParameterList = []
107 medfile = os.path.join(datadir,"concrete.med")
108 param = MESHJOB.MeshJobParameter(file_name=medfile,
109 file_type=MESHJOB.MED_CONCRETE,
110 group_name="concrete")
111 meshJobParameterList.append(param)
113 medfile = os.path.join(datadir,"ferraill.med")
114 param = MESHJOB.MeshJobParameter(file_name=medfile,
115 file_type=MESHJOB.MED_STEELBAR,
116 group_name="ferraill")
117 meshJobParameterList.append(param)
119 medfile = os.path.join(datadir,"ferrtran.med")
120 param = MESHJOB.MeshJobParameter(file_name=medfile,
121 file_type=MESHJOB.MED_STEELBAR,
122 group_name="ferrtran")
123 meshJobParameterList.append(param)
125 return meshJobParameterList
127 def test02_parameters():
128 """One steelbar mesh only, without a concrete mesh"""
129 datadir = os.path.join(PADDERTESTDIR,"test02")
130 meshJobParameterList = []
132 medfile = os.path.join(datadir,"cadreef.med")
133 param = MESHJOB.MeshJobParameter(file_name=medfile,
134 file_type=MESHJOB.MED_STEELBAR,
136 meshJobParameterList.append(param)
137 return meshJobParameterList
139 def test03_parameters():
140 """One concrete mesh only, without a steelbar mesh"""
141 datadir = os.path.join(PADDERTESTDIR,"test03")
142 meshJobParameterList = []
144 medfile = os.path.join(datadir,"concrete.med")
145 param = MESHJOB.MeshJobParameter(file_name=medfile,
146 file_type=MESHJOB.MED_CONCRETE,
147 group_name="concrete")
148 meshJobParameterList.append(param)
149 return meshJobParameterList
152 # =======================================================================
153 # Prepare the job parameters and initialize the job
154 # =======================================================================
157 # Choose here the use case
158 #meshJobParameterList = test00_parameters()
159 #meshJobParameterList = test01_parameters()
160 #meshJobParameterList = test02_parameters()
161 meshJobParameterList = test03_parameters()
164 # Prepare, start and follow-up the job
166 jobid = component.initialize(meshJobParameterList, configId)
168 msg = component.getLastErrorMessage()
175 state = component.getState(jobid)
176 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
177 if state == "CREATED":
184 # =======================================================================
185 # Submit the job and start the supervision
186 # =======================================================================
188 # Start the execution of the job identified by its job id.
190 ok=component.start(jobid)
192 msg = component.getLastErrorMessage()
196 print "job started: %s"%ok
199 # This part illustrates how you can follow the execution of the job.
201 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
202 end_states = ["FINISHED", "ERROR"]
203 all_states = run_states+end_states;
208 state = component.getState(jobid)
209 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
210 if state not in run_states:
215 if state not in end_states:
216 print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
217 msg = component.getLastErrorMessage()
220 print "OK: jobid = "+str(jobid)+" ended with state="+str(state)
221 meshJobResults = component.finalize(jobid)
223 if meshJobResults.status is not True:
224 print "ERR: the results are not OK: %s"%component.getLastErrorMessage()
225 print "ERR: see log files in %s"%meshJobResults.results_dirname