Skip to content

Commit

Permalink
Fix netlist issues (#3938)
Browse files Browse the repository at this point in the history
* Allow µ
Allow parameter with and without =

* Add warning for not imported elements

* Add GND if 0 net detected

* Add GND if 0 net detected
  • Loading branch information
Samuelopez-ansys authored Dec 4, 2023
1 parent 4f64da5 commit 22fefda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions _unittest/example_models/T21/netlist_small.cir
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ L201 N1721592 BUS_P 643.0p
V1 N1721592 BUS_N 12
V2 N1814870 0 PULSE(0 10 0 0.1u 0.1u 1.2u 5u)
I1 N1763408 0 1e-3
L4 N003 N004 110µ
L7 N018 N019 110µ
kcoupl L4 L7 0.9999
.param a=50V
.PARAM definire=20
.param a1=50V
Expand Down
19 changes: 15 additions & 4 deletions pyaedt/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __enter__(self):

def _get_number_from_string(self, stringval):
value = stringval[stringval.find("=") + 1 :].strip().replace("{", "").replace("}", "").replace(",", ".")
value = value.replace("µ", "u")
try:
float(value)
return value
Expand Down Expand Up @@ -206,8 +207,11 @@ def create_schematic_from_netlist(self, file_to_import):
line = line.decode("utf-8")
if ".param" in line[:7].lower():
try:
ppar = line[7:].split("=")[0]
pval = line[7:].split("=")[1]
param_line = " ".join(line[7:].split())
param_re = re.split("[ =]", param_line)

ppar = param_re[0]
pval = param_re[1]
self[ppar] = pval
xpos = 0.0254
except:
Expand Down Expand Up @@ -371,7 +375,7 @@ def create_schematic_from_netlist(self, file_to_import):
mycomp = self.modeler.schematic.create_voltage_pulse(
name, value, [xpos, ypos], use_instance_id_netlist=use_instance
)
elif fields[0][0] == "K":
elif fields[0][0].lower() == "k":
value = self._get_number_from_string(fields[3])
mycomp = self.modeler.schematic.create_coupling_inductors(
name, fields[1], fields[2], value, [xpos, ypos], use_instance_id_netlist=use_instance
Expand All @@ -388,6 +392,8 @@ def create_schematic_from_netlist(self, file_to_import):
mycomp = self.modeler.schematic.create_current_pulse(
name, value, [xpos, ypos], use_instance_id_netlist=use_instance
)
elif not any(word in line.lower() for word in [".param", ".model", ".lib"]):
self.logger.warning("%s could not be imported", line)
if mycomp:
id = 1
for pin in mycomp.pins:
Expand All @@ -396,7 +402,12 @@ def create_schematic_from_netlist(self, file_to_import):
angle = 0.0
else:
angle = math.pi
self.modeler.schematic.create_page_port(fields[id], [pos[0], pos[1]], angle)
if fields[id] == "0":
gnd_pos = self.modeler.schematic._convert_point_to_units([0, -0.00254])
new_pos = [i + j for i, j in zip(pos, gnd_pos)]
self.modeler.schematic.create_gnd([new_pos[0], new_pos[1]])
else:
self.modeler.schematic.create_page_port(fields[id], [pos[0], pos[1]], angle)
id += 1
ypos += delta
if ypos > 0.254:
Expand Down

0 comments on commit 22fefda

Please sign in to comment.