Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/sphinx/source/whatsnew/v0.15.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Deprecations

Bug fixes
~~~~~~~~~

* Fix a division-by-zero condition in
:py:func:`pvlib.transformer.simple_efficiency` when ``load_loss = 0``.
(:issue:`2645`, :pull:`2646`)

Enhancements
~~~~~~~~~~~~
Expand Down Expand Up @@ -42,4 +44,5 @@ Maintenance

Contributors
~~~~~~~~~~~~
* Aman Srivastava (:ghuser:`aman-coder03`)

3 changes: 2 additions & 1 deletion pvlib/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def simple_efficiency(
b = 1
c = no_load_loss - input_power_normalized

output_power_normalized = (-b + (b**2 - 4*a*c)**0.5) / (2 * a)
disc = (b*b - 4*a*c)**0.5
Comment thread
kandersolar marked this conversation as resolved.
output_power_normalized = 2*c / (-b - disc)

output_power = output_power_normalized * transformer_rating
return output_power
22 changes: 22 additions & 0 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
import pytest

from numpy.testing import assert_allclose

Expand Down Expand Up @@ -58,3 +59,24 @@ def test_simple_efficiency_known_values():
*args),
rating,
)


@pytest.mark.parametrize(
"input_power, no_load_loss, load_loss, transformer_rating, expected",
[
(1000.0, 0.01, 0.0, 1000.0, 990.0),
],
)
def test_simple_efficiency_zero_load_loss(
input_power, no_load_loss, load_loss, transformer_rating, expected
):
# for load_loss = 0, the model reduces to:
# P_out = P_in - L_no_load * P_nom
result = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=transformer_rating,
)

assert_allclose(result, expected)