Building OOFEM clone in CLion and configuring Python interpreter

 A) Building the project

CLion automatically detects CMakeLists.txt and loads the source files, the remaining process is easy:

  1. (This is for Linux, For MacOS skip this) First, install Doxygen and Python:
    sudo apt-get install doxygen
    For the next part also install python
    sudo apt install python3-pip
  2. Below the menu from the drop-down select “oofem|Debug”.
    • If you don’t see this option in the drop-down, CLion has not detected the CMake profiles properly. In this case, close CLion, restart, then open the project in CLion again and from the file menu, select “Reload CMake project”.
  3. Press the build button (hammer). The build process starts, confirm it finishes successfully. CLion automatically creates the binary files directory and excludes it from Git (that’s why they appear in red color).

B) Some parts of OOFEM are written in Python. Before continuing make sure you have the python interpreter in your machine, (for Linux see A-1 above, for MacOS, it comes with Python interpreter out of the box).

Now it’s time to set up the Python interpreter for CLion, steps may be slightly different depending on the version of CLion:

  1. Go to File>Setting>Build, Execution, Deployment>Python Interpreter>Gear Button>Add…
    (For MacOS: CLion>Preferences>Build, Execution, Deployment>Python Interpreter>Gear>Add…)
    in the new window press OK to add a new environment

2. If “Python packaging tools not found.” message appears, click “install packaging tools” wait until setuptools appear then select it

Installed packages shown in Python Interpreter dialog box

3. click + and Search “numpy” and install it and confirm the message:
“Package ‘numpy’ installed successfully” > you can close “Available Packages” window and press OK in the “Python Interpreter” settings to confirm the changes.

Install NumPy from the Available Packages

TIP: Installing the NumPy package requires downloading about 17MB. If you got some warning such as
Failed to Install 'numpy'
or
WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available. You should consider upgrading via...“,
in that case, try to resolve the problem accordingly then try installing NumPy again.

Running Python scripts

Python scripts are used for tasks such as translating mesh files to OOFEM format (unv2oofem script) or extracting reactions (extractor script).

To run Python scripts, you simply select them in the run/debug configuration list. If you don’t see Python scripts in the run/debug configurations, press the left shift on the keyboard twice to open the search tool and type the name of a python script e.g. “extractor.py”, then open the file from the search dialog and run it by right-clicking on the tab of the py file and selecting “Run ‘[script’s name]'”. The script will remain in the running configuration list in the future.

extractor python script selected in the run configuration
The double shift is the keyboard shortcut for the general search tool
Open the search tool (left shift twice) and search for extractor.py or unv2oofem.py
Right-click on the tab of the opened script file and choose Run ‘filename’

Repeat the procedure for “unv2oofem.py” to add it to the run/debug list.

You can now run one of the python scripts of OOFEM such as extractor and unv2oofem to see if they run successfully by selecting them in the running drop-down menu.

If you run the script once for the first time, CLion will keep them in the run configurations for easy future runs

2 thoughts on “Building OOFEM clone in CLion and configuring Python interpreter

Leave a comment

Design a site like this with WordPress.com
Get started