예제 #1
0
	def test_exact(self, scheme):
		self.sys = VerticalRollingDisk()
		self.scheme = scheme
		ohm_phi = 2.
		ohm_theta = 1.
		phi_0 = 0
		self.u0 = self.sys.initial(np.array([0,0,phi_0,0.,0,0,ohm_phi,ohm_theta,0,0]))
		R = self.sys.radius
		m = self.sys.mass
		# consistent initial velocities
		vx = self.u0[4] = R*ohm_theta*np.cos(phi_0)
		vy = self.u0[5] = R*ohm_theta*np.sin(phi_0)
		# lagrange multipliers: used only used as a guess in RK methods
		self.u0[8], self.u0[9] = -m*ohm_phi*R*ohm_theta*np.sin(phi_0), m*ohm_phi*R*ohm_theta*np.cos(phi_0)
		self.scheme.h = self.h
		self.s = Solver(self.scheme, self.sys)
		self.s.initialize(self.u0,)
		self.s.run(1.)
##		self.s.plot(components=[6,7])
		self.check_solution()
예제 #2
0
from odelab import Solver
from odelab.scheme.classic import RungeKutta4
from odelab.system.classic import VanderPol

s = Solver(scheme=RungeKutta4(.1), system=VanderPol())
s.initialize([2.7,0], name='2.7')
s.run(10.)
s.plot2D()

s.initialize([1.3,0], name='1.3')
s.run(10.)
s.plot2D()
예제 #3
0
from odelab import Solver
from odelab.scheme.classic import RungeKutta4
from odelab.system.classic import VanderPol

s = Solver(scheme=RungeKutta4(.1), system=VanderPol())
s.initialize([2.7, 0], name='2.7')
s.run(10.)
s.plot2D()

s.initialize([1.3, 0], name='1.3')
s.run(10.)
s.plot2D()
예제 #4
0
class TestVerticalRollingDisk:
	h = .1
	def test_exact(self, scheme):
		self.sys = VerticalRollingDisk()
		self.scheme = scheme
		ohm_phi = 2.
		ohm_theta = 1.
		phi_0 = 0
		self.u0 = self.sys.initial(np.array([0,0,phi_0,0.,0,0,ohm_phi,ohm_theta,0,0]))
		R = self.sys.radius
		m = self.sys.mass
		# consistent initial velocities
		vx = self.u0[4] = R*ohm_theta*np.cos(phi_0)
		vy = self.u0[5] = R*ohm_theta*np.sin(phi_0)
		# lagrange multipliers: used only used as a guess in RK methods
		self.u0[8], self.u0[9] = -m*ohm_phi*R*ohm_theta*np.sin(phi_0), m*ohm_phi*R*ohm_theta*np.cos(phi_0)
		self.scheme.h = self.h
		self.s = Solver(self.scheme, self.sys)
		self.s.initialize(self.u0,)
		self.s.run(1.)
##		self.s.plot(components=[6,7])
		self.check_solution()

	def check_solution(self, decimal=1):
		npt.assert_array_almost_equal(self.s.final()[:8], self.sys.exact(np.array([self.s.final_time()]),u0=self.u0)[:8,0], decimal=decimal)

	def check_energy(self, decimal):
		energy = self.sys.energy
		npt.assert_almost_equal(energy(self.s.final()), energy(self.s.initial()), decimal=decimal)

	experiences = {'50': (.01,50), '1000': (.1,1000.)}

	def run_experience(self, exp_name):
		h,time = self.experiences[exp_name]
		self.s.initialize(h=h,time=time)
		self.s.run()
예제 #5
0
파일: explot.py 프로젝트: LongyanU/odelab
from odelab import Solver, System
from odelab.scheme.classic import ExplicitEuler


def f(t, u):
    return -u


s = Solver(scheme=ExplicitEuler(0.1), system=System(f))
s.initialize(u0=1.0)
s.run(1.0)

s.plot()
예제 #6
0
파일: explot.py 프로젝트: sliao7/odelab
from odelab import Solver, System
from odelab.scheme.classic import ExplicitEuler

def f(t,u):
	return -u

s = Solver(scheme=ExplicitEuler(.1), system=System(f))
s.initialize(u0=1.)
s.run(1.)

s.plot()