In [1]:
%load_ext autoreload
%autoreload 2
from pypvcell.solarcell import SQCell
import numpy as np
import matplotlib.pyplot as plt
import scipy.constants as sc
from pypvcell.illumination import load_astm
In [2]:
def find_voltage(v,i):
pass
def rev_diode(voltage):
rev_j01 = 4.46e-15
rev_bd_v=0.1
return -rev_j01*np.exp(sc.e*(-voltage-rev_bd_v)/(sc.k*300)-1)
In [3]:
sq1_cell=SQCell(eg=1.3,cell_T=300,plug_in_term=rev_diode)
sq1_cell.set_input_spectrum(load_astm("AM1.5d"))
sq2_cell=SQCell(eg=2.0,cell_T=300,plug_in_term=rev_diode)
sq2_cell.set_input_spectrum(load_astm("AM1.5d"))
test_v=np.linspace(-2,2.5,num=50)
print(sq1_cell.jsc)
print(sq2_cell.jsc)
test_j1=sq1_cell.get_j_from_v(test_v)
test_j2=sq2_cell.get_j_from_v(test_v)
In [4]:
plt.plot(test_v,test_j1,label="cell 1")
plt.plot(test_v,test_j2,label="cell 2")
plt.legend()
plt.ylim([-400,0])
Out[4]:
In [5]:
from scipy.optimize import bisect
In [6]:
def f1(x):
return sq2_cell.get_j_from_v(x)+121
zero_result=bisect(f1,0,10)
print(zero_result)
In [7]:
def f2(x):
return sq2_cell.get_j_from_v(x)+123
zero_result=bisect(f2,-30,0)
print(zero_result)
In [8]:
def f3(x):
return sq2_cell.get_j_from_v(x)+(5+0.01)
zero_result=bisect(f3,0,10)
print(zero_result)
In [9]:
def f4(x):
return sq2_cell.get_j_from_v(x)+(5-0.01)
zero_result=bisect(f4,0,10)
print(zero_result)
In [10]:
f2(0)
Out[10]:
In [11]:
f2(-20)
Out[11]:
In [12]:
f2(-21.2)
Out[12]:
In [13]:
def f5(x,x_0):
return sq2_cell.get_j_from_v(x)-x_0
In [14]:
zero_result=bisect(f5,0,10,args=5)
print(zero_result)
In [15]:
test_v=np.linspace(-3,1.5,num=10)
test_j1=sq1_cell.get_j_from_v(test_v)
results_1=[]
results_2=[]
for j1 in test_j1:
try:
results_1.append(bisect(f5,0,5,args=j1*1.001))
except ValueError:
print("no solution found for {}".format(j1*1.001))
try:
results_2.append(bisect(f5,-30,0,args=j1*0.009))
except ValueError:
print("no solution found for {}".format(j1*0.009))
In [16]:
results_1
Out[16]:
In [17]:
results_2
Out[17]:
In [18]:
test_v=np.linspace(-3,3,num=200)
test_j1=sq1_cell.get_j_from_v(test_v)
test_j2=sq2_cell.get_j_from_v(test_v)
results_1=[]
results_2=[]
for j1 in test_j1:
jj=j1*0.99
try:
results_1.append((bisect(f5,-23,5,args=jj),jj))
except ValueError:
print("no solution found for {}".format(jj))
jj=j1*1.01
try:
results_1.append((bisect(f5,-23,5,args=jj),jj))
except ValueError:
print("no solution found for {}".format(jj))
results_1=np.array(results_1)
for j1 in test_j2:
jj=j1*0.99
try:
results_2.append((bisect(f5,-23,5,args=jj),jj))
except ValueError:
print("no solution found for {}".format(jj))
jj=j1*1.01
try:
results_2.append((bisect(f5,-23,5,args=jj),jj))
except ValueError:
print("no solution found for {}".format(jj))
results_2=np.array(results_2)
In [19]:
#plt.plot(test_v,np.array(results_1),label="solved sq2")
plt.plot(test_v,sq1_cell.get_j_from_v(test_v),label="cell 1")
plt.ylim([-400,0])
plt.legend()
Out[19]:
Get the series-connected voltages
In [20]:
plt.plot(test_v,sq1_cell.get_j_from_v(test_v),'.-',label="cell 1")
plt.plot(test_v,sq2_cell.get_j_from_v(test_v),'.-',label="cell 2")
plt.plot(results_1[:,0],results_1[:,1],'-.',label="solved cell 2 voltage from cell 1 current")
plt.plot(results_2[:,0],results_2[:,1],'-.',label="solved cell 2 voltage from cell 2 current")
plt.legend()
plt.ylim([-400,1000])
Out[20]:
In [21]:
def merge_iv_sets(v1,j1,v2,j2):
v3=np.concatenate((v1,v2))
j3=np.concatenate((j1,j2))
sorted_v3_index=np.argsort(v3)
return v3[sorted_v3_index],j3[sorted_v3_index]
In [22]:
v3,j3=merge_iv_sets(results_1[:,0],results_1[:,1],results_2[:,0],results_2[:,1])
In [23]:
plt.plot(test_v,sq1_cell.get_j_from_v(test_v),'.-',label="cell 1")
plt.plot(test_v,sq2_cell.get_j_from_v(test_v),'.-',label="cell 2")
plt.plot(v3,j3,'.-',label="solved cell 2 voltage from cell 1 and 2 current")
plt.legend()
plt.ylim([-400,1000])
Out[23]:
get current of cell 1 using j3
In [24]:
def f6(x,x_0):
return sq1_cell.get_j_from_v(x)-x_0
result_3=[] for jj in j3:
try:
result_3.append((bisect(f6,-23,5,args=jj),jj))
except ValueError:
print("no solution found for {}".format(jj))
result_3=np.array(result_3)
In [25]:
from pypvcell.ivsolver import solve_v_from_j_adding_epsilon
In [26]:
result_3=solve_v_from_j_adding_epsilon(sq1_cell.get_j_from_v,j3,bisect,epsilon=0)
In [27]:
plt.plot(test_v,sq1_cell.get_j_from_v(test_v),'.-',label="cell 1")
plt.plot(test_v,sq2_cell.get_j_from_v(test_v),'.-',label="cell 2")
#plt.plot(v3,j3,'.-',label="solved cell 2 voltage from cell 1 and 2 current")
#plt.plot(result_3[:,0],result_3[:,1],'.')
plt.plot(result_3[:,0],result_3[:,1],'.')
plt.legend()
plt.ylim([-400,1000])
Out[27]:
In [28]:
plt.plot(result_3[:,0],result_3[:,1],'.-')
plt.plot(v3,result_3[:,1],'.-')
plt.plot(v3+result_3[:,0],result_3[:,1],'.-',label="solved ")
plt.ylim([-500,100])
plt.xlim([-5,3])
plt.legend()
Out[28]:
In [29]:
iv_funcs=[sq1_cell.get_j_from_v,sq2_cell.get_j_from_v]
from pypvcell.ivsolver import solve_series_connected_ivs
In [30]:
iv_pair=solve_series_connected_ivs(iv_funcs=iv_funcs,vmin=-3,vmax=3,vnum=100)
In [31]:
plt.plot(iv_pair[:,0],iv_pair[:,1],'.-')
Out[31]:
In [32]:
sq1_cell=SQCell(eg=1.42,cell_T=300,plug_in_term=rev_diode)
sq1_cell.set_input_spectrum(load_astm("AM1.5d")*0.5)
sq2_cell=SQCell(eg=1.42,cell_T=300,plug_in_term=rev_diode)
sq2_cell.set_input_spectrum(load_astm("AM1.5d"))
sq3_cell=SQCell(eg=1.42,cell_T=300,plug_in_term=rev_diode)
sq3_cell.set_input_spectrum(load_astm("AM1.5d"))
sq4_cell=SQCell(eg=1.42,cell_T=300,plug_in_term=rev_diode)
sq4_cell.set_input_spectrum(load_astm("AM1.5d")*1.5)
sq5_cell=SQCell(eg=1.42,cell_T=300,plug_in_term=rev_diode)
sq5_cell.set_input_spectrum(load_astm("AM1.5d")*0.75)
In [33]:
iv_funcs=[sq1_cell.get_j_from_v,sq2_cell.get_j_from_v,sq3_cell.get_j_from_v,sq4_cell.get_j_from_v,sq5_cell.get_j_from_v]
In [34]:
iv_pair=solve_series_connected_ivs(iv_funcs=iv_funcs,vmin=-3,vmax=3,vnum=300)
In [35]:
volt=np.linspace(-3,3,num=300)
plt.plot(volt,sq1_cell.get_j_from_v(volt))
plt.plot(volt,sq2_cell.get_j_from_v(volt))
plt.plot(volt,sq4_cell.get_j_from_v(volt))
plt.plot(volt,sq5_cell.get_j_from_v(volt))
plt.plot(iv_pair[:,0],iv_pair[:,1],'.-')
plt.ylim([-500,0])
plt.xlim([-5,6])
Out[35]:
In [ ]: