Pre-determining mode mismatch couplings via TraceForest dependency intersections
This is another aspect of the tracing I've wanted to implement for a bit, plus it should show off the power of using the TraceForest
and TraceTree
structures.
The new method TraceForest.find_intersection_couplings
gets the (from_node, to_node)
couplings between trace trees which rely on different trace dependency objects. Using this on the simulations' changing forest, we can pre-determine all the node couplings which will have potential mode mismatches in the initialisation step of the simulation --- see the addition to initialise_trace_forest
in basematrix.pyx
in this MR. This then lets us query the new mismatched_node_couplings
attribute
of the simulation when initialising connector refill
flags, to determine whether these matrices need to be refilled during the simulation.
I have no benchmarks right now but this will definitely provide big performance boosts for simulations where some geometric parameter is changing --- especially for large files.
In addition, this also provides the means for using per-coupling refill
flags in the future - as one can simply check if a specific node coupling is in sim.mismatched_node_couplings
(as well as all the other usual checks) to initialise such potential flags. For example, in Mirror._get_workspace
one could instead have something like:
refill_P1iP2o = (
(self.p1.i, self.p2.o) in sim.mismatched_node_couplings
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))
)
# etc. for the other couplings
Note that these changes exposed the bug described in #273 (closed) and so that should be fixed before this is merged in