Skip to content

Commit

Permalink
Updated __init__ with version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
FHTMitchell committed Aug 20, 2017
1 parent b598c09 commit f03bb39
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion code/__init__.py → lagrange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def _ver_assert(module, req_ver, warn=True):
_ver_assert(_sp, (1, 0))
_ver_assert(_mpl, (2, 0, 0))

from . import driver, main, problem, solver, tests
from . import driver, problem, solver
14 changes: 7 additions & 7 deletions code/driver.py → lagrange/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import collections
import numpy as np

from .method import methods
from .stepper import Stepper
from .problem import Problem
from . import method as _method
from . import stepper as _stepper
from . import problem as _problem
from .timers import Timer

from typing import *
Expand All @@ -26,7 +26,7 @@ def static_stepsize_control(t, y, yd):

class Driver:
def __init__(self,
problem: Problem,
problem: _problem.Problem,
h0: float,
K: int,
L: int = 1,
Expand All @@ -51,7 +51,7 @@ def __init__(self,
"""


assert isinstance(problem, Problem), repr(problem)
assert isinstance(problem, _problem.Problem), repr(problem)
assert h0 > 0, repr(h0)
assert isinstance(K, int) and K >= 1, repr(K)
assert isinstance(L, int) and L >= 1, repr(L)
Expand All @@ -75,14 +75,14 @@ def __init__(self,
self.explicit_free_params = explicit_free_params or {}
self.implicit_free_params = implicit_free_params or {}

self.Method = methods()[self.method_name]
self.Method = _method.methods()[self.method_name]
self.explicit = self.Method(K, L, 'explicit', self.explicit_free_params)
if corrector_steps > 0:
self.implicit = self.Method(K, L, 'implicit', self.implicit_free_params)
else:
self.implicit = None

self.stepper = Stepper(self.stepsize_control, self.explicit, self.implicit)
self.stepper = _stepper.Stepper(self.stepsize_control, self.explicit, self.implicit)


def run(self, y0: np.ndarray, *, t0=None, tf=None) -> Tuple[np.ndarray, np.ndarray]:
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions code/main.py → lagrange/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# main.py

from .driver import Driver
from .problem import Lagrange
from .solver import Newton
from . import driver as _driver
from . import problem as _problem
from . import solver as _solver

__author__ = 'Mitchell, FHT'
__date__ = (2017, 8, 20)
Expand All @@ -18,9 +18,9 @@ def lagrange(x0=-1e-2, v0=1e-3, dx=1e-5):
:return:
"""

problem = Lagrange(1, legendre_order=3)
driver = Driver(problem, h0=0.001, K=2, L=1, tf=0.5)
solver = Newton(driver.displacement)
problem = _problem.Lagrange(1, legendre_order=3)
driver = _driver.Driver(problem, h0=0.001, K=2, L=1, tf=0.5)
solver = _solver.Newton(driver.displacement)
ans = solver.solve([x0, 0, 0, 0, v0, 0], dx=dx)

t, y = driver.run(ans[-1])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions code/stepper.py → lagrange/stepper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#stepper.py

import numpy as np
from .method import Method
from . import method as _method
from collections import deque
from typing import *

Expand All @@ -11,8 +11,8 @@

class Stepper:

def __init__(self, stepsize_control: Callable, explicit: Method,
implicit: Method = None):
def __init__(self, stepsize_control: Callable, explicit: _method.Method,
implicit: _method.Method = None):

self.stepsize_control = stepsize_control
self.explicit = explicit
Expand Down
6 changes: 3 additions & 3 deletions code/tests.py → lagrange/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
from problem import SHM, RTBP, Lagrange
from driver import Driver
from solver import Newton
from .problem import SHM, RTBP, Lagrange
from .driver import Driver
from .solver import Newton
from pprint import pprint

__author__ = 'Mitchell, FHT'
Expand Down
File renamed without changes.

0 comments on commit f03bb39

Please sign in to comment.