Exemplo n.º 1
0
    def get_solver(self, func):
        """
        Returns the solver method from odespy package.

        Args:
            func: function
            function with ODE system.

        Returns: an instance of odeSolver

        """

        if self.solverMethod is solverMethod.LSODA:
            solver = odespy.Lsoda(func)
        elif self.solverMethod is solverMethod.LSODAR:
            solver = odespy.Lsodar(func)
        elif self.solverMethod is solverMethod.LSODE:
            solver = odespy.Lsode(func)
        elif self.solverMethod is solverMethod.HEUN:
            solver = odespy.Heun(func)
        elif self.solverMethod is solverMethod.EULER:
            solver = odespy.Euler(func)
        elif self.solverMethod is solverMethod.RK4:
            solver = odespy.RK4(func)
        elif self.solverMethod is solverMethod.DORMAN_PRINCE:
            solver = odespy.DormandPrince(func)
        elif self.solverMethod is solverMethod.RKFehlberg:
            solver = odespy.RKFehlberg(func)
        elif self.solverMethod is solverMethod.Dopri5:
            solver = odespy.Dopri5(func)
        elif self.solverMethod is solverMethod.Dop853:
            solver = odespy.Dop853(func)
        elif self.solverMethod is solverMethod.Vode:
            solver = odespy.Vode(func)
        elif self.solverMethod is solverMethod.AdamsBashforth2:
            solver = odespy.AdamsBashforth2(func, method='bdf')
        elif self.solverMethod is solverMethod.Radau5:
            solver = odespy.Radau5(func)
        elif self.solverMethod is solverMethod.AdamsBashMoulton2:
            solver = odespy.AdamsBashMoulton2(func)

        # update default parameters
        solver.nsteps = SolverConfigurations.N_STEPS
        solver.atol = SolverConfigurations.ABSOLUTE_TOL
        solver.rtol = SolverConfigurations.RELATIVE_TOL

        return solver
Exemplo n.º 2
0
	return [f0, f1, f2, f3]

import odespy
import numpy as np
import sys

# initial conditions
N = int(sys.argv[1])					# initial population
#'''
pmax = 3								# max time
iterations = pmax * 10					# number of iterations
y0 = [N, 0., 0., 0.]					# initial condition vector
t  = np.linspace(0, pmax, iterations)	# time grid


solver = odespy.Lsode(f)
solver.set_initial_condition(y0)
u, t = solver.solve(t)

print("Tempo = {} seg\n".format(time.time() - start_time))

P0 = u[:,0]
P1 = u[:,1]
P2 = u[:,2]
P3 = u[:,3]

#k = len(Xd)
#print Xd[k-1]+Xi[k-1]+Xl[k-1]
#print Xe[k-1]+Xh[k-1]+Xl[k-1]
#print Xk[k-1]
for i in range(0, S):
Exemplo n.º 3
0
      subroutine f_f77(neq, t, u, udot)
Cf2py intent(hide) neq
Cf2py intent(out) udot
      integer neq
      double precision t, u, udot
      dimension u(neq), udot(neq)
      udot(1) = %.3f*u(1)*(1 - u(1)/%.1f)
      return
      end
""" % (a, R)
print f_f77_str
#import sys; sys.exit(1)

import odespy
f_f77 = odespy.compile_f77(f_f77_str)
solver = odespy.Lsode(f=None, f_f77=f_f77)

solver.set_initial_condition(A)

from numpy import linspace
T = 10  # end of simulation
N = 30  # no of time steps
time_points = linspace(0, T, N + 1)
u, t = solver.solve(time_points)

from matplotlib.pyplot import *

plot(t, u, 'r-')
savefig('tmppng')
savefig('tmp.pdf')
show()