4.3 Examples

The examples included in this section illustrate various uses of the Abaqus environment file.


4.3.1 Example environment file

An example Windows environment file is shown below. This file will work on Linux systems as well if you change the scratch directory setting appropriately. A sample environment file, abaqusinc.env, is included in the solvers_install_dir/os/SMA/site/ subdirectory of the Abaqus/CAE installation to show the options used at SIMULIA.

    scratch = "c:/temp"
    if applicationName in ('analysis','datacheck','continue'):
        memory = "4 gb"
    
    def onCaeStartup():
        #Graphics preferences
        session.graphicsOptions.setValues(dragMode=AS_IS, displayLists=ON)
        # Print preferences
        session.printOptions.setValues(vpDecorations=OFF,
            vpBackground=OFF, rendition=COLOR,
            printCommand='lpr -S marley -P hp3')
        session.psOptions.setValues(date=OFF)
        # Job preferences
        def setJobPreferences(module, userData):
             session.Queue(name='long', hostName='server',
                queueName='large', directory='/tmp')
        addImportCallback('job', setJobPreferences)
        # Visualization preferences
        def setVisPreferences(module, userData):
            session.defaultOdbDisplay.contourOptions.setValues(
                renderStyle=SHADED, visibleEdges=EXTERIOR,
                contourStyle=CONTINUOUS)
        addImportCallback('visualization', setVisPreferences)
The default compile and link environment variables for your computer have also been inserted in your site environment file.


4.3.2 Notifying users when a job is completed

The following is an example of how environment file commands can be used to notify Linux system users when their job is finished. The notification method used depends on how the job was run and if the user is logged in. If the job was run interactively, the user will not be notified that the job has finished. If the user is still logged in when the job completes, a message will be output to the screen. If the user has logged out by the time the job completes, a message will be mailed to the user. The syntax of the mail command varies from system to system. Please consult your system documentation to determine the appropriate commands.

    def onJobCompletion(): 
        import os, re
    
        userName = os.environ['USER']
        msg = 'Job %s has completed' % id
    
        # Run "who" command, pipe the output, and read into a list
        whopipe = os.popen('who', 'r')
        output = whopipe.readlines()
        whopipe.close()
     
        # Find out if the user is logged in
        loggedIn = 'no'
        terminal = [ ] 

        for line in output:
            columns = re.split('[ ]+', line) # Split into blank separated columns 
            name = columns[0]     # User name is in the first column
            if name == userName:
                terminal.append(columns[1]) # Terminal at which user is logged in                      
                loggedIn = 'yes'
        
        # Use "write" command if the user is logged in, use mail otherwise 
        if loggedIn == 'no':
           logFile = savedir + id + ".log"
           if os.path.exists(logFile):
              os.system('cat %s | Mail -s "%s" %s' % (logFile, msg, userName))
           else:
              os.system('Mail -s "%s" %s' % (msg, userName))
        else:
           for termNum in terminal:
              os.system('echo "%s" | write %s %s' % (msg, userName, termNum))


4.3.3 Customizing Abaqus/CAE startup

The following example for the onCaeStartup parameter will establish viewport preferences and print options (including a print command), set up a remote execution queue for running Abaqus jobs, and set preferences for contour plots in the Visualization module:

    def onCaeStartup():
    
        # Print preferences
        session.printOptions.setValues(vpDecorations=OFF,
            vpBackground=OFF, rendition=COLOR,
            printCommand='lpr -S server -P printer')
        session.psOptions.setValues(date=OFF, logo=OFF)
        
        def initQueues(*args):
            session.Queue(name='long', hostName='server',
               queueName='large', directory='/tmp')
        addImportCallback('job', initQueues)
    
        # Visualization preferences 
        def setVisPreferences(module, userData):
            import visualization
            session.defaultOdbDisplay.contourOptions.setValues(
               renderStyle=SHADED, visibleEdges=EXTERIOR,
               contourStyle=CONTINUOUS)
        addImportCallback('visualization', setVisPreferences)
Indented text must be valid Python commands. For more queue examples, see Chapter 19, The Job module,” of the Abaqus/CAE User's Guide.


4.3.4 Using a web browser not supported by Abaqus

Abaqus provides support only for the Firefox web browser on Linux platforms; however, it does provide the ability to use a web browser not supported by Abaqus for viewing HTML documentation. Examples are shown for setting the browser_type and browser_path system customization parameters in this situation.

The first example illustrates the parameter settings to specify a web browser not supported by Abaqus:

    browser_type = CUSTOM_BROWSER
    browser_path = ['full_path_to_browser', 'argument1', 'argument2', etc.]
where the first string contains the full path to the web browser and subsequent strings are arguments to customize the browser behavior. Refer to the specific web browser documentation for valid arguments.

The second example illustrates the parameter settings to specify the Opera browser (not supported by Abaqus) as the web browser:

    browser_type = CUSTOM_BROWSER
    browser_path = ['/usr/local/bin/opera', '-newwindow' '%s']
where /usr/local/bin/opera is the full path to the browser and the argument -newwindow opens a new browser window using the full uniform resource locator (URL) to the Abaqus HTML documentation. Use the argument -newpage to open a new page.

The third example illustrates the parameter settings to specify the Konqueror browser (not supported by Abaqus) as the web browser:

    browser_type = CUSTOM_BROWSER
    browser_path = '/opt/kde3/bin/konqueror'
where /opt/kde3/bin/konqueror is the full path to the browser. By default, a new browser window opens using the URL to the Abaqus HTML documentation.


4.3.5 Using predefined derived classes

The following example illustrates the instantiation of some predefined derived classes and their insertion into the queues dictionary:

    run_mode = BATCH
    from driverQueues import *
    queues['atq']    = AtQueue()
    queues['batchq'] = BatchQueue()
    queues['hold']   = HoldQueue()
To submit an analysis using one of the queues, specify the queue name as the value for the analysis execution procedure queue parameter.


4.3.6 Deriving and using custom queue classes

To derive a custom queue class, the driverQueues module must be imported and the class must inherit directly or indirectly from the Queue class. Derived queues must provide an implementation for the submit method. Derived class methods can raise exceptions as needed. The predefined QueueError exception is provided as a general-purpose exception.

The following examples illustrate the derivation and use of custom queue classes:

    run_mode = BATCH
    from driverQueues import *
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    class NiceQueue(Queue):
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        def __repr__(self):
            return 'Executes analysis using Linux nice command.'
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        def submit(self, options, env):
            job = options['job']
            after = options.get('after', '')
            verbose = options.get('verbose', 0)
            if options.get('after', ''):
                # a descriptive string must be supplied as data when
                # raising a QueueError exception
                #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                raise QueueError, \
                      '"after" is not a valid argument for this queue.'
            # run nice under bourne shell to eliminate platform dependencies
            cmd = "/bin/sh -c 'nice %s python ./%s.com 1>./%s.log 2>&1 &'" \
                  % (self.getDriverName(), job, job)
            return self.spawn(cmd, env, verbose)
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    class LSF_ResvQueue(LSFQueue):
        # For integration with LSF. This queue class supports cpu, memory,
        # and license reservations.
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        def __init__(self, name, memReserve=0, cpusReserve=0):
            LSFQueue.__init__(self, name)
            self.memReserve = memReserve
            self.cpusReserve = cpusReserve
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        def __repr__(self):
            return 'Submits to LSF %s queue (run "bqueues -l %s" for description)' \
                   % (self.name, self.name)
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        def submit(self, options, env):
            job = options['job']
            verbose = options.get('verbose', 0)
            queue = self.name
            cpus = options.get('cpus', '1')
            if self.cpusReserve:
                cpus = self.cpusReserve
            resLst = [ ]
            # license reservation - For the following line to work, LSF
            # must be configured with a static or dynamic resource called
            # "abqtokens".
            #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            resLst.append('abqtokens=%d' % self.getNumRequiredTokens(options))
            # memory reservation
            if self.memReserve:
                from math import ceil
                resLst.append('mem=%d' % int(ceil(self.memReserve/float(cpus))))
            resStr = ''
            if resLst:
                import string
                resStr = '-R rusage[%s]' % string.join(resLst, ':')
            bsub = 'bsub -q %s -J %s -n %s -o %s.log -N %s %s python %s.com' % \
                   (queue, job, cpus, job, resStr, self.getDriverName(), job)
            return self.spawn(bsub, env, verbose)
    # queue definitions
    queues['default']     = NiceQueue()
    queues['hold']        = HoldQueue()
    queues['benchmark']   = LSF_ResvQueue(name='benchmark', cpusReserve=16)
    queues['dedicated']   = LSF_ResvQueue(name='dedicated')
    queues['a500M']       = LSF_ResvQueue(name='a500M', memReserve=500)
    queues['a1500M']      = LSF_ResvQueue(name='a1500M', memReserve=1500)
    queues['a3000M']      = LSF_ResvQueue(name='a3000M', memReserve=3000)
    queues['a6000M']      = LSF_ResvQueue(name='a6000M', memReserve=6000)


4.3.7 Defining a string-based analysis batch queue

The following example illustrates the use of the environment file parameters for string-based analysis batch queue definition:

    try:
        queue_name=list(queue_name)
    except:
        queue_name = [ ]
    queue_name=queue_name + ["aba_short", "aba_long", "hold "]
    after_prefix="-a"
    queue_prefix="-q"
    queue_cmd="qsub -nr -me %P %Q %A %T -x -eo -o %L %S"
    aba_short="qsub -nr -me -q short %A %T -x -eo -o %L %S"
    aba_long="qsub -nr -me -q long %A %T -x -eo -o %L %S"
    hold="printf 'Job %S not submitted\n' " 
The qsub command used in this example is available only on certain computer systems. Other commands, such as at and batch, can be used to configure a queuing system on most Linux platforms. Please refer to your system documentation or contact your hardware vendor for information about queuing systems for your platform.

If the queue specified by the queue command line option matches one of the queue aliases in the queue_name parameter, that queue command is used in place of the default command queue_cmd. The following are legal command line options for the above example:

abaqus job=qt queue=normal
abaqus job=qt queue=aba_short after=10:00 
abaqus job=qt queue=hold

The first of these three command line options does not match a defined queue, so the queue_cmd string is used to submit the job to the normal queue. This queue must have been set up by the systems manager prior to submission of the job. The actual command used to send the job to the normal queue for execution on Linux platforms is

qsub -nr -me -q normal -x -eo -o qt.log qt.com
The value of %A is not output if after=time is not specified on the command line.

The second option uses the string defined by aba_short, which submits the job to the system predefined short queue. The command executed by the Linux platform is

qsub -nr -me -q short -a 10:00 -x -eo -o qt.log qt.com

The last command line option creates the file qt.com, which contains the Abaqus job commands, and saves it in the current directory. The message Job qt.com not submitted is then written to the terminal. The job is not submitted to any queue.


4.3.8 Locking out modifications to environment file parameters

In the example below, all Abaqus jobs will run in batch mode by default, and execution of Abaqus/Aqua jobs is not allowed. The inclusion of the admin parameter prevents modification of these settings in lower-level environment files. If this parameter is part of the environment file in the installation directory, the values of run_mode and no_aqua will override any corresponding values in a user's local directory or command line. Therefore, this example constrains all jobs submitted at your site to run in batch mode.

run_mode = BATCH
no_aqua = ON
admin = ['run_mode','no_aqua']
The no_aqua parameter would typically be used to provide a “friendly” message to users if Abaqus/Aqua is not licensed at your site.