# in our 'lattice', all the cells are distance 1 apart NCells = 60 cells = [Cell([x]) for x in np.linspace(1,NCells,NCells)] # add these cells to the simulation sim = Simulation() for i in xrange(NCells): sim.add_cell(cells[i]) im_id = sim.add_internal_model(IM) # set all cells to have the same internal model sim.set_internal_model(range(NCells),im_id) # set boundary conditions before setting intercellular interactions sim.set_boundary_conditions([0],'ref_on') # cells adjacent to one another are connected # for diffusion we include main diagonal # equivalent to 3 wide diagonal diff_connections = (np.eye(NCells,k=-1) + np.eye(NCells,k=0) + np.eye(NCells,k=1)) > 0 # add diffusion to h and u sim.add_interaction('h','h','diffusion',diff_connections,params=[Dh/Th]) sim.add_interaction('u','u','diffusion',diff_connections,params=[Du/Tu]) # spi diffusion sim.add_interaction('sp','sp','diffusion',diff_connections,params=[5.0/Tsp]) ''' # no just lateral connections
# place each cell at these vertices cells = [Cell(c) for c in centers] # add these cells to the simulation sim = Simulation() for i in xrange(NCells): sim.add_cell(cells[i]) im_id = sim.add_internal_model(IM) # set all cells to have the same internal model sim.set_internal_model(range(NCells),im_id) # set up reflecting boundary conditions at bottom edge # sim.set_boundary_conditions(range(ncolumns),'ref_on') sim.set_boundary_conditions(range((nrows-1)*ncolumns,nrows*ncolumns),'abs_on') # need to figure out which cells are connect to which connections = np.zeros((NCells,NCells)) > 0 # default boolean false array tri = Delaunay(centers) for k in xrange(NCells): # if index is found in triangle, add indices of points # in that triangle to connections matches = [t for t in tri.vertices if k in t] matches = reduce(lambda x,y: np.concatenate((x,y)),matches) # need to filter out connections that are two rows away # cells sticking out on the edge get triangulated with cells two rows away matches = [m for m in matches if abs(m-k) < 2*ncolumns] # duplicates don't really matter since we're just setting them all to True connections[k,matches] = True