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.
28 # =======================================================================
29 # Preparing the configuration parameters
30 # =======================================================================
35 from salome.smesh.spadder.configreader import ConfigReader, printConfig
37 configReader = ConfigReader()
38 defaultConfig = configReader.getDefaultConfig()
39 printConfig(defaultConfig)
41 from salome.smesh import spadder
47 # Setup the configuration in the component. We first have to load the
48 # catalog of SPADDER components, then load the component
49 # MeshJobManager, and finally configure this component.
51 spadder.loadSpadderCatalog()
54 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
55 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
56 binpath=defaultConfig.binpath,
57 envpath=defaultConfig.envpath)
59 configId = "localhost"
60 component.configure(configId,config)
64 # =======================================================================
65 # Define several datasets for the different use cases
66 # =======================================================================
69 # We define several functions that create each a dataset of med files
70 # for testing the component. The test function number corresponds to
71 # the number of the test defined in the SpherePadder installation
74 def test00_parameters():
75 """Test using a concrete mesh and a single steelbar mesh"""
76 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
77 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
79 meshJobParameterList = []
80 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
81 file_type=MESHJOB.MED_CONCRETE,
82 group_name="concrete")
83 meshJobParameterList.append(param)
85 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
86 file_type=MESHJOB.MED_STEELBAR,
87 group_name="steelbar")
88 meshJobParameterList.append(param)
89 return meshJobParameterList
91 def test01_parameters():
92 """One concrete mesh and two steelbar meshes"""
93 datadir = os.path.join(spadder.getTestPadderDataDir(),"test01")
94 meshJobParameterList = []
96 medfile = os.path.join(datadir,"concrete.med")
97 param = MESHJOB.MeshJobParameter(file_name=medfile,
98 file_type=MESHJOB.MED_CONCRETE,
99 group_name="concrete")
100 meshJobParameterList.append(param)
102 medfile = os.path.join(datadir,"ferraill.med")
103 param = MESHJOB.MeshJobParameter(file_name=medfile,
104 file_type=MESHJOB.MED_STEELBAR,
105 group_name="ferraill")
106 meshJobParameterList.append(param)
108 medfile = os.path.join(datadir,"ferrtran.med")
109 param = MESHJOB.MeshJobParameter(file_name=medfile,
110 file_type=MESHJOB.MED_STEELBAR,
111 group_name="ferrtran")
112 meshJobParameterList.append(param)
114 return meshJobParameterList
116 def test02_parameters():
117 """One steelbar mesh only, without a concrete mesh"""
118 datadir = os.path.join(spadder.getTestPadderDataDir(),"test02")
119 meshJobParameterList = []
121 medfile = os.path.join(datadir,"cadreef.med")
122 param = MESHJOB.MeshJobParameter(file_name=medfile,
123 file_type=MESHJOB.MED_STEELBAR,
125 meshJobParameterList.append(param)
126 return meshJobParameterList
128 def test03_parameters():
129 """One concrete mesh only, without a steelbar mesh"""
130 datadir = os.path.join(spadder.getTestPadderDataDir(),"test03")
131 meshJobParameterList = []
133 medfile = os.path.join(datadir,"concrete.med")
134 param = MESHJOB.MeshJobParameter(file_name=medfile,
135 file_type=MESHJOB.MED_CONCRETE,
136 group_name="concrete")
137 meshJobParameterList.append(param)
138 return meshJobParameterList
141 # =======================================================================
142 # Prepare the job parameters and initialize the job
143 # =======================================================================
146 # Choose here the use case
147 #meshJobParameterList = test00_parameters()
148 #meshJobParameterList = test01_parameters()
149 #meshJobParameterList = test02_parameters()
150 meshJobParameterList = test03_parameters()
153 # Prepare, start and follow-up the job
155 jobid = component.initialize(meshJobParameterList, configId)
157 msg = component.getLastErrorMessage()
164 state = component.getState(jobid)
165 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
166 if state == "CREATED":
173 # =======================================================================
174 # Submit the job and start the supervision
175 # =======================================================================
177 # Start the execution of the job identified by its job id.
179 ok=component.start(jobid)
181 msg = component.getLastErrorMessage()
185 print "job started: %s"%ok
188 # This part illustrates how you can follow the execution of the job.
190 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
191 end_states = ["FINISHED", "ERROR"]
192 all_states = run_states+end_states;
197 state = component.getState(jobid)
198 print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
199 if state not in run_states:
204 if state not in end_states:
205 print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
206 msg = component.getLastErrorMessage()
209 print "OK: jobid = "+str(jobid)+" ended with state="+str(state)
210 meshJobResults = component.finalize(jobid)
212 print "You will find the results files in the directory:\n%s"%meshJobResults.results_dirname