Skip to content

simple_efficiency raises ZeroDivisionError when load_loss=0 #2645

@aman-coder03

Description

@aman-coder03

Describe the bug

pvlib.transformer.simple_efficiency raises a ZeroDivisionError when
load_loss = 0.

A zero load_loss is a physically valid case (e.g., an ideal transformer
with only no-load losses), but the current implementation always solves
a quadratic equation and divides by 2 * load_loss, which leads to a
division by zero.


To Reproduce

from pvlib.transformer import simple_efficiency

simple_efficiency(
    input_power=1000,
    no_load_loss=0.01,
    load_loss=0,
    transformer_rating=1000,
)

Expected behavior

When load_loss = 0, the loss model becomes linear rather than quadratic.
The output power should be computed as:
P_out = P_in - L_no_load * P_nom
and the function should return a finite value instead of raising an
exception.


Proposed solution

Handle the special case where load_loss == 0 explicitly before solving
the quadratic equation.

When load_loss = 0, the loss model reduces to a linear relationship:
P_out = P_in - L_no_load * P_nom

A conditional check can be added at the beginning of the function to
return the linear solution and avoid division by zero, for example:

if load_loss == 0:
    return input_power - no_load_loss * transformer_rating

This preserves existing behavior for load_loss > 0 while correctly
handling a physically valid edge case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions