The final project in my Fluid Mechanics course involved processing 16384 discrete data points generated by a computer simulation of wind flow over sand dunes. Using MATLAB I was able to create a script that processed the data and created graphics that help the audience visualize the simulated flow. The source code can be found below.
%%Â
clear;
clc;
%% Import sim6.dat
opts = delimitedTextImportOptions("NumVariables", 4);
% Specify range and delimiter
opts.DataLines = [1, Inf];
opts.Delimiter = " ";
% Specify column names and types
opts.VariableNames = ["Var1", "VarName2", "VarName3", "VarName4"];
opts.SelectedVariableNames = ["VarName2", "VarName3", "VarName4"];
opts.VariableTypes = ["string", "double", "double", "double"];
opts = setvaropts(opts, 1, "WhitespaceRule", "preserve");
opts = setvaropts(opts, 1, "EmptyFieldRule", "auto");
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Import the data
sim6 = readtable("/MATLAB Drive/sim6.dat", opts);
% Convert to output type
sim6 = table2array(sim6);
% Clear temporary variables
clear opts
%% Resize data matrix
%set m as # of rows, n as # of columns
[m,n] = size(sim6);
% Separate u, v, w from sim6.dat into [m,1] matrices
u = sim6(1:m,1);
v = sim6(1:m,2);
w = sim6(1:m,3);
% Set s as size of length/width for new matrix
s = sqrt(m);
% Resize u, v, w column vectors into s by s matrix (plane)
u = reshape(u,s,s);
v = reshape(v,s,s);
w = reshape(w,s,s);
%% (1) Create contour plots
% Streamwise velocity contour
figure(1);
contourf(u, 'LineWidth', 1);
title("Streamwise Velocity Contour");
colorbar;
% Spanwise velocity contour
figure(2);
contourf(v, 'LineWidth', 1);
title("Spanwise Velocity Contour");
colorbar;
% Vertical velocity contour
figure(3);
contourf(w, 'LineWidth', 1);
title("Vertical Velocity Contour");
colorbar;
%% (2) Create vertical vector field v & w
figure(4);
quiver(v,w);
title("Vector Field of v & w");
xlabel("v");
ylabel("w");
%% (3) Create vertical profiles
% Fix avgu, avgv, avgw size to s by 1
avgu = zeros(s,1);
avgv = zeros(s,1);
avgw = zeros(s,1);
% Calculate average u, v, w
for i = 1:s % Iterates through rows
for j = 1:s % Iterates through columns
sumu =+ u(i,j);
sumv =+ v(i,j);
sumw =+ w(i,j);
end
avgu(i,1) = sumu/s;
avgv(i,1) = sumv/s;
avgw(i,1) = sumw/s;
end
% Create vertical profile plots
figure(5);
plot(1:s, avgu, "LineWidth", 2);
title("Average Vertical Profile of u");
figure(6);
plot(1:s, avgv, "LineWidth", 2);
title("Average Vertical Profile of v");
figure(7);
plot(1:s, avgw, "LineWidth", 2);
title("Average Vertical Profile of w");
%% (4) Create contour of spanwise vorticity
% Calculate delw/dely and delv/delz
% delw/dely = rise/run, no change along the boundary border
% therefore vortx = 0 along the boundary
% Set 0 matrices
delwy = zeros(s,s);
delvz = zeros(s,s);
vortx = zeros(s,s);
% Looping from 2:s-1 accounts for 0 border
for i = 2:s-1 % Iterates through rows
for j = 2:s-1 % Iterates through columns
delwy(i,j) = (w(i,j+1) - w(i,j-1));
delvz(i,j) = (v(i+1,j) - v(i-1,j));
vortx(i,j) = 0.5*(delwy(i,j) - delvz(i,j));
end
end
% Create contour plot of streamwise vorticity
figure(8);
contourf(vortx, 'LineWidth', 0.3);
title("Streamwise Vorticity Contour");
colorbar;