Nov
27
3D (Polar/Cylindrical Coordinate) Animation of 2D Diffusion Equation using Python, Scipy, and Matplotlib
Yup, that same code but in polar coordinate.
I use nabla operator for cylindrical coordinate but ditch the z component.
So, what's the z-axis for? It's represent the u value, in this case, temperature, as function of r and phi (I know I should use rho, but, ...)
import scipy as sp from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as p3 import matplotlib.animation as animation #dr = .1 #dp = .1 #nr = int(1/dr) #np = int(2*sp.pi/dp) nr = 10 np = 10 r = sp.linspace(0.,1.,nr) p = sp.linspace(0.,2*sp.pi,np) dr = r[1]-r[0] dp = p[1]-p[0] a = .5 tmax = 100 t = 0. dr2 = dr**2 dp2 = dp**2 dt = dr2 * dp2 / (2 * a * (dr2 + dp2) ) dt /=10.
I use nabla operator for cylindrical coordinate but ditch the z component.
So, what's the z-axis for? It's represent the u value, in this case, temperature, as function of r and phi (I know I should use rho, but, ...)
import scipy as sp from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as p3 import matplotlib.animation as animation #dr = .1 #dp = .1 #nr = int(1/dr) #np = int(2*sp.pi/dp) nr = 10 np = 10 r = sp.linspace(0.,1.,nr) p = sp.linspace(0.,2*sp.pi,np) dr = r[1]-r[0] dp = p[1]-p[0] a = .5 tmax = 100 t = 0. dr2 = dr**2 dp2 = dp**2 dt = dr2 * dp2 / (2 * a * (dr2 + dp2) ) dt /=10.