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?
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.
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.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With