|
5 | 5 | from numpy import nan, array |
6 | 6 | import pandas as pd |
7 | 7 | import scipy.constants |
| 8 | +import scipy.optimize |
8 | 9 |
|
9 | 10 | import pytest |
10 | 11 | from .conftest import ( |
|
13 | 14 | import unittest.mock as mock |
14 | 15 |
|
15 | 16 | from pvlib import inverter, pvsystem |
16 | | -from pvlib import atmosphere |
17 | 17 | from pvlib import iam as _iam |
18 | 18 | from pvlib import irradiance |
19 | 19 | from pvlib import spectrum |
@@ -2648,48 +2648,31 @@ def test_max_power_point_mismatched(inputs): |
2648 | 2648 | print(result) |
2649 | 2649 |
|
2650 | 2650 |
|
2651 | | -@pytest.mark.parametrize( |
2652 | | - 'inputs', |
2653 | | - [ |
2654 | | - { |
2655 | | - "photocurrent": -6.2, # This is bad. |
2656 | | - "saturation_current": 1.0e-8, |
2657 | | - "n": 1.1, |
2658 | | - "resistance_series": 0.0001, |
2659 | | - "resistance_shunt": 5000.0, |
2660 | | - "Ns": 60, |
2661 | | - "T": 25.0, |
2662 | | - }, |
2663 | | - { |
2664 | | - "photocurrent": -6.2, # This is bad. |
2665 | | - "saturation_current": 1.0e-8, |
2666 | | - "n": 1.1, |
2667 | | - "resistance_series": 0.0001, |
2668 | | - "resistance_shunt": 5000.0, |
2669 | | - "Ns": 60, |
2670 | | - "T": 25.0, |
2671 | | - "i_mp_ic": 5.6, |
2672 | | - }, |
2673 | | - ] |
2674 | | -) |
2675 | | -def test_max_power_point_mismatched_exception(inputs, monkeypatch): |
2676 | | - """ |
2677 | | - Test errored max power point computation for mismatched devices in series. |
2678 | | - """ |
2679 | | - # Monkey patch the objective function to force thrown exception. |
| 2651 | +def test_max_power_point_mismatched_unsuccessful_solver(monkeypatch): |
| 2652 | + """Test errored max power point computation where solver is unsuccessful.""" |
| 2653 | + photocurrent = 6.2 |
| 2654 | + saturation_current = 1.0e-8 |
| 2655 | + resistance_series = 0.0001 |
| 2656 | + resistance_shunt = 5000.0 |
| 2657 | + n = 1.1 |
| 2658 | + Ns = 60 |
| 2659 | + T = 25.0 |
| 2660 | + T_K = scipy.constants.convert_temperature(T, "Celsius", "Kelvin") |
| 2661 | + k_B_J_per_K = scipy.constants.value("Boltzmann constant") |
| 2662 | + q_C = scipy.constants.value("elementary charge") |
| 2663 | + nNsVth = n * Ns * k_B_J_per_K * T_K / q_C |
| 2664 | + |
| 2665 | + def minimize_monkeypatched(*_, **__): |
| 2666 | + """Return an unsuccessful solution from solver.""" |
| 2667 | + return scipy.optimize.OptimizeResult(success=False) |
| 2668 | + |
| 2669 | + # Monkey patch solver to return unsuccessfully. |
2680 | 2670 | monkeypatch.setattr( |
2681 | | - "pvlib.pvsystem._negative_total_power", ZeroDivisionError |
| 2671 | + scipy.optimize, |
| 2672 | + "minimize", |
| 2673 | + minimize_monkeypatched, |
2682 | 2674 | ) |
2683 | 2675 |
|
2684 | | - photocurrent = inputs["photocurrent"] |
2685 | | - saturation_current = inputs["saturation_current"] |
2686 | | - resistance_series = inputs["resistance_series"] |
2687 | | - resistance_shunt = inputs["resistance_shunt"] |
2688 | | - q_C = scipy.constants.value("elementary charge") |
2689 | | - k_B_J_per_K = scipy.constants.value("Boltzmann constant") |
2690 | | - T_K = scipy.constants.convert_temperature(inputs["T"], "Celsius", "Kelvin") |
2691 | | - nNsVth = inputs["n"] * inputs["Ns"] * k_B_J_per_K * T_K / q_C |
2692 | | - |
2693 | 2676 | with pytest.raises(RuntimeError) as e_info: |
2694 | 2677 | pvsystem.max_power_point_mismatched( |
2695 | 2678 | photocurrent, |
|
0 commit comments