Ok, So i'm attempting to simulate diffusion through a 2-D plate of multiple concentrations of compounds and my program so far looks something like follows
from scipy import * from pylab import * #============================================================================== #simulation conditions #============================================================================== nx = 64 # The number of x nodes ny = 64 # The number of y nodes h = 0.01 #spacing between nodes Du = 2*10**-5 # Diffusion coefficient of U Dv = 10**-5 # Diffusion coefficient of V delta_t = 0.9*h**2/(4*Du) # time step def lap_2d(f, h): '''Return the laplacian of a 2-D array f with node spacing h.''' return (roll(f, -1, axis=0) + roll(f, 1, axis=0) - 4*f + roll(f, -1, axis=1) + roll(f, 1, axis=1))/(h**2) def dstatedt(F, k, U, V): return ((Du*f(U, h)) - U*V**2 + F*(1-U) & ((Dv*f(V, h)) + U*V**2 - (k + F)*V) #============================================================================== # Initial conditions #============================================================================== U = zeros((nx, ny), dtype = float) # a 2-D array V = zeros((nx, ny), dtype = float) # a 2-d array U[(x > 12*nx/16) & (x < 6*nx/16)] = 1.0 +0.01* stats.uniform.rvs() # original U concentration V[ (y > 12*ny/16) & (y < 6*ny/16)] = 0.0 + 0.01*stats.uniform.rvs() # original V concentration U[(x > 6*nx/16 ) & (x < 12*nx/16)] = 0.5 + 0.01*stats.uniform.rvs() # initial U concentration added V[(y > 6*ny/16 ) & (y < 12*ny/16)] = 0.25 + 0.01*stats.uniform.rvs() #initial V concentration added
If you notice I am running into several issues. With my function dstatedt I want it to return two different numbers in some sort of an array, because where as both are based on concentrations of U and V, they are changing at different rates. However, I want them written as one function.
also, the last lines of code talk about the initial and original concentrations. As you can see I want to added random noise type data to the arrays, but only for certain parts of the arrays. My teachers gave me hints to use the stats.uniform.rvs() function, but i don't know how to manipulate the loc, scale, and size arguments so that i can get +- 0.01 random noise.
If anyone has any sort of clues as to how to fix my issues, that would be great.