OpenFOAM
(The contents on this page are under construction)
Link PETSc to OpenFOAM solver
Even though OpenFOAM offers a large number of solvers for tailored applications, they all use the segregated approach, making it difficult to obtain converged solutions for highly coupled systems of equations. There have been attempts to develop fully coupled types of solver in foam-extend-4.0 but it seems the feature didn't have enough interest from the community and hasn't been included in the official version. However, OpenFOAM can be linked to external libraries such as the Portable, Extensible Toolkit for Scientific Computation (PETSc) to employ the robust coupled solver offered by PETSc. The idea is to use OpenFOAM only for matrix assembly and pre/post-processing, while PETSc handles all the calculation parts.
In order to do this, one first needs to install PETSc. There are two ways:
Following the official instruction manual at PETSc: Documentation: Installation (anl.gov)
Download the bash script installPetsc created by folks at Rheotool(rheoTool/installPetsc at master · fppimenta/rheoTool (github.com)). After choosing the desired Petsc version by changing the PetscV variables at the very beginning of the script, execute the script to install PETSc automatically.
./installPetsc
It is worth notice that PETSc must be compiled into a library file (.so), which can then be included in the OpenFOAM's native solvers. Below is the step-by-step instruction to link the installed PETSc to an arbitrary OpenFOAM solver.
Create a shared library called libpetsc.so by invoking the following command in any PETSc source folder:
make BOPT=0 shared
Define PETSc environmental variables by adding the following lines to the $HOME/.bashrc file:
Open the file: gedit $HOME/.bashrc
Then, add the following lines to the end of the file:
export PETSC_DIR=$HOME/petsc/petsc-3.4.5
export PETSC_ARCH="arch-linux-cxx-opt"
export LD_LIBRARY_PATH=$PETSC_DIR/$PETSC_ARCH/lib
The purpose is to generate the three crucial environmental variables "PETSC_DIR", "PETSC_ARCH" and "LD_LIBRARY_PATH" every time opening a new Terminal. Otherwise, the OpenFOAM solvers won't be able to find the PETSc source files and the compilation will fail.
Include PETSc library at the beginning of the source file of a solver, e.g. icoFoam.C
#include <petsc.h>
Add the following red lines to Make/options:
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclulde \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(PETSC_DIR)/include \
-I$(PETSC)DIR)/$(PETSC_ARCH)/lib
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-L$(PETSC_DIR)/$(PETSC_ARCH)/lib -lpetsc
Recompile the solver
wclean
wmake
Distribute points evenly on a sphere algorithm
References:
[1] P. Leopardi, “Distributing points on the sphere: Partitions, separation, quadrature and energy,” PhD Thesis, 2007.
Programming in OpenFOAM - Implement a IBM library #1
Create a new solver from PISOFoam, change its name to pisoIBMFoam, add an empty forcing terms and recompile
Programming in OpenFOAM - Implement a IBM library #2
Introduction to Immersed Boundary Method, create a set of Langrangian points, then save and view in ParaView. Do it directly in the pisoIBMFoam
Programming in OpenFOAM - Implement a IBM library #3
Find neighboring cells, calculate the forcing terms
Programming in OpenFOAM - Implement a IBM library #4
Validate the new solver
Programming in OpenFOAM - Implement a IBM library #5
Create an empty library IBMlib, compile and link to pisoIBMFoam. Move the functions into library