Skip to content

Commit 3534864

Browse files
committed
start at mismatch.py
1 parent 9505a0a commit 3534864

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

pvlib/mismatch.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
Contains functions for solving for DC power in arrays with mismatched conditions.
3+
4+
"""
5+
import numpy as np
6+
import singlediode as _singlediode
7+
8+
9+
def _iv_series_lambertw(photocurrent, saturation_current, resistance_series,
10+
resistance_shunt, nNsVth, neg_v_limit=None,
11+
delta_i=0.001):
12+
r'''Solve the IV curve for series-connected devices using a single diode
13+
equivalent circuit model.
14+
15+
Uses a simplified model for reverse bias behavior, where current is
16+
unbounded at a constant reverse bias voltage ``neg_v_limit``.
17+
18+
Input parameters photocurrent, saturation_current, resistance_series,
19+
resistance_shunt, nNsVth may be arrays. If arrays, all must be
20+
broadcastable to a common shape. The first dimension of each array
21+
is time. The 2nd dimension is devices in series.
22+
23+
Parameters
24+
----------
25+
photocurrent : numeric
26+
photocurrent (A).
27+
saturation_current : numeric
28+
saturation current (A).
29+
resistance_series : numeric
30+
series resistance (ohm).
31+
resistance_shunt : numeric
32+
shunt resistance (ohm).
33+
nNsVth : numeric
34+
product of diode factor n, number of series cells Ns, and
35+
thermal voltage (Vth), (V).
36+
neg_v_limit : float, optional
37+
Limit on reverse bias voltage, from cell breakdown voltage or reverse
38+
bias diode activation voltage (V). Should be negative. For example,
39+
if neg_v_limit=-5, then at V=-5 current is unbounded in the positive
40+
direction.
41+
delta_i : float, optional
42+
Width of interval used to discretize current (A).
43+
44+
Returns
45+
-------
46+
None.
47+
48+
'''
49+
# solve for Isc
50+
isc = _singlediode._lambertw_i_from_v(
51+
0., photocurrent, saturation_current, resistance_series,
52+
resistance_shunt, nNsVth)
53+
54+
# discretize current from max(Isc) down to 0.
55+
currents = np.arange(isc.max(), 0., step=-delta_i)
56+
57+
# shape all the arrays
58+
# target shape is ntimes x ndevices x ncurrents
59+
# use a dict so we can add axes using a loop
60+
params = {'photocurrent': photocurrent,
61+
'saturation_current': saturation_current,
62+
'resistance_series': resistance_series,
63+
'resistance_shunt': resistance_shunt,
64+
'nNsVth': nNsVth}
65+
66+
for p in params:
67+
if not isinstance(params[p], np.ndarray):
68+
pass # float, int
69+
if len(params[p].shape) == 1:
70+
params[p] = params[p][:, np.newaxis, np.newaxis]
71+
elif len(params[p].shape) == 2:
72+
params[p] = params[p][:, :, np.newaxis]
73+
else:
74+
pass # already 3d
75+
76+
il, io, rs, rsh, a = (params[p] for p in params)
77+
78+
currents = currents[np.newaxis, np.newaxis, :]
79+
80+
il, io, rs, rsh, a, currents = np.broadcast_arrays(
81+
il, io, rs, rsh, a, currents)
82+
83+
# solve voltages at each current for each IV curve
84+
voltages = _singlediode._lambertw_v_from_i(
85+
currents, il, io, rs, rsh, a)
86+
87+
# apply negative voltage limit
88+
if neg_v_limit is not None:
89+
voltages[voltages < neg_v_limit] = neg_v_limit
90+
91+
# add voltage at common current to get series voltage
92+
voltage_sum = voltages.sum(axis=1)
93+
94+
# drop currents dimension for devices
95+
currents = currents[:, 0, :]
96+
97+
return voltage_sum, currents

0 commit comments

Comments
 (0)