Difference between revisions of "FSI installation instructions"
NikLebedenko (talk | contribs) m (Added link to 3D upgrade page) |
NikLebedenko (talk | contribs) m (→Install preCICE on Ubuntu: formatting) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Fluid-structure interaction (FSI) simulations model the interactions between a moving structure and a fluid flowing around it. Below are instructions of how to run FSI with free open-source software. | |||
== Step-by-step instructions== | == Step-by-step instructions== | ||
''''' | '''''Important:''''' Although I include the links to the official websites for installation instructions, I recommend you <u>follow these instructions for installation</u> (unless they no longer work), since the official instructions contain some mistakes and omissions. | ||
These instructions only work for Ubuntu or Windows 10 | These instructions only work for Ubuntu or Windows 10. | ||
===Install OpenFOAM=== | |||
Ensure you have installed OpenFOAM (v1812 or later) - [[OpenFOAM installation instructions|installation instructions here]]. | |||
=== | ===Install FEniCS on Ubuntu=== | ||
''Update 05/02/2022 - These instructions are for FEniCS, which is now considered legacy. Ideally FEniCSx should be used instead (todo), but the FEniCSx-preCICE adapter is in its infancy, so FEniCS is still the best option. Note that around 50% of the documentation online is for FEniCS, 50% for FEniCSx, which adds to confusion.'' | |||
FEniCS is an open-source Finite Element Method (FEM) library. We will use it to simulate how a solid bends as a result of applied forces. | |||
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://fenicsproject.org/download/ this website]):<syntaxhighlight lang="bash"> | The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://fenicsproject.org/download/ this website]):<syntaxhighlight lang="bash"> | ||
sudo apt-get install software-properties-common | sudo apt-get install software-properties-common | ||
Line 60: | Line 22: | ||
===Install preCICE on Ubuntu=== | ===Install preCICE on Ubuntu=== | ||
preCICE is an open-source library for coupling simulations together. We will use it to allow OpenFOAM and FEniCS to communicate with each other. | |||
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://precice.org/quickstart.html this website]): <syntaxhighlight lang="bash"> | The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://precice.org/quickstart.html this website]): <syntaxhighlight lang="bash"> | ||
sudo apt update | sudo apt update | ||
Line 69: | Line 33: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== Option 1: Install package directly ==== | |||
Note that this did not work for me, but is apparently a method that is possible for some users.<syntaxhighlight lang="bash"> | |||
wget https://github.com/precice/precice/releases/download/v2.3.0/libprecice2_2.3.0_focal.deb | 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 | sudo apt install ./libprecice2_2.3.0_focal.deb | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== Option 2: Install from source ==== | |||
If installing the package directly did not work (like in my case), then install from source:<syntaxhighlight lang="bash"> | |||
tar -xzf v2.3.0.tar.gz | tar -xzf v2.3.0.tar.gz | ||
cd precice-2.3.0 | cd precice-2.3.0 | ||
mkdir build | mkdir build | ||
cd 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! | 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 | make -j 4 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Test that the cmake | Test that the <code>cmake</code> and <code>make</code> commands worked as expected:<syntaxhighlight lang="bash"> | ||
cd ~/FSI/precice-2.3.0/build | cd ~/FSI/precice-2.3.0/build | ||
ctest --output-on-failure | ctest --output-on-failure | ||
Line 92: | Line 60: | ||
===Install the OpenFOAM-preCICE adapter=== | ===Install the OpenFOAM-preCICE adapter=== | ||
This adapter allows OpenFOAM to talk to preCICE. | |||
The Ubuntu installation instructions as of 23/01/2021 are summarised below (adapted from [https://precice.org/adapter-openfoam-get.html this website]):<syntaxhighlight lang="bash"> | The Ubuntu installation instructions as of 23/01/2021 are summarised below (adapted from [https://precice.org/adapter-openfoam-get.html this website]):<syntaxhighlight lang="bash"> | ||
cd ~/FSI | cd ~/FSI | ||
Line 100: | Line 70: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Install the FEniCS-preCICE adapter=== | ===Install the FEniCS-preCICE adapter=== | ||
This adapter allows FEniCS to talk to preCICE. | |||
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://precice.org/adapter-fenics.html this website]). This requires Python3, which should already be installed if you followed my previous instructions: <syntaxhighlight lang="bash"> | The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from [https://precice.org/adapter-fenics.html this website]). This requires Python3, which should already be installed if you followed my previous instructions: <syntaxhighlight lang="bash"> | ||
(optional, should not need this line) python3 -m pip install scipy | (optional, should not need this line) python3 -m pip install scipy | ||
python3 -m pip install --user fenicsprecice | python3 -m pip install --user fenicsprecice | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Summary of how the software works === | |||
The following four steps are run in a loop: | |||
# OpenFOAM sends the aerodynamic forces at each point on the solid to preCICE. | |||
# FEniCS reads the aerodynamic forces from preCICE, and calculates the displacement of the solid at each point. | |||
# FEniCS sends the displacement of the solid to preCICE. | |||
# OpenFOAM reads the displacement from preCICE, and calculates the new aerodynamic forces. | |||
This is a simplification of the process (called a ''serial explicit coupling''). In reality, a better method is to have all four steps occur simultaneously until the residual is low enough (called ''parallel implicit coupling''). This is faster and more accurate. | |||
Further information about coupling is [https://precice.org/couple-your-code-overview.html available here]. | |||
===Test the installation ran correctly=== | ===Test the installation ran correctly=== | ||
Line 120: | Line 103: | ||
./run.sh | ./run.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Both terminals should now have log outputs flying. After around 1 minute of computation, both terminals should finish at (roughly) the same time. | Both terminals should now have log outputs flying. After around 1 minute of computation, both terminals should finish at (roughly) the same time. | ||
If you have installed ParaView on Windows and added the folder containing its .exe file to the Windows PATH environment variable, then you can run these commands to visualise the results:<syntaxhighlight lang="bash"> | |||
cd ~/FSI/tutorials/perpendicular-flap/fluid-openfoam | cd ~/FSI/tutorials/perpendicular-flap/fluid-openfoam | ||
paraview.exe fluid-openfoam.foam | paraview.exe fluid-openfoam.foam |
Latest revision as of 10:10, 5 February 2022
Fluid-structure interaction (FSI) simulations model the interactions between a moving structure and a fluid flowing around it. Below are instructions of how to run FSI with free open-source software.
Step-by-step instructions
Important: Although I include the links to the official websites for installation instructions, I recommend you follow these instructions for installation (unless they no longer work), since the official instructions contain some mistakes and omissions.
These instructions only work for Ubuntu or Windows 10.
Install OpenFOAM
Ensure you have installed OpenFOAM (v1812 or later) - installation instructions here.
Install FEniCS on Ubuntu
Update 05/02/2022 - These instructions are for FEniCS, which is now considered legacy. Ideally FEniCSx should be used instead (todo), but the FEniCSx-preCICE adapter is in its infancy, so FEniCS is still the best option. Note that around 50% of the documentation online is for FEniCS, 50% for FEniCSx, which adds to confusion.
FEniCS is an open-source Finite Element Method (FEM) library. We will use it to simulate how a solid bends as a result of applied forces.
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from this website):
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
preCICE is an open-source library for coupling simulations together. We will use it to allow OpenFOAM and FEniCS to communicate with each other.
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from this website):
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
Option 1: Install package directly
Note that this did not work for me, but is apparently a method that is possible for some users.
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
Option 2: Install from source
If installing the package directly did not work (like in my case), then 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
and make
commands 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
This adapter allows OpenFOAM to talk to preCICE.
The Ubuntu installation instructions as of 23/01/2021 are summarised below (adapted from this website):
cd ~/FSI
git clone https://github.com/precice/openfoam-adapter
cd openfoam-adapter
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH ### You might need this line, it depends.
./Allwmake
Install the FEniCS-preCICE adapter
This adapter allows FEniCS to talk to preCICE.
The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from this website). This requires Python3, which should already be installed if you followed my previous instructions:
(optional, should not need this line) python3 -m pip install scipy
python3 -m pip install --user fenicsprecice
Summary of how the software works
The following four steps are run in a loop:
- OpenFOAM sends the aerodynamic forces at each point on the solid to preCICE.
- FEniCS reads the aerodynamic forces from preCICE, and calculates the displacement of the solid at each point.
- FEniCS sends the displacement of the solid to preCICE.
- OpenFOAM reads the displacement from preCICE, and calculates the new aerodynamic forces.
This is a simplification of the process (called a serial explicit coupling). In reality, a better method is to have all four steps occur simultaneously until the residual is low enough (called parallel implicit coupling). This is faster and more accurate.
Further information about coupling is available here.
Test the installation ran correctly
... by running this tutorial case:
cd ~/FSI
git clone --branch=master --depth 1 https://github.com/precice/tutorials.git
cd ~/FSI/tutorials/perpendicular-flap/fluid-openfoam
./run.sh
The command line output should have paused after this output. If it did not pause, something went wrong.
---[precice] I am participant "Fluid"
---[precice] Setting up master communication to coupling partner/s
Now open another Ubuntu terminal, and run these commands:
cd ~/FSI/tutorials/perpendicular-flap/solid-fenics
./run.sh
Both terminals should now have log outputs flying. After around 1 minute of computation, both terminals should finish at (roughly) the same time.
If you have installed ParaView on Windows and added the folder containing its .exe file to the Windows PATH environment variable, then you can run these commands to visualise the results:
cd ~/FSI/tutorials/perpendicular-flap/fluid-openfoam
paraview.exe fluid-openfoam.foam
Congratulations! You should now have a functional FSI installation.
Note that as of 31/12/2021, the unmodified FEniCS-preCICE adapter only works in 2D, so you will have to edit the adapter in order to add 3D FSI functionality, instructions here
Upgrade to 3D
Please see this page.