def generate_numerical_precision(): # pragma: no cover """ Generate expected data with infinite numerical precision using SymPy. :return: dataframe of expected values """ if symbols is NotImplemented: LOGGER.critical("SymPy is required to generate expected data.") raise ImportError("could not import sympy") il, io, rs, rsh, nnsvt, vd = symbols('il, io, rs, rsh, nnsvt, vd') a = sy_exp(vd / nnsvt) b = 1.0 / rsh i = il - io * (a - 1.0) - vd * b v = vd - i * rs c = io * a / nnsvt grad_i = - c - b # di/dvd grad_v = 1.0 - grad_i * rs # dv/dvd # dp/dv = d(iv)/dv = v * di/dv + i grad = grad_i / grad_v # di/dv p = i * v grad_p = v * grad + i # dp/dv grad2i = -c / nnsvt grad2v = -grad2i * rs grad2p = ( grad_v * grad + v * (grad2i/grad_v - grad_i*grad2v/grad_v**2) + grad_i ) # generate exact values data = dict(zip((il, io, rs, rsh, nnsvt), ARGS)) vdtest = np.linspace(0, estimate_voc(IL, I0, NNSVTH), IVCURVE_NPTS) expected = [] for test in vdtest: data[vd] = test test_data = { 'i': np.float64(i.evalf(subs=data)), 'v': np.float64(v.evalf(subs=data)), 'p': np.float64(p.evalf(subs=data)), 'grad_i': np.float64(grad_i.evalf(subs=data)), 'grad_v': np.float64(grad_v.evalf(subs=data)), 'grad': np.float64(grad.evalf(subs=data)), 'grad_p': np.float64(grad_p.evalf(subs=data)), 'grad2p': np.float64(grad2p.evalf(subs=data)) } LOGGER.debug(test_data) expected.append(test_data) return pd.DataFrame(expected, index=vdtest)
def generate_numerical_precision(): """ Generate expected data with infinite numerical precision using SymPy. :return: dataframe of expected values """ if symbols is NotImplemented: LOGGER.critical("SymPy is required to generate expected data.") raise ImportError("could not import sympy") il, io, rs, rsh, nnsvt, vd = symbols('il, io, rs, rsh, nnsvt, vd') a = sy_exp(vd / nnsvt) b = 1.0 / rsh i = il - io * (a - 1.0) - vd * b v = vd - i * rs c = io * a / nnsvt grad_i = - c - b # di/dvd grad_v = 1.0 - grad_i * rs # dv/dvd # dp/dv = d(iv)/dv = v * di/dv + i grad = grad_i / grad_v # di/dv p = i * v grad_p = v * grad + i # dp/dv grad2i = -c / nnsvt grad2v = -grad2i * rs grad2p = ( grad_v * grad + v * (grad2i/grad_v - grad_i*grad2v/grad_v**2) + grad_i ) # generate exact values data = dict(zip((il, io, rs, rsh, nnsvt), ARGS)) vdtest = np.linspace(0, estimate_voc(IL, I0, NNSVTH), IVCURVE_NPTS) expected = [] for test in vdtest: data[vd] = test test_data = { 'i': np.float64(i.evalf(subs=data)), 'v': np.float64(v.evalf(subs=data)), 'p': np.float64(p.evalf(subs=data)), 'grad_i': np.float64(grad_i.evalf(subs=data)), 'grad_v': np.float64(grad_v.evalf(subs=data)), 'grad': np.float64(grad.evalf(subs=data)), 'grad_p': np.float64(grad_p.evalf(subs=data)), 'grad2p': np.float64(grad2p.evalf(subs=data)) } LOGGER.debug(test_data) expected.append(test_data) return pd.DataFrame(expected, index=vdtest)