Checking a model database when it is opened

If you have custom kernel scripts that use custom data in a model database, you may want your application to verify some of the contents of a model database before it is fully opened. For example, you may want to check the database to see if you need to upgrade the data that is stored in it. In addition, you may need to initialize a new model database with your custom data. Two methods are provided for verifying and initializing a model database: verifyMdb and initializeMdb.

Verifying a model database

The verifyMdb method is used to verify the partial contents of a model database when it is opened. You must write the verifyMdb method and install it using the setVerifyMdb method. You can call the setVerifyMdb method only once per application name, which prevents unauthorized changes to the method. However, the setVerifyMdb method may be called multiple times using different application names to allow more than one application to register with the same model database.

When Abaqus opens a model database, its first action is to load only the mdb.customData.appData object and pass that object to each verifyMdb method registered in the session. If the model database has no appData, then Abaqus passes None to each verifyMdb method. Inside your verifyMdb method you can query the appData object to determine if you need to take any action, such as upgrading your data.

Initializing a model database

If a script creates a new model database, you can initialize the model database with your custom objects using the initializeMdb method. Abaqus calls each initializeMdb method registered with the session whenever a new model database is created. You must write the initializeMdb method and install it using the setInitializeMdb method. You can call the setInitializeMdb method only once per application name, which prevents unauthorized changes to the method. However, the setInitializeMdb method may be called multiple times using different application names to allow more than one application to register with the same model database.

Kernel initialization scripts specified by the startup command line option are executed by Abaqus/CAE after it has finished its initialization process. By that time, a new model database or a database specified on the command line using the database option has already been opened. A utility method called processInitialMdb has been created to automatically process the initial model database for you. If the initial model database does not have any customData or does not have customData for your particular application, your initializeMdb method will be called. If the initial model database has customData for your application, your verifyMdb method will be called.

The following example shows how you can use the verifyMdb, intializeMdb, and processInitialMdb methods. You should execute the example using the startup command line option when you start Abaqus/CAE. For more information, see Abaqus/CAE execution.

from abaqus import mdb, session 
import customKernel  
myAppName = 'My App' 
myAppData = customKernel.AbaqusAppData()
myAppData.majorVersion = 1  
myAppData.minorVersion = 1  
myAppData.updateVersion = 1  
customKernel.setAppData(myAppName, myAppData)  
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def verifyMdb(mdbAppData): 
    # If there is no appData, initialize the MDB. 
    # 
    if mdbAppData==None: 
        initializeMdb() 
        return 
    # If my application is not in appData, initialize the MDB.
    #
    if not mdbAppData.has_key(myAppName):
        initializeMdb()
        return

    # Perform any checks on the appData or customData here

# Set the verifyMdb method for the application.
# setVerifyMdb may be called only once per application name.
#
customKernel.setVerifyMdb(myAppName, verifyMdb)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initializeMdb(): 
     # Initialize the MDB here


# Set the initializeMdb method for this application.
# setInitializeMdb may be called only once per application name.
#
customKernel.setInitializeMdb(myAppName, initializeMdb)

# This file is executed after Abaqus/CAE has started, so we need to 
# process the initial MDB (either a new, empty MDB created by Abaqus/CAE,
# or a database opened via the -database command line argument).
#
customKernel.processInitialMdb(myAppName)