beamsplitter.pxd 5.9 KB
Newer Older
Daniel Brown's avatar
Daniel Brown committed
1
from finesse.cmatrix cimport SubCCSView, SubCCSView1DArray, SubCCSView2DArray
2
from finesse.knm cimport KnmMatrix, KnmWorkspace
3
from finesse.cymath cimport complex_t
4
from finesse.simulations.base cimport frequency_info_t, ModelData, NodeBeamParam
5
from finesse.simulations cimport BaseSimulation
6 7
from finesse.element cimport BaseCValues
from finesse.components.workspace cimport ConnectorWorkspace, FillFuncWrapper
8
from finesse.components.modal.workspace cimport KnmConnectorWorkspace
9

10 11 12 13 14 15 16 17
from finesse.cyexpr cimport (
    cy_expr,
    cy_expr_new,
    cy_expr_init,
    cy_expr_free,
    cy_expr_eval,
)

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
from cpython.ref cimport PyObject

import numpy as np
cimport numpy as np

cdef class BeamsplitterConnections:
    cdef public:
        Py_ssize_t P1i_P2o_idx
        Py_ssize_t P2i_P1o_idx
        Py_ssize_t P3i_P4o_idx
        Py_ssize_t P4i_P3o_idx
        Py_ssize_t P1i_P3o_idx
        Py_ssize_t P3i_P1o_idx
        Py_ssize_t P2i_P4o_idx
        Py_ssize_t P4i_P2o_idx
        Py_ssize_t P1i_Z_idx
        Py_ssize_t P1o_Z_idx
        Py_ssize_t P2i_Z_idx
        Py_ssize_t P2o_Z_idx
        Py_ssize_t P3i_Z_idx
        Py_ssize_t P3o_Z_idx
        Py_ssize_t P4i_Z_idx
        Py_ssize_t P4o_Z_idx
        Py_ssize_t Z_P1o_idx
        Py_ssize_t Z_P2o_idx
        Py_ssize_t Z_P3o_idx
        Py_ssize_t Z_P4o_idx

        SubCCSView1DArray P1i_P2o
        SubCCSView1DArray P2i_P1o
        SubCCSView1DArray P3i_P4o
        SubCCSView1DArray P4i_P3o
        SubCCSView1DArray P1i_P3o
        SubCCSView1DArray P3i_P1o
        SubCCSView1DArray P2i_P4o
        SubCCSView1DArray P4i_P2o

Daniel Brown's avatar
Daniel Brown committed
55 56 57 58 59 60 61 62 63 64 65 66
        SubCCSView2DArray P1i_Z
        SubCCSView2DArray P1o_Z
        SubCCSView2DArray P2i_Z
        SubCCSView2DArray P2o_Z
        SubCCSView2DArray P3i_Z
        SubCCSView2DArray P3o_Z
        SubCCSView2DArray P4i_Z
        SubCCSView2DArray P4o_Z
        SubCCSView2DArray Z_P1o
        SubCCSView2DArray Z_P2o
        SubCCSView2DArray Z_P3o
        SubCCSView2DArray Z_P4o
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83


cdef class BeamsplitterValues(BaseCValues):
    cdef public:
        double R
        double T
        double L
        double phi
        double Rcx
        double Rcy
        double xbeta
        double ybeta
        double mass
        double signal_gain
        double alpha


84
cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
85
    cdef public:
86
        # Complete scattering matrices for each propagation direction
87 88 89 90 91 92 93 94
        KnmMatrix K12
        KnmMatrix K21
        KnmMatrix K13
        KnmMatrix K31
        KnmMatrix K24
        KnmMatrix K42
        KnmMatrix K34
        KnmMatrix K43
95 96 97 98
        # NOTE (sjr) The above should remain as the full scattering matrices
        #            (i.e. composite over each scattering type) whilst extra
        #            KnmMatrix objects should be stored here for the different
        #            types (i.e. K12_map, K12_aperture, etc.)
99

100
        # Arrays of scattering losses for each mode coupling
101 102 103 104 105 106 107 108
        double[::1] K12_loss
        double[::1] K21_loss
        double[::1] K13_loss
        double[::1] K31_loss
        double[::1] K24_loss
        double[::1] K42_loss
        double[::1] K34_loss
        double[::1] K43_loss
109 110 111

        double cos_alpha
        double cos_alpha_2
112 113

        # Refractive indices of adjacent spaces
114 115 116 117 118 119 120 121
        double nr1
        double nr2

        Py_ssize_t car_p1o_rhs_idx, car_p1i_rhs_idx
        Py_ssize_t car_p2o_rhs_idx, car_p2i_rhs_idx
        Py_ssize_t car_p3o_rhs_idx, car_p3i_rhs_idx
        Py_ssize_t car_p4o_rhs_idx, car_p4i_rhs_idx
        Py_ssize_t car_p_num_hom
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

        # ABCD matrix views
        # -> reflection
        double[:, ::1] abcd_p1p2_x
        double[:, ::1] abcd_p1p2_y
        double[:, ::1] abcd_p2p1_x
        double[:, ::1] abcd_p2p1_y
        double[:, ::1] abcd_p3p4_x
        double[:, ::1] abcd_p3p4_y
        double[:, ::1] abcd_p4p3_x
        double[:, ::1] abcd_p4p3_y
        # -> transmission
        double[:, ::1] abcd_p1p3_x
        double[:, ::1] abcd_p1p3_y
        double[:, ::1] abcd_p3p1_x
        double[:, ::1] abcd_p3p1_y
        double[:, ::1] abcd_p2p4_x
        double[:, ::1] abcd_p2p4_y
        double[:, ::1] abcd_p4p2_x
        double[:, ::1] abcd_p4p2_y
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156
    cdef:
        BeamsplitterValues bv
        BeamsplitterConnections bc

        # Indices (in sim._c_node_info and sim.trace) of nodes
        Py_ssize_t P1i_id
        Py_ssize_t P1o_id
        Py_ssize_t P2i_id
        Py_ssize_t P2o_id
        Py_ssize_t P3i_id
        Py_ssize_t P3o_id
        Py_ssize_t P4i_id
        Py_ssize_t P4o_id

157
        # Changing expressions of each ABCD matrix
158 159 160 161 162 163 164 165 166 167
        # -> size 16 as there are 16 different coupling, plane combos
        # -> order of these corresponds exactly to order of matrix views above
        # NOTE (sjr) Elements A, C & D can change so we will just store arrays
        #            of pointers for every element here, rather than singling out
        #            each element, for convenience
        cy_expr** sym_abcd_elements[16]

        # Direct pointer access to beginning of contiguous memory chunk of
        # each ABCD matrix for speed and convenience in updating
        double* abcd_elements[16]
168

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        KnmWorkspace K12_ws_x
        KnmWorkspace K12_ws_y
        KnmWorkspace K21_ws_x
        KnmWorkspace K21_ws_y
        KnmWorkspace K34_ws_x
        KnmWorkspace K34_ws_y
        KnmWorkspace K43_ws_x
        KnmWorkspace K43_ws_y

        KnmWorkspace K13_ws_x
        KnmWorkspace K13_ws_y
        KnmWorkspace K31_ws_x
        KnmWorkspace K31_ws_y
        KnmWorkspace K24_ws_x
        KnmWorkspace K24_ws_y
        KnmWorkspace K42_ws_x
        KnmWorkspace K42_ws_y
186

187 188
    cpdef compile_abcd_cy_exprs(self)
    cpdef update_parameter_values(self)
Samuel Rowlinson's avatar
Samuel Rowlinson committed
189 190 191 192 193
    cdef void initialise_knm_workspaces(self) nogil
    cdef void free_knm_workspaces(self) nogil
    cdef void flag_changing_knm_workspaces(self)
    cdef void update_changing_knm_workspaces(self) nogil
    cdef void compute_scattering_matrices(self)
194

195 196

cdef object c_beamsplitter_fill(ConnectorWorkspace cws)