当前位置: 首页>>代码示例>>Python>>正文


Python System.add_leaf方法代码示例

本文整理汇总了Python中mbwind.System.add_leaf方法的典型用法代码示例。如果您正苦于以下问题:Python System.add_leaf方法的具体用法?Python System.add_leaf怎么用?Python System.add_leaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mbwind.System的用法示例。


在下文中一共展示了System.add_leaf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_nonzero_prescribed_acceleration

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_nonzero_prescribed_acceleration(self):
        # Test reduction where a prescribed acceleration is non-zero:
        # two sliders in series, with a mass on the end. If the second
        # slider's acceleration is prescribed, the first slider's DOF
        # sees an inertial force corresponding to the acceleration of
        # the mass.
        mass = 36.2
        s = System()
        s1 = PrismaticJoint('slider1', [1, 0, 0])
        s2 = PrismaticJoint('slider2', [1, 0, 0])
        b = RigidBody('body', mass)
        s.add_leaf(s1)
        s1.add_leaf(s2)
        s2.add_leaf(b)
        s.setup()

        s.prescribe(s2, acc=0)

        # With hinge angle = 0, no generalised inertial force
        rsys = ReducedSystem(s)
        assert_aae(rsys.M, mass)
        assert_aae(rsys.Q, 0)

        # With hinge angle = 90deg, do see generalised inertial force
        s.prescribe(s2, acc=2.3)
        rsys = ReducedSystem(s)
        assert_aae(rsys.M, mass)
        assert_aae(rsys.Q, -mass * 2.3)
开发者ID:ricklupton,项目名称:mbwind,代码行数:30,代码来源:test_reduced.py

示例2: test_single_rigid_body

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_single_rigid_body(self):
        mass = 36.2
        inertia = np.diag([75.4, 653, 234])
        s = System()
        j = FreeJoint('joint')
        b = RigidBody('body', mass, inertia)
        s.add_leaf(j)
        j.add_leaf(b)
        s.setup()

        # Calculate reduced system to get rigid body matrices
        rsys = ReducedSystem(s)
        self.assertEqual(rsys.M.shape, (6, 6))
        self.assertEqual(rsys.Q.shape, (6,))
        assert_aae(rsys.M[:3, :3], mass * np.eye(3))
        assert_aae(rsys.M[3:, 3:], inertia)
        assert_aae(rsys.M[3:, :3], 0)
        assert_aae(rsys.M[:3, 3:], 0)
        assert_aae(rsys.Q, 0)

        # Now if some freedoms are prescribed, don't appear in reduced system
        s.prescribe(j, part=[1, 2, 3, 4, 5])  # only x-translation is free now
        rsys = ReducedSystem(s)
        self.assertEqual(rsys.M.shape, (1, 1))
        self.assertEqual(rsys.Q.shape, (1,))
        assert_aae(rsys.M[0, 0], mass)
        assert_aae(rsys.Q, 0)
开发者ID:ricklupton,项目名称:mbwind,代码行数:29,代码来源:test_reduced.py

示例3: test_dof_index

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_dof_index(self):
        s = System()
        j1 = FreeJoint('j1')
        j2 = FreeJoint('j2')
        s.add_leaf(j1)
        j1.add_leaf(j2)
        s.setup()

        # Prescribe some of the strains:
        #          _____j1____   _____j2____
        # Strain:  0 1 2 3 4 5   0 1 2 3 4 5
        # Prescr:    *     *             *
        # Dofs:    0   1 2   3   4 5 6   7 8
        s.prescribe(j1, 0, part=[1, 4])
        s.prescribe(j2, 0, part=[3])

        self.assertEqual(s.dof_index('j1', 0), 0)
        self.assertEqual(s.dof_index('j1', 2), 1)
        self.assertEqual(s.dof_index('j1', 5), 3)
        self.assertEqual(s.dof_index('j2', 5), 8)

        # Strain index out of range should give IndexError
        with self.assertRaises(IndexError):
            s.dof_index('j1', 6)

        # Asking for index of prescribed strain should give ValueError
        with self.assertRaises(ValueError):
            s.dof_index('j1', 1)
开发者ID:ricklupton,项目名称:mbwind,代码行数:30,代码来源:test_system.py

示例4: test_call

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_call(self):
        s = System()
        c = RigidConnection('conn', [1, 0, 0])
        h = Hinge('hinge', [0, 1, 0])
        b = RigidBody('body', 1)
        s.add_leaf(h)
        h.add_leaf(c)
        c.add_leaf(b)
        s.setup()

        # Set hinge angle
        h.xstrain[0] = 0.82
        h.vstrain[0] = 1.2
        h.astrain[0] = -0.3
        s.update_kinematics()
        s.solve_reactions()

        # Test load outputs
        out = LoadOutput('node-1')
        assert_array_equal(out(s), s.joint_reactions['node-1'])

        out = LoadOutput('node-1', local=True)
        F = s.joint_reactions['node-1']
        assert_array_equal(out(s), np.r_[np.dot(b.Rp.T, F[:3]),
                                         np.dot(b.Rp.T, F[3:])])
开发者ID:ricklupton,项目名称:mbwind,代码行数:27,代码来源:test_integrator.py

示例5: test_solve_accelerations_coupling

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_solve_accelerations_coupling(self):
        # Further to test above, check that coupling between prescribed
        # accelerations and other dofs is correct. For example, if there
        # is a rigid body vertically offset from the joint, then a
        # prescribed horizontal acceleration should cause an angular
        # acceleration as well as the translational acceleration.
        s = System()
        j = FreeJoint('joint')
        c = RigidConnection('conn', [0, 0, 1.7])
        b = RigidBody('body', mass=23.54, inertia=74.1 * np.eye(3))
        s.add_leaf(j)
        j.add_leaf(c)
        c.add_leaf(b)
        s.setup()

        # Prescribe horizontal acceleration, solve other accelerations
        s.prescribe(j, 2.3, part=[0])  # x acceleration
        s.update_kinematics()          # update system to show prescribed acc
        s.solve_accelerations()        # solve free accelerations
        s.update_kinematics()          # update system to show solution

        # Ground shouldn't move
        assert_aae(j.ap, 0)

        # Need angular acceleration = (m a_x L) / I0
        I0 = 74.1 + (23.54 * 1.7**2)
        expected_angular_acc = -(23.54 * 2.3 * 1.7) / I0
        assert_aae(j.ad, [2.3, 0, 0, 0, expected_angular_acc, 0])
        assert_aae(j.astrain, j.ad)  # not always true, but works for FreeJoint
开发者ID:ricklupton,项目名称:mbwind,代码行数:31,代码来源:test_system.py

示例6: test_three_rigid_elements_as_disc_have_ends_in_right_place

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_three_rigid_elements_as_disc_have_ends_in_right_place(self):
        length = 20.0
        offset = 5.0

        # Make 3 elements spaced by 120 deg about z axis
        system = System()
        elements = []
        for i in range(3):
            rotmat = rotations(('z', i * 2*pi/3))
            offset_vector = dot(rotmat, [offset, 0, 0])
            conn = RigidConnection('offset%d' % i, offset_vector, rotmat)
            element = RigidConnection('element%d' % i, [length, 0, 0])
            elements.append(element)
            system.add_leaf(conn)
            conn.add_leaf(element)
        system.setup()

        r = offset
        R = offset + length
        assert_aae(elements[0].rp, [r,     0,           0])
        assert_aae(elements[1].rp, [-r/2,  r*sqrt(3)/2, 0])
        assert_aae(elements[2].rp, [-r/2, -r*sqrt(3)/2, 0])
        assert_aae(elements[0].rd, [R,     0,           0])
        assert_aae(elements[1].rd, [-R/2,  R*sqrt(3)/2, 0])
        assert_aae(elements[2].rd, [-R/2, -R*sqrt(3)/2, 0])
开发者ID:ricklupton,项目名称:mbwind,代码行数:27,代码来源:test_assemblies.py

示例7: test_adding_elements

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_adding_elements(self):
        conn = RigidConnection('conn')
        body = RigidBody('body', mass=1.235)
        s = System()
        s.add_leaf(conn)
        conn.add_leaf(body)
        s.setup()

        # Should have dict of elements
        self.assertEqual(s.elements, {'conn': conn, 'body': body})

        # Number of states:
        #   6 ground
        # + 6 constraints on conn
        # + 6 <node-0>   between conn and body
        # ---
        #  18
        self.assertEqual(s.lhs.shape, (18, 18))
        for vec in (s.rhs, s.qd, s.qdd):
            self.assertEqual(len(vec), 18)

        # Check there are no dofs
        self.assertEqual(len(s.q.dofs), 0)
        self.assertEqual(len(s.qd.dofs), 0)
        self.assertEqual(len(s.qdd.dofs), 0)
开发者ID:ricklupton,项目名称:mbwind,代码行数:27,代码来源:test_system.py

示例8: test_solve_reactions

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_solve_reactions(self):
        # Check it calls the Element method in the right order: down
        # the tree from leaves to base. It must also reset reactions.
        s = System()
        c0 = RigidConnection('c0')
        c1 = RigidConnection('c1')
        c2 = RigidConnection('c2')
        b1 = RigidBody('b1', 1)
        b2 = RigidBody('b2', 1)
        s.add_leaf(c0)
        c0.add_leaf(c1)
        c0.add_leaf(c2)
        c1.add_leaf(b1)
        c2.add_leaf(b2)
        s.setup()

        # Check elements' iter_reactions() are called
        def mock_iter_reactions(element):
            calls.append(element)
        calls = []
        import types
        for el in s.elements.values():
            el.iter_reactions = types.MethodType(mock_iter_reactions, el)

        # Test
        s.joint_reactions[:] = 3
        s.solve_reactions()
        self.assertEqual(calls, [b2, c2, b1, c1, c0])
        assert_aae(s.joint_reactions, 0)
开发者ID:ricklupton,项目名称:mbwind,代码行数:31,代码来源:test_system.py

示例9: test_solve_accelerations

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_solve_accelerations(self):
        # solve_accelerations() should find:
        #  (a) response of system to forces (here, gravity)
        #  (b) include any prescribed accelerations in qdd vector
        g = 9.81
        s = System(gravity=g)
        j = FreeJoint('joint')
        b = RigidBody('body', mass=23.54, inertia=52.1 * np.eye(3))
        s.add_leaf(j)
        j.add_leaf(b)
        s.setup()

        # Prescribe horizontal acceleration. Vertical acceleration
        # should result from gravity.
        s.prescribe(j, 2.3, part=[0])  # x acceleration

        # Initially accelerations are zero
        assert_aae(j.ap, 0)
        assert_aae(j.ad, 0)
        assert_aae(j.astrain, 0)

        # Solve accelerations & check
        s.solve_accelerations()
        s.update_kinematics()
        assert_aae(j.ap, 0)  # ground
        assert_aae(j.ad, [2.3, 0, -g, 0, 0, 0])
        assert_aae(j.astrain, j.ad)  # not always true, but works for FreeJoint
开发者ID:ricklupton,项目名称:mbwind,代码行数:29,代码来源:test_system.py

示例10: test_inertia_when_offset_axially

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_inertia_when_offset_axially(self):
        density = 230.4
        length = 20.0
        offset = 5.0
        element = _mock_rigid_uniform_beam(density, length)
        conn = RigidConnection('offset', offset=[offset, 0, 0])
        joint = FreeJoint('joint')

        system = System()
        system.add_leaf(joint)
        joint.add_leaf(conn)
        conn.add_leaf(element)
        system.setup()

        # Calculate reduced system to get rigid body matrices
        rsys = ReducedSystem(system)

        # Expected values: rod along x axis
        m = density * length
        Iy = m * (length**2 / 12 + (length/2 + offset)**2)
        expected_mass = m * eye(3)
        expected_inertia = diag([0, Iy, Iy])
        expected_offdiag = zeros((3, 3))

        # Y accel -> positive moment about Z
        # Z accel -> negative moment about Y
        expected_offdiag[2, 1] = +m * (length/2 + offset)
        expected_offdiag[1, 2] = -m * (length/2 + offset)

        assert_aae(rsys.M[:3, :3], expected_mass)
        assert_aae(rsys.M[3:, 3:], expected_inertia)
        assert_aae(rsys.M[3:, :3], expected_offdiag)
        assert_aae(rsys.M[:3, 3:], expected_offdiag.T)
开发者ID:ricklupton,项目名称:mbwind,代码行数:35,代码来源:test_assemblies.py

示例11: test_1dof_nonlinear_system

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_1dof_nonlinear_system(self):
        s = System()
        j = PrismaticJoint('joint', [0, 0, 1])
        k = 0.45  # quadratic stiffness coefficient
        j.internal_force = lambda el, t: -k * el.xstrain[0]**2
        b = RigidBody('body', 10)
        s.add_leaf(j)
        j.add_leaf(b)
        s.setup()

        # Linearise around z0 = 0: stiffness should be zero
        linsys = LinearisedSystem.from_system(s, z0=0)
        assert_aae(linsys.M, [[10.0]])
        assert_aae(linsys.C, [[0.0]])
        assert_aae(linsys.K, [[0.0]])

        # Linearise about z0 = 2: stiffness should be 2kx
        linsys = LinearisedSystem.from_system(s, z0=[2])
        assert_aae(linsys.M, [[10.0]])
        assert_aae(linsys.C, [[0.0]])
        assert_aae(linsys.K, [[2 * k * 2]])

        # Test setting z0 in another way
        linsys = LinearisedSystem.from_system(s, z0={'joint': [4.2]})
        assert_aae(linsys.M, [[10.0]])
        assert_aae(linsys.C, [[0.0]])
        assert_aae(linsys.K, [[2 * k * 4.2]])
开发者ID:ricklupton,项目名称:mbwind,代码行数:29,代码来源:test_linearisation.py

示例12: test_prescribe_free

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_prescribe_free(self):
        s = System()
        j = FreeJoint('joint')
        s.add_leaf(j)
        s.setup()
        s.time = 3.54

        # Initially all 6 joint motions are free
        self.assertEqual(len(s.q.dofs), 6)

        # Prescribing joint to be fixed results in no dofs
        s.prescribe(j)
        self.assertEqual(len(s.q.dofs), 0)

        # Freeing joint results in 6 dofs again
        s.free(j)
        self.assertEqual(len(s.q.dofs), 6)

        # Prescribing 2 of joint motions leaves 4 dofs
        s.prescribe(j, lambda t: t, [0, 2])
        self.assertEqual(len(s.q.dofs), 4)

        # Prescribing another joint motions leaves 3 dofs
        s.prescribe(j, 2.0, part=3)
        self.assertEqual(len(s.q.dofs), 3)

        # Check accelerations are applied to qdd
        assert_aae(s.qdd[j.istrain], 0)
        s.apply_prescribed_accelerations()
        assert_aae(s.qdd[j.istrain], [3.54, 0, 3.54, 2.0, 0, 0])

        # Freeing joint results in 6 dofs again
        s.free(j)
        self.assertEqual(len(s.q.dofs), 6)
开发者ID:ricklupton,项目名称:mbwind,代码行数:36,代码来源:test_system.py

示例13: test_simple_prescribed_integration

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_simple_prescribed_integration(self):
        s = System()
        h = Hinge('hinge', [0, 1, 0])
        s.add_leaf(h)
        s.setup()

        s.prescribe(h)
        w = h.vstrain[0] = 0.97  # rad/s

        integ = Integrator(s)
        t, y = integ.integrate(9.0, 0.1)

        # Check time vector and shape of result
        assert_array_equal(t, np.arange(0, 9.0, 0.1))
        self.assertEqual(len(y), 1)
        self.assertEqual(y[0].shape, (len(t), 1))

        # Result should be y = wt, but wrapped to [0, 2pi)
        assert_aae(y[0][:, 0], (w * t) % (2 * np.pi))

        # Check asking for velocity and acceleration works
        h.xstrain[0] = s.time = 0.0  # reset
        integ = Integrator(s, ('pos', 'vel', 'acc'))
        t, y = integ.integrate(1.0, 0.1)
        assert_array_equal(t, np.arange(0, 1.0, 0.1))
        self.assertEqual(len(y), 3)
        for yy in y:
            self.assertEqual(yy.shape, (len(t), 1))
        assert_aae(y[0][:, 0], w * t)
        assert_aae(y[1][:, 0], w)
        assert_aae(y[2][:, 0], 0)
开发者ID:ricklupton,项目名称:mbwind,代码行数:33,代码来源:test_integrator.py

示例14: test_rigid_body_with_no_dofs

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_rigid_body_with_no_dofs(self):
        s = System()
        b = RigidBody('body', 23.7)
        s.add_leaf(b)
        s.setup()

        # Calculate reduced system to get rigid body matrices
        rsys = ReducedSystem(s)
        self.assertEqual(rsys.M.shape, (0, 0))
        self.assertEqual(rsys.Q.shape, (0,))
开发者ID:ricklupton,项目名称:mbwind,代码行数:12,代码来源:test_reduced.py

示例15: test_accounts_for_offset_centre_of_mass_in_applied_force

# 需要导入模块: from mbwind import System [as 别名]
# 或者: from mbwind.System import add_leaf [as 别名]
    def test_accounts_for_offset_centre_of_mass_in_applied_force(self):
        # check applied force due to gravity is correct
        b = RigidBody("body", mass=5.6, Xc=[1.2, 3.4, 5.4])
        s = System(gravity=9.81)  # need a System to define gravity
        s.add_leaf(b)
        s.setup()

        b.calc_mass()
        b.calc_external_loading()
        assert_array_equal(b.applied_forces, b.mass * 9.81 * array([0, 0, -1, -3.4, 1.2, 0]))
开发者ID:ricklupton,项目名称:mbwind,代码行数:12,代码来源:test_element_rigidbody.py


注:本文中的mbwind.System.add_leaf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。