Ejemplo n.º 1
0
def test_rkdae(s):
	sys = GraphSystem(sq)
	u0 = np.array([0.,0.,1.])
	scheme = RKDAE(.1, tableau=RK.RadauIIA.tableaux[s])
	sol = Solver(scheme, sys)
	sol.initialize(u0=u0)
	CompareExact('RadauIIA-{0}'.format(s)), sol, u0, 2
Ejemplo n.º 2
0
    def setUp(self):
        self.file = tempfile.NamedTemporaryFile()
        self.path = self.file.name
        self.family = os.path.basename(self.path)
        self.prefix = os.path.dirname(self.path)
        self.file.close()
        from odelab.scheme.classic import ExplicitEuler

        self.params = params = {
            'family': self.family,
            'system': System,
            'system_params': {
                'f': f
            },
            'solver': Solver,
            'scheme': ExplicitEuler,
            'scheme_params': {
                'h': .1,
            },
            'initialize': {
                'u0': np.array([1.]),
                'time': 1.,
                'name': self.name,
            },
        }
        scheme = ExplicitEuler(**params['scheme_params'])
        s = Solver(system=System(f), scheme=scheme, path=self.path)
        s.catch_runtime = False
        s.initialize(**params['initialize'])
        s.run()
Ejemplo n.º 3
0
def test_orders(expected_orders, scheme, plot=False, tol=.2):
	system = QuasiGraphSystem(fsin)
	#system = GraphSystem(fsin)
	u0 = np.array([0.,0.,1])
	solver = Solver(scheme, system)
	#compare_exact(sol, u0, 2)

	sol = solver
	errz = []
	errl = []
	ks = np.arange(1,5)
	for k in ks:
		scheme.h = pow(2,-k)
		sol.initialize(u0=u0)
		sol.run(1)
		zexact = sol.system.exact(sol.final_time(),u0)[0]
		lexact = sol.system.exact(sol.final_time(),u0)[2]
		df = sol.final()[0] - zexact
		logerrz = np.log2(np.abs(df))
		logerrl = np.log2(np.abs(sol.final()[2] - lexact))
		errz.append(logerrz)
		errl.append(logerrl)
	if plot:
		plt.clf()
		plt.subplot(1,2,1)
		plt.title('z')
		plt.plot(ks,errz,'o-')
		plt.legend()
		plt.subplot(1,2,2)
		plt.title(u'λ')
		plt.plot(ks,errl,'o-')
		plt.legend()
	regz = order.linear_regression(ks,errz,do_plot=False)
	regl = order.linear_regression(ks,errl,do_plot=False)
	oz = -regz[0]
	ol = -regl[0]
	assert ol > expected_orders[0] - tol
	assert oz > expected_orders[1] - tol
	return sol