Jump to content

# OpenFOAM

From ArchWiki

According to Wikipedia:

  OpenFOAM (for "Open source Field Operation And Manipulation") is a C++ toolbox for the development of customized numerical solvers, and pre-/post-processing utilities for the solution of continuum mechanics problems, including computational fluid dynamics (CFD).

## Installation

This article or section needs expansion.

Reason: Explain the difference between openfoam-orgAUR and openfoam-comAUR. (Discuss in Talk:OpenFOAM)

### Basic

If you do not plan on doing development tasks with OpenFOAM, there is an updated version of the program available as openfoam-orgAUR. For most users, this will be everything needed to get an installation up and running.

OpenFOAM is installed in the `/opt` directory and provides a script in `/etc/profile.d/` that allows to activate the OpenFOAM environment with the `ofoam` command (a shell alias).

Note Scripts in `/etc/profile.d/` are sourced only at the start of a session, so the command will not be available right after installation.

### Development

For installation of OpenFOAM in a development environment, the process is fairly straight forward on Arch Linux. The basic steps are as follows:

1. Obtain source files from OpenFOAM
2. Prepare build directory
3. Create Preference File and Set Environment Variables for your installation
4. Compile OpenFOAM sources
5. Test OpenFOAM installation

#### Prerequisites

- openmpi
- paraview
- parmetisAUR
- scotch
- boost-libs
- boost

#### Obtain source files

Since OpenFoam is a picky about its location, create a directory following its naming convention and extract the source code there:

    $ mkdir $HOME/OpenFOAM
    $ wget -P $HOME/OpenFOAM https://dl.openfoam.com/source/v2206/OpenFOAM-v2206.tgz
    $ tar -xvfz $HOME/OpenFOAM/OpenFOAM-v2206.tgz -C $HOME/OpenFOAM

#### Environment variables

Paste the following code into your .bashrc file. Whenever you want to run OpenFOAM you just have to run `of2206` to initialize the environment. This has to be done prior to compilation.

    $ export FOAM_INST_DIR="$HOME/OpenFOAM"
    $ alias of2206='source $FOAM_INST_DIR/OpenFOAM-v2206/etc/bashrc'

#### Compilation

Run `of2206` to initialize the environment. Use `foamSystemCheck` to check if all requirements are installed, then `foam` to change into the project directory. Then you can use the following command to compile:

    $ ./Allwmake -j -s -q -l

This compiles with all cores (-j), reduced output (-s, -silent), with queuing (-q, -queue) and logs (-l, -log) that can be inspected later.

#### Testing

To test for successful installation, run any test case, for example:

    $ foamInstallationTest -full incompressible/simpleFoam/pitzDaily

## Troubleshooting

### zsh

Some things do not work correctly if you are not using bash. In the case of using zsh, you will need the bash-completion package, and add the following to your zshrc for the OpenFOAM scripts to work:

    zshrc

    autoload bashcompinit
    bashcompinit
    alias ofoam="source ${FOAM_INST_DIR}/OpenFOAM-10/etc/bashrc"

Then add the following environment variables, preferably into a zshenv file:

    zshenv

    export FOAM_INST_DIR=/opt/OpenFOAM
    export BASH=/bin/bash

### Paraview not installed

This happens because the dependencies are installed as separate packages, and not in the third-party apps directory of OpenFOAM. Either;

- Add `alias paraFoam='paraFoam -builtin'` to your `/opt/OpenFOAM/Open-FOAM-X.X/etc/bashrc`.
- For each project, `touch $(echo "${PWD##*/}").foam` and then open the touched file from paraview.

## See also

- Official website

Category:

- Science

Hidden category:

- Pages or sections flagged with Template:Expansion

OpenFOAM
Add topic