Installation/Linux/OpenFOAM-2.1.x/Ubuntu

From OpenFOAMWiki

1 Introduction

This page is dedicated to explaining how to install OpenFOAM OF Version 21x.png in Ubuntu.

If you do not yet feel comfortable using Linux, then perhaps you better first read the page Working with the Shell and train a bit with the shell/terminal environments, so you can have a better perception of the steps shown below.


2 Copy-Paste steps

A few notes before you start copy-pasting:

  1. Lines that start with # don't have to be copy-pasted. They are just comments to let you know what's going on.
  2. One wrong character is enough for breaking this guide, so make sure you can read the characters properly or that the installed language system does not break the copied characters!

2.1 Ubuntu 12.04

Here you have at least two choices:

  • You can install from source, by either:
    • Following the official instructions from here: Source Pack Installation
    • Or by following the detailed step-by-step instructions below...


Discussion thread where you can ask questions about these steps: No thread available. Please a create a new thread in the forum.

Steps:

  1. Switch to root mode (administrator), to install the necessary packages:
    sudo -s
    • If the 'sudo' command tells you're not in the sudoers list, then run:
      su -
  2. Install the necessary packages:
    apt-get install build-essential cmake flex bison zlib1g-dev qt4-dev-tools libqt4-dev gnuplot libreadline-dev \
    libncurses-dev libxt-dev libopenmpi-dev openmpi-bin git-core
  3. Now exit from the root mode:
    exit
  4. Download and unpack (here you can copy-paste all in single go):
    #OpenFOAM downloading and installation
    cd ~
    mkdir OpenFOAM
    cd OpenFOAM
    git clone https://github.com/OpenFOAM/OpenFOAM-2.1.x.git
    git clone https://github.com/OpenFOAM/ThirdParty-2.1.x.git

    But we will now have to download a few more of the necessary packages for the ThirdParty-2.1.x folder:

    1. First, we need to prepare for the downloads:
      cd ThirdParty-2.1.x
      mkdir download
    2. Now, we need to download the essential source code packages for these instructions you are following (the links are from the file README.org):
      wget -P download http://www.paraview.org/files/v3.12/ParaView-3.12.0.tar.gz
      wget -P download https://gforge.inria.fr/frs/download.php/28043/scotch_5.1.11.tar.gz
    3. Next, we need to unpack the packages we've downloaded:
      tar -xzf download/ParaView-3.12.0.tar.gz
      tar -xzf download/scotch_5.1.11.tar.gz
    4. Last but not least, the final command on this sub-list is to go back to the main OpenFOAM folder:
      cd ..

  5. For building OpenFOAM itself, it depends on whether you have installed the i386 or x86_64 architecture of Ubuntu. To check this, run:
    uname -m

    Now, accordingly:

    • For i386:
      #here you can change 4 to the number of cores you've got
      source $HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc WM_NCOMPPROCS=4 WM_MPLIB=SYSTEMOPENMPI WM_ARCH_OPTION=32
    • For x86_64:
      #here you can change 4 to the number of cores you've got
      source $HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc WM_NCOMPPROCS=4 WM_MPLIB=SYSTEMOPENMPI
  6. Save an alias in the personal .bashrc file, simply by running the following command:
    echo "alias of21x='source \$HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc $FOAM_SETTINGS'" >> $HOME/.bashrc
    Note: This last line means that whenever you start a new terminal window or tab, you should run the alias command associated to the OpenFOAM 2.1.x shell environment. In other words, whenever you start a new terminal, you should run:
    of21x
    
    For more information on this topic, read section Using aliases to help manage multiple OpenFOAM versions in the page Installation/Working with the Shell.
  7. Now let's build OpenFOAM:
    (Warning: this may take somewhere from 30 minutes to 6 hours, depending on your machine.)
    #Go into OpenFOAM's main source folder
    cd OpenFOAM-2.1.x
     
    # This next command will take a while... somewhere between 30 minutes to 3-6 hours.
    ./Allwmake > make.log 2>&1
     
    #Run it a second time for getting a summary of the installation
    ./Allwmake > make.log 2>&1
  8. To check if everything went well:
    1. Check if icoFoam is working, by running this command:
      icoFoam -help

      which should tell you something like this:

      Usage: icoFoam [OPTIONS]
      options:
        -case <dir>       specify alternate case directory, default is the cwd
        -noFunctionObjects
                          do not execute functionObjects
        -parallel         run in parallel
        -roots <(dir1 .. dirN)>
                          slave root directories for distributed running
        -srcDoc           display source code in browser
        -doc              display application documentation in browser
        -help             print the usage

      Note: And keep in mind that you need to be careful with the letter case of the command. It's icoFoam, not icoFOAM.

    2. If the previous command failed to work properly, then edit the file log.make and check if there are any error messages. A few examples on how you can edit this file:
      • By using kwrite:
        kwrite log.make
      • By using gedit:
        gedit log.make
      • By using nano:
        nano log.make

        You can then exit by using the key combination Ctrl+X and following any instructions it gives you.

      Note: It's the first error message that matters.

    3. If you don't understand the output, then please compress the log-file log.make and attach the compressed file to a post in the designated thread.
      If you do not know how to create a compressed file, then try one of the following examples:
      • You can compress the file with gzip by running this command:
        gzip < log.make > log.make.gz

        Then attach the resulting package file named log.make.gz to a post in the designated thread.

      • Or you can compress one or more log-files into a tarball package file, by running this command:
        tar -czf logs.tar.gz log.*

        Then attach the resulting package file named logs.tar.gz to a post in the designated thread.

    4. Instructions on how to further diagnose the issue yourself, have a look at the section Common errors when building OpenFOAM from source code in the page FAQ/Installation and Running.
  9. Now, in order to build ParaView 3.12.0 that comes with OpenFOAM:
    cd $WM_THIRD_PARTY_DIR
    ./makeParaView
     
    cd $FOAM_UTILITIES/postProcessing/graphics/PV3Readers 
    wmSET $FOAM_SETTINGS
    ./Allwclean 
    ./Allwmake
  10. Now you can go read the User Guide: official OpenFOAM User Guide


Reminder: Whenever you start a new terminal window or tab, you should run the alias command associated to the OpenFOAM 2.1.x shell environment. In other words, run the following command whenever you start a new terminal:
of21x
For more information on this topic, read section Using aliases to help manage multiple OpenFOAM versions in the page Installation/Working with the Shell.


Discussion thread where you can ask questions about these steps: No thread available. Please a create a new thread in the forum.


2.2 Ubuntu 14.04

WARNING: These instructions are currently being written and under testing!

Discussion thread where you can ask questions about these steps: No thread available. Please a create a new thread in the forum.

Steps:

  1. Switch to root mode (administrator), to install the necessary packages:
    sudo -s
    • If the 'sudo' command tells you're not in the sudoers list, then run:
      su -
  2. Install the necessary packages:
    apt-get install build-essential cmake flex bison zlib1g-dev qt4-dev-tools libqt4-dev gnuplot libreadline-dev \
    libncurses-dev libxt-dev libopenmpi-dev openmpi-bin git-core gcc-4.7 g++-4.7
  3. Now exit from the root mode:
    exit
  4. Download and unpack (here you can copy-paste all in single go):
    #OpenFOAM downloading and installation
    cd ~
    mkdir OpenFOAM
    cd OpenFOAM
    git clone https://github.com/OpenFOAM/OpenFOAM-2.1.x.git
    git clone https://github.com/OpenFOAM/ThirdParty-2.1.x.git

    But we will now have to download a few more of the necessary packages for the ThirdParty-2.1.x folder:

    1. First, we need to prepare for the downloads:
      cd ThirdParty-2.1.x
      mkdir download
    2. Now, we need to download the essential source code packages for these instructions you are following (the links are from the file README.org):
      wget -P download http://www.paraview.org/files/v3.12/ParaView-3.12.0.tar.gz
      wget -P download https://gforge.inria.fr/frs/download.php/28043/scotch_5.1.11.tar.gz
    3. Next, we need to unpack the packages we've downloaded:
      tar -xzf download/ParaView-3.12.0.tar.gz
      tar -xzf download/scotch_5.1.11.tar.gz
    4. Last but not least, the final command on this sub-list is to go back to the main OpenFOAM folder:
      cd ..
  5. For building OpenFOAM itself, it depends on whether you have installed the i386 or x86_64 architecture of Ubuntu. To check this, run:
    uname -m

    Now, accordingly:

    • For i386:
      #fix the rules' files
      sed -i -e 's/gcc/\$(WM_CC)/' wmake/rules/linuxGcc/c
      sed -i -e 's/g++/\$(WM_CXX)/' wmake/rules/linuxGcc/c++
       
      #here you can change 4 to the number of cores you've got
      source $HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc WM_NCOMPPROCS=4 WM_MPLIB=SYSTEMOPENMPI WM_ARCH_OPTION=32
      export WM_CC='gcc-4.7'
      export WM_CXX='g++-4.7'
    • For x86_64:
      #fix the rules' files
      sed -i -e 's/gcc/\$(WM_CC)/' wmake/rules/linux64Gcc/c
      sed -i -e 's/g++/\$(WM_CXX)/' wmake/rules/linux64Gcc/c++
       
      #here you can change 4 to the number of cores you've got
      source $HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc WM_NCOMPPROCS=4 WM_MPLIB=SYSTEMOPENMPI
      export WM_CC='gcc-4.7'
      export WM_CXX='g++-4.7'
  6. Save an alias in the personal .bashrc file, simply by running the following command:
    FULL_SETTINGS="$FOAM_SETTINGS; export WM_CC=gcc-4.7; export WM_CXX=g++-4.7"
    echo "alias of21x='source \$HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc $FULL_SETTINGS'" >> $HOME/.bashrc
    unset FULL_SETTINGS
    Note: This last line means that whenever you start a new terminal window or tab, you should run the alias command associated to the OpenFOAM 2.1.x shell environment. In other words, whenever you start a new terminal, you should run:
    of21x
    
    For more information on this topic, read section Using aliases to help manage multiple OpenFOAM versions in the page Installation/Working with the Shell.
  7. Now let's build OpenFOAM:
    (Warning: this may take somewhere from 30 minutes to 6 hours, depending on your machine.)
    #Go into OpenFOAM's main source folder
    cd OpenFOAM-2.1.x
     
    # This next command will take a while... somewhere between 30 minutes to 3-6 hours.
    ./Allwmake > make.log 2>&1
     
    #Run it a second time for getting a summary of the installation
    ./Allwmake > make.log 2>&1
  8. To check if everything went well:
    1. Check if icoFoam is working, by running this command:
      icoFoam -help

      which should tell you something like this:

      Usage: icoFoam [OPTIONS]
      options:
        -case <dir>       specify alternate case directory, default is the cwd
        -noFunctionObjects
                          do not execute functionObjects
        -parallel         run in parallel
        -roots <(dir1 .. dirN)>
                          slave root directories for distributed running
        -srcDoc           display source code in browser
        -doc              display application documentation in browser
        -help             print the usage

      Note: And keep in mind that you need to be careful with the letter case of the command. It's icoFoam, not icoFOAM.

    2. If the previous command failed to work properly, then edit the file log.make and check if there are any error messages. A few examples on how you can edit this file:
      • By using kwrite:
        kwrite log.make
      • By using gedit:
        gedit log.make
      • By using nano:
        nano log.make

        You can then exit by using the key combination Ctrl+X and following any instructions it gives you.

      Note: It's the first error message that matters.

    3. If you don't understand the output, then please compress the log-file log.make and attach the compressed file to a post in the designated thread.
      If you do not know how to create a compressed file, then try one of the following examples:
      • You can compress the file with gzip by running this command:
        gzip < log.make > log.make.gz

        Then attach the resulting package file named log.make.gz to a post in the designated thread.

      • Or you can compress one or more log-files into a tarball package file, by running this command:
        tar -czf logs.tar.gz log.*

        Then attach the resulting package file named logs.tar.gz to a post in the designated thread.

    4. Instructions on how to further diagnose the issue yourself, have a look at the section Common errors when building OpenFOAM from source code in the page FAQ/Installation and Running.
  9. Now, in order to build ParaView 3.8.0 that comes with OpenFOAM:
    cd $WM_THIRD_PARTY_DIR
    ./makeParaView
     
    cd $FOAM_UTILITIES/postProcessing/graphics/PV3Readers 
    wmSET $FOAM_SETTINGS
    ./Allwclean 
    ./Allwmake
  10. Now you can go read the User Guide: official OpenFOAM User Guide


Reminder: Whenever you start a new terminal window or tab, you should run the alias command associated to the OpenFOAM 2.1.x shell environment. In other words, run the following command whenever you start a new terminal:
of21x
For more information on this topic, read section Using aliases to help manage multiple OpenFOAM versions in the page Installation/Working with the Shell.


Discussion thread where you can ask questions about these steps: No thread available. Please a create a new thread in the forum.