# yade-users team mailing list archive

## Re: [Question #705744]: Divide numerical periodic microstructure box into smaller grided cubes or boxes

```Question #705744 on Yade changed:

Jan Stránský proposed the following answer:
documentations.

I don't think you will find this specific problem as is in the documentation or there is an existing script.
You can however build your script from "building blocks" found in the documentation.
As a start, below is a 2D example.
Please let us know if this is in principle what you are looking for.

Cheers
Jan

###
import random

tileSize = (2, 3)
tiling = (7, 6)

# dummy sample
########################################
colors = {
0.5: (0,1,1),
0.2: (1,0,0),
}
tileParticles = (
((0.0, 0.0), 0.5),
((1.0, 0.4), 0.5),
((0.5, 1.3), 0.5),
((1.5, 1.6), 0.5),
((0.9, 2.4), 0.5),
((0.3, 0.7), 0.2),
((1.7, 0.6), 0.2),
((1.8, 1.0), 0.2),
((1.6, 2.4), 0.2),
((0.1, 2.4), 0.2),
((0.0, 2.0), 0.2),
)
for ix in range(tiling[0]):
x0 = ix * tileSize[0]
for iy in range(tiling[1]):
y0 = iy * tileSize[1]
x = x0 + center[0]
y = y0 + center[1]
########################################

def isInTile(tile,xy):
x, y = xy
sizeX, sizeY = tileSize
x0 = tile[0] * sizeX
y0 = tile[1] * sizeY
x1 = x0 + sizeX
y1 = y0 + sizeY
return x >= x0 and x < x1 and y >= y0 and y < y1

def eliminate():
nTiles = tiling[0] * tiling[1]
tiles = set()
while len(tiles) < 0.5 * nTiles:
x = random.randint(0,tiling[0]-1)
y = random.randint(0,tiling[1]-1)
for b in O.bodies:
if b.shape.radius > 0.4: # do nothing for "large" particles
continue
x,y,z = b.state.pos
if any(isInTile(tile,(x,y)) for tile in tiles): # small particles in selected tiles
O.bodies.erase(b.id)

# see with or without eliminating
#eliminate()