Repository navigation
Villalva Algorithm Pull Request #2878
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
base: main
Are you sure you want to change the base?
Changes from all commits
8698c7a
f468215
16beb52
07654d1
547f679
5f29b13
51fdd23
eb878f6
386c004
308fe5f
e8b541e
994732b
1b6898d
1b638ac
0ed22d0
eb33c3e
c37846c
6ffbb12
e3f6400
2ebcb2d
9ea7601
5a7ea02
d18881d
01f0585
09b970e
6b62931
7307b50
af96cee
534df7c
a3f1f99
07359d8
05aa194
6386ac6
c0de33a
d397546
23514ad
7832f4f
d997727
a2ea5f4
7bd8710
f63ba4a
bc3194c
66e2940
9a73adc
15a99ec
dc4d8d8
4d7e32e
2d9d7e4
2b4b251
4d348a6
4d4750b
49dc684
ab3c2b3
41147f8
236006f
11e805d
afb4610
b2d2a2e
3328b18
9bc78b9
99b9479
c045293
975e7b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,281 @@ | ||
| """Functions for fitting the Villalva single-diode model.""" | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
| from scipy import constants | ||
|
|
||
| from pvlib import pvsystem | ||
|
|
||
|
|
||
| def _villalva_params_at_rs( | ||
| resistance_series, | ||
| v_mp, | ||
| i_mp, | ||
| v_oc, | ||
| i_sc, | ||
| a_ref, | ||
| ): | ||
| """Calculate ``I_L``, ``I_o`` and ``R_sh`` for each candidate ``R_s``.""" | ||
| exp_voc = np.expm1(v_oc / a_ref) | ||
| exp_vmp = np.expm1((v_mp + i_mp * resistance_series) / a_ref) | ||
|
|
||
| p_mp = v_mp * i_mp | ||
|
|
||
| # Algebraic combination of Villalva's equations: | ||
| # | ||
| # I_L = (R_sh + R_s) / R_sh * I_sc | ||
| # | ||
| # I_o = (I_L - V_oc / R_sh) / (exp(V_oc / a_ref) - 1) | ||
| # | ||
| # and the R_sh(R_s) relation obtained at the MPP. | ||
| a_term = ( | ||
| v_mp * i_sc | ||
| - v_mp * i_sc * exp_vmp / exp_voc | ||
| - p_mp | ||
| ) | ||
|
|
||
| b_term = ( | ||
| v_mp * i_sc * resistance_series | ||
| - v_mp | ||
| * (i_sc * resistance_series - v_oc) | ||
| * exp_vmp | ||
| / exp_voc | ||
| ) | ||
|
|
||
| resistance_shunt = ( | ||
| v_mp * (v_mp + i_mp * resistance_series) - b_term | ||
| ) / a_term | ||
|
|
||
| photocurrent = ( | ||
| (resistance_shunt + resistance_series) | ||
| / resistance_shunt | ||
| * i_sc | ||
| ) | ||
|
|
||
| saturation_current = ( | ||
| photocurrent - v_oc / resistance_shunt | ||
| ) / exp_voc | ||
|
Comment on lines
+56
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This equation differs from Equation 6 in the manuscript, what is the reason? Here the photocurrent is used over the short-circuit current, and Lots of discussion here, not sure if this was covered already... feel free to point me in the direction of the discussion if it already took place. |
||
|
|
||
| return photocurrent, saturation_current, resistance_shunt | ||
|
|
||
|
|
||
| def fit_villalva( | ||
| v_mp, | ||
| i_mp, | ||
| v_oc, | ||
| i_sc, | ||
| alpha_sc, | ||
| beta_voc, | ||
| cells_in_series, | ||
| diode_factor, | ||
| temp_ref=25.0, | ||
| irrad_ref=1000.0, | ||
| rs_step=1e-4, | ||
| rs_max=None, | ||
| ): | ||
| r"""Fit Villalva single-diode model to datasheet values. | ||
|
|
||
| Parameter extraction for Villalva's single-diode model [1]_ is | ||
| described in [2]_. Parameter estimation increments the series | ||
| resistance from zero. For each candidate :math:`R_s`, the | ||
| corresponding :math:`R_{sh}`, :math:`I_L`, and :math:`I_0` are | ||
| calculated, and the maximum power of the resulting single-diode | ||
| equation is evaluated. The returned parameter solution minimizes | ||
| the absolute difference between the modeled maximum power and the | ||
| datasheet maximum power at reference conditions. | ||
|
|
||
| The dimensionless diode ideality factor :math:`n` is supplied by the user. | ||
| The modified ideality factor at reference conditions is calculated as | ||
|
|
||
| .. math:: | ||
|
|
||
| a_{ref} = n N_s k T_{ref} / q. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| v_mp : float | ||
| Maximum-power voltage at reference conditions. [V] | ||
| i_mp : float | ||
| Maximum-power current at reference conditions. [A] | ||
| v_oc : float | ||
| Open-circuit voltage at reference conditions. [V] | ||
| i_sc : float | ||
| Short-circuit current at reference conditions. [A] | ||
| alpha_sc : float | ||
| Short-circuit current temperature coefficient. [A/K] | ||
| beta_voc : float | ||
| Open-circuit voltage temperature coefficient. [V/K] | ||
| cells_in_series : int | ||
| Effective number of cells or junctions connected in series. | ||
| diode_factor : float | ||
| Dimensionless diode ideality factor. [unitless] | ||
| temp_ref : float, default 25 | ||
| Reference cell temperature. [°C] | ||
| irrad_ref : float, default 1000 | ||
| Reference irradiance. [Wm⁻²] | ||
| rs_step : float, default 1e-4 | ||
| Increment used for the series-resistance sweep. [ohm] | ||
| rs_max : float, optional | ||
| Maximum series resistance considered. If ``None``, ``v_oc / i_sc`` | ||
| is used. [ohm] | ||
|
|
||
| Returns | ||
| ------- | ||
| params : dict | ||
| Fitted reference-condition Villalva parameters. The dictionary | ||
| contains ``I_L_ref``, ``I_o_ref``, ``R_s``, ``R_sh_ref``, ``a_ref``, | ||
| ``alpha_sc``, ``beta_voc``, ``i_sc_ref``, ``v_oc_ref``, | ||
| ``irrad_ref``, and ``temp_ref``. | ||
| history : pandas.DataFrame | ||
| Full fitting history for all valid values of ``R_s`` evaluated by the | ||
| algorithm. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the minimum shunt resistance is not positive. | ||
| RuntimeError | ||
| If no valid solution is found. | ||
|
|
||
| Notes | ||
| ----- | ||
| The returned reference parameters are intended for use with | ||
| :py:func:`pvlib.pvsystem.calcparams_villalva`. I-V curve points can then | ||
| be calculated with :py:func:`pvlib.pvsystem.singlediode` or | ||
| :py:func:`pvlib.pvsystem.i_from_v`. | ||
|
Comment on lines
+141
to
+146
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure where the right place for this is, maybe here, but could we add a note on the use of different variable names compared to the manuscript? Just something brief to note a few examples e.g. |
||
|
|
||
| References | ||
| ---------- | ||
| .. [1] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho, "Comprehensive | ||
| approach to modeling and simulation of photovoltaic arrays," IEEE Trans. | ||
| Power Electron., vol. 24, no. 5, pp. 1198-1208, May 2009. | ||
| :doi:`10.1109/TPEL.2009.2013862` | ||
| .. [2] M. G. Villalva, "Conversor eletrônico de potência trifásico para | ||
| sistema fotovoltaico conectado à rede elétrica," Ph.D. dissertation, | ||
| Faculdade de Engenharia Elétrica e de Computação, Universidade Estadual | ||
| de Campinas (UNICAMP), Campinas, Brazil, 2010. | ||
| :doi:`10.47749/T/UNICAMP.2010.781324` | ||
| """ | ||
|
JFrederico2022 marked this conversation as resolved.
Resolved
|
||
| temp_ref_k = temp_ref + 273.15 | ||
|
|
||
| # a_ref = a * Ns * kT/q | ||
| a_ref = ( | ||
| diode_factor | ||
| * cells_in_series | ||
| * constants.k | ||
| * temp_ref_k | ||
| / constants.e | ||
| ) | ||
|
|
||
| p_mp_ref = v_mp * i_mp | ||
|
|
||
| # Villalva minimum shunt resistance (Eq. 11 in [1]). | ||
| r_sh_min = v_mp / (i_sc - i_mp) - (v_oc - v_mp) / i_mp | ||
|
|
||
| if r_sh_min <= 0: | ||
| raise ValueError( | ||
| "Invalid module specifications: the calculated minimum " | ||
| "shunt resistance is non-positive. Check the consistency " | ||
| "of v_mp, i_mp, v_oc, and i_sc." | ||
| ) | ||
|
|
||
| if rs_max is None: | ||
| rs_max = v_oc / i_sc | ||
|
|
||
| rs_values = np.arange(0.0, rs_max + 0.5 * rs_step, rs_step) | ||
|
|
||
| # Calculate parameters for all candidate series resistances. | ||
| with np.errstate(divide="ignore", invalid="ignore", over="ignore"): | ||
| photocurrent, saturation_current, resistance_shunt = ( | ||
| _villalva_params_at_rs( | ||
| rs_values, | ||
| v_mp, | ||
| i_mp, | ||
| v_oc, | ||
| i_sc, | ||
| a_ref, | ||
| ) | ||
| ) | ||
|
|
||
| # Exclude non-finite and physically invalid parameters. | ||
| valid = ( | ||
| np.isfinite(photocurrent) | ||
| & np.isfinite(saturation_current) | ||
| & np.isfinite(resistance_shunt) | ||
| & (resistance_shunt >= r_sh_min) | ||
| & (photocurrent > 0) | ||
| & (saturation_current > 0) | ||
| ) | ||
|
|
||
| if not np.any(valid): | ||
| raise RuntimeError("No valid Villalva solution was found.") | ||
|
|
||
| rs_values = rs_values[valid] | ||
| photocurrent = photocurrent[valid] | ||
| saturation_current = saturation_current[valid] | ||
| resistance_shunt = resistance_shunt[valid] | ||
|
|
||
| # Calculate the maximum power point for all valid candidates. | ||
| with np.errstate(divide="ignore", invalid="ignore", over="ignore"): | ||
| mpp = pvsystem.max_power_point( | ||
| photocurrent=photocurrent, | ||
| saturation_current=saturation_current, | ||
| resistance_series=rs_values, | ||
| resistance_shunt=resistance_shunt, | ||
| nNsVth=a_ref, | ||
| method="brentq", | ||
| ) | ||
|
|
||
| v_mp_model = np.asarray(mpp["v_mp"]) | ||
| i_mp_model = np.asarray(mpp["i_mp"]) | ||
| p_mp_model = np.asarray(mpp["p_mp"]) | ||
|
|
||
| power_error = p_mp_model - p_mp_ref | ||
|
|
||
| # Exclude non-finite maximum power point results. | ||
| valid_mpp = ( | ||
| np.isfinite(v_mp_model) | ||
| & np.isfinite(i_mp_model) | ||
| & np.isfinite(p_mp_model) | ||
| & np.isfinite(power_error) | ||
| ) | ||
|
|
||
| if not np.any(valid_mpp): | ||
| raise RuntimeError( | ||
| "The fitted Villalva SDM parameters resulted in " | ||
| "invalid maximum power point (MPP) values." | ||
| ) | ||
|
|
||
| history = pd.DataFrame( | ||
| { | ||
| "R_s": rs_values[valid_mpp], | ||
| "R_sh_ref": resistance_shunt[valid_mpp], | ||
| "I_L_ref": photocurrent[valid_mpp], | ||
| "I_o_ref": saturation_current[valid_mpp], | ||
| "v_mp_model": v_mp_model[valid_mpp], | ||
| "i_mp_model": i_mp_model[valid_mpp], | ||
| "p_mp_model": p_mp_model[valid_mpp], | ||
| "p_mp_ref": p_mp_ref, | ||
| "power_error": power_error[valid_mpp], | ||
| "abs_power_error": np.abs(power_error[valid_mpp]), | ||
| } | ||
| ) | ||
|
|
||
| best = history.loc[history["abs_power_error"].idxmin()] | ||
|
|
||
| params = { | ||
| "I_L_ref": float(best["I_L_ref"]), | ||
| "I_o_ref": float(best["I_o_ref"]), | ||
| "R_s": float(best["R_s"]), | ||
| "R_sh_ref": float(best["R_sh_ref"]), | ||
| "a_ref": float(a_ref), | ||
| "alpha_sc": alpha_sc, | ||
| "beta_voc": beta_voc, | ||
| "i_sc_ref": i_sc, | ||
| "v_oc_ref": v_oc, | ||
| "irrad_ref": irrad_ref, | ||
| "temp_ref": temp_ref, | ||
| } | ||
|
|
||
| return params, history | ||
Uh oh!
There was an error while loading. Please reload this page.