问题描述
我正在尝试创建对耦合 ODE 的响应。输入电流 I 为脉冲形式。我试图得到如下响应:
不幸的是,在新的循环运行中,r 的值被覆盖了。
如何在旧值的末尾附加 r 以便根据 I 的值获得完整响应?
from scipy import *
from scipy.integrate import ode
from pylab import *
import matplotlib.pyplot as plt
import numpy as np
### Simualtion Outputs ###
N = [] # y[0] Carrier concentration
S = [] # y[1] Photon concentration
### Simualtion input parameters ###
# def gaussian(x,mu,sig):
# I = np.exp(-np.power(x - mu,2.) / (2 * np.power(sig,2.)))
# return none
I = []
wm =2
x_values = np.linspace(0,60,1200)
for x in x_values:
for mu,sig in [(30,1)]:
a = np.exp(-np.power(x - mu,2.)))
a1=a+wm
a2=a1*1e-2
I.append(a2)
print (I)
# x_values = np.linspace(-3,3,120)
# mu = 0
# sig = 0
# for a,b in [(-1,1),(0,2),(2,3)]:
# mu = a
# sig = b
# I = 2.0e-2
# I =lambda x,sig: np.exp(-np.power(x - mu,2.))) # p[0] Pumping current (A)
q = 1.6e-19 # p[1] Electron charge (C)
V = 2e-11 # p[2] Device volume (cm^3)
tn = 1.0e-9 # p[3] Carrier relaxation time in seconds (s)
g0 = 1.5e-5 # p[4] Gain slope constant (cm^3/s)
Nth = 1e18 # p[5] Threshold carrier density (cm^-3)
EPS = 1.5e-17 # p[6] Gain compression factor (cm^3)
Gamma = 0.2 # p[7] Confinement factor
tp = 1.0e-12 # p[8] Photon lifetime in cavity (s)
Beta = 1.0e-4 # p[9] Spontaneous Emission Factor
### Define equations to be solved
def Laser_rates(t,y,p):
for i in I:
i = p[0]; q = p[1]; V = p[2]; tn = p[3]; g0 = p[4]; Nth = p[5]; EPS = p[6]; Gamma = p[7]; tp = p[8]; Beta = p[9]
n = len(y) # 2: implies we have two ODEs
dy = np.zeros((n,1))
###dy = zeros([2])
dy[0] = (i/(q* V)) - (y[0]/tn) - g0*(y[0] - Nth)*(y[1]/(1 + EPS* y[1]))
dy[1] = Gamma* g0* (y[0] - Nth)*(y[1]/(1 + EPS* y[1])) - y[1]/tp + (Gamma* Beta* y[0]) / tn
return dy
### Time and initial conditions ###
t0 = 0; tEnd = 1e-9; dt = 1e-11 #Time constraints
y0 = [0,0] #Initial conditions
Y=[]; T=[] #Create empty lists
p = [I,1.6e-19,2e-11,1e-9,1.5e-5,1e18,1.5e-17,0.2,1e-12,1e-4] #Parameters for odes
#p = [ I,q,V,tn,g0,Nth,EPS,Gamma,tp,Beta]
#Setup integrator with desired parameters
#Setup integrator with desired parameters
for i in I:
r = ode(Laser_rates).set_integrator('vode',method = 'bdf')
r = ode(Laser_rates).set_integrator('dopri5',nsteps = 1e4)
p = [i,1e-4] #Parameters for odes
r.set_f_params(p).set_initial_value(y0,t0)
### Simualtion check ###
while r.successful() and r.t+dt < tEnd:
r.integrate(r.t + dt)
Y.append(r.y) #Makes a list of 1d arrays
T.append(r.t)
### Format output ###
Y = array(Y) #Convert from list to 2d array
N = Y[:,0]
S = Y[:,1]
### Plotting ###
f,axarr = plt.subplots(2,sharex=True) # Two subplots,the axes array is 1-d
axarr[0].plot(T,N,'G')
axarr[0].set_ylabel("Carrier Conc (cm^-3)")
axarr[0].set_title('Laser-Rate Simulation')
axarr[1].plot(T,S,'B')
axarr[1].set_ylabel("Photon Conc (cm^-3)")
axarr[1].set_xlabel("Time (s)")
show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)