0% found this document useful (0 votes)
36 views6 pages

File: /home/mpelibn/desktop/rigid - SBS.M Page 1 of 6

This document contains code for analyzing fluid forces on rigid cylinders subjected to laminar flow. It reads in force and displacement data from a file, calculates mean, RMS and maximum values, and plots the results. Specifically, it: 1) Reads force and displacement data for 3 cylinders from a file and calculates aerodynamic coefficients over time. 2) Calculates mean, RMS, and maximum values of drag, lift, and side force coefficients as well as cross-flow displacement for each cylinder. 3) Plots the aerodynamic coefficients, cross-flow displacement, and performs an FFT of the lift coefficient data to analyze frequencies.

Uploaded by

Bin Liu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

File: /home/mpelibn/desktop/rigid - SBS.M Page 1 of 6

This document contains code for analyzing fluid forces on rigid cylinders subjected to laminar flow. It reads in force and displacement data from a file, calculates mean, RMS and maximum values, and plots the results. Specifically, it: 1) Reads force and displacement data for 3 cylinders from a file and calculates aerodynamic coefficients over time. 2) Calculates mean, RMS, and maximum values of drag, lift, and side force coefficients as well as cross-flow displacement for each cylinder. 3) Plots the aerodynamic coefficients, cross-flow displacement, and performs an FFT of the lift coefficient data to analyze frequencies.

Uploaded by

Bin Liu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

File: /home/mpelibn/Desktop/rigid_SBS.

m Page 1 of 6

clc
clear
close all
%===================================================================
% QUALITY SETTING
%===================================================================

% Defaults for this blog post


width = 3; % Width in inches
height = 3; % Height in inches
alw = 0.75; % AxesLineWidth
fsz = 45; % Fontsize
lw = 2; % LineWidth
%lw = 1.5;
msz = 12; % MarkerSize

% Change default axes fonts.


set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize', 30)
set(0,'DefaultTextFontWeight','Bold')

% Change default text fonts.


set(0,'DefaultTextFontname', 'Times New Roman')
set(0,'DefaultTextFontSize', 30)

% Change default line width.


set(0,'defaultlinelinewidth',2)

%===================Parameters=============================================
%total number of iterations
m = 8031;
%number of nondimensionalized time for fully-developed flow
ms = 300;
mf = 400;
dt = 0.05;
time = dt:dt:m*dt;
rho = 1;
h = 10;
D = 1;
U = 1;
cd_coe=0.5*rho*h*D*U*U;
%==========================================================================

%=================READING DATA============================================================

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Laminar/DNS Data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Input_file_id = fopen('rigid.oisd', 'r');

Line1 = fgets(Input_file_id); %this will skip line 0 and read line 1

for i=1:m

Line2 = fgets(Input_file_id);
Line3 = fgets(Input_file_id);

%total cylinders
for j=1:19 %total number of lines per body; in fact, the index of line starting from 0
if(j == 8)

Vector1(i, :) = fscanf(Input_file_id, '%f', [1 3] );

end

if(j == 12)
File: /home/mpelibn/Desktop/rigid_SBS.m Page 2 of 6

Vel1(i, :) = fscanf(Input_file_id, '%f', [1 3]);


end

if(j == 15)

Disp1(i, :) = fscanf(Input_file_id, '%f', [1 3] );

end

Line4 = fgets(Input_file_id) ;

end

%cylinder1 at top
for j=1:19
if(j == 8)

Vector2(i, :) = fscanf(Input_file_id, '%f', [1 3] );

end

if(j == 12)

Vel2(i, :) = fscanf(Input_file_id, '%f', [1 3]);


end

if(j == 15)

Disp2(i, :) = fscanf(Input_file_id, '%f', [1 3] );

end

Line5 = fgets(Input_file_id) ;

end

%cylinder2 at bottom
for j=1:19
if(j == 8)

Vector3(i, :) = fscanf(Input_file_id, '%f', [1 3] );

end

if(j == 12)

Vel3(i, :) = fscanf(Input_file_id, '%f', [1 3]);


end

if(j == 15)

Disp3(i, :) = fscanf(Input_file_id, '%f', [1 3]);

end

Line6 = fgets(Input_file_id) ;

end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%=======================================================================================

%========================================================================================
File: /home/mpelibn/Desktop/rigid_SBS.m Page 3 of 6

% AVERAGE VALUE
%========================================================================================

Cd1_mean=mean(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd1_rms=rms(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd1_max=Cd1_rms*sqrt(2);
Cl1_mean=mean(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl1_rms=rms(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl1_max=Cl1_rms*sqrt(2);
Cz1_mean=mean(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz1_rms=rms(Vector1(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz1_max=Cz1_rms*sqrt(2);

Cd2_mean=mean(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd2_rms=rms(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd2_max=Cd2_rms*sqrt(2);
Cl2_mean=mean(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl2_rms=rms(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl2_max=Cl2_rms*sqrt(2);
Cz2_mean=mean(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz2_rms=rms(Vector2(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz2_max=Cz2_rms*sqrt(2);

Cd3_mean=mean(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd3_rms=rms(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,1)/cd_coe);
Cd3_max=Cd3_rms*sqrt(2);
Cl3_mean=mean(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl3_rms=rms(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,2)/cd_coe);
Cl3_max=Cd3_rms*sqrt(2);
Cz3_mean=mean(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz3_rms=rms(Vector3(ms*D/U/dt+1:mf*D/U/dt-1,3)/cd_coe);
Cz3_max=Cz3_rms*sqrt(2);

X1=mean(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,1));
Ax1_rms=rms(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,1)-X1);
Ay1_rms=rms(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,2));
Aymax1=Ay1_rms*sqrt(2);
Ymax1=max(max(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,2)),abs(min(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,2))));

X2=mean(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,1));
Ax2_rms=rms(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,1)-X2);
Ay2_rms=rms(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,2));
Aymax2=Ay2_rms*sqrt(2);
Ymax2=max(max(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,2)),abs(min(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,2))));

X3=mean(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,1));
Ax3_rms=rms(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,1)-X3);
Ay3_rms=rms(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,2));
Aymax3=Ay3_rms*sqrt(2);
Ymax3=max(max(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,2)),abs(min(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,2))));
%==================================================================================

%==================================================================================
% Outputs
%==================================================================================

%-----------------------------------------
%Cd & CL & Cz
%--------------------------------------------------
figure (1)
plot(time, Vector1(:, 1)/cd_coe, 'r','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector2(:, 1)/cd_coe, '--b','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector3(:, 1)/cd_coe, '-.g','LineWidth',lw,'MarkerSize',msz)
axis([dt m*dt*D/U -5 5])
xlabel('$tU/D$','Interpreter','latex'); % x-axis label
ylabel('$C_{d}$','Interpreter','latex'); % y-axis label
a=legend('$Cd_{tot}$','$Cd_{1}$','$Cd_{2}$');
set(a,'FontSize',fsz,'interpreter','latex');
File: /home/mpelibn/Desktop/rigid_SBS.m Page 4 of 6

figure (2)
plot(time, Vector1(:, 2)/cd_coe, 'r','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector2(:, 2)/cd_coe, '--b','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector3(:, 2)/cd_coe, '-.g','LineWidth',lw,'MarkerSize',msz)
axis([dt m*dt*D/U -5 5])
xlabel('$tU/D$','Interpreter','latex'); % x-axis label
ylabel('$Cl$','Interpreter','latex'); % y-axis label
a=legend('$Cl_{tot}$','$Cl_{1}$','$Cl_{2}$');
set(a,'FontSize',fsz,'interpreter','latex');

figure (3)
plot(time, Vector1(:, 3)/cd_coe, 'r','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector2(:, 3)/cd_coe, '--b','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Vector3(:, 3)/cd_coe, '-.g','LineWidth',lw,'MarkerSize',msz)
axis([dt m*dt*D/U -5 5])
xlabel('$tU/D$','Interpreter','latex'); % x-axis label
ylabel('$Cz$','Interpreter','latex'); % y-axis label
a=legend('$Cz_{tot}$','$Cz_{1}$','$Cz_{2}$');
set(a,'FontSize',fsz,'interpreter','latex');

%-------------------------------------------------
% A_Y/D vs T*
%-------------------------------------------------------
figure (4)
plot(time, Disp1(:, 2), 'r','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Disp2(:, 2), '--b','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Disp3(:, 2), '-.g','LineWidth',lw,'MarkerSize',msz)
axis([dt m*dt*D/U -5 5])
xlabel('$tU/D$','Interpreter','latex'); % x-axis label
ylabel('$A_{Y}/D$','Interpreter','latex'); % y-axis label
a=legend('$A_{Ytot}/D$', '$A_{Y1}/D$', '$A_{Y2}/D$');
set(a,'FontSize',fsz,'interpreter','latex');

%{
%--------------------------------------------------
% A_X/D vs T*
%--------------------------------------------------
figure (5)
plot(time, Disp1(:, 1), 'red','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Disp2(:, 1), '--b','LineWidth',lw,'MarkerSize',msz)
hold on
plot(time, Disp3(:, 1), '-.g','LineWidth',lw,'MarkerSize',msz)
axis([dt m*dt*D/U -5 5])
xlabel('$tU/D$','Interpreter','latex'); % x-axis label
ylabel('$A_{X}/D$','Interpreter','latex'); % y-axis label
a=legend('$A_{Xtot}/D$', '$A_{X1}/D$', '$A_{X2}/D$');
set(a,'FontSize',fsz,'interpreter','latex');
%}

%{
%---------------------------------------------------------------------
% TRAJECTORY
%--------------------------------------------------------------------

figure (5)
plot(Disp1(ms*D/U/dt+1:mf*D/U/dt-1,1), Disp1(ms*D/U/dt+1:mf*D/U/dt-1,2),
'blue','LineWidth',lw,'MarkerSize',msz)
title('Trajectory of whole structure');
xlabel('$X_{tot}$','Interpreter','latex'); % x-axis label
ylabel('$Y_{tot}$','Interpreter','latex'); % y-axis label
File: /home/mpelibn/Desktop/rigid_SBS.m Page 5 of 6

figure (6)
plot(Disp2(ms*D/U/dt+1:mf*D/U/dt-1,1), Disp2(ms*D/U/dt+1:mf*D/U/dt-1,2),
'blue','LineWidth',lw,'MarkerSize',msz);
title('$Trajectory of cylinder 1$','Interpreter','latex');
xlabel('$X_{1}$','Interpreter','latex'); % x-axis label
ylabel('$Y_{1}$','Interpreter','latex'); % y-axis label

figure (7)
plot(Disp3(ms*D/U/dt+1:mf*D/U/dt-1,1), Disp3(ms*D/U/dt+1:mf*D/U/dt-1,2),
'blue','LineWidth',lw,'MarkerSize',msz)
title('$Trajectory of cylinder 2$','Interpreter','latex');
xlabel('$X_{2}$','Interpreter','latex'); % x-axis label
ylabel('$Y_{2}$','Interpreter','latex'); % y-axis label

%}

%-----------------------------------------
% FFT
%-----------------------------------------
NFFT = 2^nextpow2(mf*D/U/dt-1-ms*D/U/dt+1);
Y1 = fft(Vector1((mf*D/U/dt-1-(mf*D/U/dt-1-ms*D/U/dt)+1):mf*D/U/dt-1,2)/cd_coe,NFFT)/(mf*D/U/dt-1-ms*D/
U/dt+1);
Fs1=1/dt;
f1 = Fs1/2*linspace(0,1,NFFT/2+1);
fftx1=f1;
ffty1=2*abs(Y1(1:NFFT/2+1));
[ymx1,loc1]=max(ffty1(:,1));
St1=fftx1(loc1)*D/U;

Y2 = fft(Vector2((mf*D/U/dt-1-(mf*D/U/dt-1-ms*D/U/dt)+1):mf*D/U/dt-1,2)/cd_coe,NFFT)/(mf*D/U/dt-1-ms*D/
U/dt+1);
Fs2=1/dt;
f2 = Fs2/2*linspace(0,1,NFFT/2+1);
fftx2=f2;
ffty2=2*abs(Y2(1:NFFT/2+1));
[ymx2,loc2]=max(ffty2(:,1));
St2=fftx2(loc2)*D/U;

Y3 = fft(Vector3((mf*D/U/dt-1-(mf*D/U/dt-1-ms*D/U/dt)+1):mf*D/U/dt-1,2)/cd_coe,NFFT)/(mf*D/U/dt-1-ms*D/
U/dt+1);
Fs3=1/dt;
f3 = Fs3/2*linspace(0,1,NFFT/2+1);
fftx3=f3;
ffty3=2*abs(Y3(1:NFFT/2+1));
[ymx3,loc3]=max(ffty3(:,1));
St3=fftx3(loc3)*D/U;

figure (8)
plot(fftx1,ffty1,'LineWidth',lw,'MarkerSize',msz)
xlim([0 1])
xlabel('$Frequency (Hz)$','Interpreter','latex');
title('$Single-Sided Amplitude Spectrum of ytot(t)$','Interpreter','latex');

figure (9)
plot(fftx2,ffty2,'LineWidth',lw,'MarkerSize',msz)
xlim([0 1])
xlabel('$Frequency (Hz)$','Interpreter','latex');
title('$Single-Sided Amplitude Spectrum of y1(t)$','Interpreter','latex');

figure (10)
plot(fftx3,ffty3,'LineWidth',lw,'MarkerSize',msz)
File: /home/mpelibn/Desktop/rigid_SBS.m Page 6 of 6

xlim([0 1])
xlabel('$Frequency (Hz)$','Interpreter','latex');
title('$Single-Sided Amplitude Spectrum of y2(t)$','Interpreter','latex');

You might also like