Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
finesse
finesse3
Commits
05e5aa77
Commit
05e5aa77
authored
Sep 30, 2020
by
Sean Leavey
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into reoptimise
parents
f6ee0877
7e3dcfbf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
3 deletions
+94
-3
src/finesse/solutions/beamtrace.py
src/finesse/solutions/beamtrace.py
+92
-1
src/finesse/tracing/tools.pyx
src/finesse/tracing/tools.pyx
+2
-2
No files found.
src/finesse/solutions/beamtrace.py
View file @
05e5aa77
...
...
@@ -7,7 +7,7 @@ import logging
import
numpy
as
np
from
finesse.components
import
Cavity
from
finesse.components
import
Cavity
,
Space
from
finesse.components.general
import
Connector
from
finesse.components.node
import
Port
,
OpticalNode
from
finesse.element
import
evaluate
,
Symbol
...
...
@@ -184,6 +184,11 @@ class PropagationSolution(BaseSolution):
)
return
list
(
space_entries
.
keys
())
@
property
def
components
(
self
):
"""A list of all components traversed, in order."""
return
list
(
filter
(
lambda
x
:
not
isinstance
(
x
,
Space
),
self
.
comp_info
.
keys
()))
@
property
def
path_length
(
self
):
"""The optical path length of the traversed path."""
...
...
@@ -356,6 +361,92 @@ class PropagationSolution(BaseSolution):
raise
TypeError
(
f
"Invalid type for key:
{
key
}
"
)
def
compute_distances_matrix
(
self
,
subs
=
None
):
"""Compute the distances between each optic, relative to each other.
Returns a dict of dicts for each "delta z".
Use :meth:`PropagationSolution.print_distances_matrix` to print a tabulated
string representation of this dict.
Parameters
----------
subs : dict, optional
A dictionary of model parameter to value substitutions
to pass to the ``eval`` methods of symbolic expressions.
If this solution object is not symbolic then this argument
is ignored.
Returns
-------
deltas : dict
Dict of dicts for each dz between components.
"""
if
not
self
.
symbolic
and
subs
is
not
None
:
LOGGER
.
warning
(
"Ignoring subs=%s kwarg as PropagationSolution is non-symbolic."
,
subs
,
)
deltas
=
{}
outer_done
=
set
()
for
node1
,
info1
in
self
.
node_info
.
items
():
comp1
=
node1
.
component
if
comp1
in
outer_done
:
continue
inner_done
=
set
()
deltas
[
comp1
]
=
{}
for
node2
,
info2
in
self
.
node_info
.
items
():
comp2
=
node2
.
component
if
comp2
in
inner_done
:
continue
z2
=
self
.
__eval_z_for_display
(
info2
,
subs
=
subs
)
z1
=
self
.
__eval_z_for_display
(
info1
,
subs
=
subs
)
deltas
[
comp1
][
comp2
]
=
z2
-
z1
inner_done
.
add
(
comp2
)
outer_done
.
add
(
comp1
)
return
deltas
def
print_distances_matrix
(
self
,
scale
=
1
,
tablefmt
=
"fancy_grid"
,
subs
=
None
):
"""Print the distances between each optic, relative to each other, in a table.
Note that all distances are in metres by default. You can apply a scaling factor,
via the `scale` argument, to all values to change the units accordingly.
Parameters
----------
scale : float, optional
Scaling factor to apply to distances. Defaults to unity such
that all distances are in metres.
tablefmt : str, optional; default: "fancy_grid"
The plain-text table format to pass to tabulate.
subs : dict, optional
A dictionary of model parameter to value substitutions
to pass to the ``eval`` methods of symbolic expressions.
If this solution object is not symbolic then this argument
is ignored.
"""
from
tabulate
import
tabulate
deltas
=
self
.
compute_distances_matrix
(
subs
=
subs
)
table
=
[]
headers
=
[
comp
.
name
for
comp
in
self
.
components
]
for
comp1
in
deltas
:
entry
=
[
comp1
.
name
]
for
dz
in
deltas
[
comp1
].
values
():
entry
.
append
(
scale
*
dz
)
table
.
append
(
entry
)
print
(
tabulate
(
table
,
headers
,
tablefmt
=
tablefmt
))
def
make_table
(
self
,
tablefmt
=
"fancy_grid"
,
subs
=
None
):
"""Construct a table showing the beam properties at each node.
...
...
src/finesse/tracing/tools.pyx
View file @
05e5aa77
...
...
@@ -405,7 +405,7 @@ cdef tuple propagate_beam_numeric(
info_at_space
[
"acc_gouy"
]
=
degrees
(
gouy
(
q2
)
-
gouy
(
q1
))
distance
+=
space
.
L
.
value
/
space
.
nr
.
value
distance
+=
space
.
L
.
value
info_at_space
[
"q_out"
]
=
q
else
:
...
...
@@ -465,7 +465,7 @@ cdef tuple propagate_beam_symbolic(
info_at_space
[
"acc_gouy"
]
=
np
.
degrees
(
q2
.
gouy
()
-
q1
.
gouy
())
distance
+=
space
.
L
.
ref
/
space
.
nr
.
ref
distance
+=
space
.
L
.
ref
info_at_space
[
"q_out"
]
=
q
else
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment