1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2012 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.
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
20 # Author(s): Guillaume Boulant (23/03/2011)
23 # This script illustrates the standard use case of the component
24 # MeshJobManager from within a SALOME script. It could be used as a
25 # unit test of the component. The typical procedure is:
26 # $ <appli>/runAppli -t
27 # $ <appli>/runSession </path/to>/usecase_meshJobManager.py
30 # =======================================================================
31 # Preparing the configuration parameters
32 # =======================================================================
37 from salome.smesh.spadder.configreader import ConfigReader, printConfig, getPadderTestDir
39 configReader = ConfigReader()
40 defaultConfig = configReader.getDefaultConfig()
41 printConfig(defaultConfig)
43 from salome.smesh import spadder
49 # Setup the configuration in the component. We first have to load the
50 # catalog of SPADDER components, then load the component
51 # MeshJobManager, and finally configure this component.
53 spadder.loadSpadderCatalog()
56 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
57 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
58 binpath=defaultConfig.binpath,
59 envpath=defaultConfig.envpath)
61 configId = "localhost"
62 component.configure(configId,config)
66 # =======================================================================
67 # Define several datasets for the different use cases
68 # =======================================================================
71 # We define several functions that create each a dataset of med files
72 # for testing the component. The test function number corresponds to
73 # the number of the test defined in the SpherePadder installation
75 PADDERTESTDIR = getPadderTestDir(defaultConfig)
76 #PADDERTESTDIR = spadder.getTestPadderDataDir()
78 # WARN: the above instruction (spadder.getTestPadderDataDir())
79 # localizes the PADDERTEST DIR using the PADDERDIR shell variable,
80 # while the previous one (getPadderTestDir) localizes this directory
81 # from data of the config (read from the configuration file
84 def test00_parameters():
85 """Test using a concrete mesh and a single steelbar mesh"""
86 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
87 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
89 meshJobParameterList = []
90 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
91 file_type=MESHJOB.MED_CONCRETE,
92 group_name="concrete")
93 meshJobParameterList.append(param)
95 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
96 file_type=MESHJOB.MED_STEELBAR,
97 group_name="steelbar")
98 meshJobParameterList.append(param)
99 return meshJobParameterList
101 def test01_parameters():
102 """One concrete mesh and two steelbar meshes"""
103 datadir = os.path.join(PADDERTESTDIR,"test01")
104 meshJobParameterList = []
106 medfile = os.path.join(datadir,"concrete.med")
107 param = MESHJOB.MeshJobParameter(file_name=medfile,
108 file_type=MESHJOB.MED_CONCRETE,
109 group_name="concrete")
110 meshJobParameterList.append(param)
112 medfile = os.path.join(datadir,"ferraill.med")
113 param = MESHJOB.MeshJobParameter(file_name=medfile,
114 file_type=MESHJOB.MED_STEELBAR,
115 group_name="ferraill")
116 meshJobParameterList.append(param)
118 medfile = os.path.join(datadir,"ferrtran.med")
119 param = MESHJOB.MeshJobParameter(file_name=medfile,
120 file_type=MESHJOB.MED_STEELBAR,
121 group_name="ferrtran")
122 meshJobParameterList.append(param)
124 return meshJobParameterList
126 def test02_parameters():
127 """One steelbar mesh only, without a concrete mesh"""
128 datadir = os.path.join(PADDERTESTDIR,"test02")
129 meshJobParameterList = []
131 medfile = os.path.join(datadir,"cadreef.med")
132 param = MESHJOB.MeshJobParameter(file_name=medfile,
133 file_type=MESHJOB.MED_STEELBAR,
135 meshJobParameterList.append(param)
136 return meshJobParameterList
138 def test03_parameters():
139 """One concrete mesh only, without a steelbar mesh"""
140 datadir = os.path.join(PADDERTESTDIR,"test03")
141 meshJobParameterList = []
143 medfile = os.path.join(datadir,"concrete.med")
144 param = MESHJOB.MeshJobParameter(file_name=medfile,
145 file_type=MESHJOB.MED_CONCRETE,
146 group_name="concrete")
147 meshJobParameterList.append(param)
148 return meshJobParameterList
151 # =======================================================================
152 # Prepare the job parameters and initialize the job
153 # =======================================================================
156 # Choose here the use case
157 #meshJobParameterList = test00_parameters()
158 #meshJobParameterList = test01_parameters()
159 #meshJobParameterList = test02_parameters()
160 meshJobParameterList = test03_parameters()
163 # Prepare, start and follow-up the job
165 jobid = component.initialize(meshJobParameterList, configId)
167 msg = component.getLastErrorMessage()
174 state = component.getState(jobid)
175 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
176 if state == "CREATED":
183 # =======================================================================
184 # Submit the job and start the supervision
185 # =======================================================================
187 # Start the execution of the job identified by its job id.
189 ok=component.start(jobid)
191 msg = component.getLastErrorMessage()
195 print "job started: %s"%ok
198 # This part illustrates how you can follow the execution of the job.
200 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
201 end_states = ["FINISHED", "ERROR"]
202 all_states = run_states+end_states;
207 state = component.getState(jobid)
208 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
209 if state not in run_states:
214 if state not in end_states:
215 print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
216 msg = component.getLastErrorMessage()
219 print "OK: jobid = "+str(jobid)+" ended with state="+str(state)
220 meshJobResults = component.finalize(jobid)
222 if meshJobResults.status is not True:
223 print "ERR: the results are not OK: %s"%component.getLastErrorMessage()
224 print "ERR: see log files in %s"%meshJobResults.results_dirname