# wrap-around boundaries allow us to make an 'effectively' very long problem by allowing particles to escape # out of one boundary, and enter back in another. This is a common BC when modelling tubes, or such things as rivers # or any flow situation that is too long to realistically model, but is not expected to vary a lot in the flow direction # unfortunately, with the hexagonal grid, collapsed into a cubic lattice, this BC has a lot of careful indexing(!) # left and right boundaries are wrap around # this is the left boundary for i in range(2,leny-1,2): # even lines celln[i,0] = ( cell[i,1]&8 + cell[i-1,0]&16 + cell[i-1,lenx]&32 + cell[i,lenx]&1 + cell[i+1,lenx]&2 + cell[i+1,0]&4 ) if celln[i,0] == 9: celln[i,0] = rot[np.random.randint(1,3)] elif celln[i,0] == 18: celln[i,0] = rot[np.random.randint(2,4)] elif celln[i,0] == 36: celln[i,0] = rot[np.random.randint(0,2)] elif celln[i,0] == 21: celln[i,0] = 42 elif celln[i,0] == 42: celln[i,0] = 21 for i in range(1,leny-1,2): # odd lines celln[i,0] = ( cell[i,1]&8 + cell[i-1,1]&16 + cell[i-1,0]&32 + cell[i,lenx]&1 + cell[i+1,0]&2 + cell[i+1,1]&4 ) if celln[i,0] == 9: celln[i,0] = rot[np.random.randint(1,3)] elif celln[i,0] == 18: celln[i,0] = rot[np.random.randint(2,4)] elif celln[i,0] == 36: celln[i,0] = rot[np.random.randint(0,2)] elif celln[i,0] == 21: celln[i,0] = 42 elif celln[i,0] == 42: celln[i,0] = 21 # now the right wraparound boundary for i in range(2,leny-1,2): # even lines celln[i,lenx] = ( cell[i,0]&8 + cell[i-1,lenx]&16 + cell[i-1,lenx-1]&32 + cell[i,lenx-1]&1 + cell[i+1,lenx-1]&2 + cell[i+1,lenx]&4 ) if celln[i,lenx] == 9: celln[i,lenx] = rot[np.random.randint(1,3)] elif celln[i,lenx] == 18: celln[i,lenx] = rot[np.random.randint(2,4)] elif celln[i,lenx] == 36: celln[i,lenx] = rot[np.random.randint(0,2)] elif celln[i,lenx] == 21: celln[i,lenx] = 42 elif celln[i,lenx] == 42: celln[i,lenx] = 21 for i in range(1,leny-1,2): # odd lines celln[i,lenx] = ( cell[i,0]&8 + cell[i-1,0]&16 + cell[i-1,lenx]&32 + cell[i,lenx-1]&1 + cell[i+1,lenx]&2 + cell[i+1,0]&4 ) if celln[i,lenx] == 9: celln[i,lenx] = rot[np.random.randint(1,3)] elif celln[i,lenx] == 18: celln[i,lenx] = rot[np.random.randint(2,4)] elif celln[i,lenx] == 36: celln[i,lenx] = rot[np.random.randint(0,2)] elif celln[i,lenx] == 21: celln[i,lenx] = 42 elif celln[i,lenx] == 42: celln[i,lenx] = 21