def run_example(with_plots=True): y0 = [2.0,-0.6] #Initial conditions yd0 = [-.6,-200000.] #Define an extended Assimulo problem imp_mod = VanDerPolProblem(y0=y0,yd0=yd0) #Define an explicit solver imp_sim = Radau5DAE(imp_mod) #Create a Radau5 solver #Simulate t, y, yd = imp_sim.simulate(8.) #Simulate 8 seconds #Plot if with_plots: import pylab as P P.plot(t,y[:,0], marker='o') P.xlabel('Time') P.ylabel('State') P.title(imp_mod.name) P.show() #Basic test x1 = y[:,0] assert N.abs(x1[-1]-1.14330840983) < 1e-3 #For test purpose return imp_mod, imp_sim
def integrate(system, t0, tf): # set up DAE system.rhs = dae_rhs(system) system.initial_conc_td = initial_derivative(system) prob = ACAIE_Implicit_Problem( system=system, y0=system.initial_conc, yd0=system.initial_conc_td, t0=t0) # set up solver sol = Radau5DAE(prob) sol.atol, sol.rtol = 1e-7, 1e-5 return sol.simulate(tfinal=tf)
# + ct.omega ** 2 / ct.vA(x,ct.z) ** 2 * u_perp res = np.zeros(6 * ct.nz) res[0:ct.nz] = np.real(dux + 1j * ct.omega * b_par + nabla_perp_u_perp) res[ct.nz:2*ct.nz] = np.imag(dux + 1j * ct.omega * b_par + nabla_perp_u_perp) res[2*ct.nz:3*ct.nz] = np.real(db_par + 1j / ct.omega * L_ux) res[3*ct.nz:4*ct.nz] = np.imag(db_par + 1j / ct.omega * L_ux) res[4*ct.nz:5*ct.nz] = np.real(L_u_perp - 1j * ct.omega * nabla_perp_b_par) res[5*ct.nz:] = np.imag(L_u_perp - 1j * ct.omega * nabla_perp_b_par) return res model = Implicit_Problem(residual, ct.U_x_min, ct.dU_x_min, ct.x_min) model.name = 'Resonant abosprotion' sim = Radau5DAE(model) sim.rtol = 1e-2 sim.atol = 1e-2 sim.verbosity = 10 x, U, dU = sim.simulate(ct.x_max, ct.nx-1) x = np.array(x) x0 = ct.x[ct.nx//2] z0 = ct.z[0] ux_r = U[:,0:ct.nz].T ux_i = U[:,ct.nz:2*ct.nz].T b_par_r = U[:,2*ct.nz:3*ct.nz].T b_par_i = U[:,3*ct.nz:4*ct.nz].T u_perp_r = U[:,4*ct.nz:5*ct.nz].T
def run_example(with_plots=True): r""" Example for the use of Radau5DAE to solve Van der Pol's equation .. math:: \dot y_1 &= y_2 \\ \dot y_2 &= \mu ((1.-y_1^2) y_2-y_1) with :math:`\mu= 10^6`. on return: - :dfn:`imp_mod` problem instance - :dfn:`imp_sim` solver instance """ #Define the residual def f(t, y, yd): eps = 1.e-6 my = 1. / eps yd_0 = y[1] yd_1 = my * ((1. - y[0]**2) * y[1] - y[0]) res_0 = yd[0] - yd_0 res_1 = yd[1] - yd_1 return N.array([res_0, res_1]) y0 = [2.0, -0.6] #Initial conditions yd0 = [-.6, -200000.] #Define an Assimulo problem imp_mod = Implicit_Problem(f, y0, yd0) imp_mod.name = 'Van der Pol (implicit)' #Define an explicit solver imp_sim = Radau5DAE(imp_mod) #Create a Radau5 solver #Sets the parameters imp_sim.atol = 1e-4 #Default 1e-6 imp_sim.rtol = 1e-4 #Default 1e-6 imp_sim.inith = 1.e-4 #Initial step-size #Simulate t, y, yd = imp_sim.simulate(2.) #Simulate 2 seconds #Plot if with_plots: P.subplot(211) P.plot(t, y[:, 0]) #, marker='o') P.xlabel('Time') P.ylabel('State') P.subplot(212) P.plot(t, yd[:, 0] * 1.e-5) #, marker='o') P.xlabel('Time') P.ylabel('State derivatives scaled with $10^{-5}$') P.suptitle(imp_mod.name) P.show() #Basic test x1 = y[:, 0] assert N.abs(x1[-1] - 1.706168035) < 1e-3 #For test purpose return imp_mod, imp_sim