Vous êtes sur la page 1sur 4

Compiling, linking and Debugging ABAQUS User-Subroutines

By: Hossein Talebi


This report is not fully complete; if you have questions, drop me an email and I'll try to help.
Download attachment from the link.
In this report I explain how to create and debug user subroutines for the ABAQUS finite element package. I will
show how you can write complicated user subroutines with a modern Fortran style rather than old FORTRAN77
style. There is recent topic on this in iMechanica for Windows but here I try to elaborate more and make it easier
and faster plus some more runtime checking on the data.
This report is for beginners.
Step 1: Setting up ABAQUS:
Before anything, check if your ABAQUS installation works properly. To do this, in Linux go to a any terminal
environment and in Windows use Command Prompt (cmd.exe) or the Wndows Power Shell which is much
better version of command prompt.
In Linux type the command below and this should invoke ABAQUS CAE.
/<path-to-abaqus>/abaqus/Commands_6.11-2/abaqus cae
And in Windows:
C:\Users\hosseinusername>c:\SIMULIA\Abaqus\Commands\abaqus cae
You need to determine the path to your Abaqus installation in case different.
Step 2: Setting up the Intel Fortran Compiler
To compile and link you ABAQUS user subroutine you need the Intel Fortran compiler version 11.1. However,
as I tested Intel 12.1 also works; but this is not confirmed by ABAQUS support. In both Windows and Linux,
once you are in the Terminal after you type
ifort -V
you should get the following message on the screen:
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R)
64, Version 12.1 Build 20120612
In case your Intel Fortran compiler is not properly installed or the environment variables are not set correctly,
you need to do so. Please refer to the Intel Compiler documentation on this. (this is not necessary)
In Linux, one method that I personally like and use is using the Modulecmd. The Modulecmd will prepare the
environment variables correctly. Thus, you can easily load and unload environment variables based on your
needs. For example you can do something like:

module load intel_12XE


to load the variables used to run Intel compiler version 12XE. Please refer here (http://modules.sourceforge.net/)
for the program.
Step 3: Using Codeblocks with Fortran Plugin (CB::F)
To edit and compile your code easily, you can use Codeblocks with Fortran plugin which is an IDE. You can still
use any other tool but you will see that this makes your life much easier. To do this, download the suitable CB::F
version from (http://darmar.vgtu.lt/) in this website there is also clear tutorials on how to set up and create
Fortran projects. Since we are using Intel Fortran compiler, run Codeblocks from the same terminal that ifort
works. Then set up a minimum Fortran project with one main.f90. You should be able to simply compile and run
this project from the IDE (picture below).

Step 4: Set up Library Project for Codeblocks


In this step, you need to create a Static library project for your user subroutine. After creation of this project, you
will compile and link all of the files related to your user subroutine in one file. Later, you can also create an
executable project and send some sample input data to your subroutine to see if you can get the right answer.
This way, you can use the runtime checking of the variables for different problems using the Intel Compiler.

From here I continue with an example from Abaqus itself and try to run it in a modern way.
I took this example from Abaqus Verification Manual, 4.1.14_UEL. Suppose my working directory is
"/home/hosseinuser/test/MY-uel/abq-example". I need 3 files in this directory.
1) uelnonli.inp : which is my input file
2) uelnonli.f : which is contains my user subroutine
3) abaqus_v6.env: which contains the environment variables that Abaqus uses to compile and link
the user subroutines. Later I will have to change this file. I also make a folder called "lib" inside this working
directory. Then I created a CB::F Static library project inside this "lib" folder. Then, when I push the compile
button, it will create me
/home/hosseinuser/test/MY-uel/abq-example/lib/home/qiju9410/test/MY-uel/abq-example/lib/libabq-uelCB.a
which is an static library. The example from Abaqus manual defines "IMPLICIT" definitions which is bad
programming practice. What I did was that I created a subroutine named "myuel" inside my static project library.
Then, I defined "implicit none" and carefully defined all the variables inside this routine. Finally, inside the
actual user subroutine "uelnonli.f " I call "myuel". This way, Abaqus will call the new user subroutine from the
old one but everything is fully defined. You can find the project files and source files attached to this page.
Step 5: Modify the "abaqus_v6.env" file
abaqus_v6.env contains information about how Abaqus compiles and links you user subroutines to it. One can
do pretty complicated stuff in here. However, we only like to tell Abaqus to link our Static library while
compiling the user subroutine "uelnonli.f ". abaqus_v6.env can be normally found in /<Abaqus installation
dir>/abaqus/6.11-2/site/ . However this might be different for you. You can search inside you Abaqus installation
directory though. After finding this file copy it to our working directory above.
Open the abaqus_v6.env and in two places you need to add PATH to our static library where it says "link_sl"
and "link_exe".
link_sl = (fortCmd +
" -cxxlib -fPIC -threads -shared "
+
"%E -Wl,-soname,%U -o %U %F %A %L %B -parallel -Wl,-Bdynamic " +
"-i-dynamic -lifport -lifcoremt /home/hosseinuser/test/MY-uel/abq-example
/lib/libabq-uelCB.a")
link_exe = (cppCmd + " -cxxlib -fPIC " +
"-Wl,-Bdynamic -i-dynamic -o %J %F %M %L %B %O -lpthread
/home/hosseinuser/test/MY-uel/abq-example/lib/libabq-uelCB.a ")
As you see I just added "/home/hosseinuser/test/MY-uel/abq-example/lib/libabq-uelCB.a" to
the end of the commands.
Step 6: Call Abaqus with idb
Now, everything is ready to call Abaqus. To you need to enter the command below to invoke Abaqus and the
Intel Debugger.

<path to Abaqus>/abaqus/Commands_6.11-2/abaqus job=MYJOB inp=uelnonli


-standard idb

user=uelnonli.f -debug

Now you can see something like the picture below:

You can put a pause command in your user subroutines or simply push the "play" and quickly "pause" button up
there and your source files will appear. The you can debug, watch and change the variables.
Step 7: Debugging with variable chacking without Abaqus
One problem that I encountered was that when I changed my source files, and stopped and executed idb again, I
could not find the source files again. This is because Abaqus uses some scratch directories which change.
Therefore, every time you change something in your source files, you need to close and run again with the
debugger. To make things faster, you can simply make another Fortran console project with a main file. This can
be compiled and run independent of Abaqus. Then, you can simulate what Abaqus gives to your user-subroutine
with the main file. This way you can quickly run and debug your routine for programming mistakes.
There are also some compiler options for the intel compiler and it will do all the variable, pointer, allocation,
initialization etc. checks. You can add the following options to your Codeblocks project:
-O0 -debug -traceback -check all -ftrapuv
I have already activated some of these in the sample project file. So, finally you can add many subroutines,
Fortran modules and even C/C++ files to your Fortran project and link it to Abaqus.

Vous aimerez peut-être aussi