diff --git a/src/finesse/components/modal/workspace.pxd b/src/finesse/components/modal/workspace.pxd index 116df61d1dc27e46d9e7ff72045bda3c3b495e08..83c5b778a5401fd761f3982ecb3e752c1928b8cf 100644 --- a/src/finesse/components/modal/workspace.pxd +++ b/src/finesse/components/modal/workspace.pxd @@ -1,8 +1,9 @@ from finesse.components.workspace cimport ConnectorWorkspace from finesse.knm cimport KnmWorkspace -from finesse.simulations.base cimport BaseSimulation, NodeBeamParam -from finesse.cymath cimport complex_t - +from finesse.simulations.base cimport NodeBeamParam +from finesse.simulations.basematrix cimport CarrierSignalMatrixSimulation +from finesse.cymath.complex cimport complex_t, DenseZMatrix +from cpython.ref cimport PyObject import numpy as np cimport numpy as np @@ -24,6 +25,8 @@ cdef struct KnmInfo: double *beta_y double beta_y_factor double beta_x_factor + # Pointer to a KnmMatrix + DenseZMatrix *mtx cdef class KnmConnectorWorkspace(ConnectorWorkspace): # Sequence of string reprs of the optical couplings diff --git a/src/finesse/components/modal/workspace.pyx b/src/finesse/components/modal/workspace.pyx index 6d1a5a84a8e3395c6210ea33b99f0418b2d6cd78..1555b2e5ba44b7a4b4d89b2d98e6ab2edb8058a4 100644 --- a/src/finesse/components/modal/workspace.pyx +++ b/src/finesse/components/modal/workspace.pyx @@ -14,11 +14,12 @@ from finesse.knm cimport ( compute_knm_matrix_bh, reverse_gouy_phases, zero_tem00_phase, + flip_odd_horizontal, ) from finesse.cymath.gaussbeam cimport c_transform_q from finesse.components.workspace cimport ConnectorWorkspace from finesse.components.general import NodeType -from finesse.simulations.base cimport BaseSimulation, NodeBeamParam +from finesse.simulations.base cimport NodeBeamParam import finesse.components as components @@ -56,9 +57,10 @@ cdef class KnmConnectorWorkspace(ConnectorWorkspace): pass -cdef class KnmAutoConnectorWorkspace(ConnectorWorkspace): - def __init__(self, object owner, BaseSimulation sim, *args, **kwargs): - super().__init__(owner, sim, *args, **kwargs) +cdef class KnmAutoConnectorWorkspace(KnmConnectorWorkspace): + def __init__(self, object owner, CarrierSignalMatrixSimulation sim, *args, **kwargs): + # Skip KnmConnectorWorkspace init call + ConnectorWorkspace.__init__(self, owner, sim, *args, **kwargs) # Here we automatically generate the coupling strings used # for generating the Knm matricies. We use the optical to optical @@ -90,19 +92,25 @@ cdef class KnmAutoConnectorWorkspace(ConnectorWorkspace): # need these node ids for the simulation for indexing traces for i, p in enumerate(oports): - self.onode_ids[2*i] = sim.node_id(p.i) - self.onode_ids[2*i+1] = sim.node_id(p.o) + self.onode_ids[2*i] = sim.carrier.node_id(p.i) + self.onode_ids[2*i+1] = sim.carrier.node_id(p.o) - str_couplings = [] for i, (conn, (f, t)) in enumerate(self.o2o.items()): + # TODO ddb should probably use some fixed index rather than a list of the order + # they are defined in the element definition a = oports.index(f.port) b = oports.index(t.port) - str_couplings.append(f"{a+1}{b+1}") + coupling = f"{a+1}{b+1}" self.oconn_info[i].from_port_idx = a self.oconn_info[i].to_port_idx = b self.oconn_info[i].K_ws_x = &self.Kws[2*i] self.oconn_info[i].K_ws_y = &self.Kws[2*i+1] - + knm = KnmMatrix(self.sim.model_data.homs_view, self.owner.name, coupling) + self.oconn_info[i].mtx = &knm.mtx + # Create the actual Knm matrix here based on the optical + # port coupling indices + setattr(self, f"K{coupling}", knm) + def __dealloc__(self): if self.onode_ids: free(self.onode_ids) @@ -222,17 +230,19 @@ cdef class KnmAutoConnectorWorkspace(ConnectorWorkspace): cdef void compute_scattering_matrices(KnmAutoConnectorWorkspace self): cdef: - NodeBeamParam *q_from - NodeBeamParam *q_to KnmInfo *info - complex_t qx_o_matched_trns, qy_o_matched_trns - + complex_t[:,::1] view + for i in range(self.N_opt_conns): info = &self.oconn_info[i] - # Transmission if knm_ws_is_changing(info.K_ws_x) or knm_ws_is_changing(info.K_ws_y): - #compute_knm_matrix_bh(info.K_ws_x, info.K_ws_y, self.sim.homs_view, self.K12.data_view) - reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, info.K_ws_x, info.K_ws_y, self.K12.data_view) + # Can't store memoryview in struct so have to do some converting here + view = (info.mtx.ptr) + compute_knm_matrix_bh(info.K_ws_x, info.K_ws_y, self.sim.model_data.homs_view, view) + reverse_gouy_phases(view, self.sim.homs_view, info.K_ws_x, info.K_ws_y, view) + + if self.sim.model_data.zero_K00: + zero_tem00_phase(view, view) - #if self.sim.model_data.zero_K00: - # zero_tem00_phase(self.K12.data_view, self.K12.data_view) \ No newline at end of file + if not info.is_transmission: # if reflection... + flip_odd_horizontal(view, self.sim.model_data.homs_view, view) \ No newline at end of file