Skip to content

Creating an OpenFOAM Simulation from Scratch

Hannes Kroeger edited this page Aug 5, 2019 · 2 revisions

Getting Started

Creating an OpenFOAM Simulation from Scratch

In this first example, the usage of the InsightCAE Case Builder is demonstrated. This tool is intended to quickly create an OpenFOAM case with all its configuration files from scratch. Internally, InsightCAE manages CFD solver features in so-called case elements which can be combined into a case setup. These case elements are bound the certain features but are not tied to configuration files. For example, the MRF zone case element represents a rotating frame of reference and it writes configuration entries into different files, depending on the OpenFOAM version chosen.

In this example, a simple external aerodynamics problem is solved: the result will be the drag forces on some object exposed to a wind speed. The object could be a vehicle or a building or something else. It is not so important for this demonstration. We have chosen the object below (downloaded from here: https://www.thingiverse.com/download:925086). The object needs to be a triangulated mesh (STL). This format can exported from almost every CAD software. It was loaded into ParaView to determine its bounding box:

ParaView geometry bounding box info Elephant Geometry Bounding Box

The bounding box is shown on the "Information" tab for the geometry dataset (left image above).

The following steps will be necessary to run the desired CFD simulation:

  1. Create the basic case setup (the files in constant/ and system/ folder), including blockMeshDict and snappyHexMeshDict
  2. Create a hexahedral template mesh using blockMesh
  3. Run the trimmed mesher snappyHexMesh to insert the object into the mesh
  4. Create the field files with boundary conditions
  5. Run the Solver
  6. Postprocess the result

The domain setup shall be as in the image shown below: The object remains at its location. The domain size is controlled by the template mesh which surrounds the object. First, the size of the domain needs to be determined. It is usually related to the characteristic length of the object, i.e. in this case l=12m. Here, we arbitrarily select:

  • Length of the domain: 1l upstream and 3l downstream: L = (1+1+4)*l = 60m
  • Height H=3*l=36m
  • Width ~ 2*l to each side: W=50m

From the domain size, the location of p0 can be computed: p0=(-36 -22.95 0.285)

CFD Domain created with InsightCAE Case Builder

The OpenFOAM work starts by creating a directory for the case and load the OpenFOAM environment by sourcing the appropriate bashrc file (this may be wrapped by some alias):

$ mkdir aero_demo
$ cd aero_demo
$ source /opt/OpenFOAM/OpenFOAM-plus/etc/bashrc

The case files can now be created through InsightCAE Case Builder. It is started by this command:

$ isofCaseBuilder

Now the desired case elements are added from the top left list. Once an element is selected, it is added to the current case by clicking the ">>" button. All added elements are shown in the top right list. Add the following elements for the current example:

  1. simpleFoamNumerics from category "Numerics"
  2. kOmegaSST from "Turbulence Model"
  3. singlePhaseTransportProperties from "Material Properties"
  4. blockMeshDict_Box from "Meshing"
  5. snappyHexMeshConfiguration from "Meshing"
  6. forces from "Postprocessing"

The order of the elements is not important in general. But for internal reasons, it is yet required that one of the "*Numerics" case elements is the first in the list. Case elements might conflict, but there is currently no check for this. The user has to take care to create reasonable combinations only.

Each case element needs configuration informations and has therefore a parameter set attached to it, which needs to be edited. The parameters of the element which is currently selected in the top right list, are displayed in the lower part of the window. The parameters are organized in a tree structure on the left. For the selected parameter, the documentation and a control element to edit its value are displayed on the right.

The Case Builder window while editing the parameters of the blockMeshDict_Box case element is shown below:

InsightCAE Case Builder Elements

The next step is to edit all required parameters. The following values should be set:

  • singlePhaseTransportProperties:

    • nu : 1e-5 (air)
  • blockMeshDict_Box:

    • H: 36
    • L: 60
    • W: 50
    • p0: "-36 -22.95 0.285"
    • XmPatchName: outlet (name of the patch at the low-X end of the box ("m" as "minus")
    • XpPatchName: inlet (name of the patch at the upper-X end of the box ("p" as "plus")
    • ZmPatchName: bottom
    • defaultPatchName: sides
    • nx: 20 (number of cells in X-direction, The number of cells is chosen such that the cells are approximately cubical.)
    • ny: 10
    • nz: 10
  • snappyHexMeshDict:

    • PiM: add one entry (PiM stands for "Point in Mesh")
      • [0]: "-5 0 1"
    • features: add one entry
      • [0]: select type "Geometry"
        • fileName: Elephant_with_Howdah.stl (use "..." button to open file selection dialog)
        • name: elephant
        • maxLevel: 4
  • forces:

    • patches:
      • [0]: "elephant.*" (enter the quotes as well! They indicate a regular expression)
    • rhoInf: 1.2

The configuration should be saved by clicking on the button "Save config...", because it is needed again later on. The resulting output file is in XML format and can be edited using every text editor. Make sure, the desired OpenFOAM version is selected in the combo box "OF-Version" (it should have been detected from the environment variables), then click on "Create..." to create the OpenFOAM dictionaries.

Now, the grid can be created by:

$ blockMesh
$ snappyHexMesh -overwrite

The preprocessing is now almost complete, only the fields and BCs are missing. They are can only be created interactively after the grid is there, because only then the list of boundary patches is available. Thus now restart the Case Builder again (an reload the previously saved configuration):

$ isofCaseBuilder elephant.iscb

Change to the tab "Boundary Conditions" and click on the button "Parse boundary file". This will populate the list of available boundary patches on the top left. Available boundary condition types are listed on the top right. To assign a BC type, select a boundary and a boundary conditions type and click on "<Assign<". Similarly as before, the parameters of each patch can be edited in the lower half of the window. Assign the following BC types:

  1. bottom: WallBC
  2. elephant: WallBC
  3. inlet: VelocityInletBC
  4. outlet: PressureOutletBC
  5. sides: SimpleBC

The following parameters need to be set:

  • inlet:

    • velocity/fielddata/values/[0]:
      • value: "-10 0 0" ( a velocity of 10m/s in negative x-direction)
  • sides:

    • className: symmetryPlane

InsightCAE Case Builder boundary condition setup

It is convenient to save the configuration again ("Save config..."). The final step is now to recreate all the OpenFOAM dictionaries including the field files in the 0/ directory. This is archieved by clicking on "Create...". Now the solver can be started:

$ simpleFoam

After the solver finishes, the results can be inspected. The forces are integrated throughout the solver run and are saved in the file postProcessing/forces/0/forces.dat. To visualize the flow field, start ParaView by

$ isPV.py

Paraview offers several possibilities for visualization. A common way is to look at streamlines and the pressure field. For the current case, it looks like this:

ParaView scene streamlines and pressure distribution

Note that the mesh misses some of the features of the initial geometry. This is because of the limited mesh resolution (only refinement up to level 4 was allowed). With a finer mesh, more details will be resolved.

You can’t perform that action at this time.