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

Import Numpy As NP

The document contains an assignment on Computational Fluid Dynamics by Shravan Bhosale, detailing four different scenarios of 1D steady-state heat conduction using Python. Each scenario includes code for simulating temperature distribution under various boundary conditions and internal heat generation. The results are visualized using plots and contour maps to illustrate temperature variations across the domain.

Uploaded by

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

Import Numpy As NP

The document contains an assignment on Computational Fluid Dynamics by Shravan Bhosale, detailing four different scenarios of 1D steady-state heat conduction using Python. Each scenario includes code for simulating temperature distribution under various boundary conditions and internal heat generation. The results are visualized using plots and contour maps to illustrate temperature variations across the domain.

Uploaded by

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

NAME:SHRAVANI DIPAK BHOSALE

MIS:612210029
DIV:1
SUBJECT: COMPUTATIONAL FLUID AND DYNAMICS

ASSIGNMENT

1) 1D STEADY STATE HEAT CONDUCTION


import numpy as np
import matplotlib.pyplot as plt
#number of grid points
N=101
#domain size
L=1

#grid spacing
h=np.float64(L/(N-1))

#iteration number
interations=0
#initializing temperature number
T=np.zeros(N)
T[N-1]=100.

#initializing iterated temerature


T_new=np.zeros(N)
T_new[N-1]=100.

#error related variable


epsilon=1.E-8
numerical_error=1

#checking error tolerance


while numerical_error>epsilon:
for i in range(1,N-1):
T_new[i]=0.5*(T[i+1]+T[i-1])

numerical_error=0
for i in range (1,N-1):
numerical_error=numerical_error+abs(T[i]-T_new[i])

interations=interations+1
T=T_new.copy()
x_dom=np.arange(N)*h
plt.plot(x_dom,T,'gx--',linewidth=2,markersize=10)
plt.grid(True,color='k')

plt.xlabel("position",size=20)
plt.ylabel("Temperature",size=20)
plt.title("T(x)")

plt.show()
2) 1D STEADY STATE WITH NEUMAN BOUNDARY CONDITION
import numpy as np
import matplotlib.pyplot as plt
#grid points
N=101
#domain size
L=1

#grid spacing
h=np.float64(L/(N-1))
k=0.1;
A=0.001;
q=10;

#iteration number
interations=0

T=np.zeros(N)
T[N-1]=1.

T_new=np.zeros(N)
T_new[N-1]=1.

epsilon=1.E-2
numerical_error=1
while numerical_error>epsilon:
for i in range(0,N-1):
a_E=np.float64(A*k/h)
a_W=np.float64(A*k/h)
if i==(N-1):
a_W=0
T_new[i]=(-q+a_W*T[i-1])/a_P
a_P=a_W+a_E
T_new[i]=(a_E*T[i+1]+a_W*T[i-1])/a_P

numerical_error=0
for i in range (1,N-1):
numerical_error=numerical_error+abs(T[i]-T_new[i])

interations=interations+1
T=T_new.copy()
# Plotting the results
plt.figure()

# Defining the position from indexes


x_dom = np.arange(N) * h

# Plotting the variation with customization


plt.plot(x_dom, T, 'gx--', linewidth=2, markersize=10)

# Displaying the gridlines


plt.grid(True, color='k')

# Labelling and providing a title to the plot


plt.xlabel('Position', size=10)
plt.ylabel('Temperature', size=10)
plt.title('T(x)')
plt.axis([None, None, 0, 1])
3) CONDITION WITH INTERNAL HEAT GENERATION
import numpy as np
import matplotlib.pyplot as plt
N=21
L=1
h=np.float64(L/(N-1))
interations=0
k=0.1;
A=0.001;
q=50;

T=np.zeros((N,N))
T[0,:]=1

T_new=np.zeros((N,N))
T_new[0,:]=1

epsilon=1.E-8
numerical_error=1

plt.figure(10)

while numerical_error>epsilon:
for i in range(1,N-1):
for j in range(1,N-1):
a_E=np.float64(A*k/h)
a_W=np.float64(A*k/h)
a_S=np.float64(A*k/h)
a_N=np.float64(A*k/h)
a_P=a_E+a_W+a_S+a_N
T_new[i,j]=(a_E*T[i,j+1]+a_W*T[i,j-1]+a_N*T[i-1,j]+a_S*T[i+1,j]
+h*q*A)/a_P

numerical_error=0
for i in range (1,N-1):
for j in range (1,N-1):
numerical_error=numerical_error+abs(T[i,j]-T_new[i,j])

iterations=interations+1
T=T_new.copy()

if interations%1000==0:
plt.figure(10)
plt.semilogy(iterations,numerical_error,'ko')

x_dom=np.arange(N)*h
y_dom=L-np.arange(N)*h
[X,Y]=np.meshgrid(x_dom,y_dom)

plt.figure(11)
plt.contourf(X,Y,T,12)

plt.colorbar(orientation='vertical')
plt.title("T(x,y)")

plt.show()
4) DIFFERENT TEMPEATURE AT BOUNDARY
import numpy as np
import matplotlib.pyplot as plt

# Grid parameters
N = 21 # Number of grid points
L = 1 # Length of domain
h = np.float64(L / (N - 1)) # Grid spacing
k = 0.1 # Thermal conductivity
A = 0.001 # Area (assumed constant)

# Boundary temperatures
T_top = 300
T_right = 300
T_left = 0
T_bottom = 0

# Initialize temperature array


T = np.zeros((N, N))

# Apply boundary conditions


T[N-1, :] = T_bottom # Top boundary
T[:, N-1] = T_right # Right boundary
T[0, :] = T_top # Bottom boundary
T[:, 0] = T_left # Left boundary
# Initialize new temperature array
T_new = T.copy()

# Convergence criteria
epsilon = 1.E-8
numerical_error = 1
iterations = 0

plt.figure(10)

# Iteration loop (Gauss-Seidel method)


while numerical_error > epsilon:
numerical_error = 0
for i in range(1, N-1):
for j in range(1, N-1):
a_E = np.float64(A * k / h)
a_W = np.float64(A * k / h)
a_S = np.float64(A * k / h)
a_N = np.float64(A * k / h)
a_P = a_E + a_W + a_S + a_N
T_new[i, j] = (a_E * T[i, j+1] + a_W * T[i, j-1] +
a_N * T[i-1, j] + a_S * T[i+1, j]) / a_P

numerical_error += abs(T[i, j] - T_new[i, j])


iterations += 1
T = T_new.copy()

if iterations % 1000 == 0:
plt.figure(10)
plt.semilogy(iterations, numerical_error, 'ko')

# Generate mesh grid


x_dom = np.arange(N) * h
y_dom = L - np.arange(N) * h
X, Y = np.meshgrid(x_dom, y_dom)

# Plot temperature distribution


plt.figure(11)
plt.contourf(X,Y,T,12)

plt.colorbar(orientation='vertical')

plt.title("T(x,y)")

plt.show()

You might also like