pvlib / pvlib-python

A set of documented functions for simulating the performance of photovoltaic energy systems.
https://pvlib-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.21k stars 1.01k forks source link

WIP: Convert between CEC and PVsyst single diode models #2212

Open cwhanse opened 2 months ago

cwhanse commented 2 months ago

Primary reference is in review. Feedback on function naming and signature is welcome.

adriesse commented 2 months ago

Feedback on function naming and signature is welcome.

I guess one might discuss whether you are converting models or sets of parameters.

cwhanse commented 1 month ago

Test failure for ubuntu-latest, 3.8, conda, -min is because that environment installs scipy=1.6.0, which doesn't allow for constraints when using Nelder-Mead, so the optimizer gets a different, unsatisfactory, solution.

echedey-ls commented 1 month ago

I guess one might discuss whether you are converting models or sets of parameters.

@adriesse , do you have any proposal in mind? For example, cec_params_to_pvsyst, params[_from]_pvsyst_to_cec [params_pvsyst2cec]. I don't really have a strong preference on wording.

scipy=1.6.0, which doesn't allow for constraints when using Nelder-Mead

scipy=1.7.0 is the first version to support it, and is also supported in Py3.9 (taking into account upcoming drop of Py3.8 support). I would edit this requirement for future >=Py3.9 release (#2213).

Source of scipy docs on nelder-mead; scipy 1.6.3 bumps to 1.7.0:

mikofski commented 1 month ago

Is the simplex solver required? Why not try Powell instead?

cwhanse commented 1 month ago

Is the simplex solver required? Why not try Powell instead?

@leliadeville

leliadeville commented 1 month ago

Is the simplex solver required? Why not try Powell instead?

@mikofski I used Nelder-Mead to develop and check the algorithm, but I think the optimization method would be good to have as a parameter.

mikofski commented 1 month ago

Any particular reason for choosing Simplex? Good idea to make method a parameter. I would be curious to see how other methods like Powell compare. My experience is that the system of equations is stiff and requires some transformation to improve the condition. An excellent primer for selecting methods is https://gael-varoquaux.info/scipy-lecture-notes/advanced/mathematical_optimization/index.html#choosing-a-method

cwhanse commented 1 month ago

For context, here's the submitted paper. The main point is determining that optimization is preferred over two other techniques (functions currently in pvlib, and an approach that equates quantities that should have the same values at the reference condition.) The optimization could certainly be tuned and improved.

sdm_translation_submitted.pdf

mikofski commented 1 month ago

The main point is determining that optimization is preferred …

I agree 💯. I wrote a blog on using implicit methods to solve SDM system of equations with several gists comparing using convex optimization after transforming the variables to improve the condition of the Jacobian to explicit methods using Bishop’s method. Because the equations are differential I used the SciPy wrapper around the MINPACK FORTRAN HYBRDJ solver but other solvers might be more efficient.

mikofski commented 1 month ago

I understand now, after reading the paper. This is a method of directly obtaining parameters without generating an IEC-61853 matrix as the go between first. Very clever! So the minimization method of the objective function is secondary, and there are no variables to transform. Thanks for patiently explaining. Great job @leliadeville

cwhanse commented 1 month ago

This is a method of directly obtaining parameters without generating an IEC-61853 matrix as the go between first.

I may be misunderstanding, but generating the IEC-61853 matrix data for the source model is the first step. The target model's parameters are found by fitting the target model to the IEC-61853 matrix data.

mikofski commented 1 month ago

You are right. Sorry I misread. Looking again, this does solve each model independently from the matrix. Honestly I’m not sure what I was thinking before.

However, I think it would be interesting to see by comparison a method that does use the Jacobian, similar to what I discussed in the gist linked above or in PVMismatch gen_coeffs(), the two approaches differ by single and two diode model, but both transform the variables into either parabolic or log space and then use a gradient search method to solve the convex optimization problem. The method may suffer from poor initial guess but typically converges faster than simplex. Anyway, there is no publication, so I apologize for ranting. Thanks.