# Boolean question

edited August 2010 in General
Hi Mathias,

I have two layers. Layer one consists of a two dimensional array while layer two is a circle. I want to create a third layer of cells such that the third layer only contains complete cells of layer one within the boundary of layer two circle. How can it be done. Thanks for your help. If it requires a procedure, your help will be appreciated.

Best regards,
Iftikhar

• edited August 2010

Hi Iftikhar,

That seems to be a problem similar to that of a former post of yours.

If I understand that correctly, now you would like to select cell instances rather than shapes. However, the boolean operations do not handle cell instances - that is a different kind of functionality.

One possible solution again is to create a mask layer contained in the fill(?) cells with a boundary polygon (these polygons must not touch nor overlap), do a AND between the circle and the mask layer, run the "select whole shapes" script from the previous post and perform a AND between this result and the content of the fill cells. That would render the desired result in a geometric way but not with respect to hierarchy - the fill cells will be flattened by this approach.

It's probably possible to create a script that modifies the instances of the cells. That will be complicated by the fact that one needs to resolve the array into single instances or - better - into sub-arrays. That's why such a script is probably a little more than just a few lines of code.

Best regards,

Matthias

• edited 9:46PM
Thanks Mathias for your help. You correctly understand my problem. I created a cell consisting of 10 um by 10 um box, calling it box A. Then I created another box structure 9 um by 9 um on a different layer but contained within the first cell, calling it box B. Then I created a 1000 BY 1000 array of cells. Using box B and "select whole shapes", it is possible to create a perfect pattern within a circle on a different layer. However box B is smaller than box A and array of box A must touch each other. This is where the tricky problem of sorting out box A from box B in an array begins. It is not possible to use AND function second time because it ends up creating box B pattern. I may have to use semi-manual method to sort it out. With this relatively large array, I constantly get st9bad.alloc error message and I am forced to close and restart the klayout. I hope you are aware of this problem.

Best regards,
Iftikhar
• edited 9:46PM

Hi Iftikhar,

The bad alloc error is probably indicating that the process exceeds the 2 GB process size limit (I guess you are using a 32 bit executable). That large memory allocation is likely a consequence of the flattening of the fill cells.

You could try using a 64 bit version (provided you have a 64 bit system). But that's rather a hack.

I agree that is not really a solution. The boolean operations are not well suited for that kind of operations. What you probably need is tiling operator for polygons (rendering the inner approximation of a polygon with a set of rectangles) and create the array from that tiling "bitmap". You could feed the fill region's polygons (in that case the circle) into that operation and create the fill cell arrays.

Although such a tiling operator is not rocket science I don't have one in stock for RBA currently. Coding that in Ruby is probably somewhat tedious and slow so I don't consider that a feasible option.

I'll try to dig into the code. Maybe there is something one can reuse from other functionality.

Best regards,

Matthias