KLayout / klayout

KLayout Main Sources
http://www.klayout.org
GNU General Public License v3.0
808 stars 206 forks source link

Netlist device combination / simplify requests #1832

Closed klayoutmatthias closed 2 months ago

klayoutmatthias commented 3 months ago

This is a takeaway of a number of discussions regarding extraction of C elements.

  1. Netlist#simplify could eliminate shorted elements such as R, L or C

Example:

netlist = pya.Netlist()

circuit = pya.Circuit()
circuit.name = "TOP"

netlist.add(circuit)

cap_device = pya.DeviceClassCapacitor()
cap_device.name = "model_name"

netlist.add(cap_device)

n1 = circuit.create_net("n1")
n2 = circuit.create_net("n2")

c1 = circuit.create_device(cap_device, "c1")
c1.set_parameter("C", 1e-15)

c2 = circuit.create_device(cap_device, "c2")
c2.set_parameter("C", 2e-15)

# shorted cap
c1.connect_terminal("A", n1)
c1.connect_terminal("B", n1)

# non-shorted one
c2.connect_terminal("A", n1)
c2.connect_terminal("B", n2)

netlist.simplify()

print(netlist)

Current output:

circuit TOP (n1=n1,n2=n2);
  device model_name c1 (A=n1,B=n1) (C=1e-15,A=0,P=0);
  device model_name c2 (A=n1,B=n2) (C=2e-15,A=0,P=0);
end;

Proposed output:

circuit TOP (n1=n1,n2=n2);
  device model_name c2 (A=n1,B=n2) (C=2e-15,A=0,P=0);
end;
  1. Netlist#combine_devices does not work properly on small (typical cap values):

Example:


netlist = pya.Netlist()

circuit = pya.Circuit()
circuit.name = "TOP"

netlist.add(circuit)

cap_device = pya.DeviceClassCapacitor()
cap_device.name = "model_name"

netlist.add(cap_device)

n1 = circuit.create_net("n1")
n2 = circuit.create_net("n2")
n3 = circuit.create_net("n3")

p1 = circuit.create_pin("p1")
p2 = circuit.create_pin("p2")

circuit.connect_pin(p1, n1)
circuit.connect_pin(p2, n3)

c1 = circuit.create_device(cap_device, "c1")
c1.set_parameter("C", 1e-15)

c2 = circuit.create_device(cap_device, "c2")
c2.set_parameter("C", 2e-15)

c3 = circuit.create_device(cap_device, "c3")
c3.set_parameter("C", 3e-15)

# C1 and C2 are series caps
c1.connect_terminal("A", n1)
c1.connect_terminal("B", n2)

c2.connect_terminal("A", n2)
c2.connect_terminal("B", n3)

# C3 connects across
c3.connect_terminal("A", n1)
c3.connect_terminal("B", n3)

print(netlist)

netlist.combine_devices()

print(netlist)

Output:

circuit TOP (p1=n1,p2=n3);
  device model_name c1 (A=n1,B=n2) (C=1e-15,A=0,P=0);
  device model_name c2 (A=n2,B=n3) (C=2e-15,A=0,P=0);
  device model_name c3 (A=n1,B=n3) (C=3e-15,A=0,P=0);
end;

circuit TOP (p1=n1,p2=n3);
  device model_name c1 (A=n1,B=n3) (C=3e-15,A=0,P=0);
end;

Expected output for combined-device netlist

circuit TOP (p1=n1,p2=n3);
  device model_name c1 (A=n1,B=n3) (C=3.66666666667e-15,A=0,P=0);
end;