2

this is my first time in this web, so I hope I'll do it properly.

I'm doing a heat diffusion simulation for a cylinder. Due to the heat source is outside the cylinder, this won't have cylindrical symmetry so I decided to create a X-Y grid and try to approximate it to a cyilinder. Some thing like this:

enter image description here

This is my first and simpliest try:

from numpy import empty,zeros,max
import matplotlib.pyplot as plt

# Constants
M = 10     # Grid squares on a side
V = 100.0         # Voltage at top wall
target = 1e-4   # Target accuracy

# Create arrays to hold potential values
phi = zeros([M+1,M+1],float)
phi[0,:] = V
phi[M,:]=V
phi[:,0]=V
phi[:,M]=V
phiprime = empty([M+1,M+1],float)

# Main loop

delta = 1.0
while delta>target:
  # Calculate new values of the potential
    for i in range(M+1):
      for j in range(M+1):
        if i==0 or i==M or j==0 or j==M:
            phiprime[i,j] = phi[i,j]

        elif i==1 or i==M-1:
            if j==1 or j==2 or j==M-2 or j==M-1:
                phiprime[i,j]=V-V/2
            else:
                phiprime[i,j] = (phi[i+1,j] + phi[i-1,j] \
                             + phi[i,j+1] + phi[i,j-1])/4
        elif i==2 or i==M-2:
            if j==1 or j==M-1:
                phiprime[i,j]=V-V/2
            else:
                phiprime[i,j] = (phi[i+1,j] + phi[i-1,j] \
                             + phi[i,j+1] + phi[i,j-1])/4
        else:
            phiprime[i,j] = (phi[i+1,j] + phi[i-1,j] \
                             + phi[i,j+1] + phi[i,j-1])/4

  delta = max(abs(phi - phiprime))

  phi, phiprime = phiprime, phi

plt.imshow(phiprime)
plt.gray()
plt.show()

This was quite easy, but this isn't a good approximation for a cylinder, I have to make it quite bigger. As you can see, in that attemp, I can code the "positions" by hand, but as I make it 100x100 or 1000x1000, it's impossible.

So, my question is: Is there any good parametritzation for that "indented square"(the black ones)?

Thanks

FJSevilla
  • 3,733
  • 1
  • 13
  • 20
J.Agusti
  • 161
  • 11

1 Answers1

1

I believe what you want to do is: apply a cylindrical mask function to your numpy array. There are a couple of solutions offered over here: How to apply a disc shaped mask to a numpy array?

Community
  • 1
  • 1
Alex G Rice
  • 1,561
  • 11
  • 16