Data Science for Science & Engineering: Creating a CFD 6 Degree of Freedom Kinematics OpenFoam File

In this short article I will show you how to generate a simple 6 degree of freedom kinematic file for OpenFoam. The data file we will generate specifies the magnitude and direction of motion for a series of time points.

It is a combination of a linear displacement vector and a rotation vector about the specified center of gravity (CofG) of the object, which is defined on the dynamicMeshDict file.

This data file is later linearly interpolated by OpenFoam when running your CFD simulation, so your time points do not need to match exactly the timesteps you have set in OpenFoam. However, more time points will smooth your dynamics, increasing the accuracy of your simulation, specially if, as seen in the case below, you have a sinusoidal or other non-linear motion.

The format of the data file we want to create for OpenFoam is shown below:

Each time point first specifies the reference time, and the following bracket groups contains the motion, first linear and then angular displacement in their own lists.

We will begin by importing the libraries we need: Numpy, Pandas, MatPlotLib to visualize our output, OS to import paths, and IPython to clean up our display.

We will now add our parameters for the kinematics. In this case we are making a sinusoidal pitch-plunge movement, for 5 periods. The geometric angle of attack (our pitch angle) will be 15 degrees, and our plunge amplitude will be 0.05m. It is a 2D motion, so most of our degrees of freedom are actually just going to be 0.

We are going to be saving this file as “pitchplunge.dat”

We generate our time vector by using the numpy function linspace, with our set resolution:

And now it’s just a question of creating our X,Y and Z vectors for our linear and rotational displacement. We will store them in a Pandas DataFrame (our motion matrix).

Finally we can save our motion file, adding our different brackets and required formatting as per OpenFoam’s requirements. We will use the f.write file writer, and build each line with a for loop.

We will now plot our linear displacement to double check our motion:

And now our rotational displacement:

Hope you enjoyed! You can find a video for this here, and a Jupyter Notebook to follow along here.

Scout for the IX Hispana studying vortices beyond Hadrian’s Wall.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store