Commit c096135a authored by Daniel Brown's avatar Daniel Brown
Browse files

Removing refill flag set in workspace constructors. This should be done per fill function.

parent cff3a6d5
# cython profile=True
# cython: profile=True
import logging
......
......@@ -580,7 +580,7 @@ class Beamsplitter(Surface):
or (len(is_changing) and is_changing.issubset(self.__changing_check))
)
ws = BeamsplitterWorkspace(self, sim, refill)
ws = BeamsplitterWorkspace(self, sim)
ws.carrier.add_fill_function(beamsplitter_carrier_fill, refill)
ws.signal.add_fill_function(beamsplitter_signal_fill, refill)
......
"""
Optical components performing directional redirection of beams.
"""
"""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
from finesse.components.workspace import Connections
from finesse.components.modal.workspace import KnmConnectorWorkspace
from finesse.utilities import refractive_index
LOGGER = logging.getLogger(__name__)
class DBSWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, sim, refill):
super().__init__(owner, sim, refill, refill)
class DirectionalBeamsplitter(Connector):
"""
Represents a directional beamsplitter optical component.
"""Represents a directional beamsplitter optical component.
Parameters
----------
......@@ -75,7 +65,13 @@ class DirectionalBeamsplitter(Connector):
)
def _get_workspace(self, sim):
ws = DBSWorkspace(self, sim, False)
from finesse.components.modal.workspace import KnmConnectorWorkspace
class DBSWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, sim):
super().__init__(owner, sim)
ws = DBSWorkspace(self, sim)
ws.I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
ws.carrier.add_fill_function(self._fill_carrier, False)
if sim.signal:
......
......@@ -9,8 +9,8 @@ from finesse.parameter import float_parameter
class DOFWorkspace(ConnectorWorkspace):
def __init__(self, owner, sim, refill):
super().__init__(owner, sim, refill, refill, Connections(), Connections())
def __init__(self, owner, sim):
super().__init__(owner, sim, Connections(), Connections())
self.drives = None
self.amplitudes = None
......@@ -112,7 +112,7 @@ class DegreeOfFreedom(Connector):
def _get_workspace(self, sim):
if sim.signal:
ws = DOFWorkspace(self, sim, False)
ws = DOFWorkspace(self, sim)
ws.signal.add_fill_function(self.__fill, False)
ws.drives = self.drives
ws.amplitudes = np.array(self.amplitudes)
......
......@@ -38,7 +38,7 @@ class ZPKNodeActuator(Connector):
refill = sim.model.fsig.f.is_changing or any(
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill, refill)
ws = FilterWorkspace(self, sim)
ws.signal.add_fill_function(self.fill, refill)
ws.frequencies = sim.electrical_frequencies[self.p1.i].frequencies
return ws
......@@ -76,7 +76,7 @@ class Amplifier(Connector):
refill = sim.model.fsig.f.is_changing or any(
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill, refill)
ws = FilterWorkspace(self, sim)
ws.signal.add_fill_function(self.fill, refill)
ws.frequencies = sim.signal.electrical_frequencies[self.p1.i].frequencies
return ws
......@@ -114,7 +114,7 @@ class Filter(Connector):
refill = sim.model.fsig.f.is_changing or any(
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill, refill)
ws = FilterWorkspace(self, sim)
ws.signal.add_fill_function(self.fill, refill)
ws.frequencies = sim.signal.electrical_frequencies[self.p1.i].frequencies
return ws
......@@ -131,8 +131,7 @@ class Filter(Connector):
mat[:] = Hz
def bode_plot(self, f=None, n=None, return_axes=False):
"""
Plots Bode for this filter.
"""Plots Bode for this filter.
Parameters
----------
......@@ -174,18 +173,21 @@ class ZPKFilter(Filter):
def __init__(self, name, z, p, k, *, fQ=False, gain=1):
super().__init__(name, gain)
import cmath
root = lambda f, Q: -2*np.pi*f/(2*Q) + cmath.sqrt((2*np.pi*f/(2*Q))**2 - (2*np.pi*f)**2)
root = lambda f, Q: -2 * np.pi * f / (2 * Q) + cmath.sqrt(
(2 * np.pi * f / (2 * Q)) ** 2 - (2 * np.pi * f) ** 2
)
if fQ:
self.z = []
for f,Q in z:
r = root(f,Q)
for f, Q in z:
r = root(f, Q)
self.z.append(r)
self.z.append(r.conjugate())
self.p = []
for f,Q in p:
r = root(f,Q)
for f, Q in p:
r = root(f, Q)
self.p.append(r)
self.p.append(r.conjugate())
else:
......@@ -199,6 +201,7 @@ class ZPKFilter(Filter):
def eval(self, f):
import scipy.signal as signal
return (
float(self.gain)
* signal.freqs_zpk(self.z, self.p, float(self.k), 2 * np.pi * f)[1]
......@@ -208,7 +211,7 @@ class ZPKFilter(Filter):
@float_parameter("gain", "Gain")
class ButterFilter(ZPKFilter):
def __init__(self, name, order, btype, frequency, *, gain=1, analog=True):
super().__init__(name, [],[],[], gain=gain)
super().__init__(name, [], [], [], gain=gain)
self.__order = order
self.__btype = btype
self.__analog = analog
......@@ -217,7 +220,8 @@ class ButterFilter(ZPKFilter):
def set_zpk(self):
import scipy.signal as signal
z,p,k = signal.butter(
z, p, k = signal.butter(
self.order,
2 * np.pi * np.array(self.frequency),
btype=self.btype,
......@@ -265,7 +269,6 @@ class ButterFilter(ZPKFilter):
self.set_zpk()
@float_parameter("gain", "Gain")
class Cheby1Filter(ZPKFilter):
def __init__(self, name, order, rp, btype, frequency, *, gain=1, analog=True):
......
"""
Optical components performing directional suppression of beams.
"""
"""Optical components performing directional suppression of beams."""
import logging
import numpy as np
from finesse.components.modal.isolator import IsolatorWorkspace
from finesse.components.general import Connector, InteractionType
from finesse.components.node import NodeDirection, NodeType
from finesse.parameter import float_parameter
......@@ -56,10 +53,12 @@ class Isolator(Connector):
)
def _get_workspace(self, sim):
from finesse.components.modal.isolator import IsolatorWorkspace
_, is_changing = self._eval_parameters()
refill = sim.is_component_in_mismatch_couplings(self) or len(is_changing)
ws = IsolatorWorkspace(self, sim, refill)
ws = IsolatorWorkspace(self, sim)
# This assumes that nr1/nr2 cannot change during a simulation
ws.nr1 = refractive_index(self.p1)
ws.nr2 = refractive_index(self.p2)
......
......@@ -176,7 +176,7 @@ class Laser(Connector, FrequencyGenerator):
laser_set_gouy,
)
ws = LaserWorkspace(self, sim, True)
ws = LaserWorkspace(self, sim)
ws.node_car_id = sim.carrier.node_id(self.p1.o)
ws.fsrc_car_idx = -1
......
"""
Transmissive optical components which focus or disperse light beams.
"""
"""Transmissive optical components which focus or disperse light beams."""
import logging
import numpy as np
from finesse.components.modal.lens import LensWorkspace
from finesse.components.general import Connector, InteractionType
from finesse.components.node import NodeDirection, NodeType
from finesse.parameter import float_parameter
......@@ -16,11 +13,7 @@ LOGGER = logging.getLogger(__name__)
@float_parameter(
"f",
"Focal length",
validate="_check_f",
units="m",
is_geometric=True,
"f", "Focal length", validate="_check_f", units="m", is_geometric=True,
)
class Lens(Connector):
"""Represents a thin lens optical component with an associated focal length.
......@@ -189,10 +182,12 @@ class Lens(Connector):
from finesse.simulations.basematrix import CarrierSignalMatrixSimulation
if isinstance(sim, CarrierSignalMatrixSimulation):
from finesse.components.modal.lens import LensWorkspace
_, is_changing = self._eval_parameters()
refill = sim.is_component_in_mismatch_couplings(self) or len(is_changing)
ws = LensWorkspace(self, sim, refill)
ws = LensWorkspace(self, sim)
# This assumes that nr1/nr2 cannot change during a simulation
ws.nr1 = refractive_index(self.p1)
ws.nr2 = refractive_index(self.p2)
......
......@@ -223,7 +223,7 @@ class LIGOQuadSuspension(Connector):
N += 1
if N > 0:
ws = MIMOSSWorkspace(self, sim, refill, refill)
ws = MIMOSSWorkspace(self, sim)
ws.signal.add_fill_function(self._signal_fill, refill)
ws.N = N
ws.iselect = tuple(set(idxs))
......
......@@ -49,7 +49,7 @@ cdef class MIMOTFWorkspace(ConnectorWorkspace):
complex_t curr_denom
complex_t s
def __cinit__(self, owner, sim, refill, unsigned int N_numerators):
def __cinit__(self, owner, sim, unsigned int N_numerators):
self.N_num_allocd = N_numerators
self.numerators = <double**>calloc(N_numerators, sizeof(double*))
if not self.numerators:
......@@ -64,8 +64,6 @@ cdef class MIMOTFWorkspace(ConnectorWorkspace):
super().__init__(
owner,
sim,
refill,
refill,
Connections(),
Connections()
)
......@@ -319,7 +317,7 @@ class FreeMass(Connector):
def _get_workspace(self, sim):
if sim.signal:
refill = sim.model.fsig.f.is_changing or any(p.is_changing for p in self.parameters)
ws = FreeMassWorkspace(self, sim, refill, refill)
ws = FreeMassWorkspace(self, sim)
ws.signal.add_fill_function(self.fill, refill)
return ws
else:
......@@ -405,7 +403,7 @@ class Pendulum(Connector):
def _get_workspace(self, sim):
if sim.signal:
refill = sim.model.fsig.f.is_changing or any(p.is_changing for p in self.parameters)
ws = PendulumMassWorkspace(self, sim, refill, refill)
ws = PendulumMassWorkspace(self, sim)
ws.signal.add_fill_function(self.fill, refill)
return ws
else:
......
......@@ -349,6 +349,7 @@ class Mirror(Surface):
return super().ABCD(from_node, to_node, direction, symbolic, copy, retboth)
def _get_workspace(self, sim):
"""Returns a workspace to use in a simulation."""
from finesse.simulations.basematrix import CarrierSignalMatrixSimulation
if isinstance(sim, CarrierSignalMatrixSimulation):
......@@ -370,7 +371,7 @@ class Mirror(Surface):
or len(is_changing)
)
ws = MirrorWorkspace(self, sim, refill)
ws = MirrorWorkspace(self, sim)
# This assumes that nr1/nr2 cannot change during a simulation
ws.nr1 = refractive_index(self.p1)
ws.nr2 = refractive_index(self.p2)
......
#cython: boundscheck=False, wraparound=False, initializedcheck=False
#cython: boundscheck=False, wraparound=False, initializedcheck=False, profile=True
cimport numpy as np
import numpy as np
......@@ -152,14 +152,12 @@ cdef class BeamsplitterValues(BaseCValues):
self.setup(params, sizeof(ptr), <double**>&ptr)
cdef class BeamsplitterWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, CarrierSignalMatrixSimulation sim, refill):
def __init__(self, owner, CarrierSignalMatrixSimulation sim):
cdef FrequencyContainer fcnt
super().__init__(
owner,
sim,
refill,
refill,
BeamsplitterOpticalConnections(owner, sim.carrier),
BeamsplitterSignalConnections(owner, sim.signal) if sim.signal else None,
BeamsplitterValues()
......@@ -358,22 +356,22 @@ cdef inline void beamsplitter_fill_optical_2_optical(
# reflections
if conn.P1i_P2o[freq.index]:
(<SubCCSView>conn.P1i_P2o[freq.index]).fill_negative_za_zm_2(_r1, ws.K12.mtx.ptr, ws.K12.mtx.stride1, ws.K12.mtx.stride2)
(<SubCCSView>conn.P1i_P2o[freq.index]).fill_negative_za_zm_2(_r1, &ws.K12.mtx)
if conn.P2i_P1o[freq.index]:
(<SubCCSView>conn.P2i_P1o[freq.index]).fill_negative_za_zm_2(_r1, ws.K21.mtx.ptr, ws.K21.mtx.stride1, ws.K21.mtx.stride2)
(<SubCCSView>conn.P2i_P1o[freq.index]).fill_negative_za_zm_2(_r1, &ws.K21.mtx)
if conn.P3i_P4o[freq.index]:
(<SubCCSView>conn.P3i_P4o[freq.index]).fill_negative_za_zm_2(_r2, ws.K34.mtx.ptr, ws.K34.mtx.stride1, ws.K34.mtx.stride2)
(<SubCCSView>conn.P3i_P4o[freq.index]).fill_negative_za_zm_2(_r2, &ws.K34.mtx)
if conn.P4i_P3o[freq.index]:
(<SubCCSView>conn.P4i_P3o[freq.index]).fill_negative_za_zm_2(_r2, ws.K43.mtx.ptr, ws.K43.mtx.stride1, ws.K43.mtx.stride2)
(<SubCCSView>conn.P4i_P3o[freq.index]).fill_negative_za_zm_2(_r2, &ws.K43.mtx)
# transmissions
if conn.P1i_P3o[freq.index]:
(<SubCCSView>conn.P1i_P3o[freq.index]).fill_negative_za_zm_2(_t0, ws.K13.mtx.ptr, ws.K13.mtx.stride1, ws.K13.mtx.stride2)
(<SubCCSView>conn.P1i_P3o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K13.mtx)
if conn.P3i_P1o[freq.index]:
(<SubCCSView>conn.P3i_P1o[freq.index]).fill_negative_za_zm_2(_t0, ws.K31.mtx.ptr, ws.K31.mtx.stride1, ws.K31.mtx.stride2)
(<SubCCSView>conn.P3i_P1o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K31.mtx)
if conn.P2i_P4o[freq.index]:
(<SubCCSView>conn.P2i_P4o[freq.index]).fill_negative_za_zm_2(_t0, ws.K24.mtx.ptr, ws.K24.mtx.stride1, ws.K24.mtx.stride2)
(<SubCCSView>conn.P2i_P4o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K24.mtx)
if conn.P4i_P2o[freq.index]:
(<SubCCSView>conn.P4i_P2o[freq.index]).fill_negative_za_zm_2(_t0, ws.K42.mtx.ptr, ws.K42.mtx.stride1, ws.K42.mtx.stride2)
(<SubCCSView>conn.P4i_P2o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K42.mtx)
beamsplitter_carrier_fill = FillFuncWrapper.make_from_ptr(c_beamsplitter_carrier_fill)
......
......@@ -33,12 +33,10 @@ cdef class IsolatorConnections:
cdef class IsolatorWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, CarrierSignalMatrixSimulation sim, bint refill):
def __init__(self, owner, CarrierSignalMatrixSimulation sim):
super().__init__(
owner,
sim,
refill,
refill,
IsolatorConnections(sim.carrier),
IsolatorConnections(sim.signal),
IsolatorValues()
......
......@@ -59,12 +59,10 @@ cdef class LaserValues(BaseCValues):
cdef class LaserWorkspace(ConnectorWorkspace):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim, bint refill):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim):
super().__init__(
owner,
sim,
refill,
refill,
None,
LaserConnections(sim.signal) if sim.signal else None,
LaserValues()
......
......@@ -36,12 +36,10 @@ cdef class LensConnections:
cdef class LensWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, CarrierSignalMatrixSimulation sim, refill):
def __init__(self, owner, CarrierSignalMatrixSimulation sim):
super().__init__(
owner,
sim,
refill,
refill,
LensConnections(sim),
None,
LensValues()
......
#cython: boundscheck=False, wraparound=False, initializedcheck=False
# cython: boundscheck=False, wraparound=False, initializedcheck=False, profile=True
cimport cython
cimport numpy as np
......@@ -109,13 +108,11 @@ cdef class MirrorSignalConnections(MirrorOpticalConnections):
cdef class MirrorWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, CarrierSignalMatrixSimulation sim, refill):
def __init__(self, owner, CarrierSignalMatrixSimulation sim):
cdef FrequencyContainer fcnt
super().__init__(
owner,
sim,
refill,
refill,
MirrorOpticalConnections(owner, sim.carrier),
MirrorSignalConnections(owner, sim.signal) if sim.signal else None,
MirrorValues()
......@@ -248,22 +245,14 @@ cdef inline void mirror_fill_optical_2_optical(
# Reflections
if conn.P1i_P1o[freq.index]:
(<SubCCSView>conn.P1i_P1o[freq.index]).fill_negative_za_zm_2(
_r1, ws.K11.mtx.ptr, ws.K11.mtx.stride1, ws.K11.mtx.stride2
)
(<SubCCSView>conn.P1i_P1o[freq.index]).fill_negative_za_zm_2(_r1, &ws.K11.mtx)
if conn.P2i_P2o[freq.index]:
(<SubCCSView>conn.P2i_P2o[freq.index]).fill_negative_za_zm_2(
_r2, ws.K22.mtx.ptr, ws.K22.mtx.stride1, ws.K22.mtx.stride2
)
(<SubCCSView>conn.P2i_P2o[freq.index]).fill_negative_za_zm_2(_r2, &ws.K22.mtx)
# Transmission
if conn.P1i_P2o[freq.index]:
(<SubCCSView>conn.P1i_P2o[freq.index]).fill_negative_za_zm_2(
_t0, ws.K12.mtx.ptr, ws.K12.mtx.stride1, ws.K12.mtx.stride2
)
(<SubCCSView>conn.P1i_P2o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K12.mtx)
if conn.P2i_P1o[freq.index]:
(<SubCCSView>conn.P2i_P1o[freq.index]).fill_negative_za_zm_2(
_t0, ws.K21.mtx.ptr, ws.K21.mtx.stride1, ws.K21.mtx.stride2
)
(<SubCCSView>conn.P2i_P1o[freq.index]).fill_negative_za_zm_2(_t0, &ws.K21.mtx)
mirror_carrier_fill = FillFuncWrapper.make_from_ptr(c_mirror_carrier_fill)
......
......@@ -101,10 +101,10 @@ cdef void set_coupling_orders(ndarray orders, int set_order, double f, mtx, modu
cdef class ModulatorWorkspace(KnmConnectorWorkspace):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim, bint refill):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim):
cdef Py_ssize_t i
super().__init__(owner,
sim, refill, refill,
sim,
ModulatorOpticalConnections(sim.carrier),
ModulatorSignalConnections(sim.signal) if sim.signal else None,
ModulatorValues()
......
......@@ -26,12 +26,10 @@ cdef class OpticalBandpassConnections:
cdef class OpticalBandpassWorkspace(KnmConnectorWorkspace):
def __init__(self, owner, CarrierSignalMatrixSimulation sim, bint refill):
def __init__(self, owner, CarrierSignalMatrixSimulation sim):
super().__init__(
owner,
sim,
refill,
refill,
OpticalBandpassConnections(owner, sim.carrier),
OpticalBandpassConnections(owner, sim.signal) if sim.signal else None,
OpticalBandpassValues()
......@@ -59,12 +57,12 @@ cdef void fill_optical_matrix(
H = 1 / (1 + 1j*(2*np.pi*abs(frequencies[i].f-ws.cvalues.fc))/B)
if connections.P1i_P2o:
(<SubCCSView>connections.P1i_P2o[frequencies[i].index]).fill_negative_za_zm_2(
H, ws.K12.mtx.ptr, ws.K12.mtx.stride1, ws.K12.mtx.stride2
H, &ws.K12.mtx
)
if connections.P2i_P1o:
(<SubCCSView>connections.P2i_P1o[frequencies[i].index]).fill_negative_za_zm_2(
H, ws.K21.mtx.ptr, ws.K21.mtx.stride1, ws.K21.mtx.stride2
H, &ws.K21.mtx
)
......@@ -82,4 +80,4 @@ cdef object c_fill_signal(ConnectorWorkspace ws):
ws,
ws.sim.signal,
&(<OpticalBandpassWorkspace>ws).signal_opt_conns.ptrs
)
\ No newline at end of file
)
......@@ -17,12 +17,10 @@ cdef class SignalGeneratorValues(BaseCValues):
cdef class SignalGeneratorWorkspace(ConnectorWorkspace):
def __init__(self, owner, sim, refill):
def __init__(self, owner, sim):
super().__init__(
owner,
sim,
refill,
refill,
Connections(),
Connections(),
SignalGeneratorValues()
......
# cython: profile=True
from finesse.cymath cimport complex_t
from finesse.cymath.complex cimport conj, cexp, ceq, creal, cimag, cabs
from finesse.cymath.math cimport fabs, radians, degrees
......@@ -73,9 +75,9 @@ cdef class SpaceValues(BaseCValues):
cdef class SpaceWorkspace(ConnectorWorkspace):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim, bint refill):
def __init__(self, object owner, CarrierSignalMatrixSimulation sim):
super().__init__(
owner, sim, refill, refill,
owner, sim,
SpaceOpticalConnections(sim.carrier),
SpaceSignalConnections(sim.signal) if sim.signal else None,
SpaceValues()
......
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