Skip to content

circuit_model

PV_Circuit_Model.circuit_model

CircuitElement

Bases: CircuitComponent

A circuit element class

set_operating_point(V=None, I=None)

Set the operating point for this element.

Parameters:

Name Type Description Default
V Optional[float]

Voltage to evaluate.

None
I Optional[float]

Current to evaluate.

None

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import Resistor
r = Resistor(cond=2.0)
r.set_operating_point(V=0.5)
r.operating_point[1] == 1.0 # True

draw(ax=None, x=0, y=0, color='black', fontsize=6, linewidth=1.5, display_value=False)

Draw this element on a matplotlib axis.

Parameters:

Name Type Description Default
ax Optional[Any]

Matplotlib Axes to draw into, or None.

None
x float

X position of the element center.

0
y float

Y position of the element center.

0
color str

Line color for the symbol.

'black'
display_value bool

If True, show the value label.

False

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import R
R(10).draw(ax=ax)

calc_I(V)

Compute current for a given voltage.

Parameters:

Name Type Description Default
V Union[float, ndarray]

Voltage value(s).

required

Returns:

Type Description
Union[float, ndarray]

Union[float, np.ndarray]: Current value(s).

Raises:

Type Description
NotImplementedError

If not implemented in a subclass.

Example
from PV_Circuit_Model.circuit_model import Resistor
Resistor(cond=2.0).calc_I(0.5) # 1.0

CircuitGroup

Bases: CircuitComponent

Circuit with series or parallel connected parts.

parts property writable

Alias for subgroups.

Returns:

Type Description
Sequence[CircuitComponent]

Sequence[CircuitComponent]: Child components/groups.

Example
from PV_Circuit_Model.circuit_model import series, R
group = series(R(1), R(2))
len(group.parts) # 2

children property writable

Another alias for subgroups.

Returns:

Type Description
Sequence[CircuitComponent]

Sequence[CircuitComponent]: Child components/groups.

Example
from PV_Circuit_Model.circuit_model import series, R
group = series(R(1), R(2))
len(group.children) # 2

__init__(subgroups, connection='series', name=None, location=None, rotation=0, x_mirror=1, y_mirror=1, extent=None)

Initialize a CircuitGroup.

Parameters:

Name Type Description Default
subgroups Sequence[CircuitComponent]

Child components/groups.

required
connection str

"series" or "parallel" connection type.

'series'
name Optional[str]

Optional name for lookup.

None
location Optional[Sequence[float]]

XY location for layout.

None
rotation float

Rotation in degrees.

0
x_mirror int

X mirror flag (+1 or -1).

1
y_mirror int

Y mirror flag (+1 or -1).

1
extent Optional[Sequence[float]]

Precomputed extent (width, height).

None

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import CircuitGroup, R
group = CircuitGroup([R(1), R(2)], connection="series")
group.connection # 'series' 

set_operating_point(V=None, I=None, refine_IV=False, shallow=False, use_python=False)

Set the operating point for the circuit group.

Parameters:

Name Type Description Default
V Optional[float]

Voltage to set or evaluate.

None
I Optional[float]

Current to set or evaluate.

None
refine_IV bool

If True, refine IV around operating point.

False
shallow bool

If True, skip recursion into subgroups.

False

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import *
group = R(1) + R(2)
group.build_IV()
group.set_operating_point(V=0.5, shallow=True)
group.operating_point[0] # 0.5

removeElementOfTag(tag)

Remove all elements with a matching tag.

Parameters:

Name Type Description Default
tag Any

Tag value to remove.

required

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import series, R
group = series(R(1, tag="R1"), R(2, tag="R2"))
group.removeElementOfTag("R1")
len(group.subgroups) # 1

set_temperature(temperature)

Update temperature for all diodes and current sources.

Parameters:

Name Type Description Default
temperature float

Temperature in Celsius.

required

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import series, R, CurrentSource
group = series(CurrentSource(1.0), R(1))
group.set_temperature(35)

findElementType(type_, stop_at_type_=None)

Find all elements of a given type in the subtree.

Parameters:

Name Type Description Default
type_ Union[type, str]

Class or class name to match.

required
stop_at_type_ Union[type, str]

if encounter element of stop_at_type_, do not search within it

None

Returns:

Type Description
List[CircuitComponent]

List[CircuitComponent]: Matching elements.

Example
from PV_Circuit_Model.circuit_model import series, R, Diode
group = series(R(1), Diode())
len(group.findElementType(Diode)) # 1

__getitem__(type_)

Shortcut for findElementType.

Example
from PV_Circuit_Model.circuit_model import series, R, Diode
group = series(R(1), Diode())
len(group[Diode])

draw(x=0, y=0, display_value=False, title='Model', linewidth=1.5, animate=False, V_sweep_frames=None, split_screen_with_IV=False, current_flow_log10_range=4, area_multiplier=1, fontsize=6, ax2_width=0.5, ax2_xlim=None, ax2_ylim=None, figsize=None, operating_point_size=20, max_electron_size=0.05)

Draw the CircuitGroup as a schematic, optionally with animation and an IV subplot.

If animate=True, the method animates "current flow" using moving circles along the wires. If V_sweep_frames is provided, the operating point is swept over the specified voltages and the animation updates the operating point (and optionally the IV subplot markers) per frame.

Parameters:

Name Type Description Default
x float

X position of the schematic center in diagram coordinates.

0
y float

Y position of the schematic center in diagram coordinates.

0
display_value bool

If True, display component values (where supported by elements).

False
title str

Figure window title when creating a new figure.

'Model'
linewidth float

Line width for wiring and plots

1.5
animate bool

If True, animate current flow using moving circles on the wires. Requires that operating points have been computed (e.g., via get_Pmax(), set_operating_point(), or similar).

False
V_sweep_frames Optional[Any]

Optional sequence of voltages to sweep. If provided, each animation frame sets the circuit operating point to V_sweep_frames[frame]. When omitted, the animation runs as a steady "flow" at the current operating point.

None
split_screen_with_IV bool

If True, creates a second subplot showing the IV curve

False
current_flow_log10_range float

Controls visual scaling of circle size with current magnitude. Circle radii scale approximately with log10(|I|) over this range; larger values compress the visual range (less variation), smaller values exaggerate it.

4
area_multiplier float

Not passed by users.

1
fontsize float

font size to display

6
ax2_width float

width of ax2 (max 1)

0.5
ax2_xlim tuple[float, float] | None

xlim of ax2 (dafault None)

None
ax2_ylim tuple[float, float] | None

ylim of ax2 (dafault None)

None
figsize tuple[float, float] | None

figure width and height (default None)

None
operating_point_size float

size of operating point to plot (default 20)

20
max_electron_size float

size of electrons in animation (default 0.05)

0.05
Example

Basic schematic:

from PV_Circuit_Model.circuit_model import series, R
(R(1) + R(2)).draw()

Animate current flow (after computing an operating point):

circuit.get_Pmax()
circuit.draw(animate=True)

Sweep operating point across voltages and show IV subplot:

Vs = np.linspace(0, circuit.get_Voc(), 60)
circuit.get_Pmax()
circuit.draw(animate=True, V_sweep_frames=Vs, split_screen_with_IV=True)

as_type(cls, **kwargs)

Convert this group to another circuit component type.

Parameters:

Name Type Description Default
cls Type[CircuitComponent]

Target class with from_circuitgroup.

required
**kwargs Any

Forwarded to from_circuitgroup.

{}

Returns:

Name Type Description
CircuitComponent T_CircuitComponent

Converted instance of cls.

Raises:

Type Description
TypeError

If cls is not a CircuitComponent or lacks conversion.

Example
from PV_Circuit_Model.device import *
circuit_group = ( 
    (IL(41e-3) | D1(10e-15) | D2(5e-9) | Dintrinsic_Si(180e-4) | Drev(V_shift=10) | R(1e5)) 
    + R(1/3)
)
cell_ = circuit_group.as_type(Cell, **wafer_shape(format="M10",half_cut=True))

tile_subgroups(rows=None, cols=None, x_gap=0.0, y_gap=0.0, turn=False, xflip=False, yflip=False, col_wise_ordering=True)

Tile subgroups into a grid layout.

Parameters:

Name Type Description Default
rows Optional[int]

Number of rows.

None
cols Optional[int]

Number of columns.

None
x_gap float

Horizontal gap between tiles.

0.0
y_gap float

Vertical gap between tiles.

0.0
turn bool

Alternate rotation per column/row.

False
xflip bool

Flip X orientation for 2-column layout.

False
yflip bool

Flip Y orientation for 2-row layout.

False
col_wise_ordering bool

Fill columns before rows.

True

Returns:

Name Type Description
CircuitGroup CircuitGroup

The updated group (self).

Example
from PV_Circuit_Model.device import Cell_
cell = Cell_()
cells = cell*5
cells.tile_subgroups(rows=1)

CurrentSource

Bases: CircuitElement

Ideal current source with temperature and irradiance scaling.

__init__(IL, Suns=1.0, temperature=25, temp_coeff=0.0, tag=None)

Initialize a current source.

Parameters:

Name Type Description Default
IL float

Light-generated current at reference conditions.

required
Suns float

Relative irradiance multiplier.

1.0
temperature float

Temperature in Celsius.

25
temp_coeff float

Temperature coefficient for IL scaling.

0.0
tag Optional[str]

Optional identifier for this source.

None
Example
from PV_Circuit_Model.circuit_model import CurrentSource
src = CurrentSource(IL=1.0, temperature=25)
src.IL # 1.0

set_IL(IL)

Update IL and invalidate IV caches.

Parameters:

Name Type Description Default
IL float

New light-generated current.

required
Example
from PV_Circuit_Model.circuit_model import CurrentSource
src = CurrentSource(IL=1.0)
src.set_IL(2.0)
src.IL # 2.0

changeTemperatureAndSuns(temperature=None, Suns=None)

Update temperature and irradiance, then recompute IL.

Parameters:

Name Type Description Default
temperature Optional[float]

New temperature in Celsius.

None
Suns Optional[float]

New irradiance multiplier.

None
Example
from PV_Circuit_Model.circuit_model import CurrentSource
src = CurrentSource(IL=1.0, Suns=1.0)
src.changeTemperatureAndSuns(Suns=2.0)
src.Suns # 2.0

Resistor

Bases: CircuitElement

Ohmic resistor represented by conductance (1/R).

__init__(cond=1.0, tag=None)

Initialize a resistor.

Parameters:

Name Type Description Default
cond float

Conductance in 1/ohm.

1.0
tag Optional[str]

Optional identifier for this resistor.

None

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import Resistor
r = Resistor(cond=1.0)
r.cond # 1.0

set_cond(cond)

Update conductance and invalidate IV caches.

Parameters:

Name Type Description Default
cond float

New conductance in 1/ohm.

required

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import Resistor
r = Resistor(cond=1.0)
r.set_cond(2.0)
r.cond # 2.0

Diode

Bases: CircuitElement

Generic diode class

__init__(I0=1e-15, n=1, V_shift=0, max_I=None, tag=None, temperature=25)

Initialize a diode.

Parameters:

Name Type Description Default
I0 float

Saturation current.

1e-15
n float

Ideality factor.

1
V_shift float

Voltage shift (e.g., breakdown offset).

0
max_I Optional[float]

Maximum current density for IV ranges.

None
tag Optional[str]

Optional identifier for this diode.

None
temperature float

Temperature in Celsius.

25
Example
from PV_Circuit_Model.circuit_model import Diode
d = Diode(I0=1e-12, n=1.0)
d.I0 # 1e-12

set_I0(I0)

Update saturation current and invalidate IV caches.

Parameters:

Name Type Description Default
I0 float

New saturation current.

required
Example
from PV_Circuit_Model.circuit_model import Diode
d = Diode()
d.set_I0(1e-12)
d.I0 # 1e-12

changeTemperature(temperature)

Update temperature and scale saturation current.

Parameters:

Name Type Description Default
temperature float

Temperature in Celsius.

required

Returns:

Type Description
None

None

Example
from PV_Circuit_Model.circuit_model import Diode
d = Diode()
d.changeTemperature(35)

ForwardDiode

Bases: Diode

Diode that points from '+' to '-'

ReverseDiode

Bases: Diode

Reverse (breakdown) diode with inverted IV direction.

PhotonCouplingDiode

Bases: ForwardDiode

LED-like diode for photon coupling in tandem models.

Intrinsic_Si_diode

Bases: ForwardDiode

Intrinsic silicon diode with base recombination physics.

__init__(base_thickness=0.018, base_type='n', base_doping=1000000000000000.0, area=1.0, temperature=25, max_I=None, tag=None)

Initialize an intrinsic silicon diode.

Parameters:

Name Type Description Default
base_thickness float

Base thickness in cm.

0.018
base_type str

"p" or "n" base type.

'n'
base_doping float

Base doping concentration in cm^-3.

1000000000000000.0
area float

Active area multiplier.

1.0
temperature float

Temperature in Celsius.

25
max_I Optional[float]

Maximum current density for IV ranges.

None
tag Optional[str]

Optional identifier.

None
Example
from PV_Circuit_Model.circuit_model import Intrinsic_Si_diode
d = Intrinsic_Si_diode()
d.base_type # 'n'

IL(*args, **kwargs)

This is a convenience alias for :class:CurrentSource, typically used to represent the light-generated current term in a PV circuit.

Example
IL = IL(5.0)
cell = IL + diode

R(R, tag=None)

Create a resistor by specifying resistance in ohms.

Parameters:

Name Type Description Default
R float

Resistance in ohms.

required
tag Optional[str]

Optional identifier for this resistor.

None

Returns:

Name Type Description
Resistor Resistor

A resistor with conductance 1/R.

Example
from PV_Circuit_Model.circuit_model import R
R(10).cond # 0.1

D(*args, **kwargs)

This is a shorthand constructor for :class:ForwardDiode.

D1(*args, **kwargs)

Create a forward diode with ideality factor n = 1.

D2(*args, **kwargs)

Create a forward diode with ideality factor n = 2.

Drev(*args, **kwargs)

This is a shorthand constructor for :class:ReverseDiode.

Dpc(*args, **kwargs)

This is a shorthand constructor for :class:PhotonCouplingDiode.

Dintrinsic_Si(*args, **kwargs)

This is a shorthand constructor for :class:Intrinsic_Si_diode.

tile_elements(elements, rows=None, cols=None, x_gap=0.0, y_gap=0.0, turn=False, xflip=False, yflip=False, col_wise_ordering=True)

Tile elements into a grid for layout and diagram placement.

Parameters:

Name Type Description Default
elements Sequence[Any]

Elements with extent and location.

required
rows Optional[int]

Number of rows.

None
cols Optional[int]

Number of columns.

None
x_gap float

Horizontal gap between tiles.

0.0
y_gap float

Vertical gap between tiles.

0.0
turn bool

Alternate rotation per column/row.

False
xflip bool

Flip X orientation for 2-column layout.

False
yflip bool

Flip Y orientation for 2-row layout.

False
col_wise_ordering bool

Fill columns before rows.

True

Returns:

Type Description
None

None

Example
    from PV_Circuit_Model.device import Cell_
    cell = Cell_()
    cells = cell*5
    tile_elements(cells.parts,rows=1)

circuit_deepcopy(circuit_component)

Return a deep clone of a circuit component.

Warning

This uses the component's clone method and does not deep-copy external resources.

Parameters:

Name Type Description Default
circuit_component CircuitComponent

Component to clone.

required

Returns:

Name Type Description
CircuitComponent CircuitComponent

Cloned component.

Example
from PV_Circuit_Model.circuit_model import R, circuit_deepcopy
r = R(1)
r2 = circuit_deepcopy(r)

find_subgroups_by_name(circuit_group, target_name)

Find subgroups with a matching name.

Parameters:

Name Type Description Default
circuit_group CircuitGroup

Root group to search.

required
target_name str

Name to match.

required

Returns:

Type Description
List[CircuitComponent]

List[CircuitComponent]: Matching subgroups.

Example
from PV_Circuit_Model.circuit_model import CircuitGroup, R
group = CircuitGroup([R(1)], connection="series", name="root")
len(find_subgroups_by_name(group, "root")) # 1

find_subgroups_by_tag(circuit_group, tag)

Find subgroups with a matching tag.

Warning

This uses name-based recursion for nested groups and may not find tagged children in all cases.

Parameters:

Name Type Description Default
circuit_group CircuitGroup

Root group to search.

required
tag Any

Tag value to match.

required

Returns:

Type Description
List[CircuitComponent]

List[CircuitComponent]: Matching subgroups.

Example
from PV_Circuit_Model.circuit_model import series, R
group = series(R(1, tag="R1"), R(2))
len(find_subgroups_by_tag(group, "R1")) # 1