Created
September 18, 2013 11:30
-
-
Save FedericoV/6607867 to your computer and use it in GitHub Desktop.
Subclassing Explicit_Problem
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 'Testing: %s' %prob.text | |
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 "------------------------------------------------------------" | |
prob.text = "Test2" | |
exp_sim.reset() | |
print "Test 2: %s" %prob.text | |
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