6.8 Interacting with ABAQUS/Standard and ABAQUS/Explicit

The Job commands include methods that allow you to submit jobs to ABAQUS/Standard and ABAQUS/Explicit. This section describes how you can interact with ABAQUS/Standard and ABAQUS/Explicit and synchronize your scripts with the analysis job. The following topics are covered:


6.8.1 Processing messages from ABAQUS/Standard and ABAQUS/Explicit

You can use the addMessageCallback method to associate an event-driven function with a particular message that is retrieved from ABAQUS/Standard or ABAQUS/Explicit. When ABAQUS/CAE retrieves the specific message from ABAQUS/Standard or ABAQUS/Explicit, the function executes and takes the necessary action. This type of function is called a callback function. The addMessageCallback method specifies which callback function to use for which message. The arguments to addMessageCallback are:

  • The name of the job to monitor for messages.

  • The message from ABAQUS/Standard or ABAQUS/Explicit that causes the callback function to execute.

  • The name of the callback function.

  • An object to pass to the callback function.

These arguments allow you to associate the callback function with both a particular job and a particular message. Alternatively, you can associate the callback function with all jobs and all messages. The commands are described in Chapter 28, Messaging commands,” of the ABAQUS Scripting Reference Manual.

The interface definition of the callback function is

def functionName(jobName, messageType, data, userData)
The arguments to the callback function are:
  • jobName: A String specifying the name of the job to be monitored. You can also use the SymbolicConstant ANY_JOB that specifies that the callback function will monitor messages from all jobs.

  • messageType: A SymbolicConstant specifying the message type that will call the callback function. You can also use the SymbolicConstant ANY_MESSAGE_TYPE that specifies that all messages will call the callback function. The following is a list of the message types issued by ABAQUS/Standard and ABAQUS/Explicit:

    • ABORTED

    • ANY_JOB

    • ANY_MESSAGE_TYPE

    • COMPLETED

    • END_STEP

    • ERROR

    • HEADING

    • HEALER_JOB

    • HEALER_TYPE

    • INTERRUPTED

    • ITERATION

    • JOB_ABORTED

    • JOB_COMPLETED

    • JOB_INTERRUPTED

    • JOB_SUBMITTED

    • MONITOR_DATA

    • ODB_FILE

    • ODB_FRAME

    • SIMULATION_ABORTED

    • SIMULATION_COMPLETED

    • SIMULATION_INTERRUPTED

    • SIMULATION_SUBMITTED

    • STARTED

    • STATUS

    • STEP

    • WARNING

  • data: A DataObject object containing the message data. The following list describes the members of the DataObject object:

    • clientHost: A String specifying the host name of the machine that is running the analysis.

    • clientName: A String specifying the name of the client that sent the message. Possible values are

      • “BatchPre” (the input file preprocessor)

      • “Packager” (the ABAQUS/Explicit preprocessor packager)

      • “Standard” (the ABAQUS/Standard analysis)

      • “Explicit” (the ABAQUS/Explicit analysis)

      • “Calculator” (the postprocessing calculator)

    • phase: A SymbolicConstant specifying the phase of the analysis. Possible values are

      • BATCHPRE_PHASE

      • PACKAGER_PHASE

      • STANDARD_PHASE

      • EXPLICIT_PHASE

      • CALCULATOR_PHASE

      • HEALER_PHASE

    • processId: An Int specifying the process ID of the analysis program.

    • threadId: An Int specifying the thread ID of the analysis program. Threads are used for parallel or multiprocessing; in most cases threadId is set to zero.

    • timeStamp: An Int specifying the time the message was sent in seconds since 00:00:00 UTC, January 1, 1970.

  • userData: Any Python object or None. This object is passed as the userData argument to addMessageCallback.

The following script is an example of how you can use the messaging capability of the ABAQUS Scripting Interface. The callback function will intercept all jobs from all messages from ABAQUS/Standard or ABAQUS/Explicit and print the messages in the ABAQUS/CAE command line interface. Use the following command to retrieve the example script:

abaqus fetch job=simpleMonitor
To execute the script, do the following:
  • From the ABAQUS/CAE command line interface type from simpleMonitor import printMessages

  • Submit an analysis job as usual.

  • To start printing the messages, type printMessages(ON) from the ABAQUS/CAE command line interface.

  • To stop printing the messages, type printMessages(OFF) from the ABAQUS/CAE command line interface.

"""
simpleMonitor.py

Print all messages issued during an ABAQUS 
analysis to the ABAQUS/CAE command line interface
"""

from abaqus import *
from abaqusConstants import *  
from jobMessage import ANY_JOB, ANY_MESSAGE_TYPE

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def simpleCB(jobName, messageType, data, userData):
    """
    This callback prints out all the
    members of the data objects
    """

    format = '%-18s  %-18s  %s'
    
    print 'Message type: %s'%(messageType)
    print
    print 'data members:'
    print format%('member', 'type', 'value')
    
    members =  dir(data)
    for member in members:
        memberValue = getattr(data, member)
        memberType = type(memberValue).__name__
        print format%(member, memberType, memberValue)
    
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def printMessages(start=ON):
    """
    Switch message printing ON or OFF
    """
    
    if start:
        monitorManager.addMessageCallback(ANY_JOB, 
            ANY_MESSAGE_TYPE, simpleCB, None)
    else:
        monitorManager.removeMessageCallback(ANY_JOB, 
            ANY_MESSAGE_TYPE, simpleCB, None)


6.8.2 Waiting for a job to complete

You can use the Job object's waitForCompletion method to synchronize your script with a job that has been submitted. If you call the waitForCompletion method after you submit a job, the script waits until the analysis is complete before continuing. When the script continues, you should check the status of the job to ensure that the job completed successfully and did not abort. For example, the script described in Reproducing the cantilever beam tutorial, Section 7.1, uses waitForCompletion to ensure that the analysis job has finished executing successfully before the script opens the resulting output database and displays a contour plot of the results.

You can use an optional timeOut argument with the waitForCompletion method. The timeOut argument specifies the time in seconds that the script should wait for the job to complete until the script continues. If the job has not completed before the interval specified by the timeOut argument, the waitForCompletion method throws an AbaqusException exception. You must include a try statement to catch the exception thrown by a time out.

myJob1.submit()
try:
    myJob1.waitForCompletion(6000)
except AbaqusException, message:
    print "Job timed out", message
If you do not provide a timeOut argument, the script will wait indefinitely for the job to complete.

In the following example, the script submits myJob1 and waits for it to complete before submitting myJob2.

myJob1 = mdb.Job(name='Job-1')
myJob2 = mdb.Job(name='Job-2')
myJob1.submit()
myJob1.waitForCompletion()
myJob2.submit()
myJob2.waitForCompletion()
If you submit more than one job and then issue a waitForCompletion statement, ABAQUS waits until the job associated with the waitForCompletion statement is complete before checking the status of the second job. If the second job has already completed, the waitForCompletion method returns immediately. In the following example the script will not check the status of myJob2 until myJob1 has completed.
myJob1 = mdb.Job(name='Job-1')
myJob2 = mdb.Job(name='Job-2')
myJob1.submit()
myJob2.submit()
myJob1.waitForCompletion()
myJob2.waitForCompletion()

If the job submission is delayed using either the at or wait arguments, the interval specified by the timeOut argument includes both the time required to wait and the time required to execute. It is possible for the waitForCompletion method to time-out before the job is submitted. If this occurs, the script continues, and the waitForCompletion method throws an exception to indicate that the job did not run to completion because of a time-out; however, the computer system will still submit the job. As a result, if you use the at argument, you should add statements that check the status of the job and proceed accordingly.


6.8.3 An example of a callback function

The following section describes how you can use a callback function as an alternative to the waitForCompletion method described in Waiting for a job to complete, Section 6.8.2. The example uses messaging commands to synchronize a script with an ABAQUS/Standard or ABAQUS/Explicit analysis. Messaging commands set up a callback function that monitors messages from ABAQUS/Standard and ABAQUS/Explicit. When the desired message is received, the callback function executes.

The example uses a callback function that responds to all messages from ABAQUS/Standard and ABAQUS/Explicit. The function decides what action to take based on the messages received from a job called Deform. If the message indicates that the analysis job is complete, the function opens the output database created by the job and displays a default contour plot.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define the callback function

from abaqus import *
from abaqusConstants import *

import visualization

def onMessage(jobName, messageType, data, viewport):
   if ((messageType==ABORTED) or (messageType==ERROR)):
       print 'Solver problem; stop execution of callback function'
   elif (messageType==JOB_COMPLETED):
       odb = visualization.openOdb(path=jobName + '.odb')
       viewport.setValues(displayedObject=odb)
       viewport.odbDisplay.setPlotMode(plotMode=CONTOUR)
     

The following statements show how the example script can be modified to use the callback function. After the first statement is executed, the callback function responds to all messages from the job named Deform. The final two statements create the job and submit it for analysis; the example script has now finished executing. When the job is complete, the callback function opens the resulting output database and displays a contour plot.

...
myJobName = 'Deform'
monitorManager.addMessageCallback(jobName='myJobName',
    messageType=ANY_MESSAGE_TYPE, callback=onMessage,
    userData=myViewport)
myJob = mdb.Job(name=myJobName, model='Beam',
    description=jobDescription)
myJob.submit()
# End of example script.

You can use the removeMessageCallback method at the end of the callback function to remove it from the system. The arguments to the removeMessageCallback method must be identical to the arguments to the corresponding addMessageCallback command that set up the callback function.