Monthly Archives: December 2013

Adding a new class in OOFEM using ECLIPSE

Let’s say that we want to implement a new material behaviour or a new element behaviour in OOFEM. For this purpose, we usually need to write our code in two separate files, one .h file and one .C file. The .h file contains the headers of our code and the .C file contains the main code that defines the behaviour of our material or our element.
Therefore, the first step is creating two files in our project. Let’s imagine that we are writing code related to Structural Mechanics, then we will create these files in the “sm” folder of our project. To do that, find your project in the Project Explorer and open the tree in [Source directory]. Now, open the subtree in src, right click on the sm folder and select New –> Header file. The following windows will pop up:
Type the name of your new file and repeat the process to create a .C file selecting New –> Source file.
Now you can start typing your code. Once you want to start making it work, there are a couple of things you need to do:
  1. Make OOFEM aware of your new class. To do this, find your project in the Project Explorer and go to [Source directory]–>src–>sm and open the CMakeLists.txt, which you will usually find at the end of the sm folder. There, you must include the name of your .C file, including the extension. To do this, find a logical way to place it (you will see that the file has a certain structure, try to respect it).
  2. Build your project again. To do this, just right click on the name of your project in the Project Explorer and click Build Project. That’s it!

Configuring OOFEM in ECLIPSE

Why this post?

Martin Horak helped me to work with Visual Studio (VS) to work with OOFEM. Following his helpful tips I could do the following tasks with VS:

  • Run OOFEM from VS
  • Debug OOFEM from VS, with very nice tools: highlighting, binding, etc…

I experimented some problems when trying to write my first set of code working under Windows, for example, I couldn’t build OOFEM including LAPACK libraries, while this is pretty straightforward in Linux. This, and also because Linux has some other advantages respect to Windows, I decided to try to configure ECLIPSE to do what I could do with VS.

After struggling with this for several days, I finally could set a configuration that works perfectly (in my case) to run and debug OOFEM under Eclipse, with the same features I enjoyed in VS.

The following steps describe briefly how to do this. The instructions I found useful to do what you can find here where obtained in this link.

All this said, let’s got for it:

Configuring OOFEM in ECLIPSE

  1. Before opening ECLIPSE, we need to run cmake to generate all the files that the command make will later need to build OOFEM. To do this, you have to run the following command from the folder where you want to build OOFEM (in this example, the source files are considered to be in ~/OOFEM/oofem.git):


cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ~/OOFEM/oofem.git

With -G”Eclipse CDT4 – Unix Makefiles” we are telling cmake to use the Eclipse CDT4 build system generator and we need to specify “-D CMAKE_BUILD_TYPE=Debug” if we want to debug OOFEM with gdb inside ECLIPSE.

After this, cmake will generate not only the files that make will need to build OOFEM, but also a .cproject and a .project file that can be imported directly from ECLIPSE.

  1. Open ECLIPSE and import the files that cmake has created:

    File → Import → Existing Projects into Workspace

    In Select root directory, specify where the .cproject and the .project files are.

  1. Now we have our project created and only need to build it. To do so, in the Project Explorer, we just have to right-click on the name of the project and select Build Project. After building it, we have a completely operative OOFEM ready to be run and debugged in Eclipse!

Configuring the run/debug modes

The following applies both to the run mode and to the debug mode:

  1. Open the Run/Debug configurations (→ Run → Run Configurations…/ Debug Configurations…) and, on the list displayed on the left, select your project under C/C++ Application.

  2. In the tab Main:

  • In Project:, click Browse… and select your project (e.g. OOFEM)

  • In C/C++ Aplication:, click Browse… and specify where the .exe file of OOFEM is (it will be in the folder where you have built OOFEM, named “oofem”)

  1. In the tab Arguments

  • In program arguments, specify the arguments of your OOFEM launch (e.g. “-f nameoftheinputfile.in”)

  • In the working directory, click on File System… and specify where your input file is. The files generated during the execution of OOFEM will be place in this folder.

  1. Click Apply and you are done!

Why this blog?

I am enjoying a postdoc position in the Czech Technical University in Prague since September 2013. Since the department where I am working now has been developing OOFEM during the last 20 years or so, this situation has “forced” me to become familiar with OOFEM, which, by the way, has served me to get familiar with this great tool.

Therefore, I can say that I have started using OOFEM lately and have become really interested in it. OOFEM is a very powerful tool for those interested in the Finite Element Method, specially for researchers, since it allows you to use many interesting capabilities of it but also, and specially, because it is open source and, therefore, allows you to write your own code to perform some specific features that you might be interested in.

Not all is so perfect about OOFEM, though. All of us who start using it may find difficulties getting used to it, specially when one is interested in developing classes and functions that are not implemented yet in OOFEM. This is basically because it is powerful in many ways but not as friendly as a commercial software.

This blog is intended to help those who start using OOFEM and will be based on my personal experience. It will serve myself as a personal repository of issues that I will probably need to consult again in the future. I hope somebody else will find it useful.

Enjoy!