Demo entry 6776843

Single Diode Equation

   

Submitted by anonymous on Dec 04, 2018 at 19:25
Language: Python. Code size: 2.7 kB.

# -*- coding: utf-8 -*-
"""
Created on Wed Nov  7 18:56:30 2018

@author: alvar
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy import constants as cte
from scipy import optimize

def sdmIfromV(diodeVoltage, photoCurrent, saturationCurrent, seriesResistance, shuntResistance, nNsVth):
    
    def iPrime_prev(i_):
        ans = saturationCurrent * seriesResistance / nNsVth
        ans = ans * np.exp((diodeVoltage + i_ * seriesResistance)/nNsVth)
#        print("fPrime: " + str(-1 - ans - seriesResistance / shuntResistance))
        return -1 - ans - seriesResistance / shuntResistance
    
    def i_prev(i_):
        diodeCurrent = saturationCurrent * np.expm1((diodeVoltage + i_ * seriesResistance)/nNsVth)
        shuntCurrent = (diodeVoltage + i_ * seriesResistance) / shuntResistance
#        print("diodeCurrent: " + str(diodeCurrent) + " shuntCurrent: "+ str(shuntCurrent) + " func: " + str(photoCurrent - i_ - diodeCurrent - shuntCurrent))
        return photoCurrent - i_ - diodeCurrent - shuntCurrent  
    
    i = optimize.newton(i_prev, 0, iPrime_prev)
    return i

def sdmAproxVoc(photoCurrent, saturationCurrent, nNsVth):
    return nNsVth * np.log((photoCurrent) / saturationCurrent + 1.0);

if __name__ == '__main__':
    
    nslices = 200
    TaC = 25    #para calcular Vth
    
    
    model = "KC200GT"
#    model = "SF-160-24-M175a"
#    model = "CNPV-280P"
    
    if(model == "KC200GT"):
        photoCurrent = 8.2
        saturationCurrent = 1.05 *(10**-9)
        seriesResistance = 4.85 * (10**-3)
        shuntResistance = np.inf
        n = 1.05
        Ns = 54
    elif(model == "SF-160-24-M175a"):
        photoCurrent = 5.18
        saturationCurrent = 10.2 *(10**-9)
        seriesResistance = 7.1 * (10**-3)
        shuntResistance = np.inf
        n = 1.2
        Ns = 72
    elif(model == "CNPV-280P"):
        photoCurrent = 8.19
        saturationCurrent = 0.27 *(10**-9)
        seriesResistance = 4.2 * (10**-3)
        shuntResistance = np.inf
        n = 1
        Ns = 54
    
    
    TaK = 273 + TaC
    Vth = cte.Boltzmann * TaK / cte.electron_volt 
    voc = sdmAproxVoc(photoCurrent, saturationCurrent, n * Ns * Vth)
    v = np.linspace(0,voc,nslices)
    i = np.empty(nslices)
    for a in range(nslices):
        i[a] = sdmIfromV(v[a], photoCurrent, saturationCurrent, seriesResistance,
         shuntResistance, n * Ns * Vth)
        if i[a] <= 0:
            i[a] = 0
    P = v * i
    
    f, axarr = plt.subplots(2, sharex=True)
    axarr[0].plot(v, i)
    axarr[0].set_title('')
    axarr[1].plot(v,P)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).