Simulation of flow through a pipe of circular cross section by wedge symmetry
AIM:- To simulate a laminar flow through a pipe of circular cross section
Hagen poiseulli flow is defined as a fully developed laminar flow through a pipe. It is an exact solution of navier stokes equation.
considering water as the test fluid, the thermo-physical properties are:
- reynolds number : 2100
- dynamic viscocity: 0.89e-3
- density : 997 kg/m^3
- diameter of pipe : 0.020m
- entry length L_e: 0.06*Re*D
- length for fully developed flow :L_e+o.3
the average velocity is given by :`(Re*mu)/(rho*d)`
pressure `trianglep`:`(32*mu*v*l)/d^2`
kinematic pressure :`(triangle p)/rho`
calculated values for above conditions:
- pressure = 0.018876
- velocity = 0.1874
CODE STRUCTURE:-
the simulation of flow through entire cross section of a pipe is very resource intensive calculation so to compensate for this we can simulate the flow through a wedge shaped element of the pipe and since the pipe is of a circular cross section the results obtained will be of symmetric nature .
matlab can be used to automate the process of setting up an openFoam case.
- progam to ask for input of the thermo-physical quantities of the fluid.
the program asks user to specify the properties of the fluid, calculates the initial condition of pressure and velocity and asks for the wedge geometry , simulation time and time step. after taking the inputs it calls on different functions to set openfoam case.#a program to simulate laminar flow through a pipe of circular cross section #input variables and conditions clear all close all clc #flow variables disp(\'input flow variables\') Re = input(\'specify the reynolds number of the flow:\'); mu = input(\'dynamic viscocity of fluid:\'); D = input(\'diameter of pipe:\'); R = D/2; Rho = input(\'the density of liquid:\'); L_e = 0.06*Re*D; L = L_e+0.3; #simulation variables disp(\'input simulation parameters\') endTime = input(\'specify the end time for simulation:\'); deltaT = input(\'specify the time step for simulation:\'); #initial calculations #velocity v = (Re*mu)/(Rho*D) #pressure p = (32*mu*L*v)/(D^2); #kinematic pressure P = p/Rho #pipe geometry theta = input(\'input wedge angle\'); x = L; y = R*cosd(theta/2); z = R*sind(theta/2); #setting up an openFoam case for the simulation openFoam_case_gen velocity_gen(v); cd .. cd .. pressure_gen(P); cd .. cd .. controldict_gen(endTime ,deltaT); cd .. cd .. blockmesh_gen(x,y,z,R); cd .. cd .. transportproperties_gen(mu); cd .. - openFoam case generator
this is a function to create the folders which are typically found in a openFoam case such as constant , system and 0#function for setting up an openFoam case function out = openFoam_case_gen mkdir pipe_flow_solution; mkdir pipe_flow_solution constant; mkdir pipe_flow_solution system; mkdir pipe_flow_solution 0; end - initial value generators
#function to generate velocity file_in_loadpath function out = velocity_gen(v); cd pipe_flow_solution cd 0 h1 = (\'/*--------------------------------*- C++ -*----------------------------------*\\\'); h2 = \'\\*---------------------------------------------------------------------------*/\'; fid = fopen(\'u.txt\',\'w\'); fprintf(fid,h1) fprintf(fid,\'\\n\') fprintf(fid,\' ========= |\\n\') fprintf(fid,\' \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\n\') fprintf(fid,\' \\\\ / O peration | Website: https://openfoam.org\\n\') fprintf(fid,\' \\\\ / A nd | Version: 7\\n\') fprintf(fid,\' \\\\/ M anipulation |\\n\') fprintf(fid,\'%s\\n\',h2); fprintf(fid,\'\\n\') fprintf(fid,\'FoamFile\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' version 2.0;\\n\') fprintf(fid,\' format ascii;\\n\') fprintf(fid,\' class dictionary;\\n\') fprintf(fid,\' location \"constant\";\\n\') fprintf(fid,\' object transportProperties;\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'dimensions [0 1 -1 0 0 0 0];\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'internalField uniform (0 0 0);\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'boundaryField\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' inlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type fixedValue;\\n\') fprintf(fid,\' value uniform (%f 0 0);\\n\',v) fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' outlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type zeroGradient;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' axis\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type empty;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' top\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type noSlip;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' front\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' back\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'// ************************************************************************* //\\n\') fclose (fid) end#function to generate pressure file function out = pressure_gen(P) cd pipe_flow_solution cd 0 h1 = (\'/*--------------------------------*- C++ -*----------------------------------*\\\'); h2 = \'\\*---------------------------------------------------------------------------*/\'; fid = fopen(\'p.txt\',\'w\'); fprintf(fid,h1) fprintf(fid,\'\\n\') fprintf(fid,\' ========= |\\n\') fprintf(fid,\' \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\n\') fprintf(fid,\' \\\\ / O peration | Website: https://openfoam.org\\n\') fprintf(fid,\' \\\\ / A nd | Version: 7\\n\') fprintf(fid,\' \\\\/ M anipulation |\\n\') fprintf(fid,\'%s\\n\',h2); fprintf(fid,\'\\n\') fprintf(fid,\'FoamFile\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' version 2.0;\\n\') fprintf(fid,\' format ascii;\\n\') fprintf(fid,\' class dictionary;\\n\') fprintf(fid,\' location \"constant\";\\n\') fprintf(fid,\' object transportProperties;\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\\n\') fprintf(fid,\'dimensions [0 2 -2 0 0 0 0];\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'internalField uniform 0;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'boundaryField\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' inlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type zeroGradient;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' outlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type fixedValue;\\n\') fprintf(fid,\' value uniform (%f);\\n\',P) fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' axis\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type empty;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\' \\n\') fprintf(fid,\' top\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type zeroGradient;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' front\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' back\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'// ************************************************************************* //\\n\') fclose(fid) endthe functions take their inputs form the main program and create initial condition files of pressure and velocity in the 0 folder.
- system generator functions:
#function to generate controldict file for simulation function out = controldict_gen(endTime ,deltaT) cd pipe_flow_solution cd system h1 = (\'/*--------------------------------*- C++ -*----------------------------------*\\\'); h2 = \'\\*---------------------------------------------------------------------------*/\'; fid = fopen(\'controlDict.txt\',\'w\'); fprintf(fid,h1) fprintf(fid,\'\\n\') fprintf(fid,\' ========= |\\n\') fprintf(fid,\' \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\n\') fprintf(fid,\' \\\\ / O peration | Website: https://openfoam.org\\n\') fprintf(fid,\' \\\\ / A nd | Version: 7\\n\') fprintf(fid,\' \\\\/ M anipulation |\\n\') fprintf(fid,\'%s\\n\',h2); fprintf(fid,\'\\n\') fprintf(fid,\'FoamFile\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' version 2.0;\\n\') fprintf(fid,\' format ascii;\\n\') fprintf(fid,\' class dictionary;\\n\') fprintf(fid,\' location \"constant\";\\n\') fprintf(fid,\' object transportProperties;\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'application icoFoam;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'startFrom startTime;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'startTime 0;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'stopAt endTime;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'endTime %f;\\n\',endTime) fprintf(fid,\'\\n\') fprintf(fid,\'deltaT %f;\\n\',deltaT) fprintf(fid,\'\\n\') fprintf(fid,\'writeControl timeStep;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'writeInterval 20;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'purgeWrite 0;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'writeFormat ascii;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'writePrecision 6;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'writeCompression off;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'timeFormat general;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'timePrecision 6;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'runTimeModifiable true;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'// ************************************************************************* //\\n\') fclose(fid) end #function to create the blockmesh part file function out = blockmesh_gen(x,y,z,R) cd pipe_flow_solution cd system fid = fopen(\'blockmeshDict.txt\' , \'w\') h1 = (\'/*--------------------------------*- C++ -*----------------------------------*\\\'); h2 = \'\\*---------------------------------------------------------------------------*/\'; fprintf(fid,h1) fprintf(fid,\'\\n\') fprintf(fid,\' ========= |\\n\') fprintf(fid,\' \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\n\') fprintf(fid,\' \\\\ / O peration | Website: https://openfoam.org\\n\') fprintf(fid,\' \\\\ / A nd | Version: 7\\n\') fprintf(fid,\' \\\\/ M anipulation |\\n\') fprintf(fid,\'%s\\n\',h2); fprintf(fid,\'\\n\') fprintf(fid,\'FoamFile\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' version 2.0;\\n\') fprintf(fid,\' format ascii;\\n\') fprintf(fid,\' class dictionary;\\n\') fprintf(fid,\' location \"constant\";\\n\') fprintf(fid,\' object transportProperties;\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'convertToMeters 1;\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'vertices\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'(\\n\') fprintf(fid,\' (0 0 0)\\n\') fprintf(fid,\' (0 %f %f)\\n\',y,z) fprintf(fid,\' (0 %f %f)\\n\',y,-z) fprintf(fid,\' (%f 0 0)\\n\',x) fprintf(fid,\' (%f %f% f)\\n\',x,y,z) fprintf(fid,\' (%f %f %f)\\n\',x,y,-z) fprintf(fid,\'\\n\') fprintf(fid,\');\\n\') fprintf(fid,\'blocks\\n\') fprintf(fid,\'( hex (0 3 5 2 0 3 4 1) (300 10 1) simpleGrading (1 1 1));\\n\') fprintf(fid,\'edges\\n\') fprintf(fid,\'(\\n\') fprintf(fid,\'arc 1 2 (0 %f 0)\\n\',R) fprintf(fid,\'arc 4 5 (%f %f 0)\\n\',x,R) fprintf(fid,\');\\n\') fprintf(fid,\'boundary\\n\') fprintf(fid,\'(\\n\') fprintf(fid,\' inlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type patch;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (1 2 0 0)\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' outlet\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type patch;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (3 5 4 3)\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\' \\n\') fprintf(fid,\' top\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wall;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (2 1 4 5)\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\'\\n\') fprintf(fid,\' front\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (3 4 1 0)\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\' \\n\') fprintf(fid,\' back\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type wedge;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (3 5 2 0)\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\' \\n\') fprintf(fid,\' axis\\n\') fprintf(fid,\' {\\n\') fprintf(fid,\' type empty;\\n\') fprintf(fid,\' faces\\n\') fprintf(fid,\' (\\n\') fprintf(fid,\' (0 3 3 0)\\n\') fprintf(fid,\' );\\n\') fprintf(fid,\' }\\n\') fprintf(fid,\');\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'mergePatchPairs\\n\') fprintf(fid,\'(\\n\') fprintf(fid,\');\\n\') fclose (fid) end the functions controldict_gen and blockmesh_gen creates controlDict and blockmeshDict file in the system folder of the case
- transportproperties generator function
creates transportproperties file in the constant folder#function to create transportproperties file function out = transportproperties_gen(mu) cd pipe_flow_solution cd constant h1 = (\'/*--------------------------------*- C++ -*----------------------------------*\\\'); h2 = \'\\*---------------------------------------------------------------------------*/\'; fid = fopen(\'transportProperties.txt\',\'w\'); fprintf(fid,h1) fprintf(fid,\'\\n\') fprintf(fid,\' ========= |\\n\') fprintf(fid,\' \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\n\') fprintf(fid,\' \\\\ / O peration | Website: https://openfoam.org\\n\') fprintf(fid,\' \\\\ / A nd | Version: 7\\n\') fprintf(fid,\' \\\\/ M anipulation |\\n\') fprintf(fid,\'%s\\n\',h2); fprintf(fid,\'\\n\') fprintf(fid,\'FoamFile\\n\') fprintf(fid,\'{\\n\') fprintf(fid,\' version 2.0;\\n\') fprintf(fid,\' format ascii;\\n\') fprintf(fid,\' class dictionary;\\n\') fprintf(fid,\' location \"constant\";\\n\') fprintf(fid,\' object transportProperties;\\n\') fprintf(fid,\'}\\n\') fprintf(fid,\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'nu [0 2 -1 0 0 0 0] %f;\\n\',mu) fprintf(fid,\'\\n\') fprintf(fid,\'\\n\') fprintf(fid,\'// ************************************************************************* //\\n\') fclose (fid) end
an example case for wedge angle of 4 degrees and simulation time of 10 and time step 0f 0.01s is shown
- blockmeshdict file:
/*--------------------------------*- C++ -*----------------------------------*\\ ========= | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\\\ / O peration | Website: https://openfoam.org \\\\ / A nd | Version: 7 \\\\/ M anipulation | \\*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; object blockMeshDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // convertToMeters 1; vertices ( (0 0 0) (0 9.993908e-3 3.489950e-4) (0 9.993908e-3 -3.489950e-4) (2.82 0 0) (2.82 9.993908e-3 3.489950e-4) (2.82 9.993908e-3 -3.489950e-4) ); blocks ( hex (0 3 5 2 0 3 4 1) (300 10 1) simpleGrading (1 1 1)); edges ( arc 1 2 (0 0.01 0) arc 4 5 (2.82 0.01 0) ); boundary ( inlet { type patch; faces ( (1 2 0 0) ); } outlet { type patch; faces ( (3 5 4 3) ); } top { type wall; faces ( (2 1 4 5) ); } front { type wedge; faces ( (3 4 1 0) ); } back { type wedge; faces ( (3 5 2 0) ); } axis { type empty; faces ( (0 3 3 0) ); } ); mergePatchPairs ( ); // ************************************************************************* // - controlDict file
/*--------------------------------*- C++ -*----------------------------------*\\ ========= | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\\\ / O peration | Website: https://openfoam.org \\\\ / A nd | Version: 7 \\\\/ M anipulation | \\*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location \"system\"; object controlDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // application icoFoam; startFrom startTime; startTime 0; stopAt endTime; endTime 10; deltaT 0.01; writeControl timeStep; writeInterval 20; purgeWrite 0; writeFormat ascii; writePrecision 6; writeCompression off; timeFormat general; timePrecision 6; runTimeModifiable true; // ************************************************************************* // - u
/*--------------------------------*- C++ -*----------------------------------*\\ ========= | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\\\ / O peration | Website: https://openfoam.org \\\\ / A nd | Version: 7 \\\\/ M anipulation | \\*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volVectorField; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { inlet { type fixedValue; value uniform (0.0937 0 0); } outlet { type zeroGradient; } axis { type empty; } top { type noSlip; } front { type wedge; } back { type wedge; } } // ************************************************************************* // - p
/*--------------------------------*- C++ -*----------------------------------*\\ ========= | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\\\ / O peration | Website: https://openfoam.org \\\\ / A nd | Version: 7 \\\\/ M anipulation | \\*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; object p; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 2 -2 0 0 0 0]; internalField uniform 0; boundaryField { inlet { type zeroGradient; } outlet { type fixedValue; value uniform 0.018; } axis { type empty; } top { type zeroGradient; } front { type wedge; } back { type wedge; } } // ************************************************************************* //
RESULTS:
- initially the flow is not parabolic but as it crosses the entrance length the flow is fully developed and the velocity profile is parabolic
- maximum velocity is at the center and minimum velocity is at the walls
- wedge mesh:
- pressure distribution:
velocity distribution:
development of flow :
0.2m
0.5m
0.9m
1.2m
2.4m
2.8m
it is evident from the above curves that as the length of the pipe increses the velocity profile achies parabolic shape