Week 10 - Simulation of Flow through a pipe in OpenFoam
Numerical Simulation Setup (OpenFOAM)
- Define a wedge-shaped domain using
blockMeshDict (automated using MATLAB). - Specify boundary conditions:
- Inlet: Parabolic velocity profile (or uniform if developing flow is studied).
- Wall: No-slip condition.
- Outlet: Zero pressure gradient.
- Wedge: Symmetry condition.
- Run steady or transient flow simulation using
simpleFoam or pimpleFoam. - Extract results for velocity, pressure, and shear stress.
blockMeshDict (automated using MATLAB).- Inlet: Parabolic velocity profile (or uniform if developing flow is studied).
- Wall: No-slip condition.
- Outlet: Zero pressure gradient.
- Wedge: Symmetry condition.
simpleFoam or pimpleFoam.2. Validation Criteria
- Hydrodynamic Entrance Length:
- Lh≈0.05×Re×D
- Velocity Profile (Hagen-Poiseuille Law):
- u(r)=Umax(1−R2r2)
- Umax=32Uavg
- Pressure Drop:
- LΔP=D232μUavg
- Wall Shear Stress:
- τw=drμdur=R
-
- function generateBlockMeshDict(pipe_length, diameter, wedge_angle, num_cells_axial, num_cells_radial)
- % Define file path
- fileID = fopen('blockMeshDict', 'w');
-
- % Compute key dimensions
- R = diameter / 2;
- theta = wedge_angle * (pi / 180); % Convert to radians
-
- % Write blockMeshDict header
- fprintf(fileID, 'FoamFile\n{\n version 2.0;\n format ascii;\n class dictionary;\n object blockMeshDict;\n}\n\n');
- % Define vertices
- fprintf(fileID, 'vertices\n(\n');
- fprintf(fileID, ' (0 0 0)\n'); % Vertex 0
- fprintf(fileID, ' (%f 0 0)\n', R); % Vertex 1
- fprintf(fileID, ' (%f %f 0)\n', R*cos(theta), R*sin(theta)); % Vertex 2
- fprintf(fileID, ' (0 %f 0)\n', R*sin(theta)); % Vertex 3
- fprintf(fileID, ' (0 0 %f)\n', pipe_length); % Vertex 4
- fprintf(fileID, ' (%f 0 %f)\n', R, pipe_length); % Vertex 5
- fprintf(fileID, ' (%f %f %f)\n', R*cos(theta), R*sin(theta), pipe_length); % Vertex 6
- fprintf(fileID, ' (0 %f %f)\n', R*sin(theta), pipe_length); % Vertex 7
- fprintf(fileID, ');\n\n');
- % Define blocks
- fprintf(fileID, 'blocks\n(\n');
- fprintf(fileID, ' hex (0 1 2 3 4 5 6 7) (%d %d 1) simpleGrading (1 1 1)\n', num_cells_axial, num_cells_radial);
- fprintf(fileID, ');\n\n');
- % Define boundary conditions
- fprintf(fileID, 'boundary\n(\n');
- fprintf(fileID, ' inlet\n {\n type patch;\n faces ((0 3 7 4));\n }\n');
- fprintf(fileID, ' outlet\n {\n type patch;\n faces ((1 5 6 2));\n }\n');
- fprintf(fileID, ' wall\n {\n type wall;\n faces ((3 2 6 7));\n }\n');
- fprintf(fileID, ' wedge1\n {\n type wedge;\n faces ((0 1 5 4));\n }\n');
- fprintf(fileID, ' wedge2\n {\n type wedge;\n faces ((2 3 7 6));\n }\n');
- fprintf(fileID, ');\n');
- % Close file
- fclose(fileID);
- fprintf('blockMeshDict file generated successfully!\n');
- end
- Running the OpenFOAM Simulation
- Lh≈0.05×Re×D
- u(r)=Umax(1−R2r2)
- Umax=32Uavg
- LΔP=D232μUavg
- τw=drμdur=R
-
- function generateBlockMeshDict(pipe_length, diameter, wedge_angle, num_cells_axial, num_cells_radial)
- % Define file path
- fileID = fopen('blockMeshDict', 'w');
- % Compute key dimensions
- R = diameter / 2;
- theta = wedge_angle * (pi / 180); % Convert to radians
- % Write blockMeshDict header
- fprintf(fileID, 'FoamFile\n{\n version 2.0;\n format ascii;\n class dictionary;\n object blockMeshDict;\n}\n\n');
- % Define vertices
- fprintf(fileID, 'vertices\n(\n');
- fprintf(fileID, ' (0 0 0)\n'); % Vertex 0
- fprintf(fileID, ' (%f 0 0)\n', R); % Vertex 1
- fprintf(fileID, ' (%f %f 0)\n', R*cos(theta), R*sin(theta)); % Vertex 2
- fprintf(fileID, ' (0 %f 0)\n', R*sin(theta)); % Vertex 3
- fprintf(fileID, ' (0 0 %f)\n', pipe_length); % Vertex 4
- fprintf(fileID, ' (%f 0 %f)\n', R, pipe_length); % Vertex 5
- fprintf(fileID, ' (%f %f %f)\n', R*cos(theta), R*sin(theta), pipe_length); % Vertex 6
- fprintf(fileID, ' (0 %f %f)\n', R*sin(theta), pipe_length); % Vertex 7
- fprintf(fileID, ');\n\n');
- % Define blocks
- fprintf(fileID, 'blocks\n(\n');
- fprintf(fileID, ' hex (0 1 2 3 4 5 6 7) (%d %d 1) simpleGrading (1 1 1)\n', num_cells_axial, num_cells_radial);
- fprintf(fileID, ');\n\n');
- % Define boundary conditions
- fprintf(fileID, 'boundary\n(\n');
- fprintf(fileID, ' inlet\n {\n type patch;\n faces ((0 3 7 4));\n }\n');
- fprintf(fileID, ' outlet\n {\n type patch;\n faces ((1 5 6 2));\n }\n');
- fprintf(fileID, ' wall\n {\n type wall;\n faces ((3 2 6 7));\n }\n');
- fprintf(fileID, ' wedge1\n {\n type wedge;\n faces ((0 1 5 4));\n }\n');
- fprintf(fileID, ' wedge2\n {\n type wedge;\n faces ((2 3 7 6));\n }\n');
- fprintf(fileID, ');\n');
- % Close file
- fclose(fileID);
- fprintf('blockMeshDict file generated successfully!\n');
- end
- Running the OpenFOAM Simulation
1.Generate Mesh
blockMesh
2.Run the Simulation
simpleFoam
3.Post-process Results
paraFoam
5. Expected Results
- Hydrodynamic length should match Lh=0.05×Re×D.
- Velocity profile should be parabolic and match Hagen-Poiseuille.
- Pressure drop along the pipe should match theoretical values.
- Shear stress at the wall should match analytical values.