Commit 2853ed35 authored by Samuel Rowlinson's avatar Samuel Rowlinson
Browse files

Refs #368 --- applying refractive index correctly to Cavity class eigenmode values

The BeamParam instances created in Cavity.qx and Cavity.qy were incorrectly assuming
that the source node of the cavity was associated with nr=1. This is updated to use
the correct refractive index linked with the source node.

Additionally a added generate_abcd_str method to Cavity class. This gives a string
representation of the operation used to perform the round-trip matrices of the cavity.
Useful for debugging purposes.
parent b91b8a19
Pipeline #240951 passed with stages
in 62 minutes and 43 seconds
......@@ -16,6 +16,7 @@ from finesse.cymath.math import sgn
from finesse.constants import values as constants
from finesse.parameter import info_parameter
from finesse.gaussian import BeamParam
from finesse.utilities.components import refractive_index
from .trace_dependency import TraceDependency
......@@ -414,7 +415,8 @@ class Cavity(TraceDependency):
if q is None:
return None
return BeamParam(q=q, wavelength=self.__get_lambda0())
nr = refractive_index(self.source)
return BeamParam(q=q * nr, wavelength=self.__get_lambda0(), nr=nr)
@property
def qy(self):
......@@ -430,7 +432,8 @@ class Cavity(TraceDependency):
if q is None:
return None
return BeamParam(q=q, wavelength=self.__get_lambda0())
nr = refractive_index(self.source)
return BeamParam(q=q * nr, wavelength=self.__get_lambda0(), nr=nr)
@property
def w0(self):
......@@ -1104,6 +1107,29 @@ class Cavity(TraceDependency):
return BeamTraceSolution(f"{self.name}_trace", trace, [self.__tree])
def generate_abcd_str(self):
"""Generates a string representation of the cavity round-trip ABCD matrix
operations.
This can be useful for debugging purposes as the returned string will
correspond exactly to the operation performed internally for calculating
the round-trip matrices.
The format of each matrix symbol will be ``<comp>__<from_port>_<to_port>``,
e.g. the reflection at the rear (port two) surface of a mirror named ITM
would be represented as ``ITM__p2_p2``. The matrix multiplication is denoted
via the ``@`` symbol.
Returns
-------
abcd_str : str
A string representing the operation to obtain the cavity round-trip
ABCD matrix (in either plane).
"""
from finesse.tracing.cytools import generate_rt_abcd_str
return generate_rt_abcd_str(self.__tree)
def plot(self, direction=None, *args, **kwargs):
"""Plots the beam representing the cavity eigenmode over the path of the cavity.
......
......@@ -232,7 +232,7 @@ cdef class TraceForest:
for j in range(i + 1, self.N_trees):
tree2 = self.forest[j]
for node in tree1_nodes:
if tree2.contains_node(node):
if tree2.contains_node(node) or tree2.contains_node(node.opposite):
overlaps.append((tree1, tree2))
break
......@@ -594,8 +594,8 @@ cdef class TraceForest:
Py_ssize_t tree_idx
TraceTree tree, found
for tree_idx in range(self.N_trees):
tree = self.forest[tree_idx]
for tree_idx in range(self.N_trees, 0, -1):
tree = self.forest[tree_idx - 1]
found = tree.find_tree_at_node(node, self.symmetric)
if found is not None:
......
......@@ -315,3 +315,35 @@ cpdef tuple propagate_beam_symbolic(
t = t.left
return node_info, comp_info
### Debugging tools ###
cpdef generate_rt_abcd_str(TraceTree tree):
cdef TraceTree t = tree
src_node = t.node
# Find the bottom first as round-trip matrix is
# computed from multiplying each ABCD "upwards"
# in the internal tree
while t.left is not None:
if t.left is None:
break
t = t.left
M_str = f"{t.node.component.name}__{t.node.port.name}_{src_node.port.name} @"
t = t.parent
while t is not None:
if t.node.is_input:
comp = t.node.component
else:
comp = t.node.space
M_str += f" {comp.name}__{t.left.node.port.name}_{t.node.port.name} "
if t.parent is not None:
M_str += "@"
t = t.parent
return M_str
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