Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit a job, wait for its completion and after submit another job

Tags:

python

abaqus

I need to run multiple times the same abaqus .inp file (slightly changed within runs) and after each run ends I need to submit a abaqus python script that will read the results.

I've done the following:

#run the programme
os.system('abaqus job=file_name cpus=2')

#get results and write them to myresults.txt
os.system('abaqus viewer noGUI=python_name.py')

However, the main program executes the second line before the program started in the first line ends. As a result I get an error. How can I solve this?

like image 521
jpcgandre Avatar asked Mar 11 '12 19:03

jpcgandre


3 Answers

I guess the problem here is not about subprocess waiting (indeed it waits) but the fact that after running the solver, Abaqus takes some seconds to delete some temp files and close its odb. I suggest one of the following:

  • run the solver from the command line with 'interactive' as @glenn_gould proposed

    strCommandLine = 'abaqus interactive job=jobname'  
    subprocess.call(strCommandLine)
    
  • run an abaqus python script

    strCommandLine = 'abaqus python ScriptToRun.py -- (jobname)'  
    subprocess.call(strCommandLine)
    

    and within ScriptToRun.py use waitForCompletion() as @ellumini proposed

    from abaqus import *
    import job
    import sys
    
    jobname = mdb.JobFromInputFile(sys.argv[-1], sys.argv[-1]+".inp") 
    jobname.submit() 
    jobname.waitForCompletion()
    
  • use a try statement to run while file jobname.023 or jobname.lck exist, something like:

    strCommandLine = 'abaqus job=jobname'  
    subprocess.call(strCommandLine)
    
    while os.path.isfile('jobname.023') == True:
        sleep(0.1)
    

This was my first post in this magnificent community, I'd be glad to know if I did something wrong.

like image 87
Francisco Cruz Avatar answered Nov 03 '22 00:11

Francisco Cruz


I think you need system('abaqus job=inputfile.inp interactive')

interactive does not consider the system command finished until abaqus has finished running.

Without interactive abaqus runs in the background while the system command is over and we have moved to the next one which is what we do not want.

like image 22
glenn_gould Avatar answered Nov 02 '22 23:11

glenn_gould


Take a look at the subprocess module. The call methods waits until the process is finished. You can also get a much better control over the child process than using os.system().

like image 43
El Barto Avatar answered Nov 03 '22 01:11

El Barto