Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

OBJECTIVE: Simulate an axi-symmetric flow by applying the wedge boundary condition. The flow is laminar and flows through a constant cross-section pipe at an inlet Reynold's number of 2100.

THEORY:

`Deltap = (8(mu)LQ)/(piR^4)`

Given parameters

wedge angle less than 5 degrees

Flow axi symmetrical

Fluid is incompressible and flow is laminar

Reynolds number 2100

PROCEDURE

Mesh file was created MATLAB program

then velocity and pressure is applied according to BC

ControlDict is edited for simulaton control

blockMesh is used to check the mesh

then icoFoam solver is used once the simulation is completed it is opened in paraview using paraFoam

we run the simulation after which we use plot over line filter to plot required results

MATLAB CODE FOR blockMeshDict FILE:

close all
clear all
clc
%variables
D =0.01;
r=D/2;
L=1.2;
theta = input('input the value of wedge angle = ');

%HEADER STRING
h1 ='/*--------------------------------*- C++ -*----------------------------------*\';
 h2=' =========                 |';
 h3=' \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox';
  h4=' \\    /   O peration     | Website:  https://openfoam.org';
   h5='\\  /    A nd           | Version:  9';
    h6=' \\/     M anipulation  |';
h7='\*---------------------------------------------------------------------------*/';
h8='FoamFile';
h9='{';
    h10='format      ascii;';
    h11='class       dictionary;';
    h12='object      blockMeshDict;';
   h13=' }';
h14='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';
conv ='convertToMeters 1;';

sp1 = blanks(5);
sp2 = blanks(10);
sp3 = blanks(15);
v_0 = [0 0 0];
v_1 = [r*sind(theta/2) r*cosd(theta/2) 0];
v_2 = [-r*sind(theta/2) r*cosd(theta/2) 0];
v_3 = [0 0 L];
v_4 = [r*sind(theta/2) r*cosd(theta/2) L];
v_5 = [-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 = '// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

f1 = fopen('blockMeshDict.doc','w');
fprintf(f1,'%sn',h1);
fprintf(f1,'%sn',h2);
fprintf(f1,'%sn',h3);
fprintf(f1,'%sn',h4);
fprintf(f1,'%sn',h5);
fprintf(f1,'%sn',h6);
fprintf(f1,'%sn',h7);
fprintf(f1,'%sn',h8);
fprintf(f1,'%sn',h9);
fprintf(f1,'%sn',h10);
fprintf(f1,'%sn',h11);
fprintf(f1,'%sn',h12);
fprintf(f1,'%sn',h13);
fprintf(f1,'%sn',h14);

fprintf(f1,'n');

fprintf(f1,'%sn',conv);
fprintf(f1,'n');

fprintf(f1,'%sn','vertices');
fprintf(f1,'%sn','(');
fprintf(f1,'%s (%f %f %f) n',sp1,v_0(1),v_0(2),v_0(3));
fprintf(f1,'%s (%f %f %f) n',sp1,v_1(1),v_1(2),v_1(3));
fprintf(f1,'%s (%f %f %f) n',sp1,v_2(1),v_2(2),v_2(3));
fprintf(f1,'%s (%f %f %f) n',sp1,v_3(1),v_3(2),v_3(3));
fprintf(f1,'%s (%f %f %f) n',sp1,v_4(1),v_4(2),v_4(3));
fprintf(f1,'%s (%f %f %f) n',sp1,v_5(1),v_5(2),v_5(3));
fprintf(f1,'%sn',');');
fprintf(f1,'n');


fprintf(f1,'%sn','blocks');
fprintf(f1,'%sn','(');
fprintf(f1,'%s %s n',sp1,block);
fprintf(f1,'%sn',');');
fprintf(f1,'n');

fprintf(f1,'%s n','edges');
fprintf(f1,'%sn','(');
fprintf(f1,'%s %s (%f %f %f) n',sp1,edge1,e1(1),e1(2),e1(3));
fprintf(f1,'%s %s (%f %f %f) n',sp1,edge2,e2(1),e2(2),e2(3));
fprintf(f1,'%sn',');');
fprintf(f1,'n');


fprintf(f1,'%s n','boundary');
fprintf(f1,'%sn','(');

fprintf(f1,'%s %s n',sp1,'inflow');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type patch;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,inlet);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%s %s n',sp1,'outflow');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type patch;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,outlet);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%s %s n',sp1,'front');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type wedge;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,wedge1);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%s %s n',sp1,'back');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type wedge;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,wedge2);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%s %s n',sp1,'wall');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type wall;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,wall);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%s %s n',sp1,'axis');
fprintf(f1,'%s %s n',sp1,'{');
fprintf(f1,'%s %s n',sp2,'type empty;');
fprintf(f1,'%s %s n',sp2,'faces');
fprintf(f1,'%s %s n',sp2,'(');
fprintf(f1,'%s %s n',sp3,axis);
fprintf(f1,'%s %s n',sp2,');');
fprintf(f1,'%s %s n',sp1,'}');

fprintf(f1,'%sn',');');
fprintf(f1,'n');

fprintf(f1,'%sn','mergePatchPairs');
fprintf(f1,'%sn','(');
fprintf(f1,'%sn',');');
fprintf(f1,'n');
fprintf(f1,'%s n',final);

fclose(f1);


CONTROL DICT FILE:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application icoFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 10;

deltaT 0.005;

writeControl timeStep;

writeInterval 20;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression off;

timeFormat general;

timePrecision 6;

runTimeModifiable true;


// ************************************************************************* //

INITIAL PRESSURE CONDITION:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 0;

boundaryField
{
inflow
{
type zeroGradient;
}

outflow
{
type fixedValue;
value uniform 0;
}

axis
{
type empty;
}

back
{
type wedge;
}

front
{
type wedge;
}

wall
{
type zeroGradient;
}


// ************************************************************************* //

INITIAL VELOCITY CONDITIONS:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
inflow
{
type fixedValue;
value uniform(0.1875 0 0);
}

outflow
{
type zeroGradient;
}

axis
{
type empty;
}
back
{
type wedge;
}
front
{
type wedge;
}
wall
{
type noSlip;
}
}

// ************************************************************************* //

OUTPUTS:

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.