Skip to content

Instantly share code, notes, and snippets.

@appleparan
Last active June 5, 2022 07:34
Show Gist options
  • Save appleparan/1ece78e2335ac52761aeeefe31ff2873 to your computer and use it in GitHub Desktop.
Save appleparan/1ece78e2335ac52761aeeefe31ff2873 to your computer and use it in GitHub Desktop.
Install OpenFOAM
  • $ means shell prompt
  1. Install gcc (Takes very long time, about 6 hours)

    1. go to ~/src
    $ cd ~/src
    
    1. install gcc (for cmake, takes few HOURS)
    $ mkdir gcc_src
    $ cd gcc_src
    $ curl -L -O http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.3.0/gcc-7.3.0.tar.gz
    $ tar zxvf gcc-7.3.0
    $ mkdir objdir 
    $ cd gcc-7.3.0
    $ contrib/download_prerequisites
    $ cd ../objdir
    $ ../gcc-7.3.0/configure --prefix=$HOME/usr/local/gcc --disable-multilib
    $ make && make install
    

    update PATH and LD_LIBRARY_PATH to ~/.bashrc, but don't modify original export just append additional paths

    export LD_LIBRARY_PATH=$HOME/usr/lib:$HOME/usr/local/gcc/lib64:$HOME/usr/local/gcc/lib:$LD_LIBRARY_PATH
    export PATH=$HOME/usr/bin:$HOME/usr/local/gcc/bin:$PATH
    

    then restart remote shell or use source command

    $ source ~/.bashrc
    

    Check gcc is properly installed

    $ gcc --version
    
  2. Install cURL

    $ cd ~/src
    $ curl -L -O https://curl.haxx.se/download/curl-7.60.0.tar.gz
    $ tar zxvf curl-7.60.0.tar.gz
    $ cd curl-7.60.0
    $ ./configure --prefix=$HOME/usr 
    $ make && make install
    

    update PATH and LD_LIBRARY_PATH to ~/.bashrc, but don't modify original export just append additional paths

    export LD_LIBRARY_PATH=$HOME/usr/lib:$LD_LIBRARY_PATH
    export PATH=$HOME/usr/bin:$HOME/usr/local/gcc/bin:$PATH
    

    then restart remote shell or use source command

    $ source ~/.bashrc
    
  3. Install Make

    $ cd ~/src
    $ curl -L -O http://ftp.kaist.ac.kr/gnu/make/make-4.2.tar.gz
    $ tar zxvf make-4.2.tar.gz
    $ cd make-4.2
    $ ./configure --prefix=$HOME/usr
    $ make && make install
    $ ln -s /home/bagitup/usr/bin/make /home/bagitup/usr/bin/gmake
    $ source ~/.bashrc
    
  4. Install binutils

    
    $ cd ~/src
    $ curl -L -O http://ftp.kaist.ac.kr/gnu/binutils/binutils-2.31.tar.gz
    $ tar zxvf binutils-2.31.tar.gz
    $ cd binutils-2.31
    $ ./configure --prefix=$HOME/usr
    $ make && make install
    $ source ~/.bashrc
    
  5. Install bison

    $ cd ~/src
    $ curl -L -O http://ftp.kaist.ac.kr/gnu/bison/bison-3.0.5.tar.gz
    $ tar zxvf bison-3.0.5.tar.gz
    $ cd bison-3.0.5
    $ ./configure --prefix=$HOME/usr
    $ make && make install
    $ source ~/.bashrc
    
  6. Install LinuxBrew Follow this page's instruction Add or update PATH, MANPATH, INFOPATH variables on ~/.bashrc, but don't modify or remove original variables, just append additional paths. i.e.

    # linuxbrew path
    LINUXBREWHOME=$HOME/.linuxbrew
    PATH=$LINUXBREWHOME/bin:$PATH
    MANPATH=$LINUXBREWHOME/share/man:$MANPATH
    INFOPATH=$ILNUXBREWHOME/share/info:$INFOPATH
    

    then restart remote shell or use source command

    $ source ~/.bashrc
    

    You must check this link and read 'with-out-sudo' part because our system is based on CentOS6. You might need to install ruby and git for LinuxBrew.

    $ brew vendor-install ruby
    $ brew install git
    
  7. install glibc

    $ brew install gcc --without-glibc
    $ brew install glibc
    $ brew uninstall gcc
    $ brew install gcc
    
  8. install readline

    $ cd ~/src
    $ curl -L -O ftp://ftp.cwru.edu/pub/bash/readline-7.0.tar.gz 
    $ tar zxvf readline-7.0.tar.gz
    $ cd readline-7.0
    $ ./configure --prefix=$HOME/usr
    $ make && make install
    $ source ~/.bashrc
    
  9. install flex

    $ cd ~/src
    
    • download recent versions from here
    $ curl -L -O https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
    $ tar zxvf flex-2.6.4.tar.gz
    $ cd flex-2.6.4
    $ ./configure --prefix=$HOME/usr
    $ make && make install
    $ source ~/.bashrc
    
  10. install cmake

    • download recent version from here
    $ cd ~/src
    $ curl -L -O https://cmake.org/files/v3.12/cmake-3.12.1.tar.gz
    $ tar zxvf cmake-3.12.1.tar.gz
    $ cd cmake-3.12.1
    $ ./configure --prefix=$HOME/usr/local/cmake
    $ make && make install
    

    update ~/.bashrc

    # cmake path
    LD_LIBRARY_PATH=$HOME/usr/local/cmake/lib$LD_LIBRARY_PATH
    PATH=$HOME/usr/local/cmake/bin:$PATH
    
  11. Download OpenFOAM

    • We installed all preliminaries. Now download OpenFOAM source from this page
    1. Download OpenFOAM

      $ mkdir $HOME/OpenFOAM
      $ cd ~/src
      $ curl -L -O https://sourceforge.net/projects/openfoamplus/files/v1806/OpenFOAM-v1806.tgz
      $ curl -L -O https://sourceforge.net/projects/openfoamplus/files/v1806/ThirdParty-v1806.tgz
      $ tar zxvf OpenFOAM-v1806.tgz
      $ tar zxvf ThirdParty-v1806.tgz
      
    2. Add new environment variables for MPI to ~/.bashrc

      export MPI_ROOT=$MPIHOME
      
    3. Change OpenFOAM bashrc

      • open OpenFOAM bashrc
      $ vim OpenFOAM_v1806/etc/bashrc
      
      • change WM_MPLIB variable to use SYSTEMMPI
      export WM_MPLIB=SYSTEMMPI
      
      • create mpi-system file
      vim etc/config.sh/mpi-system
      
      • save the file with following lines
      export MPI_ROOT=$MPIHOME
      export MPI_ARCH_FLAGS="-DOMPI_SKIP_MPICXX"
      export MPI_ARCH_INC="-isystem $MPI_ROOT/include"
      export MPI_ARCH_LIBS="-L$MPI_ROOT/lib -lmpi"
      
    4. type following commands to shell prompt (use parallel build for faster build)

      $ export WM_NCOMPPROCS=4
      
    5. Follow official build guide

      $ source etc/bashrc
      $ ./Allwmake
      
    6. TroubleShooting

      • If you stuck at INT32_MAX error, read this and apply the patch manually but location is different; modify this file wmake/rules/General/Gcc/c++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment