Modelling Finite Difference for Temperature Distribution on a house-shaped domain

329 views Asked by At

Currently I am doing a research to re-model a temperature distribution (dirichlet) in several house-shaped domains (firstly I'll model the steady state and will continue to the unsteady state with time variable).

There are three different roof geometries to make, here's the picture of the domains to make it easier to interpret: https://www.dropbox.com/sh/92lmwv67k8chzi1/AABmozTBmQqeTz_fGigBsvsaa?dl=0

The boundary conditions were that the temperature at (the bottom of) the roof was 30 C and the temperature at (the inside of) the wall was 25 C and the temperature at the (top of the) ground was 25 C. All are the conditions for steady state model.

So far, I'm done with the rectangular domain in Math approach using handwritten matrix and construct the matrix in a kind of brute-force Python-numpy-matplotlib code. Here's the code:

import numpy as np
import matplotlib.pyplot as plt


floor=25
rightwall=25
leftwall=25
ceiling=30 
width=19
height=20
numofnodes=width*height
#all the variables above depend on user input

K=[]
K = [[0 for i in range(numofnodes)]for j in range(numofnodes)]

for i in range (numofnodes):
    for j in range (numofnodes):
        if(i==j):
            K[i][j]=-4
for i in range(numofnodes-1):
    K[i][i+1]=1
for i in range(1,numofnodes):
    K[i][i-1]=1
for i in range(numofnodes-width):
    K[i][i+width]=1
for i in range(width, numofnodes):
    K[i][i-width]=1
for i in range(1,height):
    K[width*i][(width*i)-1]=0
for i in range(height):
    K[(width*i)-1][(width*i)]=0 

D1=np.zeros([numofnodes,1])
for i in range(width):
    D1[i]=leftwall

D2=np.zeros([numofnodes,1])
for i in range(height):
    D2[(i*width)]=floor

D3=np.zeros([numofnodes,1])
for i in range(1,height+1):
    D3[(i*width)-1]=ceiling

D4=np.zeros([numofnodes,1])
for i in range(numofnodes-width, numofnodes):
    D4[i]=rightwall
D=np.zeros([numofnodes,1])
Dnew=np.negative(D1+D2+D3+D4)

Kinv=np.linalg.inv(K)
T=np.dot(Kinv,Dnew)

Tnew=np.reshape(T,(height,width))
Tmatrix=np.transpose(Tnew)

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(1,1,1)
ax.set_title('temp distribution')
plt.imshow(Tmatrix,origin='lower', interpolation='bilinear')
ax.set_aspect('auto')
plt.clim(25,30)
plt.colorbar(orientation='vertical')
plt.grid()
plt.show()

My apology for the brutality of the code, the code was intended to be made as pure-algorithmic as possible. Now, I'm having hard time to construct the "Roof" shape even for the simplest one (the rightmost in the domains picture).

These are the pictures of my goals (copied from the MATLAB-based-literature) : https://www.dropbox.com/s/lxan6i5q0hr3ax3/goals.PNG?dl=0

Can anybody tell me how to implement the steady state finite difference on the roof side (arbitrary or irregular domain) and join it with the rectangular domain code like the goalpicture above? Or maybe tell me some helping literature or examples with case to read?

Apology for the question if the question is violating the terms of Stackoverflow, this is my first time here and thank you for your help.

0

There are 0 answers