# Path: odelab/system/exponential/burgers.py
# class BurgersComplex(Burgers):
# 	def __getstate__(self):
# 		state = self.__dict__.copy()
# 		del state['laplace']
# 		del state['points']
# 		del state['k']
# 		return state
# 
# 	def initialize(self):
# 		self.k = 2*np.pi*np.array(np.fft.fftfreq(self.size, 1/self.size),dtype='complex')
# 		self.k[len(self.k)/2] = 0
# 		self.laplace = self.viscosity*np.diag(self.k**2)
# 		x = np.linspace(0,1,self.size,endpoint=False)
# 		self.points = x - x.mean() # too lazy to compute x.mean manually here...
# 
# 	def preprocess(self, event0):
# 		return np.hstack([np.fft.fft(event0[:-1]), event0[-1]])
# 
# 	def postprocess(self, event1):
# 		return np.hstack([np.real(np.fft.ifft(event1[:-1])),event1[-1]])
# 
# 	def nonlin(self, t, u):
# 		return -0.5j * self.k * np.fft.fft(np.real(np.fft.ifft(u)) ** 2)


from odelab.scheme import *
from odelab.scheme.exponential import *
from odelab.scheme.rungekutta import *
from odelab.scheme.generallinear import *
from odelab.scheme.classic import *
from odelab.system import *
from odelab.system.exponential.burgers import BurgersComplex
from odelab.solver import *
import numpy.testing as npt
import pytest
import scipy.linalg as slin
import odelab.scheme.exponential as E
	u0 = np.array([1.,0.])
	s.initialize(u0 = u0)

	s.run(time=1.)
	computed = s.final()[:-1]
	phi = Phi(0)
	tf = s.final_time()
	phi_0 = np.dot(phi(tf*L)[0], u0)
	expected = np.dot(slin.expm(tf*L), u0)
	CompareLinearExponential(scheme), computed, expected, phi_0

# Complex convection


def check_convection(scheme, time, h, B, u0, sol, do_plot):
	scheme.h = h
	s = SingleStepSolver(scheme, system=B, init_scheme=HochOst4(h=h))
	s.initialize(u0=u0)
	s.run(time=time)
	e1 = s.final()
	u1 = e1[:-1]
	if do_plot:
		pl.plot(B.points, u0)
		pl.plot(B.points, u1)
	npt.assert_array_almost_equal(u1, sol, decimal=2)

schemes = [ExplicitEuler(), 150], [Kutta4(), 10], [Kutta38(), 10], [Heun(), 10], [ABNorset4(), 50], [ABLawson2(), 50], [ABLawson3(), 50], [ABLawson4(), 50], [Lawson4(), 10], [GenLawson45(), 10], [LawsonEuler(), 150], [RKMK4T(), 10], [ode15s(), 2], [AdamsBashforth1(), 150], [AdamsBashforth2(), 50], [AdamsBashforth2e(), 50], [Butcher1(), 50], [Butcher3(), 120],

@pytest.mark.parametrize(["scheme", "N"], schemes, ids=repr)
def test_run(scheme, N, do_plot=False):

# Path: odelab/system/exponential/burgers.py
# class BurgersComplex(Burgers):
# 	def __getstate__(self):
# 		state = self.__dict__.copy()
# 		del state['laplace']
# 		del state['points']
# 		del state['k']
# 		return state
# 
# 	def initialize(self):
# 		self.k = 2*np.pi*np.array(np.fft.fftfreq(self.size, 1/self.size),dtype='complex')
# 		self.k[len(self.k)/2] = 0
# 		self.laplace = self.viscosity*np.diag(self.k**2)
# 		x = np.linspace(0,1,self.size,endpoint=False)
# 		self.points = x - x.mean() # too lazy to compute x.mean manually here...
# 
# 	def preprocess(self, event0):
# 		return np.hstack([np.fft.fft(event0[:-1]), event0[-1]])
# 
# 	def postprocess(self, event1):
# 		return np.hstack([np.real(np.fft.ifft(event1[:-1])),event1[-1]])
# 
# 	def nonlin(self, t, u):
# 		return -0.5j * self.k * np.fft.fft(np.real(np.fft.ifft(u)) ** 2)


# Path: tests/scheme/test_exponential.py
from odelab.scheme import *
from odelab.scheme.exponential import *
from odelab.scheme.rungekutta import *
from odelab.scheme.generallinear import *
from odelab.scheme.classic import *
from odelab.system import *
from odelab.system.exponential.burgers import BurgersComplex
from odelab.solver import *
import numpy.testing as npt
import pytest
import scipy.linalg as slin
import odelab.scheme.exponential as E

	u0 = np.array([1.,0.])
	s.initialize(u0 = u0)

	s.run(time=1.)
	computed = s.final()[:-1]
	phi = Phi(0)
	tf = s.final_time()
	phi_0 = np.dot(phi(tf*L)[0], u0)
	expected = np.dot(slin.expm(tf*L), u0)
	CompareLinearExponential(scheme), computed, expected, phi_0

# Complex convection


def check_convection(scheme, time, h, B, u0, sol, do_plot):
	scheme.h = h
	s = SingleStepSolver(scheme, system=B, init_scheme=HochOst4(h=h))
	s.initialize(u0=u0)
	s.run(time=time)
	e1 = s.final()
	u1 = e1[:-1]
	if do_plot:
		pl.plot(B.points, u0)
		pl.plot(B.points, u1)
	npt.assert_array_almost_equal(u1, sol, decimal=2)

schemes = [ExplicitEuler(), 150], [Kutta4(), 10], [Kutta38(), 10], [Heun(), 10], [ABNorset4(), 50], [ABLawson2(), 50], [ABLawson3(), 50], [ABLawson4(), 50], [Lawson4(), 10], [GenLawson45(), 10], [LawsonEuler(), 150], [RKMK4T(), 10], [ode15s(), 2], [AdamsBashforth1(), 150], [AdamsBashforth2(), 50], [AdamsBashforth2e(), 50], [Butcher1(), 50], [Butcher3(), 120],

@pytest.mark.parametrize(["scheme", "N"], schemes, ids=repr)
def test_run(scheme, N, do_plot=False):

	B = BurgersComplex(viscosity=0., size=16)