|
| 1 | +""" |
| 2 | +ASV benchmarks for singlediode.py |
| 3 | +""" |
| 4 | +from numpy.random import Generator, MT19937 |
| 5 | +from pvlib import singlediode as _singlediode |
| 6 | + |
| 7 | +seed = 11471 |
| 8 | + |
| 9 | +rng = Generator(MT19937(seed)) |
| 10 | +base_params = (1., 5.e-9, 0.5, 2000., 72 * 1.1 * 0.025) |
| 11 | +nsamples = 10000 |
| 12 | + |
| 13 | + |
| 14 | +def b88(params): |
| 15 | + # for a fair comparison, need to also compute isc, voc, i_x and i_xx |
| 16 | + isc = _singlediode.bishop88_i_from_v(0., *params) |
| 17 | + voc = _singlediode.bishop88_v_from_i(0., *params) |
| 18 | + imp, vmp, pmp = _singlediode.bishop88_mpp(*params) |
| 19 | + ix = _singlediode.bishop88_i_from_v(vmp/2., *params) |
| 20 | + ixx = _singlediode.bishop88_i_from_v((voc + vmp)/2., *params) |
| 21 | + return imp, vmp, pmp, isc, voc, ix, ixx |
| 22 | + |
| 23 | + |
| 24 | +class SingleDiode: |
| 25 | + |
| 26 | + def setup(self, base_params, nsamples): |
| 27 | + self.il = 9 * rng(nsamples) + 1. # 1.- 10. A |
| 28 | + self.io = 10**(-9 + 3. * rng(nsamples)) # 1e-9 to 1e-6 A |
| 29 | + self.rs = 5 * rng(nsamples) + 0.05 # 0.05 to 5.05 Ohm |
| 30 | + self.rsh = 10**(2 + 2 * rng(nsamples)) # 100 to 10000 Ohm |
| 31 | + self.n = 1 + 0.7 * rng(nsamples) # 1.0 to 1.7 |
| 32 | + self.nNsVth = 72 * self.n * 0.025 # 72 cells in series, roughly 25C Tcell |
| 33 | + self.params = (self.il, self.io, self.rs, self.rsh, self.nNsVth) |
| 34 | + |
| 35 | + def bishop88(self): |
| 36 | + b88(*self.params) |
| 37 | + |
| 38 | + def lambertw(self): |
| 39 | + _singlediode.lambertw(*self.params) |
0 commit comments