Salome HOME
Update copyright information
[modules/smesh.git] / src / Tools / padder / unittests / usecase_meshJobManager.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2012  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author(s): Guillaume Boulant (23/03/2011)
21 #
22
23 # This script illustrates the standard use case of the component
24 # MeshJobManager from within a SALOME script.
25
26
27 #
28 # Preparing the configuration parameters
29 #
30 import os
31 from salome.smesh import spadder
32 pathpadderexe=os.path.join(spadder.getTestDataDir(),"padder.exe")
33 pathpadderenv=os.path.join(spadder.getTestDataDir(),"envPadder.sh")
34 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
35 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
36
37 import salome
38 import MESHJOB
39
40 #
41 # Setup the configuration in the component. When first have to load
42 # the catalog of SPADDER components, then load the component
43 # MeshJobManager, and finally configure this component.
44 #
45 from salome.smesh import spadder
46 spadder.loadSpadderCatalog()
47
48 salome.salome_init()
49 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
50 config = MESHJOB.ConfigParameter(resname="localhost",
51                                  binpath=pathpadderexe,
52                                  envpath=pathpadderenv)
53 component.configure("localhost",config)
54
55 #
56 # Prepare the job parameters and initialize the job
57 #
58 meshJobParameterList = []
59 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
60                                  file_type=MESHJOB.MED_CONCRETE,
61                                  group_name="concrete")
62 meshJobParameterList.append(param)
63
64 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
65                                  file_type=MESHJOB.MED_STEELBAR,
66                                  group_name="steelbar")
67 meshJobParameterList.append(param)
68 jobid = component.initialize(meshJobParameterList, "localhost")
69
70 #
71 # Start the execution of the job identified by its job id.
72 #
73 component.start(jobid)
74
75
76 #
77 # This part illustrates how you can follow the execution of the job.
78 #
79 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
80 end_states = ["FINISHED", "ERROR"]
81 all_states = run_states+end_states;
82
83 ended  = False
84 nbiter = 0
85 import time
86 while not ended:
87     state = component.getState(jobid)
88     print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
89     if state not in run_states:
90         ended=True
91     time.sleep(0.5)
92     nbiter+=1
93         
94 if state not in end_states:
95     print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
96 else:
97     print "OK:  jobid = "+str(jobid)+" ended with state="+str(state)
98     meshJobResults = component.finalize(jobid)
99     print meshJobResults
100     print "You will find the results files in the directory:\n%s"%meshJobResults.results_dirname