Replies: 1 comment 2 replies
-
We haven't added a "plug-and-play" function, like we did with the linewidth/linespacing constraints (yet). But hopefully we can add a tutorial sometime soon. In the meantime, it's rather straightforward to implement yourself. I just used the from skimage import measure
from scipy import ndimage
''' create a function that 'builds' the appropriate constraint function
and corresponding gradient (differentiable using autograd)'''
def area_constraint(x,min_area):
# x ........... design variables after mapping
# min_area .... minimum area constraint (meep units)
dA = 1/resolution * 1/resolution # differential area
N = x.size # total number of elements
# pad to take care of boundary conditions
pd = int(resolution*min_area*4)
y_p = np.pad(x,(pd,pd),mode='edge')
y_p = np.pad(y_p,(10,10),mode='constant',constant_values=0)
# pull the contours
temp = np.array(y_p)
contours = measure.find_contours(temp, 0.5)
# build the indicator function
I = np.zeros(x.shape)
for c in contours: # loop through contours
r_mask = np.zeros_like(y_p, dtype='bool')
r_mask[np.round(c[:, 0]).astype('int'), np.round(c[:, 1]).astype('int')] = 1
r_mask = ndimage.binary_fill_holes(r_mask)
area = np.sum(y_p[r_mask].flatten())*dA
# only worry about a contour if it is smaller than the threshold and sufficiently gray
if (np.mean(y_p[r_mask].flatten()) > 0.6) and (area < min_area):
I[mpa.centered(r_mask,x.shape)] = 1
Ja = lambda x_a: npa.dot(x_a.flatten(),I.flatten())/N
a = Ja(x)
g = grad(Ja)(x)
return a, g I haven't ran this... so you might need to tweak some things. But it gives you the basic idea. (Feel free to submit a PR with a new tutorial if this ends of working for you). |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone!
Currently, I am trying to optimize a structure using the adjoint solver. To make sure that the resulting structure is also manufacturable, I want to implement a constraint on the linewidth and area of the solid and void regions. The constraint on the linewidth is already accomplished as shown in the examples. However, I don't seem to be able to find a function for the area constraint. The constraint that I am talking about is described in the following article:
A. M. Hammond, A. Oskooi, S. G. Johnson, and S. E. Ralph, “Photonic topology optimization with semiconductorfoundry
design-rule constraints,” Opt. Express 29(15), 23916–23938 (2021).
Does anyone know where I can find the function that I am looking for?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions