コード例 #1
0
ファイル: electrical.py プロジェクト: pythonoptics/PICwriter
 def build_ports(self):
     # Portlist format:
     # example: example:  {'port':(x_position, y_position), 'direction': 'NORTH'}
     self.portlist["input"] = {
         'port': (self.trace[0][0], self.trace[0][1]),
         'direction': tk.get_direction(self.trace[1], self.trace[0])
     }
     self.portlist["output"] = {
         'port': (self.trace[-1][0], self.trace[-1][1]),
         'direction': tk.get_direction(self.trace[-2], self.trace[-1])
     }
コード例 #2
0
ファイル: electrical.py プロジェクト: pythonoptics/PICwriter
    def build_cell(self):
        # Sequentially build all the geometric shapes using gdspy path functions
        # for waveguide, then add it to the Cell
        br = self.mt.bend_radius

        path = gdspy.Path(self.mt.width, self.trace[0])
        path2 = gdspy.Path(self.mt.width + 2 * self.mt.clad_width,
                           self.trace[0])

        prior_direction = tk.get_direction(self.trace[0], self.trace[1])

        if br != 0:
            """ Path routing for curved bends.  Same as in waveguide class. """
            path.segment(tk.dist(self.trace[0], self.trace[1]) - br,
                         direction=tk.get_angle(self.trace[0], self.trace[1]),
                         **self.spec)
            path2.segment(tk.dist(self.trace[0], self.trace[1]) - br,
                          direction=tk.get_angle(self.trace[0], self.trace[1]),
                          **self.clad_spec)
            for i in range(len(self.trace) - 2):
                direction = tk.get_direction(self.trace[i + 1],
                                             self.trace[i + 2])
                turn = tk.get_turn(prior_direction, direction)
                path.turn(br, turn, number_of_points=0.1, **self.spec)
                path2.turn(br, turn, number_of_points=0.1, **self.clad_spec)
                if tk.dist(
                        self.trace[i + 1], self.trace[i + 2]
                ) - 2 * br > 0:  #ONLY False for last points if spaced br < distance < 2br
                    path.segment(
                        tk.dist(self.trace[i + 1], self.trace[i + 2]) - 2 * br,
                        **self.spec)
                    path2.segment(
                        tk.dist(self.trace[i + 1], self.trace[i + 2]) - 2 * br,
                        **self.clad_spec)
                prior_direction = direction
            if tk.dist(self.trace[-2], self.trace[-1]) < 2 * br:
                path.segment(
                    tk.dist(self.trace[-2], self.trace[-1]) - br, **self.spec)
                path2.segment(
                    tk.dist(self.trace[-2], self.trace[-1]) - br,
                    **self.clad_spec)
            else:
                path.segment(br, **self.spec)
                path2.segment(br, **self.clad_spec)

            if len(self.trace) == 2 and tk.dist(
                    self.trace[1], self.trace[0]) <= self.mt.bend_radius:
                path = gdspy.Path(self.mt.width, self.trace[0])
                path.segment(tk.dist(self.trace[0], self.trace[1]),
                             direction=tk.get_angle(self.trace[0],
                                                    self.trace[1]),
                             **self.spec)
                path2 = gdspy.Path(self.mt.width + 2 * self.mt.clad_width,
                                   self.trace[0])
                path2.segment(tk.dist(self.trace[0], self.trace[1]),
                              direction=tk.get_angle(self.trace[0],
                                                     self.trace[1]),
                              **self.clad_spec)
        elif br == 0:
            """ Do path routing for sharp 90 degree trace bends """
            path.segment(tk.dist(self.trace[0], self.trace[1]),
                         direction=tk.get_angle(self.trace[0], self.trace[1]),
                         **self.spec)
            path2.segment(tk.dist(self.trace[0], self.trace[1]),
                          direction=tk.get_angle(self.trace[0], self.trace[1]),
                          **self.clad_spec)
            for i in range(len(self.trace) - 2):
                """ Add a square to fill in the corner """
                self.add(
                    gdspy.Rectangle(
                        (self.trace[i + 1][0] - self.mt.width / 2.0,
                         self.trace[i + 1][1] - self.mt.width / 2.0),
                        (self.trace[i + 1][0] + self.mt.width / 2.0,
                         self.trace[i + 1][1] + self.mt.width / 2.0),
                        **self.spec))
                self.add(
                    gdspy.Rectangle(
                        (self.trace[i + 1][0] - self.mt.width / 2.0 -
                         self.mt.clad_width, self.trace[i + 1][1] -
                         self.mt.width / 2.0 - self.mt.clad_width),
                        (self.trace[i + 1][0] + self.mt.width / 2.0 +
                         self.mt.clad_width, self.trace[i + 1][1] +
                         self.mt.width / 2.0 + self.mt.clad_width),
                        **self.clad_spec))
                angle = tk.get_angle(self.trace[i + 1], self.trace[i + 2])
                path.segment(tk.dist(self.trace[i + 1], self.trace[i + 2]),
                             direction=angle,
                             **self.spec)
                path2.segment(tk.dist(self.trace[i + 1], self.trace[i + 2]),
                              direction=angle,
                              **self.clad_spec)
        """ Extra padding """
        if tk.get_direction(self.trace[0],
                            self.trace[1]) == 'EAST' or tk.get_direction(
                                self.trace[0], self.trace[1]) == 'WEST':
            pad_ll = (self.trace[0][0] - self.mt.clad_width, self.trace[0][1] -
                      self.mt.width / 2.0 - self.mt.clad_width)
            pad_ul = (self.trace[0][0] + self.mt.clad_width, self.trace[0][1] +
                      self.mt.width / 2.0 + self.mt.clad_width)
        else:
            pad_ll = (self.trace[0][0] - self.mt.width / 2.0 -
                      self.mt.clad_width,
                      self.trace[0][1] - self.mt.clad_width)
            pad_ul = (self.trace[0][0] + self.mt.width / 2.0 +
                      self.mt.clad_width,
                      self.trace[0][1] + self.mt.clad_width)
        self.add(gdspy.Rectangle(pad_ll, pad_ul, **self.clad_spec))

        if tk.get_direction(self.trace[-2],
                            self.trace[-1]) == 'EAST' or tk.get_direction(
                                self.trace[-2], self.trace[-1]) == 'WEST':
            pad_ll = (self.trace[-1][0] - self.mt.clad_width,
                      self.trace[-1][1] - self.mt.width / 2.0 -
                      self.mt.clad_width)
            pad_ul = (self.trace[-1][0] + self.mt.clad_width,
                      self.trace[-1][1] + self.mt.width / 2.0 +
                      self.mt.clad_width)
        else:
            pad_ll = (self.trace[-1][0] - self.mt.width / 2.0 -
                      self.mt.clad_width,
                      self.trace[-1][1] - self.mt.clad_width)
            pad_ul = (self.trace[-1][0] + self.mt.width / 2.0 +
                      self.mt.clad_width,
                      self.trace[-1][1] + self.mt.clad_width)
        self.add(gdspy.Rectangle(pad_ll, pad_ul, **self.clad_spec))

        self.add(path)
        self.add(path2)