|
@@ -59,74 +59,82 @@ def jacobiSEFull(t,S,system):
|
|
|
fJ[i*system.n:(i+1)*system.n,i*system.n:(i+1)*system.n]=system.M(t)
|
|
|
return fJ
|
|
|
|
|
|
-def solveSimultaneous(sys,tmax,atol,rtol,method='LSODA'):
|
|
|
- S1=numpy.zeros((sys.n,sys.m+1))
|
|
|
- y0=numpy.zeros(sys.n)
|
|
|
+def solveSimultaneous(model,tmax,atol,rtol,method='LSODA',t0=0,y0=None, S1=None):
|
|
|
+ if S1==None:
|
|
|
+ S1=numpy.zeros((model.n,model.m+1))
|
|
|
+ if y0==None:
|
|
|
+ y0=numpy.zeros(model.n)
|
|
|
#set initial condition
|
|
|
S1[:,0]=y0
|
|
|
S1=S1.ravel()
|
|
|
- sol=scipy.integrate.solve_ivp(dfdySFull,[0, tmax],S1, args=(sys,), jac=jacobiSEFull,
|
|
|
+ sol=scipy.integrate.solve_ivp(dfdySFull,[t0, tmax],S1, args=(model,), jac=jacobiSEFull,
|
|
|
method=method, atol=atol, rtol=rtol)
|
|
|
t=sol.t
|
|
|
- sFull=numpy.reshape(numpy.transpose(sol.y),(len(t),sys.n,sys.m+1))
|
|
|
+ sFull=numpy.reshape(numpy.transpose(sol.y),(len(t),model.n,model.m+1))
|
|
|
s1=sFull[:,:,1:]
|
|
|
ysol=sFull[:,:,0]
|
|
|
- se=sys.calculateUncertainty(ysol,s1)
|
|
|
+ se=model.calculateUncertainty(ysol,s1)
|
|
|
print('Done simultaneous LSODA SE')
|
|
|
return t,ysol,se,s1
|
|
|
|
|
|
-def solveSequential(sys,tmax,atol,rtol,method='LSODA'):
|
|
|
- y0=numpy.zeros(sys.n)
|
|
|
- solIVP=scipy.integrate.solve_ivp(dfdy,[0, tmax],y0, args=(sys,), jac=jacobi,
|
|
|
+def solveSequential(model,tmax,atol,rtol,method='LSODA',t0=0,y0=None, S1=None):
|
|
|
+ if y0==None:
|
|
|
+ y0=numpy.zeros(model.n)
|
|
|
+ solIVP=scipy.integrate.solve_ivp(dfdy,[t0, tmax],y0, args=(model,), jac=jacobi,
|
|
|
method=method, atol=atol, rtol=rtol)
|
|
|
-#y is n x nt (odeint nt x n)
|
|
|
+ #y is n x nt (odeint nt x n)
|
|
|
sol=numpy.transpose(solIVP.y)
|
|
|
t=solIVP.t
|
|
|
print('shape (y) {}'.format(sol.shape))
|
|
|
- sys.setY(t,sol)
|
|
|
- S0=numpy.zeros((sys.n,sys.m))
|
|
|
- S0=S0.ravel()
|
|
|
+ model.setY(t,sol)
|
|
|
+ if S1==None:
|
|
|
+ S1=numpy.zeros((model.n,model.m))
|
|
|
+ S1=S1.ravel()
|
|
|
|
|
|
- solIVPSE=scipy.integrate.solve_ivp(dfdyS,[0, tmax],S0, args=(sys,), jac=jacobiSE,
|
|
|
+ solIVPSE=scipy.integrate.solve_ivp(dfdyS,[0, tmax],S1, args=(model,), jac=jacobiSE,
|
|
|
method=method, atol=atol, rtol=rtol)
|
|
|
- sraw=numpy.reshape(numpy.transpose(solIVPSE.y),(len(solIVPSE.t),sys.n,sys.m))
|
|
|
-#interpolate on t
|
|
|
- s1=numpy.zeros((len(t),sys.n,sys.m))
|
|
|
- for i in range(sys.n):
|
|
|
- for j in range(sys.m):
|
|
|
+ sraw=numpy.reshape(numpy.transpose(solIVPSE.y),(len(solIVPSE.t),model.n,model.m))
|
|
|
+ #interpolate on t
|
|
|
+ s1=numpy.zeros((len(t),model.n,model.m))
|
|
|
+ for i in range(model.n):
|
|
|
+ for j in range(model.m):
|
|
|
tck = scipy.interpolate.splrep(solIVPSE.t, sraw[:,i,j], s=0)
|
|
|
s1[:,i,j]=scipy.interpolate.splev(t, tck, der=0)
|
|
|
|
|
|
- se=sys.calculateUncertainty(sol,s1)
|
|
|
+ se=model.calculateUncertainty(sol,s1)
|
|
|
return t,sol,se,s1
|
|
|
|
|
|
-def solveSimultaneousOdeint(sys,tmax,nt=201):
|
|
|
- t = numpy.linspace(0,tmax, nt)
|
|
|
- y0=numpy.zeros(sys.n)
|
|
|
- S1=numpy.zeros((sys.n,sys.m+1))
|
|
|
-#set initial condition
|
|
|
+def solveSimultaneousOdeint(model,tmax,nt=201,t0=0,y0=None, S1=None):
|
|
|
+ t = numpy.linspace(t0,tmax, nt)
|
|
|
+ if y0==None:
|
|
|
+ y0=numpy.zeros(model.n)
|
|
|
+ if S1==None:
|
|
|
+ S1=numpy.zeros((model.n,model.m+1))
|
|
|
+ #set initial condition
|
|
|
S1[:,0]=y0
|
|
|
S1=S1.ravel()
|
|
|
- solSE1=scipy.integrate.odeint(dfdySFull, S1, t, args=(sys,),Dfun=jacobiSEFull,tfirst=True)
|
|
|
- sFull=numpy.reshape(solSE1,(len(t),sys.n,sys.m+1))
|
|
|
+ solSE1=scipy.integrate.odeint(dfdySFull, S1, t, args=(model,),Dfun=jacobiSEFull,tfirst=True)
|
|
|
+ sFull=numpy.reshape(solSE1,(len(t),model.n,model.m+1))
|
|
|
s1=sFull[:,:,1:]
|
|
|
sol=sFull[:,:,0]
|
|
|
se=sys.calculateUncertainty(sol,s1)
|
|
|
print('Done simultaneous SE')
|
|
|
return t,sol,se,s1
|
|
|
|
|
|
-def solveSequentialOdeint(sys,tmax,nt=201):
|
|
|
- t = numpy.linspace(0,tmax, nt)
|
|
|
- y0=numpy.zeros(sys.n)
|
|
|
- sol = scipy.integrate.odeint(dfdy, y0=y0, t=t, args=(sys,),Dfun=jacobi,tfirst=True)
|
|
|
+def solveSequentialOdeint(model,tmax,nt=201,t0=0,y0=None,S1=None):
|
|
|
+ t = numpy.linspace(t0,tmax, nt)
|
|
|
+ if y0==None:
|
|
|
+ y0=numpy.zeros(sys.n)
|
|
|
+ sol = scipy.integrate.odeint(dfdy, y0=y0, t=t, args=(model,),Dfun=jacobi,tfirst=True)
|
|
|
print('shape (y) {}'.format(sol.shape))
|
|
|
|
|
|
- sys.setY(t,sol)
|
|
|
- S0=numpy.zeros((sys.n,sys.m))
|
|
|
- S0=S0.ravel()
|
|
|
- solSE=scipy.integrate.odeint(dfdyS, S0, t, args=(sys,),Dfun=jacobiSE,tfirst=True)
|
|
|
- s1=numpy.reshape(solSE,(len(t),sys.n,sys.m))
|
|
|
- se=sys.calculateUncertainty(sol,s1)
|
|
|
+ model.setY(t,sol)
|
|
|
+ if S1==None:
|
|
|
+ S1=numpy.zeros((model.n,model.m))
|
|
|
+ S1=S1.ravel()
|
|
|
+ solSE=scipy.integrate.odeint(dfdyS, S1, t, args=(model,),Dfun=jacobiSE,tfirst=True)
|
|
|
+ s1=numpy.reshape(solSE,(len(t),model.n,model.m))
|
|
|
+ se=model.calculateUncertainty(sol,s1)
|
|
|
print('Done sequential SE')
|
|
|
return t,sol,se,s1
|
|
|
|