0% found this document useful (0 votes)
15 views12 pages

Me24m026 Ahmt Na 2

The document presents a Python code solution for an advanced heat and mass transfer assignment, focusing on solving differential equations related to velocity and temperature profiles. It includes iterative methods for boundary conditions and plots for velocity and temperature profiles across various Prandtl numbers. The results indicate convergence and provide final values for the Nusselt number and temperature derivatives at specific conditions.
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)
15 views12 pages

Me24m026 Ahmt Na 2

The document presents a Python code solution for an advanced heat and mass transfer assignment, focusing on solving differential equations related to velocity and temperature profiles. It includes iterative methods for boundary conditions and plots for velocity and temperature profiles across various Prandtl numbers. The results indicate convergence and provide final values for the Nusselt number and temperature derivatives at specific conditions.
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/ 12

NAME: DINESH ARAVINDHAN R

ROLL NO: ME24M026

COMPUTER ASSIGNMENT 2

ME5101- ADVANCED HEAT AND MASS TRANSFER

Solution:
PYTHON CODE:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from scipy.optimize import newton

# Parameters and discretization setup


xi = 10
dxi = 0.001
max_steps = 1001
num_points = int(xi / dxi + 1)
xi_range = np.linspace(0, xi, num_points)
tolerance = 1e-7

# Initializing solution arrays


u = np.zeros((num_points, max_steps))
v = np.zeros((num_points, max_steps))
w = np.zeros((num_points, max_steps))

# Boundary conditions
u[0, :] = 0 # u(0) = 0
v[0, :] = 0 # v(0) = 0

# Initial guesses for w to implement the shooting method


w[0, 0] = 10
w[0, 1] = 40

# Solve the differential equations iteratively


iterations = 0
for step in range(max_steps):
for i in range(1, num_points):
u[i, step] = u[i-1, step] + v[i-1, step] * dxi
v[i, step] = v[i-1, step] + w[i-1, step] * dxi
w[i, step] = w[i-1, step] - (u[i-1, step] * w[i-1, step]) * dxi / 2

# Check if the boundary condition at infinity is met within tolerance


if abs(v[num_points-1, step] - 1) < tolerance:
iterations = step
break

# Adjust w[0, step+1] using a secant-like approach for improved guess


if step >= 1:
w[0, step+1] = w[0, step] + (1.0 - v[num_points-1, step]) * (w[0, step] - w[0, step-1]) /
(v[num_points-1, step] - v[num_points-1, step-1])

# Ensure non-negative values for the updated guess


w[0, step+1] = max(w[0, step+1], 0)

# Plotting v vs xi to show velocity profile


plt.figure(figsize=(10, 5))
plt.plot(xi_range, v[:, iterations], color='darkgreen') # Changed to dark green
plt.title('Velocity Profile (u/U_inf vs xi)')
plt.xlabel("xi")
plt.ylabel('u/U_inf')
plt.grid(True)
plt.show()

# Plotting w vs xi for curvature profile visualization


plt.figure(figsize=(10, 5))
plt.plot(xi_range, w[:, iterations], color='darkorange') # Changed to dark orange
plt.title('Curvature Profile (f" vs xi)')
plt.xlabel("xi")
plt.ylabel("f''")
plt.grid(True)
plt.show()

# Function for the temperature profile's differential equation


def temperature_ode(xi, y, v_values, Pr):
v_interp = np.interp(xi, xi_range, v_values)
theta, theta_prime = y
return [theta_prime, -0.5 * v_interp * Pr * theta_prime]

# Calculating temperature profiles for different Prandtl numbers


Pr_values = [0.1, 0.7, 1.0, 100]
temp_profiles = {}
theta_prime_values = {}

for Pr in Pr_values:
# Define function to find theta'(0) with root-finding
def temp_bc(guess):
theta_init = [0, guess] # Initial conditions for theta and its derivative
sol_theta = solve_ivp(temperature_ode, [0, xi], theta_init, args=(v[:, iterations], Pr),
t_eval=np.linspace(0, xi, num_points), rtol=1e-6)
return sol_theta.y[0][-1] - 1 # Condition for theta(xi_max) ≈ 1
theta_prime_0 = newton(temp_bc, 1, tol=1e-6)
theta_prime_values[Pr] = theta_prime_0

# Solve the temperature profile with the found theta'(0)


theta_init = [0, theta_prime_0]
sol_theta = solve_ivp(temperature_ode, [0, xi], theta_init, args=(v[:, iterations], Pr),
t_eval=np.linspace(0, xi, num_points), rtol=1e-6)
temp_profiles[Pr] = sol_theta.y[0]

# Plot temperature profiles for each Prandtl number


plt.figure(figsize=(10, 5))
colors = ['blue', 'red', 'purple', 'brown'] # New color choices
for i, (Pr, theta) in enumerate(temp_profiles.items()):
plt.plot(xi_range, theta, label=f'Pr = {Pr}', color=colors[i]) # Apply new colors
plt.title('Temperature Profiles for Various Prandtl Numbers')
plt.xlabel("xi")
plt.ylabel('Theta')
plt.legend()
plt.grid(True)
plt.show()

# Output theta' at xi=0 for each Prandtl number


print("Values of Theta' at xi=0 for different Prandtl numbers:")
for Pr in Pr_values:
print(f"Pr = {Pr}: {theta_prime_values[Pr]:.4f}")

OUTPUT
Values of Theta' at xi=0 for different Prandtl numbers:

Pr = 0.1: 0.1181
Pr = 0.7: 0.2371
Pr = 1.0: 0.2926
Pr = 100: 3.2498
CODING

import numpy as np

# Domain
R=1

# Discretization
drdash = 0.01
N = int(R / drdash) + 1
rdash = np.linspace(0, 1, N)
K = 1001
tolerance = 1e-7

# theta, sci matrices


phi = np.zeros((N, K))
sci = np.zeros((N, K))

# Initial conditions
phi[0, :] = 0.0 # phi at rdash = 0
sci[0, 0] = 5 # initial guess for sci at rdash = 0
sci[0, 1] = 3 # another initial guess

# Start iteration
for k in range(K):
Nu = 2 * sci[0, k]

# Space marching for phi and sci


for i in range(1, N):
phi[i, k] = phi[i - 1, k] + sci[i - 1, k] * drdash
eq2_RHS = (sci[i - 1, k] / (1 - rdash[i - 1])) - (2 * Nu * phi[i - 1, k] * (1 - (1 - rdash[i -
1]) ** 2))
sci[i, k] = sci[i - 1, k] + eq2_RHS * drdash

# Check for convergence


if abs(sci[N - 1, k]) < tolerance:
iter_k = k # Store iteration number for convergence
break

# Better guess for sci(rdash=0) using Secant Method


if k >= 1:
denominator = (sci[N - 1, k] - sci[N - 1, k - 1]) / (sci[0, k] - sci[0, k - 1])
# Ensure denominator is not zero to avoid division by zero errors
if denominator != 0:
sci[0, k + 1] = sci[0, k] - (sci[N - 1, k]) / denominator
else:
sci[0, k + 1] = sci[0, k] # If denominator is zero, retain previous guess

# Ensure sci[0, k + 1] is non-negative


if sci[0, k + 1] < 0:
sci[0, k + 1] = -sci[0, k + 1]

# Output the results for inspection


if 'iter_k' in locals():
nu_final = 2 * sci[0, iter_k] # Calculate final Nu
print(f'Final guess for sci(0): {sci[0, iter_k]}')
print(f'Converged after {iter_k + 1} iterations.')
print(f'Final Nu: {nu_final:.2f}')
else:
print("Did not converge within the maximum iterations.")

OUTPUT

Final guess for sci(0): 1.8451344534269418

Converged after 7 iterations.

Final Nu: 3.69

You might also like