Skip to content

add v_from_i, improve singlediode speed by 2x #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 14, 2016

Conversation

wholmgren
Copy link
Member

I implemented a v_from_i function, similar to i_from_v, by following Jain and Kapoor (2004) and PVLIB MATLAB pvl_singlediode.m. This lets us replace the singlediode function's numerical solver for v_oc with an analytic solution. Thus, the singlediode function is about 2x faster.

The analytic solution differs from the numerical solution by a little more than 1 part in 1000, which is similar to the tolerance of the _golden_sect_DataFrame numerical solver.

@wholmgren wholmgren added this to the 0.3.3 milestone Jun 13, 2016
@cwhanse
Copy link
Member

cwhanse commented Jun 13, 2016

Will,
For v_from_i be sure to test for a module with a high value of Voc, e.g., Rsh = 500, Rs = 10, nNsVth = 4.06 (n = 1.4, Ns = 116, Vth = 0.025), Io = 6e-10, Iph = 1.2. These values should give Voc around 90 and are representative of a CdTe module.

The numerical issue is to handle overflow in the lambertw function.

Cliff

@cwhanse
Copy link
Member

cwhanse commented Jun 13, 2016

What do you think about replacing the golden section determination of Pmp by a lambertw approach? Is the Pmp determination the limiting performance step in this subroutine? We used a Pmp from lambertw approach in PVLib matlab to get past a piece of custom optimization for which we couldn't release source code. It still uses an iteration so maybe we can reuse the golden section search code.

@wholmgren
Copy link
Member Author

The Pmp determination is the limiting step and it would be great to speed it up in any way.

Over the weekend I benchmarked some of Scipy's optimization routines for Pmp but could not find anything as fast as what we already have. The fastest was scipy.optimize.fmin_tnc and it was 50% slower than our method. I also implemented a dpower/dcurrent function based on Jain and Kapoor and supplied it to the optimization routines. If I remember correctly, the optimizer is about twice as slow if it has to compute the gradients numerically, though it varies a bit depending on which optimizer you choose.

In any case, I pushed what I did to my scipyoptimize branch. Here's the crux of it: https://github.com/wholmgren/pvlib-python/blob/scipyoptimize/pvlib/pvsystem.py#L1422

It might be possible to speed up that loop with multithreading or numba JIT. That scipy function should release the GIL and allow for efficient multithreading, but it won't make any difference if the functions that it's calling are Python functions. It might not be too hard to write the these simple functions in cython, though. The first thing I would do is decorate the function with numba.jit and see if it helps (see spa.py for examples, though it does a little bit of work first to avoid making numba a pvlib requirement). If that's all new to you, then welcome to Python's multithreading hell.

@wholmgren
Copy link
Member Author

I added test_v_from_i_big with your parameters and it passed on my 64 bit mac and the 32 bit appveyor windows build. Would that have failed on matlab?

@cwhanse
Copy link
Member

cwhanse commented Jun 14, 2016

Matlab PVLib currently uses a bisection to find Vmp, then gets Imp from Vmp. Its faster than the Matlab root finder, and guarantees convergence. The function operated on by the bisection (to find a zero) involves Lamberts W.

I can implement in python next week (I hope) when I’m back from catching fish.

Cliff

@wholmgren
Copy link
Member Author

Great, thanks. I'm going to merge this in the meantime.

@wholmgren wholmgren merged commit 5bf127e into pvlib:master Jun 14, 2016
@wholmgren wholmgren deleted the vfromi branch June 28, 2016 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants