finesse.utilities.components.names_to_nodes

finesse.utilities.components.names_to_nodes(model, names, default_hints=())[source]

Attempts to convert a list of node/dof/ports into nodes. This is to provide a way for actions to convert string names into nodes for simulation use. It attempts to provide useful default behaviours, and can accept “hints” on how to select nodes.

Parameters
namesiterable[str|(str, iterable[str])]

A collection of names to convert. A (name, hint) pair can also be provided where hint is an iterable of strings.

default_hintsiterable[str]

Default hint to use with particular set of names if no hints are provided.

Notes

Posible hints when name is a Port or DOF: - input : try and select a singular input node - output : try and select a singular output node

Examples

Selecting various nodes from a model with and without hinting:

>>> import finesse
>>> from finesse.utilities.components import names_to_nodes
>>> model = finesse.Model()
>>> model.parse('''
... l l1 P=100k
... mod mod1 f=10M midx=0.1 order=1 mod_type=pm
... m m1 R=1-m1.T T=0.014 Rc=-1984 xbeta=0n
... m m2 R=1 T=0 Rc=2245 xbeta=0n phi=0
... link(l1, mod1, m1, 3994, m2)
... dof DARM m1.dofs.z -1 m2.dofs.z +1
... ''')
>>> names_to_nodes(model, ('m1.p1', 'DARM.AC'), default_hints=('output'))
[<OpticalNode m1.p1.o @ 0x7f92c9a5c880>,
 <SignalNode DARM.AC.o @ 0x7f92c9a0e5b0>]
>>> names_to_nodes(model, ('m1.p1', 'DARM.AC'), default_hints=('input'))
[<OpticalNode m1.p1.i @ 0x7f92c9a5ca60>,
 <SignalNode DARM.AC.i @ 0x7f92c9a0e460>]
>>> names_to_nodes(model, ('m1.p1.o', 'DARM.AC.i'))
[<OpticalNode m1.p1.o @ 0x7f92c9a5c880>,
 <SignalNode DARM.AC.i @ 0x7f92c9a0e460>]

Hints do not insist on a particular output. For example, this is valid:

>>> names_to_nodes(model, ('m1.p1.o', ('DARM.AC.o', "input")))