Created
September 18, 2013 11:34
-
-
Save FedericoV/6607904 to your computer and use it in GitHub Desktop.
Assimulo Experiments 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from assimulo.solvers import CVode | |
from assimulo.problem import Explicit_Problem | |
import numpy as np | |
class MyProblem(Explicit_Problem): | |
def __init__(self, y0): | |
Explicit_Problem.__init__(self,y0=y0) | |
self.text = "Test" | |
#Define the rhs | |
def rhs(self, t,y): | |
print self.text | |
ydot = -y[0] | |
return np.array([ydot]) | |
#Define an Assimulo problem | |
prob = MyProblem(y0=4) | |
print 'Test:' | |
exp_mod = MyProblem(y0=4) | |
#Define an explicit solver | |
exp_sim = CVode(exp_mod) | |
exp_sim.iter = 'Newton' | |
exp_sim.discr = 'BDF' | |
exp_sim.rtol = 1e-7 | |
exp_sim.atol = 1e-6 | |
t, assi_y = exp_sim.simulate(4) #Simulate 100 seconds | |
print "------------------------------------------------------------" | |
print "Test 2:" | |
exp_sim.reset() | |
prob.text = "Test2" | |
t, assi_y = exp_sim.simulate(4) #Simulate 100 seconds | |
print "------------------------------------------------------------" | |
print "Test 3:" | |
exp_sim.reset() | |
exp_sim.problem.text = "Test3" | |
t, assi_y = exp_sim.simulate(4) #Simulate 100 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment