|
@@ -66,31 +66,43 @@ 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(model,tmax,atol,rtol,method='LSODA',t0=0,y0=numpy.array([]), sIn=numpy.array([])):
|
|
|
- s0=numpy.zeros((model.n,model.m+1))
|
|
|
- if sIn.size!=0:
|
|
|
- s0[:,1:]=sIn
|
|
|
- if y0.size==0:
|
|
|
- y0=numpy.zeros(model.n)
|
|
|
- #set initial condition
|
|
|
- s0[:,0]=y0
|
|
|
- s0=s0.ravel()
|
|
|
- sol=scipy.integrate.solve_ivp(dfdySFull,[t0, tmax],s0, args=(model,), jac=jacobiSEFull,
|
|
|
- method=method, atol=atol, rtol=rtol)
|
|
|
- t=sol.t
|
|
|
- sFull=numpy.reshape(numpy.transpose(sol.y),(len(t),model.n,model.m+1))
|
|
|
- s1=sFull[:,:,1:]
|
|
|
- ysol=sFull[:,:,0]
|
|
|
- se=model.calculateUncertainty(s1)
|
|
|
- print('Done simultaneous LSODA SE')
|
|
|
- return t,ysol,se,s1
|
|
|
-
|
|
|
-def solveSequential(model,tmax,atol,rtol,method='LSODA',t0=0,y0=numpy.array([]), sIn=numpy.array([])):
|
|
|
+def solveSimultaneous(model,tmax,atol,rtol,method='LSODA',nt=201,\
|
|
|
+ t0=0,y0=numpy.array([]), sIn=numpy.array([])):
|
|
|
+
|
|
|
+ t_eval=numpy.linspace(t0,tmax,nt)
|
|
|
+
|
|
|
+ s0=numpy.zeros((model.n,model.m+1))
|
|
|
+
|
|
|
+ if sIn.size!=0:
|
|
|
+ s0[:,1:]=sIn
|
|
|
+ if y0.size==0:
|
|
|
+ y0=numpy.zeros(model.n)
|
|
|
+
|
|
|
+ #set initial condition
|
|
|
+ s0[:,0]=y0
|
|
|
+ s0=s0.ravel()
|
|
|
+ sol=scipy.integrate.solve_ivp(dfdySFull,[t0, tmax],s0, args=(model,),\
|
|
|
+ jac=jacobiSEFull, method=method, \
|
|
|
+ atol=atol, rtol=rtol, t_eval=t_eval)
|
|
|
+ t=sol.t
|
|
|
+ sFull=numpy.reshape(numpy.transpose(sol.y),(len(t),model.n,model.m+1))
|
|
|
+ s1=sFull[:,:,1:]
|
|
|
+ ysol=sFull[:,:,0]
|
|
|
+ se=model.calculateUncertainty(s1)
|
|
|
+ print('Done simultaneous LSODA SE')
|
|
|
+ return t,ysol,se,s1
|
|
|
+
|
|
|
+def solveSequential(model,tmax,atol,rtol,method='LSODA',nt=201,\
|
|
|
+ t0=0,y0=numpy.array([]), sIn=numpy.array([])):
|
|
|
+
|
|
|
+ t_eval=numpy.linspace(t0,tmax,nt)
|
|
|
+
|
|
|
if y0.size==0:
|
|
|
y0=numpy.zeros(model.n)
|
|
|
- model.iPrint=0
|
|
|
+
|
|
|
solIVP=scipy.integrate.solve_ivp(dfdy,[t0, tmax],y0, args=(model,), jac=jacobi,
|
|
|
- method=method, atol=atol, rtol=rtol)
|
|
|
+ method=method, atol=atol, rtol=rtol, t_eval=t_eval)
|
|
|
+
|
|
|
#y is n x nt (odeint nt x n)
|
|
|
sol=numpy.transpose(solIVP.y)
|
|
|
t=solIVP.t
|
|
@@ -102,7 +114,8 @@ def solveSequential(model,tmax,atol,rtol,method='LSODA',t0=0,y0=numpy.array([]),
|
|
|
s0=s0.ravel()
|
|
|
|
|
|
solIVPSE=scipy.integrate.solve_ivp(dfdyS,[0, tmax],s0, args=(model,), jac=jacobiSE,
|
|
|
- method=method, atol=atol, rtol=rtol)
|
|
|
+ method=method, atol=atol, rtol=rtol,t_eval=t_eval)
|
|
|
+
|
|
|
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))
|