07 Directoryorganization
07 Directoryorganization
You know how to use OpenFOAM, and how to find hints on usage in $FOAM_TUTORIALS
Learning outcomes
• Browse through the OpenFOAM installation in different ways
• Understand the organization of directories in OpenFOAM
• Understand the difference between applications and libraries, and their relation to pro-
gramming
• Get a first understanding of the compilation process in OpenFOAM, and how it is related to
the environment
You can use the Linux command tree to examine the source code directory organization, lo-
cated in the installation directory $WM_PROJECT_DIR:
tree -d -L 1 $WM_PROJECT_DIR
yielding (version dependent):
$WM_PROJECT_DIR
|-- applications
|-- bin
|-- build
|-- doc
|-- etc
|-- modules
|-- platforms
|-- src
|-- tutorials
`-- wmake
The global controlDict gives OpenFOAM some global settings (not at case-level, as the
system/controlDict files).
It is useful for debugging. We will have a look at this later.
It also sets some DimensionedConstants, and defines DimensionSets for the SI units (or USCS,
if the unitSet is switched to that).
Read more about the global controlDict in the Programmers Guide.
The src directory contains source code for all libraries, organized in sub-directories
The most relevant are:
• finiteVolume. This library provides all the classes needed for the finiteVolume dis-
cretization, such as the fvMesh class, finiteVolume discretization operators (divergence,
laplacian, gradient, and fvc/fvm), and boundary conditions (fields/fvPatchFields). In
cfdTools/general/include/ you also find the very important file fvCFD.H, which is
included in most applications.
• OpenFOAM. This core library includes the definitions of the containers used for the opera-
tions, the field definitions, the declaration of the mesh and of all the mesh features such as
zones and sets
• TurbulenceModels which contains the source code of turbulence models
There is also an Allwmake script, which compiles all the libraries.
It should be noted in particular that the compilation of the source code in the
src directory yields shared object (*.so) files, that are NOT executable!
If you are not familiar with make commands, read more here:
https://en.wikipedia.org/wiki/Make_(software)
wmake understands the file structure in OpenFOAM and has some default compiler directives
that are set in the wmake directory. There is also a command, wclean, that cleans up (some of)
the output from the wmake command.
If you added a new compiler name in the bashrc file, you should also tell wmake how to inter-
pret that name. In wmake/rules you find the default settings for the available compilers.
You can also find some scripts that are useful when organizing your files for compilation, or for
cleaning up.
The wmake command must be executed in directories where there is a Make directory. The Make
directory contains specific compilation instructions for that application or library.
The build directory contains intermediate files during compilation. These are files only used
by the compiler. The only thing that happens if the build directory is removed is that the
compiler has to repeat the compilation again if the compilation process is started over again.
If they are left in place, the compiler will skip the steps that have already been done. We will
therefore not investigate the build directory further.
After the second step, the final binaries are created. They are saved in the platforms direc-
tory...
The first option is to add the setting of an enviroment variable when sourcing the bashrc
file, such as for the Debug version:
. $HOME/OpenFOAM/OpenFOAM-plus/etc/bashrc WM_COMPILE_OPTION=Debug
This option uses the _foamEval() function *=* in etc/config.sh/functions.
Have a look in that file and see that the prefs.sh file must be found by foamEtcFile. You
can list the appropriate paths by:
foamEtcFile -list
yielding (if your user name is oscfd and if you have installed OpenFOAM in your home direc-
tory, version dependent):
/home/oscfd/.OpenFOAM/plus
/home/oscfd/.OpenFOAM
/home/oscfd/OpenFOAM/site/plus
/home/oscfd/OpenFOAM/site
/home/oscfd/OpenFOAM/OpenFOAM-plus/etc
Those are searched in order, and you can therefore do the modifications at different levels (for
only you, at a site, or for all users).
The use of the $WM_OPTIONS level in the directory structure makes it possible to have
the same source code compiled in as many ways as desired.
Find written descriptions in the files, and use your bash knowledge to read the scripts.
The doc directory previously also contained the User Guide and Programmer’s Guide, which
are now moved to http://openfoam.com/
You already found some details about git in the installation instructions.