Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def experiment():
    # Domain size
    L = 1.0
    # Number of compartments in x direction
    num_comps = 20
    # Diffusion constant
    D = 1.0
    # Assumed average number of particles to the left of domain (fixed
    # concentration boundary conditions
    A0 = 10
    
    # Time step
    mol_dt = 0.000001
    
    # Create species
    A = tyche.new_species(D)
    
    # Create domain bounds
    xlow = tyche.new_xplane(1e-5,1)
    xghost = tyche.new_xplane(L/2.,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)
    # Create interface box
    interface = tyche.new_box([0,0,0],[L/2.,L,L],True)

    # Boundary conditions on the domain bounds and the interface
    # Need a reflective boundary at the ghost cell interface
    xghostboundary = tyche.new_reflective_boundary(xghost)
    xminboundary = tyche.new_reflective_boundary(xlow)
    xmaxboundary = tyche.new_reflective_boundary(xhigh)
    yminboundary = tyche.new_reflective_boundary(ylow)
    ymaxboundary = tyche.new_reflective_boundary(yhigh)
    zminboundary = tyche.new_reflective_boundary(zlow)
    zmaxboundary = tyche.new_reflective_boundary(zhigh)

    # Add all boundaries to a single operator
    boundaries = tyche.group([xghostboundary,xmaxboundary,yminboundary, ymaxboundary, zminboundary, zmaxboundary])
    boundaries.add_species(A)
    
    # Create compartments throughout the domain
    compartments = tyche.new_compartments([0,0,0],[L,L,L],[L*1./num_comps,L,L])
    compartments.add_diffusion(A);

    # Boundary reaction on leftmost boundary (particle creation)
    compartments.add_reaction_on(A0/(L/num_comps)**3, [[],[A]], xlow)
    compartments.add_reaction_on(1./(L/num_comps)**2, [[A],[]], xlow)

    # Removal reaction
    compartments.add_reaction(1., [[A],[]])
    
    # Introduce ghost cell interface at L/2
    compartments.set_ghost_cell_interface(interface)

    # Diffusion operator with tracking (tracks number of particles in ghost
    # compartment at the interface
    bd = tyche.new_diffusion_with_tracking(interface,compartments)
    bd.add_species(A)

    # Removal reaction in molecular domain
    remove = tyche.new_uni_reaction(1., [[A],[]])

    # Create algorithm
    algorithm = tyche.group([bd,boundaries,compartments, remove])
    
    # Get data every Dt
    output_dt = 1e-2
    
    # Set up plotting
    ion()
    figure()
    ax = subplot(211)
    ax2 = subplot(212)

    # List to hold number of particles in compartments
    nums = []
    # Run until steady state is reached
    time = algorithm.integrate_for_time(5.,mol_dt)
    while True:
        # Collect data
        for i in range(10):
            # Run for Dt
            time = algorithm.integrate_for_time(output_dt,mol_dt)
            # Put molecules in bins similar to compartment spacing
            h,b = histogram(A.get_particles()[0], range=(0,L), bins=num_comps)
            # Get compartment data
            c = A.get_compartments()[:,0,0]
            # Fix ghost compartment so that we do not count it twice
            c[num_comps/2] = 0
            # Add compartments to molecule histogram
            h += c
            nums.append(h)

        #P Plotting
        ax.clear()
        ax2.clear()
        x = (arange(0,num_comps)+0.5)*L*1./num_comps

        # Plot mean number of particles
        ax.plot(x,mean(nums,axis=0))
        # Solution for steady state of reaction-diffusion PDE (has an error
        # whereby the first compartment should be shifted by h/2)
        ax.plot((1-x), A0*1./cosh(1.)*cosh(x))

        # Plot standard deviation
        ax2.plot(x,std(nums,axis=0))

        ax.set_xlabel("x")
        ax.set_ylabel("Mean Frequency")
        ax2.set_xlabel("x")
        ax2.set_ylabel("Standard deviation")
        draw()        
A = tyche.new_species([D,0,0])
dummy = tyche.new_species([0,0,0])
not_dummy = tyche.new_species([0,0,0])

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)) * (
Exemplo n.º 5
0
steps = 200
mol_dt = timeStepDuration/100.

A = tyche.new_species([D,0,0])
A.fill_uniform([0,0,0],[L,0,0],1000)
grid = tyche.new_structured_grid([0,0,0],[L,1,1],[dx,1,1])
print grid
A.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)

#set off-lattice sink and source
sink = tyche.new_uni_reaction(conversion_rate,[[A],[A.pde()]])
pde_region = tyche.new_xplane(interface,1)
sink.set_geometry(0,pde_region)
source = tyche.new_zero_reaction_lattice(conversion_rate,[[A.pde()],[A]])
offlattice_region = tyche.new_xplane(interface,1)
source.set_geometry(offlattice_region)

diffusion = tyche.new_diffusion()
algorithm = tyche.group([diffusion,sink,source,xminboundary, xmaxboundary])

algorithm.add_species(A)

mesh = Grid1D(nx=nx, dx=dx)
phi = CellVariable(name="solution variable",  mesh=mesh, value=1000.)

# setup plotting
Exemplo n.º 6
0
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