directional_beamsplitter.py 2.72 KB
Newer Older
Phil Jones's avatar
Phil Jones committed
1 2 3 4 5 6 7 8 9
"""
Optical components performing directional redirection of beams.
"""

import logging
import numpy as np

from finesse.components.general import Connector, InteractionType
from finesse.components.node import NodeDirection, NodeType
10
from .workspace import ConnectorWorkspace, Connections
Phil Jones's avatar
Phil Jones committed
11 12 13 14 15


LOGGER = logging.getLogger(__name__)


Daniel Brown's avatar
Daniel Brown committed
16 17 18 19 20
class DBSWorkspace(ConnectorWorkspace):
    def __init__(self, owner, sim, refill):
        super().__init__(owner, sim, refill, Connections(sim))


Phil Jones's avatar
Phil Jones committed
21 22
class DirectionalBeamsplitter(Connector):
    """
23 24 25 26 27 28
    Represents a directional beamsplitter optical component.

    Parameters
    ----------
    name : str
        Name of newly created directional beamsplitter.
Phil Jones's avatar
Phil Jones committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    """

    def __init__(self, name):
        super().__init__(name)

        self._add_port("p1", NodeType.OPTICAL)
        self.p1._add_node("i", NodeDirection.INPUT)
        self.p1._add_node("o", NodeDirection.OUTPUT)

        self._add_port("p2", NodeType.OPTICAL)
        self.p2._add_node("i", NodeDirection.INPUT)
        self.p2._add_node("o", NodeDirection.OUTPUT)

        self._add_port("p3", NodeType.OPTICAL)
        self.p3._add_node("i", NodeDirection.INPUT)
        self.p3._add_node("o", NodeDirection.OUTPUT)

        self._add_port("p4", NodeType.OPTICAL)
        self.p4._add_node("i", NodeDirection.INPUT)
        self.p4._add_node("o", NodeDirection.OUTPUT)

        # optic to optic couplings
        self._register_node_coupling(
Daniel Brown's avatar
Daniel Brown committed
52 53 54 55
            "P1i_P3o",
            self.p1.i,
            self.p3.o,
            interaction_type=InteractionType.TRANSMISSION,
Phil Jones's avatar
Phil Jones committed
56 57
        )
        self._register_node_coupling(
Daniel Brown's avatar
Daniel Brown committed
58 59 60 61
            "P3i_P4o",
            self.p3.i,
            self.p4.o,
            interaction_type=InteractionType.TRANSMISSION,
Phil Jones's avatar
Phil Jones committed
62 63
        )
        self._register_node_coupling(
Daniel Brown's avatar
Daniel Brown committed
64 65 66 67
            "P4i_P2o",
            self.p4.i,
            self.p2.o,
            interaction_type=InteractionType.TRANSMISSION,
Phil Jones's avatar
Phil Jones committed
68 69
        )
        self._register_node_coupling(
Daniel Brown's avatar
Daniel Brown committed
70 71 72 73
            "P2i_P1o",
            self.p2.i,
            self.p1.o,
            interaction_type=InteractionType.TRANSMISSION,
Phil Jones's avatar
Phil Jones committed
74 75
        )

Daniel Brown's avatar
Daniel Brown committed
76 77
    def _get_workspace(self, sim):
        ws = DBSWorkspace(self, sim, False)
78
        ws.I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
Daniel Brown's avatar
Daniel Brown committed
79
        ws.set_fill_function(self._fill_matrix)
Daniel Brown's avatar
Daniel Brown committed
80 81 82 83 84 85 86 87 88 89 90
        return ws

    def _fill_matrix(self, ws):
        for freq in ws.sim.frequencies:
            for idx in (
                ws.connections.P1i_P3o_idx,
                ws.connections.P3i_P4o_idx,
                ws.connections.P4i_P2o_idx,
                ws.connections.P2i_P1o_idx,
            ):
                with ws.sim.component_edge_fill3(
Daniel Brown's avatar
Daniel Brown committed
91
                    ws.owner_id, idx, freq.index, freq.index,
Daniel Brown's avatar
Daniel Brown committed
92 93
                ) as mat:
                    mat[:] = ws.I