Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Enhancements
Bug fixes
~~~~~~~~~

* Prevent `v_oc` to be negative in `_lambertw` (:pull:`1782`)
Comment thread
cedricleroy marked this conversation as resolved.
Outdated


Testing
~~~~~~~
Expand All @@ -71,3 +73,4 @@ Contributors
* Adam R. Jensen (:ghuser:`AdamRJensen`)
* Echedey Luis (:ghuser:`echedey-ls`)
* Cliff Hansen (:ghuser:`cwhanse`)
* Cédric Leroy (:ghuser:`cedricleroy`)
Comment thread
kandersolar marked this conversation as resolved.
7 changes: 7 additions & 0 deletions pvlib/singlediode.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,13 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
# Compute open circuit voltage
v_oc = _lambertw_v_from_i(0., **params)

# Set elements <0 or close to 0 in v_oc to 0
if isinstance(v_oc, np.ndarray):
v_oc[(v_oc < 0) | ((v_oc > 0) & (v_oc < 1e-12))] = 0.
elif isinstance(v_oc, (float, int)):
if v_oc < 0 or 0 < v_oc < 1e-12:
Comment thread
cedricleroy marked this conversation as resolved.
Outdated
v_oc = 0.

# Find the voltage, v_mp, where the power is maximized.
# Start the golden section search at v_oc * 1.14
p_mp, v_mp = _golden_sect_DataFrame(params, 0., v_oc * 1.14, _pwr_optfcn)
Expand Down
15 changes: 15 additions & 0 deletions pvlib/tests/test_singlediode.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ def test_singlediode_precision(method, precise_iv_curves):
assert np.allclose(pc['i_xx'], outs['i_xx'], atol=1e-6, rtol=0)


def test_singlediode_lambert_negative_voc():

x1 = np.array([0., 1.480501e-11, 0.178, 8000., 1.797559])
outs = pvsystem.singlediode(*x1, method='lambertw')
assert outs['v_oc'] == 0

x2 = np.array([0., 1.456894e-11, 0.178, 8000., 1.797048])
outs = pvsystem.singlediode(*x2, method='lambertw')
assert outs['v_oc'] == 0

x = np.array([x1, x2]).T
outs = pvsystem.singlediode(*x, method='lambertw')
assert np.array_equal(outs['v_oc'], [0, 0])


@pytest.mark.parametrize('method', ['lambertw'])
def test_ivcurve_pnts_precision(method, precise_iv_curves):
"""
Expand Down