Challenge

Week 12 - Validation studies of Symmetry BC vs Wedge BC in OpenFOAM vs Analytical H.P equation

clear all
close all
clc

%  inputs
% assumptions made the fluid is assumed as water
Re=2100; % given reynolds number
rho=997; % density of the water 
D=0.02; % diiameter of the pipe
r=D/2; % radius of the pipe
mu=0.89*10^-3; % dynamic viscosity of the water at 25 degree celcius
v=0.88927*10^-6; % kinematic viscosity of the water at 25 degree celcius
theta=input('Enter the value of the wedge angle= ')
L_h=0.06*Re*D; % hydrodynamic lenght 

L=L_h+0.5;
% Analytical solutions 
V_avg=(Re*mu)/(rho*D);  % average velocity
V_max=2*V_avg;   % maximum velocity
P_drop=(32*mu*L*V_avg)/D^2;  % pressure drop
P_kinematic=(P_drop)/rho;  % kinematic pressure drop

% vertices 
v0=[0 0 0]
v1=[0 r*cosd(theta/2) r*sind(theta/2)]
v2=[0 r*cosd(theta/2) -r*sind(theta/2)]
v3=[L 0 0]
v4=[L r*cosd(theta/2) r*sind(theta/2)]
v5=[L r*cosd(theta/2) -r*sind(theta/2)]


% PRINTING THE blockMeshDict FILE

H1='/*--------------------------------*- C++ -*----------------------------------*';
H2='  =========                 |';
H3='  \      /  F ield         | OpenFOAM: The Open Source CFD Toolbox';
H4='  \    /   O peration     | Website:  https://openfoam.org';
H5='    \  /    A nd           | Version:  8';
H6='     \/     M anipulation  |';
H7='*---------------------------------------------------------------------------*/';
H8='FoamFile';
H9='{'
H10='    version     2.0;';
H11='    format      ascii;';
H12='    class       dictionary;';
H13='    object      blockMeshDict;';
H14='}'
H15='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

% opening the file
f1=fopen('blockMeshDict_parsedNEW.txt','wt');

fprintf(f1,'%s n',H1);
fprintf(f1,'%s n',H2);
fprintf(f1,'%s n',H3);
fprintf(f1,'%s n',H4);
fprintf(f1,'%s n',H5);
fprintf(f1,'%s n',H6);
fprintf(f1,'%s n',H7);
fprintf(f1,'%s n',H8);
fprintf(f1,'%s n',H9);
fprintf(f1,'%s n',H10);
fprintf(f1,'%s n',H11);
fprintf(f1,'%s n',H12);
fprintf(f1,'%s n',H13);
fprintf(f1,'%s n',H14);
fprintf(f1,'%s n',H15);
fprintf(f1,'n');

fprintf(f1,'%s n','convertToMeters 1;');

fprintf(f1,'%s n','vertices');
fprintf(f1,'%s n','(');
fprintf(f1,'%s (%f %f %f) n',blanks(5),v0(1),v0(2),v0(3));
fprintf(f1,'%s (%f %f %f) n',blanks(5),v1(1),v1(2),v1(3));
fprintf(f1,'%s (%f %f %f) n',blanks(5),v2(1),v2(2),v2(3));
fprintf(f1,'%s (%f %f %f) n',blanks(5),v3(1),v3(2),v3(3));
fprintf(f1,'%s (%f %f %f) n',blanks(5),v4(1),v4(2),v4(3));
fprintf(f1,'%s (%f %f %f) n',blanks(5),v5(1),v5(2),v5(3));
  
fprintf(f1,'%s n',');');

fprintf(f1,'%s n','blocks');
fprintf(f1,'%s n','(');
fprintf(f1,'%s %s n',blanks(5),'hex (0 2 1 0 3 5 4 3) (20 1 200) simpleGrading (1 1 1)');
fprintf(f1,'%s n',');');

fprintf(f1,'%s n','edges');
fprintf(f1,'%s n','(');
fprintf(f1,'arc 1 2 (%f %f %f) n',0,r,0);
fprintf(f1,'arc 4 5 (%f %f %f) n',L,r,0);
fprintf(f1,'%s n',');');

fprintf(f1,'%s n','boundary');
fprintf(f1,'( n');
fprintf(f1,'%s %s n',blanks(5),'inlet');
fprintf(f1,'%s %s n',blanks(5),'{');
fprintf(f1,'%s %s n',blanks(10),'type patch;');
fprintf(f1,'           %s n','faces');
fprintf(f1,'          %s n','(');
fprintf(f1,'           (%d %d %d %d)n',0, 1, 2, 0);
fprintf(f1,'          );n');
fprintf(f1,'      }n');
fprintf(f1,'      %sn','outlet');
fprintf(f1,'      {n');
fprintf(f1,'        %sn','type patch;');
fprintf(f1,'         %sn','faces');
fprintf(f1,'         (n');
fprintf(f1,'            (%d %d %d %d)n',3, 4, 5, 3);
fprintf(f1,'          );n');
fprintf(f1,'     }n');
fprintf(f1,'     %sn','wedge_front');
fprintf(f1,'     {n');
fprintf(f1,'         %sn','type wedge;');
fprintf(f1,'         %sn','faces');
fprintf(f1,'         (n');
fprintf(f1,'             (%d %d %d %d)n',2, 5, 3, 0);
fprintf(f1,'n');            
fprintf(f1,'          );n');
fprintf(f1,'     }n');
fprintf(f1,'     %sn','wedge_Back');
fprintf(f1,'     {n');
fprintf(f1,'%sn','         type wedge;');
fprintf(f1,'%sn','         faces');
fprintf(f1,'         (n');
fprintf(f1,'n');            
fprintf(f1,'             (%d %d %d %d)n',0, 3, 4, 1);
fprintf(f1,'          );n');
fprintf(f1,'     }n');
fprintf(f1,'     %sn','top');
fprintf(f1,'     {n');
fprintf(f1,'         %sn','type wall;');
fprintf(f1,'         %sn','faces');
fprintf(f1,'         (n');
fprintf(f1,'             (%d %d %d %d)n',1, 4, 5, 2);
fprintf(f1,'          );n');
fprintf(f1,'     }n');
fprintf(f1,'     %sn','axis');
fprintf(f1,'     {n');
fprintf(f1,'         %sn','type empty;');
fprintf(f1,'         %sn','faces');
fprintf(f1,'         (n');
fprintf(f1,'             (%d %d %d %d)n',0, 3, 3, 0);
fprintf(f1,'          );n');
fprintf(f1,'     }n');
fprintf(f1,' );n');
fprintf(f1,'n'); 
fprintf(f1,' %sn','mergePatchPairs');
fprintf(f1,'(n');
fprintf(f1,' );n');
fprintf(f1,'n'); 
fprintf(f1,' // ************************************************************************* //n');
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.