def test_solver2(N, plot=True, version='scalar'): s = StoreSolution() s.main(N, version) print 'CPU time:', s.cpu if len(s.x) < 10: print s.solutions if plot: from py4cs.CurveViz import graph g = graph(program='Gnuplot', coor=s.x, ymax=1, ymin=-1) for s in s.solutions: g.plotcurve(s)
def __init__(self, solver, plot=0, **graphics_kwargs): """Store solver instance. Initialize graphics tool.""" self.s = solver self.solutions = [] # store self.up at each time level if not 'program' in graphics_kwargs: graphics_kwargs['program'] = 'Gnuplot' self._plot = plot if self._plot: self.g = graph(**graphics_kwargs) else: self.g = None
def test_solver_plug(plot=1, version='scalar', n=50): L = 1 c = 1 tstop = 2 def I(x): """Plug profile as initial condition.""" if abs(x - L / 2.0) > 0.1: return 0 else: return 1 def f(x, t): return 0 def U_0(t): return 0 def U_L(t): return 0 def action(u, x, t): print t, u if plot: g = graph(program='Gnuplot') g.configure(ymin=-1.1, ymax=1.1) else: g = None import time t0 = time.clock() solutions, x, dt, cpu = visualizer(I, f, c, U_0, U_L, L, n, 0, tstop, user_action=None, version=version, graphics=g) print 'CPU time: %s version =' % version, cpu # check that first and last (if tstop=2) are equal: if not allclose(solutions[0], solutions[-1], atol=1.0E-10, rtol=1.0E-12): print 'error in computations' else: print 'correct solution'
def test2(program, parent=None): from py4cs.CurveViz import graph t = sequence(-4, 4, 0.1, Float) g = graph(coor=t, ymin=-1.2, ymax=1.2, xlabel='t', program=program, parent_frame=parent) # make animations: for p in sequence(0, 3, 0.25): u = exp(-p*p)*(sin(t) + 0.2*sin(5*t)) g.plotcurve((t,u), legend='u(t); p=%4.2f' % p) # plot several curves in one plot: t = sequence(0, 10, 0.01) g.configure(coor=t) # change coordinate vector g.configure(ymin=-4, ymax=4, ylabel='u') u1 = sin(t)*t; u2 = sin(t)*sqrt(t) g.plotcurves([((t,u1),'t ampl.'),((t,u2),'sqrt(t) ampl.')], ps=1)