Commit bf69195b authored by Daniel Brown's avatar Daniel Brown

Fleshing out automatic Knm handling workspace

parent 1466c237
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
......@@ -14,11 +14,12 @@ from finesse.knm cimport (
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):
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)
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,, 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:
......@@ -222,17 +230,19 @@ cdef class KnmAutoConnectorWorkspace(ConnectorWorkspace):
cdef void compute_scattering_matrices(KnmAutoConnectorWorkspace self):
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 = <complex_t[:info.mtx.size1, :info.mtx.size2:1]>(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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment