Skip to content

critical error in singlediode p_mp calculation #221

Closed
@wholmgren

Description

@wholmgren

Bad news. I discovered a major error in the singlediode p_mp calculation: given a time series input, the numerical solver exits if the solution for any single time is within the error tolerance, rather than requiring that the solution for all times be close enough. The error is in this line.

Here's some sample code:

photocurrent = np.linspace(0, 10, 11)
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09

sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd['i_mp']
array([ 0.        ,  0.59453544,  1.56145498,  2.54105091,  3.52353436,
        4.50658749,  5.4890739 ,  6.47016579,  7.44909413,  8.42504244,
        9.39708533])

# change .all() to .any()

pvsystem = reload(pvlib.pvsystem)

sd_any = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd_any['i_mp']
array([ 0.        ,  0.54538398,  1.43273966,  2.36328163,  3.29255606,
        4.23101358,  5.16177031,  6.09368251,  7.02197553,  7.96846051,
        8.88220557])

sd['i_mp']/sd_any['i_mp']
array([        nan,  1.09012266,  1.0898386 ,  1.07522137,  1.07015167,
        1.06513189,  1.06340917,  1.06178256,  1.06082599,  1.05729864,
        1.05796756])

sd['p_mp']/sd_any['p_mp']
array([        nan,  0.98250248,  0.92482996,  0.91242588,  0.91052337,
        0.91256532,  0.9165425 ,  0.92159883,  0.92731275,  0.93339723,
        0.93974898])

So the error here is on the order of 5 to 10%, but the results will depend on your exact input.

The blue dots on the IV curve below show the p_mp points in the old code. The black dots show the p_mp points in fixed code. These IV curves are generated using a fix for #83 that I'll make a PR for soon. They're also what led me to discovering the problem.

ivcurves

On a related note, someone should put more effort into verifying that the matlab and python libraries give the same results. Not me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions