# OpenFOAM-version-7/C2/Simulating-Hagen-Poiseuille-flow-through-a-pipe-in-OpenFOAM/English

Jump to: navigation, search

Title of the script: Simulating Hagen Poiseuille flow through a pipe in OpenFOAM

Author: Divyesh Variya

Keywords: OpenFOAM, Hagen Poiseuille, Pipe flow, icoFoam, controlDict, Video-Tutorial

 Visual Cue Narration Slide: Opening Slide Welcome to this tutorial on Simulating Hagen Poiseuille flow through a pipe in OpenFOAM. Slide: Learning Objective In this tutorial, we will learn to, Set up the boundary and initial conditions Set up the physical properties Set up the solve & write control parameter and Run the simulation Slide: System Specifications To record this tutorial, I am using, Ubuntu Linux OS version 18.04 OpenFOAM version 7 ParaView version 5.6.0 and gedit Text editor You may use any other text editor of your choice. Slide: Prerequisites If not, please go through the prerequisite OpenFOAM tutorial on https://spoken-tutorial.org As a prerequisite: You should be familiar with Hagen Poiseuille flow and basic Fluid Dynamics concepts You should also be familiar with creation of a 3D pipe geometry in OpenFOAM If you are not, please go through the prerequisite OpenFOAM tutorial on this website. Slide: Code Files The files used in this tutorial are available in the Code Files link on this tutorial page Please download and extract them Make a copy and then use them while practising Slide: Problem Setup In this diagram, a section view of a 3D pipe is shown. This describes the problem statement. The diameter of the pipe is 1 centimeter and its length is 30 centimeters. It has one inlet, one outlet and a cylindrical wall. The fluid here is water and its kinematic viscosity is taken as 1e to the power minus 6. The Inlet velocity is 0.025 metres per second and the Outlet pressure is 0 Pascals as shown in the diagram. Slide: Geometry Check Highlight 250 Highlight laminar Only Narration Le = 0.06*Re*D Highlight 0.15 m Let us check whether our geometry is suitable or not. Reynolds number of the problem is 250. Hence, the flow is laminar. For fully developed flow, length of the geometry should be greater than the Entrance length. Entrance length can be calculated by this formula. The length we have taken is greater than the Entrance length. Slide: Solver detail To simulate this problem, we will use the icoFoam solver. icoFoam is a transient solver for incompressible, laminar flow of Newtonian fluids. This is the most suitable solver for Hagen Poiseuille flow. Slide : Pressure Boundary Condition The Pressure boundary conditions used are, At inlet - zero gradient At outlet - fixed Pressure and At wall - zero gradient Slide: Velocity Boundary Condition The Velocity boundary conditions used are, At inlet - fixed value At outlet - zero Gradient and At wall - No Slip Only Narration We will use the mesh that we have created in the tutorial “Creating 3D Pipe Geometry and Mesh in OpenFoam”. Press Ctrl + Alt + T keys Open the terminal by pressing the Ctrl, Alt and T keys together. [Terminal] Only Narration From now onwards please remember to press the Enter key after typing each command. [Terminal] Type: cd \$FOAM_RUN At the prompt, type the following command to go to the RUN directory. [Terminal] Type: cd pipe Navigate to the pipe case folder. [Terminal] Type: mv 0.Orig 0 Now, rename zero dot Orig folder to zero by typing this command. [Terminal] Type: gedit 0/p Let us open the “p” file in a text editor. [gedit - p] Highlight dimensions [0 2 -2 0 0 0 0]; Here we can see, the p file is in the form of pressure divided by density. This means, it is kinematic pressure. [gedit - p] Highlight Selection in the Text Editor >> Delete Delete the lines from internalField to the end of the file as shown here. [gedit - pressure] Open the file pressure.txt, that you had downloaded in any text editor. [gedit - pressure] Highlight Selection in the Text Editor >> Copy Copy the entire content of the text file. [gedit - p] Now let me switch back to the “p” file. [gedit - p] Paste Paste the copied contents into the “p” file as shown here. [gedit - p] Highlight internalField Right after dimensions, we have to define the initial condition. It could be uniform, non-uniform or in the form of code. [gedit - p] Highlight uniform 0; In this case, we will use the initial condition as uniform zero. This means that the kinematic pressure inside the entire domain is zero. [gedit - p] Highlight boundaryField In the boundaryField, we specify boundary conditions for all patches and walls. [gedit - p] Highlight Selection in the Text Editor >> inlet Boundary condition for inlet in pressure is defined as shown. [gedit - p] Highlight type zeroGradient; Type of the boundary condition is zeroGradient. Zero Gradient boundary extrapolates the quantity to the patch from the nearest cell value. So, the value at the patch will be the same as the cell value. Note that z is small and G is capital. [gedit - p] Highlight Selection in the Text Editor >> wall Boundary condition for the wall is defined as the same as inlet. [gedit - p] Highlight Selection in the Text Editor >> outlet Boundary condition for outlet in pressure is defined as shown here. [gedit - p] Highlight type fixedValue; value 0; The type of boundary condition is fixedValue. Value given is zero. CTRL+S >> Close Text Editor Now, save the p file and close the text editor. [Terminal] Type: gedit 0/U Now, let us set the initial and boundary condition for velocity. To do so, open the U file in a text editor. [gedit - U] Highlight dimensions [0 1 -1 0 0 0 0]; Dimensions here are in meters per second. [gedit - U] Highlight internalField uniform (0 0 0); Velocity is a vector field. So the internal initial field is set as uniform (0 0 0). [gedit - U] Highlight Selection in the Text Editor >> Delete Delete the lines from boundaryField to the end of the file as shown here. [gedit - velocity] Open the velocity.txt file that you had downloaded in a text editor. [gedit - velocity] Highlight Selection in the Text Editor >> Copy Copy the entire content of the text file. [gedit - U] Paste Paste the copied contents into the “U” file as shown. [gedit - U] Highlight boundaryField In the boundaryField, we will specify boundary conditions for all patches and walls. [gedit - U] Highlight Selection in the Text Editor >> inlet Boundary condition for inlet in velocity is defined as shown here. [gedit - U] Highlight type fixedValue; value uniform (0 0 0.025); Type of the boundary condition is fixedValue. Value of velocity is 0.025 meters per second in the Z direction. [gedit - U] Highlight type noSlip; Boundary condition for the wall is defined as noSlip. This means velocity at the wall is zero. [gedit - U] Highlight type zeroGradient; Boundary condition for outlet is zeroGradient, defined as shown here. CTRL+S >> Close Text Editor Now, save the U file and close the text editor. [Terminal] Type: gedit constant/transportProperties Open transport properties file from constant folder in the text editor. [gedit - transportProperties] Highlight nu All properties of fluid which remain constant during the simulation is to be specified in the constant folder. Here, we will set the value of kinematic viscosity. [gedit - transportProperties] Highlight [0 2 -1 0 0 0 0] Dimensions of kinematic viscosity are specified here. [gedit - transportProperties] Change: 0.01 >> 1e-06 To set the value of nu, replace 0.01 to 1e to the power minus 6. CTRL+S >> Close Text Editor Now, save the transportProperties file and close the text editor. Only Narration Solve & write control parameters can be modified in the controlDict file. The controlDict file is located in the system folder. [Terminal] Type: gedit system/controlDict Open the controlDict file in a text editor. [gedit - controlDict] Highlight Selection in the Text Editor >> Delete Delete the lines from application to the end of the file as shown here. [gedit - control] Open the control.txt file that you had downloaded in a text editor. [gedit - control] Highlight Selection in the Text Editor >> Copy Copy the entire content of the text file. [gedit - controlDict] Paste And paste the copied contents into the “controlDict” file as shown here. [gedit - controlDict] Highlight application icoFoam; First line of the controlDict file shows the name of the solver. In our case it is icoFoam. [gedit - controlDict] Highlight startFrom startTime; startTime 0; The second and third lines are start simulation controls. Our simulation will start from the value specified in start time. Here our start time is set to zero. [gedit - controlDict] Highlight stopAt endTime; endTime 5; The fourth and fifth lines are stop simulation controls. Simulation will stop at the endTime of 5 seconds. [gedit - controlDict] Highlight deltaT 1e-2; Then the value of delta T is given, which is 1e to the power minus 2. So, it will simulate for 5 seconds with in a 1e to the power minus 2 time step. [gedit - controlDict] Highlight writeInterval 100; writeInterval is 100. So it will print and save every 100 time-step value that OpenFOAM solves. So we will get results written for 1, 2, 3, 4, and 5 seconds. [gedit - controlDict] Highlight purgeWrite 2; OpenFOAM gives the option to save only the last few time steps. To enable that option, you can use the purgeWrite value. By changing it to 2, we will get the 2 latest updated time-step results. The old files will automatically be deleted. At the end of the simulation we will get results of 4 and 5 seconds. This option will save space on your computer. Only Narration The rest of the options are for the format of writing data files in OpenFOAM. We do not need to change them. Therefore, we won’t be making any more changes to the controlDict file. CTRL+S >> Close Text Editor Now, save the controlDict file and close the text editor. Only Narration We are done setting up the case. And now we will run the simulation. [Terminal] Type: icoFoam To do so, type icoFoam in the terminal and press Enter. Only Narration It will take some time to simulate, based on your computer’s hardware. For me it took around 4 minutes to simulate. [Terminal] Highlight End Once the simulation is finished, you will get this line at the end. Slide: Formula and Analytical Solution Highlight 2.4 Pa Highlight 0.05 m/s To calculate pressure at inlet, let us put the values of the U, L, D and Po in this formula. We will get an inlet pressure value of 2.4 Pascals. Maximum velocity will be twice of average velocity, as per analytical solution. Slide: Result Comparison From the simulation we get, Maximum velocity 0.05 metres per second and inlet Pressure 2.8 Pascals. In CFD, there are always some deviations in results of analytical and numerical solutions. We will discuss results in details later in this series. Only Narration With this we have come to the end of this tutorial. To summarize. Slide: Summary In this tutorial, we have learnt to, Set up the boundary and initial conditions Set up the physical properties Set up the solve & write control parameter and Run the simulation Slide: About the Spoken Tutorial Project The video at the following link summarises the Spoken Tutorial project. Please download and watch it. Slide: Spoken Tutorial Workshops We conduct workshops using Spoken Tutorials and give certificates. Please contact us. Slide: Spoken Tutorial Forum Please post your timed queries in this forum. Slide: FOSSEE Forum Do you have any general/technical questions? Please visit the forum given in this link. Slide: FOSSEE Case Study Project The FOSSEE team coordinates solving feasible CFD problems of reasonable complexity using OpenFOAM. We give honorarium and certificates to those who do this. For more details, please visit these sites. Slide: Spoken Tutorial The Spoken Tutorial project is supported by MHRD, Govt. of India. The script for this tutorial is contributed by Divyesh Variya. And this is Swetha Sridhar from IIT Bombay signing off. Thank you for joining.