Difference between revisions of "CFD"

From CUSF Wiki
Jump to navigation Jump to search
(More installation instructions added)
(More installation instructions added)
Line 10: Line 10:
* FEniCS ([https://fenicsproject.org/ website], [https://fenicsproject.org/download/ install on Ubuntu]) - a Python interface to the DOLFIN C++ library for the solution of solid mechanics problems formulated with the Finite Element Method (FEM), and
* FEniCS ([https://fenicsproject.org/ website], [https://fenicsproject.org/download/ install on Ubuntu]) - a Python interface to the DOLFIN C++ library for the solution of solid mechanics problems formulated with the Finite Element Method (FEM), and
* preCICE ([https://precice.org/index.html website], [https://precice.org/quickstart.html install on Ubuntu]) - a very powerful library which allows the coupling of arbitrary solvers using human-readable syntax.
* preCICE ([https://precice.org/index.html website], [https://precice.org/quickstart.html install on Ubuntu]) - a very powerful library which allows the coupling of arbitrary solvers using human-readable syntax.
** Note: in order to use OpenFOAM and FEniCS with preCICE, it is also necessary to download their respective adapters. See [https://precice.org/adapter-openfoam-overview.html this page] and [https://precice.org/adapter-fenics.html this page] from the preCICE website for further information.
** Note: in order to use OpenFOAM and FEniCS with preCICE, it is also necessary to download their respective adapters. See [https://precice.org/adapter-openfoam-overview.html this page for OpenFOAM] and [https://precice.org/adapter-fenics.html this page for FEniCS] from the preCICE website for further information.


==== Step-by-step instructions ====
==== Step-by-step instructions ====
 
IMPORTANT: Although I include the links to the official websites for Ubuntu installation instructions, I recommend you follow my instructions for installation (unless you are a masochist), since the official instructions contain some mistakes and omissions.
# Install Ubuntu. If you are running a Windows machine (Windows 10 or above), I recommend installing [https://docs.microsoft.com/en-us/windows/wsl/install-manual Windows Subsystem for Linux] (WSL - use WSL1, discussion of WSL2 below) instead of setting up a dual-boot partition.
*Install Ubuntu. If you are running a Windows machine (Windows 10 or above), I recommend installing [https://docs.microsoft.com/en-us/windows/wsl/install-manual Windows Subsystem for Linux] (WSL - use WSL1, discussion of WSL2 below) instead of setting up a dual-boot partition.
#* Note: there is a choice between WSL1 and WSL2, with the main difference being that WSL2 has significantly improved read-write speeds compared with WSL1 while staying within the Linux file system, but WSL2 has significantly worse read-write speeds when moving between the Linux and Windows file systems. In practical terms, this means that the Linux-based software (OpenFOAM, FEniCS) will read and write faster, at the expense of Windows-based ParaView installations loading results much slower when post-processing. Since OpenFOAM spends significantly more time solving equations than reading and writing files, and gigabytes of data need to be loaded across file systems for post-processing in Windows, I recommend sticking with WSL1. If you prefer WSL2, you can install ParaView on Ubuntu, installing XMing to view the GUI (see [https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2 this page] and [https://newbedev.com/how-to-set-up-working-x11-forwarding-on-wsl2 this page] for further information)
** Note: there is a choice between WSL1 and WSL2, with the main difference being that WSL2 has significantly improved read-write speeds compared with WSL1 while staying within the Linux file system, but WSL2 has significantly worse read-write speeds when moving between the Linux and Windows file systems. In practical terms, this means that the Linux-based software (OpenFOAM, FEniCS) will read and write faster, at the expense of Windows-based ParaView installations loading results much slower when post-processing. Since OpenFOAM spends significantly more time solving equations than reading and writing files, and gigabytes of data need to be loaded across file systems for post-processing in Windows, I recommend sticking with WSL1. If you prefer WSL2, you can install ParaView on Ubuntu, installing XMing to view the GUI (see [https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2 this page] and [https://newbedev.com/how-to-set-up-working-x11-forwarding-on-wsl2 this page] for further information)
# [https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/debian Install OpenFOAM on Ubuntu]. The Ubuntu installation instructions as of 31/12/21 are summarised below for redundancy:<syntaxhighlight lang="bash">
* [https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/debian Install OpenFOAM on Ubuntu]. The Ubuntu installation instructions as of 31/12/2021 are summarised below:<syntaxhighlight lang="bash">
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
sudo apt-get install openfoam2012-default
sudo apt-get install openfoam2012-default
</syntaxhighlight>
</syntaxhighlight> Ensure that your ~/.bashrc file has the following line appended (with XXXX replaced with your version number):<syntaxhighlight lang="bash">
#* Note: I use OpenFOAMv2012, but later versions should also work.
source /usr/lib/openfoam/openfoamXXXX/etc/bashrc
#[https://fenicsproject.org/download/ Install FEniCS on Ubuntu]. The Ubuntu installation instructions as of 31/12/21 are summarised below for redundancy:<syntaxhighlight lang="bash">
</syntaxhighlight>Restart your Ubuntu. Now check the installation completed correctly by running a tutorial case:<syntaxhighlight lang="bash">
cd ~
mkdir -p OpenFOAM-sims/tutorials
cp -r $FOAM_TUTORIALS/incompressible OpenFOAM-sims/tutorials
cd OpenFOAM-sims/tutorials/incompressible/icoFoam/cavity/cavity/
blockMesh > log.blockMesh
icoFoam > log.icoFoam
</syntaxhighlight>Note: I use OpenFOAMv2012, but later versions should also work.
 
*[https://fenicsproject.org/download/ Install FEniCS on Ubuntu]. The Ubuntu installation instructions as of 31/12/2021 are summarised below:<syntaxhighlight lang="bash">
sudo apt-get install software-properties-common
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:fenics-packages/fenics
sudo add-apt-repository ppa:fenics-packages/fenics
Line 27: Line 36:
sudo apt-get install fenics
sudo apt-get install fenics
</syntaxhighlight>
</syntaxhighlight>
#[https://precice.org/quickstart.html Install preCICE on Ubuntu].  
*[https://precice.org/quickstart.html Install preCICE on Ubuntu]. The Ubuntu installation instructions as of 31/12/2021 are summarised below: <syntaxhighlight lang="bash">
#
sudo apt update
#
sudo apt install build-essential cmake libeigen3-dev libxml2-dev libboost-all-dev petsc-dev python3-dev python3-numpy
cd ~
mkdir FSI
cd FSI
 
 
</syntaxhighlight>Now either install the Ubuntu package directly with the instructions below (which did not work for me)...<syntaxhighlight lang="bash">
wget https://github.com/precice/precice/releases/download/v2.3.0/libprecice2_2.3.0_focal.deb
sudo apt install ./libprecice2_2.3.0_focal.deb
</syntaxhighlight>... or install from source:<syntaxhighlight lang="bash">
tar -xzf v2.3.0.tar.gz
cd precice-2.3.0
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/FSI/precice-2.3.0 -DPRECICE_MPICommunication=ON .. ### IMPORTANT! INCLUDE THE TWO DOTS!
make -j 4
</syntaxhighlight>Test that the cmake command worked as expected:<syntaxhighlight lang="bash">
cd ~/FSI/precice-2.3.0/build
ctest --output-on-failure
</syntaxhighlight>If no errors were shown, install the software and test it worked:<syntaxhighlight lang="bash">
make install
make test_install
</syntaxhighlight>Note: I used preCICE v2.3.0, but later versions should also work.
*[https://precice.org/adapter-openfoam-get.html Install the OpenFOAM-preCICE adapter]. The Ubuntu installation instructions as of 31/12/2021 are summarised below:<syntaxhighlight lang="bash">
cd ~/FSI
wget https://github.com/precice/openfoam-adapter/releases/download/v1.0.0/openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012.tar.gz
tar -xzf openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012.tar.gz
cd openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012/
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH ### This line may-or-may-not be needed. YMMV.
./Allwmake
</syntaxhighlight>Note: this is for OpenFOAMv2012. Please see the preCICE website for information on adapters for later versions.
*[https://precice.org/adapter-fenics.html Install the FEniCS-preCICE adapter]. The Ubuntu installation instructions as of 31/12/2021 are summarised below (requires Python3, should already be installed if you followed my previous instructions): <syntaxhighlight lang="bash">
python3 -m pip install --user fenicsprecice
</syntaxhighlight>
*Test the installation ran correctly: [todo]
Congratulations! You should now have a functional FSI installation.
 
*

Revision as of 19:46, 31 December 2021

This page is currently a work in progress by Nik Lebedenko - if you want to ask questions / see a mistake / request more details to be added to this page, feel free to email me or message me on slack.

Fluid-structure interaction (FSI)

This technique allows complex interactions between flexible structures and fluid flows. This has been used to predict fin flutter at hypersonic speeds for Griffin 1.

Simulations of this kind are achievable with the combination of the following free open-source software packages:

  • OpenFOAM (website, install on Ubuntu) - a C/C++ library for the solution of fluid mechanics problems formulated with the Finite Volume Method (FVM),
    • Important: there are two main versions of OpenFOAM, provided at OpenFOAM.com and OpenFOAM.org. I have only used the .com version, but everything here should also be possible with the .org version.
  • FEniCS (website, install on Ubuntu) - a Python interface to the DOLFIN C++ library for the solution of solid mechanics problems formulated with the Finite Element Method (FEM), and
  • preCICE (website, install on Ubuntu) - a very powerful library which allows the coupling of arbitrary solvers using human-readable syntax.
    • Note: in order to use OpenFOAM and FEniCS with preCICE, it is also necessary to download their respective adapters. See this page for OpenFOAM and this page for FEniCS from the preCICE website for further information.

Step-by-step instructions

IMPORTANT: Although I include the links to the official websites for Ubuntu installation instructions, I recommend you follow my instructions for installation (unless you are a masochist), since the official instructions contain some mistakes and omissions.

  • Install Ubuntu. If you are running a Windows machine (Windows 10 or above), I recommend installing Windows Subsystem for Linux (WSL - use WSL1, discussion of WSL2 below) instead of setting up a dual-boot partition.
    • Note: there is a choice between WSL1 and WSL2, with the main difference being that WSL2 has significantly improved read-write speeds compared with WSL1 while staying within the Linux file system, but WSL2 has significantly worse read-write speeds when moving between the Linux and Windows file systems. In practical terms, this means that the Linux-based software (OpenFOAM, FEniCS) will read and write faster, at the expense of Windows-based ParaView installations loading results much slower when post-processing. Since OpenFOAM spends significantly more time solving equations than reading and writing files, and gigabytes of data need to be loaded across file systems for post-processing in Windows, I recommend sticking with WSL1. If you prefer WSL2, you can install ParaView on Ubuntu, installing XMing to view the GUI (see this page and this page for further information)
  • Install OpenFOAM on Ubuntu. The Ubuntu installation instructions as of 31/12/2021 are summarised below:
    curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
    sudo apt-get install openfoam2012-default
    Ensure that your ~/.bashrc file has the following line appended (with XXXX replaced with your version number):
    source /usr/lib/openfoam/openfoamXXXX/etc/bashrc
    Restart your Ubuntu. Now check the installation completed correctly by running a tutorial case:
    cd ~
    mkdir -p OpenFOAM-sims/tutorials
    cp -r $FOAM_TUTORIALS/incompressible OpenFOAM-sims/tutorials
    cd OpenFOAM-sims/tutorials/incompressible/icoFoam/cavity/cavity/
    blockMesh > log.blockMesh
    icoFoam > log.icoFoam
    Note: I use OpenFOAMv2012, but later versions should also work.
  • Install FEniCS on Ubuntu. The Ubuntu installation instructions as of 31/12/2021 are summarised below:
    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:fenics-packages/fenics
    sudo apt-get update
    sudo apt-get install fenics
  • Install preCICE on Ubuntu. The Ubuntu installation instructions as of 31/12/2021 are summarised below:
    sudo apt update
    sudo apt install build-essential cmake libeigen3-dev libxml2-dev libboost-all-dev petsc-dev python3-dev python3-numpy
    cd ~
    mkdir FSI
    cd FSI
    Now either install the Ubuntu package directly with the instructions below (which did not work for me)...
    wget https://github.com/precice/precice/releases/download/v2.3.0/libprecice2_2.3.0_focal.deb
    sudo apt install ./libprecice2_2.3.0_focal.deb
    ... or install from source:
    tar -xzf v2.3.0.tar.gz
    cd precice-2.3.0
    mkdir build
    cd build
    cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/FSI/precice-2.3.0 -DPRECICE_MPICommunication=ON .. ### IMPORTANT! INCLUDE THE TWO DOTS!
    make -j 4
    Test that the cmake command worked as expected:
    cd ~/FSI/precice-2.3.0/build
    ctest --output-on-failure
    If no errors were shown, install the software and test it worked:
    make install
    make test_install
    Note: I used preCICE v2.3.0, but later versions should also work.
  • Install the OpenFOAM-preCICE adapter. The Ubuntu installation instructions as of 31/12/2021 are summarised below:
    cd ~/FSI
    wget https://github.com/precice/openfoam-adapter/releases/download/v1.0.0/openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012.tar.gz
    tar -xzf openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012.tar.gz
    cd openfoam-adapter_v1.0.0_OpenFOAMv1812-v2012/
    export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH ### This line may-or-may-not be needed. YMMV.
    ./Allwmake
    Note: this is for OpenFOAMv2012. Please see the preCICE website for information on adapters for later versions.
  • Install the FEniCS-preCICE adapter. The Ubuntu installation instructions as of 31/12/2021 are summarised below (requires Python3, should already be installed if you followed my previous instructions):
    python3 -m pip install --user fenicsprecice
  • Test the installation ran correctly: [todo]

Congratulations! You should now have a functional FSI installation.