0% found this document useful (0 votes)
0 views16 pages

ME505-2235901-HW3

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

Q1 Code:

% ME505 HW3
clc
clear all
close all

% Define symbolic variables


syms lamda lamda_f

% Constants
U = 0.25; % m/s
r0 = 0.1; % meter
mu = 855E-6; % Dynamic viscosity of water
nu = 855E-6/(1000/1.003); % Kinematic viscosity of water
k = 0.613; % W/(m.K), thermal conductivity of water
Pr = 5.83; % Prandtl number of water

% Define functions
f2 = @(lamda) (2 + lamda/6) * (37/315 - lamda/945 - lamda^2/9072);
K = @(lamda) (37/315 - lamda/945 - lamda^2/9072)^2 * lamda;
f1 = @(lamda) (3/10 - lamda/120) / (37/315 - lamda/945 - lamda^2/9072);
H = @(lamda) 2 * f2(lamda) - 2 * K(lamda) * (2 + f1(lamda));

% Numerically approximate the roots of H


lamda_stag = vpasolve(H(lamda), lamda);

% Filter roots within the range -12 to 12


lamda_0 = lamda_stag(lamda_stag >= -12 & lamda_stag <= 12 & imag(lamda_stag) ==
0);
disp('Initial lamda:');
disp(lamda_0)

% Stagnation values
K_0 = double(K(lamda_0));
Z_0 = double(K_0 / (2 * U / r0));
f2_0 = double(f2(lamda_0));
f1_0 = double(f1(lamda_0));
H_0 = double(H(lamda_0));

% Define the differential equation as a function


dZdx = @(x, Z, H) H / (2 * U * sin(x / r0));

% Initialize arrays
num_steps = 17000;
x_values = linspace(0.001, 0.187, num_steps); % Define the range of x values
Z_values = zeros(1, num_steps);
lamda_values = zeros(1, num_steps);
delta_values = zeros(1, num_steps);
H_values = zeros(1, num_steps);
f2_values = zeros(1, num_steps);
f1_values = zeros(1, num_steps);
K_values = zeros(1, num_steps);
h_values = zeros(1, num_steps); % Heat transfer coefficient
delta_T_values = zeros(1, num_steps); % Thermal boundary layer thickness
Nu_values = zeros(1, num_steps); % Nusselt number
Tau_w_values = zeros(1, num_steps); % Wall shear stress

% Set initial values


Z_values(1) = Z_0;
lamda_values(1) = lamda_0;
delta_values(1) = sqrt(lamda_0 * nu / (2 * U * cos(x_values(1) / r0) / r0));
H_values(1) = H_0;
f2_values(1) = f2_0;
f1_values(1) = f1_0;
K_values(1) = K_0;
delta_T_values(1) = Pr^(-1/3) * delta_values(1);
h_values(1) = 3 * k / (2 * Pr^(-1/3) * delta_values(1));
Nu_values(1) = h_values(1) * 2 * r0 / k;
Tau_w_values(1) = mu * 2 * U * sin(x_values(1) / r0) * (2 + lamda_0 / 6) /
delta_values(1);

for i = 2:num_steps
% Get previous values
Z_prev = Z_values(i-1);
x_prev = x_values(i-1);
lamda_prev = lamda_values(i-1);
H_prev = H_values(i-1);

% Update x
x_current = x_values(i);
a = 2 * U * sin(x_prev / r0); % Uinf
b = 2 * U * cos(x_prev / r0) / r0; % dUinf/dx

% Solve the differential equation using ode23 for the current step
odefun = @(x, Z) dZdx(x, Z, H_prev);
[x_sol, Z_sol] = ode23(odefun, [x_prev, x_current], Z_prev);
Z_values(i) = Z_sol(end);

% Define the equation involving lamda_f


eq = ((37/315 - lamda_f/945 - lamda_f^2/9072)^2 * (lamda_f / b) ==
Z_values(i));
lamda_sol = vpasolve(eq, lamda_f, lamda_prev); % Use previous lambda as
initial guess

% Filter roots within the range -12 to 12


lamda_filtered = double(lamda_sol(lamda_sol >= -12 & lamda_sol <= 12 &
imag(lamda_sol) == 0));
if isempty(lamda_filtered)
disp(['No valid lambda found at iteration ', num2str(i)]);
break; % Exit the loop if no valid solution is found
end

% Update lamda_values
lamda_values(i) = lamda_filtered(1); % Use the first valid solution

% Calculate delta, delta_T, h, Nu, and Tau_w


delta_values(i) = sqrt(lamda_values(i) * nu / (2 * U * cos(x_current / r0) /
r0));
f2_values(i) = f2(lamda_values(i));
f1_values(i) = f1(lamda_values(i));
K_values(i) = K(lamda_values(i));
H_values(i) = H(lamda_values(i));
delta_T_values(i) = Pr^(-1/3) * delta_values(i);
h_values(i) = 3 * k / (2 * Pr^(-1/3) * delta_values(i));
Nu_values(i) = h_values(i) * 2 * r0 / k;
Tau_w_values(i) = mu * 2 * U * sin(x_current / r0) * (2 + lamda_values(i) / 6)
/ delta_values(i);
% Diagnostics: display values at each iteration
disp(['Iteration: ', num2str(i)]);
disp([' Z_values: ', num2str(Z_values(i))]);
disp([' lamda_values: ', num2str(lamda_values(i))]);
disp([' f2_values: ', num2str(f2_values(i))]);
disp([' f1_values: ', num2str(f1_values(i))]);
disp([' K_values: ', num2str(K_values(i))]);
disp([' H_values: ', num2str(H_values(i))]);
disp([' delta_T_values: ', num2str(delta_T_values(i))]);
disp([' h_values: ', num2str(h_values(i))]);
disp([' Nu_values: ', num2str(Nu_values(i))]);
disp([' Tau_w_values: ', num2str(Tau_w_values(i))]);
end

% Convert x to theta
theta_values = x_values / r0;

% Plotting results for visualization


figure;
plot(theta_values*180/pi, delta_T_values);
title('Thermal Boundary Layer Thickness vs \theta');
xlabel('\theta (degrees)');
ylabel('delta_T values');

figure;
plot(theta_values*180/pi, lamda_values);
title('Lamda values vs \theta');
xlabel('\theta (degrees)');
ylabel('lamda values');

figure;
plot(theta_values*180/pi, delta_values);
title('Boundary Layer Thickness vs \theta');
xlabel('\theta (degrees)');
ylabel('delta');

figure;
plot(theta_values*180/pi, h_values);
title('Convection coefficient vs \theta');
xlabel('\theta (degrees)');
ylabel('h');

figure;
plot(theta_values*180/pi, Nu_values);
title('Nusselt Number vs \theta');
xlabel('\theta (degrees)');
ylabel('Nu');

figure;
plot(theta_values*180/pi, Tau_w_values);
title('Wall Shear Stress (\tau_w) vs \theta');
xlabel('\theta (degrees)');
ylabel('\tau_w (Pa)');

% Report the final theta value


final_theta = theta_values(find(lamda_values >= -12, 1, 'last'));
disp(['Final theta value: ', num2str(final_theta*180/pi), ' degrees']);
Figure 1 – Seperation angle for laminar flow

Figure 2 – Lambda values vs. Theta


I think the jumps are due to cos term in the differential of the dUinf/dx term
because jump at teta=90 degree does not appear on lambda graph.

Figure 3 – Shear stress vs. Theta

Figure 4 – Boundary layer thickness vs. Theta


Figure 5 – Thermal boundary layer thickness vs. Theta
Figure 6 – Convection coefficient vs. Theta

Figure 7 – Nusselt number vs. Theta


Q2- Φ(η) graph for random Φ(0) condition:

Nu is independent from the value of the Φ at the center. All Φ(0) values give Nu=9.8696.

Figure 8 – Φ(η) vs. Theta

Q2 Code:

function find_nu
% Initial guess for Nu
Nu_guess = 6;

% Use the fzero function to find the root of the boundary condition function
options = optimset('Display','iter');
Nu_corrected = fzero(@boundary_condition, Nu_guess, options);

fprintf('The true value of Nu is: %.10f\n', Nu_corrected);

% Solve the system with the found nu


[x_vals, y_vals] = solve_odes(Nu_corrected);

% Plot the solution


figure;
plot(x_vals, y_vals(1,:), 'DisplayName', 'Φ(x)');
xlabel('η');
ylabel('Φ(η)');
title(sprintf('Solution of the Energy Equation (For Φ=T-Ts) with Nusselt Number=%.4f',
Nu_corrected));
legend;
grid on;

% Verify boundary conditions


y_at_1 = y_vals(1,end);
y_prime_at_0 = y_vals(2,1);
fprintf('y(1) = %.10f, y''(0) = %.10f\n', y_at_1, y_prime_at_0);
end
function res = boundary_condition(Nu)
% Boundary condition to be satisfied at x = 1
[~, y_vals] = solve_odes(Nu);
y_at_1 = y_vals(1,end);
res = y_at_1; % We want this to be 0
end
function [x_vals, y_vals] = solve_odes(Nu)
% Define the system of ODEs
function dydx = odes(x, y)
dydx = [y(2); -Nu/4 * y(1)];
end
% Initial conditions
y0 = [1; 0]; % y(0) = 1 and y'(0) = 0

% Solve the system using ode45


[x_vals, y_vals] = ode45(@odes, [0, 1], y0);

% Transpose to match the MATLAB output format


y_vals = y_vals';
end

REFERENCES

Al Ahmar, R., & Majdalani, J. (2022). On the Kármán momentum-integral approach and the
Pohlhausen paradox: Extension to a cylinder in Crossflow with a potential Farfield Motion. Physics of
Fluids, 34(6). https://doi.org/10.1063/5.0096780

Mecili, M., & Mezaache, E. H. (2013). Slug flow-heat transfer in parallel plate microchannel
including slip effects and axial conduction. Energy Procedia, 36, 268–277.
https://doi.org/10.1016/j.egypro.2013.07.031

You might also like