class Test_ContactOscillator(unittest.TestCase): def setUp(self): self.s = 3 self.co = ContactOscillator() def prepare(self): u = np.random.rand(7) us = np.column_stack([u] * self.s) return u, us def test_constraint(self): u, us = self.prepare() c = self.co.constraint(u) cs = self.co.constraint(us) npt.assert_array_almost_equal(cs - c.reshape(-1, 1), 0) def test_reaction_force(self): u, us = self.prepare() r = self.co.reaction_force(u) rs = self.co.reaction_force(us) npt.assert_array_almost_equal(rs - r.reshape(-1, 1), 0) def test_prop_lag(self): """ reaction force is proportional to lambda """ n = 5 u = np.random.rand(7) us = np.column_stack([u] * n) us[-1] = np.linspace(0, 1, 5) f = self.co.reaction_force(us) dfs = np.diff(f) npt.assert_array_almost_equal(dfs - dfs[:, 0:1], 0) def test_dynamics(self): u, us = self.prepare() d = self.co.multi_dynamics(u) ds = self.co.multi_dynamics(us) for k in d: npt.assert_array_almost_equal(ds[k] - d[k].reshape(-1, 1), 0) def test_initial(self): z0s = np.linspace(-0.9, 0.9, 10) * np.sqrt(2) u0 = self.co.initial_cos(z0s[5]) u00 = ContactSystem.initial(self.co, u0) self.assertFalse(u0 is u00) npt.assert_almost_equal(u0, u00)
class Test_ContactOscillator(unittest.TestCase): def setUp(self): self.s = 3 self.co = ContactOscillator() def prepare(self): u = np.random.rand(7) us = np.column_stack([u] * self.s) return u, us def test_constraint(self): u, us = self.prepare() c = self.co.constraint(u) cs = self.co.constraint(us) npt.assert_array_almost_equal(cs - c.reshape(-1, 1), 0) def test_reaction_force(self): u, us = self.prepare() r = self.co.reaction_force(u) rs = self.co.reaction_force(us) npt.assert_array_almost_equal(rs - r.reshape(-1, 1), 0) def test_prop_lag(self): """ reaction force is proportional to lambda """ n = 5 u = np.random.rand(7) us = np.column_stack([u] * n) us[-1] = np.linspace(0, 1, 5) f = self.co.reaction_force(us) dfs = np.diff(f) npt.assert_array_almost_equal(dfs - dfs[:, 0:1], 0) def test_dynamics(self): u, us = self.prepare() d = self.co.multi_dynamics(u) ds = self.co.multi_dynamics(us) for k in d: npt.assert_array_almost_equal(ds[k] - d[k].reshape(-1, 1), 0) def test_initial(self): z0s = np.linspace(-.9, .9, 10) * np.sqrt(2) u0 = self.co.initial_cos(z0s[5]) u00 = ContactSystem.initial(self.co, u0) self.assertFalse(u0 is u00) npt.assert_almost_equal(u0, u00)
class Test_ContactOscillator(object): def __init__(self, s=3): self.s = 3 def setUp(self): self.co = ContactOscillator() def prepare(self): u = np.random.rand(7) us = np.column_stack([u] * self.s) return u, us def test_constraint(self): u, us = self.prepare() c = self.co.constraint(u) cs = self.co.constraint(us) npt.assert_array_almost_equal(cs - c.reshape(-1, 1), 0) def test_reaction_force(self): u, us = self.prepare() r = self.co.reaction_force(u) rs = self.co.reaction_force(us) npt.assert_array_almost_equal(rs - r.reshape(-1, 1), 0) def test_prop_lag(self): """ reaction force is proportional to lambda """ n = 5 u = np.random.rand(7) us = np.column_stack([u] * n) us[-1] = np.linspace(0, 1, 5) f = self.co.reaction_force(us) dfs = np.diff(f) npt.assert_array_almost_equal(dfs - dfs[:, 0:1], 0) def test_dynamics(self): u, us = self.prepare() d = self.co.multi_dynamics(u) ds = self.co.multi_dynamics(us) for k in d: npt.assert_array_almost_equal(ds[k] - d[k].reshape(-1, 1), 0)
class Test_ContactOscillator(object): def __init__(self, s=3): self.s = 3 def setUp(self): self.co = ContactOscillator() def prepare(self): u = np.random.rand(7) us = np.column_stack([u]*self.s) return u, us def test_constraint(self): u, us = self.prepare() c = self.co.constraint(u) cs = self.co.constraint(us) npt.assert_array_almost_equal(cs - c.reshape(-1,1), 0) def test_reaction_force(self): u, us = self.prepare() r = self.co.reaction_force(u) rs = self.co.reaction_force(us) npt.assert_array_almost_equal(rs - r.reshape(-1,1), 0) def test_prop_lag(self): """ reaction force is proportional to lambda """ n = 5 u = np.random.rand(7) us = np.column_stack([u]*n) us[-1] = np.linspace(0,1,5) f = self.co.reaction_force(us) dfs = np.diff(f) npt.assert_array_almost_equal(dfs - dfs[:,0:1], 0) def test_dynamics(self): u, us = self.prepare() d = self.co.multi_dynamics(u) ds = self.co.multi_dynamics(us) for k in d: npt.assert_array_almost_equal(ds[k] - d[k].reshape(-1,1),0)
def setUp(self): self.co = ContactOscillator()
def setUp(self): self.sys = ContactOscillator()
def test_dynamics(self): u, us = self.prepare() d = self.co.multi_dynamics(u) ds = self.co.multi_dynamics(us) for k in d: npt.assert_array_almost_equal(ds[k] - d[k].reshape(-1, 1), 0) def test_initial(self): z0s = np.linspace(-.9, .9, 10) * np.sqrt(2) u0 = self.co.initial_cos(z0s[5]) u00 = ContactSystem.initial(self.co, u0) self.assertFalse(u0 is u00) npt.assert_almost_equal(u0, u00) @pytest.fixture(params=[ContactOscillator(), VerticalRollingDisk()]) def sys(request): return request.param def test_constraint(sys, nb_stages=4): u = np.random.random_sample([sys.size, nb_stages]) constraints = sys.constraint(u) for U, C in zip(u.T, constraints.T): npt.assert_array_almost_equal( np.dot(sys.codistribution(U), sys.velocity(U)), C) def test_reaction_force(sys, nb_stages=4): u = np.random.random_sample([sys.size, nb_stages]) force = sys.reaction_force(u)