Cascade
- class pmrf.models.composite.interconnected.cascade.Cascade(cascade: tuple[Model, ...], *, name: str | None = None, metadata: Any = None, flatten: bool = True, method: Literal['s', 'a'] = 's', eps: float = 1e-12)
Bases:
ModelRepresents a cascade, or series connection, of two or more Model objects.
This container connects multiple models end-to-end. The output port of one model is connected to the input port of the next.
All models must have 2N-many ports. Ports N to 2*N-1 of the first model are connected to ports 0 to N-1 of the second, and so on.
Any nested Cascade instances are automatically flattened to maintain a simple, linear chain of models.
- Parameters:
cascade (tuple[Model, ...]) – The sequence of models in the cascade.
method ({'s', 'a'}, default='s') – The underlying mathematical domain to use for the cascade reduction.
flatten (bool, default=True) – (experimental) Flattens the cascade into one large cascade if they contain sub-cascades.
Examples
Cascading models is most easily done using the ** operator, which is an alias for creating a Cascade model.
>>> import pmrf as prf >>> from pmrf.models import Resistor, Capacitor, Inductor
# Create individual component models >>> res = Resistor(50) >>> cap = Capacitor(1e-12) >>> ind = Inductor(1e-9)
# Cascade them together in a series R-L-C configuration # This is equivalent to Cascade(models=(res, ind, cap)) >>> rlc_series = res ** ind ** cap
# Define a frequency axis >>> freq = prf.Frequency(start=1, stop=10, npoints=101, unit=’ghz’)
# Calculate the S-parameters of the cascaded network >>> s_params = rlc_series.s(freq)
- expand()
Expands this model into its internal graph representation for circuit flattening.
This method is used by graph algorithms (like the solver in Circuit.flattened) to unpack composite models, wrappers, and nested hierarchies into a single flat netlist. This allows global matrix solves to be used, where desired.
Note that expand is automatically implemented if
pmrf.Model.build()is overridden and the built model also implements expand. This means that most user-classes do NOT need to manually implement this method, and it is mainly intended for built-in composite models in ParamRF to override e.g.pmrf.models.Cascadeorpmrf.models.Renumbered.- Returns:
If the model is a composite or routing container, it returns a tuple of: - port_mapping: A list of length nports mapping each external port index
of this model to an internal (Model, port_index) tuple.
internal_connections: A list of sub-nodes (connections) to add to the netlist. Each node is a list of (Model, port_index) tuples.
If the model is a fundamental leaf component, it returns None.
- Return type:
tuple or None
Examples
Imagine a custom 2-port model that internally connects an Inductor and Capacitor in series. When asked to expand, it exposes the inner components and their wiring:
>>> def expand(self): ... # 1. Grab internal components ... L, C = self.inductor, self.capacitor ... ... # 2. Map our external ports to the internal components ... port_mapping = [ ... (L, 0), # External port 0 maps to Inductor port 0 ... (C, 1) # External port 1 maps to Capacitor port 1 ... ] ... ... # 3. Define the internal connections (the netlist) ... # Connect Inductor port 1 to Capacitor port 0 ... internal_connections = [ ... [(L, 1), (C, 0)] ... ] ... ... return port_mapping, internal_connections
- eps: float = 1e-12
Epsilon for matrix singularity nudging in scattering cascade.
- flatten: bool = True
(experimental) Flatten the connections if they contain any sub-circuits
- method: Literal['s', 'a'] = 's'
The cascade reduction algorithm method.
- property number_of_ports
Number of ports.
- Return type:
int