Project

Simulation of flow through pipe in OpenFOAM part-1

Objective of the project:

1) calculation of flow variables.

2) Generation of blockMeshDict using the wedge boundry condition. Create the blockMeshDict file in Matlab such that the mesh is automatically created for variable.

3). Simulation the pipe flow in OpenFOAM using icoFoam solver.

4). Post prosess the velocity profile and shear stress and compare the simulation results with analytical resuts obtained using the Hagen-Poiseuille equation.

\"\"

\"\"

\"\"

Matlab code for automatic generation of blockMeshDict file:

     clear all 
     close all 
     clc
 
   %% variable values
  diameter = 0.01;
  r = diameter/2;
  L = 1.2;
  theta = input(\'Enter the value of wedge angle = \');
  %% specifing string for header part 
  h1=\'/*----------------------*- C++ -*--------------------------------------*\\\';
  h2=\'| ==========                   |                                         |\';
  h3=\'| \\\\       /   F ield          | OpenFOAM:  The Open Source CFD Toolbox  |\';
  h4=\'|  \\\\     /    O peration      | Version:   4.0                          |\';
  h5=\'|   \\\\   /     A nd            | Web:       www.OpenFOAM.org             |\';
  h6=\'|    \\\\ /      M anipulation   |                                         |\';
  h7=\' \\*---------------------------------------------------------------------*/
  h8=\'FoamFile\';
  h9=\'{\';
  h10=\'    version     2.0;\';
  h11=\'    format      ascii;\';
  h12=\'    class       dictionary;\';
  h13=\'    object      blockMeshDict;\';
  h14=\'}\';
  h15=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\';
  conv=\'convertTometers 1;\';
  
  s1=blanks(5);
  s2=blanks(10);
  s3=blanks(15);
  
  v0=[0 0 0];
  v1=[r*sind(theta/2) r*cosd(theta/2) 0];
  v2=[-r*sind(theta/2) r*cosd(theta/2) 0];
  v3=[0 0 L];
  v4=[r*sind(theta/2) r*cosd(theta/2) L];
  v5=[-r*sind(theta/2) r*cosd(theta/2) L];
  
  block=\'hex (0 0 1 2 3 3 4 5) (1 50 200) SimpleGrading(1 0.5 1)\';
  edge1=\'arc 1 2\';
  edge2=\'arc 4 5\';
  
  e1=[0 r 0];
  e2=[0 r L];
  
  inlet=\'(0 0 2 1)\';
  outlet=\'(3 4 5 3)\';
  wedge1=\'(0 1 4 3)\';
  wedge2=\'(3 5 2 0)\';
  wall=\'(4 1 2 5)\';
  axis=\'(0 3 3 0)\';
  
  final=\'// ***************************************************************** //\';
  
  %% writting the blockMeshDict
  f1=fopen(\'blockMeshDict.txt\',\'w\');
  
  fprintf(f1, \'%s rn\',h1);
  fprintf(f1, \'%s rn\',h2);
  fprintf(f1, \'%s rn\',h3);
  fprintf(f1, \'%s rn\',h4);
  fprintf(f1, \'%s rn\',h5);
  fprintf(f1, \'%s rn\',h6);
  fprintf(f1, \'%s rn\',h7);
  fprintf(f1, \'%s rn\',h8);
  fprintf(f1, \'%s rn\',h9);
  fprintf(f1, \'%s rn\',h10);
  fprintf(f1, \'%s rn\',h11);
  fprintf(f1, \'%s rn\',h12);
  fprintf(f1, \'%s rn\',h13);
  fprintf(f1, \'%s rn\',h14);
  fprintf(f1, \'%s rn\',h15);
  fprintf(f1,\'% rn\');
  
  fprintf(f1, \'%s rn\',conv);
  fprintf(f1, \'rn\');
  
  fprintf(f1,\'% rn\',\'vertices\');
  fprintf(f1,\'% rn\',\'(\');
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v0(1),v0(2),v0(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v1(1),v1(2),v1(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v2(1),v2(2),v2(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v3(1),v3(2),v3(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v4(1),v4(2),v4(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v5(1),v5(2),v5(3));
  fprintf(f1,\'% rn\',\');\');
  fprintf(f1,\'rn\');
  
  fprintf(f1,\'% rn\',\'blocks\');
  fprintf(f1,\'% rn\', \'(\');
  fprintf(f1,\'% %s rn\',s1,block);
  fprintf(f1,\'%s rn\', \');\');
  fprintf(f1,\'% rn\');
  
  fprintf(f1,\'%s rn\', \'boundry\');
  fprintf(f1,\'%s rn\',\'(\');
   
  fprintf(f1,\'%s %s rn\', s1,\'inflow\'); 
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type patch;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,inlet);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'front\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wedge;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wedge1);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'back\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wedge;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wedge2);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'wall\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wall;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wall);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'axis\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type empty;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,axis);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s rn\', \');\');
  fprintf(f1,\'rn\');
  
  fprintf(f1,\'%s rn\', \'mergePatchPairs\');
  fprintf(f1,\'%s rn\',\'(\');
  fprintf(f1,\'%s rn\',\');\');
  fprintf(f1,\'rn\');
  fprintf(f1,\'%s rn\',final);
  
  fclose(f1);
  
  
  
  
  
  
  
  
  
  
  

\"\"

\"\"

\"\"

Velocity profile at x=0.05m

\"\"

\"\"

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.

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.