|
| 1 | +from typing import List, Literal, Optional, Union |
| 2 | + |
| 3 | +from pydantic import BaseModel |
| 4 | + |
| 5 | + |
| 6 | +class CfgBase(BaseModel): |
| 7 | + model_config = { |
| 8 | + "populate_by_name": True, |
| 9 | + "extra": "forbid", |
| 10 | + } |
| 11 | + |
| 12 | + |
| 13 | +class CfgTerminal(CfgBase): |
| 14 | + name: str |
| 15 | + impedance: Union[float, int, str] |
| 16 | + is_circuit_port: bool |
| 17 | + reference_terminal: Optional[str] = None |
| 18 | + amplitude: Optional[Union[float, int, str]] = 1 |
| 19 | + phase: Optional[Union[float, int, str]] = 0 |
| 20 | + terminal_to_ground: Optional[Literal["kNoGround", "kNegative", "kPositive"]] = "kNoGround" |
| 21 | + boundary_type: Literal[ |
| 22 | + "PortBoundary", |
| 23 | + "PecBoundary", |
| 24 | + "RlcBoundary", |
| 25 | + "kCurrentSource", |
| 26 | + "kVoltageSource", |
| 27 | + "kNexximGround", |
| 28 | + "kNexximPort", |
| 29 | + "kDcTerminal", |
| 30 | + "kVoltageProbe", |
| 31 | + "InvalidBoundary", |
| 32 | + ] |
| 33 | + hfss_type: Literal["Wave", "Gap", None] |
| 34 | + |
| 35 | + |
| 36 | +class CfgPadstackInstanceTerminal(CfgTerminal): |
| 37 | + terminal_type: str = "padstack_instance" |
| 38 | + padstack_instance: str |
| 39 | + padstack_instance_id: Optional[int] = None |
| 40 | + layer: Optional[Union[str, None]] = None |
| 41 | + |
| 42 | + |
| 43 | +class CfgPinGroupTerminal(CfgTerminal): |
| 44 | + terminal_type: str = "pin_group" |
| 45 | + is_circuit_port: bool = True |
| 46 | + pin_group: str |
| 47 | + |
| 48 | + |
| 49 | +class CfgPointTerminal(CfgTerminal): |
| 50 | + terminal_type: str = "point" |
| 51 | + x: Union[float, int, str] |
| 52 | + y: Union[float, int, str] |
| 53 | + layer: str |
| 54 | + net: str |
| 55 | + |
| 56 | + |
| 57 | +class CfgEdgeTerminal(CfgTerminal): |
| 58 | + terminal_type: str = "edge" |
| 59 | + name: str |
| 60 | + primitive: str |
| 61 | + point_on_edge_x: Union[float, int, str] |
| 62 | + point_on_edge_y: Union[float, int, str] |
| 63 | + horizontal_extent_factor: Union[int, str] |
| 64 | + vertical_extent_factor: Union[int, str] |
| 65 | + pec_launch_width: Union[int, str] |
| 66 | + |
| 67 | + |
| 68 | +class CfgBundleTerminal(CfgBase): |
| 69 | + terminal_type: str = "bundle" |
| 70 | + terminals: List[str] |
| 71 | + name: str |
| 72 | + |
| 73 | + |
| 74 | +class CfgTerminals(CfgBase): |
| 75 | + terminals: List[ |
| 76 | + Union[ |
| 77 | + CfgPadstackInstanceTerminal, CfgPinGroupTerminal, CfgPointTerminal, CfgEdgeTerminal, CfgBundleTerminal, dict |
| 78 | + ] |
| 79 | + ] |
| 80 | + |
| 81 | + @classmethod |
| 82 | + def create(cls, terminals: List[dict]): |
| 83 | + manager = cls(terminals=[]) |
| 84 | + for i in terminals: |
| 85 | + terminal_type = i.pop("terminal_type") |
| 86 | + if terminal_type == "padstack_instance": |
| 87 | + manager.add_padstack_instance_terminal(**i) |
| 88 | + elif terminal_type == "pin_group": |
| 89 | + manager.add_pin_group_terminal(**i) |
| 90 | + elif terminal_type == "point": |
| 91 | + manager.add_point_terminal(**i) |
| 92 | + elif terminal_type == "edge": |
| 93 | + manager.add_edge_terminal(**i) |
| 94 | + elif terminal_type == "bundle": |
| 95 | + manager.add_bundle_terminal(**i) |
| 96 | + else: # pragma: no cover |
| 97 | + raise ValueError(f"Unknown terminal type: {terminal_type}") |
| 98 | + return manager |
| 99 | + |
| 100 | + def add_padstack_instance_terminal( |
| 101 | + self, |
| 102 | + padstack_instance, |
| 103 | + name, |
| 104 | + impedance, |
| 105 | + is_circuit_port, |
| 106 | + boundary_type, |
| 107 | + hfss_type, |
| 108 | + reference_terminal=None, |
| 109 | + amplitude=1, |
| 110 | + phase=0, |
| 111 | + terminal_to_ground="kNoGround", |
| 112 | + padstack_instance_id=None, |
| 113 | + layer=None, |
| 114 | + ): |
| 115 | + terminal = CfgPadstackInstanceTerminal( |
| 116 | + padstack_instance=padstack_instance, |
| 117 | + name=name, |
| 118 | + impedance=impedance, |
| 119 | + is_circuit_port=is_circuit_port, |
| 120 | + boundary_type=boundary_type, |
| 121 | + reference_terminal=reference_terminal, |
| 122 | + amplitude=amplitude, |
| 123 | + phase=phase, |
| 124 | + terminal_to_ground=terminal_to_ground, |
| 125 | + layer=layer, |
| 126 | + hfss_type=hfss_type, |
| 127 | + padstack_instance_id=padstack_instance_id, |
| 128 | + ) |
| 129 | + self.terminals.append(terminal) |
| 130 | + |
| 131 | + def add_pin_group_terminal( |
| 132 | + self, |
| 133 | + pin_group, |
| 134 | + name, |
| 135 | + impedance, |
| 136 | + boundary_type, |
| 137 | + reference_terminal=None, |
| 138 | + amplitude=1, |
| 139 | + phase=0, |
| 140 | + terminal_to_ground="kNoGround", |
| 141 | + ): |
| 142 | + terminal = CfgPinGroupTerminal( |
| 143 | + pin_group=pin_group, |
| 144 | + name=name, |
| 145 | + impedance=impedance, |
| 146 | + is_circuit_port=True, |
| 147 | + boundary_type=boundary_type, |
| 148 | + reference_terminal=reference_terminal, |
| 149 | + amplitude=amplitude, |
| 150 | + phase=phase, |
| 151 | + terminal_to_ground=terminal_to_ground, |
| 152 | + hfss_type=None, |
| 153 | + ) |
| 154 | + self.terminals.append(terminal) |
| 155 | + |
| 156 | + def add_point_terminal( |
| 157 | + self, |
| 158 | + x, |
| 159 | + y, |
| 160 | + layer, |
| 161 | + name, |
| 162 | + impedance, |
| 163 | + boundary_type, |
| 164 | + net, |
| 165 | + reference_terminal=None, |
| 166 | + amplitude=1, |
| 167 | + phase=0, |
| 168 | + terminal_to_ground="kNoGround", |
| 169 | + ): |
| 170 | + terminal = CfgPointTerminal( |
| 171 | + x=x, |
| 172 | + y=y, |
| 173 | + layer=layer, |
| 174 | + name=name, |
| 175 | + impedance=impedance, |
| 176 | + is_circuit_port=True, |
| 177 | + boundary_type=boundary_type, |
| 178 | + reference_terminal=reference_terminal, |
| 179 | + amplitude=amplitude, |
| 180 | + phase=phase, |
| 181 | + net=net, |
| 182 | + terminal_to_ground=terminal_to_ground, |
| 183 | + hfss_type=None, |
| 184 | + ) |
| 185 | + self.terminals.append(terminal) |
| 186 | + |
| 187 | + def add_edge_terminal( |
| 188 | + self, |
| 189 | + name, |
| 190 | + impedance, |
| 191 | + is_circuit_port, |
| 192 | + boundary_type, |
| 193 | + primitive, |
| 194 | + point_on_edge_x, |
| 195 | + point_on_edge_y, |
| 196 | + horizontal_extent_factor=6, |
| 197 | + vertical_extent_factor=8, |
| 198 | + pec_launch_width="0.02mm", |
| 199 | + reference_terminal=None, |
| 200 | + amplitude=1, |
| 201 | + phase=0, |
| 202 | + terminal_to_ground="kNoGround", |
| 203 | + ): |
| 204 | + terminal = CfgEdgeTerminal( |
| 205 | + name=name, |
| 206 | + impedance=impedance, |
| 207 | + is_circuit_port=is_circuit_port, |
| 208 | + boundary_type=boundary_type, |
| 209 | + reference_terminal=reference_terminal, |
| 210 | + amplitude=amplitude, |
| 211 | + phase=phase, |
| 212 | + terminal_to_ground=terminal_to_ground, |
| 213 | + primitive=primitive, |
| 214 | + point_on_edge_x=point_on_edge_x, |
| 215 | + point_on_edge_y=point_on_edge_y, |
| 216 | + horizontal_extent_factor=horizontal_extent_factor, |
| 217 | + vertical_extent_factor=vertical_extent_factor, |
| 218 | + pec_launch_width=pec_launch_width, |
| 219 | + hfss_type="Wave", |
| 220 | + ) |
| 221 | + self.terminals.append(terminal) |
| 222 | + |
| 223 | + def add_bundle_terminal( |
| 224 | + self, |
| 225 | + terminals, |
| 226 | + name, |
| 227 | + ): |
| 228 | + terminal = CfgBundleTerminal( |
| 229 | + terminals=terminals, |
| 230 | + name=name, |
| 231 | + ) |
| 232 | + self.terminals.append(terminal) |
0 commit comments