Challenge

Week 10 - Simulation of Flow through a pipe in OpenFoam

To tackle this challenge, we will simulate an axi-symmetric flow through a pipe using a wedge boundary condition, perform numerical analysis of the flow, and validate the results with Hagen-Poiseuille's equations for fully developed laminar flow. I'll walk you through the steps and provide MATLAB code to automate the creation of the OpenFOAM blockMeshDict file for the simulation.

Step-by-Step Plan:

  1. Understanding the Problem:

    • Laminar flow through a constant cross-section pipe at an inlet Reynolds number of 2100.
    • Fully developed flow is expected after a certain hydrodynamic entrance length.
    • Validation using Hagen-Poiseuille law, which gives an analytical solution for velocity and pressure drop in fully developed laminar pipe flow.
  2. Wedge Geometry Setup:

    • The wedge geometry is created by collapsing one face of a hexahedral block.
    • The wedge angle should be less than 5 degrees to approximate axi-symmetry.
  3. Mathematical Equations:

    • Hagen-Poiseuille Law for fully developed laminar flow:
      • Velocity profile: u(r)=umax(1−(rR)2)u(r) = u_{\text{max}} \left( 1 - \left( \frac{r}{R} \right)^2 \right)
      • Pressure drop per unit length: ΔP=8μQπR4\Delta P = \frac{8 \mu Q}{\pi R^4}​
    • Where:
      • RR is the pipe radius,
      • μ\mu is the dynamic viscosity,
      • umaxu_{\text{max}} is the maximum velocity at the centerline,
      • QQ is the volumetric flow rate.
  4. Key Outputs:

    • Hydrodynamic entrance length: LH=0.05×Re×DL_H = 0.05 \times \text{Re} \times DLH​=0.05×Re×D
    • Fully developed velocity profile validation.
    • Maximum velocity and pressure drop validation.
    • Wall shear stress validation: τw=4ΔPLR\tau_w = \frac{4 \Delta P}{L} R
  5. MATLAB Code for blockMeshDict Generation: The following MATLAB script will automate the creation of the blockMeshDict file, taking inputs like pipe length, diameter, wedge angle, etc.

function generateBlockMeshDict(pipe_length, pipe_diameter, wedge_angle, num_cells_length, num_cells_radial, num_cells_angular)
% Function to generate blockMeshDict file for OpenFOAM wedge geometry simulation.
% Convert wedge_angle to radians for further calculations
wedge_angle_rad = deg2rad(wedge_angle);
% Pipe dimensions
radius = pipe_diameter / 2;
length = pipe_length;
% Define the vertices for a wedge (hex block)
vertices = [
0, 0, 0;
radius*cos(wedge_angle_rad), radius*sin(wedge_angle_rad), 0;
radius*cos(wedge_angle_rad), radius*sin(wedge_angle_rad), length;
0, 0, length;
0, 0, 0;
radius, 0, 0;
radius, 0, length;
0, 0, length
];
% Define the block connectivity
blocks = [0, 1, 2, 3, 4, 5, 6, 7];
% Define the number of cells in each direction
cells = [num_cells_radial, num_cells_angular, num_cells_length];
% Open the file to write
fileID = fopen('blockMeshDict', 'w');
% Write header information
fprintf(fileID, '/*--------------------------------*- C++ -*----------------------------------*\n');
fprintf(fileID, '| ========= | |\n');
fprintf(fileID, '| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n');
fprintf(fileID, '| \\ / O peration | Version: 2.3.0 |\n');
fprintf(fileID, '| \\ / A nd | Web: www.OpenFOAM.org |\n');
fprintf(fileID, '| \\/ M anipulation | |\n');
fprintf(fileID, '/*---------------------------------------------------------------------------*/\n');
fprintf(fileID, 'FoamFile\n{\n');
fprintf(fileID, ' version 2.0;\n');
fprintf(fileID, ' format ascii;\n');
fprintf(fileID, ' class dictionary;\n');
fprintf(fileID, ' object blockMeshDict;\n');
fprintf(fileID, '}\n\n');
% Write units and scaling factor
fprintf(fileID, 'convertToMeters 1;\n\n');
% Write vertices section
fprintf(fileID, 'vertices\n(\n');
for i = 1:size(vertices, 1)
fprintf(fileID, ' (%.6f %.6f %.6f)\n', vertices(i, 1), vertices(i, 2), vertices(i, 3));
end
fprintf(fileID, ');\n\n');
% Write block information
fprintf(fileID, 'blocks\n(\n');
fprintf(fileID, ' hex (%d %d %d %d %d %d %d %d) (%d %d %d) simpleGrading (1 1 1)\n', blocks, cells);
fprintf(fileID, ');\n\n');
% Write boundary patches
fprintf(fileID, 'boundary\n(\n');
fprintf(fileID, ' inlet\n {\n');
fprintf(fileID, ' type patch;\n');
fprintf(fileID, ' faces\n (\n');
fprintf(fileID, ' (0 4 7 3)\n');
fprintf(fileID, ' );\n');
fprintf(fileID, ' }\n\n');
fprintf(fileID, ' outlet\n {\n');
fprintf(fileID, ' type patch;\n');
fprintf(fileID, ' faces\n (\n');
fprintf(fileID, ' (1 5 6 2)\n');
fprintf(fileID, ' );\n');
fprintf(fileID, ' }\n\n');
fprintf(fileID, ' wall\n {\n');
fprintf(fileID, ' type wall;\n');
fprintf(fileID, ' faces\n (\n');
fprintf(fileID, ' (1 5 6 2)\n');
fprintf(fileID, ' );\n');
fprintf(fileID, ' }\n');
fprintf(fileID, ');\n\n');
% Close file
fclose(fileID);
disp('blockMeshDict file generated successfully.');
end
generateBlockMeshDict(5, 0.1, 3, 100, 20, 50);

How to Use the Code:

  1. Save the code in a file called generateBlockMeshDict.m.
  2. In MATLAB, call the function with the desired pipe dimensions and mesh properties

  1. This will generate a blockMeshDict file for a pipe of length 5 m, diameter 0.1 m, and a wedge angle of 3°, with 100 cells in the radial direction, 20 angular cells, and 50 cells along the length.

Validation:

  1. Hydrodynamic Length: Compare the entrance length computed from the simulation with the theoretical prediction LH=0.05×Re×DL_H = 0.05 \times \text{Re} \times D.
  2. Fully Developed Flow Profile: Plot the numerical velocity profile at fully developed sections and compare with the analytical profile u(r)=umax(1−(r/R)2).
  3. Pressure Drop: Measure pressure drop across the pipe from the simulation and compare with the analytical expression.
  4. Wall Shear Stress: Calculate wall shear stress from both the simulation and the analytical model.

This setup should allow you to simulate the flow and validate it against analytical solutions efficiently. Let me know if you need further modifications!

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.