Skip to content

Commit 09c6a75

Browse files
committed
update test_singlediode_methods to use lambertw in comparison
* add comment about how Voc is estimated and that it's useful as a bound for the bisection method * remove "unreliable" from fast/newton methods
1 parent c0e18a5 commit 09c6a75

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

pvlib/singlediode_methods.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def est_voc(photocurrent, saturation_current, nNsVth):
4545
ideality factor ``n``, and number of series cells ``Ns``
4646
:returns: rough estimate of open circuit voltage [V]
4747
48-
The equation is from [1].
48+
Calculating the open circuit voltage, :math:`V_{oc}`, of an ideal device
49+
with infinite shunt resistance, :math:`R_{sh} \\to \\infty`, and zero series
50+
resistance, :math:`R_s = 0`, yields the following equation [1]. As an
51+
estimate of :math:`V_{oc}` it is useful as an upper bound for the bisection
52+
method.
4953
5054
.. math::
5155
@@ -120,7 +124,7 @@ def slow_i_from_v(v, photocurrent, saturation_current, resistance_series,
120124
def fast_i_from_v(v, photocurrent, saturation_current, resistance_series,
121125
resistance_shunt, nNsVth):
122126
"""
123-
This is a fast but unreliable way to find current given any voltage.
127+
This is a possibly faster way to find current given any voltage.
124128
"""
125129
if newton is NotImplemented:
126130
raise ImportError('This function requires scipy')
@@ -152,7 +156,7 @@ def slow_v_from_i(i, photocurrent, saturation_current, resistance_series,
152156
def fast_v_from_i(i, photocurrent, saturation_current, resistance_series,
153157
resistance_shunt, nNsVth):
154158
"""
155-
This is a fast but unreliable way to find voltage given any current.
159+
This is a possibly faster way to find voltage given any current.
156160
"""
157161
if newton is NotImplemented:
158162
raise ImportError('This function requires scipy')
@@ -187,7 +191,7 @@ def slow_mppt(photocurrent, saturation_current, resistance_series,
187191
def fast_mppt(photocurrent, saturation_current, resistance_series,
188192
resistance_shunt, nNsVth):
189193
"""
190-
This is a fast but unreliable way to find mpp.
194+
This is a possibly faster way to find mpp.
191195
"""
192196
if newton is NotImplemented:
193197
raise ImportError('This function requires scipy')

pvlib/test/test_singlediode_methods.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_fast_spr_e20_327():
2929
EgRef=1.121, dEgdT=-0.0002677)
3030
il, io, rs, rsh, nnsvt = x
3131
tstart = clock()
32-
pvs = pvsystem.singlediode(*x)
32+
pvs = pvsystem.singlediode(*x, method='lambertw')
3333
tstop = clock()
3434
dt_slow = tstop - tstart
3535
LOGGER.debug('single diode elapsed time = %g[s]', dt_slow)
@@ -43,13 +43,14 @@ def test_fast_spr_e20_327():
4343
assert np.isclose(pvs['i_sc'], isc)
4444
assert np.isclose(pvs['v_oc'], voc)
4545
# the singlediode method doesn't actually get the MPP correct
46-
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il)
47-
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il)
46+
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw')
47+
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw')
4848
assert np.isclose(pvs_imp, imp)
4949
assert np.isclose(pvs_vmp, vmp)
5050
assert np.isclose(pvs['p_mp'], pmp)
5151
assert np.isclose(pvs['i_x'], ix)
52-
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il)
52+
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il,
53+
method='lambertw')
5354
assert np.isclose(pvs_ixx, ixx)
5455
return isc, voc, imp, vmp, pmp, pvs
5556

@@ -64,7 +65,7 @@ def test_fast_fs_495():
6465
il, io, rs, rsh, nnsvt = x
6566
x += (101, )
6667
tstart = clock()
67-
pvs = pvsystem.singlediode(*x)
68+
pvs = pvsystem.singlediode(*x, method='lambertw')
6869
tstop = clock()
6970
dt_slow = tstop - tstart
7071
LOGGER.debug('single diode elapsed time = %g[s]', dt_slow)
@@ -78,13 +79,14 @@ def test_fast_fs_495():
7879
assert np.isclose(pvs['i_sc'], isc)
7980
assert np.isclose(pvs['v_oc'], voc)
8081
# the singlediode method doesn't actually get the MPP correct
81-
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il)
82-
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il)
82+
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw')
83+
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw')
8384
assert np.isclose(pvs_imp, imp)
8485
assert np.isclose(pvs_vmp, vmp)
8586
assert np.isclose(pvs['p_mp'], pmp)
8687
assert np.isclose(pvs['i_x'], ix)
87-
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il)
88+
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il,
89+
method='lambertw')
8890
assert np.isclose(pvs_ixx, ixx)
8991
return isc, voc, imp, vmp, pmp, i, v, p, pvs
9092

@@ -98,7 +100,7 @@ def test_slow_spr_e20_327():
98100
EgRef=1.121, dEgdT=-0.0002677)
99101
il, io, rs, rsh, nnsvt = x
100102
tstart = clock()
101-
pvs = pvsystem.singlediode(*x)
103+
pvs = pvsystem.singlediode(*x, method='lambertw')
102104
tstop = clock()
103105
dt_slow = tstop - tstart
104106
LOGGER.debug('single diode elapsed time = %g[s]', dt_slow)
@@ -112,13 +114,14 @@ def test_slow_spr_e20_327():
112114
assert np.isclose(pvs['i_sc'], isc)
113115
assert np.isclose(pvs['v_oc'], voc)
114116
# the singlediode method doesn't actually get the MPP correct
115-
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il)
116-
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il)
117+
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw')
118+
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw')
117119
assert np.isclose(pvs_imp, imp)
118120
assert np.isclose(pvs_vmp, vmp)
119121
assert np.isclose(pvs['p_mp'], pmp)
120122
assert np.isclose(pvs['i_x'], ix)
121-
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il)
123+
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il,
124+
method='lambertw')
122125
assert np.isclose(pvs_ixx, ixx)
123126
return isc, voc, imp, vmp, pmp, pvs
124127

@@ -133,7 +136,7 @@ def test_slow_fs_495():
133136
il, io, rs, rsh, nnsvt = x
134137
x += (101, )
135138
tstart = clock()
136-
pvs = pvsystem.singlediode(*x)
139+
pvs = pvsystem.singlediode(*x, method='lambertw')
137140
tstop = clock()
138141
dt_slow = tstop - tstart
139142
LOGGER.debug('single diode elapsed time = %g[s]', dt_slow)
@@ -147,13 +150,14 @@ def test_slow_fs_495():
147150
assert np.isclose(pvs['i_sc'], isc)
148151
assert np.isclose(pvs['v_oc'], voc)
149152
# the singlediode method doesn't actually get the MPP correct
150-
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il)
151-
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il)
153+
pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw')
154+
pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw')
152155
assert np.isclose(pvs_imp, imp)
153156
assert np.isclose(pvs_vmp, vmp)
154157
assert np.isclose(pvs['p_mp'], pmp)
155158
assert np.isclose(pvs['i_x'], ix)
156-
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il)
159+
pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il,
160+
method='lambertw')
157161
assert np.isclose(pvs_ixx, ixx)
158162
return isc, voc, imp, vmp, pmp, i, v, p, pvs
159163

0 commit comments

Comments
 (0)