tidy3d.PolySlab#
- class PolySlab[source]#
Bases:
PlanarPolygon extruded with optional sidewall angle along axis direction.
- Parameters:
axis (Literal[0, 1, 2] = 2) – Specifies dimension of the planar axis (0,1,2) -> (x,y,z).
sidewall_angle (Union[float, autograd.tracer.Box] = 0.0) – [units = rad]. Angle of the sidewall.
sidewall_angle=0(default) specifies a vertical wall;0<sidewall_angle<np.pi/2specifies a shrinking cross section along theaxisdirection; and-np.pi/2<sidewall_angle<0specifies an expanding cross section along theaxisdirection.reference_plane (Literal['bottom', 'middle', 'top'] = middle) – The position of the plane where the supplied cross section are defined. The plane is perpendicular to the
axis. The plane is located at thebottom,middle, ortopof the geometry with respect to the axis. E.g. ifaxis=1,bottomrefers to the negative side of the y-axis, andtoprefers to the positive side of the y-axis.slab_bounds (tuple[Union[float, autograd.tracer.Box], Union[float, autograd.tracer.Box]]) – [units = um]. Minimum and maximum positions of the slab along axis dimension.
dilation (float = 0.0) – [units = um]. Dilation of the supplied polygon by shifting each edge along its normal outwards direction by a distance; a negative value corresponds to erosion.
vertices (Union[ArrayLike[dtype=float, ndim=2], autograd.tracer.Box]) – [units = um]. List of (d1, d2) defining the 2 dimensional positions of the polygon face vertices at the
reference_plane. The index of dimension should be in the ascending order: e.g. if the slab normal axis isaxis=y, the coordinate of the vertices will be in (x, z)bulges (Optional[ArrayLike[dtype=float, ndim=1]] = None) – List of values describing the bulge of each edge, following the typical convention:
bulge = tan(θ/4)where θ is the included angle of the arc. Whenbulges=None, all segments are straight lines; otherwise, the number of bulge values must equal the number of vertices.bulges[i]defines the arc on the edge from vertexito vertex(i+1) mod N. Sign convention:bulge=0means straight line;bulge>0bulges outward (for CCW polygons);bulge<0bulges inward. All values must be finite. Canonicalization: bulges are kept synchronized with vertices during internal canonicalization. When winding order is reversed to CCW (i.e., when the input polygon is CW), bulges are permuted to match the reversed edges and their signs are flipped. When duplicate adjacent vertices are removed, the corresponding zero-bulge entry is dropped; a zero-length edge with non-zero bulge raisesSetupError.parameter (Polygon edges may optionally be circular arcs via the bulges)
which
convention (follows the)
polygon (included angle of the arc. For CCW)
outward (a positive bulge produces an arc that bulges)
edge. (; a negative bulge bulges inward; and zero means a straight)
Example
>>> vertices = np.array([(0,0), (1,0), (1,1)]) >>> p = PolySlab(vertices=vertices, axis=2, slab_bounds=(-1, 1)) >>> # With arc segments (a rounded edge from vertex 1 to vertex 2): >>> p_arc = PolySlab( ... vertices=vertices, axis=2, slab_bounds=(-1, 1), bulges=[0, 0.5, 0] ... )
Attributes
The polygon at the base, derived from the
middle_polygon.Returns bounding box min and max coordinates.
Gets the position of the center of the geometry in the out of plane dimension.
Gets the length of the PolySlab along the out of plane dimension.
Angle formed inside polygon by two adjacent edges.
Is this
PolySlabCCW-oriented?Gets the length of the geometry along the out of plane dimension.
The polygon at the middle.
The polygon at the reference plane.
The polygon at the top, derived from the
middle_polygon.axissidewall_anglereference_planeMethods
array_to_vertices(arr_vertices)Converts a numpy array of vertices to a list of tuples.
Handle degenerate line cross-section case
2d surface integral on a Gauss quadrature grid
correct_shape(val)Makes sure vertices size is correct.
edge_basis_vectors(edges)Normalized basis vectors for
normaldirection,slabtangent direction andedge.from_gds(gds_cell, axis, slab_bounds, gds_layer)Import
PolySlabfrom agdstk.Cell.inside(x, y, z)For input arrays
x,y,zof arbitrary but identical shape, return an array with the same shape which isTruefor every point in zip(x, y, z) that is inside the volume of theGeometry, andFalseotherwise.make_shapely_polygon(vertices)Make a shapely polygon from some vertices, first ensures they are untraced.
At the reference plane, check if the polygon is self-intersecting.
In this simple polyslab, we don't support self-intersecting polygons yet, meaning that any normal cross section of the PolySlab cannot be self-intersecting.
normalize_vect(arr)normalize an array shaped (N, d) along the d axis and return (N, 1).
pop_axis_vect(coord)Combine coordinate along axis with coordinates on the plane tangent to the axis.
reflected(normal)Return a reflected copy of this geometry.
rotated(angle, axis)Return a rotated copy of this geometry.
scaled([x, y, z])Return a scaled copy of this geometry.
slab_bounds_order(val)Maximum position of the slab should be no smaller than its minimal position.
translated(x, y, z)Return a translated copy of this geometry.
unpop_axis_vect(ax_coords, plane_coords)Combine coordinate along axis with coordinates on the plane tangent to the axis.
vertices_to_array(vertices_tuple)Converts a list of tuples (vertices) to a numpy array.
- slab_bounds#
- dilation#
- vertices#
- bulges#
- static make_shapely_polygon(vertices)[source]#
Make a shapely polygon from some vertices, first ensures they are untraced.
- classmethod slab_bounds_order(val)[source]#
Maximum position of the slab should be no smaller than its minimal position.
- classmethod correct_shape(val)[source]#
Makes sure vertices size is correct. Make sure no intersecting edges.
- no_complex_self_intersecting_polygon_at_reference_plane()[source]#
At the reference plane, check if the polygon is self-intersecting.
There are two types of self-intersection that can occur during dilation: 1) the one that creates holes/islands, or splits polygons, or removes everything; 2) the one that does not.
For 1), we issue an error since it is yet to be supported; For 2), we heal the polygon, and warn that the polygon has been cleaned up.
- no_self_intersecting_polygon_during_extrusion()[source]#
In this simple polyslab, we don’t support self-intersecting polygons yet, meaning that any normal cross section of the PolySlab cannot be self-intersecting. This part checks if any self-interction will occur during extrusion with non-zero sidewall angle.
There are two types of self-intersection, known as edge events, that can occur during dilation: 1) neighboring vertex-vertex crossing. This type of edge event can be treated with
ComplexPolySlabwhich divides the polyslab into a list of simple polyslabs.2) other types of edge events that can create holes/islands or split polygons. To detect this, we sample _N_SAMPLE_POLYGON_INTERSECT cross sections to see if any creation of polygons/holes, and changes in vertices number.
- classmethod from_gds(gds_cell, axis, slab_bounds, gds_layer, gds_dtype=None, gds_scale=1.0, dilation=0.0, sidewall_angle=0, reference_plane='middle')[source]#
Import
PolySlabfrom agdstk.Cell.- Parameters:
gds_cell (gdstk.Cell) –
gdstk.Cellcontaining 2D geometric data.axis (int) – Integer index into the polygon’s slab axis. (0,1,2) -> (x,y,z).
slab_bounds (tuple[float, float]) – Minimum and maximum positions of the slab along
axis.gds_layer (int) – Layer index in the
gds_cell.gds_dtype (int = None) – Data-type index in the
gds_cell. IfNone, imports all data for this layer into the returned list.gds_scale (float = 1.0) – Length scale used in GDS file in units of MICROMETER. For example, if gds file uses nanometers, set
gds_scale=1e-3. Must be positive.dilation (float = 0.0) – Dilation of the polygon in the base by shifting each edge along its normal outwards direction by a distance; a negative value corresponds to erosion.
sidewall_angle (float = 0) – Angle of the sidewall.
sidewall_angle=0(default) specifies vertical wall, while0<sidewall_angle<np.pi/2for the base to be larger than the top.reference_plane (PlanePosition = "middle") – The position of the GDS layer. It can be at the
bottom,middle, ortopof the PolySlab. E.g. ifaxis=1,bottomrefers to the negative side of y-axis, andtoprefers to the positive side of y-axis.
- Returns:
List of
PolySlabobjects sharingaxisand slab bound properties.- Return type:
list[
PolySlab]
- property center_axis#
Gets the position of the center of the geometry in the out of plane dimension.
- property length_axis#
Gets the length of the geometry along the out of plane dimension.
- property finite_length_axis#
Gets the length of the PolySlab along the out of plane dimension. First clips the slab bounds to LARGE_NUMBER and then returns difference.
- property reference_polygon#
The polygon at the reference plane.
- property middle_polygon#
The polygon at the middle.
- property base_polygon#
The polygon at the base, derived from the
middle_polygon.
- property top_polygon#
The polygon at the top, derived from the
middle_polygon.
- property is_ccw#
Is this
PolySlabCCW-oriented?
- inside(x, y, z)[source]#
For input arrays
x,y,zof arbitrary but identical shape, return an array with the same shape which isTruefor every point in zip(x, y, z) that is inside the volume of theGeometry, andFalseotherwise.Note
For slanted sidewalls, this function only works if x, y, and z are arrays produced by a
meshgrid call, i.e. 3D arrays and each is constant along one axis.
- property bounds#
Returns bounding box min and max coordinates. The dilation and slant angle are not taken into account exactly for speed. Instead, the polygon may be slightly smaller than the returned bounds, but it should always be fully contained.
- static array_to_vertices(arr_vertices)[source]#
Converts a numpy array of vertices to a list of tuples.
- static vertices_to_array(vertices_tuple)[source]#
Converts a list of tuples (vertices) to a numpy array.
- property interior_angle#
Angle formed inside polygon by two adjacent edges.
- compute_derivative_slab_bounds_line(derivative_info, extents, r1_min, r1_max, r2_min, r2_max, ax_val, face_poly, min_max_index, interpolators)[source]#
Handle degenerate line cross-section case
- compute_derivative_slab_bounds_surface(derivative_info, extents, r1_min, r1_max, r2_min, r2_max, ax_val, face_poly, min_max_index, interpolators)[source]#
2d surface integral on a Gauss quadrature grid
- edge_basis_vectors(edges)[source]#
Normalized basis vectors for
normaldirection,slabtangent direction andedge.
- unpop_axis_vect(ax_coords, plane_coords)[source]#
Combine coordinate along axis with coordinates on the plane tangent to the axis.
ax_coords.shape == [N] plane_coords.shape == [N, 2] return shape == [N, 3]
- pop_axis_vect(coord)[source]#
Combine coordinate along axis with coordinates on the plane tangent to the axis.
coord.shape == [N, 3] return shape == ([N], [N, 2]
- static normalize_vect(arr)[source]#
normalize an array shaped (N, d) along the d axis and return (N, 1).
- scaled(x=1.0, y=1.0, z=1.0)[source]#
Return a scaled copy of this geometry.
- Parameters:
x (float = 1.0) – Scaling factor along x.
y (float = 1.0) – Scaling factor along y.
z (float = 1.0) – Scaling factor along z.
- Returns:
Scaled copy of this geometry.
- Return type: