# This is a test script for the Euler solver written in Fortran # To use it, simply do # >> import test_fEuler # >> test_fEuler.run() # defining the derivative functions: def f1(x,t): return x[0]*x[1] def f2(x,t): return -x[0]*t L = [f1,f2] # this is the array of derivatives (represents the ODE) # importing the extension module: import fEuler # we need fEuler.so or fEuler.pyd in the path... # we define here a routine similar to the one that will be # used from the 522 Simulator def step(f,x,t,dt): # we need to change the way f is called (to be consistent with # new interface of the solver def fun(i,x1,t1): return f[i](x1,t1) return fEuler.step(fun,x,t,dt) # setting the initial conditions: x = [1,2] t = 1.0 dt = 5.0 # the testing routine: def run(): newx = step(L,x,t,dt) # testing fEuler extension! print "step(f,x,t,dt) with f = [x[0]*x[1], -x[0]*t], x =", x, "t =", t, \ "and dt =", dt print "yields newx = ", newx print "This should be [11.0, -3.0] if everything works."