Ejemplo n.º 1
0
    def eval(self, sim: mp.Simulation) -> goos.NumericFlow:
        eps = sim.get_epsilon(omega=2 * np.pi / self._wlen)

        if len(eps.shape) < 3:
            eps = np.expand_dims(eps, axis=self._expand_axis)

        return goos.NumericFlow(eps)
Ejemplo n.º 2
0
    def eval(self, sim: FdfdSimProp) -> goos.NumericFlow:
        """Computes frequency-domain fields.

        Frequency domain fields are computed for all three components and
        stacked into one numpy array.

        Returns:
            A `NumericFlow` where the ith entry of the array corresponds to
            electric field component i (e.g. 0th entry is Ex).
        """
        return goos.NumericFlow(sim.fields)
Ejemplo n.º 3
0
    def eval(self, inputs: List[goos.NumericFlow]) -> goos.NumericFlow:
        vector = inputs[0].array
        index = inputs[1].array

        if np.isscalar(self._min_features):
            min_feats = self._min_features
        else:
            min_feats = np.array([self._min_features[i] for i in index[:-1]])
        val = min_feats - (vector[1:] - vector[:-1])
        # Append constraints for first and last edge.
        val = np.r_[val, -vector[0], vector[-1] - self._grating_len]

        return goos.NumericFlow(val)
Ejemplo n.º 4
0
    def eval(self, sim: mp.Simulation) -> goos.NumericFlow:

        # Retrieve the relevant tangential fields.
        fields = []
        for comp in self._wg_mode.field_comps:
            fields.append(
                np.reshape(sim.get_dft_array(self._mon, comp, 0),
                           self._wg_mode.xyzw[3].shape))

        norms = _get_overlap_integral(self._wg_mode.mode_fields, fields,
                                      self._wg_mode.xyzw)
        if gridlock.axisvec2polarity(self._overlap.normal) > 0:
            val = 0.5 * (norms[0] + norms[1]) / self._mode_norm
        else:
            val = 0.5 * (norms[0] - norms[1]) / self._mode_norm

        return goos.NumericFlow(val * self._amp_factor)
Ejemplo n.º 5
0
    def eval(self, sim: mp.Simulation) -> goos.NumericFlow:
        """Computes frequency-domain fields.

        Frequency domain fields are computed for all three components and
        stacked into one numpy array.

        Returns:
            A `NumericFlow` where the ith entry of the array corresponds to
            electric field component i (e.g. 0th entry is Ex).
        """
        fields = np.stack([
            sim.get_dft_array(self._dft_field, mp.Ex, 0),
            sim.get_dft_array(self._dft_field, mp.Ey, 0),
            sim.get_dft_array(self._dft_field, mp.Ez, 0)
        ],
                          axis=0)

        if len(fields.shape) < 4:
            fields = np.expand_dims(fields, axis=self._expand_axis[0] + 1)
        return goos.NumericFlow(fields)
Ejemplo n.º 6
0
 def eval(self, sim: EigSimProp) -> goos.NumericFlow:
     return goos.NumericFlow(sim.omegas)
Ejemplo n.º 7
0
 def eval(self, sim: FdfdSimProp) -> goos.NumericFlow:
     return goos.NumericFlow(np.sum(self._wg_overlap * sim.fields))
Ejemplo n.º 8
0
 def eval(self, sim: FdfdSimProp) -> goos.NumericFlow:
     return goos.NumericFlow(sim.eps)
Ejemplo n.º 9
0
 def eval(self, input_vals: List[goos.NumericFlow]) -> goos.NumericFlow:
     return goos.NumericFlow(
         np.linalg.norm(input_vals[0].array.flatten(), ord=self._ord))
Ejemplo n.º 10
0
 def eval(self, input_vals: List[goos.NumericFlow]) -> goos.NumericFlow:
     return goos.NumericFlow(
         np.sum(input_vals[0].array * input_vals[1].array))
Ejemplo n.º 11
0
    def eval(self, inputs: List[goos.NumericFlow]) -> goos.NumericFlow:
        shape = inputs[0].array.shape
        slices = self._make_slices(shape)

        return goos.NumericFlow(inputs[0].array[slices])
Ejemplo n.º 12
0
 def eval(self, inputs):
     agg_flow = [goos.NumericFlow(x) for x in self._nums]
     return goos.ArrayFlow(agg_flow)
Ejemplo n.º 13
0
def test_array_flow_inequality():
    flow = goos.ArrayFlow([goos.NumericFlow(3), goos.NumericFlow(2)])
    flow2 = goos.ArrayFlow([goos.NumericFlow(3), goos.NumericFlow(1)])

    assert flow != flow2