Back to index

salome-smesh  6.5.0
usecase_meshJobManager.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2011-2012  EDF R&D
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 # Author(s): Guillaume Boulant (23/03/2011)
00021 #
00022 
00023 # This script illustrates the standard use case of the component
00024 # MeshJobManager from within a SALOME script.
00025 
00026 
00027 #
00028 # Preparing the configuration parameters
00029 #
00030 import os
00031 from salome.smesh.spadder.configreader import ConfigReader, printConfig
00032 
00033 configReader = ConfigReader()
00034 defaultConfig = configReader.getDefaultConfig()
00035 printConfig(defaultConfig)
00036 
00037 from salome.smesh import spadder
00038 file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
00039 file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
00040 
00041 import salome
00042 import MESHJOB
00043 
00044 #
00045 # Setup the configuration in the component. When first have to load
00046 # the catalog of SPADDER components, then load the component
00047 # MeshJobManager, and finally configure this component.
00048 #
00049 spadder.loadSpadderCatalog()
00050 
00051 salome.salome_init()
00052 component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
00053 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
00054                                  binpath=defaultConfig.binpath,
00055                                  envpath=defaultConfig.envpath)
00056 component.configure("localhost",config)
00057 
00058 #
00059 # Prepare the job parameters and initialize the job
00060 #
00061 meshJobParameterList = []
00062 param = MESHJOB.MeshJobParameter(file_name=file_concrete,
00063                                  file_type=MESHJOB.MED_CONCRETE,
00064                                  group_name="concrete")
00065 meshJobParameterList.append(param)
00066 
00067 param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
00068                                  file_type=MESHJOB.MED_STEELBAR,
00069                                  group_name="steelbar")
00070 meshJobParameterList.append(param)
00071 jobid = component.initialize(meshJobParameterList, "localhost")
00072 
00073 #
00074 # Start the execution of the job identified by its job id.
00075 #
00076 ok=component.start(jobid)
00077 
00078 #
00079 # This part illustrates how you can follow the execution of the job.
00080 #
00081 run_states = ["CREATED", "IN_PROCESS", "QUEUED", "RUNNING", "PAUSED"];
00082 end_states = ["FINISHED", "ERROR"]
00083 all_states = run_states+end_states;
00084 
00085 ended  = False
00086 nbiter = 0
00087 import time
00088 while not ended:
00089     state = component.getState(jobid)
00090     print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
00091     if state not in run_states:
00092         ended=True
00093     time.sleep(0.5)
00094     nbiter+=1
00095         
00096 if state not in end_states:
00097     print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
00098 else:
00099     print "OK:  jobid = "+str(jobid)+" ended with state="+str(state)
00100     meshJobResults = component.finalize(jobid)
00101     print meshJobResults
00102     print "You will find the results files in the directory:\n%s"%meshJobResults.results_dirname