def _stamp_port(n, port, context):
"""
Stamp a port in the MNA matrix by adding KVL and KCL equations to the
kvl_equations and kcl_equations lists in the context dictionary.
"""
an = context["a"][n]
bn = context["b"][n]
node_voltages = context["node_voltages"]
kvl_equations = context["kvl_equations"]
kcl_equations = context["kcl_equations"]
node1, node2 = port["nodes"]
v1 = node_voltages[node1]
v2 = node_voltages[node2]
port_voltage = (an + bn) / 2
kvl_equation = sympy.Eq(port_voltage, v2 - v1)
kvl_equations.append(kvl_equation)
port_current = (an - bn) / (2 * context["port_resistances"][n])
context["kcl_equations"][node1] += -port_current
context["kcl_equations"][node2] += port_current
评论列表
文章目录