Ejemplo n.º 1
0
class TestVode(unittest.TestCase, TestSkeletonWithBackwards):
    def initialise(self, f, jac, **kwargs):
        self.integrator = ODE_wrapper(f, jac)
        self.integrator.set_integrator("vode")

    # Because this integrator likes to flood the screen with status reports rather than throwing an error
    def test_failed_integration(self):
        pass
Ejemplo n.º 2
0
    def set_integrator(self,
                       name,
                       nsteps=10**6,
                       interpolate=True,
                       **integrator_params):
        """
		Analogous to the function in SciPy’s ODE with the same name. This automatically generates the derivative and Jacobian if they do not exist yet and are needed. You can also choose integrators from `scipy.integrate.solve_ivp`.
		
		Parameters
		----------
		name: name of the integrator
			One of the following (or a new method supported by either backend):
			
			* `"dopri5"` – Dormand’s and Prince’s explicit fifth-order method via `ode`
			* `"RK45"` – Dormand’s and Prince’s explicit fifth-order method via `solve_ivp`
			* `"dop853"` – DoP853 (explicit) via `ode`
			* `"RK23"` – Bogacki’s and Shampine’s explicit third-order method via `solve_ivp`
			* `"BDF"` – Implicit backward-differentiation formula via `solve_ivp`
			* `"lsoda"` – LSODA (implicit) via `ode`
			* `"LSODA"` – LSODA (implicit) via `solve_ivp`
			* `"Radau"` – The implicit Radau method via `solve_ivp`
			* `"vode"` – VODE (implicit) via `ode`
			
			The `solve_ivp` methods are usually slightly faster for large differential equations, but they come with a massive overhead that makes them considerably slower for small differential equations. Implicit solvers are slower than explicit ones, except for stiff problems. If you don’t know what to choose, start with `"dopri5"`.
		
		nsteps: integer
 			Same as the respective parameter of the `ode` solvers, but with a higher default value to avoid annoying errors when getting rid of transients.
		
		interpolate: boolean
			Whether the sampled solutions for `solve_ivp` solvers shall be obtained using interpolation. If your sampling step is small, this may make things faster; otherwise it depends. This may also make the results slightly less accurate.
		
		integrator_params
			Parameters passed to the respective integrator. See its documentation for more.
		"""

        info = integrator_info(name)
        self._wants_jacobian |= info["wants_jac"]

        old_integrator = self.integrator

        self.generate_functions()

        if info["backend"] == "ode":
            self.integrator = ODE_wrapper(self.f, self.jac)
            self.integrator.set_integrator(name,
                                           nsteps=nsteps,
                                           **integrator_params)
        elif info["backend"] == "ivp":
            if not interpolate and name == "LSODA":
                raise NotImplementedError(
                    "LSODA doesn’t work without interpolation.")
            IVP = IVP_wrapper if interpolate else IVP_wrapper_no_interpolation
            self.integrator = IVP(name, self.f, self.jac, **integrator_params)

        # Restore state and params, if applicable:
        try:
            self.set_initial_value(old_integrator._y, old_integrator.t)
        except (AttributeError, RuntimeError):
            pass
        self.integrator.set_params(*old_integrator.params)
Ejemplo n.º 3
0
 def initialise(self, f, jac, **kwargs):
     self.integrator = ODE_wrapper(f, jac)
     self.integrator.set_integrator("vode")
Ejemplo n.º 4
0
 def initialise(self, f, jac, **kwargs):
     self.integrator = ODE_wrapper(f)
     self.integrator.set_integrator("dop853")
Ejemplo n.º 5
0
class TestDop853(unittest.TestCase, TestSkeletonWithBackwards):
    def initialise(self, f, jac, **kwargs):
        self.integrator = ODE_wrapper(f)
        self.integrator.set_integrator("dop853")