Commit 0e7fbccf authored by Daniel Brown's avatar Daniel Brown
Browse files

refactor fill function name

parent e6fc56d2
......@@ -54,7 +54,7 @@ class MicroResonator(Connector):
or self.Q.is_changing
)
ws = MicroResonatorWorkspace(self, sim, refill)
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
ws.Fz_frequencies = sim.mechanical_frequencies[self.mech.F_z]
ws.z_frequencies = sim.mechanical_frequencies[self.mech.z]
return ws
......
......@@ -604,7 +604,7 @@ class Beamsplitter(Surface):
ws.nr1 = refractive_index(self.p1) or refractive_index(self.p2) or 1
ws.nr2 = refractive_index(self.p3) or refractive_index(self.p4) or 1
ws.set_fill_fn(beamsplitter_fill)
ws.set_fill_function(beamsplitter_fill)
# Initialise the ABCD matrix memory-views
if sim.is_modal:
......
......@@ -76,7 +76,7 @@ class DirectionalBeamsplitter(Connector):
def _get_workspace(self, sim):
ws = DBSWorkspace(self, sim, False)
ws.I = np.eye(sim.nhoms, dtype=np.complex128)
ws.set_fill_fn(self._fill_matrix)
ws.set_fill_function(self._fill_matrix)
return ws
def _fill_matrix(self, ws):
......
......@@ -74,7 +74,7 @@ class DegreeOfFreedom(Connector):
def _get_workspace(self, sim):
if sim.is_audio:
ws = DOFWorkspace(self, sim, False)
ws.set_fill_fn(self.__fill)
ws.set_fill_function(self.__fill)
ws.drives = self.drives
ws.amplitudes = self.amplitudes
return ws
......
......@@ -39,7 +39,7 @@ class ZPKNodeActuator(Connector):
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill)
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
ws.frequencies = sim.electrical_frequencies[self.p1.i].frequencies
return ws
else:
......@@ -74,7 +74,7 @@ class Amplifier(Connector):
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill)
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
ws.frequencies = sim.electrical_frequencies[self.p1.i].frequencies
return ws
else:
......@@ -111,7 +111,7 @@ class Filter(Connector):
p.is_changing for p in self.parameters
)
ws = FilterWorkspace(self, sim, refill)
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
ws.frequencies = sim.electrical_frequencies[self.p1.i].frequencies
return ws
else:
......
......@@ -66,7 +66,7 @@ class Isolator(Connector):
ws.nr1 = refractive_index(self.p1) or 1
ws.nr2 = refractive_index(self.p2) or 1
ws.set_fill_fn(self._fill_matrix)
ws.set_fill_function(self._fill_matrix)
return ws
def _fill_matrix(self, ws):
......
......@@ -131,7 +131,7 @@ class Laser(Connector, FrequencyGenerator):
ws.node_sig_id = sim.signal.node_id(self.p1.o)
# Audio sim requies matrix filling
# for signal couplings
ws.signal.set_fill_fn(laser_fill_signal)
ws.signal.set_fill_function(laser_fill_signal)
# Find the sideband frequencies
sb = tuple(
(f for f in sim.frequencies if f.audio_carrier_index == fsrc.index)
......
......@@ -203,8 +203,8 @@ class Lens(Connector):
ws.nr1 = refractive_index(self.p1) or 1
ws.nr2 = refractive_index(self.p2) or 1
ws.carrier.set_fill_fn(self._fill_carrier)
ws.signal.set_fill_fn(self._fill_signal)
ws.carrier.set_fill_function(self._fill_carrier)
ws.signal.set_fill_function(self._fill_signal)
if sim.is_modal:
key = (self.p1.i, self.p2.o, "x")
......
......@@ -113,7 +113,7 @@ class LIGOTripleSuspension(Connector):
refill = sim.model.fsig.f.is_changing # Need to recompute H(f)
N = len(self._registered_connections)
ws = MIMOTFWorkspace(self, sim, refill, N)
ws.set_fill_fn(mimo_fill)
ws.set_fill_function(mimo_fill)
ws.set_denominator(self.tfs.den[0][0])
name_map = {n.port.name: "tst" for n in self.tst.nodes}
......
......@@ -285,7 +285,7 @@ class FreeMass(Connector):
if sim.is_audio:
refill = sim.model.fsig.f.is_changing or any(p.is_changing for p in self.parameters)
ws = FreeMassWorkspace(self, sim, refill)
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
return ws
else:
return None
......
......@@ -353,8 +353,8 @@ class Mirror(Surface):
ws.nr1 = refractive_index(self.p1) or 1
ws.nr2 = refractive_index(self.p2) or 1
ws.carrier.set_fill_fn(mirror_carrier_fill)
ws.signal.set_fill_fn(mirror_signal_fill)
ws.carrier.set_fill_function(mirror_carrier_fill)
ws.signal.set_fill_function(mirror_signal_fill)
# Initialise the ABCD matrix memory-views
if sim.is_modal:
......
#cython: profile=True, boundscheck=False, wraparound=False, initializedcheck=False
from finesse.cymath cimport complex_t
from finesse.simulations.base cimport BaseSimulation, NodeBeamParam
from finesse.simulations.base cimport NodeBeamParam
from finesse.cmatrix cimport SubCCSView1DArray
from finesse.knm cimport (
KnmMatrix,
......
......@@ -4,7 +4,7 @@ from finesse.cmatrix cimport SubCCSView1DArray
from finesse.knm cimport KnmMatrix, KnmWorkspace
from finesse.components.workspace cimport ConnectorWorkspace
from finesse.element cimport BaseCValues
from finesse.simulations.base cimport BaseSimulation
from finesse.simulations.basematrix cimport CarrierSignalMatrixSimulation
from finesse.components.modal.workspace cimport KnmConnectorWorkspace
from finesse.cyexpr cimport (
......
from finesse.frequency cimport frequency_info_t
from finesse.cmatrix cimport SubCCSView, SubCCSView1DArray, SubCCSView2DArray
from finesse.knm cimport KnmMatrix, KnmWorkspace
from finesse.cymath cimport complex_t
from finesse.simulations.base cimport ModelData, NodeBeamParam
from finesse.frequency cimport frequency_info_t
from finesse.element cimport BaseCValues
from finesse.components.workspace cimport ConnectorWorkspace, FillFuncWrapper
from finesse.components.modal.workspace cimport KnmConnectorWorkspace
......@@ -79,7 +79,6 @@ cdef class MirrorWorkspace(KnmConnectorWorkspace):
cdef public:
complex_t field_to_Fz
complex_t z_to_field
int audio_fill_mode
# Complete scattering matrices for each propagation direction
KnmMatrix K11
......
......@@ -26,7 +26,7 @@ from finesse.knm cimport (
)
from finesse.cmatrix cimport SubCCSView, SubCCSView1DArray
from finesse.symbols import Symbol
from finesse.simulations.basematrix cimport CarrierSignalMatrixSimulation
from finesse.simulations.basematrix cimport MatrixSystemSolver, CarrierSignalMatrixSimulation
from cpython.ref cimport PyObject, Py_XINCREF, Py_XDECREF
from libc.string cimport strcmp, memcpy
......@@ -54,12 +54,11 @@ cdef class MirrorValues(BaseCValues):
cdef class MirrorOpticalConnections:
"""Contains C accessible references to submatrices for
optical connections for this element. Should be accessed
when performing carrier simulations.
optical connections for this element.
"""
def __cinit__(self, object mirror, CarrierSignalMatrixSimulation sim):
def __cinit__(self, object mirror, MatrixSystemSolver mtx):
# Only 1D arrays of submatrices as no frequency coupling happening
cdef int Nf = sim.carrier.optical_frequencies.size
cdef int Nf = mtx.optical_frequencies.size
self.P1i_P1o = SubCCSView1DArray(Nf)
self.P2i_P2o = SubCCSView1DArray(Nf)
......@@ -74,24 +73,20 @@ cdef class MirrorOpticalConnections:
cdef class MirrorSignalConnections(MirrorOpticalConnections):
"""Contains C accessible references to submatrices for
optical, electrical, and mechanical connections for this
element. Should be accessed when performing signal
simulations.
element.
"""
def __cinit__(self, object mirror, CarrierSignalMatrixSimulation sim):
def __cinit__(self, object mirror, MatrixSystemSolver mtx):
cdef:
int Nfo = sim.signal.optical_frequencies.size
int Nmz1 = sim.signal.mechanical_frequencies.size
int Nmz2 = sim.signal.mechanical_frequencies.size
assert(sim.signal is not None)
super().__cinit__(mirror, sim)
int Nfo = mtx.optical_frequencies.size
super().__cinit__(mirror, mtx)
Nmz = mirror.mech.z.num_frequencies # num of mechanic frequencies
self.P1i_Fz = SubCCSView2DArray(Nfo, Nmz1)
self.P1o_Fz = SubCCSView2DArray(Nfo, Nmz1)
self.P2i_Fz = SubCCSView2DArray(Nfo, Nmz2)
self.P2o_Fz = SubCCSView2DArray(Nfo, Nmz2)
self.Z_P1o = SubCCSView2DArray(Nmz1, Nfo)
self.Z_P2o = SubCCSView2DArray(Nmz2, Nfo)
self.P1i_Fz = SubCCSView2DArray(Nfo, Nmz)
self.P1o_Fz = SubCCSView2DArray(Nfo, Nmz)
self.P2i_Fz = SubCCSView2DArray(Nfo, Nmz)
self.P2o_Fz = SubCCSView2DArray(Nfo, Nmz)
self.Z_P1o = SubCCSView2DArray(Nmz, Nfo)
self.Z_P2o = SubCCSView2DArray(Nmz, Nfo)
self.sig_conn_ptrs.P1i_Fz = <PyObject***>self.P1i_Fz.views
self.sig_conn_ptrs.P2i_Fz = <PyObject***>self.P2i_Fz.views
......@@ -109,8 +104,8 @@ cdef class MirrorWorkspace(KnmConnectorWorkspace):
owner,
sim,
refill,
MirrorOpticalConnections(owner, sim),
MirrorSignalConnections(owner, sim) if sim.signal else None,
MirrorOpticalConnections(owner, sim.carrier),
MirrorSignalConnections(owner, sim.signal) if sim.signal else None,
MirrorValues()
)
......@@ -660,7 +655,7 @@ cdef void single_z_mechanical_frequency_signal_calc (
#
# phase_shift = phi * (1 + car.f / f0) + phi * (1 + freq.f/f0)
# = phi * (2 + (order*fsig + freq.f) / f0)
phase_shift = phi * (2 + (freq.f + freq.f_car) / ws.sim.model_data.f0)
phase_shift = phi * (2 + (freq.f + freq.f_car[0]) / ws.sim.model_data.f0)
# -----------------------------------------------------------------
# Signal generation z->p1.o
......
......@@ -152,7 +152,7 @@ class Modulator(Connector, FrequencyGenerator):
ws.nr1 = refractive_index(self.p1) or 1
ws.nr2 = refractive_index(self.p2) or 1
ws.set_fill_fn(self._fill_matrix)
ws.set_fill_function(self._fill_matrix)
# TODO ddb : change this from a dict to an array, it should just be
# doing a direct frequency index lookup to a boolean or something
......
......@@ -61,8 +61,8 @@ class Nothing(Connector):
def _get_workspace(self, sim):
ws = NothingWorkspace(self, sim)
ws.I = np.eye(sim.model_data.num_HOMs, dtype=np.complex128)
ws.carrier.set_fill_fn(self._fill_carrier_matrix)
ws.signal.set_fill_fn(self._fill_signal_matrix)
ws.carrier.set_fill_function(self._fill_carrier_matrix)
ws.signal.set_fill_function(self._fill_signal_matrix)
return ws
def _fill_carrier_matrix(self, ws):
......
......@@ -48,7 +48,7 @@ class Photodiode(Connector):
if sim.is_audio:
ws = PhotodiodeWorkspace(self, sim, True)
ws.I = np.eye(sim.nhoms, dtype=np.complex128)
ws.set_fill_fn(self._fill_matrix)
ws.set_fill_function(self._fill_matrix)
ws.frequencies = sim.electrical_frequencies[self.DC.o].frequencies
return ws
else:
......@@ -97,7 +97,7 @@ class Photodiode1Demod(Connector):
def _get_workspace(self, sim):
if sim.is_audio:
ws = PhotodiodeWorkspace(self, sim, True)
ws.set_fill_fn(self._fill_matrix)
ws.set_fill_function(self._fill_matrix)
ws.frequencies = sim.electrical_frequencies[self.I.o].frequencies
ws.dc_node_id = sim.DC.node_id(self.p1.i)
return ws
......
......@@ -176,7 +176,7 @@ class Space(Connector):
ws = SpaceWorkspace(self, sim, refill)
# Set the fill function for this simulation
ws.carrier.set_fill_fn(space_carrier_fill)
ws.carrier.set_fill_function(space_carrier_fill)
ws.carrier.connection_settings["P1i_P2o"] = ConnectionSetting.DIAGONAL
ws.carrier.connection_settings["P2i_P1o"] = ConnectionSetting.DIAGONAL
......@@ -184,7 +184,7 @@ class Space(Connector):
if sim.signal:
refill |= sim.model.fsig.f.is_changing
refill |= sim.signal.any_frequencies_changing
ws.signal.set_fill_fn(space_signal_fill, refill)
ws.signal.set_fill_function(space_signal_fill, refill)
ws.signal.connection_settings["SIGPHS_P1o"] = ConnectionSetting.DIAGONAL
ws.signal.connection_settings["SIGPHS_P2o"] = ConnectionSetting.DIAGONAL
......
......@@ -125,7 +125,7 @@ class Wire(Connector):
ws = WireWorkspace(self, sim, refill)
ws.frequencies = sim.electrical_frequencies[self.p1.i].frequencies
# Set the fill function for this simulation
ws.set_fill_fn(self.fill)
ws.set_fill_function(self.fill)
return ws
else:
return None
......
......@@ -44,7 +44,7 @@ cdef class ConnectorMatrixSimulationInfo:
self.connections = connections or Connections()
self.connection_settings = {}
def set_fill_fn(self, callback):
def set_fill_function(self, callback):
""" This sets the callback function that will be used by the model to
fill the matrix elements. This can either be a Python function, which
accepts a
......
......@@ -56,6 +56,7 @@ cdef class KLUMatrixSystemSolver(MatrixSystemSolver):
def __init__(self, *args, **kwargs):
super().__init__(KLUMatrix, *args, **kwargs)
self.rcond_diff_lim = float(FinesseConfig()['klu']['rcond_diff_lim'])
cdef solve(self):
cdef double rcond = (<KLUMatrix>self._M).rcond()
......@@ -87,8 +88,6 @@ cdef class KLUMatrixSystemSolver(MatrixSystemSolver):
self.out_view = self._M.rhs_view
cdef initial_run(self):
self.rcond_diff_lim = float(FinesseConfig()['klu']['rcond_diff_lim'])
self.initial_fill()
self._M.factor()
self.prev_rcond = self._M.rcond()
......
......@@ -33,145 +33,145 @@ cdef class ModelData:
bint zero_tem00_gouy # should Gouy phase of TEM00 be zeroed
cdef class BaseSimulation:
"""
Base Simulation class for executing a model.
The `Simulation` class uses the :class:`.Model` to build
and fill the sparse matrix and is used as a reference for
detectors to compute outputs to return to the user.
.. note::
Instances of this class **cannot** be copied, they are generated
from and operate on a :class:`.Model` object in a particular
built state.
.. note::
The module :mod:`pickle` **cannot** be used on instances of this class.
"""
cdef:
readonly unicode name
readonly object model
readonly bint is_matrix_sim
readonly bint is_audio
readonly bint is_modal
readonly bint any_frequencies_changing
# cdef class BaseSimulation:
# """
# Base Simulation class for executing a model.
# The `Simulation` class uses the :class:`.Model` to build
# and fill the sparse matrix and is used as a reference for
# detectors to compute outputs to return to the user.
# .. note::
# Instances of this class **cannot** be copied, they are generated
# from and operate on a :class:`.Model` object in a particular
# built state.
# .. note::
# The module :mod:`pickle` **cannot** be used on instances of this class.
# """
# cdef:
# readonly unicode name
# readonly object model
# readonly bint is_matrix_sim
# readonly bint is_audio
# readonly bint is_modal
# readonly bint any_frequencies_changing
# Optical frequencies
# TODO ddb - refactor to optical_frequencies at some point
np.ndarray _input_frequencies
readonly frequency_info_t[:] frequency_info
readonly tuple frequencies
readonly int num_frequencies
readonly tuple unique_fcnt # Unique frequency containers for mech/elec
# # Optical frequencies
# # TODO ddb - refactor to optical_frequencies at some point
# np.ndarray _input_frequencies
# readonly frequency_info_t[:] frequency_info
# readonly tuple frequencies
# readonly int num_frequencies
# readonly tuple unique_fcnt # Unique frequency containers for mech/elec
readonly dict mechanical_frequencies
readonly dict electrical_frequencies
# readonly dict mechanical_frequencies
# readonly dict electrical_frequencies
# mode indices only ever need to be indexed or iterated over
# so make it a readonly memoryview on the models' homs array
readonly int[:, ::1] homs_view
readonly int nhoms
# the beam trace results
NodeBeamParam* trace
# forest of changing trace trees
readonly TraceForest trace_forest
# flag indicating whether to retrace (true means
# determined automatically by TraceForest code)
bint retrace
bint manual_rhs # If true run call won't clear/fill rhs
public dict _submatrices
Py_ssize_t num_nodes
readonly dict nodes
readonly dict nodes_idx
NodeInfoEntry* _c_node_info
#public np.ndarray out
const complex_t[::1] out_view
public list _edge_owners
public list workspaces
public list variable_workspaces
list to_initial_fill
list to_refill
PyObject** ptr_to_refill
int num_to_refill
list to_rhs_fill
list to_rhs_refill
PyObject** ptr_to_rhs_refill
int num_to_rhs_refill
public dict cavity_workspaces
# List of workspaces for components which scatter modes
list to_scatter_matrix_compute
readonly ModelData model_data
public BaseSimulation DC
object __weakref__
cdef _initialise_submatrices(self)
cpdef get_node_info(self, name)
cpdef Py_ssize_t findex(self, object node, Py_ssize_t freq)
cdef Py_ssize_t findex_fast(self, Py_ssize_t node_id, Py_ssize_t freq) nogil
cpdef Py_ssize_t field(self, object node, Py_ssize_t freq=?, Py_ssize_t hom=?)
cdef Py_ssize_t field_fast(self, Py_ssize_t node_id, Py_ssize_t freq=?, Py_ssize_t hom=?) nogil
cdef inline Py_ssize_t field_fast_2(
self,
Py_ssize_t node_rhs_idx,
Py_ssize_t num_hom,
Py_ssize_t freq,
Py_ssize_t hom) nogil
cpdef complex_t get_DC_out(self, object node, Py_ssize_t freq=?, Py_ssize_t hom=?)
cdef complex_t get_DC_out_fast(self, Py_ssize_t node_id, Py_ssize_t freq=?, Py_ssize_t hom=?) nogil
cpdef Py_ssize_t node_id(self, object node)
cpdef int modal_update(self) except -1
cpdef component_edge_get(self, object comp, unicode edgestr, object f1, object f2)
cdef solve(self)
cdef _clear_rhs(self)
cdef initial_fill(self)
cdef refill(self)
cdef fill_rhs(self)
cdef void update_all_parameter_values(self)
cdef void update_cavities(self)
cdef void compute_knm_matrices(self)
cdef int set_gouy_phases(self) except -1
cpdef int run(self) except -1
cpdef _initialise_frequencies(self)
cdef void _determine_changing_beam_params(self)
# TODO (sjr) Would prefer to have the below methods in finesse.tracing.ctracer
# (see commented out blocks there) but circular import nonsense
# prevents that right now
cdef void _setup_trace_forest(self)
cdef void _setup_single_trace_tree(self, TraceTree tree)
cdef void _propagate_trace(self, TraceTree tree)
cdef bint trace_beam(self)
# # mode indices only ever need to be indexed or iterated over
# # so make it a readonly memoryview on the models' homs array
# readonly int[:, ::1] homs_view
# readonly int nhoms
# # the beam trace results
# NodeBeamParam* trace
# # forest of changing trace trees
# readonly TraceForest trace_forest
# # flag indicating whether to retrace (true means
# # determined automatically by TraceForest code)
# bint retrace
# bint manual_rhs # If true run call won't clear/fill rhs
# public dict _submatrices
# Py_ssize_t num_nodes
# readonly dict nodes
# readonly dict nodes_idx
# NodeInfoEntry* _c_node_info
# #public np.ndarray out
# const complex_t[::1] out_view
# public list _edge_owners
# public list workspaces
# public list variable_workspaces
# list to_initial_fill
# list to_refill
# PyObject** ptr_to_refill
# int num_to_refill
# list to_rhs_fill
# list to_rhs_refill
# PyObject** ptr_to_rhs_refill
# int num_to_rhs_refill
# public dict cavity_workspaces
# # List of workspaces for components which scatter modes
# list to_scatter_matrix_compute
# readonly ModelData model_data
# public BaseSimulation DC
# object __weakref__
# cdef _initialise_submatrices(self)
# cpdef get_node_info(self, name)
# cpdef Py_ssize_t findex(self, object node, Py_ssize_t freq)
# cdef Py_ssize_t findex_fast(self, Py_ssize_t node_id, Py_ssize_t freq) nogil
# cpdef Py_ssize_t field(self, object node, Py_ssize_t freq=?, Py_ssize_t hom=?)
# cdef Py_ssize_t field_fast(self, Py_ssize_t node_id, Py_ssize_t freq=?, Py_ssize_t hom=?) nogil
# cdef inline Py_ssize_t field_fast_2(
# self,
# Py_ssize_t node_rhs_idx,
# Py_ssize_t num_hom,
# Py_ssize_t freq,
# Py_ssize_t hom) nogil
# cpdef complex_t get_DC_out(self, object node, Py_ssize_t freq=?, Py_ssize_t hom=?)
# cdef complex_t get_DC_out_fast(self, Py_ssize_t node_id, Py_ssize_t freq=?, Py_ssize_t hom=?) nogil
# cpdef Py_ssize_t node_id(self, object node)
# cpdef int modal_update(self) except -1
# cpdef component_edge_get(self, object comp, unicode edgestr, object f1, object f2)
# cdef solve(self)
# cdef _clear_rhs(self)
# cdef initial_fill(self)
# cdef refill(self)
# cdef fill_rhs(self)
# cdef void update_all_parameter_values(self)
# cdef void update_cavities(self)
# cdef void compute_knm_matrices(self)
# cdef int set_gouy_phases(self) except -1
# cpdef int run(self) except -1