%% MATLAB program to Auto-generate the blockMeshDict file for a Wedge geometry:
clear all;
close all;
clc;
%% Input Parameters
Re = 2100; % Given Reynold\'s Number
d = 0.02; % Diameter of the pipe
r = d/2; % Radius of the pipe
L_entrance = 0.06*Re*d; % Length of the pipe
fprintf(\'Enter 2, 3, 4, 5 for wedge boundary condition nEnter 10, 25, 45 for symmetry boundary conditionn\');
theta = input(\'Enter the angle in angles:n \'); % Angle of wedge
mu = 0.89e-3; % Viscosity of water at 25 deg C
rho = 997.0; % Density of water at 25 deg C
nu = mu/rho; % Kinematic Viscosity of water at 25 deg C
%% Calculation of pressure and velocity:
L = L_entrance + 0.3; % Length of the Wedge
v_avg = Re*mu/(d*rho); % Average Velocity
v_max = 2*v_avg; % Max Velocity
del_P = (32*mu*v_avg*L)/(d^2); % Pressure Drop
kin_P = del_P/rho; % KinematicPressure Drop
%% Calculating the vertices of the wedge:
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)];
%% String format specifying for BlockMesh File:
head1 = \"/*--------------------------------*- C++ -*----------------------------------*\";
head2 = \" ========= | \";
head3 = \" \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \";
head4 = \" \\ / O peration | Website: https://openfoam.org \";
head5 = \" \\ / A nd | Version: 6 \";
head6 = \" \\/ M anipulation | \";
head7 = \"*---------------------------------------------------------------------------*/\";
b4 = blanks(4);
b8 = blanks(8);
b12 = blanks(12);
b16 = blanks(16);
dict1 = \" version 2.0;\";
dict2 = \" format ascii;\";
dict3 = \" class dictionary;\";
dict4 = \" object blockMeshDict;\";
dict5 = \"// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\";
conv = \"convertToMeters 1;\";
vertex1 = \"vertices\";
blocks1 = b4 + \"hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1)\";
footer = \"// ************************************************************************* //\";
%% Creating BlockMeshDict file for OpenFOAM:
f1 = fopen(\'blockMeshDict_45.txt\',\'wt\');
% Printing the Header File
fprintf(f1,\'%sn\',head1);
fprintf(f1,\'%sn\',head2);
fprintf(f1,\'%sn\',head3);
fprintf(f1,\'%sn\',head4);
fprintf(f1,\'%sn\',head5);
fprintf(f1,\'%sn\',head6);
fprintf(f1,\'%sn\',head7);
fprintf(f1,\'FoamFilen{n\');
fprintf(f1,\'%sn\',dict1);
fprintf(f1,\'%sn\',dict2);
fprintf(f1,\'%sn\',dict3);
fprintf(f1,\'%sn}n\',dict4);
fprintf(f1,\'%sn\',dict5);
fprintf(f1,\'n%sn\',conv);
% Printing the vertices
fprintf(f1,\'nverticesn(n\');
fprintf(f1,\'%s(%d %d %d)n\',b4,v0(1),v0(2),v0(3));
fprintf(f1,\'%s(%d %f %f)n\',b4,v1(1),v1(2),v1(3));
fprintf(f1,\'%s(%d %f %f)n\',b4,v2(1),v2(2),v2(3));
fprintf(f1,\'%s(%f %d %d)n\',b4,v3(1),v3(2),v3(3));
fprintf(f1,\'%s(%f %f %f)n\',b4,v4(1),v4(2),v4(3));
fprintf(f1,\'%s(%f %f %f)n\',b4,v5(1),v5(2),v5(3));
% Printing the blocks
fprintf(f1,\');nnblocksn(n\');
fprintf(f1,\'%sn);nn\',blocks1);
fprintf(f1,\'edgesn(n\');
% Printing the edges
fprintf(f1,\'%sarc 1 2 (0 %0.3f 0)n\',b4,r);
fprintf(f1,\'%sarc 4 5 (%0.4f %0.3f 0)n\',b4,L,r);
% Printing the boundaries
fprintf(f1,\');nnboundaryn(n\');
fprintf(f1,\'%saxisn%s{n\',b4,b4);
fprintf(f1,\'%stype empty;n%sfacesn%s(n%s(0 3 3 0)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\'%swalln%s{n\',b4,b4);
fprintf(f1,\'%stype wall;n%sfacesn%s(n%s(2 5 4 1)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\'%sinletn%s{n\',b4,b4);
fprintf(f1,\'%stype patch;n%sfacesn%s(n%s(0 0 2 1)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\'%soutletn%s{n\',b4,b4);
fprintf(f1,\'%stype patch;n%sfacesn%s(n%s(3 4 5 3)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\'%swedgeFrontn%s{n\',b4,b4);
fprintf(f1,\'%stype symmetry;n%sfacesn%s(n%s(0 3 5 2)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\'%swedgeBackn%s{n\',b4,b4);
fprintf(f1,\'%stype symmetry;n%sfacesn%s(n%s(0 1 4 3)n%s);n%s}n\',b8,b8,b8,b12,b8,b4);
fprintf(f1,\');nnmergePatchPairsn(n);nn\');
fprintf(f1,\'%s\',footer);