Submit the work, wait until it is completed and after submitting another work

I need to run the same abaqus.inp file several times (slightly changed within the runs), and after each run ends, I need to send an abaqus python script that will read the results.

I have 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 starting the program in the first line. As a result, I get an error message. How can i solve this?

+4
source share
7 answers

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

interactive does not take into account that the system command is completed until abaqus finishes work.

Without interactive abaqus it runs in the background until the system command is complete and we moved on to the next one, which we don’t want.

+2
source

I assume that the problem here is not waiting for the subprocess (indeed, it is waiting), but that after starting the solver, Abaqus takes a few seconds to delete some temporary files and close its odb. I suggest one of the following:

  • run the solver from the command line using "interactive" as suggested by @glenn_gould

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

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

    and inside ScriptToRun.py use waitForCompletion () as suggested by @ellumini

     from abaqus import * import job import sys jobname = mdb.JobFromInputFile(sys.argv[-1], sys.argv[-1]+".inp") jobname.submit() jobname.waitForCompletion() 
  • use the try statement to run while the file name .023 or task_name exists, 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 great community, I would be happy to know if I did something wrong.

+4
source

Take a look at the subprocess module. call methods wait for the process to complete. You can also get much better control over the child process than with os.system() .

+1
source

The subprocess module was recommended in another answer. This is the officially recommended way to do this. However, a faster and simpler method (and also deprecated in Python 3, but still works fine in 2.x, so keep this in mind) is commands .

 import commands (return_code, output) = commands.getstatusoutput('abaqus job=file_name cpus=2') 
+1
source

About running in the background, are you sure it is?

This site suggests that os.system('abaqus job=file_name cpus=2') will work in the foreground.

Using Abaqus in Batch Mode To call the Abaqus system in batch mode, you must specify the file name in the Abaqus> command. For example, if you want myProg.inp to read:

abaqus job = myProg

(Note that no extension should follow the file name)

This command should start Abaqus in batch mode. The team will run the program in the foreground. If you want to run the program in the background, add an ampersand to the end of the command:

abaqus job = myProg &

Maybe there is a local configuration setting that forces background processing? If possible, you can add a switch to make sure that the processing is in the foreground.

+1
source

Try using subprocess , but without the os.call option. You can use this method to start Abaqus in the background:

 import subprocess path = location of file in any directory abaqusCall = 'abaqus job=file_name cpus=2' runCommand = 'cmd.exe /c ' + abaqusCall process = subprocess.Popen(runCommand, cwd=path) 

The problem with Abaqus is that it takes a long time to run the analysis, so if you try to run the file "python_name.py" to get the results, the program may get errors because the * .odb file is either not yet created or does not contain data requiring extraction.

You can use the command:

 process.wait() 

to tell Python to wait for Abaqus to complete the analysis before executing your "python_name.py", but this will cause your python (or GUI) command to hang until Abaqus is completed, which will take a long time.

One of the methods I use is to read the Abaqus * .sta file, which has solution time and progress. That way, you can write a sequence to read the file every 5 seconds, for example, and keep track of when the job ends before executing the result file.

Another trick for extracting data is that as long as you do not use (import) classes from the CAE module, you can run your Python script with this command:

 #get results and write them to myresults.txt os.system('abaqus python python_name.py') 
0
source

Not sure if you have already found a suitable solution, but the task object:

 Jobxy.waitForCompletion() 

waits for the task to complete, and then continues to run the pyhton script; for example, with message processing commands. See the abaqus scripts user guide for more information ...

0
source

Source: https://habr.com/ru/post/1400877/


All Articles