Commit 749b494c authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing refactors all over the place. Added HOM code back in

parent 9446e346
......@@ -75,7 +75,7 @@ class DirectionalBeamsplitter(Connector):
def _get_workspace(self, sim):
ws = DBSWorkspace(self, sim, False)
ws.I = np.eye(sim.nhoms, dtype=np.complex128)
ws.I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
ws.set_fill_function(self._fill_matrix)
return ws
......
......@@ -236,7 +236,7 @@ class Joint(Connector):
def _on_init(self, sim):
# TODO: (sjr) does this need to have rows > 1 for HOM simulations?
self.__I = np.eye(sim.nhoms, dtype=np.complex128)
self.__I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
def _fill_matrix(self, sim):
if not sim.is_audio:
......
......@@ -342,9 +342,9 @@ class Mirror(Surface):
_, is_changing = self._eval_parameters()
refill = (
(sim.is_audio and sim.model.fsig.f.is_changing)
or self in sim.trace_forest.changing_components
or sim.any_frequencies_changing
self in sim.trace_forest.changing_components
or sim.carrier.any_frequencies_changing
or (sim.signal.any_frequencies_changing if sim.signal else False)
or (len(is_changing) and is_changing.issubset(self.__changing_check))
)
......
......@@ -642,59 +642,59 @@ cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
# Reflection p1 -> p2
if not self.K12_ws_x.total_reflection and not self.K12_ws_y.total_reflection:
if knm_ws_is_changing(&self.K12_ws_x) or knm_ws_is_changing(&self.K12_ws_y):
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.model_data.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.model_data.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K12.data_view, self.K12.data_view)
flip_odd_horizontal(self.K12.data_view, self.sim.homs_view, self.K12.data_view)
flip_odd_horizontal(self.K12.data_view, self.sim.model_data.homs_view, self.K12.data_view)
knm_loss(self.K12.data_view, self.K12_loss)
# Reflection p2 -> p1
if not self.K21_ws_x.total_reflection and not self.K21_ws_y.total_reflection:
if knm_ws_is_changing(&self.K21_ws_x) or knm_ws_is_changing(&self.K21_ws_y):
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.model_data.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.model_data.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K21.data_view, self.K21.data_view)
flip_odd_horizontal(self.K21.data_view, self.sim.homs_view, self.K21.data_view)
flip_odd_horizontal(self.K21.data_view, self.sim.model_data.homs_view, self.K21.data_view)
knm_loss(self.K21.data_view, self.K21_loss)
# Reflection p3 -> p4
if not self.K34_ws_x.total_reflection and not self.K34_ws_y.total_reflection:
if knm_ws_is_changing(&self.K34_ws_x) or knm_ws_is_changing(&self.K34_ws_y):
compute_knm_matrix_bh(&self.K34_ws_x, &self.K34_ws_y, self.sim.homs_view, self.K34.data_view)
reverse_gouy_phases(self.K34.data_view, self.sim.homs_view, &self.K34_ws_x, &self.K34_ws_y, self.K34.data_view)
compute_knm_matrix_bh(&self.K34_ws_x, &self.K34_ws_y, self.sim.model_data.homs_view, self.K34.data_view)
reverse_gouy_phases(self.K34.data_view, self.sim.model_data.homs_view, &self.K34_ws_x, &self.K34_ws_y, self.K34.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K34.data_view, self.K34.data_view)
flip_odd_horizontal(self.K34.data_view, self.sim.homs_view, self.K34.data_view)
flip_odd_horizontal(self.K34.data_view, self.sim.model_data.homs_view, self.K34.data_view)
knm_loss(self.K34.data_view, self.K34_loss)
# Reflection p4 -> p3
if not self.K43_ws_x.total_reflection and not self.K43_ws_y.total_reflection:
if knm_ws_is_changing(&self.K43_ws_x) or knm_ws_is_changing(&self.K43_ws_y):
compute_knm_matrix_bh(&self.K43_ws_x, &self.K43_ws_y, self.sim.homs_view, self.K43.data_view)
reverse_gouy_phases(self.K43.data_view, self.sim.homs_view, &self.K43_ws_x, &self.K43_ws_y, self.K43.data_view)
compute_knm_matrix_bh(&self.K43_ws_x, &self.K43_ws_y, self.sim.model_data.homs_view, self.K43.data_view)
reverse_gouy_phases(self.K43.data_view, self.sim.model_data.homs_view, &self.K43_ws_x, &self.K43_ws_y, self.K43.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K43.data_view, self.K43.data_view)
flip_odd_horizontal(self.K43.data_view, self.sim.homs_view, self.K43.data_view)
flip_odd_horizontal(self.K43.data_view, self.sim.model_data.homs_view, self.K43.data_view)
knm_loss(self.K43.data_view, self.K43_loss)
# Transmission p1 -> p3
if knm_ws_is_changing(&self.K13_ws_x) or knm_ws_is_changing(&self.K13_ws_y):
compute_knm_matrix_bh(&self.K13_ws_x, &self.K13_ws_y, self.sim.homs_view, self.K13.data_view)
reverse_gouy_phases(self.K13.data_view, self.sim.homs_view, &self.K13_ws_x, &self.K13_ws_y, self.K13.data_view)
compute_knm_matrix_bh(&self.K13_ws_x, &self.K13_ws_y, self.sim.model_data.homs_view, self.K13.data_view)
reverse_gouy_phases(self.K13.data_view, self.sim.model_data.homs_view, &self.K13_ws_x, &self.K13_ws_y, self.K13.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K13.data_view, self.K13.data_view)
......@@ -703,8 +703,8 @@ cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
# Transmission p3 -> p1
if knm_ws_is_changing(&self.K31_ws_x) or knm_ws_is_changing(&self.K31_ws_y):
compute_knm_matrix_bh(&self.K31_ws_x, &self.K31_ws_y, self.sim.homs_view, self.K31.data_view)
reverse_gouy_phases(self.K31.data_view, self.sim.homs_view, &self.K31_ws_x, &self.K31_ws_y, self.K31.data_view)
compute_knm_matrix_bh(&self.K31_ws_x, &self.K31_ws_y, self.sim.model_data.homs_view, self.K31.data_view)
reverse_gouy_phases(self.K31.data_view, self.sim.model_data.homs_view, &self.K31_ws_x, &self.K31_ws_y, self.K31.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K31.data_view, self.K31.data_view)
......@@ -713,8 +713,8 @@ cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
# Transmission p2 -> p4
if knm_ws_is_changing(&self.K24_ws_x) or knm_ws_is_changing(&self.K24_ws_y):
compute_knm_matrix_bh(&self.K24_ws_x, &self.K24_ws_y, self.sim.homs_view, self.K24.data_view)
reverse_gouy_phases(self.K24.data_view, self.sim.homs_view, &self.K24_ws_x, &self.K24_ws_y, self.K24.data_view)
compute_knm_matrix_bh(&self.K24_ws_x, &self.K24_ws_y, self.sim.model_data.homs_view, self.K24.data_view)
reverse_gouy_phases(self.K24.data_view, self.sim.model_data.homs_view, &self.K24_ws_x, &self.K24_ws_y, self.K24.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K24.data_view, self.K24.data_view)
......@@ -723,8 +723,8 @@ cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
# Transmission p4 -> p2
if knm_ws_is_changing(&self.K42_ws_x) or knm_ws_is_changing(&self.K42_ws_y):
compute_knm_matrix_bh(&self.K42_ws_x, &self.K42_ws_y, self.sim.homs_view, self.K42.data_view)
reverse_gouy_phases(self.K42.data_view, self.sim.homs_view, &self.K42_ws_x, &self.K42_ws_y, self.K42.data_view)
compute_knm_matrix_bh(&self.K42_ws_x, &self.K42_ws_y, self.sim.model_data.homs_view, self.K42.data_view)
reverse_gouy_phases(self.K42.data_view, self.sim.model_data.homs_view, &self.K42_ws_x, &self.K42_ws_y, self.K42.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K42.data_view, self.K42.data_view)
......
......@@ -151,16 +151,16 @@ cdef class IsolatorWorkspace(KnmConnectorWorkspace):
cdef void compute_scattering_matrices(self):
# Transmission p1 -> p2
if knm_ws_is_changing(&self.K12_ws_x) or knm_ws_is_changing(&self.K12_ws_y):
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.model_data.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.model_data.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K12.data_view, self.K12.data_view)
# Transmission p2 -> p1
if knm_ws_is_changing(&self.K21_ws_x) or knm_ws_is_changing(&self.K21_ws_y):
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.model_data.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.model_data.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K21.data_view, self.K21.data_view)
......@@ -199,16 +199,16 @@ cdef class LensWorkspace(KnmConnectorWorkspace):
cdef void compute_scattering_matrices(self):
# Transmission p1 -> p2
if knm_ws_is_changing(&self.K12_ws_x) or knm_ws_is_changing(&self.K12_ws_y):
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.model_data.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.model_data.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K12.data_view, self.K12.data_view)
# Transmission p2 -> p1
if knm_ws_is_changing(&self.K21_ws_x) or knm_ws_is_changing(&self.K21_ws_y):
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.model_data.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.model_data.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K21.data_view, self.K21.data_view)
......
......@@ -106,13 +106,17 @@ cdef class MirrorWorkspace(KnmConnectorWorkspace):
owner,
sim,
refill,
refill,
MirrorOpticalConnections(owner, sim.carrier),
MirrorSignalConnections(owner, sim.signal) if sim.signal else None,
MirrorValues()
)
self.mcc = self.carrier_connections
self.mcs = self.signal_connections
self.mcc = self.carrier.connections
if sim.signal:
self.mcs = self.signal.connections
else:
self.mcs = None
self.mv = self.values
# These are only use for beam tracing as far as I can tell
......@@ -305,32 +309,32 @@ cdef class MirrorWorkspace(KnmConnectorWorkspace):
cdef void compute_scattering_matrices(self):
# Reflection p1 -> p1
if knm_ws_is_changing(&self.K11_ws_x) or knm_ws_is_changing(&self.K11_ws_y):
compute_knm_matrix_bh(&self.K11_ws_x, &self.K11_ws_y, self.sim.homs_view, self.K11.data_view)
reverse_gouy_phases(self.K11.data_view, self.sim.homs_view, &self.K11_ws_x, &self.K11_ws_y, self.K11.data_view)
compute_knm_matrix_bh(&self.K11_ws_x, &self.K11_ws_y, self.sim.model_data.homs_view, self.K11.data_view)
reverse_gouy_phases(self.K11.data_view, self.sim.model_data.homs_view, &self.K11_ws_x, &self.K11_ws_y, self.K11.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K11.data_view, self.K11.data_view)
flip_odd_horizontal(self.K11.data_view, self.sim.homs_view, self.K11.data_view)
flip_odd_horizontal(self.K11.data_view, self.sim.model_data.homs_view, self.K11.data_view)
knm_loss(self.K11.data_view, self.K11_loss)
# Reflection p2 -> p2
if knm_ws_is_changing(&self.K22_ws_x) or knm_ws_is_changing(&self.K22_ws_y):
compute_knm_matrix_bh(&self.K22_ws_x, &self.K22_ws_y, self.sim.homs_view, self.K22.data_view)
reverse_gouy_phases(self.K22.data_view, self.sim.homs_view, &self.K22_ws_x, &self.K22_ws_y, self.K22.data_view)
compute_knm_matrix_bh(&self.K22_ws_x, &self.K22_ws_y, self.sim.model_data.homs_view, self.K22.data_view)
reverse_gouy_phases(self.K22.data_view, self.sim.model_data.homs_view, &self.K22_ws_x, &self.K22_ws_y, self.K22.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K22.data_view, self.K22.data_view)
flip_odd_horizontal(self.K22.data_view, self.sim.homs_view, self.K22.data_view)
flip_odd_horizontal(self.K22.data_view, self.sim.model_data.homs_view, self.K22.data_view)
knm_loss(self.K22.data_view, self.K22_loss)
# Transmission p1 -> p2
if knm_ws_is_changing(&self.K12_ws_x) or knm_ws_is_changing(&self.K12_ws_y):
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.model_data.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.model_data.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K12.data_view, self.K12.data_view)
......@@ -339,8 +343,8 @@ cdef class MirrorWorkspace(KnmConnectorWorkspace):
# Transmission p2 -> p1
if knm_ws_is_changing(&self.K21_ws_x) or knm_ws_is_changing(&self.K21_ws_y):
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.model_data.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.model_data.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K21.data_view, self.K21.data_view)
......@@ -507,13 +511,14 @@ cdef object c_mirror_carrier_fill(ConnectorWorkspace cws):
complex_t _it = 1.0j * sqrt(ws.mv.T)
double _r = sqrt(ws.mv.R)
double phi = radians(ws.mv.phi)
Py_ssize_t i
Py_ssize_t i, size
mirror_optical_connections *conn = &ws.mcc.opt_conn_ptrs
frequency_info_t *frequencies
size = ws.sim.carrier.optical_frequencies.size
frequencies = ws.sim.carrier.optical_frequencies.frequency_info
for i in range(ws.sim.num_frequencies):
for i in range(size):
mirror_fill_optical_2_optical(conn, ws, &(frequencies[i]), _r, _it, phi)
......@@ -524,17 +529,18 @@ cdef object c_mirror_signal_fill(ConnectorWorkspace cws):
complex_t _it = 1.0j * sqrt(ws.mv.T)
double _r = sqrt(ws.mv.R)
double phi = radians(ws.mv.phi)
Py_ssize_t i
Py_ssize_t i, size
mirror_optical_connections *conn = &ws.mcs.opt_conn_ptrs
mirror_signal_connections *sconn = &ws.mcs.sig_conn_ptrs
frequency_info_t *freq
frequency_info_t *frequencies
size = ws.sim.signal.optical_frequencies.size
frequencies = ws.sim.signal.optical_frequencies.frequency_info
ws.z_to_field = 1j * ws.sim.model_data.k0 * _r * ws.sim.model_data.x_scale
ws.field_to_Fz = 1 / (C_LIGHT * ws.sim.model_data.x_scale)
for i in range(ws.sim.num_frequencies):
for i in range(size):
freq = &(frequencies[i])
mirror_fill_optical_2_optical(conn, ws, freq, _r, _it, phi)
......
......@@ -136,16 +136,16 @@ cdef class ModulatorWorkspace(KnmConnectorWorkspace):
cdef void compute_scattering_matrices(self):
# Transmission p1 -> p2
if knm_ws_is_changing(&self.K12_ws_x) or knm_ws_is_changing(&self.K12_ws_y):
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
compute_knm_matrix_bh(&self.K12_ws_x, &self.K12_ws_y, self.sim.model_data.homs_view, self.K12.data_view)
reverse_gouy_phases(self.K12.data_view, self.sim.model_data.homs_view, &self.K12_ws_x, &self.K12_ws_y, self.K12.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K12.data_view, self.K12.data_view)
# Transmission p2 -> p1
if knm_ws_is_changing(&self.K21_ws_x) or knm_ws_is_changing(&self.K21_ws_y):
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
compute_knm_matrix_bh(&self.K21_ws_x, &self.K21_ws_y, self.sim.model_data.homs_view, self.K21.data_view)
reverse_gouy_phases(self.K21.data_view, self.sim.model_data.homs_view, &self.K21_ws_x, &self.K21_ws_y, self.K21.data_view)
if self.sim.model_data.zero_K00:
zero_tem00_phase(self.K21.data_view, self.K21.data_view)
......
......@@ -19,7 +19,7 @@ cdef class KnmConnectorWorkspace(ConnectorWorkspace):
setattr(self, f"K{coupling}", kmat)
if make_knm_losses:
setattr(self, f"K{coupling}_loss", np.ones(self.sim.nhoms))
setattr(self, f"K{coupling}_loss", np.ones(self.sim.model_data.num_HOMs))
cdef void initialise_knm_workspaces(KnmConnectorWorkspace self) nogil:
pass
......
......@@ -47,7 +47,7 @@ class Photodiode(Connector):
def _get_workspace(self, sim):
if sim.is_audio:
ws = PhotodiodeWorkspace(self, sim, True)
ws.I = np.eye(sim.nhoms, dtype=np.complex128)
ws.I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
ws.set_fill_function(self._fill_matrix)
ws.frequencies = sim.electrical_frequencies[self.DC.o].frequencies
return ws
......
......@@ -112,7 +112,7 @@ class QuantumNoiseDetector(Detector):
# vacuum noise and demodulate that into our signal.
for el in self.demod_vac_contri.values():
if len(el["c_idx"]) > 1:
for j in range(max(sim.nhoms, 1)):
for j in range(max(sim.model_data.num_HOMs, 1)):
val = 0
for k in el["c_idx"]:
val += (
......@@ -126,7 +126,7 @@ class QuantumNoiseDetector(Detector):
rtn += abs(val) * (1 + el["f"] / sim.model.f0) ** 2
else:
val = 0
for j in range(max(sim.nhoms, 1)):
for j in range(max(sim.model_data.num_HOMs, 1)):
# val += abs(carrier.out[carrier.field(self._node, el["c_idx"][0], j)])**2
val += abs(carrier.get_DC_out(self._node, el["c_idx"][0], j)) ** 2
rtn += val * (1 + el["f"] / sim.model.f0)
......@@ -219,7 +219,7 @@ class QuantumNoiseDetector(Detector):
# product between the j'th carrier and this.
fs = sim.frequencies[self.demod_f_sig[j][k]]
if fs.order > 0:
for i in range(max(sim.nhoms, 1)):
for i in range(max(sim.model_data.num_HOMs, 1)):
c_idx = carrier.field(self._node, fc.index, i)
s_idx = sim.field(self._node, fs.index, i)
self.s[s_idx] += (
......@@ -228,7 +228,7 @@ class QuantumNoiseDetector(Detector):
* np.exp(-1j * np.deg2rad(self.demod_phi[k]))
)
else:
for i in range(max(sim.nhoms, 1)):
for i in range(max(sim.model_data.num_HOMs, 1)):
c_idx = carrier.field(self._node, fc.index, i)
s_idx = sim.field(self._node, fs.index, i)
self.s[s_idx] += np.conj(
......
......@@ -669,6 +669,9 @@ cdef class CarrierSignalMatrixSimulation:
self.trace = NULL
def build(self):
cdef:
Py_ssize_t i = 0
from finesse.simulations.KLU import KLUMatrixSystemSolver
self.compute_signals = self.model.fsig.f.value is not None
......@@ -677,17 +680,37 @@ cdef class CarrierSignalMatrixSimulation:
# First we sort out the two matrix simulations as required by the model
cf = self.generate_carrier_frequencies()
nodes = self.model.optical_nodes
self.carrier = KLUMatrixSystemSolver("carrier", nodes, cf, None, None, self.model_data.num_HOMs, False)
onodes = self.model.optical_nodes
self.carrier = KLUMatrixSystemSolver("carrier", onodes, cf, None, None, self.model_data.num_HOMs, False)
if self.compute_signals:
sf, mf, ef, umef = self.generate_signal_frequencies(cf)
nodes = onodes.copy()
nodes.extend(self.model.mechanical_nodes)
nodes.extend(self.model.electrical_nodes)
self.signal = KLUMatrixSystemSolver("signal", nodes, sf, mf, ef, self.model_data.num_HOMs, True)
self.initialise_trace_forest()
# Before we setup the workspaces some initial beam trace must be done
# so that workspaces can initialise themselves
if self.is_modal:
# Perform an initial beam trace
self.model.beam_trace(**self.model.beam_trace_args)
self.trace = <NodeBeamParam*> calloc(len(onodes), sizeof(NodeBeamParam))
if not self.trace:
raise MemoryError()
for i, n in enumerate(onodes):
qx, qy = self.model.last_trace[n]
# NOTE set is_changing to True for all node beam params initially
# so that initial scattering matrices get computed, these flags
# will then be updated in _determine_changing_beam_params
self.trace[i] = NodeBeamParam(qx.q, qy.q, True)
# ddb - nothing should be accessing trace if it isn't a modal simulation
#else:
# self.trace[i] = NodeBeamParam(COMPLEX_0, COMPLEX_0, False)
self.initialise_trace_forest()
self.initialise_workspaces()
self.update_all_parameter_values()
......@@ -697,11 +720,11 @@ cdef class CarrierSignalMatrixSimulation:
# - space Gouy phases
# - laser tem Gouy phases
self.compute_knm_matrices()
self.set_gouy_phases()
#self.set_gouy_phases()
# ... then determine which beam parameters will be changing
# so that only the items from above which change get
# re-computed on subsequent calls to their respective functions
self._determine_changing_beam_params()
#self._determine_changing_beam_params()
self.carrier.assign_submatrices(self.workspaces)
self.carrier.construct()
......@@ -1013,6 +1036,9 @@ cdef class CarrierSignalMatrixSimulation:
self.to_scatter_matrix_compute = []
self.variable_workspaces = []
if self.is_modal and self.trace == NULL:
raise Exception("Beam trace has not been set before workspaces are initialised")
# Get any callbacks for the elements in the model
# tell the element that we have now built the model and it
# should do some initialisations for running simulations
......
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