def experiment_ab(num_particles): L = 0.5 #L = 50e-9 D = 1 #D = 1e-10 timesteps = 100000 #timesteps = 10000 max_t = 4.0/(2.0*num_particles**0.5); mol_dt = max_t/timesteps #mol_dt = 0.025*1e-8 #max_t = mol_dt * timesteps k2 = num_particles #k2 = 6.67e6 k1 = 1.0 #k1 = (k2*L**3)/num_particles binding = 0.00303416 #binding = 3.76432e-10 unbinding = 0.15*0.00303416 #unbinding = 0.01*3.76432e-10 A = tyche.new_species(D) B = tyche.new_species(D) C = tyche.new_species(D) bd = tyche.new_diffusion() bd.add_species(A) bd.add_species(B) bd.add_species(C) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) ylow = tyche.new_yplane(0,1) yhigh = tyche.new_yplane(L,-1) zlow = tyche.new_zplane(0,1) zhigh = tyche.new_zplane(L,-1) xminboundary = tyche.new_jump_boundary(xlow,[L,0,0]) xmaxboundary = tyche.new_jump_boundary(xhigh,[-L,0,0]) yminboundary = tyche.new_jump_boundary(ylow,[0,L,0]) ymaxboundary = tyche.new_jump_boundary(yhigh,[0,-L,0]) zminboundary = tyche.new_jump_boundary(zlow,[0,0,L]) zmaxboundary = tyche.new_jump_boundary(zhigh,[0,0,-L]) boundaries = tyche.group([xminboundary, xmaxboundary, yminboundary, ymaxboundary, zminboundary, zmaxboundary]) boundaries.add_species(A) boundaries.add_species(B) boundaries.add_species(C) dr2 = tyche.new_bi_reaction(k1, A, B, [C], binding,unbinding, mol_dt, [0,0,0], [L,L,L], [True, True, True],True) dr3 = tyche.new_bi_reaction(k1, A, B, [C], mol_dt, [0,0,0], [L,L,L], [True, True, True],True) dr = tyche.new_uni_reaction(k2,C,[A,B],unbinding) algorithm = tyche.group([bd,boundaries,dr2,dr,boundaries]) A.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) B.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) C.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) output_dt = max_t/100.0 time = 0; print algorithm for i in range(100): print A,B,C print 'time = ',time,' ',i,' percent done' time = algorithm.integrate_for_time(output_dt,mol_dt) # grid = tvtk.to_tvtk(A.get_vtk()) # g = init_vis(grid) print algorithm
def experiment(num_particles): L = 0.25 D = 1 timesteps = 100000; max_t = 4.0/(2.0*num_particles**0.5); mol_dt = max_t/timesteps; k2 = num_particles k1 = 0.01 print 'hcrit = ',k1/(2.0*D) binding = 0.01 unbinding = 0.01 A = tyche.new_species(D) bd = tyche.new_diffusion() bd.add_species(A) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) ylow = tyche.new_yplane(0,1) yhigh = tyche.new_yplane(L,-1) zlow = tyche.new_zplane(0,1) zhigh = tyche.new_zplane(L,-1) xminboundary = tyche.new_jump_boundary(xlow,[L,0,0]) xmaxboundary = tyche.new_jump_boundary(xhigh,[-L,0,0]) yminboundary = tyche.new_jump_boundary(ylow,[0,L,0]) ymaxboundary = tyche.new_jump_boundary(yhigh,[0,-L,0]) zminboundary = tyche.new_jump_boundary(zlow,[0,0,L]) zmaxboundary = tyche.new_jump_boundary(zhigh,[0,0,-L]) boundaries = tyche.group([xminboundary, xmaxboundary, yminboundary, ymaxboundary, zminboundary, zmaxboundary]) boundaries.add_species(A) dr2 = tyche.new_bi_reaction(k1, A, A, [A], binding,unbinding, mol_dt, [0,0,0], [L,L,L], [True, True, True],True) dr3 = tyche.new_bi_reaction(k1, A, A, [A], mol_dt, [0,0,0], [L,L,L], [True, True, True],True) dr = tyche.new_uni_reaction(k2,A,[A,A],unbinding) algorithm = tyche.group([bd,boundaries,dr2,dr,boundaries]) A.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3/k1)) output_dt = max_t/100.0 time = 0; print algorithm for i in range(100): print A print 'time = ',time,' ',i,' percent done' time = algorithm.integrate_for_time(output_dt,mol_dt) # grid = tvtk.to_tvtk(A.get_vtk()) # g = init_vis(grid) print algorithm
def experiment(num_particles): L = 1 #L = 50e-9 D = 1 #D = 1e-10 timesteps = 100000 #timesteps = 10000 max_t = 4.0/(2.0*num_particles**0.5); mol_dt = max_t/timesteps #mol_dt = 0.025*1e-8 #max_t = mol_dt * timesteps A = tyche.new_species(D) B = tyche.new_species(D) C = tyche.new_species(D) bd = tyche.new_diffusion() bd.add_species(A) bd.add_species(B) bd.add_species(C) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) ylow = tyche.new_yplane(0,1) yhigh = tyche.new_yplane(L,-1) zlow = tyche.new_zplane(0,1) zhigh = tyche.new_zplane(L,-1) xminboundary = tyche.new_jump_boundary(xlow,[L,0,0]) xmaxboundary = tyche.new_jump_boundary(xhigh,[-L,0,0]) yminboundary = tyche.new_jump_boundary(ylow,[0,L,0]) ymaxboundary = tyche.new_jump_boundary(yhigh,[0,-L,0]) zminboundary = tyche.new_jump_boundary(zlow,[0,0,L]) zmaxboundary = tyche.new_jump_boundary(zhigh,[0,0,-L]) boundaries = tyche.group([xminboundary, xmaxboundary, yminboundary, ymaxboundary, zminboundary, zmaxboundary]) boundaries.add_species(A) boundaries.add_species(B) boundaries.add_species(C) algorithm = tyche.group([bd,boundaries]) A.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) B.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) C.fill_uniform([0,0,0],[L,L,L],int(num_particles*L**3)) output_dt = max_t/100.0 time = 0; print algorithm for i in range(100): print A,B,C print 'time = ',time,' ',i,' percent done' time = algorithm.integrate_for_time(output_dt,mol_dt) grid = tvtk.to_tvtk(A.get_vtk()) g = init_vis(grid) print algorithm
grid = tyche.new_structured_grid([0,0,0],[L,1,1],[dx,1,1]) A.set_grid(grid) dummy.set_grid(grid) not_dummy.set_grid(grid) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) xminboundary = tyche.new_reflective_boundary(xlow) xmaxboundary = tyche.new_reflective_boundary(xhigh) sink = tyche.new_uni_reaction(conversion_rate,[[A,dummy.pde()],[A.pde()]]) source = tyche.new_zero_reaction_lattice(conversion_rate,[[A.pde(),not_dummy.pde()],[A]]) uni = tyche.new_uni_reaction(k,[[A],[]]) flux = tyche.new_zero_reaction(lam/dx,[0,0,0],[dx,1,1]) diffusion = tyche.new_diffusion() algorithm = tyche.group([diffusion,xminboundary,flux,uni,sink,source]) algorithm.add_species(A) ############ # Plotting # ############ def concentration_gradient(x,t): exact = (lam/(D*beta)) * ( np.exp(-beta*(x)) - 0.5*np.exp(-beta*(x))*erfc((2.0*beta*D*t-(x))/np.sqrt(4.0*D*t)) - 0.5*np.exp(beta*(x))*erfc((2.0*beta*D*t+(x))/np.sqrt(4.0*D*t)) ) return exact
def experiment(num_particles,timesteps): L = 1 D = 1 k2 = 1000.0 k1 = k2/num_particles**3 max_t = 1.0 DAB = D+D; DABC = D + D*D/DAB; Rsq = ( k1 / (4*3.14**3*(DAB*DABC)**(3.0/2.0) ) )**0.5; mol_dt = Rsq/10000; A = tyche.new_species(D) B = tyche.new_species(D) C = tyche.new_species(D) bd = tyche.new_diffusion() bd.add_species(A) bd.add_species(B) bd.add_species(C) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) ylow = tyche.new_yplane(0,1) yhigh = tyche.new_yplane(L,-1) zlow = tyche.new_zplane(0,1) zhigh = tyche.new_zplane(L,-1) xminboundary = tyche.new_jump_boundary(xlow,[L,0,0]) xmaxboundary = tyche.new_jump_boundary(xhigh,[-L,0,0]) yminboundary = tyche.new_jump_boundary(ylow,[0,L,0]) ymaxboundary = tyche.new_jump_boundary(yhigh,[0,-L,0]) zminboundary = tyche.new_jump_boundary(zlow,[0,0,L]) zmaxboundary = tyche.new_jump_boundary(zhigh,[0,0,-L]) boundaries = tyche.group([xminboundary, xmaxboundary, yminboundary, ymaxboundary, zminboundary, zmaxboundary]) boundaries.add_species(A) boundaries.add_species(B) boundaries.add_species(C) dr3 = tyche.new_tri_reaction(k1, A, B, C, [B,C], mol_dt, [0,0,0], [L,L,L], [True, True, True]) dr = tyche.new_zero_reaction(k2,[0,0,0],[L,L,L]) dr.add_species(A) algorithm = tyche.group([bd,boundaries,dr,dr3]) A.fill_uniform([0,0,0],[L,L,L],int(num_particles)) B.fill_uniform([0,0,0],[L,L,L],int(num_particles)) C.fill_uniform([0,0,0],[L,L,L],int(num_particles)) N = 1000 output_dt = max_t/N time = 0; print algorithm grid = tvtk.to_tvtk(A.get_vtk()) numA = np.zeros(N) for i in range(N): print A,B,C numA[i] = A.get_concentration([0,0,0],[L,L,L],[1,1,1])[0] print 'time = ',time,' ',i*100.0/N,' percent done' time = algorithm.integrate_for_time(output_dt,mol_dt) # grid = tvtk.to_tvtk(A.get_vtk()) # g = init_vis(grid) print algorithm return numA
def experiment(): L = 1.0 D = 1.0 num_particles = 10000.0 max_t = 10.0; factor = 2.0; mol_dt = 0.001 A = tyche.new_species(D) bd = tyche.new_diffusion() bd.add_species(A) xlow = tyche.new_xplane(0,1) xhigh = tyche.new_xplane(L,-1) ylow = tyche.new_yplane(0,1) yhigh = tyche.new_yplane(L,-1) zlow = tyche.new_zplane(0,1) zhigh = tyche.new_zplane(L,-1) interface = tyche.new_box([0,0,0],[L/2.0,L,L],True) xminboundary = tyche.new_reflective_boundary(xlow) yminboundary = tyche.new_reflective_boundary(ylow) ymaxboundary = tyche.new_reflective_boundary(yhigh) zminboundary = tyche.new_reflective_boundary(zlow) zmaxboundary = tyche.new_reflective_boundary(zhigh) boundaries = tyche.group([xminboundary, yminboundary, ymaxboundary, zminboundary, zmaxboundary]) boundaries.add_species(A) dr = tyche.new_uni_reaction(1.0,[[A],[]]) compartments = tyche.new_compartments([0,0,0],[L,L,L],[L/20.0,L,L]) compartments.add_diffusion(A); compartments.add_reaction(1.0,[[A],[]]) compartments.add_reaction_on(num_particles*20.0/L,[[],[A]],xlow) corrected_interface = True compartments.set_interface(interface, mol_dt, corrected_interface) coupling = tyche.new_coupling_boundary(interface,compartments,corrected_interface) coupling.add_species(A) algorithm = tyche.group([bd,compartments,dr,boundaries,coupling]) output_dt = max_t/100.0 time = 0; print algorithm # plt.figure() # plt.ion() # concentration = A.get_concentration([0,0,0],[2.0*L,L,L],[40,1,1]) # x = np.arange(0,2.0*L,L/20.0) # l, = plt.plot(x,concentration[:,0,0]) # plt.ylim([0,num_particles]) for i in range(100): print A print 'time = ',time,' ',i,' percent done' time = algorithm.integrate_for_time(output_dt,mol_dt) # concentration = A.get_concentration([0,0,0],[2.0*L,L,L],[40,1,1]) # l.set_ydata(concentration[:,0,0]) # plt.draw() # x,y,z = A.get_particles() # mlab.points3d(np.array(x),np.array(y),np.array(z),scale_factor = 0.05,color=(1,1,1)) # [0,0,0],[L,L,L],[L/20.0,L,L] # x, y, z = np.mgrid[0:L:L/20.0, 0:L:L, 0:L:L] # comps = A.get_compartments() # values = tools.pipeline.scalar_field(x,y,z,comps) # mlab.pipeline.volume(values) print algorithm