Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/__init__.py +90 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/actuator.py +992 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/body.py +710 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/body_base.py +94 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/jointsmethod.py +318 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/kane.py +860 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/lagrange.py +512 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/linearize.py +474 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/particle.py +209 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/pathway.py +688 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/rigidbody.py +314 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/__init__.py +0 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/__pycache__/test_kane3.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_actuator.py +851 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_body.py +340 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_functions.py +262 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_kane3.py +315 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_method.py +5 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_rigidbody.py +184 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/wrapping_geometry.py +641 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/__pycache__/utils.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/tests/__pycache__/test_polarization.cpython-310.pyc +0 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_backward.h +26 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_chunk_cat_compositeexplicitautograd_dispatch.h +25 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_convolution.h +113 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_embedding_bag_dense_backward_compositeexplicitautograd_dispatch.h +26 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_lazy_clone_compositeexplicitautograd_dispatch.h +23 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_linalg_slogdet_compositeexplicitautogradnonfunctional_dispatch.h +23 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_unique2_cuda_dispatch.h +23 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_meta.h +27 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_nearest_exact1d_backward_compositeexplicitautogradnonfunctional_dispatch.h +24 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_use_cudnn_ctc_loss_ops.h +39 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/cholesky_solve_ops.h +39 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/conv_depthwise3d_native.h +22 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/cummaxmin_backward.h +30 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/div_meta_dispatch.h +30 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/erf_cuda_dispatch.h +26 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/fft_ihfft_compositeimplicitautograd_dispatch.h +28 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/hstack_native.h +22 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/kron_ops.h +39 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/linear_backward_native.h +22 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/log_normal_cuda_dispatch.h +23 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/logaddexp_cuda_dispatch.h +25 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/logdet_compositeimplicitautograd_dispatch.h +23 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/lshift.h +53 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/masked_fill_meta_dispatch.h +24 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/max_pool3d_with_indices_backward_cuda_dispatch.h +25 -0
- falcon/lib/python3.10/site-packages/torch/include/ATen/ops/miopen_rnn_ops.h +39 -0
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = [
|
| 2 |
+
'vector',
|
| 3 |
+
|
| 4 |
+
'CoordinateSym', 'ReferenceFrame', 'Dyadic', 'Vector', 'Point', 'cross',
|
| 5 |
+
'dot', 'express', 'time_derivative', 'outer', 'kinematic_equations',
|
| 6 |
+
'get_motion_params', 'partial_velocity', 'dynamicsymbols', 'vprint',
|
| 7 |
+
'vsstrrepr', 'vsprint', 'vpprint', 'vlatex', 'init_vprinting', 'curl',
|
| 8 |
+
'divergence', 'gradient', 'is_conservative', 'is_solenoidal',
|
| 9 |
+
'scalar_potential', 'scalar_potential_difference',
|
| 10 |
+
|
| 11 |
+
'KanesMethod',
|
| 12 |
+
|
| 13 |
+
'RigidBody',
|
| 14 |
+
|
| 15 |
+
'linear_momentum', 'angular_momentum', 'kinetic_energy', 'potential_energy',
|
| 16 |
+
'Lagrangian', 'mechanics_printing', 'mprint', 'msprint', 'mpprint',
|
| 17 |
+
'mlatex', 'msubs', 'find_dynamicsymbols',
|
| 18 |
+
|
| 19 |
+
'inertia', 'inertia_of_point_mass', 'Inertia',
|
| 20 |
+
|
| 21 |
+
'Force', 'Torque',
|
| 22 |
+
|
| 23 |
+
'Particle',
|
| 24 |
+
|
| 25 |
+
'LagrangesMethod',
|
| 26 |
+
|
| 27 |
+
'Linearizer',
|
| 28 |
+
|
| 29 |
+
'Body',
|
| 30 |
+
|
| 31 |
+
'SymbolicSystem', 'System',
|
| 32 |
+
|
| 33 |
+
'PinJoint', 'PrismaticJoint', 'CylindricalJoint', 'PlanarJoint',
|
| 34 |
+
'SphericalJoint', 'WeldJoint',
|
| 35 |
+
|
| 36 |
+
'JointsMethod',
|
| 37 |
+
|
| 38 |
+
'WrappingCylinder', 'WrappingGeometryBase', 'WrappingSphere',
|
| 39 |
+
|
| 40 |
+
'PathwayBase', 'LinearPathway', 'ObstacleSetPathway', 'WrappingPathway',
|
| 41 |
+
|
| 42 |
+
'ActuatorBase', 'ForceActuator', 'LinearDamper', 'LinearSpring',
|
| 43 |
+
'TorqueActuator', 'DuffingSpring'
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
from sympy.physics import vector
|
| 47 |
+
|
| 48 |
+
from sympy.physics.vector import (CoordinateSym, ReferenceFrame, Dyadic, Vector, Point,
|
| 49 |
+
cross, dot, express, time_derivative, outer, kinematic_equations,
|
| 50 |
+
get_motion_params, partial_velocity, dynamicsymbols, vprint,
|
| 51 |
+
vsstrrepr, vsprint, vpprint, vlatex, init_vprinting, curl, divergence,
|
| 52 |
+
gradient, is_conservative, is_solenoidal, scalar_potential,
|
| 53 |
+
scalar_potential_difference)
|
| 54 |
+
|
| 55 |
+
from .kane import KanesMethod
|
| 56 |
+
|
| 57 |
+
from .rigidbody import RigidBody
|
| 58 |
+
|
| 59 |
+
from .functions import (linear_momentum, angular_momentum, kinetic_energy,
|
| 60 |
+
potential_energy, Lagrangian, mechanics_printing,
|
| 61 |
+
mprint, msprint, mpprint, mlatex, msubs,
|
| 62 |
+
find_dynamicsymbols)
|
| 63 |
+
|
| 64 |
+
from .inertia import inertia, inertia_of_point_mass, Inertia
|
| 65 |
+
|
| 66 |
+
from .loads import Force, Torque
|
| 67 |
+
|
| 68 |
+
from .particle import Particle
|
| 69 |
+
|
| 70 |
+
from .lagrange import LagrangesMethod
|
| 71 |
+
|
| 72 |
+
from .linearize import Linearizer
|
| 73 |
+
|
| 74 |
+
from .body import Body
|
| 75 |
+
|
| 76 |
+
from .system import SymbolicSystem, System
|
| 77 |
+
|
| 78 |
+
from .jointsmethod import JointsMethod
|
| 79 |
+
|
| 80 |
+
from .joint import (PinJoint, PrismaticJoint, CylindricalJoint, PlanarJoint,
|
| 81 |
+
SphericalJoint, WeldJoint)
|
| 82 |
+
|
| 83 |
+
from .wrapping_geometry import (WrappingCylinder, WrappingGeometryBase,
|
| 84 |
+
WrappingSphere)
|
| 85 |
+
|
| 86 |
+
from .pathway import (PathwayBase, LinearPathway, ObstacleSetPathway,
|
| 87 |
+
WrappingPathway)
|
| 88 |
+
|
| 89 |
+
from .actuator import (ActuatorBase, ForceActuator, LinearDamper, LinearSpring,
|
| 90 |
+
TorqueActuator, DuffingSpring)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/actuator.py
ADDED
|
@@ -0,0 +1,992 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Implementations of actuators for linked force and torque application."""
|
| 2 |
+
|
| 3 |
+
from abc import ABC, abstractmethod
|
| 4 |
+
|
| 5 |
+
from sympy import S, sympify
|
| 6 |
+
from sympy.physics.mechanics.joint import PinJoint
|
| 7 |
+
from sympy.physics.mechanics.loads import Torque
|
| 8 |
+
from sympy.physics.mechanics.pathway import PathwayBase
|
| 9 |
+
from sympy.physics.mechanics.rigidbody import RigidBody
|
| 10 |
+
from sympy.physics.vector import ReferenceFrame, Vector
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
__all__ = [
|
| 14 |
+
'ActuatorBase',
|
| 15 |
+
'ForceActuator',
|
| 16 |
+
'LinearDamper',
|
| 17 |
+
'LinearSpring',
|
| 18 |
+
'TorqueActuator',
|
| 19 |
+
'DuffingSpring'
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class ActuatorBase(ABC):
|
| 24 |
+
"""Abstract base class for all actuator classes to inherit from.
|
| 25 |
+
|
| 26 |
+
Notes
|
| 27 |
+
=====
|
| 28 |
+
|
| 29 |
+
Instances of this class cannot be directly instantiated by users. However,
|
| 30 |
+
it can be used to created custom actuator types through subclassing.
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def __init__(self):
|
| 35 |
+
"""Initializer for ``ActuatorBase``."""
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
@abstractmethod
|
| 39 |
+
def to_loads(self):
|
| 40 |
+
"""Loads required by the equations of motion method classes.
|
| 41 |
+
|
| 42 |
+
Explanation
|
| 43 |
+
===========
|
| 44 |
+
|
| 45 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 46 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 47 |
+
when constructing the equations of motion. This method acts as a
|
| 48 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 49 |
+
required so that these can be easily concatenated with other items in
|
| 50 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 51 |
+
loads are also in the correct form to also be passed to the other
|
| 52 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 53 |
+
|
| 54 |
+
"""
|
| 55 |
+
pass
|
| 56 |
+
|
| 57 |
+
def __repr__(self):
|
| 58 |
+
"""Default representation of an actuator."""
|
| 59 |
+
return f'{self.__class__.__name__}()'
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class ForceActuator(ActuatorBase):
|
| 63 |
+
"""Force-producing actuator.
|
| 64 |
+
|
| 65 |
+
Explanation
|
| 66 |
+
===========
|
| 67 |
+
|
| 68 |
+
A ``ForceActuator`` is an actuator that produces a (expansile) force along
|
| 69 |
+
its length.
|
| 70 |
+
|
| 71 |
+
A force actuator uses a pathway instance to determine the direction and
|
| 72 |
+
number of forces that it applies to a system. Consider the simplest case
|
| 73 |
+
where a ``LinearPathway`` instance is used. This pathway is made up of two
|
| 74 |
+
points that can move relative to each other, and results in a pair of equal
|
| 75 |
+
and opposite forces acting on the endpoints. If the positive time-varying
|
| 76 |
+
Euclidean distance between the two points is defined, then the "extension
|
| 77 |
+
velocity" is the time derivative of this distance. The extension velocity
|
| 78 |
+
is positive when the two points are moving away from each other and
|
| 79 |
+
negative when moving closer to each other. The direction for the force
|
| 80 |
+
acting on either point is determined by constructing a unit vector directed
|
| 81 |
+
from the other point to this point. This establishes a sign convention such
|
| 82 |
+
that a positive force magnitude tends to push the points apart, this is the
|
| 83 |
+
meaning of "expansile" in this context. The following diagram shows the
|
| 84 |
+
positive force sense and the distance between the points::
|
| 85 |
+
|
| 86 |
+
P Q
|
| 87 |
+
o<--- F --->o
|
| 88 |
+
| |
|
| 89 |
+
|<--l(t)--->|
|
| 90 |
+
|
| 91 |
+
Examples
|
| 92 |
+
========
|
| 93 |
+
|
| 94 |
+
To construct an actuator, an expression (or symbol) must be supplied to
|
| 95 |
+
represent the force it can produce, alongside a pathway specifying its line
|
| 96 |
+
of action. Let's also create a global reference frame and spatially fix one
|
| 97 |
+
of the points in it while setting the other to be positioned such that it
|
| 98 |
+
can freely move in the frame's x direction specified by the coordinate
|
| 99 |
+
``q``.
|
| 100 |
+
|
| 101 |
+
>>> from sympy import symbols
|
| 102 |
+
>>> from sympy.physics.mechanics import (ForceActuator, LinearPathway,
|
| 103 |
+
... Point, ReferenceFrame)
|
| 104 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 105 |
+
>>> N = ReferenceFrame('N')
|
| 106 |
+
>>> q = dynamicsymbols('q')
|
| 107 |
+
>>> force = symbols('F')
|
| 108 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 109 |
+
>>> pA.set_vel(N, 0)
|
| 110 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 111 |
+
>>> pB.pos_from(pA)
|
| 112 |
+
q(t)*N.x
|
| 113 |
+
>>> linear_pathway = LinearPathway(pA, pB)
|
| 114 |
+
>>> actuator = ForceActuator(force, linear_pathway)
|
| 115 |
+
>>> actuator
|
| 116 |
+
ForceActuator(F, LinearPathway(pA, pB))
|
| 117 |
+
|
| 118 |
+
Parameters
|
| 119 |
+
==========
|
| 120 |
+
|
| 121 |
+
force : Expr
|
| 122 |
+
The scalar expression defining the (expansile) force that the actuator
|
| 123 |
+
produces.
|
| 124 |
+
pathway : PathwayBase
|
| 125 |
+
The pathway that the actuator follows. This must be an instance of a
|
| 126 |
+
concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 127 |
+
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
def __init__(self, force, pathway):
|
| 131 |
+
"""Initializer for ``ForceActuator``.
|
| 132 |
+
|
| 133 |
+
Parameters
|
| 134 |
+
==========
|
| 135 |
+
|
| 136 |
+
force : Expr
|
| 137 |
+
The scalar expression defining the (expansile) force that the
|
| 138 |
+
actuator produces.
|
| 139 |
+
pathway : PathwayBase
|
| 140 |
+
The pathway that the actuator follows. This must be an instance of
|
| 141 |
+
a concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 142 |
+
|
| 143 |
+
"""
|
| 144 |
+
self.force = force
|
| 145 |
+
self.pathway = pathway
|
| 146 |
+
|
| 147 |
+
@property
|
| 148 |
+
def force(self):
|
| 149 |
+
"""The magnitude of the force produced by the actuator."""
|
| 150 |
+
return self._force
|
| 151 |
+
|
| 152 |
+
@force.setter
|
| 153 |
+
def force(self, force):
|
| 154 |
+
if hasattr(self, '_force'):
|
| 155 |
+
msg = (
|
| 156 |
+
f'Can\'t set attribute `force` to {repr(force)} as it is '
|
| 157 |
+
f'immutable.'
|
| 158 |
+
)
|
| 159 |
+
raise AttributeError(msg)
|
| 160 |
+
self._force = sympify(force, strict=True)
|
| 161 |
+
|
| 162 |
+
@property
|
| 163 |
+
def pathway(self):
|
| 164 |
+
"""The ``Pathway`` defining the actuator's line of action."""
|
| 165 |
+
return self._pathway
|
| 166 |
+
|
| 167 |
+
@pathway.setter
|
| 168 |
+
def pathway(self, pathway):
|
| 169 |
+
if hasattr(self, '_pathway'):
|
| 170 |
+
msg = (
|
| 171 |
+
f'Can\'t set attribute `pathway` to {repr(pathway)} as it is '
|
| 172 |
+
f'immutable.'
|
| 173 |
+
)
|
| 174 |
+
raise AttributeError(msg)
|
| 175 |
+
if not isinstance(pathway, PathwayBase):
|
| 176 |
+
msg = (
|
| 177 |
+
f'Value {repr(pathway)} passed to `pathway` was of type '
|
| 178 |
+
f'{type(pathway)}, must be {PathwayBase}.'
|
| 179 |
+
)
|
| 180 |
+
raise TypeError(msg)
|
| 181 |
+
self._pathway = pathway
|
| 182 |
+
|
| 183 |
+
def to_loads(self):
|
| 184 |
+
"""Loads required by the equations of motion method classes.
|
| 185 |
+
|
| 186 |
+
Explanation
|
| 187 |
+
===========
|
| 188 |
+
|
| 189 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 190 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 191 |
+
when constructing the equations of motion. This method acts as a
|
| 192 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 193 |
+
required so that these can be easily concatenated with other items in
|
| 194 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 195 |
+
loads are also in the correct form to also be passed to the other
|
| 196 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 197 |
+
|
| 198 |
+
Examples
|
| 199 |
+
========
|
| 200 |
+
|
| 201 |
+
The below example shows how to generate the loads produced by a force
|
| 202 |
+
actuator that follows a linear pathway. In this example we'll assume
|
| 203 |
+
that the force actuator is being used to model a simple linear spring.
|
| 204 |
+
First, create a linear pathway between two points separated by the
|
| 205 |
+
coordinate ``q`` in the ``x`` direction of the global frame ``N``.
|
| 206 |
+
|
| 207 |
+
>>> from sympy.physics.mechanics import (LinearPathway, Point,
|
| 208 |
+
... ReferenceFrame)
|
| 209 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 210 |
+
>>> q = dynamicsymbols('q')
|
| 211 |
+
>>> N = ReferenceFrame('N')
|
| 212 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 213 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 214 |
+
>>> pathway = LinearPathway(pA, pB)
|
| 215 |
+
|
| 216 |
+
Now create a symbol ``k`` to describe the spring's stiffness and
|
| 217 |
+
instantiate a force actuator that produces a (contractile) force
|
| 218 |
+
proportional to both the spring's stiffness and the pathway's length.
|
| 219 |
+
Note that actuator classes use the sign convention that expansile
|
| 220 |
+
forces are positive, so for a spring to produce a contractile force the
|
| 221 |
+
spring force needs to be calculated as the negative for the stiffness
|
| 222 |
+
multiplied by the length.
|
| 223 |
+
|
| 224 |
+
>>> from sympy import symbols
|
| 225 |
+
>>> from sympy.physics.mechanics import ForceActuator
|
| 226 |
+
>>> stiffness = symbols('k')
|
| 227 |
+
>>> spring_force = -stiffness*pathway.length
|
| 228 |
+
>>> spring = ForceActuator(spring_force, pathway)
|
| 229 |
+
|
| 230 |
+
The forces produced by the spring can be generated in the list of loads
|
| 231 |
+
form that ``KanesMethod`` (and other equations of motion methods)
|
| 232 |
+
requires by calling the ``to_loads`` method.
|
| 233 |
+
|
| 234 |
+
>>> spring.to_loads()
|
| 235 |
+
[(pA, k*q(t)*N.x), (pB, - k*q(t)*N.x)]
|
| 236 |
+
|
| 237 |
+
A simple linear damper can be modeled in a similar way. Create another
|
| 238 |
+
symbol ``c`` to describe the dampers damping coefficient. This time
|
| 239 |
+
instantiate a force actuator that produces a force proportional to both
|
| 240 |
+
the damper's damping coefficient and the pathway's extension velocity.
|
| 241 |
+
Note that the damping force is negative as it acts in the opposite
|
| 242 |
+
direction to which the damper is changing in length.
|
| 243 |
+
|
| 244 |
+
>>> damping_coefficient = symbols('c')
|
| 245 |
+
>>> damping_force = -damping_coefficient*pathway.extension_velocity
|
| 246 |
+
>>> damper = ForceActuator(damping_force, pathway)
|
| 247 |
+
|
| 248 |
+
Again, the forces produces by the damper can be generated by calling
|
| 249 |
+
the ``to_loads`` method.
|
| 250 |
+
|
| 251 |
+
>>> damper.to_loads()
|
| 252 |
+
[(pA, c*Derivative(q(t), t)*N.x), (pB, - c*Derivative(q(t), t)*N.x)]
|
| 253 |
+
|
| 254 |
+
"""
|
| 255 |
+
return self.pathway.to_loads(self.force)
|
| 256 |
+
|
| 257 |
+
def __repr__(self):
|
| 258 |
+
"""Representation of a ``ForceActuator``."""
|
| 259 |
+
return f'{self.__class__.__name__}({self.force}, {self.pathway})'
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
class LinearSpring(ForceActuator):
|
| 263 |
+
"""A spring with its spring force as a linear function of its length.
|
| 264 |
+
|
| 265 |
+
Explanation
|
| 266 |
+
===========
|
| 267 |
+
|
| 268 |
+
Note that the "linear" in the name ``LinearSpring`` refers to the fact that
|
| 269 |
+
the spring force is a linear function of the springs length. I.e. for a
|
| 270 |
+
linear spring with stiffness ``k``, distance between its ends of ``x``, and
|
| 271 |
+
an equilibrium length of ``0``, the spring force will be ``-k*x``, which is
|
| 272 |
+
a linear function in ``x``. To create a spring that follows a linear, or
|
| 273 |
+
straight, pathway between its two ends, a ``LinearPathway`` instance needs
|
| 274 |
+
to be passed to the ``pathway`` parameter.
|
| 275 |
+
|
| 276 |
+
A ``LinearSpring`` is a subclass of ``ForceActuator`` and so follows the
|
| 277 |
+
same sign conventions for length, extension velocity, and the direction of
|
| 278 |
+
the forces it applies to its points of attachment on bodies. The sign
|
| 279 |
+
convention for the direction of forces is such that, for the case where a
|
| 280 |
+
linear spring is instantiated with a ``LinearPathway`` instance as its
|
| 281 |
+
pathway, they act to push the two ends of the spring away from one another.
|
| 282 |
+
Because springs produces a contractile force and acts to pull the two ends
|
| 283 |
+
together towards the equilibrium length when stretched, the scalar portion
|
| 284 |
+
of the forces on the endpoint are negative in order to flip the sign of the
|
| 285 |
+
forces on the endpoints when converted into vector quantities. The
|
| 286 |
+
following diagram shows the positive force sense and the distance between
|
| 287 |
+
the points::
|
| 288 |
+
|
| 289 |
+
P Q
|
| 290 |
+
o<--- F --->o
|
| 291 |
+
| |
|
| 292 |
+
|<--l(t)--->|
|
| 293 |
+
|
| 294 |
+
Examples
|
| 295 |
+
========
|
| 296 |
+
|
| 297 |
+
To construct a linear spring, an expression (or symbol) must be supplied to
|
| 298 |
+
represent the stiffness (spring constant) of the spring, alongside a
|
| 299 |
+
pathway specifying its line of action. Let's also create a global reference
|
| 300 |
+
frame and spatially fix one of the points in it while setting the other to
|
| 301 |
+
be positioned such that it can freely move in the frame's x direction
|
| 302 |
+
specified by the coordinate ``q``.
|
| 303 |
+
|
| 304 |
+
>>> from sympy import symbols
|
| 305 |
+
>>> from sympy.physics.mechanics import (LinearPathway, LinearSpring,
|
| 306 |
+
... Point, ReferenceFrame)
|
| 307 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 308 |
+
>>> N = ReferenceFrame('N')
|
| 309 |
+
>>> q = dynamicsymbols('q')
|
| 310 |
+
>>> stiffness = symbols('k')
|
| 311 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 312 |
+
>>> pA.set_vel(N, 0)
|
| 313 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 314 |
+
>>> pB.pos_from(pA)
|
| 315 |
+
q(t)*N.x
|
| 316 |
+
>>> linear_pathway = LinearPathway(pA, pB)
|
| 317 |
+
>>> spring = LinearSpring(stiffness, linear_pathway)
|
| 318 |
+
>>> spring
|
| 319 |
+
LinearSpring(k, LinearPathway(pA, pB))
|
| 320 |
+
|
| 321 |
+
This spring will produce a force that is proportional to both its stiffness
|
| 322 |
+
and the pathway's length. Note that this force is negative as SymPy's sign
|
| 323 |
+
convention for actuators is that negative forces are contractile.
|
| 324 |
+
|
| 325 |
+
>>> spring.force
|
| 326 |
+
-k*sqrt(q(t)**2)
|
| 327 |
+
|
| 328 |
+
To create a linear spring with a non-zero equilibrium length, an expression
|
| 329 |
+
(or symbol) can be passed to the ``equilibrium_length`` parameter on
|
| 330 |
+
construction on a ``LinearSpring`` instance. Let's create a symbol ``l``
|
| 331 |
+
to denote a non-zero equilibrium length and create another linear spring.
|
| 332 |
+
|
| 333 |
+
>>> l = symbols('l')
|
| 334 |
+
>>> spring = LinearSpring(stiffness, linear_pathway, equilibrium_length=l)
|
| 335 |
+
>>> spring
|
| 336 |
+
LinearSpring(k, LinearPathway(pA, pB), equilibrium_length=l)
|
| 337 |
+
|
| 338 |
+
The spring force of this new spring is again proportional to both its
|
| 339 |
+
stiffness and the pathway's length. However, the spring will not produce
|
| 340 |
+
any force when ``q(t)`` equals ``l``. Note that the force will become
|
| 341 |
+
expansile when ``q(t)`` is less than ``l``, as expected.
|
| 342 |
+
|
| 343 |
+
>>> spring.force
|
| 344 |
+
-k*(-l + sqrt(q(t)**2))
|
| 345 |
+
|
| 346 |
+
Parameters
|
| 347 |
+
==========
|
| 348 |
+
|
| 349 |
+
stiffness : Expr
|
| 350 |
+
The spring constant.
|
| 351 |
+
pathway : PathwayBase
|
| 352 |
+
The pathway that the actuator follows. This must be an instance of a
|
| 353 |
+
concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 354 |
+
equilibrium_length : Expr, optional
|
| 355 |
+
The length at which the spring is in equilibrium, i.e. it produces no
|
| 356 |
+
force. The default value is 0, i.e. the spring force is a linear
|
| 357 |
+
function of the pathway's length with no constant offset.
|
| 358 |
+
|
| 359 |
+
See Also
|
| 360 |
+
========
|
| 361 |
+
|
| 362 |
+
ForceActuator: force-producing actuator (superclass of ``LinearSpring``).
|
| 363 |
+
LinearPathway: straight-line pathway between a pair of points.
|
| 364 |
+
|
| 365 |
+
"""
|
| 366 |
+
|
| 367 |
+
def __init__(self, stiffness, pathway, equilibrium_length=S.Zero):
|
| 368 |
+
"""Initializer for ``LinearSpring``.
|
| 369 |
+
|
| 370 |
+
Parameters
|
| 371 |
+
==========
|
| 372 |
+
|
| 373 |
+
stiffness : Expr
|
| 374 |
+
The spring constant.
|
| 375 |
+
pathway : PathwayBase
|
| 376 |
+
The pathway that the actuator follows. This must be an instance of
|
| 377 |
+
a concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 378 |
+
equilibrium_length : Expr, optional
|
| 379 |
+
The length at which the spring is in equilibrium, i.e. it produces
|
| 380 |
+
no force. The default value is 0, i.e. the spring force is a linear
|
| 381 |
+
function of the pathway's length with no constant offset.
|
| 382 |
+
|
| 383 |
+
"""
|
| 384 |
+
self.stiffness = stiffness
|
| 385 |
+
self.pathway = pathway
|
| 386 |
+
self.equilibrium_length = equilibrium_length
|
| 387 |
+
|
| 388 |
+
@property
|
| 389 |
+
def force(self):
|
| 390 |
+
"""The spring force produced by the linear spring."""
|
| 391 |
+
return -self.stiffness*(self.pathway.length - self.equilibrium_length)
|
| 392 |
+
|
| 393 |
+
@force.setter
|
| 394 |
+
def force(self, force):
|
| 395 |
+
raise AttributeError('Can\'t set computed attribute `force`.')
|
| 396 |
+
|
| 397 |
+
@property
|
| 398 |
+
def stiffness(self):
|
| 399 |
+
"""The spring constant for the linear spring."""
|
| 400 |
+
return self._stiffness
|
| 401 |
+
|
| 402 |
+
@stiffness.setter
|
| 403 |
+
def stiffness(self, stiffness):
|
| 404 |
+
if hasattr(self, '_stiffness'):
|
| 405 |
+
msg = (
|
| 406 |
+
f'Can\'t set attribute `stiffness` to {repr(stiffness)} as it '
|
| 407 |
+
f'is immutable.'
|
| 408 |
+
)
|
| 409 |
+
raise AttributeError(msg)
|
| 410 |
+
self._stiffness = sympify(stiffness, strict=True)
|
| 411 |
+
|
| 412 |
+
@property
|
| 413 |
+
def equilibrium_length(self):
|
| 414 |
+
"""The length of the spring at which it produces no force."""
|
| 415 |
+
return self._equilibrium_length
|
| 416 |
+
|
| 417 |
+
@equilibrium_length.setter
|
| 418 |
+
def equilibrium_length(self, equilibrium_length):
|
| 419 |
+
if hasattr(self, '_equilibrium_length'):
|
| 420 |
+
msg = (
|
| 421 |
+
f'Can\'t set attribute `equilibrium_length` to '
|
| 422 |
+
f'{repr(equilibrium_length)} as it is immutable.'
|
| 423 |
+
)
|
| 424 |
+
raise AttributeError(msg)
|
| 425 |
+
self._equilibrium_length = sympify(equilibrium_length, strict=True)
|
| 426 |
+
|
| 427 |
+
def __repr__(self):
|
| 428 |
+
"""Representation of a ``LinearSpring``."""
|
| 429 |
+
string = f'{self.__class__.__name__}({self.stiffness}, {self.pathway}'
|
| 430 |
+
if self.equilibrium_length == S.Zero:
|
| 431 |
+
string += ')'
|
| 432 |
+
else:
|
| 433 |
+
string += f', equilibrium_length={self.equilibrium_length})'
|
| 434 |
+
return string
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class LinearDamper(ForceActuator):
|
| 438 |
+
"""A damper whose force is a linear function of its extension velocity.
|
| 439 |
+
|
| 440 |
+
Explanation
|
| 441 |
+
===========
|
| 442 |
+
|
| 443 |
+
Note that the "linear" in the name ``LinearDamper`` refers to the fact that
|
| 444 |
+
the damping force is a linear function of the damper's rate of change in
|
| 445 |
+
its length. I.e. for a linear damper with damping ``c`` and extension
|
| 446 |
+
velocity ``v``, the damping force will be ``-c*v``, which is a linear
|
| 447 |
+
function in ``v``. To create a damper that follows a linear, or straight,
|
| 448 |
+
pathway between its two ends, a ``LinearPathway`` instance needs to be
|
| 449 |
+
passed to the ``pathway`` parameter.
|
| 450 |
+
|
| 451 |
+
A ``LinearDamper`` is a subclass of ``ForceActuator`` and so follows the
|
| 452 |
+
same sign conventions for length, extension velocity, and the direction of
|
| 453 |
+
the forces it applies to its points of attachment on bodies. The sign
|
| 454 |
+
convention for the direction of forces is such that, for the case where a
|
| 455 |
+
linear damper is instantiated with a ``LinearPathway`` instance as its
|
| 456 |
+
pathway, they act to push the two ends of the damper away from one another.
|
| 457 |
+
Because dampers produce a force that opposes the direction of change in
|
| 458 |
+
length, when extension velocity is positive the scalar portions of the
|
| 459 |
+
forces applied at the two endpoints are negative in order to flip the sign
|
| 460 |
+
of the forces on the endpoints wen converted into vector quantities. When
|
| 461 |
+
extension velocity is negative (i.e. when the damper is shortening), the
|
| 462 |
+
scalar portions of the fofces applied are also negative so that the signs
|
| 463 |
+
cancel producing forces on the endpoints that are in the same direction as
|
| 464 |
+
the positive sign convention for the forces at the endpoints of the pathway
|
| 465 |
+
(i.e. they act to push the endpoints away from one another). The following
|
| 466 |
+
diagram shows the positive force sense and the distance between the
|
| 467 |
+
points::
|
| 468 |
+
|
| 469 |
+
P Q
|
| 470 |
+
o<--- F --->o
|
| 471 |
+
| |
|
| 472 |
+
|<--l(t)--->|
|
| 473 |
+
|
| 474 |
+
Examples
|
| 475 |
+
========
|
| 476 |
+
|
| 477 |
+
To construct a linear damper, an expression (or symbol) must be supplied to
|
| 478 |
+
represent the damping coefficient of the damper (we'll use the symbol
|
| 479 |
+
``c``), alongside a pathway specifying its line of action. Let's also
|
| 480 |
+
create a global reference frame and spatially fix one of the points in it
|
| 481 |
+
while setting the other to be positioned such that it can freely move in
|
| 482 |
+
the frame's x direction specified by the coordinate ``q``. The velocity
|
| 483 |
+
that the two points move away from one another can be specified by the
|
| 484 |
+
coordinate ``u`` where ``u`` is the first time derivative of ``q``
|
| 485 |
+
(i.e., ``u = Derivative(q(t), t)``).
|
| 486 |
+
|
| 487 |
+
>>> from sympy import symbols
|
| 488 |
+
>>> from sympy.physics.mechanics import (LinearDamper, LinearPathway,
|
| 489 |
+
... Point, ReferenceFrame)
|
| 490 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 491 |
+
>>> N = ReferenceFrame('N')
|
| 492 |
+
>>> q = dynamicsymbols('q')
|
| 493 |
+
>>> damping = symbols('c')
|
| 494 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 495 |
+
>>> pA.set_vel(N, 0)
|
| 496 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 497 |
+
>>> pB.pos_from(pA)
|
| 498 |
+
q(t)*N.x
|
| 499 |
+
>>> pB.vel(N)
|
| 500 |
+
Derivative(q(t), t)*N.x
|
| 501 |
+
>>> linear_pathway = LinearPathway(pA, pB)
|
| 502 |
+
>>> damper = LinearDamper(damping, linear_pathway)
|
| 503 |
+
>>> damper
|
| 504 |
+
LinearDamper(c, LinearPathway(pA, pB))
|
| 505 |
+
|
| 506 |
+
This damper will produce a force that is proportional to both its damping
|
| 507 |
+
coefficient and the pathway's extension length. Note that this force is
|
| 508 |
+
negative as SymPy's sign convention for actuators is that negative forces
|
| 509 |
+
are contractile and the damping force of the damper will oppose the
|
| 510 |
+
direction of length change.
|
| 511 |
+
|
| 512 |
+
>>> damper.force
|
| 513 |
+
-c*sqrt(q(t)**2)*Derivative(q(t), t)/q(t)
|
| 514 |
+
|
| 515 |
+
Parameters
|
| 516 |
+
==========
|
| 517 |
+
|
| 518 |
+
damping : Expr
|
| 519 |
+
The damping constant.
|
| 520 |
+
pathway : PathwayBase
|
| 521 |
+
The pathway that the actuator follows. This must be an instance of a
|
| 522 |
+
concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 523 |
+
|
| 524 |
+
See Also
|
| 525 |
+
========
|
| 526 |
+
|
| 527 |
+
ForceActuator: force-producing actuator (superclass of ``LinearDamper``).
|
| 528 |
+
LinearPathway: straight-line pathway between a pair of points.
|
| 529 |
+
|
| 530 |
+
"""
|
| 531 |
+
|
| 532 |
+
def __init__(self, damping, pathway):
|
| 533 |
+
"""Initializer for ``LinearDamper``.
|
| 534 |
+
|
| 535 |
+
Parameters
|
| 536 |
+
==========
|
| 537 |
+
|
| 538 |
+
damping : Expr
|
| 539 |
+
The damping constant.
|
| 540 |
+
pathway : PathwayBase
|
| 541 |
+
The pathway that the actuator follows. This must be an instance of
|
| 542 |
+
a concrete subclass of ``PathwayBase``, e.g. ``LinearPathway``.
|
| 543 |
+
|
| 544 |
+
"""
|
| 545 |
+
self.damping = damping
|
| 546 |
+
self.pathway = pathway
|
| 547 |
+
|
| 548 |
+
@property
|
| 549 |
+
def force(self):
|
| 550 |
+
"""The damping force produced by the linear damper."""
|
| 551 |
+
return -self.damping*self.pathway.extension_velocity
|
| 552 |
+
|
| 553 |
+
@force.setter
|
| 554 |
+
def force(self, force):
|
| 555 |
+
raise AttributeError('Can\'t set computed attribute `force`.')
|
| 556 |
+
|
| 557 |
+
@property
|
| 558 |
+
def damping(self):
|
| 559 |
+
"""The damping constant for the linear damper."""
|
| 560 |
+
return self._damping
|
| 561 |
+
|
| 562 |
+
@damping.setter
|
| 563 |
+
def damping(self, damping):
|
| 564 |
+
if hasattr(self, '_damping'):
|
| 565 |
+
msg = (
|
| 566 |
+
f'Can\'t set attribute `damping` to {repr(damping)} as it is '
|
| 567 |
+
f'immutable.'
|
| 568 |
+
)
|
| 569 |
+
raise AttributeError(msg)
|
| 570 |
+
self._damping = sympify(damping, strict=True)
|
| 571 |
+
|
| 572 |
+
def __repr__(self):
|
| 573 |
+
"""Representation of a ``LinearDamper``."""
|
| 574 |
+
return f'{self.__class__.__name__}({self.damping}, {self.pathway})'
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
class TorqueActuator(ActuatorBase):
|
| 578 |
+
"""Torque-producing actuator.
|
| 579 |
+
|
| 580 |
+
Explanation
|
| 581 |
+
===========
|
| 582 |
+
|
| 583 |
+
A ``TorqueActuator`` is an actuator that produces a pair of equal and
|
| 584 |
+
opposite torques on a pair of bodies.
|
| 585 |
+
|
| 586 |
+
Examples
|
| 587 |
+
========
|
| 588 |
+
|
| 589 |
+
To construct a torque actuator, an expression (or symbol) must be supplied
|
| 590 |
+
to represent the torque it can produce, alongside a vector specifying the
|
| 591 |
+
axis about which the torque will act, and a pair of frames on which the
|
| 592 |
+
torque will act.
|
| 593 |
+
|
| 594 |
+
>>> from sympy import symbols
|
| 595 |
+
>>> from sympy.physics.mechanics import (ReferenceFrame, RigidBody,
|
| 596 |
+
... TorqueActuator)
|
| 597 |
+
>>> N = ReferenceFrame('N')
|
| 598 |
+
>>> A = ReferenceFrame('A')
|
| 599 |
+
>>> torque = symbols('T')
|
| 600 |
+
>>> axis = N.z
|
| 601 |
+
>>> parent = RigidBody('parent', frame=N)
|
| 602 |
+
>>> child = RigidBody('child', frame=A)
|
| 603 |
+
>>> bodies = (child, parent)
|
| 604 |
+
>>> actuator = TorqueActuator(torque, axis, *bodies)
|
| 605 |
+
>>> actuator
|
| 606 |
+
TorqueActuator(T, axis=N.z, target_frame=A, reaction_frame=N)
|
| 607 |
+
|
| 608 |
+
Note that because torques actually act on frames, not bodies,
|
| 609 |
+
``TorqueActuator`` will extract the frame associated with a ``RigidBody``
|
| 610 |
+
when one is passed instead of a ``ReferenceFrame``.
|
| 611 |
+
|
| 612 |
+
Parameters
|
| 613 |
+
==========
|
| 614 |
+
|
| 615 |
+
torque : Expr
|
| 616 |
+
The scalar expression defining the torque that the actuator produces.
|
| 617 |
+
axis : Vector
|
| 618 |
+
The axis about which the actuator applies torques.
|
| 619 |
+
target_frame : ReferenceFrame | RigidBody
|
| 620 |
+
The primary frame on which the actuator will apply the torque.
|
| 621 |
+
reaction_frame : ReferenceFrame | RigidBody | None
|
| 622 |
+
The secondary frame on which the actuator will apply the torque. Note
|
| 623 |
+
that the (equal and opposite) reaction torque is applied to this frame.
|
| 624 |
+
|
| 625 |
+
"""
|
| 626 |
+
|
| 627 |
+
def __init__(self, torque, axis, target_frame, reaction_frame=None):
|
| 628 |
+
"""Initializer for ``TorqueActuator``.
|
| 629 |
+
|
| 630 |
+
Parameters
|
| 631 |
+
==========
|
| 632 |
+
|
| 633 |
+
torque : Expr
|
| 634 |
+
The scalar expression defining the torque that the actuator
|
| 635 |
+
produces.
|
| 636 |
+
axis : Vector
|
| 637 |
+
The axis about which the actuator applies torques.
|
| 638 |
+
target_frame : ReferenceFrame | RigidBody
|
| 639 |
+
The primary frame on which the actuator will apply the torque.
|
| 640 |
+
reaction_frame : ReferenceFrame | RigidBody | None
|
| 641 |
+
The secondary frame on which the actuator will apply the torque.
|
| 642 |
+
Note that the (equal and opposite) reaction torque is applied to
|
| 643 |
+
this frame.
|
| 644 |
+
|
| 645 |
+
"""
|
| 646 |
+
self.torque = torque
|
| 647 |
+
self.axis = axis
|
| 648 |
+
self.target_frame = target_frame
|
| 649 |
+
self.reaction_frame = reaction_frame
|
| 650 |
+
|
| 651 |
+
@classmethod
|
| 652 |
+
def at_pin_joint(cls, torque, pin_joint):
|
| 653 |
+
"""Alternate construtor to instantiate from a ``PinJoint`` instance.
|
| 654 |
+
|
| 655 |
+
Examples
|
| 656 |
+
========
|
| 657 |
+
|
| 658 |
+
To create a pin joint the ``PinJoint`` class requires a name, parent
|
| 659 |
+
body, and child body to be passed to its constructor. It is also
|
| 660 |
+
possible to control the joint axis using the ``joint_axis`` keyword
|
| 661 |
+
argument. In this example let's use the parent body's reference frame's
|
| 662 |
+
z-axis as the joint axis.
|
| 663 |
+
|
| 664 |
+
>>> from sympy.physics.mechanics import (PinJoint, ReferenceFrame,
|
| 665 |
+
... RigidBody, TorqueActuator)
|
| 666 |
+
>>> N = ReferenceFrame('N')
|
| 667 |
+
>>> A = ReferenceFrame('A')
|
| 668 |
+
>>> parent = RigidBody('parent', frame=N)
|
| 669 |
+
>>> child = RigidBody('child', frame=A)
|
| 670 |
+
>>> pin_joint = PinJoint(
|
| 671 |
+
... 'pin',
|
| 672 |
+
... parent,
|
| 673 |
+
... child,
|
| 674 |
+
... joint_axis=N.z,
|
| 675 |
+
... )
|
| 676 |
+
|
| 677 |
+
Let's also create a symbol ``T`` that will represent the torque applied
|
| 678 |
+
by the torque actuator.
|
| 679 |
+
|
| 680 |
+
>>> from sympy import symbols
|
| 681 |
+
>>> torque = symbols('T')
|
| 682 |
+
|
| 683 |
+
To create the torque actuator from the ``torque`` and ``pin_joint``
|
| 684 |
+
variables previously instantiated, these can be passed to the alternate
|
| 685 |
+
constructor class method ``at_pin_joint`` of the ``TorqueActuator``
|
| 686 |
+
class. It should be noted that a positive torque will cause a positive
|
| 687 |
+
displacement of the joint coordinate or that the torque is applied on
|
| 688 |
+
the child body with a reaction torque on the parent.
|
| 689 |
+
|
| 690 |
+
>>> actuator = TorqueActuator.at_pin_joint(torque, pin_joint)
|
| 691 |
+
>>> actuator
|
| 692 |
+
TorqueActuator(T, axis=N.z, target_frame=A, reaction_frame=N)
|
| 693 |
+
|
| 694 |
+
Parameters
|
| 695 |
+
==========
|
| 696 |
+
|
| 697 |
+
torque : Expr
|
| 698 |
+
The scalar expression defining the torque that the actuator
|
| 699 |
+
produces.
|
| 700 |
+
pin_joint : PinJoint
|
| 701 |
+
The pin joint, and by association the parent and child bodies, on
|
| 702 |
+
which the torque actuator will act. The pair of bodies acted upon
|
| 703 |
+
by the torque actuator are the parent and child bodies of the pin
|
| 704 |
+
joint, with the child acting as the reaction body. The pin joint's
|
| 705 |
+
axis is used as the axis about which the torque actuator will apply
|
| 706 |
+
its torque.
|
| 707 |
+
|
| 708 |
+
"""
|
| 709 |
+
if not isinstance(pin_joint, PinJoint):
|
| 710 |
+
msg = (
|
| 711 |
+
f'Value {repr(pin_joint)} passed to `pin_joint` was of type '
|
| 712 |
+
f'{type(pin_joint)}, must be {PinJoint}.'
|
| 713 |
+
)
|
| 714 |
+
raise TypeError(msg)
|
| 715 |
+
return cls(
|
| 716 |
+
torque,
|
| 717 |
+
pin_joint.joint_axis,
|
| 718 |
+
pin_joint.child_interframe,
|
| 719 |
+
pin_joint.parent_interframe,
|
| 720 |
+
)
|
| 721 |
+
|
| 722 |
+
@property
|
| 723 |
+
def torque(self):
|
| 724 |
+
"""The magnitude of the torque produced by the actuator."""
|
| 725 |
+
return self._torque
|
| 726 |
+
|
| 727 |
+
@torque.setter
|
| 728 |
+
def torque(self, torque):
|
| 729 |
+
if hasattr(self, '_torque'):
|
| 730 |
+
msg = (
|
| 731 |
+
f'Can\'t set attribute `torque` to {repr(torque)} as it is '
|
| 732 |
+
f'immutable.'
|
| 733 |
+
)
|
| 734 |
+
raise AttributeError(msg)
|
| 735 |
+
self._torque = sympify(torque, strict=True)
|
| 736 |
+
|
| 737 |
+
@property
|
| 738 |
+
def axis(self):
|
| 739 |
+
"""The axis about which the torque acts."""
|
| 740 |
+
return self._axis
|
| 741 |
+
|
| 742 |
+
@axis.setter
|
| 743 |
+
def axis(self, axis):
|
| 744 |
+
if hasattr(self, '_axis'):
|
| 745 |
+
msg = (
|
| 746 |
+
f'Can\'t set attribute `axis` to {repr(axis)} as it is '
|
| 747 |
+
f'immutable.'
|
| 748 |
+
)
|
| 749 |
+
raise AttributeError(msg)
|
| 750 |
+
if not isinstance(axis, Vector):
|
| 751 |
+
msg = (
|
| 752 |
+
f'Value {repr(axis)} passed to `axis` was of type '
|
| 753 |
+
f'{type(axis)}, must be {Vector}.'
|
| 754 |
+
)
|
| 755 |
+
raise TypeError(msg)
|
| 756 |
+
self._axis = axis
|
| 757 |
+
|
| 758 |
+
@property
|
| 759 |
+
def target_frame(self):
|
| 760 |
+
"""The primary reference frames on which the torque will act."""
|
| 761 |
+
return self._target_frame
|
| 762 |
+
|
| 763 |
+
@target_frame.setter
|
| 764 |
+
def target_frame(self, target_frame):
|
| 765 |
+
if hasattr(self, '_target_frame'):
|
| 766 |
+
msg = (
|
| 767 |
+
f'Can\'t set attribute `target_frame` to {repr(target_frame)} '
|
| 768 |
+
f'as it is immutable.'
|
| 769 |
+
)
|
| 770 |
+
raise AttributeError(msg)
|
| 771 |
+
if isinstance(target_frame, RigidBody):
|
| 772 |
+
target_frame = target_frame.frame
|
| 773 |
+
elif not isinstance(target_frame, ReferenceFrame):
|
| 774 |
+
msg = (
|
| 775 |
+
f'Value {repr(target_frame)} passed to `target_frame` was of '
|
| 776 |
+
f'type {type(target_frame)}, must be {ReferenceFrame}.'
|
| 777 |
+
)
|
| 778 |
+
raise TypeError(msg)
|
| 779 |
+
self._target_frame = target_frame
|
| 780 |
+
|
| 781 |
+
@property
|
| 782 |
+
def reaction_frame(self):
|
| 783 |
+
"""The primary reference frames on which the torque will act."""
|
| 784 |
+
return self._reaction_frame
|
| 785 |
+
|
| 786 |
+
@reaction_frame.setter
|
| 787 |
+
def reaction_frame(self, reaction_frame):
|
| 788 |
+
if hasattr(self, '_reaction_frame'):
|
| 789 |
+
msg = (
|
| 790 |
+
f'Can\'t set attribute `reaction_frame` to '
|
| 791 |
+
f'{repr(reaction_frame)} as it is immutable.'
|
| 792 |
+
)
|
| 793 |
+
raise AttributeError(msg)
|
| 794 |
+
if isinstance(reaction_frame, RigidBody):
|
| 795 |
+
reaction_frame = reaction_frame.frame
|
| 796 |
+
elif (
|
| 797 |
+
not isinstance(reaction_frame, ReferenceFrame)
|
| 798 |
+
and reaction_frame is not None
|
| 799 |
+
):
|
| 800 |
+
msg = (
|
| 801 |
+
f'Value {repr(reaction_frame)} passed to `reaction_frame` was '
|
| 802 |
+
f'of type {type(reaction_frame)}, must be {ReferenceFrame}.'
|
| 803 |
+
)
|
| 804 |
+
raise TypeError(msg)
|
| 805 |
+
self._reaction_frame = reaction_frame
|
| 806 |
+
|
| 807 |
+
def to_loads(self):
|
| 808 |
+
"""Loads required by the equations of motion method classes.
|
| 809 |
+
|
| 810 |
+
Explanation
|
| 811 |
+
===========
|
| 812 |
+
|
| 813 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 814 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 815 |
+
when constructing the equations of motion. This method acts as a
|
| 816 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 817 |
+
required so that these can be easily concatenated with other items in
|
| 818 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 819 |
+
loads are also in the correct form to also be passed to the other
|
| 820 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 821 |
+
|
| 822 |
+
Examples
|
| 823 |
+
========
|
| 824 |
+
|
| 825 |
+
The below example shows how to generate the loads produced by a torque
|
| 826 |
+
actuator that acts on a pair of bodies attached by a pin joint.
|
| 827 |
+
|
| 828 |
+
>>> from sympy import symbols
|
| 829 |
+
>>> from sympy.physics.mechanics import (PinJoint, ReferenceFrame,
|
| 830 |
+
... RigidBody, TorqueActuator)
|
| 831 |
+
>>> torque = symbols('T')
|
| 832 |
+
>>> N = ReferenceFrame('N')
|
| 833 |
+
>>> A = ReferenceFrame('A')
|
| 834 |
+
>>> parent = RigidBody('parent', frame=N)
|
| 835 |
+
>>> child = RigidBody('child', frame=A)
|
| 836 |
+
>>> pin_joint = PinJoint(
|
| 837 |
+
... 'pin',
|
| 838 |
+
... parent,
|
| 839 |
+
... child,
|
| 840 |
+
... joint_axis=N.z,
|
| 841 |
+
... )
|
| 842 |
+
>>> actuator = TorqueActuator.at_pin_joint(torque, pin_joint)
|
| 843 |
+
|
| 844 |
+
The forces produces by the damper can be generated by calling the
|
| 845 |
+
``to_loads`` method.
|
| 846 |
+
|
| 847 |
+
>>> actuator.to_loads()
|
| 848 |
+
[(A, T*N.z), (N, - T*N.z)]
|
| 849 |
+
|
| 850 |
+
Alternatively, if a torque actuator is created without a reaction frame
|
| 851 |
+
then the loads returned by the ``to_loads`` method will contain just
|
| 852 |
+
the single load acting on the target frame.
|
| 853 |
+
|
| 854 |
+
>>> actuator = TorqueActuator(torque, N.z, N)
|
| 855 |
+
>>> actuator.to_loads()
|
| 856 |
+
[(N, T*N.z)]
|
| 857 |
+
|
| 858 |
+
"""
|
| 859 |
+
loads = [
|
| 860 |
+
Torque(self.target_frame, self.torque*self.axis),
|
| 861 |
+
]
|
| 862 |
+
if self.reaction_frame is not None:
|
| 863 |
+
loads.append(Torque(self.reaction_frame, -self.torque*self.axis))
|
| 864 |
+
return loads
|
| 865 |
+
|
| 866 |
+
def __repr__(self):
|
| 867 |
+
"""Representation of a ``TorqueActuator``."""
|
| 868 |
+
string = (
|
| 869 |
+
f'{self.__class__.__name__}({self.torque}, axis={self.axis}, '
|
| 870 |
+
f'target_frame={self.target_frame}'
|
| 871 |
+
)
|
| 872 |
+
if self.reaction_frame is not None:
|
| 873 |
+
string += f', reaction_frame={self.reaction_frame})'
|
| 874 |
+
else:
|
| 875 |
+
string += ')'
|
| 876 |
+
return string
|
| 877 |
+
|
| 878 |
+
|
| 879 |
+
class DuffingSpring(ForceActuator):
|
| 880 |
+
"""A nonlinear spring based on the Duffing equation.
|
| 881 |
+
|
| 882 |
+
Explanation
|
| 883 |
+
===========
|
| 884 |
+
|
| 885 |
+
Here, ``DuffingSpring`` represents the force exerted by a nonlinear spring based on the Duffing equation:
|
| 886 |
+
F = -beta*x-alpha*x**3, where x is the displacement from the equilibrium position, beta is the linear spring constant,
|
| 887 |
+
and alpha is the coefficient for the nonlinear cubic term.
|
| 888 |
+
|
| 889 |
+
Parameters
|
| 890 |
+
==========
|
| 891 |
+
|
| 892 |
+
linear_stiffness : Expr
|
| 893 |
+
The linear stiffness coefficient (beta).
|
| 894 |
+
nonlinear_stiffness : Expr
|
| 895 |
+
The nonlinear stiffness coefficient (alpha).
|
| 896 |
+
pathway : PathwayBase
|
| 897 |
+
The pathway that the actuator follows.
|
| 898 |
+
equilibrium_length : Expr, optional
|
| 899 |
+
The length at which the spring is in equilibrium (x).
|
| 900 |
+
"""
|
| 901 |
+
|
| 902 |
+
def __init__(self, linear_stiffness, nonlinear_stiffness, pathway, equilibrium_length=S.Zero):
|
| 903 |
+
self.linear_stiffness = sympify(linear_stiffness, strict=True)
|
| 904 |
+
self.nonlinear_stiffness = sympify(nonlinear_stiffness, strict=True)
|
| 905 |
+
self.equilibrium_length = sympify(equilibrium_length, strict=True)
|
| 906 |
+
|
| 907 |
+
if not isinstance(pathway, PathwayBase):
|
| 908 |
+
raise TypeError("pathway must be an instance of PathwayBase.")
|
| 909 |
+
self._pathway = pathway
|
| 910 |
+
|
| 911 |
+
@property
|
| 912 |
+
def linear_stiffness(self):
|
| 913 |
+
return self._linear_stiffness
|
| 914 |
+
|
| 915 |
+
@linear_stiffness.setter
|
| 916 |
+
def linear_stiffness(self, linear_stiffness):
|
| 917 |
+
if hasattr(self, '_linear_stiffness'):
|
| 918 |
+
msg = (
|
| 919 |
+
f'Can\'t set attribute `linear_stiffness` to '
|
| 920 |
+
f'{repr(linear_stiffness)} as it is immutable.'
|
| 921 |
+
)
|
| 922 |
+
raise AttributeError(msg)
|
| 923 |
+
self._linear_stiffness = sympify(linear_stiffness, strict=True)
|
| 924 |
+
|
| 925 |
+
@property
|
| 926 |
+
def nonlinear_stiffness(self):
|
| 927 |
+
return self._nonlinear_stiffness
|
| 928 |
+
|
| 929 |
+
@nonlinear_stiffness.setter
|
| 930 |
+
def nonlinear_stiffness(self, nonlinear_stiffness):
|
| 931 |
+
if hasattr(self, '_nonlinear_stiffness'):
|
| 932 |
+
msg = (
|
| 933 |
+
f'Can\'t set attribute `nonlinear_stiffness` to '
|
| 934 |
+
f'{repr(nonlinear_stiffness)} as it is immutable.'
|
| 935 |
+
)
|
| 936 |
+
raise AttributeError(msg)
|
| 937 |
+
self._nonlinear_stiffness = sympify(nonlinear_stiffness, strict=True)
|
| 938 |
+
|
| 939 |
+
@property
|
| 940 |
+
def pathway(self):
|
| 941 |
+
return self._pathway
|
| 942 |
+
|
| 943 |
+
@pathway.setter
|
| 944 |
+
def pathway(self, pathway):
|
| 945 |
+
if hasattr(self, '_pathway'):
|
| 946 |
+
msg = (
|
| 947 |
+
f'Can\'t set attribute `pathway` to {repr(pathway)} as it is '
|
| 948 |
+
f'immutable.'
|
| 949 |
+
)
|
| 950 |
+
raise AttributeError(msg)
|
| 951 |
+
if not isinstance(pathway, PathwayBase):
|
| 952 |
+
msg = (
|
| 953 |
+
f'Value {repr(pathway)} passed to `pathway` was of type '
|
| 954 |
+
f'{type(pathway)}, must be {PathwayBase}.'
|
| 955 |
+
)
|
| 956 |
+
raise TypeError(msg)
|
| 957 |
+
self._pathway = pathway
|
| 958 |
+
|
| 959 |
+
@property
|
| 960 |
+
def equilibrium_length(self):
|
| 961 |
+
return self._equilibrium_length
|
| 962 |
+
|
| 963 |
+
@equilibrium_length.setter
|
| 964 |
+
def equilibrium_length(self, equilibrium_length):
|
| 965 |
+
if hasattr(self, '_equilibrium_length'):
|
| 966 |
+
msg = (
|
| 967 |
+
f'Can\'t set attribute `equilibrium_length` to '
|
| 968 |
+
f'{repr(equilibrium_length)} as it is immutable.'
|
| 969 |
+
)
|
| 970 |
+
raise AttributeError(msg)
|
| 971 |
+
self._equilibrium_length = sympify(equilibrium_length, strict=True)
|
| 972 |
+
|
| 973 |
+
@property
|
| 974 |
+
def force(self):
|
| 975 |
+
"""The force produced by the Duffing spring."""
|
| 976 |
+
displacement = self.pathway.length - self.equilibrium_length
|
| 977 |
+
return -self.linear_stiffness * displacement - self.nonlinear_stiffness * displacement**3
|
| 978 |
+
|
| 979 |
+
@force.setter
|
| 980 |
+
def force(self, force):
|
| 981 |
+
if hasattr(self, '_force'):
|
| 982 |
+
msg = (
|
| 983 |
+
f'Can\'t set attribute `force` to {repr(force)} as it is '
|
| 984 |
+
f'immutable.'
|
| 985 |
+
)
|
| 986 |
+
raise AttributeError(msg)
|
| 987 |
+
self._force = sympify(force, strict=True)
|
| 988 |
+
|
| 989 |
+
def __repr__(self):
|
| 990 |
+
return (f"{self.__class__.__name__}("
|
| 991 |
+
f"{self.linear_stiffness}, {self.nonlinear_stiffness}, {self.pathway}, "
|
| 992 |
+
f"equilibrium_length={self.equilibrium_length})")
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/body.py
ADDED
|
@@ -0,0 +1,710 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import Symbol
|
| 2 |
+
from sympy.physics.vector import Point, Vector, ReferenceFrame, Dyadic
|
| 3 |
+
from sympy.physics.mechanics import RigidBody, Particle, Inertia
|
| 4 |
+
from sympy.physics.mechanics.body_base import BodyBase
|
| 5 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 6 |
+
|
| 7 |
+
__all__ = ['Body']
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# XXX: We use type:ignore because the classes RigidBody and Particle have
|
| 11 |
+
# inconsistent parallel axis methods that take different numbers of arguments.
|
| 12 |
+
class Body(RigidBody, Particle): # type: ignore
|
| 13 |
+
"""
|
| 14 |
+
Body is a common representation of either a RigidBody or a Particle SymPy
|
| 15 |
+
object depending on what is passed in during initialization. If a mass is
|
| 16 |
+
passed in and central_inertia is left as None, the Particle object is
|
| 17 |
+
created. Otherwise a RigidBody object will be created.
|
| 18 |
+
|
| 19 |
+
.. deprecated:: 1.13
|
| 20 |
+
The Body class is deprecated. Its functionality is captured by
|
| 21 |
+
:class:`~.RigidBody` and :class:`~.Particle`.
|
| 22 |
+
|
| 23 |
+
Explanation
|
| 24 |
+
===========
|
| 25 |
+
|
| 26 |
+
The attributes that Body possesses will be the same as a Particle instance
|
| 27 |
+
or a Rigid Body instance depending on which was created. Additional
|
| 28 |
+
attributes are listed below.
|
| 29 |
+
|
| 30 |
+
Attributes
|
| 31 |
+
==========
|
| 32 |
+
|
| 33 |
+
name : string
|
| 34 |
+
The body's name
|
| 35 |
+
masscenter : Point
|
| 36 |
+
The point which represents the center of mass of the rigid body
|
| 37 |
+
frame : ReferenceFrame
|
| 38 |
+
The reference frame which the body is fixed in
|
| 39 |
+
mass : Sympifyable
|
| 40 |
+
The body's mass
|
| 41 |
+
inertia : (Dyadic, Point)
|
| 42 |
+
The body's inertia around its center of mass. This attribute is specific
|
| 43 |
+
to the rigid body form of Body and is left undefined for the Particle
|
| 44 |
+
form
|
| 45 |
+
loads : iterable
|
| 46 |
+
This list contains information on the different loads acting on the
|
| 47 |
+
Body. Forces are listed as a (point, vector) tuple and torques are
|
| 48 |
+
listed as (reference frame, vector) tuples.
|
| 49 |
+
|
| 50 |
+
Parameters
|
| 51 |
+
==========
|
| 52 |
+
|
| 53 |
+
name : String
|
| 54 |
+
Defines the name of the body. It is used as the base for defining
|
| 55 |
+
body specific properties.
|
| 56 |
+
masscenter : Point, optional
|
| 57 |
+
A point that represents the center of mass of the body or particle.
|
| 58 |
+
If no point is given, a point is generated.
|
| 59 |
+
mass : Sympifyable, optional
|
| 60 |
+
A Sympifyable object which represents the mass of the body. If no
|
| 61 |
+
mass is passed, one is generated.
|
| 62 |
+
frame : ReferenceFrame, optional
|
| 63 |
+
The ReferenceFrame that represents the reference frame of the body.
|
| 64 |
+
If no frame is given, a frame is generated.
|
| 65 |
+
central_inertia : Dyadic, optional
|
| 66 |
+
Central inertia dyadic of the body. If none is passed while creating
|
| 67 |
+
RigidBody, a default inertia is generated.
|
| 68 |
+
|
| 69 |
+
Examples
|
| 70 |
+
========
|
| 71 |
+
|
| 72 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 73 |
+
purposes only. The functionality of Body is fully captured by
|
| 74 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 75 |
+
warning we can use the ignore_warnings context manager.
|
| 76 |
+
|
| 77 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 78 |
+
|
| 79 |
+
Default behaviour. This results in the creation of a RigidBody object for
|
| 80 |
+
which the mass, mass center, frame and inertia attributes are given default
|
| 81 |
+
values. ::
|
| 82 |
+
|
| 83 |
+
>>> from sympy.physics.mechanics import Body
|
| 84 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 85 |
+
... body = Body('name_of_body')
|
| 86 |
+
|
| 87 |
+
This next example demonstrates the code required to specify all of the
|
| 88 |
+
values of the Body object. Note this will also create a RigidBody version of
|
| 89 |
+
the Body object. ::
|
| 90 |
+
|
| 91 |
+
>>> from sympy import Symbol
|
| 92 |
+
>>> from sympy.physics.mechanics import ReferenceFrame, Point, inertia
|
| 93 |
+
>>> from sympy.physics.mechanics import Body
|
| 94 |
+
>>> mass = Symbol('mass')
|
| 95 |
+
>>> masscenter = Point('masscenter')
|
| 96 |
+
>>> frame = ReferenceFrame('frame')
|
| 97 |
+
>>> ixx = Symbol('ixx')
|
| 98 |
+
>>> body_inertia = inertia(frame, ixx, 0, 0)
|
| 99 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 100 |
+
... body = Body('name_of_body', masscenter, mass, frame, body_inertia)
|
| 101 |
+
|
| 102 |
+
The minimal code required to create a Particle version of the Body object
|
| 103 |
+
involves simply passing in a name and a mass. ::
|
| 104 |
+
|
| 105 |
+
>>> from sympy import Symbol
|
| 106 |
+
>>> from sympy.physics.mechanics import Body
|
| 107 |
+
>>> mass = Symbol('mass')
|
| 108 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 109 |
+
... body = Body('name_of_body', mass=mass)
|
| 110 |
+
|
| 111 |
+
The Particle version of the Body object can also receive a masscenter point
|
| 112 |
+
and a reference frame, just not an inertia.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
def __init__(self, name, masscenter=None, mass=None, frame=None,
|
| 116 |
+
central_inertia=None):
|
| 117 |
+
sympy_deprecation_warning(
|
| 118 |
+
"""
|
| 119 |
+
Support for the Body class has been removed, as its functionality is
|
| 120 |
+
fully captured by RigidBody and Particle.
|
| 121 |
+
""",
|
| 122 |
+
deprecated_since_version="1.13",
|
| 123 |
+
active_deprecations_target="deprecated-mechanics-body-class"
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
self._loads = []
|
| 127 |
+
|
| 128 |
+
if frame is None:
|
| 129 |
+
frame = ReferenceFrame(name + '_frame')
|
| 130 |
+
|
| 131 |
+
if masscenter is None:
|
| 132 |
+
masscenter = Point(name + '_masscenter')
|
| 133 |
+
|
| 134 |
+
if central_inertia is None and mass is None:
|
| 135 |
+
ixx = Symbol(name + '_ixx')
|
| 136 |
+
iyy = Symbol(name + '_iyy')
|
| 137 |
+
izz = Symbol(name + '_izz')
|
| 138 |
+
izx = Symbol(name + '_izx')
|
| 139 |
+
ixy = Symbol(name + '_ixy')
|
| 140 |
+
iyz = Symbol(name + '_iyz')
|
| 141 |
+
_inertia = Inertia.from_inertia_scalars(masscenter, frame, ixx, iyy,
|
| 142 |
+
izz, ixy, iyz, izx)
|
| 143 |
+
else:
|
| 144 |
+
_inertia = (central_inertia, masscenter)
|
| 145 |
+
|
| 146 |
+
if mass is None:
|
| 147 |
+
_mass = Symbol(name + '_mass')
|
| 148 |
+
else:
|
| 149 |
+
_mass = mass
|
| 150 |
+
|
| 151 |
+
masscenter.set_vel(frame, 0)
|
| 152 |
+
|
| 153 |
+
# If user passes masscenter and mass then a particle is created
|
| 154 |
+
# otherwise a rigidbody. As a result a body may or may not have inertia.
|
| 155 |
+
# Note: BodyBase.__init__ is used to prevent problems with super() calls in
|
| 156 |
+
# Particle and RigidBody arising due to multiple inheritance.
|
| 157 |
+
if central_inertia is None and mass is not None:
|
| 158 |
+
BodyBase.__init__(self, name, masscenter, _mass)
|
| 159 |
+
self.frame = frame
|
| 160 |
+
self._central_inertia = Dyadic(0)
|
| 161 |
+
else:
|
| 162 |
+
BodyBase.__init__(self, name, masscenter, _mass)
|
| 163 |
+
self.frame = frame
|
| 164 |
+
self.inertia = _inertia
|
| 165 |
+
|
| 166 |
+
def __repr__(self):
|
| 167 |
+
if self.is_rigidbody:
|
| 168 |
+
return RigidBody.__repr__(self)
|
| 169 |
+
return Particle.__repr__(self)
|
| 170 |
+
|
| 171 |
+
@property
|
| 172 |
+
def loads(self):
|
| 173 |
+
return self._loads
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def x(self):
|
| 177 |
+
"""The basis Vector for the Body, in the x direction."""
|
| 178 |
+
return self.frame.x
|
| 179 |
+
|
| 180 |
+
@property
|
| 181 |
+
def y(self):
|
| 182 |
+
"""The basis Vector for the Body, in the y direction."""
|
| 183 |
+
return self.frame.y
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def z(self):
|
| 187 |
+
"""The basis Vector for the Body, in the z direction."""
|
| 188 |
+
return self.frame.z
|
| 189 |
+
|
| 190 |
+
@property
|
| 191 |
+
def inertia(self):
|
| 192 |
+
"""The body's inertia about a point; stored as (Dyadic, Point)."""
|
| 193 |
+
if self.is_rigidbody:
|
| 194 |
+
return RigidBody.inertia.fget(self)
|
| 195 |
+
return (self.central_inertia, self.masscenter)
|
| 196 |
+
|
| 197 |
+
@inertia.setter
|
| 198 |
+
def inertia(self, I):
|
| 199 |
+
RigidBody.inertia.fset(self, I)
|
| 200 |
+
|
| 201 |
+
@property
|
| 202 |
+
def is_rigidbody(self):
|
| 203 |
+
if hasattr(self, '_inertia'):
|
| 204 |
+
return True
|
| 205 |
+
return False
|
| 206 |
+
|
| 207 |
+
def kinetic_energy(self, frame):
|
| 208 |
+
"""Kinetic energy of the body.
|
| 209 |
+
|
| 210 |
+
Parameters
|
| 211 |
+
==========
|
| 212 |
+
|
| 213 |
+
frame : ReferenceFrame or Body
|
| 214 |
+
The Body's angular velocity and the velocity of it's mass
|
| 215 |
+
center are typically defined with respect to an inertial frame but
|
| 216 |
+
any relevant frame in which the velocities are known can be supplied.
|
| 217 |
+
|
| 218 |
+
Examples
|
| 219 |
+
========
|
| 220 |
+
|
| 221 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 222 |
+
purposes only. The functionality of Body is fully captured by
|
| 223 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 224 |
+
warning we can use the ignore_warnings context manager.
|
| 225 |
+
|
| 226 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 227 |
+
>>> from sympy.physics.mechanics import Body, ReferenceFrame, Point
|
| 228 |
+
>>> from sympy import symbols
|
| 229 |
+
>>> m, v, r, omega = symbols('m v r omega')
|
| 230 |
+
>>> N = ReferenceFrame('N')
|
| 231 |
+
>>> O = Point('O')
|
| 232 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 233 |
+
... P = Body('P', masscenter=O, mass=m)
|
| 234 |
+
>>> P.masscenter.set_vel(N, v * N.y)
|
| 235 |
+
>>> P.kinetic_energy(N)
|
| 236 |
+
m*v**2/2
|
| 237 |
+
|
| 238 |
+
>>> N = ReferenceFrame('N')
|
| 239 |
+
>>> b = ReferenceFrame('b')
|
| 240 |
+
>>> b.set_ang_vel(N, omega * b.x)
|
| 241 |
+
>>> P = Point('P')
|
| 242 |
+
>>> P.set_vel(N, v * N.x)
|
| 243 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 244 |
+
... B = Body('B', masscenter=P, frame=b)
|
| 245 |
+
>>> B.kinetic_energy(N)
|
| 246 |
+
B_ixx*omega**2/2 + B_mass*v**2/2
|
| 247 |
+
|
| 248 |
+
See Also
|
| 249 |
+
========
|
| 250 |
+
|
| 251 |
+
sympy.physics.mechanics : Particle, RigidBody
|
| 252 |
+
|
| 253 |
+
"""
|
| 254 |
+
if isinstance(frame, Body):
|
| 255 |
+
frame = Body.frame
|
| 256 |
+
if self.is_rigidbody:
|
| 257 |
+
return RigidBody(self.name, self.masscenter, self.frame, self.mass,
|
| 258 |
+
(self.central_inertia, self.masscenter)).kinetic_energy(frame)
|
| 259 |
+
return Particle(self.name, self.masscenter, self.mass).kinetic_energy(frame)
|
| 260 |
+
|
| 261 |
+
def apply_force(self, force, point=None, reaction_body=None, reaction_point=None):
|
| 262 |
+
"""Add force to the body(s).
|
| 263 |
+
|
| 264 |
+
Explanation
|
| 265 |
+
===========
|
| 266 |
+
|
| 267 |
+
Applies the force on self or equal and opposite forces on
|
| 268 |
+
self and other body if both are given on the desired point on the bodies.
|
| 269 |
+
The force applied on other body is taken opposite of self, i.e, -force.
|
| 270 |
+
|
| 271 |
+
Parameters
|
| 272 |
+
==========
|
| 273 |
+
|
| 274 |
+
force: Vector
|
| 275 |
+
The force to be applied.
|
| 276 |
+
point: Point, optional
|
| 277 |
+
The point on self on which force is applied.
|
| 278 |
+
By default self's masscenter.
|
| 279 |
+
reaction_body: Body, optional
|
| 280 |
+
Second body on which equal and opposite force
|
| 281 |
+
is to be applied.
|
| 282 |
+
reaction_point : Point, optional
|
| 283 |
+
The point on other body on which equal and opposite
|
| 284 |
+
force is applied. By default masscenter of other body.
|
| 285 |
+
|
| 286 |
+
Example
|
| 287 |
+
=======
|
| 288 |
+
|
| 289 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 290 |
+
purposes only. The functionality of Body is fully captured by
|
| 291 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 292 |
+
warning we can use the ignore_warnings context manager.
|
| 293 |
+
|
| 294 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 295 |
+
>>> from sympy import symbols
|
| 296 |
+
>>> from sympy.physics.mechanics import Body, Point, dynamicsymbols
|
| 297 |
+
>>> m, g = symbols('m g')
|
| 298 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 299 |
+
... B = Body('B')
|
| 300 |
+
>>> force1 = m*g*B.z
|
| 301 |
+
>>> B.apply_force(force1) #Applying force on B's masscenter
|
| 302 |
+
>>> B.loads
|
| 303 |
+
[(B_masscenter, g*m*B_frame.z)]
|
| 304 |
+
|
| 305 |
+
We can also remove some part of force from any point on the body by
|
| 306 |
+
adding the opposite force to the body on that point.
|
| 307 |
+
|
| 308 |
+
>>> f1, f2 = dynamicsymbols('f1 f2')
|
| 309 |
+
>>> P = Point('P') #Considering point P on body B
|
| 310 |
+
>>> B.apply_force(f1*B.x + f2*B.y, P)
|
| 311 |
+
>>> B.loads
|
| 312 |
+
[(B_masscenter, g*m*B_frame.z), (P, f1(t)*B_frame.x + f2(t)*B_frame.y)]
|
| 313 |
+
|
| 314 |
+
Let's remove f1 from point P on body B.
|
| 315 |
+
|
| 316 |
+
>>> B.apply_force(-f1*B.x, P)
|
| 317 |
+
>>> B.loads
|
| 318 |
+
[(B_masscenter, g*m*B_frame.z), (P, f2(t)*B_frame.y)]
|
| 319 |
+
|
| 320 |
+
To further demonstrate the use of ``apply_force`` attribute,
|
| 321 |
+
consider two bodies connected through a spring.
|
| 322 |
+
|
| 323 |
+
>>> from sympy.physics.mechanics import Body, dynamicsymbols
|
| 324 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 325 |
+
... N = Body('N') #Newtonion Frame
|
| 326 |
+
>>> x = dynamicsymbols('x')
|
| 327 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 328 |
+
... B1 = Body('B1')
|
| 329 |
+
... B2 = Body('B2')
|
| 330 |
+
>>> spring_force = x*N.x
|
| 331 |
+
|
| 332 |
+
Now let's apply equal and opposite spring force to the bodies.
|
| 333 |
+
|
| 334 |
+
>>> P1 = Point('P1')
|
| 335 |
+
>>> P2 = Point('P2')
|
| 336 |
+
>>> B1.apply_force(spring_force, point=P1, reaction_body=B2, reaction_point=P2)
|
| 337 |
+
|
| 338 |
+
We can check the loads(forces) applied to bodies now.
|
| 339 |
+
|
| 340 |
+
>>> B1.loads
|
| 341 |
+
[(P1, x(t)*N_frame.x)]
|
| 342 |
+
>>> B2.loads
|
| 343 |
+
[(P2, - x(t)*N_frame.x)]
|
| 344 |
+
|
| 345 |
+
Notes
|
| 346 |
+
=====
|
| 347 |
+
|
| 348 |
+
If a new force is applied to a body on a point which already has some
|
| 349 |
+
force applied on it, then the new force is added to the already applied
|
| 350 |
+
force on that point.
|
| 351 |
+
|
| 352 |
+
"""
|
| 353 |
+
|
| 354 |
+
if not isinstance(point, Point):
|
| 355 |
+
if point is None:
|
| 356 |
+
point = self.masscenter # masscenter
|
| 357 |
+
else:
|
| 358 |
+
raise TypeError("Force must be applied to a point on the body.")
|
| 359 |
+
if not isinstance(force, Vector):
|
| 360 |
+
raise TypeError("Force must be a vector.")
|
| 361 |
+
|
| 362 |
+
if reaction_body is not None:
|
| 363 |
+
reaction_body.apply_force(-force, point=reaction_point)
|
| 364 |
+
|
| 365 |
+
for load in self._loads:
|
| 366 |
+
if point in load:
|
| 367 |
+
force += load[1]
|
| 368 |
+
self._loads.remove(load)
|
| 369 |
+
break
|
| 370 |
+
|
| 371 |
+
self._loads.append((point, force))
|
| 372 |
+
|
| 373 |
+
def apply_torque(self, torque, reaction_body=None):
|
| 374 |
+
"""Add torque to the body(s).
|
| 375 |
+
|
| 376 |
+
Explanation
|
| 377 |
+
===========
|
| 378 |
+
|
| 379 |
+
Applies the torque on self or equal and opposite torques on
|
| 380 |
+
self and other body if both are given.
|
| 381 |
+
The torque applied on other body is taken opposite of self,
|
| 382 |
+
i.e, -torque.
|
| 383 |
+
|
| 384 |
+
Parameters
|
| 385 |
+
==========
|
| 386 |
+
|
| 387 |
+
torque: Vector
|
| 388 |
+
The torque to be applied.
|
| 389 |
+
reaction_body: Body, optional
|
| 390 |
+
Second body on which equal and opposite torque
|
| 391 |
+
is to be applied.
|
| 392 |
+
|
| 393 |
+
Example
|
| 394 |
+
=======
|
| 395 |
+
|
| 396 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 397 |
+
purposes only. The functionality of Body is fully captured by
|
| 398 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 399 |
+
warning we can use the ignore_warnings context manager.
|
| 400 |
+
|
| 401 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 402 |
+
>>> from sympy import symbols
|
| 403 |
+
>>> from sympy.physics.mechanics import Body, dynamicsymbols
|
| 404 |
+
>>> t = symbols('t')
|
| 405 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 406 |
+
... B = Body('B')
|
| 407 |
+
>>> torque1 = t*B.z
|
| 408 |
+
>>> B.apply_torque(torque1)
|
| 409 |
+
>>> B.loads
|
| 410 |
+
[(B_frame, t*B_frame.z)]
|
| 411 |
+
|
| 412 |
+
We can also remove some part of torque from the body by
|
| 413 |
+
adding the opposite torque to the body.
|
| 414 |
+
|
| 415 |
+
>>> t1, t2 = dynamicsymbols('t1 t2')
|
| 416 |
+
>>> B.apply_torque(t1*B.x + t2*B.y)
|
| 417 |
+
>>> B.loads
|
| 418 |
+
[(B_frame, t1(t)*B_frame.x + t2(t)*B_frame.y + t*B_frame.z)]
|
| 419 |
+
|
| 420 |
+
Let's remove t1 from Body B.
|
| 421 |
+
|
| 422 |
+
>>> B.apply_torque(-t1*B.x)
|
| 423 |
+
>>> B.loads
|
| 424 |
+
[(B_frame, t2(t)*B_frame.y + t*B_frame.z)]
|
| 425 |
+
|
| 426 |
+
To further demonstrate the use, let us consider two bodies such that
|
| 427 |
+
a torque `T` is acting on one body, and `-T` on the other.
|
| 428 |
+
|
| 429 |
+
>>> from sympy.physics.mechanics import Body, dynamicsymbols
|
| 430 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 431 |
+
... N = Body('N') #Newtonion frame
|
| 432 |
+
... B1 = Body('B1')
|
| 433 |
+
... B2 = Body('B2')
|
| 434 |
+
>>> v = dynamicsymbols('v')
|
| 435 |
+
>>> T = v*N.y #Torque
|
| 436 |
+
|
| 437 |
+
Now let's apply equal and opposite torque to the bodies.
|
| 438 |
+
|
| 439 |
+
>>> B1.apply_torque(T, B2)
|
| 440 |
+
|
| 441 |
+
We can check the loads (torques) applied to bodies now.
|
| 442 |
+
|
| 443 |
+
>>> B1.loads
|
| 444 |
+
[(B1_frame, v(t)*N_frame.y)]
|
| 445 |
+
>>> B2.loads
|
| 446 |
+
[(B2_frame, - v(t)*N_frame.y)]
|
| 447 |
+
|
| 448 |
+
Notes
|
| 449 |
+
=====
|
| 450 |
+
|
| 451 |
+
If a new torque is applied on body which already has some torque applied on it,
|
| 452 |
+
then the new torque is added to the previous torque about the body's frame.
|
| 453 |
+
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
if not isinstance(torque, Vector):
|
| 457 |
+
raise TypeError("A Vector must be supplied to add torque.")
|
| 458 |
+
|
| 459 |
+
if reaction_body is not None:
|
| 460 |
+
reaction_body.apply_torque(-torque)
|
| 461 |
+
|
| 462 |
+
for load in self._loads:
|
| 463 |
+
if self.frame in load:
|
| 464 |
+
torque += load[1]
|
| 465 |
+
self._loads.remove(load)
|
| 466 |
+
break
|
| 467 |
+
self._loads.append((self.frame, torque))
|
| 468 |
+
|
| 469 |
+
def clear_loads(self):
|
| 470 |
+
"""
|
| 471 |
+
Clears the Body's loads list.
|
| 472 |
+
|
| 473 |
+
Example
|
| 474 |
+
=======
|
| 475 |
+
|
| 476 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 477 |
+
purposes only. The functionality of Body is fully captured by
|
| 478 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 479 |
+
warning we can use the ignore_warnings context manager.
|
| 480 |
+
|
| 481 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 482 |
+
>>> from sympy.physics.mechanics import Body
|
| 483 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 484 |
+
... B = Body('B')
|
| 485 |
+
>>> force = B.x + B.y
|
| 486 |
+
>>> B.apply_force(force)
|
| 487 |
+
>>> B.loads
|
| 488 |
+
[(B_masscenter, B_frame.x + B_frame.y)]
|
| 489 |
+
>>> B.clear_loads()
|
| 490 |
+
>>> B.loads
|
| 491 |
+
[]
|
| 492 |
+
|
| 493 |
+
"""
|
| 494 |
+
|
| 495 |
+
self._loads = []
|
| 496 |
+
|
| 497 |
+
def remove_load(self, about=None):
|
| 498 |
+
"""
|
| 499 |
+
Remove load about a point or frame.
|
| 500 |
+
|
| 501 |
+
Parameters
|
| 502 |
+
==========
|
| 503 |
+
|
| 504 |
+
about : Point or ReferenceFrame, optional
|
| 505 |
+
The point about which force is applied,
|
| 506 |
+
and is to be removed.
|
| 507 |
+
If about is None, then the torque about
|
| 508 |
+
self's frame is removed.
|
| 509 |
+
|
| 510 |
+
Example
|
| 511 |
+
=======
|
| 512 |
+
|
| 513 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 514 |
+
purposes only. The functionality of Body is fully captured by
|
| 515 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 516 |
+
warning we can use the ignore_warnings context manager.
|
| 517 |
+
|
| 518 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 519 |
+
>>> from sympy.physics.mechanics import Body, Point
|
| 520 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 521 |
+
... B = Body('B')
|
| 522 |
+
>>> P = Point('P')
|
| 523 |
+
>>> f1 = B.x
|
| 524 |
+
>>> f2 = B.y
|
| 525 |
+
>>> B.apply_force(f1)
|
| 526 |
+
>>> B.apply_force(f2, P)
|
| 527 |
+
>>> B.loads
|
| 528 |
+
[(B_masscenter, B_frame.x), (P, B_frame.y)]
|
| 529 |
+
|
| 530 |
+
>>> B.remove_load(P)
|
| 531 |
+
>>> B.loads
|
| 532 |
+
[(B_masscenter, B_frame.x)]
|
| 533 |
+
|
| 534 |
+
"""
|
| 535 |
+
|
| 536 |
+
if about is not None:
|
| 537 |
+
if not isinstance(about, Point):
|
| 538 |
+
raise TypeError('Load is applied about Point or ReferenceFrame.')
|
| 539 |
+
else:
|
| 540 |
+
about = self.frame
|
| 541 |
+
|
| 542 |
+
for load in self._loads:
|
| 543 |
+
if about in load:
|
| 544 |
+
self._loads.remove(load)
|
| 545 |
+
break
|
| 546 |
+
|
| 547 |
+
def masscenter_vel(self, body):
|
| 548 |
+
"""
|
| 549 |
+
Returns the velocity of the mass center with respect to the provided
|
| 550 |
+
rigid body or reference frame.
|
| 551 |
+
|
| 552 |
+
Parameters
|
| 553 |
+
==========
|
| 554 |
+
|
| 555 |
+
body: Body or ReferenceFrame
|
| 556 |
+
The rigid body or reference frame to calculate the velocity in.
|
| 557 |
+
|
| 558 |
+
Example
|
| 559 |
+
=======
|
| 560 |
+
|
| 561 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 562 |
+
purposes only. The functionality of Body is fully captured by
|
| 563 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 564 |
+
warning we can use the ignore_warnings context manager.
|
| 565 |
+
|
| 566 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 567 |
+
>>> from sympy.physics.mechanics import Body
|
| 568 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 569 |
+
... A = Body('A')
|
| 570 |
+
... B = Body('B')
|
| 571 |
+
>>> A.masscenter.set_vel(B.frame, 5*B.frame.x)
|
| 572 |
+
>>> A.masscenter_vel(B)
|
| 573 |
+
5*B_frame.x
|
| 574 |
+
>>> A.masscenter_vel(B.frame)
|
| 575 |
+
5*B_frame.x
|
| 576 |
+
|
| 577 |
+
"""
|
| 578 |
+
|
| 579 |
+
if isinstance(body, ReferenceFrame):
|
| 580 |
+
frame=body
|
| 581 |
+
elif isinstance(body, Body):
|
| 582 |
+
frame = body.frame
|
| 583 |
+
return self.masscenter.vel(frame)
|
| 584 |
+
|
| 585 |
+
def ang_vel_in(self, body):
|
| 586 |
+
"""
|
| 587 |
+
Returns this body's angular velocity with respect to the provided
|
| 588 |
+
rigid body or reference frame.
|
| 589 |
+
|
| 590 |
+
Parameters
|
| 591 |
+
==========
|
| 592 |
+
|
| 593 |
+
body: Body or ReferenceFrame
|
| 594 |
+
The rigid body or reference frame to calculate the angular velocity in.
|
| 595 |
+
|
| 596 |
+
Example
|
| 597 |
+
=======
|
| 598 |
+
|
| 599 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 600 |
+
purposes only. The functionality of Body is fully captured by
|
| 601 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 602 |
+
warning we can use the ignore_warnings context manager.
|
| 603 |
+
|
| 604 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 605 |
+
>>> from sympy.physics.mechanics import Body, ReferenceFrame
|
| 606 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 607 |
+
... A = Body('A')
|
| 608 |
+
>>> N = ReferenceFrame('N')
|
| 609 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 610 |
+
... B = Body('B', frame=N)
|
| 611 |
+
>>> A.frame.set_ang_vel(N, 5*N.x)
|
| 612 |
+
>>> A.ang_vel_in(B)
|
| 613 |
+
5*N.x
|
| 614 |
+
>>> A.ang_vel_in(N)
|
| 615 |
+
5*N.x
|
| 616 |
+
|
| 617 |
+
"""
|
| 618 |
+
|
| 619 |
+
if isinstance(body, ReferenceFrame):
|
| 620 |
+
frame=body
|
| 621 |
+
elif isinstance(body, Body):
|
| 622 |
+
frame = body.frame
|
| 623 |
+
return self.frame.ang_vel_in(frame)
|
| 624 |
+
|
| 625 |
+
def dcm(self, body):
|
| 626 |
+
"""
|
| 627 |
+
Returns the direction cosine matrix of this body relative to the
|
| 628 |
+
provided rigid body or reference frame.
|
| 629 |
+
|
| 630 |
+
Parameters
|
| 631 |
+
==========
|
| 632 |
+
|
| 633 |
+
body: Body or ReferenceFrame
|
| 634 |
+
The rigid body or reference frame to calculate the dcm.
|
| 635 |
+
|
| 636 |
+
Example
|
| 637 |
+
=======
|
| 638 |
+
|
| 639 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 640 |
+
purposes only. The functionality of Body is fully captured by
|
| 641 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 642 |
+
warning we can use the ignore_warnings context manager.
|
| 643 |
+
|
| 644 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 645 |
+
>>> from sympy.physics.mechanics import Body
|
| 646 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 647 |
+
... A = Body('A')
|
| 648 |
+
... B = Body('B')
|
| 649 |
+
>>> A.frame.orient_axis(B.frame, B.frame.x, 5)
|
| 650 |
+
>>> A.dcm(B)
|
| 651 |
+
Matrix([
|
| 652 |
+
[1, 0, 0],
|
| 653 |
+
[0, cos(5), sin(5)],
|
| 654 |
+
[0, -sin(5), cos(5)]])
|
| 655 |
+
>>> A.dcm(B.frame)
|
| 656 |
+
Matrix([
|
| 657 |
+
[1, 0, 0],
|
| 658 |
+
[0, cos(5), sin(5)],
|
| 659 |
+
[0, -sin(5), cos(5)]])
|
| 660 |
+
|
| 661 |
+
"""
|
| 662 |
+
|
| 663 |
+
if isinstance(body, ReferenceFrame):
|
| 664 |
+
frame=body
|
| 665 |
+
elif isinstance(body, Body):
|
| 666 |
+
frame = body.frame
|
| 667 |
+
return self.frame.dcm(frame)
|
| 668 |
+
|
| 669 |
+
def parallel_axis(self, point, frame=None):
|
| 670 |
+
"""Returns the inertia dyadic of the body with respect to another
|
| 671 |
+
point.
|
| 672 |
+
|
| 673 |
+
Parameters
|
| 674 |
+
==========
|
| 675 |
+
|
| 676 |
+
point : sympy.physics.vector.Point
|
| 677 |
+
The point to express the inertia dyadic about.
|
| 678 |
+
frame : sympy.physics.vector.ReferenceFrame
|
| 679 |
+
The reference frame used to construct the dyadic.
|
| 680 |
+
|
| 681 |
+
Returns
|
| 682 |
+
=======
|
| 683 |
+
|
| 684 |
+
inertia : sympy.physics.vector.Dyadic
|
| 685 |
+
The inertia dyadic of the rigid body expressed about the provided
|
| 686 |
+
point.
|
| 687 |
+
|
| 688 |
+
Example
|
| 689 |
+
=======
|
| 690 |
+
|
| 691 |
+
As Body has been deprecated, the following examples are for illustrative
|
| 692 |
+
purposes only. The functionality of Body is fully captured by
|
| 693 |
+
:class:`~.RigidBody` and :class:`~.Particle`. To ignore the deprecation
|
| 694 |
+
warning we can use the ignore_warnings context manager.
|
| 695 |
+
|
| 696 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 697 |
+
>>> from sympy.physics.mechanics import Body
|
| 698 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 699 |
+
... A = Body('A')
|
| 700 |
+
>>> P = A.masscenter.locatenew('point', 3 * A.x + 5 * A.y)
|
| 701 |
+
>>> A.parallel_axis(P).to_matrix(A.frame)
|
| 702 |
+
Matrix([
|
| 703 |
+
[A_ixx + 25*A_mass, A_ixy - 15*A_mass, A_izx],
|
| 704 |
+
[A_ixy - 15*A_mass, A_iyy + 9*A_mass, A_iyz],
|
| 705 |
+
[ A_izx, A_iyz, A_izz + 34*A_mass]])
|
| 706 |
+
|
| 707 |
+
"""
|
| 708 |
+
if self.is_rigidbody:
|
| 709 |
+
return RigidBody.parallel_axis(self, point, frame)
|
| 710 |
+
return Particle.parallel_axis(self, point, frame)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/body_base.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod
|
| 2 |
+
from sympy import Symbol, sympify
|
| 3 |
+
from sympy.physics.vector import Point
|
| 4 |
+
|
| 5 |
+
__all__ = ['BodyBase']
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class BodyBase(ABC):
|
| 9 |
+
"""Abstract class for body type objects."""
|
| 10 |
+
def __init__(self, name, masscenter=None, mass=None):
|
| 11 |
+
# Note: If frame=None, no auto-generated frame is created, because a
|
| 12 |
+
# Particle does not need to have a frame by default.
|
| 13 |
+
if not isinstance(name, str):
|
| 14 |
+
raise TypeError('Supply a valid name.')
|
| 15 |
+
self._name = name
|
| 16 |
+
if mass is None:
|
| 17 |
+
mass = Symbol(f'{name}_mass')
|
| 18 |
+
if masscenter is None:
|
| 19 |
+
masscenter = Point(f'{name}_masscenter')
|
| 20 |
+
self.mass = mass
|
| 21 |
+
self.masscenter = masscenter
|
| 22 |
+
self.potential_energy = 0
|
| 23 |
+
self.points = []
|
| 24 |
+
|
| 25 |
+
def __str__(self):
|
| 26 |
+
return self.name
|
| 27 |
+
|
| 28 |
+
def __repr__(self):
|
| 29 |
+
return (f'{self.__class__.__name__}({repr(self.name)}, masscenter='
|
| 30 |
+
f'{repr(self.masscenter)}, mass={repr(self.mass)})')
|
| 31 |
+
|
| 32 |
+
@property
|
| 33 |
+
def name(self):
|
| 34 |
+
"""The name of the body."""
|
| 35 |
+
return self._name
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def masscenter(self):
|
| 39 |
+
"""The body's center of mass."""
|
| 40 |
+
return self._masscenter
|
| 41 |
+
|
| 42 |
+
@masscenter.setter
|
| 43 |
+
def masscenter(self, point):
|
| 44 |
+
if not isinstance(point, Point):
|
| 45 |
+
raise TypeError("The body's center of mass must be a Point object.")
|
| 46 |
+
self._masscenter = point
|
| 47 |
+
|
| 48 |
+
@property
|
| 49 |
+
def mass(self):
|
| 50 |
+
"""The body's mass."""
|
| 51 |
+
return self._mass
|
| 52 |
+
|
| 53 |
+
@mass.setter
|
| 54 |
+
def mass(self, mass):
|
| 55 |
+
self._mass = sympify(mass)
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def potential_energy(self):
|
| 59 |
+
"""The potential energy of the body.
|
| 60 |
+
|
| 61 |
+
Examples
|
| 62 |
+
========
|
| 63 |
+
|
| 64 |
+
>>> from sympy.physics.mechanics import Particle, Point
|
| 65 |
+
>>> from sympy import symbols
|
| 66 |
+
>>> m, g, h = symbols('m g h')
|
| 67 |
+
>>> O = Point('O')
|
| 68 |
+
>>> P = Particle('P', O, m)
|
| 69 |
+
>>> P.potential_energy = m * g * h
|
| 70 |
+
>>> P.potential_energy
|
| 71 |
+
g*h*m
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
return self._potential_energy
|
| 75 |
+
|
| 76 |
+
@potential_energy.setter
|
| 77 |
+
def potential_energy(self, scalar):
|
| 78 |
+
self._potential_energy = sympify(scalar)
|
| 79 |
+
|
| 80 |
+
@abstractmethod
|
| 81 |
+
def kinetic_energy(self, frame):
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
@abstractmethod
|
| 85 |
+
def linear_momentum(self, frame):
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
@abstractmethod
|
| 89 |
+
def angular_momentum(self, point, frame):
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
@abstractmethod
|
| 93 |
+
def parallel_axis(self, point, frame):
|
| 94 |
+
pass
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/jointsmethod.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.physics.mechanics import (Body, Lagrangian, KanesMethod, LagrangesMethod,
|
| 2 |
+
RigidBody, Particle)
|
| 3 |
+
from sympy.physics.mechanics.body_base import BodyBase
|
| 4 |
+
from sympy.physics.mechanics.method import _Methods
|
| 5 |
+
from sympy import Matrix
|
| 6 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 7 |
+
|
| 8 |
+
__all__ = ['JointsMethod']
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class JointsMethod(_Methods):
|
| 12 |
+
"""Method for formulating the equations of motion using a set of interconnected bodies with joints.
|
| 13 |
+
|
| 14 |
+
.. deprecated:: 1.13
|
| 15 |
+
The JointsMethod class is deprecated. Its functionality has been
|
| 16 |
+
replaced by the new :class:`~.System` class.
|
| 17 |
+
|
| 18 |
+
Parameters
|
| 19 |
+
==========
|
| 20 |
+
|
| 21 |
+
newtonion : Body or ReferenceFrame
|
| 22 |
+
The newtonion(inertial) frame.
|
| 23 |
+
*joints : Joint
|
| 24 |
+
The joints in the system
|
| 25 |
+
|
| 26 |
+
Attributes
|
| 27 |
+
==========
|
| 28 |
+
|
| 29 |
+
q, u : iterable
|
| 30 |
+
Iterable of the generalized coordinates and speeds
|
| 31 |
+
bodies : iterable
|
| 32 |
+
Iterable of Body objects in the system.
|
| 33 |
+
loads : iterable
|
| 34 |
+
Iterable of (Point, vector) or (ReferenceFrame, vector) tuples
|
| 35 |
+
describing the forces on the system.
|
| 36 |
+
mass_matrix : Matrix, shape(n, n)
|
| 37 |
+
The system's mass matrix
|
| 38 |
+
forcing : Matrix, shape(n, 1)
|
| 39 |
+
The system's forcing vector
|
| 40 |
+
mass_matrix_full : Matrix, shape(2*n, 2*n)
|
| 41 |
+
The "mass matrix" for the u's and q's
|
| 42 |
+
forcing_full : Matrix, shape(2*n, 1)
|
| 43 |
+
The "forcing vector" for the u's and q's
|
| 44 |
+
method : KanesMethod or Lagrange's method
|
| 45 |
+
Method's object.
|
| 46 |
+
kdes : iterable
|
| 47 |
+
Iterable of kde in they system.
|
| 48 |
+
|
| 49 |
+
Examples
|
| 50 |
+
========
|
| 51 |
+
|
| 52 |
+
As Body and JointsMethod have been deprecated, the following examples are
|
| 53 |
+
for illustrative purposes only. The functionality of Body is fully captured
|
| 54 |
+
by :class:`~.RigidBody` and :class:`~.Particle` and the functionality of
|
| 55 |
+
JointsMethod is fully captured by :class:`~.System`. To ignore the
|
| 56 |
+
deprecation warning we can use the ignore_warnings context manager.
|
| 57 |
+
|
| 58 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 59 |
+
|
| 60 |
+
This is a simple example for a one degree of freedom translational
|
| 61 |
+
spring-mass-damper.
|
| 62 |
+
|
| 63 |
+
>>> from sympy import symbols
|
| 64 |
+
>>> from sympy.physics.mechanics import Body, JointsMethod, PrismaticJoint
|
| 65 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 66 |
+
>>> c, k = symbols('c k')
|
| 67 |
+
>>> x, v = dynamicsymbols('x v')
|
| 68 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 69 |
+
... wall = Body('W')
|
| 70 |
+
... body = Body('B')
|
| 71 |
+
>>> J = PrismaticJoint('J', wall, body, coordinates=x, speeds=v)
|
| 72 |
+
>>> wall.apply_force(c*v*wall.x, reaction_body=body)
|
| 73 |
+
>>> wall.apply_force(k*x*wall.x, reaction_body=body)
|
| 74 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 75 |
+
... method = JointsMethod(wall, J)
|
| 76 |
+
>>> method.form_eoms()
|
| 77 |
+
Matrix([[-B_mass*Derivative(v(t), t) - c*v(t) - k*x(t)]])
|
| 78 |
+
>>> M = method.mass_matrix_full
|
| 79 |
+
>>> F = method.forcing_full
|
| 80 |
+
>>> rhs = M.LUsolve(F)
|
| 81 |
+
>>> rhs
|
| 82 |
+
Matrix([
|
| 83 |
+
[ v(t)],
|
| 84 |
+
[(-c*v(t) - k*x(t))/B_mass]])
|
| 85 |
+
|
| 86 |
+
Notes
|
| 87 |
+
=====
|
| 88 |
+
|
| 89 |
+
``JointsMethod`` currently only works with systems that do not have any
|
| 90 |
+
configuration or motion constraints.
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
def __init__(self, newtonion, *joints):
|
| 95 |
+
sympy_deprecation_warning(
|
| 96 |
+
"""
|
| 97 |
+
The JointsMethod class is deprecated.
|
| 98 |
+
Its functionality has been replaced by the new System class.
|
| 99 |
+
""",
|
| 100 |
+
deprecated_since_version="1.13",
|
| 101 |
+
active_deprecations_target="deprecated-mechanics-jointsmethod"
|
| 102 |
+
)
|
| 103 |
+
if isinstance(newtonion, BodyBase):
|
| 104 |
+
self.frame = newtonion.frame
|
| 105 |
+
else:
|
| 106 |
+
self.frame = newtonion
|
| 107 |
+
|
| 108 |
+
self._joints = joints
|
| 109 |
+
self._bodies = self._generate_bodylist()
|
| 110 |
+
self._loads = self._generate_loadlist()
|
| 111 |
+
self._q = self._generate_q()
|
| 112 |
+
self._u = self._generate_u()
|
| 113 |
+
self._kdes = self._generate_kdes()
|
| 114 |
+
|
| 115 |
+
self._method = None
|
| 116 |
+
|
| 117 |
+
@property
|
| 118 |
+
def bodies(self):
|
| 119 |
+
"""List of bodies in they system."""
|
| 120 |
+
return self._bodies
|
| 121 |
+
|
| 122 |
+
@property
|
| 123 |
+
def loads(self):
|
| 124 |
+
"""List of loads on the system."""
|
| 125 |
+
return self._loads
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
def q(self):
|
| 129 |
+
"""List of the generalized coordinates."""
|
| 130 |
+
return self._q
|
| 131 |
+
|
| 132 |
+
@property
|
| 133 |
+
def u(self):
|
| 134 |
+
"""List of the generalized speeds."""
|
| 135 |
+
return self._u
|
| 136 |
+
|
| 137 |
+
@property
|
| 138 |
+
def kdes(self):
|
| 139 |
+
"""List of the generalized coordinates."""
|
| 140 |
+
return self._kdes
|
| 141 |
+
|
| 142 |
+
@property
|
| 143 |
+
def forcing_full(self):
|
| 144 |
+
"""The "forcing vector" for the u's and q's."""
|
| 145 |
+
return self.method.forcing_full
|
| 146 |
+
|
| 147 |
+
@property
|
| 148 |
+
def mass_matrix_full(self):
|
| 149 |
+
"""The "mass matrix" for the u's and q's."""
|
| 150 |
+
return self.method.mass_matrix_full
|
| 151 |
+
|
| 152 |
+
@property
|
| 153 |
+
def mass_matrix(self):
|
| 154 |
+
"""The system's mass matrix."""
|
| 155 |
+
return self.method.mass_matrix
|
| 156 |
+
|
| 157 |
+
@property
|
| 158 |
+
def forcing(self):
|
| 159 |
+
"""The system's forcing vector."""
|
| 160 |
+
return self.method.forcing
|
| 161 |
+
|
| 162 |
+
@property
|
| 163 |
+
def method(self):
|
| 164 |
+
"""Object of method used to form equations of systems."""
|
| 165 |
+
return self._method
|
| 166 |
+
|
| 167 |
+
def _generate_bodylist(self):
|
| 168 |
+
bodies = []
|
| 169 |
+
for joint in self._joints:
|
| 170 |
+
if joint.child not in bodies:
|
| 171 |
+
bodies.append(joint.child)
|
| 172 |
+
if joint.parent not in bodies:
|
| 173 |
+
bodies.append(joint.parent)
|
| 174 |
+
return bodies
|
| 175 |
+
|
| 176 |
+
def _generate_loadlist(self):
|
| 177 |
+
load_list = []
|
| 178 |
+
for body in self.bodies:
|
| 179 |
+
if isinstance(body, Body):
|
| 180 |
+
load_list.extend(body.loads)
|
| 181 |
+
return load_list
|
| 182 |
+
|
| 183 |
+
def _generate_q(self):
|
| 184 |
+
q_ind = []
|
| 185 |
+
for joint in self._joints:
|
| 186 |
+
for coordinate in joint.coordinates:
|
| 187 |
+
if coordinate in q_ind:
|
| 188 |
+
raise ValueError('Coordinates of joints should be unique.')
|
| 189 |
+
q_ind.append(coordinate)
|
| 190 |
+
return Matrix(q_ind)
|
| 191 |
+
|
| 192 |
+
def _generate_u(self):
|
| 193 |
+
u_ind = []
|
| 194 |
+
for joint in self._joints:
|
| 195 |
+
for speed in joint.speeds:
|
| 196 |
+
if speed in u_ind:
|
| 197 |
+
raise ValueError('Speeds of joints should be unique.')
|
| 198 |
+
u_ind.append(speed)
|
| 199 |
+
return Matrix(u_ind)
|
| 200 |
+
|
| 201 |
+
def _generate_kdes(self):
|
| 202 |
+
kd_ind = Matrix(1, 0, []).T
|
| 203 |
+
for joint in self._joints:
|
| 204 |
+
kd_ind = kd_ind.col_join(joint.kdes)
|
| 205 |
+
return kd_ind
|
| 206 |
+
|
| 207 |
+
def _convert_bodies(self):
|
| 208 |
+
# Convert `Body` to `Particle` and `RigidBody`
|
| 209 |
+
bodylist = []
|
| 210 |
+
for body in self.bodies:
|
| 211 |
+
if not isinstance(body, Body):
|
| 212 |
+
bodylist.append(body)
|
| 213 |
+
continue
|
| 214 |
+
if body.is_rigidbody:
|
| 215 |
+
rb = RigidBody(body.name, body.masscenter, body.frame, body.mass,
|
| 216 |
+
(body.central_inertia, body.masscenter))
|
| 217 |
+
rb.potential_energy = body.potential_energy
|
| 218 |
+
bodylist.append(rb)
|
| 219 |
+
else:
|
| 220 |
+
part = Particle(body.name, body.masscenter, body.mass)
|
| 221 |
+
part.potential_energy = body.potential_energy
|
| 222 |
+
bodylist.append(part)
|
| 223 |
+
return bodylist
|
| 224 |
+
|
| 225 |
+
def form_eoms(self, method=KanesMethod):
|
| 226 |
+
"""Method to form system's equation of motions.
|
| 227 |
+
|
| 228 |
+
Parameters
|
| 229 |
+
==========
|
| 230 |
+
|
| 231 |
+
method : Class
|
| 232 |
+
Class name of method.
|
| 233 |
+
|
| 234 |
+
Returns
|
| 235 |
+
========
|
| 236 |
+
|
| 237 |
+
Matrix
|
| 238 |
+
Vector of equations of motions.
|
| 239 |
+
|
| 240 |
+
Examples
|
| 241 |
+
========
|
| 242 |
+
|
| 243 |
+
As Body and JointsMethod have been deprecated, the following examples
|
| 244 |
+
are for illustrative purposes only. The functionality of Body is fully
|
| 245 |
+
captured by :class:`~.RigidBody` and :class:`~.Particle` and the
|
| 246 |
+
functionality of JointsMethod is fully captured by :class:`~.System`. To
|
| 247 |
+
ignore the deprecation warning we can use the ignore_warnings context
|
| 248 |
+
manager.
|
| 249 |
+
|
| 250 |
+
>>> from sympy.utilities.exceptions import ignore_warnings
|
| 251 |
+
|
| 252 |
+
This is a simple example for a one degree of freedom translational
|
| 253 |
+
spring-mass-damper.
|
| 254 |
+
|
| 255 |
+
>>> from sympy import S, symbols
|
| 256 |
+
>>> from sympy.physics.mechanics import LagrangesMethod, dynamicsymbols, Body
|
| 257 |
+
>>> from sympy.physics.mechanics import PrismaticJoint, JointsMethod
|
| 258 |
+
>>> q = dynamicsymbols('q')
|
| 259 |
+
>>> qd = dynamicsymbols('q', 1)
|
| 260 |
+
>>> m, k, b = symbols('m k b')
|
| 261 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 262 |
+
... wall = Body('W')
|
| 263 |
+
... part = Body('P', mass=m)
|
| 264 |
+
>>> part.potential_energy = k * q**2 / S(2)
|
| 265 |
+
>>> J = PrismaticJoint('J', wall, part, coordinates=q, speeds=qd)
|
| 266 |
+
>>> wall.apply_force(b * qd * wall.x, reaction_body=part)
|
| 267 |
+
>>> with ignore_warnings(DeprecationWarning):
|
| 268 |
+
... method = JointsMethod(wall, J)
|
| 269 |
+
>>> method.form_eoms(LagrangesMethod)
|
| 270 |
+
Matrix([[b*Derivative(q(t), t) + k*q(t) + m*Derivative(q(t), (t, 2))]])
|
| 271 |
+
|
| 272 |
+
We can also solve for the states using the 'rhs' method.
|
| 273 |
+
|
| 274 |
+
>>> method.rhs()
|
| 275 |
+
Matrix([
|
| 276 |
+
[ Derivative(q(t), t)],
|
| 277 |
+
[(-b*Derivative(q(t), t) - k*q(t))/m]])
|
| 278 |
+
|
| 279 |
+
"""
|
| 280 |
+
|
| 281 |
+
bodylist = self._convert_bodies()
|
| 282 |
+
if issubclass(method, LagrangesMethod): #LagrangesMethod or similar
|
| 283 |
+
L = Lagrangian(self.frame, *bodylist)
|
| 284 |
+
self._method = method(L, self.q, self.loads, bodylist, self.frame)
|
| 285 |
+
else: #KanesMethod or similar
|
| 286 |
+
self._method = method(self.frame, q_ind=self.q, u_ind=self.u, kd_eqs=self.kdes,
|
| 287 |
+
forcelist=self.loads, bodies=bodylist)
|
| 288 |
+
soln = self.method._form_eoms()
|
| 289 |
+
return soln
|
| 290 |
+
|
| 291 |
+
def rhs(self, inv_method=None):
|
| 292 |
+
"""Returns equations that can be solved numerically.
|
| 293 |
+
|
| 294 |
+
Parameters
|
| 295 |
+
==========
|
| 296 |
+
|
| 297 |
+
inv_method : str
|
| 298 |
+
The specific sympy inverse matrix calculation method to use. For a
|
| 299 |
+
list of valid methods, see
|
| 300 |
+
:meth:`~sympy.matrices.matrixbase.MatrixBase.inv`
|
| 301 |
+
|
| 302 |
+
Returns
|
| 303 |
+
========
|
| 304 |
+
|
| 305 |
+
Matrix
|
| 306 |
+
Numerically solvable equations.
|
| 307 |
+
|
| 308 |
+
See Also
|
| 309 |
+
========
|
| 310 |
+
|
| 311 |
+
sympy.physics.mechanics.kane.KanesMethod.rhs:
|
| 312 |
+
KanesMethod's rhs function.
|
| 313 |
+
sympy.physics.mechanics.lagrange.LagrangesMethod.rhs:
|
| 314 |
+
LagrangesMethod's rhs function.
|
| 315 |
+
|
| 316 |
+
"""
|
| 317 |
+
|
| 318 |
+
return self.method.rhs(inv_method=inv_method)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/kane.py
ADDED
|
@@ -0,0 +1,860 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import zeros, Matrix, diff, eye
|
| 2 |
+
from sympy.core.sorting import default_sort_key
|
| 3 |
+
from sympy.physics.vector import (ReferenceFrame, dynamicsymbols,
|
| 4 |
+
partial_velocity)
|
| 5 |
+
from sympy.physics.mechanics.method import _Methods
|
| 6 |
+
from sympy.physics.mechanics.particle import Particle
|
| 7 |
+
from sympy.physics.mechanics.rigidbody import RigidBody
|
| 8 |
+
from sympy.physics.mechanics.functions import (msubs, find_dynamicsymbols,
|
| 9 |
+
_f_list_parser,
|
| 10 |
+
_validate_coordinates,
|
| 11 |
+
_parse_linear_solver)
|
| 12 |
+
from sympy.physics.mechanics.linearize import Linearizer
|
| 13 |
+
from sympy.utilities.iterables import iterable
|
| 14 |
+
|
| 15 |
+
__all__ = ['KanesMethod']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class KanesMethod(_Methods):
|
| 19 |
+
r"""Kane's method object.
|
| 20 |
+
|
| 21 |
+
Explanation
|
| 22 |
+
===========
|
| 23 |
+
|
| 24 |
+
This object is used to do the "book-keeping" as you go through and form
|
| 25 |
+
equations of motion in the way Kane presents in:
|
| 26 |
+
Kane, T., Levinson, D. Dynamics Theory and Applications. 1985 McGraw-Hill
|
| 27 |
+
|
| 28 |
+
The attributes are for equations in the form [M] udot = forcing.
|
| 29 |
+
|
| 30 |
+
Attributes
|
| 31 |
+
==========
|
| 32 |
+
|
| 33 |
+
q, u : Matrix
|
| 34 |
+
Matrices of the generalized coordinates and speeds
|
| 35 |
+
bodies : iterable
|
| 36 |
+
Iterable of Particle and RigidBody objects in the system.
|
| 37 |
+
loads : iterable
|
| 38 |
+
Iterable of (Point, vector) or (ReferenceFrame, vector) tuples
|
| 39 |
+
describing the forces on the system.
|
| 40 |
+
auxiliary_eqs : Matrix
|
| 41 |
+
If applicable, the set of auxiliary Kane's
|
| 42 |
+
equations used to solve for non-contributing
|
| 43 |
+
forces.
|
| 44 |
+
mass_matrix : Matrix
|
| 45 |
+
The system's dynamics mass matrix: [k_d; k_dnh]
|
| 46 |
+
forcing : Matrix
|
| 47 |
+
The system's dynamics forcing vector: -[f_d; f_dnh]
|
| 48 |
+
mass_matrix_kin : Matrix
|
| 49 |
+
The "mass matrix" for kinematic differential equations: k_kqdot
|
| 50 |
+
forcing_kin : Matrix
|
| 51 |
+
The forcing vector for kinematic differential equations: -(k_ku*u + f_k)
|
| 52 |
+
mass_matrix_full : Matrix
|
| 53 |
+
The "mass matrix" for the u's and q's with dynamics and kinematics
|
| 54 |
+
forcing_full : Matrix
|
| 55 |
+
The "forcing vector" for the u's and q's with dynamics and kinematics
|
| 56 |
+
|
| 57 |
+
Parameters
|
| 58 |
+
==========
|
| 59 |
+
|
| 60 |
+
frame : ReferenceFrame
|
| 61 |
+
The inertial reference frame for the system.
|
| 62 |
+
q_ind : iterable of dynamicsymbols
|
| 63 |
+
Independent generalized coordinates.
|
| 64 |
+
u_ind : iterable of dynamicsymbols
|
| 65 |
+
Independent generalized speeds.
|
| 66 |
+
kd_eqs : iterable of Expr, optional
|
| 67 |
+
Kinematic differential equations, which linearly relate the generalized
|
| 68 |
+
speeds to the time-derivatives of the generalized coordinates.
|
| 69 |
+
q_dependent : iterable of dynamicsymbols, optional
|
| 70 |
+
Dependent generalized coordinates.
|
| 71 |
+
configuration_constraints : iterable of Expr, optional
|
| 72 |
+
Constraints on the system's configuration, i.e. holonomic constraints.
|
| 73 |
+
u_dependent : iterable of dynamicsymbols, optional
|
| 74 |
+
Dependent generalized speeds.
|
| 75 |
+
velocity_constraints : iterable of Expr, optional
|
| 76 |
+
Constraints on the system's velocity, i.e. the combination of the
|
| 77 |
+
nonholonomic constraints and the time-derivative of the holonomic
|
| 78 |
+
constraints.
|
| 79 |
+
acceleration_constraints : iterable of Expr, optional
|
| 80 |
+
Constraints on the system's acceleration, by default these are the
|
| 81 |
+
time-derivative of the velocity constraints.
|
| 82 |
+
u_auxiliary : iterable of dynamicsymbols, optional
|
| 83 |
+
Auxiliary generalized speeds.
|
| 84 |
+
bodies : iterable of Particle and/or RigidBody, optional
|
| 85 |
+
The particles and rigid bodies in the system.
|
| 86 |
+
forcelist : iterable of tuple[Point | ReferenceFrame, Vector], optional
|
| 87 |
+
Forces and torques applied on the system.
|
| 88 |
+
explicit_kinematics : bool
|
| 89 |
+
Boolean whether the mass matrices and forcing vectors should use the
|
| 90 |
+
explicit form (default) or implicit form for kinematics.
|
| 91 |
+
See the notes for more details.
|
| 92 |
+
kd_eqs_solver : str, callable
|
| 93 |
+
Method used to solve the kinematic differential equations. If a string
|
| 94 |
+
is supplied, it should be a valid method that can be used with the
|
| 95 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 96 |
+
supplied, it should have the format ``f(A, rhs)``, where it solves the
|
| 97 |
+
equations and returns the solution. The default utilizes LU solve. See
|
| 98 |
+
the notes for more information.
|
| 99 |
+
constraint_solver : str, callable
|
| 100 |
+
Method used to solve the velocity constraints. If a string is
|
| 101 |
+
supplied, it should be a valid method that can be used with the
|
| 102 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 103 |
+
supplied, it should have the format ``f(A, rhs)``, where it solves the
|
| 104 |
+
equations and returns the solution. The default utilizes LU solve. See
|
| 105 |
+
the notes for more information.
|
| 106 |
+
|
| 107 |
+
Notes
|
| 108 |
+
=====
|
| 109 |
+
|
| 110 |
+
The mass matrices and forcing vectors related to kinematic equations
|
| 111 |
+
are given in the explicit form by default. In other words, the kinematic
|
| 112 |
+
mass matrix is $\mathbf{k_{k\dot{q}}} = \mathbf{I}$.
|
| 113 |
+
In order to get the implicit form of those matrices/vectors, you can set the
|
| 114 |
+
``explicit_kinematics`` attribute to ``False``. So $\mathbf{k_{k\dot{q}}}$
|
| 115 |
+
is not necessarily an identity matrix. This can provide more compact
|
| 116 |
+
equations for non-simple kinematics.
|
| 117 |
+
|
| 118 |
+
Two linear solvers can be supplied to ``KanesMethod``: one for solving the
|
| 119 |
+
kinematic differential equations and one to solve the velocity constraints.
|
| 120 |
+
Both of these sets of equations can be expressed as a linear system ``Ax = rhs``,
|
| 121 |
+
which have to be solved in order to obtain the equations of motion.
|
| 122 |
+
|
| 123 |
+
The default solver ``'LU'``, which stands for LU solve, results relatively low
|
| 124 |
+
number of operations. The weakness of this method is that it can result in zero
|
| 125 |
+
division errors.
|
| 126 |
+
|
| 127 |
+
If zero divisions are encountered, a possible solver which may solve the problem
|
| 128 |
+
is ``"CRAMER"``. This method uses Cramer's rule to solve the system. This method
|
| 129 |
+
is slower and results in more operations than the default solver. However it only
|
| 130 |
+
uses a single division by default per entry of the solution.
|
| 131 |
+
|
| 132 |
+
While a valid list of solvers can be found at
|
| 133 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`, it is also possible to supply a
|
| 134 |
+
`callable`. This way it is possible to use a different solver routine. If the
|
| 135 |
+
kinematic differential equations are not too complex it can be worth it to simplify
|
| 136 |
+
the solution by using ``lambda A, b: simplify(Matrix.LUsolve(A, b))``. Another
|
| 137 |
+
option solver one may use is :func:`sympy.solvers.solveset.linsolve`. This can be
|
| 138 |
+
done using `lambda A, b: tuple(linsolve((A, b)))[0]`, where we select the first
|
| 139 |
+
solution as our system should have only one unique solution.
|
| 140 |
+
|
| 141 |
+
Examples
|
| 142 |
+
========
|
| 143 |
+
|
| 144 |
+
This is a simple example for a one degree of freedom translational
|
| 145 |
+
spring-mass-damper.
|
| 146 |
+
|
| 147 |
+
In this example, we first need to do the kinematics.
|
| 148 |
+
This involves creating generalized speeds and coordinates and their
|
| 149 |
+
derivatives.
|
| 150 |
+
Then we create a point and set its velocity in a frame.
|
| 151 |
+
|
| 152 |
+
>>> from sympy import symbols
|
| 153 |
+
>>> from sympy.physics.mechanics import dynamicsymbols, ReferenceFrame
|
| 154 |
+
>>> from sympy.physics.mechanics import Point, Particle, KanesMethod
|
| 155 |
+
>>> q, u = dynamicsymbols('q u')
|
| 156 |
+
>>> qd, ud = dynamicsymbols('q u', 1)
|
| 157 |
+
>>> m, c, k = symbols('m c k')
|
| 158 |
+
>>> N = ReferenceFrame('N')
|
| 159 |
+
>>> P = Point('P')
|
| 160 |
+
>>> P.set_vel(N, u * N.x)
|
| 161 |
+
|
| 162 |
+
Next we need to arrange/store information in the way that KanesMethod
|
| 163 |
+
requires. The kinematic differential equations should be an iterable of
|
| 164 |
+
expressions. A list of forces/torques must be constructed, where each entry
|
| 165 |
+
in the list is a (Point, Vector) or (ReferenceFrame, Vector) tuple, where
|
| 166 |
+
the Vectors represent the Force or Torque.
|
| 167 |
+
Next a particle needs to be created, and it needs to have a point and mass
|
| 168 |
+
assigned to it.
|
| 169 |
+
Finally, a list of all bodies and particles needs to be created.
|
| 170 |
+
|
| 171 |
+
>>> kd = [qd - u]
|
| 172 |
+
>>> FL = [(P, (-k * q - c * u) * N.x)]
|
| 173 |
+
>>> pa = Particle('pa', P, m)
|
| 174 |
+
>>> BL = [pa]
|
| 175 |
+
|
| 176 |
+
Finally we can generate the equations of motion.
|
| 177 |
+
First we create the KanesMethod object and supply an inertial frame,
|
| 178 |
+
coordinates, generalized speeds, and the kinematic differential equations.
|
| 179 |
+
Additional quantities such as configuration and motion constraints,
|
| 180 |
+
dependent coordinates and speeds, and auxiliary speeds are also supplied
|
| 181 |
+
here (see the online documentation).
|
| 182 |
+
Next we form FR* and FR to complete: Fr + Fr* = 0.
|
| 183 |
+
We have the equations of motion at this point.
|
| 184 |
+
It makes sense to rearrange them though, so we calculate the mass matrix and
|
| 185 |
+
the forcing terms, for E.o.M. in the form: [MM] udot = forcing, where MM is
|
| 186 |
+
the mass matrix, udot is a vector of the time derivatives of the
|
| 187 |
+
generalized speeds, and forcing is a vector representing "forcing" terms.
|
| 188 |
+
|
| 189 |
+
>>> KM = KanesMethod(N, q_ind=[q], u_ind=[u], kd_eqs=kd)
|
| 190 |
+
>>> (fr, frstar) = KM.kanes_equations(BL, FL)
|
| 191 |
+
>>> MM = KM.mass_matrix
|
| 192 |
+
>>> forcing = KM.forcing
|
| 193 |
+
>>> rhs = MM.inv() * forcing
|
| 194 |
+
>>> rhs
|
| 195 |
+
Matrix([[(-c*u(t) - k*q(t))/m]])
|
| 196 |
+
>>> KM.linearize(A_and_B=True)[0]
|
| 197 |
+
Matrix([
|
| 198 |
+
[ 0, 1],
|
| 199 |
+
[-k/m, -c/m]])
|
| 200 |
+
|
| 201 |
+
Please look at the documentation pages for more information on how to
|
| 202 |
+
perform linearization and how to deal with dependent coordinates & speeds,
|
| 203 |
+
and how do deal with bringing non-contributing forces into evidence.
|
| 204 |
+
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
def __init__(self, frame, q_ind, u_ind, kd_eqs=None, q_dependent=None,
|
| 208 |
+
configuration_constraints=None, u_dependent=None,
|
| 209 |
+
velocity_constraints=None, acceleration_constraints=None,
|
| 210 |
+
u_auxiliary=None, bodies=None, forcelist=None,
|
| 211 |
+
explicit_kinematics=True, kd_eqs_solver='LU',
|
| 212 |
+
constraint_solver='LU'):
|
| 213 |
+
|
| 214 |
+
"""Please read the online documentation. """
|
| 215 |
+
if not q_ind:
|
| 216 |
+
q_ind = [dynamicsymbols('dummy_q')]
|
| 217 |
+
kd_eqs = [dynamicsymbols('dummy_kd')]
|
| 218 |
+
|
| 219 |
+
if not isinstance(frame, ReferenceFrame):
|
| 220 |
+
raise TypeError('An inertial ReferenceFrame must be supplied')
|
| 221 |
+
self._inertial = frame
|
| 222 |
+
|
| 223 |
+
self._fr = None
|
| 224 |
+
self._frstar = None
|
| 225 |
+
|
| 226 |
+
self._forcelist = forcelist
|
| 227 |
+
self._bodylist = bodies
|
| 228 |
+
|
| 229 |
+
self.explicit_kinematics = explicit_kinematics
|
| 230 |
+
self._constraint_solver = constraint_solver
|
| 231 |
+
self._initialize_vectors(q_ind, q_dependent, u_ind, u_dependent,
|
| 232 |
+
u_auxiliary)
|
| 233 |
+
_validate_coordinates(self.q, self.u)
|
| 234 |
+
self._initialize_kindiffeq_matrices(kd_eqs, kd_eqs_solver)
|
| 235 |
+
self._initialize_constraint_matrices(
|
| 236 |
+
configuration_constraints, velocity_constraints,
|
| 237 |
+
acceleration_constraints, constraint_solver)
|
| 238 |
+
|
| 239 |
+
def _initialize_vectors(self, q_ind, q_dep, u_ind, u_dep, u_aux):
|
| 240 |
+
"""Initialize the coordinate and speed vectors."""
|
| 241 |
+
|
| 242 |
+
none_handler = lambda x: Matrix(x) if x else Matrix()
|
| 243 |
+
|
| 244 |
+
# Initialize generalized coordinates
|
| 245 |
+
q_dep = none_handler(q_dep)
|
| 246 |
+
if not iterable(q_ind):
|
| 247 |
+
raise TypeError('Generalized coordinates must be an iterable.')
|
| 248 |
+
if not iterable(q_dep):
|
| 249 |
+
raise TypeError('Dependent coordinates must be an iterable.')
|
| 250 |
+
q_ind = Matrix(q_ind)
|
| 251 |
+
self._qdep = q_dep
|
| 252 |
+
self._q = Matrix([q_ind, q_dep])
|
| 253 |
+
self._qdot = self.q.diff(dynamicsymbols._t)
|
| 254 |
+
|
| 255 |
+
# Initialize generalized speeds
|
| 256 |
+
u_dep = none_handler(u_dep)
|
| 257 |
+
if not iterable(u_ind):
|
| 258 |
+
raise TypeError('Generalized speeds must be an iterable.')
|
| 259 |
+
if not iterable(u_dep):
|
| 260 |
+
raise TypeError('Dependent speeds must be an iterable.')
|
| 261 |
+
u_ind = Matrix(u_ind)
|
| 262 |
+
self._udep = u_dep
|
| 263 |
+
self._u = Matrix([u_ind, u_dep])
|
| 264 |
+
self._udot = self.u.diff(dynamicsymbols._t)
|
| 265 |
+
self._uaux = none_handler(u_aux)
|
| 266 |
+
|
| 267 |
+
def _initialize_constraint_matrices(self, config, vel, acc, linear_solver='LU'):
|
| 268 |
+
"""Initializes constraint matrices."""
|
| 269 |
+
linear_solver = _parse_linear_solver(linear_solver)
|
| 270 |
+
# Define vector dimensions
|
| 271 |
+
o = len(self.u)
|
| 272 |
+
m = len(self._udep)
|
| 273 |
+
p = o - m
|
| 274 |
+
none_handler = lambda x: Matrix(x) if x else Matrix()
|
| 275 |
+
|
| 276 |
+
# Initialize configuration constraints
|
| 277 |
+
config = none_handler(config)
|
| 278 |
+
if len(self._qdep) != len(config):
|
| 279 |
+
raise ValueError('There must be an equal number of dependent '
|
| 280 |
+
'coordinates and configuration constraints.')
|
| 281 |
+
self._f_h = none_handler(config)
|
| 282 |
+
|
| 283 |
+
# Initialize velocity and acceleration constraints
|
| 284 |
+
vel = none_handler(vel)
|
| 285 |
+
acc = none_handler(acc)
|
| 286 |
+
if len(vel) != m:
|
| 287 |
+
raise ValueError('There must be an equal number of dependent '
|
| 288 |
+
'speeds and velocity constraints.')
|
| 289 |
+
if acc and (len(acc) != m):
|
| 290 |
+
raise ValueError('There must be an equal number of dependent '
|
| 291 |
+
'speeds and acceleration constraints.')
|
| 292 |
+
if vel:
|
| 293 |
+
u_zero = dict.fromkeys(self.u, 0)
|
| 294 |
+
udot_zero = dict.fromkeys(self._udot, 0)
|
| 295 |
+
|
| 296 |
+
# When calling kanes_equations, another class instance will be
|
| 297 |
+
# created if auxiliary u's are present. In this case, the
|
| 298 |
+
# computation of kinetic differential equation matrices will be
|
| 299 |
+
# skipped as this was computed during the original KanesMethod
|
| 300 |
+
# object, and the qd_u_map will not be available.
|
| 301 |
+
if self._qdot_u_map is not None:
|
| 302 |
+
vel = msubs(vel, self._qdot_u_map)
|
| 303 |
+
|
| 304 |
+
self._f_nh = msubs(vel, u_zero)
|
| 305 |
+
self._k_nh = (vel - self._f_nh).jacobian(self.u)
|
| 306 |
+
# If no acceleration constraints given, calculate them.
|
| 307 |
+
if not acc:
|
| 308 |
+
_f_dnh = (self._k_nh.diff(dynamicsymbols._t) * self.u +
|
| 309 |
+
self._f_nh.diff(dynamicsymbols._t))
|
| 310 |
+
if self._qdot_u_map is not None:
|
| 311 |
+
_f_dnh = msubs(_f_dnh, self._qdot_u_map)
|
| 312 |
+
self._f_dnh = _f_dnh
|
| 313 |
+
self._k_dnh = self._k_nh
|
| 314 |
+
else:
|
| 315 |
+
if self._qdot_u_map is not None:
|
| 316 |
+
acc = msubs(acc, self._qdot_u_map)
|
| 317 |
+
self._f_dnh = msubs(acc, udot_zero)
|
| 318 |
+
self._k_dnh = (acc - self._f_dnh).jacobian(self._udot)
|
| 319 |
+
|
| 320 |
+
# Form of non-holonomic constraints is B*u + C = 0.
|
| 321 |
+
# We partition B into independent and dependent columns:
|
| 322 |
+
# Ars is then -B_dep.inv() * B_ind, and it relates dependent speeds
|
| 323 |
+
# to independent speeds as: udep = Ars*uind, neglecting the C term.
|
| 324 |
+
B_ind = self._k_nh[:, :p]
|
| 325 |
+
B_dep = self._k_nh[:, p:o]
|
| 326 |
+
self._Ars = -linear_solver(B_dep, B_ind)
|
| 327 |
+
else:
|
| 328 |
+
self._f_nh = Matrix()
|
| 329 |
+
self._k_nh = Matrix()
|
| 330 |
+
self._f_dnh = Matrix()
|
| 331 |
+
self._k_dnh = Matrix()
|
| 332 |
+
self._Ars = Matrix()
|
| 333 |
+
|
| 334 |
+
def _initialize_kindiffeq_matrices(self, kdeqs, linear_solver='LU'):
|
| 335 |
+
"""Initialize the kinematic differential equation matrices.
|
| 336 |
+
|
| 337 |
+
Parameters
|
| 338 |
+
==========
|
| 339 |
+
kdeqs : sequence of sympy expressions
|
| 340 |
+
Kinematic differential equations in the form of f(u,q',q,t) where
|
| 341 |
+
f() = 0. The equations have to be linear in the generalized
|
| 342 |
+
coordinates and generalized speeds.
|
| 343 |
+
|
| 344 |
+
"""
|
| 345 |
+
linear_solver = _parse_linear_solver(linear_solver)
|
| 346 |
+
if kdeqs:
|
| 347 |
+
if len(self.q) != len(kdeqs):
|
| 348 |
+
raise ValueError('There must be an equal number of kinematic '
|
| 349 |
+
'differential equations and coordinates.')
|
| 350 |
+
|
| 351 |
+
u = self.u
|
| 352 |
+
qdot = self._qdot
|
| 353 |
+
|
| 354 |
+
kdeqs = Matrix(kdeqs)
|
| 355 |
+
|
| 356 |
+
u_zero = dict.fromkeys(u, 0)
|
| 357 |
+
uaux_zero = dict.fromkeys(self._uaux, 0)
|
| 358 |
+
qdot_zero = dict.fromkeys(qdot, 0)
|
| 359 |
+
|
| 360 |
+
# Extract the linear coefficient matrices as per the following
|
| 361 |
+
# equation:
|
| 362 |
+
#
|
| 363 |
+
# k_ku(q,t)*u(t) + k_kqdot(q,t)*q'(t) + f_k(q,t) = 0
|
| 364 |
+
#
|
| 365 |
+
k_ku = kdeqs.jacobian(u)
|
| 366 |
+
k_kqdot = kdeqs.jacobian(qdot)
|
| 367 |
+
f_k = kdeqs.xreplace(u_zero).xreplace(qdot_zero)
|
| 368 |
+
|
| 369 |
+
# The kinematic differential equations should be linear in both q'
|
| 370 |
+
# and u, so check for u and q' in the components.
|
| 371 |
+
dy_syms = find_dynamicsymbols(k_ku.row_join(k_kqdot).row_join(f_k))
|
| 372 |
+
nonlin_vars = [vari for vari in u[:] + qdot[:] if vari in dy_syms]
|
| 373 |
+
if nonlin_vars:
|
| 374 |
+
msg = ('The provided kinematic differential equations are '
|
| 375 |
+
'nonlinear in {}. They must be linear in the '
|
| 376 |
+
'generalized speeds and derivatives of the generalized '
|
| 377 |
+
'coordinates.')
|
| 378 |
+
raise ValueError(msg.format(nonlin_vars))
|
| 379 |
+
|
| 380 |
+
self._f_k_implicit = f_k.xreplace(uaux_zero)
|
| 381 |
+
self._k_ku_implicit = k_ku.xreplace(uaux_zero)
|
| 382 |
+
self._k_kqdot_implicit = k_kqdot
|
| 383 |
+
|
| 384 |
+
# Solve for q'(t) such that the coefficient matrices are now in
|
| 385 |
+
# this form:
|
| 386 |
+
#
|
| 387 |
+
# k_kqdot^-1*k_ku*u(t) + I*q'(t) + k_kqdot^-1*f_k = 0
|
| 388 |
+
#
|
| 389 |
+
# NOTE : Solving the kinematic differential equations here is not
|
| 390 |
+
# necessary and prevents the equations from being provided in fully
|
| 391 |
+
# implicit form.
|
| 392 |
+
f_k_explicit = linear_solver(k_kqdot, f_k)
|
| 393 |
+
k_ku_explicit = linear_solver(k_kqdot, k_ku)
|
| 394 |
+
self._qdot_u_map = dict(zip(qdot, -(k_ku_explicit*u + f_k_explicit)))
|
| 395 |
+
|
| 396 |
+
self._f_k = f_k_explicit.xreplace(uaux_zero)
|
| 397 |
+
self._k_ku = k_ku_explicit.xreplace(uaux_zero)
|
| 398 |
+
self._k_kqdot = eye(len(qdot))
|
| 399 |
+
|
| 400 |
+
else:
|
| 401 |
+
self._qdot_u_map = None
|
| 402 |
+
self._f_k_implicit = self._f_k = Matrix()
|
| 403 |
+
self._k_ku_implicit = self._k_ku = Matrix()
|
| 404 |
+
self._k_kqdot_implicit = self._k_kqdot = Matrix()
|
| 405 |
+
|
| 406 |
+
def _form_fr(self, fl):
|
| 407 |
+
"""Form the generalized active force."""
|
| 408 |
+
if fl is not None and (len(fl) == 0 or not iterable(fl)):
|
| 409 |
+
raise ValueError('Force pairs must be supplied in an '
|
| 410 |
+
'non-empty iterable or None.')
|
| 411 |
+
|
| 412 |
+
N = self._inertial
|
| 413 |
+
# pull out relevant velocities for constructing partial velocities
|
| 414 |
+
vel_list, f_list = _f_list_parser(fl, N)
|
| 415 |
+
vel_list = [msubs(i, self._qdot_u_map) for i in vel_list]
|
| 416 |
+
f_list = [msubs(i, self._qdot_u_map) for i in f_list]
|
| 417 |
+
|
| 418 |
+
# Fill Fr with dot product of partial velocities and forces
|
| 419 |
+
o = len(self.u)
|
| 420 |
+
b = len(f_list)
|
| 421 |
+
FR = zeros(o, 1)
|
| 422 |
+
partials = partial_velocity(vel_list, self.u, N)
|
| 423 |
+
for i in range(o):
|
| 424 |
+
FR[i] = sum(partials[j][i].dot(f_list[j]) for j in range(b))
|
| 425 |
+
|
| 426 |
+
# In case there are dependent speeds
|
| 427 |
+
if self._udep:
|
| 428 |
+
p = o - len(self._udep)
|
| 429 |
+
FRtilde = FR[:p, 0]
|
| 430 |
+
FRold = FR[p:o, 0]
|
| 431 |
+
FRtilde += self._Ars.T * FRold
|
| 432 |
+
FR = FRtilde
|
| 433 |
+
|
| 434 |
+
self._forcelist = fl
|
| 435 |
+
self._fr = FR
|
| 436 |
+
return FR
|
| 437 |
+
|
| 438 |
+
def _form_frstar(self, bl):
|
| 439 |
+
"""Form the generalized inertia force."""
|
| 440 |
+
|
| 441 |
+
if not iterable(bl):
|
| 442 |
+
raise TypeError('Bodies must be supplied in an iterable.')
|
| 443 |
+
|
| 444 |
+
t = dynamicsymbols._t
|
| 445 |
+
N = self._inertial
|
| 446 |
+
# Dicts setting things to zero
|
| 447 |
+
udot_zero = dict.fromkeys(self._udot, 0)
|
| 448 |
+
uaux_zero = dict.fromkeys(self._uaux, 0)
|
| 449 |
+
uauxdot = [diff(i, t) for i in self._uaux]
|
| 450 |
+
uauxdot_zero = dict.fromkeys(uauxdot, 0)
|
| 451 |
+
# Dictionary of q' and q'' to u and u'
|
| 452 |
+
q_ddot_u_map = {k.diff(t): v.diff(t).xreplace(
|
| 453 |
+
self._qdot_u_map) for (k, v) in self._qdot_u_map.items()}
|
| 454 |
+
q_ddot_u_map.update(self._qdot_u_map)
|
| 455 |
+
|
| 456 |
+
# Fill up the list of partials: format is a list with num elements
|
| 457 |
+
# equal to number of entries in body list. Each of these elements is a
|
| 458 |
+
# list - either of length 1 for the translational components of
|
| 459 |
+
# particles or of length 2 for the translational and rotational
|
| 460 |
+
# components of rigid bodies. The inner most list is the list of
|
| 461 |
+
# partial velocities.
|
| 462 |
+
def get_partial_velocity(body):
|
| 463 |
+
if isinstance(body, RigidBody):
|
| 464 |
+
vlist = [body.masscenter.vel(N), body.frame.ang_vel_in(N)]
|
| 465 |
+
elif isinstance(body, Particle):
|
| 466 |
+
vlist = [body.point.vel(N),]
|
| 467 |
+
else:
|
| 468 |
+
raise TypeError('The body list may only contain either '
|
| 469 |
+
'RigidBody or Particle as list elements.')
|
| 470 |
+
v = [msubs(vel, self._qdot_u_map) for vel in vlist]
|
| 471 |
+
return partial_velocity(v, self.u, N)
|
| 472 |
+
partials = [get_partial_velocity(body) for body in bl]
|
| 473 |
+
|
| 474 |
+
# Compute fr_star in two components:
|
| 475 |
+
# fr_star = -(MM*u' + nonMM)
|
| 476 |
+
o = len(self.u)
|
| 477 |
+
MM = zeros(o, o)
|
| 478 |
+
nonMM = zeros(o, 1)
|
| 479 |
+
zero_uaux = lambda expr: msubs(expr, uaux_zero)
|
| 480 |
+
zero_udot_uaux = lambda expr: msubs(msubs(expr, udot_zero), uaux_zero)
|
| 481 |
+
for i, body in enumerate(bl):
|
| 482 |
+
if isinstance(body, RigidBody):
|
| 483 |
+
M = zero_uaux(body.mass)
|
| 484 |
+
I = zero_uaux(body.central_inertia)
|
| 485 |
+
vel = zero_uaux(body.masscenter.vel(N))
|
| 486 |
+
omega = zero_uaux(body.frame.ang_vel_in(N))
|
| 487 |
+
acc = zero_udot_uaux(body.masscenter.acc(N))
|
| 488 |
+
inertial_force = (M.diff(t) * vel + M * acc)
|
| 489 |
+
inertial_torque = zero_uaux((I.dt(body.frame).dot(omega)) +
|
| 490 |
+
msubs(I.dot(body.frame.ang_acc_in(N)), udot_zero) +
|
| 491 |
+
(omega.cross(I.dot(omega))))
|
| 492 |
+
for j in range(o):
|
| 493 |
+
tmp_vel = zero_uaux(partials[i][0][j])
|
| 494 |
+
tmp_ang = zero_uaux(I.dot(partials[i][1][j]))
|
| 495 |
+
for k in range(o):
|
| 496 |
+
# translational
|
| 497 |
+
MM[j, k] += M*tmp_vel.dot(partials[i][0][k])
|
| 498 |
+
# rotational
|
| 499 |
+
MM[j, k] += tmp_ang.dot(partials[i][1][k])
|
| 500 |
+
nonMM[j] += inertial_force.dot(partials[i][0][j])
|
| 501 |
+
nonMM[j] += inertial_torque.dot(partials[i][1][j])
|
| 502 |
+
else:
|
| 503 |
+
M = zero_uaux(body.mass)
|
| 504 |
+
vel = zero_uaux(body.point.vel(N))
|
| 505 |
+
acc = zero_udot_uaux(body.point.acc(N))
|
| 506 |
+
inertial_force = (M.diff(t) * vel + M * acc)
|
| 507 |
+
for j in range(o):
|
| 508 |
+
temp = zero_uaux(partials[i][0][j])
|
| 509 |
+
for k in range(o):
|
| 510 |
+
MM[j, k] += M*temp.dot(partials[i][0][k])
|
| 511 |
+
nonMM[j] += inertial_force.dot(partials[i][0][j])
|
| 512 |
+
# Compose fr_star out of MM and nonMM
|
| 513 |
+
MM = zero_uaux(msubs(MM, q_ddot_u_map))
|
| 514 |
+
nonMM = msubs(msubs(nonMM, q_ddot_u_map),
|
| 515 |
+
udot_zero, uauxdot_zero, uaux_zero)
|
| 516 |
+
fr_star = -(MM * msubs(Matrix(self._udot), uauxdot_zero) + nonMM)
|
| 517 |
+
|
| 518 |
+
# If there are dependent speeds, we need to find fr_star_tilde
|
| 519 |
+
if self._udep:
|
| 520 |
+
p = o - len(self._udep)
|
| 521 |
+
fr_star_ind = fr_star[:p, 0]
|
| 522 |
+
fr_star_dep = fr_star[p:o, 0]
|
| 523 |
+
fr_star = fr_star_ind + (self._Ars.T * fr_star_dep)
|
| 524 |
+
# Apply the same to MM
|
| 525 |
+
MMi = MM[:p, :]
|
| 526 |
+
MMd = MM[p:o, :]
|
| 527 |
+
MM = MMi + (self._Ars.T * MMd)
|
| 528 |
+
# Apply the same to nonMM
|
| 529 |
+
nonMM = nonMM[:p, :] + (self._Ars.T * nonMM[p:o, :])
|
| 530 |
+
|
| 531 |
+
self._bodylist = bl
|
| 532 |
+
self._frstar = fr_star
|
| 533 |
+
self._k_d = MM
|
| 534 |
+
self._f_d = -(self._fr - nonMM)
|
| 535 |
+
return fr_star
|
| 536 |
+
|
| 537 |
+
def to_linearizer(self, linear_solver='LU'):
|
| 538 |
+
"""Returns an instance of the Linearizer class, initiated from the
|
| 539 |
+
data in the KanesMethod class. This may be more desirable than using
|
| 540 |
+
the linearize class method, as the Linearizer object will allow more
|
| 541 |
+
efficient recalculation (i.e. about varying operating points).
|
| 542 |
+
|
| 543 |
+
Parameters
|
| 544 |
+
==========
|
| 545 |
+
linear_solver : str, callable
|
| 546 |
+
Method used to solve the several symbolic linear systems of the
|
| 547 |
+
form ``A*x=b`` in the linearization process. If a string is
|
| 548 |
+
supplied, it should be a valid method that can be used with the
|
| 549 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 550 |
+
supplied, it should have the format ``x = f(A, b)``, where it
|
| 551 |
+
solves the equations and returns the solution. The default is
|
| 552 |
+
``'LU'`` which corresponds to SymPy's ``A.LUsolve(b)``.
|
| 553 |
+
``LUsolve()`` is fast to compute but will often result in
|
| 554 |
+
divide-by-zero and thus ``nan`` results.
|
| 555 |
+
|
| 556 |
+
Returns
|
| 557 |
+
=======
|
| 558 |
+
Linearizer
|
| 559 |
+
An instantiated
|
| 560 |
+
:class:`sympy.physics.mechanics.linearize.Linearizer`.
|
| 561 |
+
|
| 562 |
+
"""
|
| 563 |
+
|
| 564 |
+
if (self._fr is None) or (self._frstar is None):
|
| 565 |
+
raise ValueError('Need to compute Fr, Fr* first.')
|
| 566 |
+
|
| 567 |
+
# Get required equation components. The Kane's method class breaks
|
| 568 |
+
# these into pieces. Need to reassemble
|
| 569 |
+
f_c = self._f_h
|
| 570 |
+
if self._f_nh and self._k_nh:
|
| 571 |
+
f_v = self._f_nh + self._k_nh*Matrix(self.u)
|
| 572 |
+
else:
|
| 573 |
+
f_v = Matrix()
|
| 574 |
+
if self._f_dnh and self._k_dnh:
|
| 575 |
+
f_a = self._f_dnh + self._k_dnh*Matrix(self._udot)
|
| 576 |
+
else:
|
| 577 |
+
f_a = Matrix()
|
| 578 |
+
# Dicts to sub to zero, for splitting up expressions
|
| 579 |
+
u_zero = dict.fromkeys(self.u, 0)
|
| 580 |
+
ud_zero = dict.fromkeys(self._udot, 0)
|
| 581 |
+
qd_zero = dict.fromkeys(self._qdot, 0)
|
| 582 |
+
qd_u_zero = dict.fromkeys(Matrix([self._qdot, self.u]), 0)
|
| 583 |
+
# Break the kinematic differential eqs apart into f_0 and f_1
|
| 584 |
+
f_0 = msubs(self._f_k, u_zero) + self._k_kqdot*Matrix(self._qdot)
|
| 585 |
+
f_1 = msubs(self._f_k, qd_zero) + self._k_ku*Matrix(self.u)
|
| 586 |
+
# Break the dynamic differential eqs into f_2 and f_3
|
| 587 |
+
f_2 = msubs(self._frstar, qd_u_zero)
|
| 588 |
+
f_3 = msubs(self._frstar, ud_zero) + self._fr
|
| 589 |
+
f_4 = zeros(len(f_2), 1)
|
| 590 |
+
|
| 591 |
+
# Get the required vector components
|
| 592 |
+
q = self.q
|
| 593 |
+
u = self.u
|
| 594 |
+
if self._qdep:
|
| 595 |
+
q_i = q[:-len(self._qdep)]
|
| 596 |
+
else:
|
| 597 |
+
q_i = q
|
| 598 |
+
q_d = self._qdep
|
| 599 |
+
if self._udep:
|
| 600 |
+
u_i = u[:-len(self._udep)]
|
| 601 |
+
else:
|
| 602 |
+
u_i = u
|
| 603 |
+
u_d = self._udep
|
| 604 |
+
|
| 605 |
+
# Form dictionary to set auxiliary speeds & their derivatives to 0.
|
| 606 |
+
uaux = self._uaux
|
| 607 |
+
uauxdot = uaux.diff(dynamicsymbols._t)
|
| 608 |
+
uaux_zero = dict.fromkeys(Matrix([uaux, uauxdot]), 0)
|
| 609 |
+
|
| 610 |
+
# Checking for dynamic symbols outside the dynamic differential
|
| 611 |
+
# equations; throws error if there is.
|
| 612 |
+
sym_list = set(Matrix([q, self._qdot, u, self._udot, uaux, uauxdot]))
|
| 613 |
+
if any(find_dynamicsymbols(i, sym_list) for i in [self._k_kqdot,
|
| 614 |
+
self._k_ku, self._f_k, self._k_dnh, self._f_dnh, self._k_d]):
|
| 615 |
+
raise ValueError('Cannot have dynamicsymbols outside dynamic \
|
| 616 |
+
forcing vector.')
|
| 617 |
+
|
| 618 |
+
# Find all other dynamic symbols, forming the forcing vector r.
|
| 619 |
+
# Sort r to make it canonical.
|
| 620 |
+
r = list(find_dynamicsymbols(msubs(self._f_d, uaux_zero), sym_list))
|
| 621 |
+
r.sort(key=default_sort_key)
|
| 622 |
+
|
| 623 |
+
# Check for any derivatives of variables in r that are also found in r.
|
| 624 |
+
for i in r:
|
| 625 |
+
if diff(i, dynamicsymbols._t) in r:
|
| 626 |
+
raise ValueError('Cannot have derivatives of specified \
|
| 627 |
+
quantities when linearizing forcing terms.')
|
| 628 |
+
return Linearizer(f_0, f_1, f_2, f_3, f_4, f_c, f_v, f_a, q, u, q_i,
|
| 629 |
+
q_d, u_i, u_d, r, linear_solver=linear_solver)
|
| 630 |
+
|
| 631 |
+
# TODO : Remove `new_method` after 1.1 has been released.
|
| 632 |
+
def linearize(self, *, new_method=None, linear_solver='LU', **kwargs):
|
| 633 |
+
""" Linearize the equations of motion about a symbolic operating point.
|
| 634 |
+
|
| 635 |
+
Parameters
|
| 636 |
+
==========
|
| 637 |
+
new_method
|
| 638 |
+
Deprecated, does nothing and will be removed.
|
| 639 |
+
linear_solver : str, callable
|
| 640 |
+
Method used to solve the several symbolic linear systems of the
|
| 641 |
+
form ``A*x=b`` in the linearization process. If a string is
|
| 642 |
+
supplied, it should be a valid method that can be used with the
|
| 643 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 644 |
+
supplied, it should have the format ``x = f(A, b)``, where it
|
| 645 |
+
solves the equations and returns the solution. The default is
|
| 646 |
+
``'LU'`` which corresponds to SymPy's ``A.LUsolve(b)``.
|
| 647 |
+
``LUsolve()`` is fast to compute but will often result in
|
| 648 |
+
divide-by-zero and thus ``nan`` results.
|
| 649 |
+
**kwargs
|
| 650 |
+
Extra keyword arguments are passed to
|
| 651 |
+
:meth:`sympy.physics.mechanics.linearize.Linearizer.linearize`.
|
| 652 |
+
|
| 653 |
+
Explanation
|
| 654 |
+
===========
|
| 655 |
+
|
| 656 |
+
If kwarg A_and_B is False (default), returns M, A, B, r for the
|
| 657 |
+
linearized form, M*[q', u']^T = A*[q_ind, u_ind]^T + B*r.
|
| 658 |
+
|
| 659 |
+
If kwarg A_and_B is True, returns A, B, r for the linearized form
|
| 660 |
+
dx = A*x + B*r, where x = [q_ind, u_ind]^T. Note that this is
|
| 661 |
+
computationally intensive if there are many symbolic parameters. For
|
| 662 |
+
this reason, it may be more desirable to use the default A_and_B=False,
|
| 663 |
+
returning M, A, and B. Values may then be substituted in to these
|
| 664 |
+
matrices, and the state space form found as
|
| 665 |
+
A = P.T*M.inv()*A, B = P.T*M.inv()*B, where P = Linearizer.perm_mat.
|
| 666 |
+
|
| 667 |
+
In both cases, r is found as all dynamicsymbols in the equations of
|
| 668 |
+
motion that are not part of q, u, q', or u'. They are sorted in
|
| 669 |
+
canonical form.
|
| 670 |
+
|
| 671 |
+
The operating points may be also entered using the ``op_point`` kwarg.
|
| 672 |
+
This takes a dictionary of {symbol: value}, or a an iterable of such
|
| 673 |
+
dictionaries. The values may be numeric or symbolic. The more values
|
| 674 |
+
you can specify beforehand, the faster this computation will run.
|
| 675 |
+
|
| 676 |
+
For more documentation, please see the ``Linearizer`` class.
|
| 677 |
+
|
| 678 |
+
"""
|
| 679 |
+
|
| 680 |
+
linearizer = self.to_linearizer(linear_solver=linear_solver)
|
| 681 |
+
result = linearizer.linearize(**kwargs)
|
| 682 |
+
return result + (linearizer.r,)
|
| 683 |
+
|
| 684 |
+
def kanes_equations(self, bodies=None, loads=None):
|
| 685 |
+
""" Method to form Kane's equations, Fr + Fr* = 0.
|
| 686 |
+
|
| 687 |
+
Explanation
|
| 688 |
+
===========
|
| 689 |
+
|
| 690 |
+
Returns (Fr, Fr*). In the case where auxiliary generalized speeds are
|
| 691 |
+
present (say, s auxiliary speeds, o generalized speeds, and m motion
|
| 692 |
+
constraints) the length of the returned vectors will be o - m + s in
|
| 693 |
+
length. The first o - m equations will be the constrained Kane's
|
| 694 |
+
equations, then the s auxiliary Kane's equations. These auxiliary
|
| 695 |
+
equations can be accessed with the auxiliary_eqs property.
|
| 696 |
+
|
| 697 |
+
Parameters
|
| 698 |
+
==========
|
| 699 |
+
|
| 700 |
+
bodies : iterable
|
| 701 |
+
An iterable of all RigidBody's and Particle's in the system.
|
| 702 |
+
A system must have at least one body.
|
| 703 |
+
loads : iterable
|
| 704 |
+
Takes in an iterable of (Particle, Vector) or (ReferenceFrame, Vector)
|
| 705 |
+
tuples which represent the force at a point or torque on a frame.
|
| 706 |
+
Must be either a non-empty iterable of tuples or None which corresponds
|
| 707 |
+
to a system with no constraints.
|
| 708 |
+
"""
|
| 709 |
+
if bodies is None:
|
| 710 |
+
bodies = self.bodies
|
| 711 |
+
if loads is None and self._forcelist is not None:
|
| 712 |
+
loads = self._forcelist
|
| 713 |
+
if loads == []:
|
| 714 |
+
loads = None
|
| 715 |
+
if not self._k_kqdot:
|
| 716 |
+
raise AttributeError('Create an instance of KanesMethod with '
|
| 717 |
+
'kinematic differential equations to use this method.')
|
| 718 |
+
fr = self._form_fr(loads)
|
| 719 |
+
frstar = self._form_frstar(bodies)
|
| 720 |
+
if self._uaux:
|
| 721 |
+
if not self._udep:
|
| 722 |
+
km = KanesMethod(self._inertial, self.q, self._uaux,
|
| 723 |
+
u_auxiliary=self._uaux, constraint_solver=self._constraint_solver)
|
| 724 |
+
else:
|
| 725 |
+
km = KanesMethod(self._inertial, self.q, self._uaux,
|
| 726 |
+
u_auxiliary=self._uaux, u_dependent=self._udep,
|
| 727 |
+
velocity_constraints=(self._k_nh * self.u +
|
| 728 |
+
self._f_nh),
|
| 729 |
+
acceleration_constraints=(self._k_dnh * self._udot +
|
| 730 |
+
self._f_dnh),
|
| 731 |
+
constraint_solver=self._constraint_solver
|
| 732 |
+
)
|
| 733 |
+
km._qdot_u_map = self._qdot_u_map
|
| 734 |
+
self._km = km
|
| 735 |
+
fraux = km._form_fr(loads)
|
| 736 |
+
frstaraux = km._form_frstar(bodies)
|
| 737 |
+
self._aux_eq = fraux + frstaraux
|
| 738 |
+
self._fr = fr.col_join(fraux)
|
| 739 |
+
self._frstar = frstar.col_join(frstaraux)
|
| 740 |
+
return (self._fr, self._frstar)
|
| 741 |
+
|
| 742 |
+
def _form_eoms(self):
|
| 743 |
+
fr, frstar = self.kanes_equations(self.bodylist, self.forcelist)
|
| 744 |
+
return fr + frstar
|
| 745 |
+
|
| 746 |
+
def rhs(self, inv_method=None):
|
| 747 |
+
"""Returns the system's equations of motion in first order form. The
|
| 748 |
+
output is the right hand side of::
|
| 749 |
+
|
| 750 |
+
x' = |q'| =: f(q, u, r, p, t)
|
| 751 |
+
|u'|
|
| 752 |
+
|
| 753 |
+
The right hand side is what is needed by most numerical ODE
|
| 754 |
+
integrators.
|
| 755 |
+
|
| 756 |
+
Parameters
|
| 757 |
+
==========
|
| 758 |
+
|
| 759 |
+
inv_method : str
|
| 760 |
+
The specific sympy inverse matrix calculation method to use. For a
|
| 761 |
+
list of valid methods, see
|
| 762 |
+
:meth:`~sympy.matrices.matrixbase.MatrixBase.inv`
|
| 763 |
+
|
| 764 |
+
"""
|
| 765 |
+
rhs = zeros(len(self.q) + len(self.u), 1)
|
| 766 |
+
kdes = self.kindiffdict()
|
| 767 |
+
for i, q_i in enumerate(self.q):
|
| 768 |
+
rhs[i] = kdes[q_i.diff()]
|
| 769 |
+
|
| 770 |
+
if inv_method is None:
|
| 771 |
+
rhs[len(self.q):, 0] = self.mass_matrix.LUsolve(self.forcing)
|
| 772 |
+
else:
|
| 773 |
+
rhs[len(self.q):, 0] = (self.mass_matrix.inv(inv_method,
|
| 774 |
+
try_block_diag=True) *
|
| 775 |
+
self.forcing)
|
| 776 |
+
|
| 777 |
+
return rhs
|
| 778 |
+
|
| 779 |
+
def kindiffdict(self):
|
| 780 |
+
"""Returns a dictionary mapping q' to u."""
|
| 781 |
+
if not self._qdot_u_map:
|
| 782 |
+
raise AttributeError('Create an instance of KanesMethod with '
|
| 783 |
+
'kinematic differential equations to use this method.')
|
| 784 |
+
return self._qdot_u_map
|
| 785 |
+
|
| 786 |
+
@property
|
| 787 |
+
def auxiliary_eqs(self):
|
| 788 |
+
"""A matrix containing the auxiliary equations."""
|
| 789 |
+
if not self._fr or not self._frstar:
|
| 790 |
+
raise ValueError('Need to compute Fr, Fr* first.')
|
| 791 |
+
if not self._uaux:
|
| 792 |
+
raise ValueError('No auxiliary speeds have been declared.')
|
| 793 |
+
return self._aux_eq
|
| 794 |
+
|
| 795 |
+
@property
|
| 796 |
+
def mass_matrix_kin(self):
|
| 797 |
+
r"""The kinematic "mass matrix" $\mathbf{k_{k\dot{q}}}$ of the system."""
|
| 798 |
+
return self._k_kqdot if self.explicit_kinematics else self._k_kqdot_implicit
|
| 799 |
+
|
| 800 |
+
@property
|
| 801 |
+
def forcing_kin(self):
|
| 802 |
+
"""The kinematic "forcing vector" of the system."""
|
| 803 |
+
if self.explicit_kinematics:
|
| 804 |
+
return -(self._k_ku * Matrix(self.u) + self._f_k)
|
| 805 |
+
else:
|
| 806 |
+
return -(self._k_ku_implicit * Matrix(self.u) + self._f_k_implicit)
|
| 807 |
+
|
| 808 |
+
@property
|
| 809 |
+
def mass_matrix(self):
|
| 810 |
+
"""The mass matrix of the system."""
|
| 811 |
+
if not self._fr or not self._frstar:
|
| 812 |
+
raise ValueError('Need to compute Fr, Fr* first.')
|
| 813 |
+
return Matrix([self._k_d, self._k_dnh])
|
| 814 |
+
|
| 815 |
+
@property
|
| 816 |
+
def forcing(self):
|
| 817 |
+
"""The forcing vector of the system."""
|
| 818 |
+
if not self._fr or not self._frstar:
|
| 819 |
+
raise ValueError('Need to compute Fr, Fr* first.')
|
| 820 |
+
return -Matrix([self._f_d, self._f_dnh])
|
| 821 |
+
|
| 822 |
+
@property
|
| 823 |
+
def mass_matrix_full(self):
|
| 824 |
+
"""The mass matrix of the system, augmented by the kinematic
|
| 825 |
+
differential equations in explicit or implicit form."""
|
| 826 |
+
if not self._fr or not self._frstar:
|
| 827 |
+
raise ValueError('Need to compute Fr, Fr* first.')
|
| 828 |
+
o, n = len(self.u), len(self.q)
|
| 829 |
+
return (self.mass_matrix_kin.row_join(zeros(n, o))).col_join(
|
| 830 |
+
zeros(o, n).row_join(self.mass_matrix))
|
| 831 |
+
|
| 832 |
+
@property
|
| 833 |
+
def forcing_full(self):
|
| 834 |
+
"""The forcing vector of the system, augmented by the kinematic
|
| 835 |
+
differential equations in explicit or implicit form."""
|
| 836 |
+
return Matrix([self.forcing_kin, self.forcing])
|
| 837 |
+
|
| 838 |
+
@property
|
| 839 |
+
def q(self):
|
| 840 |
+
return self._q
|
| 841 |
+
|
| 842 |
+
@property
|
| 843 |
+
def u(self):
|
| 844 |
+
return self._u
|
| 845 |
+
|
| 846 |
+
@property
|
| 847 |
+
def bodylist(self):
|
| 848 |
+
return self._bodylist
|
| 849 |
+
|
| 850 |
+
@property
|
| 851 |
+
def forcelist(self):
|
| 852 |
+
return self._forcelist
|
| 853 |
+
|
| 854 |
+
@property
|
| 855 |
+
def bodies(self):
|
| 856 |
+
return self._bodylist
|
| 857 |
+
|
| 858 |
+
@property
|
| 859 |
+
def loads(self):
|
| 860 |
+
return self._forcelist
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/lagrange.py
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import diff, zeros, Matrix, eye, sympify
|
| 2 |
+
from sympy.core.sorting import default_sort_key
|
| 3 |
+
from sympy.physics.vector import dynamicsymbols, ReferenceFrame
|
| 4 |
+
from sympy.physics.mechanics.method import _Methods
|
| 5 |
+
from sympy.physics.mechanics.functions import (
|
| 6 |
+
find_dynamicsymbols, msubs, _f_list_parser, _validate_coordinates)
|
| 7 |
+
from sympy.physics.mechanics.linearize import Linearizer
|
| 8 |
+
from sympy.utilities.iterables import iterable
|
| 9 |
+
|
| 10 |
+
__all__ = ['LagrangesMethod']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LagrangesMethod(_Methods):
|
| 14 |
+
"""Lagrange's method object.
|
| 15 |
+
|
| 16 |
+
Explanation
|
| 17 |
+
===========
|
| 18 |
+
|
| 19 |
+
This object generates the equations of motion in a two step procedure. The
|
| 20 |
+
first step involves the initialization of LagrangesMethod by supplying the
|
| 21 |
+
Lagrangian and the generalized coordinates, at the bare minimum. If there
|
| 22 |
+
are any constraint equations, they can be supplied as keyword arguments.
|
| 23 |
+
The Lagrange multipliers are automatically generated and are equal in
|
| 24 |
+
number to the constraint equations. Similarly any non-conservative forces
|
| 25 |
+
can be supplied in an iterable (as described below and also shown in the
|
| 26 |
+
example) along with a ReferenceFrame. This is also discussed further in the
|
| 27 |
+
__init__ method.
|
| 28 |
+
|
| 29 |
+
Attributes
|
| 30 |
+
==========
|
| 31 |
+
|
| 32 |
+
q, u : Matrix
|
| 33 |
+
Matrices of the generalized coordinates and speeds
|
| 34 |
+
loads : iterable
|
| 35 |
+
Iterable of (Point, vector) or (ReferenceFrame, vector) tuples
|
| 36 |
+
describing the forces on the system.
|
| 37 |
+
bodies : iterable
|
| 38 |
+
Iterable containing the rigid bodies and particles of the system.
|
| 39 |
+
mass_matrix : Matrix
|
| 40 |
+
The system's mass matrix
|
| 41 |
+
forcing : Matrix
|
| 42 |
+
The system's forcing vector
|
| 43 |
+
mass_matrix_full : Matrix
|
| 44 |
+
The "mass matrix" for the qdot's, qdoubledot's, and the
|
| 45 |
+
lagrange multipliers (lam)
|
| 46 |
+
forcing_full : Matrix
|
| 47 |
+
The forcing vector for the qdot's, qdoubledot's and
|
| 48 |
+
lagrange multipliers (lam)
|
| 49 |
+
|
| 50 |
+
Examples
|
| 51 |
+
========
|
| 52 |
+
|
| 53 |
+
This is a simple example for a one degree of freedom translational
|
| 54 |
+
spring-mass-damper.
|
| 55 |
+
|
| 56 |
+
In this example, we first need to do the kinematics.
|
| 57 |
+
This involves creating generalized coordinates and their derivatives.
|
| 58 |
+
Then we create a point and set its velocity in a frame.
|
| 59 |
+
|
| 60 |
+
>>> from sympy.physics.mechanics import LagrangesMethod, Lagrangian
|
| 61 |
+
>>> from sympy.physics.mechanics import ReferenceFrame, Particle, Point
|
| 62 |
+
>>> from sympy.physics.mechanics import dynamicsymbols
|
| 63 |
+
>>> from sympy import symbols
|
| 64 |
+
>>> q = dynamicsymbols('q')
|
| 65 |
+
>>> qd = dynamicsymbols('q', 1)
|
| 66 |
+
>>> m, k, b = symbols('m k b')
|
| 67 |
+
>>> N = ReferenceFrame('N')
|
| 68 |
+
>>> P = Point('P')
|
| 69 |
+
>>> P.set_vel(N, qd * N.x)
|
| 70 |
+
|
| 71 |
+
We need to then prepare the information as required by LagrangesMethod to
|
| 72 |
+
generate equations of motion.
|
| 73 |
+
First we create the Particle, which has a point attached to it.
|
| 74 |
+
Following this the lagrangian is created from the kinetic and potential
|
| 75 |
+
energies.
|
| 76 |
+
Then, an iterable of nonconservative forces/torques must be constructed,
|
| 77 |
+
where each item is a (Point, Vector) or (ReferenceFrame, Vector) tuple,
|
| 78 |
+
with the Vectors representing the nonconservative forces or torques.
|
| 79 |
+
|
| 80 |
+
>>> Pa = Particle('Pa', P, m)
|
| 81 |
+
>>> Pa.potential_energy = k * q**2 / 2.0
|
| 82 |
+
>>> L = Lagrangian(N, Pa)
|
| 83 |
+
>>> fl = [(P, -b * qd * N.x)]
|
| 84 |
+
|
| 85 |
+
Finally we can generate the equations of motion.
|
| 86 |
+
First we create the LagrangesMethod object. To do this one must supply
|
| 87 |
+
the Lagrangian, and the generalized coordinates. The constraint equations,
|
| 88 |
+
the forcelist, and the inertial frame may also be provided, if relevant.
|
| 89 |
+
Next we generate Lagrange's equations of motion, such that:
|
| 90 |
+
Lagrange's equations of motion = 0.
|
| 91 |
+
We have the equations of motion at this point.
|
| 92 |
+
|
| 93 |
+
>>> l = LagrangesMethod(L, [q], forcelist = fl, frame = N)
|
| 94 |
+
>>> print(l.form_lagranges_equations())
|
| 95 |
+
Matrix([[b*Derivative(q(t), t) + 1.0*k*q(t) + m*Derivative(q(t), (t, 2))]])
|
| 96 |
+
|
| 97 |
+
We can also solve for the states using the 'rhs' method.
|
| 98 |
+
|
| 99 |
+
>>> print(l.rhs())
|
| 100 |
+
Matrix([[Derivative(q(t), t)], [(-b*Derivative(q(t), t) - 1.0*k*q(t))/m]])
|
| 101 |
+
|
| 102 |
+
Please refer to the docstrings on each method for more details.
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
def __init__(self, Lagrangian, qs, forcelist=None, bodies=None, frame=None,
|
| 106 |
+
hol_coneqs=None, nonhol_coneqs=None):
|
| 107 |
+
"""Supply the following for the initialization of LagrangesMethod.
|
| 108 |
+
|
| 109 |
+
Lagrangian : Sympifyable
|
| 110 |
+
|
| 111 |
+
qs : array_like
|
| 112 |
+
The generalized coordinates
|
| 113 |
+
|
| 114 |
+
hol_coneqs : array_like, optional
|
| 115 |
+
The holonomic constraint equations
|
| 116 |
+
|
| 117 |
+
nonhol_coneqs : array_like, optional
|
| 118 |
+
The nonholonomic constraint equations
|
| 119 |
+
|
| 120 |
+
forcelist : iterable, optional
|
| 121 |
+
Takes an iterable of (Point, Vector) or (ReferenceFrame, Vector)
|
| 122 |
+
tuples which represent the force at a point or torque on a frame.
|
| 123 |
+
This feature is primarily to account for the nonconservative forces
|
| 124 |
+
and/or moments.
|
| 125 |
+
|
| 126 |
+
bodies : iterable, optional
|
| 127 |
+
Takes an iterable containing the rigid bodies and particles of the
|
| 128 |
+
system.
|
| 129 |
+
|
| 130 |
+
frame : ReferenceFrame, optional
|
| 131 |
+
Supply the inertial frame. This is used to determine the
|
| 132 |
+
generalized forces due to non-conservative forces.
|
| 133 |
+
"""
|
| 134 |
+
|
| 135 |
+
self._L = Matrix([sympify(Lagrangian)])
|
| 136 |
+
self.eom = None
|
| 137 |
+
self._m_cd = Matrix() # Mass Matrix of differentiated coneqs
|
| 138 |
+
self._m_d = Matrix() # Mass Matrix of dynamic equations
|
| 139 |
+
self._f_cd = Matrix() # Forcing part of the diff coneqs
|
| 140 |
+
self._f_d = Matrix() # Forcing part of the dynamic equations
|
| 141 |
+
self.lam_coeffs = Matrix() # The coeffecients of the multipliers
|
| 142 |
+
|
| 143 |
+
forcelist = forcelist if forcelist else []
|
| 144 |
+
if not iterable(forcelist):
|
| 145 |
+
raise TypeError('Force pairs must be supplied in an iterable.')
|
| 146 |
+
self._forcelist = forcelist
|
| 147 |
+
if frame and not isinstance(frame, ReferenceFrame):
|
| 148 |
+
raise TypeError('frame must be a valid ReferenceFrame')
|
| 149 |
+
self._bodies = bodies
|
| 150 |
+
self.inertial = frame
|
| 151 |
+
|
| 152 |
+
self.lam_vec = Matrix()
|
| 153 |
+
|
| 154 |
+
self._term1 = Matrix()
|
| 155 |
+
self._term2 = Matrix()
|
| 156 |
+
self._term3 = Matrix()
|
| 157 |
+
self._term4 = Matrix()
|
| 158 |
+
|
| 159 |
+
# Creating the qs, qdots and qdoubledots
|
| 160 |
+
if not iterable(qs):
|
| 161 |
+
raise TypeError('Generalized coordinates must be an iterable')
|
| 162 |
+
self._q = Matrix(qs)
|
| 163 |
+
self._qdots = self.q.diff(dynamicsymbols._t)
|
| 164 |
+
self._qdoubledots = self._qdots.diff(dynamicsymbols._t)
|
| 165 |
+
_validate_coordinates(self.q)
|
| 166 |
+
|
| 167 |
+
mat_build = lambda x: Matrix(x) if x else Matrix()
|
| 168 |
+
hol_coneqs = mat_build(hol_coneqs)
|
| 169 |
+
nonhol_coneqs = mat_build(nonhol_coneqs)
|
| 170 |
+
self.coneqs = Matrix([hol_coneqs.diff(dynamicsymbols._t),
|
| 171 |
+
nonhol_coneqs])
|
| 172 |
+
self._hol_coneqs = hol_coneqs
|
| 173 |
+
|
| 174 |
+
def form_lagranges_equations(self):
|
| 175 |
+
"""Method to form Lagrange's equations of motion.
|
| 176 |
+
|
| 177 |
+
Returns a vector of equations of motion using Lagrange's equations of
|
| 178 |
+
the second kind.
|
| 179 |
+
"""
|
| 180 |
+
|
| 181 |
+
qds = self._qdots
|
| 182 |
+
qdd_zero = dict.fromkeys(self._qdoubledots, 0)
|
| 183 |
+
n = len(self.q)
|
| 184 |
+
|
| 185 |
+
# Internally we represent the EOM as four terms:
|
| 186 |
+
# EOM = term1 - term2 - term3 - term4 = 0
|
| 187 |
+
|
| 188 |
+
# First term
|
| 189 |
+
self._term1 = self._L.jacobian(qds)
|
| 190 |
+
self._term1 = self._term1.diff(dynamicsymbols._t).T
|
| 191 |
+
|
| 192 |
+
# Second term
|
| 193 |
+
self._term2 = self._L.jacobian(self.q).T
|
| 194 |
+
|
| 195 |
+
# Third term
|
| 196 |
+
if self.coneqs:
|
| 197 |
+
coneqs = self.coneqs
|
| 198 |
+
m = len(coneqs)
|
| 199 |
+
# Creating the multipliers
|
| 200 |
+
self.lam_vec = Matrix(dynamicsymbols('lam1:' + str(m + 1)))
|
| 201 |
+
self.lam_coeffs = -coneqs.jacobian(qds)
|
| 202 |
+
self._term3 = self.lam_coeffs.T * self.lam_vec
|
| 203 |
+
# Extracting the coeffecients of the qdds from the diff coneqs
|
| 204 |
+
diffconeqs = coneqs.diff(dynamicsymbols._t)
|
| 205 |
+
self._m_cd = diffconeqs.jacobian(self._qdoubledots)
|
| 206 |
+
# The remaining terms i.e. the 'forcing' terms in diff coneqs
|
| 207 |
+
self._f_cd = -diffconeqs.subs(qdd_zero)
|
| 208 |
+
else:
|
| 209 |
+
self._term3 = zeros(n, 1)
|
| 210 |
+
|
| 211 |
+
# Fourth term
|
| 212 |
+
if self.forcelist:
|
| 213 |
+
N = self.inertial
|
| 214 |
+
self._term4 = zeros(n, 1)
|
| 215 |
+
for i, qd in enumerate(qds):
|
| 216 |
+
flist = zip(*_f_list_parser(self.forcelist, N))
|
| 217 |
+
self._term4[i] = sum(v.diff(qd, N).dot(f) for (v, f) in flist)
|
| 218 |
+
else:
|
| 219 |
+
self._term4 = zeros(n, 1)
|
| 220 |
+
|
| 221 |
+
# Form the dynamic mass and forcing matrices
|
| 222 |
+
without_lam = self._term1 - self._term2 - self._term4
|
| 223 |
+
self._m_d = without_lam.jacobian(self._qdoubledots)
|
| 224 |
+
self._f_d = -without_lam.subs(qdd_zero)
|
| 225 |
+
|
| 226 |
+
# Form the EOM
|
| 227 |
+
self.eom = without_lam - self._term3
|
| 228 |
+
return self.eom
|
| 229 |
+
|
| 230 |
+
def _form_eoms(self):
|
| 231 |
+
return self.form_lagranges_equations()
|
| 232 |
+
|
| 233 |
+
@property
|
| 234 |
+
def mass_matrix(self):
|
| 235 |
+
"""Returns the mass matrix, which is augmented by the Lagrange
|
| 236 |
+
multipliers, if necessary.
|
| 237 |
+
|
| 238 |
+
Explanation
|
| 239 |
+
===========
|
| 240 |
+
|
| 241 |
+
If the system is described by 'n' generalized coordinates and there are
|
| 242 |
+
no constraint equations then an n X n matrix is returned.
|
| 243 |
+
|
| 244 |
+
If there are 'n' generalized coordinates and 'm' constraint equations
|
| 245 |
+
have been supplied during initialization then an n X (n+m) matrix is
|
| 246 |
+
returned. The (n + m - 1)th and (n + m)th columns contain the
|
| 247 |
+
coefficients of the Lagrange multipliers.
|
| 248 |
+
"""
|
| 249 |
+
|
| 250 |
+
if self.eom is None:
|
| 251 |
+
raise ValueError('Need to compute the equations of motion first')
|
| 252 |
+
if self.coneqs:
|
| 253 |
+
return (self._m_d).row_join(self.lam_coeffs.T)
|
| 254 |
+
else:
|
| 255 |
+
return self._m_d
|
| 256 |
+
|
| 257 |
+
@property
|
| 258 |
+
def mass_matrix_full(self):
|
| 259 |
+
"""Augments the coefficients of qdots to the mass_matrix."""
|
| 260 |
+
|
| 261 |
+
if self.eom is None:
|
| 262 |
+
raise ValueError('Need to compute the equations of motion first')
|
| 263 |
+
n = len(self.q)
|
| 264 |
+
m = len(self.coneqs)
|
| 265 |
+
row1 = eye(n).row_join(zeros(n, n + m))
|
| 266 |
+
row2 = zeros(n, n).row_join(self.mass_matrix)
|
| 267 |
+
if self.coneqs:
|
| 268 |
+
row3 = zeros(m, n).row_join(self._m_cd).row_join(zeros(m, m))
|
| 269 |
+
return row1.col_join(row2).col_join(row3)
|
| 270 |
+
else:
|
| 271 |
+
return row1.col_join(row2)
|
| 272 |
+
|
| 273 |
+
@property
|
| 274 |
+
def forcing(self):
|
| 275 |
+
"""Returns the forcing vector from 'lagranges_equations' method."""
|
| 276 |
+
|
| 277 |
+
if self.eom is None:
|
| 278 |
+
raise ValueError('Need to compute the equations of motion first')
|
| 279 |
+
return self._f_d
|
| 280 |
+
|
| 281 |
+
@property
|
| 282 |
+
def forcing_full(self):
|
| 283 |
+
"""Augments qdots to the forcing vector above."""
|
| 284 |
+
|
| 285 |
+
if self.eom is None:
|
| 286 |
+
raise ValueError('Need to compute the equations of motion first')
|
| 287 |
+
if self.coneqs:
|
| 288 |
+
return self._qdots.col_join(self.forcing).col_join(self._f_cd)
|
| 289 |
+
else:
|
| 290 |
+
return self._qdots.col_join(self.forcing)
|
| 291 |
+
|
| 292 |
+
def to_linearizer(self, q_ind=None, qd_ind=None, q_dep=None, qd_dep=None,
|
| 293 |
+
linear_solver='LU'):
|
| 294 |
+
"""Returns an instance of the Linearizer class, initiated from the data
|
| 295 |
+
in the LagrangesMethod class. This may be more desirable than using the
|
| 296 |
+
linearize class method, as the Linearizer object will allow more
|
| 297 |
+
efficient recalculation (i.e. about varying operating points).
|
| 298 |
+
|
| 299 |
+
Parameters
|
| 300 |
+
==========
|
| 301 |
+
|
| 302 |
+
q_ind, qd_ind : array_like, optional
|
| 303 |
+
The independent generalized coordinates and speeds.
|
| 304 |
+
q_dep, qd_dep : array_like, optional
|
| 305 |
+
The dependent generalized coordinates and speeds.
|
| 306 |
+
linear_solver : str, callable
|
| 307 |
+
Method used to solve the several symbolic linear systems of the
|
| 308 |
+
form ``A*x=b`` in the linearization process. If a string is
|
| 309 |
+
supplied, it should be a valid method that can be used with the
|
| 310 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 311 |
+
supplied, it should have the format ``x = f(A, b)``, where it
|
| 312 |
+
solves the equations and returns the solution. The default is
|
| 313 |
+
``'LU'`` which corresponds to SymPy's ``A.LUsolve(b)``.
|
| 314 |
+
``LUsolve()`` is fast to compute but will often result in
|
| 315 |
+
divide-by-zero and thus ``nan`` results.
|
| 316 |
+
|
| 317 |
+
Returns
|
| 318 |
+
=======
|
| 319 |
+
Linearizer
|
| 320 |
+
An instantiated
|
| 321 |
+
:class:`sympy.physics.mechanics.linearize.Linearizer`.
|
| 322 |
+
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
# Compose vectors
|
| 326 |
+
t = dynamicsymbols._t
|
| 327 |
+
q = self.q
|
| 328 |
+
u = self._qdots
|
| 329 |
+
ud = u.diff(t)
|
| 330 |
+
# Get vector of lagrange multipliers
|
| 331 |
+
lams = self.lam_vec
|
| 332 |
+
|
| 333 |
+
mat_build = lambda x: Matrix(x) if x else Matrix()
|
| 334 |
+
q_i = mat_build(q_ind)
|
| 335 |
+
q_d = mat_build(q_dep)
|
| 336 |
+
u_i = mat_build(qd_ind)
|
| 337 |
+
u_d = mat_build(qd_dep)
|
| 338 |
+
|
| 339 |
+
# Compose general form equations
|
| 340 |
+
f_c = self._hol_coneqs
|
| 341 |
+
f_v = self.coneqs
|
| 342 |
+
f_a = f_v.diff(t)
|
| 343 |
+
f_0 = u
|
| 344 |
+
f_1 = -u
|
| 345 |
+
f_2 = self._term1
|
| 346 |
+
f_3 = -(self._term2 + self._term4)
|
| 347 |
+
f_4 = -self._term3
|
| 348 |
+
|
| 349 |
+
# Check that there are an appropriate number of independent and
|
| 350 |
+
# dependent coordinates
|
| 351 |
+
if len(q_d) != len(f_c) or len(u_d) != len(f_v):
|
| 352 |
+
raise ValueError(("Must supply {:} dependent coordinates, and " +
|
| 353 |
+
"{:} dependent speeds").format(len(f_c), len(f_v)))
|
| 354 |
+
if set(Matrix([q_i, q_d])) != set(q):
|
| 355 |
+
raise ValueError("Must partition q into q_ind and q_dep, with " +
|
| 356 |
+
"no extra or missing symbols.")
|
| 357 |
+
if set(Matrix([u_i, u_d])) != set(u):
|
| 358 |
+
raise ValueError("Must partition qd into qd_ind and qd_dep, " +
|
| 359 |
+
"with no extra or missing symbols.")
|
| 360 |
+
|
| 361 |
+
# Find all other dynamic symbols, forming the forcing vector r.
|
| 362 |
+
# Sort r to make it canonical.
|
| 363 |
+
insyms = set(Matrix([q, u, ud, lams]))
|
| 364 |
+
r = list(find_dynamicsymbols(f_3, insyms))
|
| 365 |
+
r.sort(key=default_sort_key)
|
| 366 |
+
# Check for any derivatives of variables in r that are also found in r.
|
| 367 |
+
for i in r:
|
| 368 |
+
if diff(i, dynamicsymbols._t) in r:
|
| 369 |
+
raise ValueError('Cannot have derivatives of specified \
|
| 370 |
+
quantities when linearizing forcing terms.')
|
| 371 |
+
|
| 372 |
+
return Linearizer(f_0, f_1, f_2, f_3, f_4, f_c, f_v, f_a, q, u, q_i,
|
| 373 |
+
q_d, u_i, u_d, r, lams, linear_solver=linear_solver)
|
| 374 |
+
|
| 375 |
+
def linearize(self, q_ind=None, qd_ind=None, q_dep=None, qd_dep=None,
|
| 376 |
+
linear_solver='LU', **kwargs):
|
| 377 |
+
"""Linearize the equations of motion about a symbolic operating point.
|
| 378 |
+
|
| 379 |
+
Parameters
|
| 380 |
+
==========
|
| 381 |
+
linear_solver : str, callable
|
| 382 |
+
Method used to solve the several symbolic linear systems of the
|
| 383 |
+
form ``A*x=b`` in the linearization process. If a string is
|
| 384 |
+
supplied, it should be a valid method that can be used with the
|
| 385 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 386 |
+
supplied, it should have the format ``x = f(A, b)``, where it
|
| 387 |
+
solves the equations and returns the solution. The default is
|
| 388 |
+
``'LU'`` which corresponds to SymPy's ``A.LUsolve(b)``.
|
| 389 |
+
``LUsolve()`` is fast to compute but will often result in
|
| 390 |
+
divide-by-zero and thus ``nan`` results.
|
| 391 |
+
**kwargs
|
| 392 |
+
Extra keyword arguments are passed to
|
| 393 |
+
:meth:`sympy.physics.mechanics.linearize.Linearizer.linearize`.
|
| 394 |
+
|
| 395 |
+
Explanation
|
| 396 |
+
===========
|
| 397 |
+
|
| 398 |
+
If kwarg A_and_B is False (default), returns M, A, B, r for the
|
| 399 |
+
linearized form, M*[q', u']^T = A*[q_ind, u_ind]^T + B*r.
|
| 400 |
+
|
| 401 |
+
If kwarg A_and_B is True, returns A, B, r for the linearized form
|
| 402 |
+
dx = A*x + B*r, where x = [q_ind, u_ind]^T. Note that this is
|
| 403 |
+
computationally intensive if there are many symbolic parameters. For
|
| 404 |
+
this reason, it may be more desirable to use the default A_and_B=False,
|
| 405 |
+
returning M, A, and B. Values may then be substituted in to these
|
| 406 |
+
matrices, and the state space form found as
|
| 407 |
+
A = P.T*M.inv()*A, B = P.T*M.inv()*B, where P = Linearizer.perm_mat.
|
| 408 |
+
|
| 409 |
+
In both cases, r is found as all dynamicsymbols in the equations of
|
| 410 |
+
motion that are not part of q, u, q', or u'. They are sorted in
|
| 411 |
+
canonical form.
|
| 412 |
+
|
| 413 |
+
The operating points may be also entered using the ``op_point`` kwarg.
|
| 414 |
+
This takes a dictionary of {symbol: value}, or a an iterable of such
|
| 415 |
+
dictionaries. The values may be numeric or symbolic. The more values
|
| 416 |
+
you can specify beforehand, the faster this computation will run.
|
| 417 |
+
|
| 418 |
+
For more documentation, please see the ``Linearizer`` class."""
|
| 419 |
+
|
| 420 |
+
linearizer = self.to_linearizer(q_ind, qd_ind, q_dep, qd_dep,
|
| 421 |
+
linear_solver=linear_solver)
|
| 422 |
+
result = linearizer.linearize(**kwargs)
|
| 423 |
+
return result + (linearizer.r,)
|
| 424 |
+
|
| 425 |
+
def solve_multipliers(self, op_point=None, sol_type='dict'):
|
| 426 |
+
"""Solves for the values of the lagrange multipliers symbolically at
|
| 427 |
+
the specified operating point.
|
| 428 |
+
|
| 429 |
+
Parameters
|
| 430 |
+
==========
|
| 431 |
+
|
| 432 |
+
op_point : dict or iterable of dicts, optional
|
| 433 |
+
Point at which to solve at. The operating point is specified as
|
| 434 |
+
a dictionary or iterable of dictionaries of {symbol: value}. The
|
| 435 |
+
value may be numeric or symbolic itself.
|
| 436 |
+
|
| 437 |
+
sol_type : str, optional
|
| 438 |
+
Solution return type. Valid options are:
|
| 439 |
+
- 'dict': A dict of {symbol : value} (default)
|
| 440 |
+
- 'Matrix': An ordered column matrix of the solution
|
| 441 |
+
"""
|
| 442 |
+
|
| 443 |
+
# Determine number of multipliers
|
| 444 |
+
k = len(self.lam_vec)
|
| 445 |
+
if k == 0:
|
| 446 |
+
raise ValueError("System has no lagrange multipliers to solve for.")
|
| 447 |
+
# Compose dict of operating conditions
|
| 448 |
+
if isinstance(op_point, dict):
|
| 449 |
+
op_point_dict = op_point
|
| 450 |
+
elif iterable(op_point):
|
| 451 |
+
op_point_dict = {}
|
| 452 |
+
for op in op_point:
|
| 453 |
+
op_point_dict.update(op)
|
| 454 |
+
elif op_point is None:
|
| 455 |
+
op_point_dict = {}
|
| 456 |
+
else:
|
| 457 |
+
raise TypeError("op_point must be either a dictionary or an "
|
| 458 |
+
"iterable of dictionaries.")
|
| 459 |
+
# Compose the system to be solved
|
| 460 |
+
mass_matrix = self.mass_matrix.col_join(-self.lam_coeffs.row_join(
|
| 461 |
+
zeros(k, k)))
|
| 462 |
+
force_matrix = self.forcing.col_join(self._f_cd)
|
| 463 |
+
# Sub in the operating point
|
| 464 |
+
mass_matrix = msubs(mass_matrix, op_point_dict)
|
| 465 |
+
force_matrix = msubs(force_matrix, op_point_dict)
|
| 466 |
+
# Solve for the multipliers
|
| 467 |
+
sol_list = mass_matrix.LUsolve(-force_matrix)[-k:]
|
| 468 |
+
if sol_type == 'dict':
|
| 469 |
+
return dict(zip(self.lam_vec, sol_list))
|
| 470 |
+
elif sol_type == 'Matrix':
|
| 471 |
+
return Matrix(sol_list)
|
| 472 |
+
else:
|
| 473 |
+
raise ValueError("Unknown sol_type {:}.".format(sol_type))
|
| 474 |
+
|
| 475 |
+
def rhs(self, inv_method=None, **kwargs):
|
| 476 |
+
"""Returns equations that can be solved numerically.
|
| 477 |
+
|
| 478 |
+
Parameters
|
| 479 |
+
==========
|
| 480 |
+
|
| 481 |
+
inv_method : str
|
| 482 |
+
The specific sympy inverse matrix calculation method to use. For a
|
| 483 |
+
list of valid methods, see
|
| 484 |
+
:meth:`~sympy.matrices.matrixbase.MatrixBase.inv`
|
| 485 |
+
"""
|
| 486 |
+
|
| 487 |
+
if inv_method is None:
|
| 488 |
+
self._rhs = self.mass_matrix_full.LUsolve(self.forcing_full)
|
| 489 |
+
else:
|
| 490 |
+
self._rhs = (self.mass_matrix_full.inv(inv_method,
|
| 491 |
+
try_block_diag=True) * self.forcing_full)
|
| 492 |
+
return self._rhs
|
| 493 |
+
|
| 494 |
+
@property
|
| 495 |
+
def q(self):
|
| 496 |
+
return self._q
|
| 497 |
+
|
| 498 |
+
@property
|
| 499 |
+
def u(self):
|
| 500 |
+
return self._qdots
|
| 501 |
+
|
| 502 |
+
@property
|
| 503 |
+
def bodies(self):
|
| 504 |
+
return self._bodies
|
| 505 |
+
|
| 506 |
+
@property
|
| 507 |
+
def forcelist(self):
|
| 508 |
+
return self._forcelist
|
| 509 |
+
|
| 510 |
+
@property
|
| 511 |
+
def loads(self):
|
| 512 |
+
return self._forcelist
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/linearize.py
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['Linearizer']
|
| 2 |
+
|
| 3 |
+
from sympy import Matrix, eye, zeros
|
| 4 |
+
from sympy.core.symbol import Dummy
|
| 5 |
+
from sympy.utilities.iterables import flatten
|
| 6 |
+
from sympy.physics.vector import dynamicsymbols
|
| 7 |
+
from sympy.physics.mechanics.functions import msubs, _parse_linear_solver
|
| 8 |
+
|
| 9 |
+
from collections import namedtuple
|
| 10 |
+
from collections.abc import Iterable
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class Linearizer:
|
| 14 |
+
"""This object holds the general model form for a dynamic system. This
|
| 15 |
+
model is used for computing the linearized form of the system, while
|
| 16 |
+
properly dealing with constraints leading to dependent coordinates and
|
| 17 |
+
speeds. The notation and method is described in [1]_.
|
| 18 |
+
|
| 19 |
+
Attributes
|
| 20 |
+
==========
|
| 21 |
+
|
| 22 |
+
f_0, f_1, f_2, f_3, f_4, f_c, f_v, f_a : Matrix
|
| 23 |
+
Matrices holding the general system form.
|
| 24 |
+
q, u, r : Matrix
|
| 25 |
+
Matrices holding the generalized coordinates, speeds, and
|
| 26 |
+
input vectors.
|
| 27 |
+
q_i, u_i : Matrix
|
| 28 |
+
Matrices of the independent generalized coordinates and speeds.
|
| 29 |
+
q_d, u_d : Matrix
|
| 30 |
+
Matrices of the dependent generalized coordinates and speeds.
|
| 31 |
+
perm_mat : Matrix
|
| 32 |
+
Permutation matrix such that [q_ind, u_ind]^T = perm_mat*[q, u]^T
|
| 33 |
+
|
| 34 |
+
References
|
| 35 |
+
==========
|
| 36 |
+
|
| 37 |
+
.. [1] D. L. Peterson, G. Gede, and M. Hubbard, "Symbolic linearization of
|
| 38 |
+
equations of motion of constrained multibody systems," Multibody
|
| 39 |
+
Syst Dyn, vol. 33, no. 2, pp. 143-161, Feb. 2015, doi:
|
| 40 |
+
10.1007/s11044-014-9436-5.
|
| 41 |
+
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
def __init__(self, f_0, f_1, f_2, f_3, f_4, f_c, f_v, f_a, q, u, q_i=None,
|
| 45 |
+
q_d=None, u_i=None, u_d=None, r=None, lams=None,
|
| 46 |
+
linear_solver='LU'):
|
| 47 |
+
"""
|
| 48 |
+
Parameters
|
| 49 |
+
==========
|
| 50 |
+
|
| 51 |
+
f_0, f_1, f_2, f_3, f_4, f_c, f_v, f_a : array_like
|
| 52 |
+
System of equations holding the general system form.
|
| 53 |
+
Supply empty array or Matrix if the parameter
|
| 54 |
+
does not exist.
|
| 55 |
+
q : array_like
|
| 56 |
+
The generalized coordinates.
|
| 57 |
+
u : array_like
|
| 58 |
+
The generalized speeds
|
| 59 |
+
q_i, u_i : array_like, optional
|
| 60 |
+
The independent generalized coordinates and speeds.
|
| 61 |
+
q_d, u_d : array_like, optional
|
| 62 |
+
The dependent generalized coordinates and speeds.
|
| 63 |
+
r : array_like, optional
|
| 64 |
+
The input variables.
|
| 65 |
+
lams : array_like, optional
|
| 66 |
+
The lagrange multipliers
|
| 67 |
+
linear_solver : str, callable
|
| 68 |
+
Method used to solve the several symbolic linear systems of the
|
| 69 |
+
form ``A*x=b`` in the linearization process. If a string is
|
| 70 |
+
supplied, it should be a valid method that can be used with the
|
| 71 |
+
:meth:`sympy.matrices.matrixbase.MatrixBase.solve`. If a callable is
|
| 72 |
+
supplied, it should have the format ``x = f(A, b)``, where it
|
| 73 |
+
solves the equations and returns the solution. The default is
|
| 74 |
+
``'LU'`` which corresponds to SymPy's ``A.LUsolve(b)``.
|
| 75 |
+
``LUsolve()`` is fast to compute but will often result in
|
| 76 |
+
divide-by-zero and thus ``nan`` results.
|
| 77 |
+
|
| 78 |
+
"""
|
| 79 |
+
self.linear_solver = _parse_linear_solver(linear_solver)
|
| 80 |
+
|
| 81 |
+
# Generalized equation form
|
| 82 |
+
self.f_0 = Matrix(f_0)
|
| 83 |
+
self.f_1 = Matrix(f_1)
|
| 84 |
+
self.f_2 = Matrix(f_2)
|
| 85 |
+
self.f_3 = Matrix(f_3)
|
| 86 |
+
self.f_4 = Matrix(f_4)
|
| 87 |
+
self.f_c = Matrix(f_c)
|
| 88 |
+
self.f_v = Matrix(f_v)
|
| 89 |
+
self.f_a = Matrix(f_a)
|
| 90 |
+
|
| 91 |
+
# Generalized equation variables
|
| 92 |
+
self.q = Matrix(q)
|
| 93 |
+
self.u = Matrix(u)
|
| 94 |
+
none_handler = lambda x: Matrix(x) if x else Matrix()
|
| 95 |
+
self.q_i = none_handler(q_i)
|
| 96 |
+
self.q_d = none_handler(q_d)
|
| 97 |
+
self.u_i = none_handler(u_i)
|
| 98 |
+
self.u_d = none_handler(u_d)
|
| 99 |
+
self.r = none_handler(r)
|
| 100 |
+
self.lams = none_handler(lams)
|
| 101 |
+
|
| 102 |
+
# Derivatives of generalized equation variables
|
| 103 |
+
self._qd = self.q.diff(dynamicsymbols._t)
|
| 104 |
+
self._ud = self.u.diff(dynamicsymbols._t)
|
| 105 |
+
# If the user doesn't actually use generalized variables, and the
|
| 106 |
+
# qd and u vectors have any intersecting variables, this can cause
|
| 107 |
+
# problems. We'll fix this with some hackery, and Dummy variables
|
| 108 |
+
dup_vars = set(self._qd).intersection(self.u)
|
| 109 |
+
self._qd_dup = Matrix([var if var not in dup_vars else Dummy() for var
|
| 110 |
+
in self._qd])
|
| 111 |
+
|
| 112 |
+
# Derive dimesion terms
|
| 113 |
+
l = len(self.f_c)
|
| 114 |
+
m = len(self.f_v)
|
| 115 |
+
n = len(self.q)
|
| 116 |
+
o = len(self.u)
|
| 117 |
+
s = len(self.r)
|
| 118 |
+
k = len(self.lams)
|
| 119 |
+
dims = namedtuple('dims', ['l', 'm', 'n', 'o', 's', 'k'])
|
| 120 |
+
self._dims = dims(l, m, n, o, s, k)
|
| 121 |
+
|
| 122 |
+
self._Pq = None
|
| 123 |
+
self._Pqi = None
|
| 124 |
+
self._Pqd = None
|
| 125 |
+
self._Pu = None
|
| 126 |
+
self._Pui = None
|
| 127 |
+
self._Pud = None
|
| 128 |
+
self._C_0 = None
|
| 129 |
+
self._C_1 = None
|
| 130 |
+
self._C_2 = None
|
| 131 |
+
self.perm_mat = None
|
| 132 |
+
|
| 133 |
+
self._setup_done = False
|
| 134 |
+
|
| 135 |
+
def _setup(self):
|
| 136 |
+
# Calculations here only need to be run once. They are moved out of
|
| 137 |
+
# the __init__ method to increase the speed of Linearizer creation.
|
| 138 |
+
self._form_permutation_matrices()
|
| 139 |
+
self._form_block_matrices()
|
| 140 |
+
self._form_coefficient_matrices()
|
| 141 |
+
self._setup_done = True
|
| 142 |
+
|
| 143 |
+
def _form_permutation_matrices(self):
|
| 144 |
+
"""Form the permutation matrices Pq and Pu."""
|
| 145 |
+
|
| 146 |
+
# Extract dimension variables
|
| 147 |
+
l, m, n, o, s, k = self._dims
|
| 148 |
+
# Compute permutation matrices
|
| 149 |
+
if n != 0:
|
| 150 |
+
self._Pq = permutation_matrix(self.q, Matrix([self.q_i, self.q_d]))
|
| 151 |
+
if l > 0:
|
| 152 |
+
self._Pqi = self._Pq[:, :-l]
|
| 153 |
+
self._Pqd = self._Pq[:, -l:]
|
| 154 |
+
else:
|
| 155 |
+
self._Pqi = self._Pq
|
| 156 |
+
self._Pqd = Matrix()
|
| 157 |
+
if o != 0:
|
| 158 |
+
self._Pu = permutation_matrix(self.u, Matrix([self.u_i, self.u_d]))
|
| 159 |
+
if m > 0:
|
| 160 |
+
self._Pui = self._Pu[:, :-m]
|
| 161 |
+
self._Pud = self._Pu[:, -m:]
|
| 162 |
+
else:
|
| 163 |
+
self._Pui = self._Pu
|
| 164 |
+
self._Pud = Matrix()
|
| 165 |
+
# Compute combination permutation matrix for computing A and B
|
| 166 |
+
P_col1 = Matrix([self._Pqi, zeros(o + k, n - l)])
|
| 167 |
+
P_col2 = Matrix([zeros(n, o - m), self._Pui, zeros(k, o - m)])
|
| 168 |
+
if P_col1:
|
| 169 |
+
if P_col2:
|
| 170 |
+
self.perm_mat = P_col1.row_join(P_col2)
|
| 171 |
+
else:
|
| 172 |
+
self.perm_mat = P_col1
|
| 173 |
+
else:
|
| 174 |
+
self.perm_mat = P_col2
|
| 175 |
+
|
| 176 |
+
def _form_coefficient_matrices(self):
|
| 177 |
+
"""Form the coefficient matrices C_0, C_1, and C_2."""
|
| 178 |
+
|
| 179 |
+
# Extract dimension variables
|
| 180 |
+
l, m, n, o, s, k = self._dims
|
| 181 |
+
# Build up the coefficient matrices C_0, C_1, and C_2
|
| 182 |
+
# If there are configuration constraints (l > 0), form C_0 as normal.
|
| 183 |
+
# If not, C_0 is I_(nxn). Note that this works even if n=0
|
| 184 |
+
if l > 0:
|
| 185 |
+
f_c_jac_q = self.f_c.jacobian(self.q)
|
| 186 |
+
self._C_0 = (eye(n) - self._Pqd *
|
| 187 |
+
self.linear_solver(f_c_jac_q*self._Pqd,
|
| 188 |
+
f_c_jac_q))*self._Pqi
|
| 189 |
+
else:
|
| 190 |
+
self._C_0 = eye(n)
|
| 191 |
+
# If there are motion constraints (m > 0), form C_1 and C_2 as normal.
|
| 192 |
+
# If not, C_1 is 0, and C_2 is I_(oxo). Note that this works even if
|
| 193 |
+
# o = 0.
|
| 194 |
+
if m > 0:
|
| 195 |
+
f_v_jac_u = self.f_v.jacobian(self.u)
|
| 196 |
+
temp = f_v_jac_u * self._Pud
|
| 197 |
+
if n != 0:
|
| 198 |
+
f_v_jac_q = self.f_v.jacobian(self.q)
|
| 199 |
+
self._C_1 = -self._Pud * self.linear_solver(temp, f_v_jac_q)
|
| 200 |
+
else:
|
| 201 |
+
self._C_1 = zeros(o, n)
|
| 202 |
+
self._C_2 = (eye(o) - self._Pud *
|
| 203 |
+
self.linear_solver(temp, f_v_jac_u))*self._Pui
|
| 204 |
+
else:
|
| 205 |
+
self._C_1 = zeros(o, n)
|
| 206 |
+
self._C_2 = eye(o)
|
| 207 |
+
|
| 208 |
+
def _form_block_matrices(self):
|
| 209 |
+
"""Form the block matrices for composing M, A, and B."""
|
| 210 |
+
|
| 211 |
+
# Extract dimension variables
|
| 212 |
+
l, m, n, o, s, k = self._dims
|
| 213 |
+
# Block Matrix Definitions. These are only defined if under certain
|
| 214 |
+
# conditions. If undefined, an empty matrix is used instead
|
| 215 |
+
if n != 0:
|
| 216 |
+
self._M_qq = self.f_0.jacobian(self._qd)
|
| 217 |
+
self._A_qq = -(self.f_0 + self.f_1).jacobian(self.q)
|
| 218 |
+
else:
|
| 219 |
+
self._M_qq = Matrix()
|
| 220 |
+
self._A_qq = Matrix()
|
| 221 |
+
if n != 0 and m != 0:
|
| 222 |
+
self._M_uqc = self.f_a.jacobian(self._qd_dup)
|
| 223 |
+
self._A_uqc = -self.f_a.jacobian(self.q)
|
| 224 |
+
else:
|
| 225 |
+
self._M_uqc = Matrix()
|
| 226 |
+
self._A_uqc = Matrix()
|
| 227 |
+
if n != 0 and o - m + k != 0:
|
| 228 |
+
self._M_uqd = self.f_3.jacobian(self._qd_dup)
|
| 229 |
+
self._A_uqd = -(self.f_2 + self.f_3 + self.f_4).jacobian(self.q)
|
| 230 |
+
else:
|
| 231 |
+
self._M_uqd = Matrix()
|
| 232 |
+
self._A_uqd = Matrix()
|
| 233 |
+
if o != 0 and m != 0:
|
| 234 |
+
self._M_uuc = self.f_a.jacobian(self._ud)
|
| 235 |
+
self._A_uuc = -self.f_a.jacobian(self.u)
|
| 236 |
+
else:
|
| 237 |
+
self._M_uuc = Matrix()
|
| 238 |
+
self._A_uuc = Matrix()
|
| 239 |
+
if o != 0 and o - m + k != 0:
|
| 240 |
+
self._M_uud = self.f_2.jacobian(self._ud)
|
| 241 |
+
self._A_uud = -(self.f_2 + self.f_3).jacobian(self.u)
|
| 242 |
+
else:
|
| 243 |
+
self._M_uud = Matrix()
|
| 244 |
+
self._A_uud = Matrix()
|
| 245 |
+
if o != 0 and n != 0:
|
| 246 |
+
self._A_qu = -self.f_1.jacobian(self.u)
|
| 247 |
+
else:
|
| 248 |
+
self._A_qu = Matrix()
|
| 249 |
+
if k != 0 and o - m + k != 0:
|
| 250 |
+
self._M_uld = self.f_4.jacobian(self.lams)
|
| 251 |
+
else:
|
| 252 |
+
self._M_uld = Matrix()
|
| 253 |
+
if s != 0 and o - m + k != 0:
|
| 254 |
+
self._B_u = -self.f_3.jacobian(self.r)
|
| 255 |
+
else:
|
| 256 |
+
self._B_u = Matrix()
|
| 257 |
+
|
| 258 |
+
def linearize(self, op_point=None, A_and_B=False, simplify=False):
|
| 259 |
+
"""Linearize the system about the operating point. Note that
|
| 260 |
+
q_op, u_op, qd_op, ud_op must satisfy the equations of motion.
|
| 261 |
+
These may be either symbolic or numeric.
|
| 262 |
+
|
| 263 |
+
Parameters
|
| 264 |
+
==========
|
| 265 |
+
op_point : dict or iterable of dicts, optional
|
| 266 |
+
Dictionary or iterable of dictionaries containing the operating
|
| 267 |
+
point conditions for all or a subset of the generalized
|
| 268 |
+
coordinates, generalized speeds, and time derivatives of the
|
| 269 |
+
generalized speeds. These will be substituted into the linearized
|
| 270 |
+
system before the linearization is complete. Leave set to ``None``
|
| 271 |
+
if you want the operating point to be an arbitrary set of symbols.
|
| 272 |
+
Note that any reduction in symbols (whether substituted for numbers
|
| 273 |
+
or expressions with a common parameter) will result in faster
|
| 274 |
+
runtime.
|
| 275 |
+
A_and_B : bool, optional
|
| 276 |
+
If A_and_B=False (default), (M, A, B) is returned and of
|
| 277 |
+
A_and_B=True, (A, B) is returned. See below.
|
| 278 |
+
simplify : bool, optional
|
| 279 |
+
Determines if returned values are simplified before return.
|
| 280 |
+
For large expressions this may be time consuming. Default is False.
|
| 281 |
+
|
| 282 |
+
Returns
|
| 283 |
+
=======
|
| 284 |
+
M, A, B : Matrices, ``A_and_B=False``
|
| 285 |
+
Matrices from the implicit form:
|
| 286 |
+
``[M]*[q', u']^T = [A]*[q_ind, u_ind]^T + [B]*r``
|
| 287 |
+
A, B : Matrices, ``A_and_B=True``
|
| 288 |
+
Matrices from the explicit form:
|
| 289 |
+
``[q_ind', u_ind']^T = [A]*[q_ind, u_ind]^T + [B]*r``
|
| 290 |
+
|
| 291 |
+
Notes
|
| 292 |
+
=====
|
| 293 |
+
|
| 294 |
+
Note that the process of solving with A_and_B=True is computationally
|
| 295 |
+
intensive if there are many symbolic parameters. For this reason, it
|
| 296 |
+
may be more desirable to use the default A_and_B=False, returning M, A,
|
| 297 |
+
and B. More values may then be substituted in to these matrices later
|
| 298 |
+
on. The state space form can then be found as A = P.T*M.LUsolve(A), B =
|
| 299 |
+
P.T*M.LUsolve(B), where P = Linearizer.perm_mat.
|
| 300 |
+
|
| 301 |
+
"""
|
| 302 |
+
|
| 303 |
+
# Run the setup if needed:
|
| 304 |
+
if not self._setup_done:
|
| 305 |
+
self._setup()
|
| 306 |
+
|
| 307 |
+
# Compose dict of operating conditions
|
| 308 |
+
if isinstance(op_point, dict):
|
| 309 |
+
op_point_dict = op_point
|
| 310 |
+
elif isinstance(op_point, Iterable):
|
| 311 |
+
op_point_dict = {}
|
| 312 |
+
for op in op_point:
|
| 313 |
+
op_point_dict.update(op)
|
| 314 |
+
else:
|
| 315 |
+
op_point_dict = {}
|
| 316 |
+
|
| 317 |
+
# Extract dimension variables
|
| 318 |
+
l, m, n, o, s, k = self._dims
|
| 319 |
+
|
| 320 |
+
# Rename terms to shorten expressions
|
| 321 |
+
M_qq = self._M_qq
|
| 322 |
+
M_uqc = self._M_uqc
|
| 323 |
+
M_uqd = self._M_uqd
|
| 324 |
+
M_uuc = self._M_uuc
|
| 325 |
+
M_uud = self._M_uud
|
| 326 |
+
M_uld = self._M_uld
|
| 327 |
+
A_qq = self._A_qq
|
| 328 |
+
A_uqc = self._A_uqc
|
| 329 |
+
A_uqd = self._A_uqd
|
| 330 |
+
A_qu = self._A_qu
|
| 331 |
+
A_uuc = self._A_uuc
|
| 332 |
+
A_uud = self._A_uud
|
| 333 |
+
B_u = self._B_u
|
| 334 |
+
C_0 = self._C_0
|
| 335 |
+
C_1 = self._C_1
|
| 336 |
+
C_2 = self._C_2
|
| 337 |
+
|
| 338 |
+
# Build up Mass Matrix
|
| 339 |
+
# |M_qq 0_nxo 0_nxk|
|
| 340 |
+
# M = |M_uqc M_uuc 0_mxk|
|
| 341 |
+
# |M_uqd M_uud M_uld|
|
| 342 |
+
if o != 0:
|
| 343 |
+
col2 = Matrix([zeros(n, o), M_uuc, M_uud])
|
| 344 |
+
if k != 0:
|
| 345 |
+
col3 = Matrix([zeros(n + m, k), M_uld])
|
| 346 |
+
if n != 0:
|
| 347 |
+
col1 = Matrix([M_qq, M_uqc, M_uqd])
|
| 348 |
+
if o != 0 and k != 0:
|
| 349 |
+
M = col1.row_join(col2).row_join(col3)
|
| 350 |
+
elif o != 0:
|
| 351 |
+
M = col1.row_join(col2)
|
| 352 |
+
else:
|
| 353 |
+
M = col1
|
| 354 |
+
elif k != 0:
|
| 355 |
+
M = col2.row_join(col3)
|
| 356 |
+
else:
|
| 357 |
+
M = col2
|
| 358 |
+
M_eq = msubs(M, op_point_dict)
|
| 359 |
+
|
| 360 |
+
# Build up state coefficient matrix A
|
| 361 |
+
# |(A_qq + A_qu*C_1)*C_0 A_qu*C_2|
|
| 362 |
+
# A = |(A_uqc + A_uuc*C_1)*C_0 A_uuc*C_2|
|
| 363 |
+
# |(A_uqd + A_uud*C_1)*C_0 A_uud*C_2|
|
| 364 |
+
# Col 1 is only defined if n != 0
|
| 365 |
+
if n != 0:
|
| 366 |
+
r1c1 = A_qq
|
| 367 |
+
if o != 0:
|
| 368 |
+
r1c1 += (A_qu * C_1)
|
| 369 |
+
r1c1 = r1c1 * C_0
|
| 370 |
+
if m != 0:
|
| 371 |
+
r2c1 = A_uqc
|
| 372 |
+
if o != 0:
|
| 373 |
+
r2c1 += (A_uuc * C_1)
|
| 374 |
+
r2c1 = r2c1 * C_0
|
| 375 |
+
else:
|
| 376 |
+
r2c1 = Matrix()
|
| 377 |
+
if o - m + k != 0:
|
| 378 |
+
r3c1 = A_uqd
|
| 379 |
+
if o != 0:
|
| 380 |
+
r3c1 += (A_uud * C_1)
|
| 381 |
+
r3c1 = r3c1 * C_0
|
| 382 |
+
else:
|
| 383 |
+
r3c1 = Matrix()
|
| 384 |
+
col1 = Matrix([r1c1, r2c1, r3c1])
|
| 385 |
+
else:
|
| 386 |
+
col1 = Matrix()
|
| 387 |
+
# Col 2 is only defined if o != 0
|
| 388 |
+
if o != 0:
|
| 389 |
+
if n != 0:
|
| 390 |
+
r1c2 = A_qu * C_2
|
| 391 |
+
else:
|
| 392 |
+
r1c2 = Matrix()
|
| 393 |
+
if m != 0:
|
| 394 |
+
r2c2 = A_uuc * C_2
|
| 395 |
+
else:
|
| 396 |
+
r2c2 = Matrix()
|
| 397 |
+
if o - m + k != 0:
|
| 398 |
+
r3c2 = A_uud * C_2
|
| 399 |
+
else:
|
| 400 |
+
r3c2 = Matrix()
|
| 401 |
+
col2 = Matrix([r1c2, r2c2, r3c2])
|
| 402 |
+
else:
|
| 403 |
+
col2 = Matrix()
|
| 404 |
+
if col1:
|
| 405 |
+
if col2:
|
| 406 |
+
Amat = col1.row_join(col2)
|
| 407 |
+
else:
|
| 408 |
+
Amat = col1
|
| 409 |
+
else:
|
| 410 |
+
Amat = col2
|
| 411 |
+
Amat_eq = msubs(Amat, op_point_dict)
|
| 412 |
+
|
| 413 |
+
# Build up the B matrix if there are forcing variables
|
| 414 |
+
# |0_(n + m)xs|
|
| 415 |
+
# B = |B_u |
|
| 416 |
+
if s != 0 and o - m + k != 0:
|
| 417 |
+
Bmat = zeros(n + m, s).col_join(B_u)
|
| 418 |
+
Bmat_eq = msubs(Bmat, op_point_dict)
|
| 419 |
+
else:
|
| 420 |
+
Bmat_eq = Matrix()
|
| 421 |
+
|
| 422 |
+
# kwarg A_and_B indicates to return A, B for forming the equation
|
| 423 |
+
# dx = [A]x + [B]r, where x = [q_indnd, u_indnd]^T,
|
| 424 |
+
if A_and_B:
|
| 425 |
+
A_cont = self.perm_mat.T * self.linear_solver(M_eq, Amat_eq)
|
| 426 |
+
if Bmat_eq:
|
| 427 |
+
B_cont = self.perm_mat.T * self.linear_solver(M_eq, Bmat_eq)
|
| 428 |
+
else:
|
| 429 |
+
# Bmat = Matrix([]), so no need to sub
|
| 430 |
+
B_cont = Bmat_eq
|
| 431 |
+
if simplify:
|
| 432 |
+
A_cont.simplify()
|
| 433 |
+
B_cont.simplify()
|
| 434 |
+
return A_cont, B_cont
|
| 435 |
+
# Otherwise return M, A, B for forming the equation
|
| 436 |
+
# [M]dx = [A]x + [B]r, where x = [q, u]^T
|
| 437 |
+
else:
|
| 438 |
+
if simplify:
|
| 439 |
+
M_eq.simplify()
|
| 440 |
+
Amat_eq.simplify()
|
| 441 |
+
Bmat_eq.simplify()
|
| 442 |
+
return M_eq, Amat_eq, Bmat_eq
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def permutation_matrix(orig_vec, per_vec):
|
| 446 |
+
"""Compute the permutation matrix to change order of
|
| 447 |
+
orig_vec into order of per_vec.
|
| 448 |
+
|
| 449 |
+
Parameters
|
| 450 |
+
==========
|
| 451 |
+
|
| 452 |
+
orig_vec : array_like
|
| 453 |
+
Symbols in original ordering.
|
| 454 |
+
per_vec : array_like
|
| 455 |
+
Symbols in new ordering.
|
| 456 |
+
|
| 457 |
+
Returns
|
| 458 |
+
=======
|
| 459 |
+
|
| 460 |
+
p_matrix : Matrix
|
| 461 |
+
Permutation matrix such that orig_vec == (p_matrix * per_vec).
|
| 462 |
+
"""
|
| 463 |
+
if not isinstance(orig_vec, (list, tuple)):
|
| 464 |
+
orig_vec = flatten(orig_vec)
|
| 465 |
+
if not isinstance(per_vec, (list, tuple)):
|
| 466 |
+
per_vec = flatten(per_vec)
|
| 467 |
+
if set(orig_vec) != set(per_vec):
|
| 468 |
+
raise ValueError("orig_vec and per_vec must be the same length, "
|
| 469 |
+
"and contain the same symbols.")
|
| 470 |
+
ind_list = [orig_vec.index(i) for i in per_vec]
|
| 471 |
+
p_matrix = zeros(len(orig_vec))
|
| 472 |
+
for i, j in enumerate(ind_list):
|
| 473 |
+
p_matrix[i, j] = 1
|
| 474 |
+
return p_matrix
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/particle.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import S
|
| 2 |
+
from sympy.physics.vector import cross, dot
|
| 3 |
+
from sympy.physics.mechanics.body_base import BodyBase
|
| 4 |
+
from sympy.physics.mechanics.inertia import inertia_of_point_mass
|
| 5 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 6 |
+
|
| 7 |
+
__all__ = ['Particle']
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Particle(BodyBase):
|
| 11 |
+
"""A particle.
|
| 12 |
+
|
| 13 |
+
Explanation
|
| 14 |
+
===========
|
| 15 |
+
|
| 16 |
+
Particles have a non-zero mass and lack spatial extension; they take up no
|
| 17 |
+
space.
|
| 18 |
+
|
| 19 |
+
Values need to be supplied on initialization, but can be changed later.
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
==========
|
| 23 |
+
|
| 24 |
+
name : str
|
| 25 |
+
Name of particle
|
| 26 |
+
point : Point
|
| 27 |
+
A physics/mechanics Point which represents the position, velocity, and
|
| 28 |
+
acceleration of this Particle
|
| 29 |
+
mass : Sympifyable
|
| 30 |
+
A SymPy expression representing the Particle's mass
|
| 31 |
+
potential_energy : Sympifyable
|
| 32 |
+
The potential energy of the Particle.
|
| 33 |
+
|
| 34 |
+
Examples
|
| 35 |
+
========
|
| 36 |
+
|
| 37 |
+
>>> from sympy.physics.mechanics import Particle, Point
|
| 38 |
+
>>> from sympy import Symbol
|
| 39 |
+
>>> po = Point('po')
|
| 40 |
+
>>> m = Symbol('m')
|
| 41 |
+
>>> pa = Particle('pa', po, m)
|
| 42 |
+
>>> # Or you could change these later
|
| 43 |
+
>>> pa.mass = m
|
| 44 |
+
>>> pa.point = po
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
point = BodyBase.masscenter
|
| 48 |
+
|
| 49 |
+
def __init__(self, name, point=None, mass=None):
|
| 50 |
+
super().__init__(name, point, mass)
|
| 51 |
+
|
| 52 |
+
def linear_momentum(self, frame):
|
| 53 |
+
"""Linear momentum of the particle.
|
| 54 |
+
|
| 55 |
+
Explanation
|
| 56 |
+
===========
|
| 57 |
+
|
| 58 |
+
The linear momentum L, of a particle P, with respect to frame N is
|
| 59 |
+
given by:
|
| 60 |
+
|
| 61 |
+
L = m * v
|
| 62 |
+
|
| 63 |
+
where m is the mass of the particle, and v is the velocity of the
|
| 64 |
+
particle in the frame N.
|
| 65 |
+
|
| 66 |
+
Parameters
|
| 67 |
+
==========
|
| 68 |
+
|
| 69 |
+
frame : ReferenceFrame
|
| 70 |
+
The frame in which linear momentum is desired.
|
| 71 |
+
|
| 72 |
+
Examples
|
| 73 |
+
========
|
| 74 |
+
|
| 75 |
+
>>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
|
| 76 |
+
>>> from sympy.physics.mechanics import dynamicsymbols
|
| 77 |
+
>>> from sympy.physics.vector import init_vprinting
|
| 78 |
+
>>> init_vprinting(pretty_print=False)
|
| 79 |
+
>>> m, v = dynamicsymbols('m v')
|
| 80 |
+
>>> N = ReferenceFrame('N')
|
| 81 |
+
>>> P = Point('P')
|
| 82 |
+
>>> A = Particle('A', P, m)
|
| 83 |
+
>>> P.set_vel(N, v * N.x)
|
| 84 |
+
>>> A.linear_momentum(N)
|
| 85 |
+
m*v*N.x
|
| 86 |
+
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
return self.mass * self.point.vel(frame)
|
| 90 |
+
|
| 91 |
+
def angular_momentum(self, point, frame):
|
| 92 |
+
"""Angular momentum of the particle about the point.
|
| 93 |
+
|
| 94 |
+
Explanation
|
| 95 |
+
===========
|
| 96 |
+
|
| 97 |
+
The angular momentum H, about some point O of a particle, P, is given
|
| 98 |
+
by:
|
| 99 |
+
|
| 100 |
+
``H = cross(r, m * v)``
|
| 101 |
+
|
| 102 |
+
where r is the position vector from point O to the particle P, m is
|
| 103 |
+
the mass of the particle, and v is the velocity of the particle in
|
| 104 |
+
the inertial frame, N.
|
| 105 |
+
|
| 106 |
+
Parameters
|
| 107 |
+
==========
|
| 108 |
+
|
| 109 |
+
point : Point
|
| 110 |
+
The point about which angular momentum of the particle is desired.
|
| 111 |
+
|
| 112 |
+
frame : ReferenceFrame
|
| 113 |
+
The frame in which angular momentum is desired.
|
| 114 |
+
|
| 115 |
+
Examples
|
| 116 |
+
========
|
| 117 |
+
|
| 118 |
+
>>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
|
| 119 |
+
>>> from sympy.physics.mechanics import dynamicsymbols
|
| 120 |
+
>>> from sympy.physics.vector import init_vprinting
|
| 121 |
+
>>> init_vprinting(pretty_print=False)
|
| 122 |
+
>>> m, v, r = dynamicsymbols('m v r')
|
| 123 |
+
>>> N = ReferenceFrame('N')
|
| 124 |
+
>>> O = Point('O')
|
| 125 |
+
>>> A = O.locatenew('A', r * N.x)
|
| 126 |
+
>>> P = Particle('P', A, m)
|
| 127 |
+
>>> P.point.set_vel(N, v * N.y)
|
| 128 |
+
>>> P.angular_momentum(O, N)
|
| 129 |
+
m*r*v*N.z
|
| 130 |
+
|
| 131 |
+
"""
|
| 132 |
+
|
| 133 |
+
return cross(self.point.pos_from(point),
|
| 134 |
+
self.mass * self.point.vel(frame))
|
| 135 |
+
|
| 136 |
+
def kinetic_energy(self, frame):
|
| 137 |
+
"""Kinetic energy of the particle.
|
| 138 |
+
|
| 139 |
+
Explanation
|
| 140 |
+
===========
|
| 141 |
+
|
| 142 |
+
The kinetic energy, T, of a particle, P, is given by:
|
| 143 |
+
|
| 144 |
+
``T = 1/2 (dot(m * v, v))``
|
| 145 |
+
|
| 146 |
+
where m is the mass of particle P, and v is the velocity of the
|
| 147 |
+
particle in the supplied ReferenceFrame.
|
| 148 |
+
|
| 149 |
+
Parameters
|
| 150 |
+
==========
|
| 151 |
+
|
| 152 |
+
frame : ReferenceFrame
|
| 153 |
+
The Particle's velocity is typically defined with respect to
|
| 154 |
+
an inertial frame but any relevant frame in which the velocity is
|
| 155 |
+
known can be supplied.
|
| 156 |
+
|
| 157 |
+
Examples
|
| 158 |
+
========
|
| 159 |
+
|
| 160 |
+
>>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
|
| 161 |
+
>>> from sympy import symbols
|
| 162 |
+
>>> m, v, r = symbols('m v r')
|
| 163 |
+
>>> N = ReferenceFrame('N')
|
| 164 |
+
>>> O = Point('O')
|
| 165 |
+
>>> P = Particle('P', O, m)
|
| 166 |
+
>>> P.point.set_vel(N, v * N.y)
|
| 167 |
+
>>> P.kinetic_energy(N)
|
| 168 |
+
m*v**2/2
|
| 169 |
+
|
| 170 |
+
"""
|
| 171 |
+
|
| 172 |
+
return S.Half * self.mass * dot(self.point.vel(frame),
|
| 173 |
+
self.point.vel(frame))
|
| 174 |
+
|
| 175 |
+
def set_potential_energy(self, scalar):
|
| 176 |
+
sympy_deprecation_warning(
|
| 177 |
+
"""
|
| 178 |
+
The sympy.physics.mechanics.Particle.set_potential_energy()
|
| 179 |
+
method is deprecated. Instead use
|
| 180 |
+
|
| 181 |
+
P.potential_energy = scalar
|
| 182 |
+
""",
|
| 183 |
+
deprecated_since_version="1.5",
|
| 184 |
+
active_deprecations_target="deprecated-set-potential-energy",
|
| 185 |
+
)
|
| 186 |
+
self.potential_energy = scalar
|
| 187 |
+
|
| 188 |
+
def parallel_axis(self, point, frame):
|
| 189 |
+
"""Returns an inertia dyadic of the particle with respect to another
|
| 190 |
+
point and frame.
|
| 191 |
+
|
| 192 |
+
Parameters
|
| 193 |
+
==========
|
| 194 |
+
|
| 195 |
+
point : sympy.physics.vector.Point
|
| 196 |
+
The point to express the inertia dyadic about.
|
| 197 |
+
frame : sympy.physics.vector.ReferenceFrame
|
| 198 |
+
The reference frame used to construct the dyadic.
|
| 199 |
+
|
| 200 |
+
Returns
|
| 201 |
+
=======
|
| 202 |
+
|
| 203 |
+
inertia : sympy.physics.vector.Dyadic
|
| 204 |
+
The inertia dyadic of the particle expressed about the provided
|
| 205 |
+
point and frame.
|
| 206 |
+
|
| 207 |
+
"""
|
| 208 |
+
return inertia_of_point_mass(self.mass, self.point.pos_from(point),
|
| 209 |
+
frame)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/pathway.py
ADDED
|
@@ -0,0 +1,688 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 3 |
+
from abc import ABC, abstractmethod
|
| 4 |
+
|
| 5 |
+
from sympy.core.singleton import S
|
| 6 |
+
from sympy.physics.mechanics.loads import Force
|
| 7 |
+
from sympy.physics.mechanics.wrapping_geometry import WrappingGeometryBase
|
| 8 |
+
from sympy.physics.vector import Point, dynamicsymbols
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
__all__ = ['PathwayBase', 'LinearPathway', 'ObstacleSetPathway',
|
| 12 |
+
'WrappingPathway']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class PathwayBase(ABC):
|
| 16 |
+
"""Abstract base class for all pathway classes to inherit from.
|
| 17 |
+
|
| 18 |
+
Notes
|
| 19 |
+
=====
|
| 20 |
+
|
| 21 |
+
Instances of this class cannot be directly instantiated by users. However,
|
| 22 |
+
it can be used to created custom pathway types through subclassing.
|
| 23 |
+
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
def __init__(self, *attachments):
|
| 27 |
+
"""Initializer for ``PathwayBase``."""
|
| 28 |
+
self.attachments = attachments
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def attachments(self):
|
| 32 |
+
"""The pair of points defining a pathway's ends."""
|
| 33 |
+
return self._attachments
|
| 34 |
+
|
| 35 |
+
@attachments.setter
|
| 36 |
+
def attachments(self, attachments):
|
| 37 |
+
if hasattr(self, '_attachments'):
|
| 38 |
+
msg = (
|
| 39 |
+
f'Can\'t set attribute `attachments` to {repr(attachments)} '
|
| 40 |
+
f'as it is immutable.'
|
| 41 |
+
)
|
| 42 |
+
raise AttributeError(msg)
|
| 43 |
+
if len(attachments) != 2:
|
| 44 |
+
msg = (
|
| 45 |
+
f'Value {repr(attachments)} passed to `attachments` was an '
|
| 46 |
+
f'iterable of length {len(attachments)}, must be an iterable '
|
| 47 |
+
f'of length 2.'
|
| 48 |
+
)
|
| 49 |
+
raise ValueError(msg)
|
| 50 |
+
for i, point in enumerate(attachments):
|
| 51 |
+
if not isinstance(point, Point):
|
| 52 |
+
msg = (
|
| 53 |
+
f'Value {repr(point)} passed to `attachments` at index '
|
| 54 |
+
f'{i} was of type {type(point)}, must be {Point}.'
|
| 55 |
+
)
|
| 56 |
+
raise TypeError(msg)
|
| 57 |
+
self._attachments = tuple(attachments)
|
| 58 |
+
|
| 59 |
+
@property
|
| 60 |
+
@abstractmethod
|
| 61 |
+
def length(self):
|
| 62 |
+
"""An expression representing the pathway's length."""
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
@abstractmethod
|
| 67 |
+
def extension_velocity(self):
|
| 68 |
+
"""An expression representing the pathway's extension velocity."""
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
@abstractmethod
|
| 72 |
+
def to_loads(self, force):
|
| 73 |
+
"""Loads required by the equations of motion method classes.
|
| 74 |
+
|
| 75 |
+
Explanation
|
| 76 |
+
===========
|
| 77 |
+
|
| 78 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 79 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 80 |
+
when constructing the equations of motion. This method acts as a
|
| 81 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 82 |
+
required so that these can be easily concatenated with other items in
|
| 83 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 84 |
+
loads are also in the correct form to also be passed to the other
|
| 85 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 86 |
+
|
| 87 |
+
"""
|
| 88 |
+
pass
|
| 89 |
+
|
| 90 |
+
def __repr__(self):
|
| 91 |
+
"""Default representation of a pathway."""
|
| 92 |
+
attachments = ', '.join(str(a) for a in self.attachments)
|
| 93 |
+
return f'{self.__class__.__name__}({attachments})'
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class LinearPathway(PathwayBase):
|
| 97 |
+
"""Linear pathway between a pair of attachment points.
|
| 98 |
+
|
| 99 |
+
Explanation
|
| 100 |
+
===========
|
| 101 |
+
|
| 102 |
+
A linear pathway forms a straight-line segment between two points and is
|
| 103 |
+
the simplest pathway that can be formed. It will not interact with any
|
| 104 |
+
other objects in the system, i.e. a ``LinearPathway`` will intersect other
|
| 105 |
+
objects to ensure that the path between its two ends (its attachments) is
|
| 106 |
+
the shortest possible.
|
| 107 |
+
|
| 108 |
+
A linear pathway is made up of two points that can move relative to each
|
| 109 |
+
other, and a pair of equal and opposite forces acting on the points. If the
|
| 110 |
+
positive time-varying Euclidean distance between the two points is defined,
|
| 111 |
+
then the "extension velocity" is the time derivative of this distance. The
|
| 112 |
+
extension velocity is positive when the two points are moving away from
|
| 113 |
+
each other and negative when moving closer to each other. The direction for
|
| 114 |
+
the force acting on either point is determined by constructing a unit
|
| 115 |
+
vector directed from the other point to this point. This establishes a sign
|
| 116 |
+
convention such that a positive force magnitude tends to push the points
|
| 117 |
+
apart. The following diagram shows the positive force sense and the
|
| 118 |
+
distance between the points::
|
| 119 |
+
|
| 120 |
+
P Q
|
| 121 |
+
o<--- F --->o
|
| 122 |
+
| |
|
| 123 |
+
|<--l(t)--->|
|
| 124 |
+
|
| 125 |
+
Examples
|
| 126 |
+
========
|
| 127 |
+
|
| 128 |
+
>>> from sympy.physics.mechanics import LinearPathway
|
| 129 |
+
|
| 130 |
+
To construct a pathway, two points are required to be passed to the
|
| 131 |
+
``attachments`` parameter as a ``tuple``.
|
| 132 |
+
|
| 133 |
+
>>> from sympy.physics.mechanics import Point
|
| 134 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 135 |
+
>>> linear_pathway = LinearPathway(pA, pB)
|
| 136 |
+
>>> linear_pathway
|
| 137 |
+
LinearPathway(pA, pB)
|
| 138 |
+
|
| 139 |
+
The pathway created above isn't very interesting without the positions and
|
| 140 |
+
velocities of its attachment points being described. Without this its not
|
| 141 |
+
possible to describe how the pathway moves, i.e. its length or its
|
| 142 |
+
extension velocity.
|
| 143 |
+
|
| 144 |
+
>>> from sympy.physics.mechanics import ReferenceFrame
|
| 145 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 146 |
+
>>> N = ReferenceFrame('N')
|
| 147 |
+
>>> q = dynamicsymbols('q')
|
| 148 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 149 |
+
>>> pB.pos_from(pA)
|
| 150 |
+
q(t)*N.x
|
| 151 |
+
|
| 152 |
+
A pathway's length can be accessed via its ``length`` attribute.
|
| 153 |
+
|
| 154 |
+
>>> linear_pathway.length
|
| 155 |
+
sqrt(q(t)**2)
|
| 156 |
+
|
| 157 |
+
Note how what appears to be an overly-complex expression is returned. This
|
| 158 |
+
is actually required as it ensures that a pathway's length is always
|
| 159 |
+
positive.
|
| 160 |
+
|
| 161 |
+
A pathway's extension velocity can be accessed similarly via its
|
| 162 |
+
``extension_velocity`` attribute.
|
| 163 |
+
|
| 164 |
+
>>> linear_pathway.extension_velocity
|
| 165 |
+
sqrt(q(t)**2)*Derivative(q(t), t)/q(t)
|
| 166 |
+
|
| 167 |
+
Parameters
|
| 168 |
+
==========
|
| 169 |
+
|
| 170 |
+
attachments : tuple[Point, Point]
|
| 171 |
+
Pair of ``Point`` objects between which the linear pathway spans.
|
| 172 |
+
Constructor expects two points to be passed, e.g.
|
| 173 |
+
``LinearPathway(Point('pA'), Point('pB'))``. More or fewer points will
|
| 174 |
+
cause an error to be thrown.
|
| 175 |
+
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
def __init__(self, *attachments):
|
| 179 |
+
"""Initializer for ``LinearPathway``.
|
| 180 |
+
|
| 181 |
+
Parameters
|
| 182 |
+
==========
|
| 183 |
+
|
| 184 |
+
attachments : Point
|
| 185 |
+
Pair of ``Point`` objects between which the linear pathway spans.
|
| 186 |
+
Constructor expects two points to be passed, e.g.
|
| 187 |
+
``LinearPathway(Point('pA'), Point('pB'))``. More or fewer points
|
| 188 |
+
will cause an error to be thrown.
|
| 189 |
+
|
| 190 |
+
"""
|
| 191 |
+
super().__init__(*attachments)
|
| 192 |
+
|
| 193 |
+
@property
|
| 194 |
+
def length(self):
|
| 195 |
+
"""Exact analytical expression for the pathway's length."""
|
| 196 |
+
return _point_pair_length(*self.attachments)
|
| 197 |
+
|
| 198 |
+
@property
|
| 199 |
+
def extension_velocity(self):
|
| 200 |
+
"""Exact analytical expression for the pathway's extension velocity."""
|
| 201 |
+
return _point_pair_extension_velocity(*self.attachments)
|
| 202 |
+
|
| 203 |
+
def to_loads(self, force):
|
| 204 |
+
"""Loads required by the equations of motion method classes.
|
| 205 |
+
|
| 206 |
+
Explanation
|
| 207 |
+
===========
|
| 208 |
+
|
| 209 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 210 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 211 |
+
when constructing the equations of motion. This method acts as a
|
| 212 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 213 |
+
required so that these can be easily concatenated with other items in
|
| 214 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 215 |
+
loads are also in the correct form to also be passed to the other
|
| 216 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 217 |
+
|
| 218 |
+
Examples
|
| 219 |
+
========
|
| 220 |
+
|
| 221 |
+
The below example shows how to generate the loads produced in a linear
|
| 222 |
+
actuator that produces an expansile force ``F``. First, create a linear
|
| 223 |
+
actuator between two points separated by the coordinate ``q`` in the
|
| 224 |
+
``x`` direction of the global frame ``N``.
|
| 225 |
+
|
| 226 |
+
>>> from sympy.physics.mechanics import (LinearPathway, Point,
|
| 227 |
+
... ReferenceFrame)
|
| 228 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 229 |
+
>>> q = dynamicsymbols('q')
|
| 230 |
+
>>> N = ReferenceFrame('N')
|
| 231 |
+
>>> pA, pB = Point('pA'), Point('pB')
|
| 232 |
+
>>> pB.set_pos(pA, q*N.x)
|
| 233 |
+
>>> linear_pathway = LinearPathway(pA, pB)
|
| 234 |
+
|
| 235 |
+
Now create a symbol ``F`` to describe the magnitude of the (expansile)
|
| 236 |
+
force that will be produced along the pathway. The list of loads that
|
| 237 |
+
``KanesMethod`` requires can be produced by calling the pathway's
|
| 238 |
+
``to_loads`` method with ``F`` passed as the only argument.
|
| 239 |
+
|
| 240 |
+
>>> from sympy import symbols
|
| 241 |
+
>>> F = symbols('F')
|
| 242 |
+
>>> linear_pathway.to_loads(F)
|
| 243 |
+
[(pA, - F*q(t)/sqrt(q(t)**2)*N.x), (pB, F*q(t)/sqrt(q(t)**2)*N.x)]
|
| 244 |
+
|
| 245 |
+
Parameters
|
| 246 |
+
==========
|
| 247 |
+
|
| 248 |
+
force : Expr
|
| 249 |
+
Magnitude of the force acting along the length of the pathway. As
|
| 250 |
+
per the sign conventions for the pathway length, pathway extension
|
| 251 |
+
velocity, and pair of point forces, if this ``Expr`` is positive
|
| 252 |
+
then the force will act to push the pair of points away from one
|
| 253 |
+
another (it is expansile).
|
| 254 |
+
|
| 255 |
+
"""
|
| 256 |
+
relative_position = _point_pair_relative_position(*self.attachments)
|
| 257 |
+
loads = [
|
| 258 |
+
Force(self.attachments[0], -force*relative_position/self.length),
|
| 259 |
+
Force(self.attachments[-1], force*relative_position/self.length),
|
| 260 |
+
]
|
| 261 |
+
return loads
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
class ObstacleSetPathway(PathwayBase):
|
| 265 |
+
"""Obstacle-set pathway between a set of attachment points.
|
| 266 |
+
|
| 267 |
+
Explanation
|
| 268 |
+
===========
|
| 269 |
+
|
| 270 |
+
An obstacle-set pathway forms a series of straight-line segment between
|
| 271 |
+
pairs of consecutive points in a set of points. It is similiar to multiple
|
| 272 |
+
linear pathways joined end-to-end. It will not interact with any other
|
| 273 |
+
objects in the system, i.e. an ``ObstacleSetPathway`` will intersect other
|
| 274 |
+
objects to ensure that the path between its pairs of points (its
|
| 275 |
+
attachments) is the shortest possible.
|
| 276 |
+
|
| 277 |
+
Examples
|
| 278 |
+
========
|
| 279 |
+
|
| 280 |
+
To construct an obstacle-set pathway, three or more points are required to
|
| 281 |
+
be passed to the ``attachments`` parameter as a ``tuple``.
|
| 282 |
+
|
| 283 |
+
>>> from sympy.physics.mechanics import ObstacleSetPathway, Point
|
| 284 |
+
>>> pA, pB, pC, pD = Point('pA'), Point('pB'), Point('pC'), Point('pD')
|
| 285 |
+
>>> obstacle_set_pathway = ObstacleSetPathway(pA, pB, pC, pD)
|
| 286 |
+
>>> obstacle_set_pathway
|
| 287 |
+
ObstacleSetPathway(pA, pB, pC, pD)
|
| 288 |
+
|
| 289 |
+
The pathway created above isn't very interesting without the positions and
|
| 290 |
+
velocities of its attachment points being described. Without this its not
|
| 291 |
+
possible to describe how the pathway moves, i.e. its length or its
|
| 292 |
+
extension velocity.
|
| 293 |
+
|
| 294 |
+
>>> from sympy import cos, sin
|
| 295 |
+
>>> from sympy.physics.mechanics import ReferenceFrame
|
| 296 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 297 |
+
>>> N = ReferenceFrame('N')
|
| 298 |
+
>>> q = dynamicsymbols('q')
|
| 299 |
+
>>> pO = Point('pO')
|
| 300 |
+
>>> pA.set_pos(pO, N.y)
|
| 301 |
+
>>> pB.set_pos(pO, -N.x)
|
| 302 |
+
>>> pC.set_pos(pA, cos(q) * N.x - (sin(q) + 1) * N.y)
|
| 303 |
+
>>> pD.set_pos(pA, sin(q) * N.x + (cos(q) - 1) * N.y)
|
| 304 |
+
>>> pB.pos_from(pA)
|
| 305 |
+
- N.x - N.y
|
| 306 |
+
>>> pC.pos_from(pA)
|
| 307 |
+
cos(q(t))*N.x + (-sin(q(t)) - 1)*N.y
|
| 308 |
+
>>> pD.pos_from(pA)
|
| 309 |
+
sin(q(t))*N.x + (cos(q(t)) - 1)*N.y
|
| 310 |
+
|
| 311 |
+
A pathway's length can be accessed via its ``length`` attribute.
|
| 312 |
+
|
| 313 |
+
>>> obstacle_set_pathway.length.simplify()
|
| 314 |
+
sqrt(2)*(sqrt(cos(q(t)) + 1) + 2)
|
| 315 |
+
|
| 316 |
+
A pathway's extension velocity can be accessed similarly via its
|
| 317 |
+
``extension_velocity`` attribute.
|
| 318 |
+
|
| 319 |
+
>>> obstacle_set_pathway.extension_velocity.simplify()
|
| 320 |
+
-sqrt(2)*sin(q(t))*Derivative(q(t), t)/(2*sqrt(cos(q(t)) + 1))
|
| 321 |
+
|
| 322 |
+
Parameters
|
| 323 |
+
==========
|
| 324 |
+
|
| 325 |
+
attachments : tuple[Point, Point]
|
| 326 |
+
The set of ``Point`` objects that define the segmented obstacle-set
|
| 327 |
+
pathway.
|
| 328 |
+
|
| 329 |
+
"""
|
| 330 |
+
|
| 331 |
+
def __init__(self, *attachments):
|
| 332 |
+
"""Initializer for ``ObstacleSetPathway``.
|
| 333 |
+
|
| 334 |
+
Parameters
|
| 335 |
+
==========
|
| 336 |
+
|
| 337 |
+
attachments : tuple[Point, ...]
|
| 338 |
+
The set of ``Point`` objects that define the segmented obstacle-set
|
| 339 |
+
pathway.
|
| 340 |
+
|
| 341 |
+
"""
|
| 342 |
+
super().__init__(*attachments)
|
| 343 |
+
|
| 344 |
+
@property
|
| 345 |
+
def attachments(self):
|
| 346 |
+
"""The set of points defining a pathway's segmented path."""
|
| 347 |
+
return self._attachments
|
| 348 |
+
|
| 349 |
+
@attachments.setter
|
| 350 |
+
def attachments(self, attachments):
|
| 351 |
+
if hasattr(self, '_attachments'):
|
| 352 |
+
msg = (
|
| 353 |
+
f'Can\'t set attribute `attachments` to {repr(attachments)} '
|
| 354 |
+
f'as it is immutable.'
|
| 355 |
+
)
|
| 356 |
+
raise AttributeError(msg)
|
| 357 |
+
if len(attachments) <= 2:
|
| 358 |
+
msg = (
|
| 359 |
+
f'Value {repr(attachments)} passed to `attachments` was an '
|
| 360 |
+
f'iterable of length {len(attachments)}, must be an iterable '
|
| 361 |
+
f'of length 3 or greater.'
|
| 362 |
+
)
|
| 363 |
+
raise ValueError(msg)
|
| 364 |
+
for i, point in enumerate(attachments):
|
| 365 |
+
if not isinstance(point, Point):
|
| 366 |
+
msg = (
|
| 367 |
+
f'Value {repr(point)} passed to `attachments` at index '
|
| 368 |
+
f'{i} was of type {type(point)}, must be {Point}.'
|
| 369 |
+
)
|
| 370 |
+
raise TypeError(msg)
|
| 371 |
+
self._attachments = tuple(attachments)
|
| 372 |
+
|
| 373 |
+
@property
|
| 374 |
+
def length(self):
|
| 375 |
+
"""Exact analytical expression for the pathway's length."""
|
| 376 |
+
length = S.Zero
|
| 377 |
+
attachment_pairs = zip(self.attachments[:-1], self.attachments[1:])
|
| 378 |
+
for attachment_pair in attachment_pairs:
|
| 379 |
+
length += _point_pair_length(*attachment_pair)
|
| 380 |
+
return length
|
| 381 |
+
|
| 382 |
+
@property
|
| 383 |
+
def extension_velocity(self):
|
| 384 |
+
"""Exact analytical expression for the pathway's extension velocity."""
|
| 385 |
+
extension_velocity = S.Zero
|
| 386 |
+
attachment_pairs = zip(self.attachments[:-1], self.attachments[1:])
|
| 387 |
+
for attachment_pair in attachment_pairs:
|
| 388 |
+
extension_velocity += _point_pair_extension_velocity(*attachment_pair)
|
| 389 |
+
return extension_velocity
|
| 390 |
+
|
| 391 |
+
def to_loads(self, force):
|
| 392 |
+
"""Loads required by the equations of motion method classes.
|
| 393 |
+
|
| 394 |
+
Explanation
|
| 395 |
+
===========
|
| 396 |
+
|
| 397 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 398 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 399 |
+
when constructing the equations of motion. This method acts as a
|
| 400 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 401 |
+
required so that these can be easily concatenated with other items in
|
| 402 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 403 |
+
loads are also in the correct form to also be passed to the other
|
| 404 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 405 |
+
|
| 406 |
+
Examples
|
| 407 |
+
========
|
| 408 |
+
|
| 409 |
+
The below example shows how to generate the loads produced in an
|
| 410 |
+
actuator that follows an obstacle-set pathway between four points and
|
| 411 |
+
produces an expansile force ``F``. First, create a pair of reference
|
| 412 |
+
frames, ``A`` and ``B``, in which the four points ``pA``, ``pB``,
|
| 413 |
+
``pC``, and ``pD`` will be located. The first two points in frame ``A``
|
| 414 |
+
and the second two in frame ``B``. Frame ``B`` will also be oriented
|
| 415 |
+
such that it relates to ``A`` via a rotation of ``q`` about an axis
|
| 416 |
+
``N.z`` in a global frame (``N.z``, ``A.z``, and ``B.z`` are parallel).
|
| 417 |
+
|
| 418 |
+
>>> from sympy.physics.mechanics import (ObstacleSetPathway, Point,
|
| 419 |
+
... ReferenceFrame)
|
| 420 |
+
>>> from sympy.physics.vector import dynamicsymbols
|
| 421 |
+
>>> q = dynamicsymbols('q')
|
| 422 |
+
>>> N = ReferenceFrame('N')
|
| 423 |
+
>>> N = ReferenceFrame('N')
|
| 424 |
+
>>> A = N.orientnew('A', 'axis', (0, N.x))
|
| 425 |
+
>>> B = A.orientnew('B', 'axis', (q, N.z))
|
| 426 |
+
>>> pO = Point('pO')
|
| 427 |
+
>>> pA, pB, pC, pD = Point('pA'), Point('pB'), Point('pC'), Point('pD')
|
| 428 |
+
>>> pA.set_pos(pO, A.x)
|
| 429 |
+
>>> pB.set_pos(pO, -A.y)
|
| 430 |
+
>>> pC.set_pos(pO, B.y)
|
| 431 |
+
>>> pD.set_pos(pO, B.x)
|
| 432 |
+
>>> obstacle_set_pathway = ObstacleSetPathway(pA, pB, pC, pD)
|
| 433 |
+
|
| 434 |
+
Now create a symbol ``F`` to describe the magnitude of the (expansile)
|
| 435 |
+
force that will be produced along the pathway. The list of loads that
|
| 436 |
+
``KanesMethod`` requires can be produced by calling the pathway's
|
| 437 |
+
``to_loads`` method with ``F`` passed as the only argument.
|
| 438 |
+
|
| 439 |
+
>>> from sympy import Symbol
|
| 440 |
+
>>> F = Symbol('F')
|
| 441 |
+
>>> obstacle_set_pathway.to_loads(F)
|
| 442 |
+
[(pA, sqrt(2)*F/2*A.x + sqrt(2)*F/2*A.y),
|
| 443 |
+
(pB, - sqrt(2)*F/2*A.x - sqrt(2)*F/2*A.y),
|
| 444 |
+
(pB, - F/sqrt(2*cos(q(t)) + 2)*A.y - F/sqrt(2*cos(q(t)) + 2)*B.y),
|
| 445 |
+
(pC, F/sqrt(2*cos(q(t)) + 2)*A.y + F/sqrt(2*cos(q(t)) + 2)*B.y),
|
| 446 |
+
(pC, - sqrt(2)*F/2*B.x + sqrt(2)*F/2*B.y),
|
| 447 |
+
(pD, sqrt(2)*F/2*B.x - sqrt(2)*F/2*B.y)]
|
| 448 |
+
|
| 449 |
+
Parameters
|
| 450 |
+
==========
|
| 451 |
+
|
| 452 |
+
force : Expr
|
| 453 |
+
The force acting along the length of the pathway. It is assumed
|
| 454 |
+
that this ``Expr`` represents an expansile force.
|
| 455 |
+
|
| 456 |
+
"""
|
| 457 |
+
loads = []
|
| 458 |
+
attachment_pairs = zip(self.attachments[:-1], self.attachments[1:])
|
| 459 |
+
for attachment_pair in attachment_pairs:
|
| 460 |
+
relative_position = _point_pair_relative_position(*attachment_pair)
|
| 461 |
+
length = _point_pair_length(*attachment_pair)
|
| 462 |
+
loads.extend([
|
| 463 |
+
Force(attachment_pair[0], -force*relative_position/length),
|
| 464 |
+
Force(attachment_pair[1], force*relative_position/length),
|
| 465 |
+
])
|
| 466 |
+
return loads
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
class WrappingPathway(PathwayBase):
|
| 470 |
+
"""Pathway that wraps a geometry object.
|
| 471 |
+
|
| 472 |
+
Explanation
|
| 473 |
+
===========
|
| 474 |
+
|
| 475 |
+
A wrapping pathway interacts with a geometry object and forms a path that
|
| 476 |
+
wraps smoothly along its surface. The wrapping pathway along the geometry
|
| 477 |
+
object will be the geodesic that the geometry object defines based on the
|
| 478 |
+
two points. It will not interact with any other objects in the system, i.e.
|
| 479 |
+
a ``WrappingPathway`` will intersect other objects to ensure that the path
|
| 480 |
+
between its two ends (its attachments) is the shortest possible.
|
| 481 |
+
|
| 482 |
+
To explain the sign conventions used for pathway length, extension
|
| 483 |
+
velocity, and direction of applied forces, we can ignore the geometry with
|
| 484 |
+
which the wrapping pathway interacts. A wrapping pathway is made up of two
|
| 485 |
+
points that can move relative to each other, and a pair of equal and
|
| 486 |
+
opposite forces acting on the points. If the positive time-varying
|
| 487 |
+
Euclidean distance between the two points is defined, then the "extension
|
| 488 |
+
velocity" is the time derivative of this distance. The extension velocity
|
| 489 |
+
is positive when the two points are moving away from each other and
|
| 490 |
+
negative when moving closer to each other. The direction for the force
|
| 491 |
+
acting on either point is determined by constructing a unit vector directed
|
| 492 |
+
from the other point to this point. This establishes a sign convention such
|
| 493 |
+
that a positive force magnitude tends to push the points apart. The
|
| 494 |
+
following diagram shows the positive force sense and the distance between
|
| 495 |
+
the points::
|
| 496 |
+
|
| 497 |
+
P Q
|
| 498 |
+
o<--- F --->o
|
| 499 |
+
| |
|
| 500 |
+
|<--l(t)--->|
|
| 501 |
+
|
| 502 |
+
Examples
|
| 503 |
+
========
|
| 504 |
+
|
| 505 |
+
>>> from sympy.physics.mechanics import WrappingPathway
|
| 506 |
+
|
| 507 |
+
To construct a wrapping pathway, like other pathways, a pair of points must
|
| 508 |
+
be passed, followed by an instance of a wrapping geometry class as a
|
| 509 |
+
keyword argument. We'll use a cylinder with radius ``r`` and its axis
|
| 510 |
+
parallel to ``N.x`` passing through a point ``pO``.
|
| 511 |
+
|
| 512 |
+
>>> from sympy import symbols
|
| 513 |
+
>>> from sympy.physics.mechanics import Point, ReferenceFrame, WrappingCylinder
|
| 514 |
+
>>> r = symbols('r')
|
| 515 |
+
>>> N = ReferenceFrame('N')
|
| 516 |
+
>>> pA, pB, pO = Point('pA'), Point('pB'), Point('pO')
|
| 517 |
+
>>> cylinder = WrappingCylinder(r, pO, N.x)
|
| 518 |
+
>>> wrapping_pathway = WrappingPathway(pA, pB, cylinder)
|
| 519 |
+
>>> wrapping_pathway
|
| 520 |
+
WrappingPathway(pA, pB, geometry=WrappingCylinder(radius=r, point=pO,
|
| 521 |
+
axis=N.x))
|
| 522 |
+
|
| 523 |
+
Parameters
|
| 524 |
+
==========
|
| 525 |
+
|
| 526 |
+
attachment_1 : Point
|
| 527 |
+
First of the pair of ``Point`` objects between which the wrapping
|
| 528 |
+
pathway spans.
|
| 529 |
+
attachment_2 : Point
|
| 530 |
+
Second of the pair of ``Point`` objects between which the wrapping
|
| 531 |
+
pathway spans.
|
| 532 |
+
geometry : WrappingGeometryBase
|
| 533 |
+
Geometry about which the pathway wraps.
|
| 534 |
+
|
| 535 |
+
"""
|
| 536 |
+
|
| 537 |
+
def __init__(self, attachment_1, attachment_2, geometry):
|
| 538 |
+
"""Initializer for ``WrappingPathway``.
|
| 539 |
+
|
| 540 |
+
Parameters
|
| 541 |
+
==========
|
| 542 |
+
|
| 543 |
+
attachment_1 : Point
|
| 544 |
+
First of the pair of ``Point`` objects between which the wrapping
|
| 545 |
+
pathway spans.
|
| 546 |
+
attachment_2 : Point
|
| 547 |
+
Second of the pair of ``Point`` objects between which the wrapping
|
| 548 |
+
pathway spans.
|
| 549 |
+
geometry : WrappingGeometryBase
|
| 550 |
+
Geometry about which the pathway wraps.
|
| 551 |
+
The geometry about which the pathway wraps.
|
| 552 |
+
|
| 553 |
+
"""
|
| 554 |
+
super().__init__(attachment_1, attachment_2)
|
| 555 |
+
self.geometry = geometry
|
| 556 |
+
|
| 557 |
+
@property
|
| 558 |
+
def geometry(self):
|
| 559 |
+
"""Geometry around which the pathway wraps."""
|
| 560 |
+
return self._geometry
|
| 561 |
+
|
| 562 |
+
@geometry.setter
|
| 563 |
+
def geometry(self, geometry):
|
| 564 |
+
if hasattr(self, '_geometry'):
|
| 565 |
+
msg = (
|
| 566 |
+
f'Can\'t set attribute `geometry` to {repr(geometry)} as it '
|
| 567 |
+
f'is immutable.'
|
| 568 |
+
)
|
| 569 |
+
raise AttributeError(msg)
|
| 570 |
+
if not isinstance(geometry, WrappingGeometryBase):
|
| 571 |
+
msg = (
|
| 572 |
+
f'Value {repr(geometry)} passed to `geometry` was of type '
|
| 573 |
+
f'{type(geometry)}, must be {WrappingGeometryBase}.'
|
| 574 |
+
)
|
| 575 |
+
raise TypeError(msg)
|
| 576 |
+
self._geometry = geometry
|
| 577 |
+
|
| 578 |
+
@property
|
| 579 |
+
def length(self):
|
| 580 |
+
"""Exact analytical expression for the pathway's length."""
|
| 581 |
+
return self.geometry.geodesic_length(*self.attachments)
|
| 582 |
+
|
| 583 |
+
@property
|
| 584 |
+
def extension_velocity(self):
|
| 585 |
+
"""Exact analytical expression for the pathway's extension velocity."""
|
| 586 |
+
return self.length.diff(dynamicsymbols._t)
|
| 587 |
+
|
| 588 |
+
def to_loads(self, force):
|
| 589 |
+
"""Loads required by the equations of motion method classes.
|
| 590 |
+
|
| 591 |
+
Explanation
|
| 592 |
+
===========
|
| 593 |
+
|
| 594 |
+
``KanesMethod`` requires a list of ``Point``-``Vector`` tuples to be
|
| 595 |
+
passed to the ``loads`` parameters of its ``kanes_equations`` method
|
| 596 |
+
when constructing the equations of motion. This method acts as a
|
| 597 |
+
utility to produce the correctly-structred pairs of points and vectors
|
| 598 |
+
required so that these can be easily concatenated with other items in
|
| 599 |
+
the list of loads and passed to ``KanesMethod.kanes_equations``. These
|
| 600 |
+
loads are also in the correct form to also be passed to the other
|
| 601 |
+
equations of motion method classes, e.g. ``LagrangesMethod``.
|
| 602 |
+
|
| 603 |
+
Examples
|
| 604 |
+
========
|
| 605 |
+
|
| 606 |
+
The below example shows how to generate the loads produced in an
|
| 607 |
+
actuator that produces an expansile force ``F`` while wrapping around a
|
| 608 |
+
cylinder. First, create a cylinder with radius ``r`` and an axis
|
| 609 |
+
parallel to the ``N.z`` direction of the global frame ``N`` that also
|
| 610 |
+
passes through a point ``pO``.
|
| 611 |
+
|
| 612 |
+
>>> from sympy import symbols
|
| 613 |
+
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
|
| 614 |
+
... WrappingCylinder)
|
| 615 |
+
>>> N = ReferenceFrame('N')
|
| 616 |
+
>>> r = symbols('r', positive=True)
|
| 617 |
+
>>> pO = Point('pO')
|
| 618 |
+
>>> cylinder = WrappingCylinder(r, pO, N.z)
|
| 619 |
+
|
| 620 |
+
Create the pathway of the actuator using the ``WrappingPathway`` class,
|
| 621 |
+
defined to span between two points ``pA`` and ``pB``. Both points lie
|
| 622 |
+
on the surface of the cylinder and the location of ``pB`` is defined
|
| 623 |
+
relative to ``pA`` by the dynamics symbol ``q``.
|
| 624 |
+
|
| 625 |
+
>>> from sympy import cos, sin
|
| 626 |
+
>>> from sympy.physics.mechanics import WrappingPathway, dynamicsymbols
|
| 627 |
+
>>> q = dynamicsymbols('q')
|
| 628 |
+
>>> pA = Point('pA')
|
| 629 |
+
>>> pB = Point('pB')
|
| 630 |
+
>>> pA.set_pos(pO, r*N.x)
|
| 631 |
+
>>> pB.set_pos(pO, r*(cos(q)*N.x + sin(q)*N.y))
|
| 632 |
+
>>> pB.pos_from(pA)
|
| 633 |
+
(r*cos(q(t)) - r)*N.x + r*sin(q(t))*N.y
|
| 634 |
+
>>> pathway = WrappingPathway(pA, pB, cylinder)
|
| 635 |
+
|
| 636 |
+
Now create a symbol ``F`` to describe the magnitude of the (expansile)
|
| 637 |
+
force that will be produced along the pathway. The list of loads that
|
| 638 |
+
``KanesMethod`` requires can be produced by calling the pathway's
|
| 639 |
+
``to_loads`` method with ``F`` passed as the only argument.
|
| 640 |
+
|
| 641 |
+
>>> F = symbols('F')
|
| 642 |
+
>>> loads = pathway.to_loads(F)
|
| 643 |
+
>>> [load.__class__(load.location, load.vector.simplify()) for load in loads]
|
| 644 |
+
[(pA, F*N.y), (pB, F*sin(q(t))*N.x - F*cos(q(t))*N.y),
|
| 645 |
+
(pO, - F*sin(q(t))*N.x + F*(cos(q(t)) - 1)*N.y)]
|
| 646 |
+
|
| 647 |
+
Parameters
|
| 648 |
+
==========
|
| 649 |
+
|
| 650 |
+
force : Expr
|
| 651 |
+
Magnitude of the force acting along the length of the pathway. It
|
| 652 |
+
is assumed that this ``Expr`` represents an expansile force.
|
| 653 |
+
|
| 654 |
+
"""
|
| 655 |
+
pA, pB = self.attachments
|
| 656 |
+
pO = self.geometry.point
|
| 657 |
+
pA_force, pB_force = self.geometry.geodesic_end_vectors(pA, pB)
|
| 658 |
+
pO_force = -(pA_force + pB_force)
|
| 659 |
+
|
| 660 |
+
loads = [
|
| 661 |
+
Force(pA, force * pA_force),
|
| 662 |
+
Force(pB, force * pB_force),
|
| 663 |
+
Force(pO, force * pO_force),
|
| 664 |
+
]
|
| 665 |
+
return loads
|
| 666 |
+
|
| 667 |
+
def __repr__(self):
|
| 668 |
+
"""Representation of a ``WrappingPathway``."""
|
| 669 |
+
attachments = ', '.join(str(a) for a in self.attachments)
|
| 670 |
+
return (
|
| 671 |
+
f'{self.__class__.__name__}({attachments}, '
|
| 672 |
+
f'geometry={self.geometry})'
|
| 673 |
+
)
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def _point_pair_relative_position(point_1, point_2):
|
| 677 |
+
"""The relative position between a pair of points."""
|
| 678 |
+
return point_2.pos_from(point_1)
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
def _point_pair_length(point_1, point_2):
|
| 682 |
+
"""The length of the direct linear path between two points."""
|
| 683 |
+
return _point_pair_relative_position(point_1, point_2).magnitude()
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
def _point_pair_extension_velocity(point_1, point_2):
|
| 687 |
+
"""The extension velocity of the direct linear path between two points."""
|
| 688 |
+
return _point_pair_length(point_1, point_2).diff(dynamicsymbols._t)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/rigidbody.py
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import Symbol, S
|
| 2 |
+
from sympy.physics.vector import ReferenceFrame, Dyadic, Point, dot
|
| 3 |
+
from sympy.physics.mechanics.body_base import BodyBase
|
| 4 |
+
from sympy.physics.mechanics.inertia import inertia_of_point_mass, Inertia
|
| 5 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 6 |
+
|
| 7 |
+
__all__ = ['RigidBody']
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class RigidBody(BodyBase):
|
| 11 |
+
"""An idealized rigid body.
|
| 12 |
+
|
| 13 |
+
Explanation
|
| 14 |
+
===========
|
| 15 |
+
|
| 16 |
+
This is essentially a container which holds the various components which
|
| 17 |
+
describe a rigid body: a name, mass, center of mass, reference frame, and
|
| 18 |
+
inertia.
|
| 19 |
+
|
| 20 |
+
All of these need to be supplied on creation, but can be changed
|
| 21 |
+
afterwards.
|
| 22 |
+
|
| 23 |
+
Attributes
|
| 24 |
+
==========
|
| 25 |
+
|
| 26 |
+
name : string
|
| 27 |
+
The body's name.
|
| 28 |
+
masscenter : Point
|
| 29 |
+
The point which represents the center of mass of the rigid body.
|
| 30 |
+
frame : ReferenceFrame
|
| 31 |
+
The ReferenceFrame which the rigid body is fixed in.
|
| 32 |
+
mass : Sympifyable
|
| 33 |
+
The body's mass.
|
| 34 |
+
inertia : (Dyadic, Point)
|
| 35 |
+
The body's inertia about a point; stored in a tuple as shown above.
|
| 36 |
+
potential_energy : Sympifyable
|
| 37 |
+
The potential energy of the RigidBody.
|
| 38 |
+
|
| 39 |
+
Examples
|
| 40 |
+
========
|
| 41 |
+
|
| 42 |
+
>>> from sympy import Symbol
|
| 43 |
+
>>> from sympy.physics.mechanics import ReferenceFrame, Point, RigidBody
|
| 44 |
+
>>> from sympy.physics.mechanics import outer
|
| 45 |
+
>>> m = Symbol('m')
|
| 46 |
+
>>> A = ReferenceFrame('A')
|
| 47 |
+
>>> P = Point('P')
|
| 48 |
+
>>> I = outer (A.x, A.x)
|
| 49 |
+
>>> inertia_tuple = (I, P)
|
| 50 |
+
>>> B = RigidBody('B', P, A, m, inertia_tuple)
|
| 51 |
+
>>> # Or you could change them afterwards
|
| 52 |
+
>>> m2 = Symbol('m2')
|
| 53 |
+
>>> B.mass = m2
|
| 54 |
+
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def __init__(self, name, masscenter=None, frame=None, mass=None,
|
| 58 |
+
inertia=None):
|
| 59 |
+
super().__init__(name, masscenter, mass)
|
| 60 |
+
if frame is None:
|
| 61 |
+
frame = ReferenceFrame(f'{name}_frame')
|
| 62 |
+
self.frame = frame
|
| 63 |
+
if inertia is None:
|
| 64 |
+
ixx = Symbol(f'{name}_ixx')
|
| 65 |
+
iyy = Symbol(f'{name}_iyy')
|
| 66 |
+
izz = Symbol(f'{name}_izz')
|
| 67 |
+
izx = Symbol(f'{name}_izx')
|
| 68 |
+
ixy = Symbol(f'{name}_ixy')
|
| 69 |
+
iyz = Symbol(f'{name}_iyz')
|
| 70 |
+
inertia = Inertia.from_inertia_scalars(self.masscenter, self.frame,
|
| 71 |
+
ixx, iyy, izz, ixy, iyz, izx)
|
| 72 |
+
self.inertia = inertia
|
| 73 |
+
|
| 74 |
+
def __repr__(self):
|
| 75 |
+
return (f'{self.__class__.__name__}({repr(self.name)}, masscenter='
|
| 76 |
+
f'{repr(self.masscenter)}, frame={repr(self.frame)}, mass='
|
| 77 |
+
f'{repr(self.mass)}, inertia={repr(self.inertia)})')
|
| 78 |
+
|
| 79 |
+
@property
|
| 80 |
+
def frame(self):
|
| 81 |
+
"""The ReferenceFrame fixed to the body."""
|
| 82 |
+
return self._frame
|
| 83 |
+
|
| 84 |
+
@frame.setter
|
| 85 |
+
def frame(self, F):
|
| 86 |
+
if not isinstance(F, ReferenceFrame):
|
| 87 |
+
raise TypeError("RigidBody frame must be a ReferenceFrame object.")
|
| 88 |
+
self._frame = F
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def x(self):
|
| 92 |
+
"""The basis Vector for the body, in the x direction. """
|
| 93 |
+
return self.frame.x
|
| 94 |
+
|
| 95 |
+
@property
|
| 96 |
+
def y(self):
|
| 97 |
+
"""The basis Vector for the body, in the y direction. """
|
| 98 |
+
return self.frame.y
|
| 99 |
+
|
| 100 |
+
@property
|
| 101 |
+
def z(self):
|
| 102 |
+
"""The basis Vector for the body, in the z direction. """
|
| 103 |
+
return self.frame.z
|
| 104 |
+
|
| 105 |
+
@property
|
| 106 |
+
def inertia(self):
|
| 107 |
+
"""The body's inertia about a point; stored as (Dyadic, Point)."""
|
| 108 |
+
return self._inertia
|
| 109 |
+
|
| 110 |
+
@inertia.setter
|
| 111 |
+
def inertia(self, I):
|
| 112 |
+
# check if I is of the form (Dyadic, Point)
|
| 113 |
+
if len(I) != 2 or not isinstance(I[0], Dyadic) or not isinstance(I[1], Point):
|
| 114 |
+
raise TypeError("RigidBody inertia must be a tuple of the form (Dyadic, Point).")
|
| 115 |
+
|
| 116 |
+
self._inertia = Inertia(I[0], I[1])
|
| 117 |
+
# have I S/O, want I S/S*
|
| 118 |
+
# I S/O = I S/S* + I S*/O; I S/S* = I S/O - I S*/O
|
| 119 |
+
# I_S/S* = I_S/O - I_S*/O
|
| 120 |
+
I_Ss_O = inertia_of_point_mass(self.mass,
|
| 121 |
+
self.masscenter.pos_from(I[1]),
|
| 122 |
+
self.frame)
|
| 123 |
+
self._central_inertia = I[0] - I_Ss_O
|
| 124 |
+
|
| 125 |
+
@property
|
| 126 |
+
def central_inertia(self):
|
| 127 |
+
"""The body's central inertia dyadic."""
|
| 128 |
+
return self._central_inertia
|
| 129 |
+
|
| 130 |
+
@central_inertia.setter
|
| 131 |
+
def central_inertia(self, I):
|
| 132 |
+
if not isinstance(I, Dyadic):
|
| 133 |
+
raise TypeError("RigidBody inertia must be a Dyadic object.")
|
| 134 |
+
self.inertia = Inertia(I, self.masscenter)
|
| 135 |
+
|
| 136 |
+
def linear_momentum(self, frame):
|
| 137 |
+
""" Linear momentum of the rigid body.
|
| 138 |
+
|
| 139 |
+
Explanation
|
| 140 |
+
===========
|
| 141 |
+
|
| 142 |
+
The linear momentum L, of a rigid body B, with respect to frame N is
|
| 143 |
+
given by:
|
| 144 |
+
|
| 145 |
+
``L = m * v``
|
| 146 |
+
|
| 147 |
+
where m is the mass of the rigid body, and v is the velocity of the mass
|
| 148 |
+
center of B in the frame N.
|
| 149 |
+
|
| 150 |
+
Parameters
|
| 151 |
+
==========
|
| 152 |
+
|
| 153 |
+
frame : ReferenceFrame
|
| 154 |
+
The frame in which linear momentum is desired.
|
| 155 |
+
|
| 156 |
+
Examples
|
| 157 |
+
========
|
| 158 |
+
|
| 159 |
+
>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
|
| 160 |
+
>>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
|
| 161 |
+
>>> from sympy.physics.vector import init_vprinting
|
| 162 |
+
>>> init_vprinting(pretty_print=False)
|
| 163 |
+
>>> m, v = dynamicsymbols('m v')
|
| 164 |
+
>>> N = ReferenceFrame('N')
|
| 165 |
+
>>> P = Point('P')
|
| 166 |
+
>>> P.set_vel(N, v * N.x)
|
| 167 |
+
>>> I = outer (N.x, N.x)
|
| 168 |
+
>>> Inertia_tuple = (I, P)
|
| 169 |
+
>>> B = RigidBody('B', P, N, m, Inertia_tuple)
|
| 170 |
+
>>> B.linear_momentum(N)
|
| 171 |
+
m*v*N.x
|
| 172 |
+
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
return self.mass * self.masscenter.vel(frame)
|
| 176 |
+
|
| 177 |
+
def angular_momentum(self, point, frame):
|
| 178 |
+
"""Returns the angular momentum of the rigid body about a point in the
|
| 179 |
+
given frame.
|
| 180 |
+
|
| 181 |
+
Explanation
|
| 182 |
+
===========
|
| 183 |
+
|
| 184 |
+
The angular momentum H of a rigid body B about some point O in a frame N
|
| 185 |
+
is given by:
|
| 186 |
+
|
| 187 |
+
``H = dot(I, w) + cross(r, m * v)``
|
| 188 |
+
|
| 189 |
+
where I and m are the central inertia dyadic and mass of rigid body B, w
|
| 190 |
+
is the angular velocity of body B in the frame N, r is the position
|
| 191 |
+
vector from point O to the mass center of B, and v is the velocity of
|
| 192 |
+
the mass center in the frame N.
|
| 193 |
+
|
| 194 |
+
Parameters
|
| 195 |
+
==========
|
| 196 |
+
|
| 197 |
+
point : Point
|
| 198 |
+
The point about which angular momentum is desired.
|
| 199 |
+
frame : ReferenceFrame
|
| 200 |
+
The frame in which angular momentum is desired.
|
| 201 |
+
|
| 202 |
+
Examples
|
| 203 |
+
========
|
| 204 |
+
|
| 205 |
+
>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
|
| 206 |
+
>>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
|
| 207 |
+
>>> from sympy.physics.vector import init_vprinting
|
| 208 |
+
>>> init_vprinting(pretty_print=False)
|
| 209 |
+
>>> m, v, r, omega = dynamicsymbols('m v r omega')
|
| 210 |
+
>>> N = ReferenceFrame('N')
|
| 211 |
+
>>> b = ReferenceFrame('b')
|
| 212 |
+
>>> b.set_ang_vel(N, omega * b.x)
|
| 213 |
+
>>> P = Point('P')
|
| 214 |
+
>>> P.set_vel(N, 1 * N.x)
|
| 215 |
+
>>> I = outer(b.x, b.x)
|
| 216 |
+
>>> B = RigidBody('B', P, b, m, (I, P))
|
| 217 |
+
>>> B.angular_momentum(P, N)
|
| 218 |
+
omega*b.x
|
| 219 |
+
|
| 220 |
+
"""
|
| 221 |
+
I = self.central_inertia
|
| 222 |
+
w = self.frame.ang_vel_in(frame)
|
| 223 |
+
m = self.mass
|
| 224 |
+
r = self.masscenter.pos_from(point)
|
| 225 |
+
v = self.masscenter.vel(frame)
|
| 226 |
+
|
| 227 |
+
return I.dot(w) + r.cross(m * v)
|
| 228 |
+
|
| 229 |
+
def kinetic_energy(self, frame):
|
| 230 |
+
"""Kinetic energy of the rigid body.
|
| 231 |
+
|
| 232 |
+
Explanation
|
| 233 |
+
===========
|
| 234 |
+
|
| 235 |
+
The kinetic energy, T, of a rigid body, B, is given by:
|
| 236 |
+
|
| 237 |
+
``T = 1/2 * (dot(dot(I, w), w) + dot(m * v, v))``
|
| 238 |
+
|
| 239 |
+
where I and m are the central inertia dyadic and mass of rigid body B
|
| 240 |
+
respectively, w is the body's angular velocity, and v is the velocity of
|
| 241 |
+
the body's mass center in the supplied ReferenceFrame.
|
| 242 |
+
|
| 243 |
+
Parameters
|
| 244 |
+
==========
|
| 245 |
+
|
| 246 |
+
frame : ReferenceFrame
|
| 247 |
+
The RigidBody's angular velocity and the velocity of it's mass
|
| 248 |
+
center are typically defined with respect to an inertial frame but
|
| 249 |
+
any relevant frame in which the velocities are known can be
|
| 250 |
+
supplied.
|
| 251 |
+
|
| 252 |
+
Examples
|
| 253 |
+
========
|
| 254 |
+
|
| 255 |
+
>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
|
| 256 |
+
>>> from sympy.physics.mechanics import RigidBody
|
| 257 |
+
>>> from sympy import symbols
|
| 258 |
+
>>> m, v, r, omega = symbols('m v r omega')
|
| 259 |
+
>>> N = ReferenceFrame('N')
|
| 260 |
+
>>> b = ReferenceFrame('b')
|
| 261 |
+
>>> b.set_ang_vel(N, omega * b.x)
|
| 262 |
+
>>> P = Point('P')
|
| 263 |
+
>>> P.set_vel(N, v * N.x)
|
| 264 |
+
>>> I = outer (b.x, b.x)
|
| 265 |
+
>>> inertia_tuple = (I, P)
|
| 266 |
+
>>> B = RigidBody('B', P, b, m, inertia_tuple)
|
| 267 |
+
>>> B.kinetic_energy(N)
|
| 268 |
+
m*v**2/2 + omega**2/2
|
| 269 |
+
|
| 270 |
+
"""
|
| 271 |
+
|
| 272 |
+
rotational_KE = S.Half * dot(
|
| 273 |
+
self.frame.ang_vel_in(frame),
|
| 274 |
+
dot(self.central_inertia, self.frame.ang_vel_in(frame)))
|
| 275 |
+
translational_KE = S.Half * self.mass * dot(self.masscenter.vel(frame),
|
| 276 |
+
self.masscenter.vel(frame))
|
| 277 |
+
return rotational_KE + translational_KE
|
| 278 |
+
|
| 279 |
+
def set_potential_energy(self, scalar):
|
| 280 |
+
sympy_deprecation_warning(
|
| 281 |
+
"""
|
| 282 |
+
The sympy.physics.mechanics.RigidBody.set_potential_energy()
|
| 283 |
+
method is deprecated. Instead use
|
| 284 |
+
|
| 285 |
+
B.potential_energy = scalar
|
| 286 |
+
""",
|
| 287 |
+
deprecated_since_version="1.5",
|
| 288 |
+
active_deprecations_target="deprecated-set-potential-energy",
|
| 289 |
+
)
|
| 290 |
+
self.potential_energy = scalar
|
| 291 |
+
|
| 292 |
+
def parallel_axis(self, point, frame=None):
|
| 293 |
+
"""Returns the inertia dyadic of the body with respect to another point.
|
| 294 |
+
|
| 295 |
+
Parameters
|
| 296 |
+
==========
|
| 297 |
+
|
| 298 |
+
point : sympy.physics.vector.Point
|
| 299 |
+
The point to express the inertia dyadic about.
|
| 300 |
+
frame : sympy.physics.vector.ReferenceFrame
|
| 301 |
+
The reference frame used to construct the dyadic.
|
| 302 |
+
|
| 303 |
+
Returns
|
| 304 |
+
=======
|
| 305 |
+
|
| 306 |
+
inertia : sympy.physics.vector.Dyadic
|
| 307 |
+
The inertia dyadic of the rigid body expressed about the provided
|
| 308 |
+
point.
|
| 309 |
+
|
| 310 |
+
"""
|
| 311 |
+
if frame is None:
|
| 312 |
+
frame = self.frame
|
| 313 |
+
return self.central_inertia + inertia_of_point_mass(
|
| 314 |
+
self.mass, self.masscenter.pos_from(point), frame)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/__init__.py
ADDED
|
File without changes
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/__pycache__/test_kane3.cpython-310.pyc
ADDED
|
Binary file (5.43 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_actuator.py
ADDED
|
@@ -0,0 +1,851 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for the ``sympy.physics.mechanics.actuator.py`` module."""
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from sympy import (
|
| 6 |
+
S,
|
| 7 |
+
Matrix,
|
| 8 |
+
Symbol,
|
| 9 |
+
SympifyError,
|
| 10 |
+
sqrt,
|
| 11 |
+
Abs
|
| 12 |
+
)
|
| 13 |
+
from sympy.physics.mechanics import (
|
| 14 |
+
ActuatorBase,
|
| 15 |
+
Force,
|
| 16 |
+
ForceActuator,
|
| 17 |
+
KanesMethod,
|
| 18 |
+
LinearDamper,
|
| 19 |
+
LinearPathway,
|
| 20 |
+
LinearSpring,
|
| 21 |
+
Particle,
|
| 22 |
+
PinJoint,
|
| 23 |
+
Point,
|
| 24 |
+
ReferenceFrame,
|
| 25 |
+
RigidBody,
|
| 26 |
+
TorqueActuator,
|
| 27 |
+
Vector,
|
| 28 |
+
dynamicsymbols,
|
| 29 |
+
DuffingSpring,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
from sympy.core.expr import Expr as ExprType
|
| 33 |
+
|
| 34 |
+
target = RigidBody('target')
|
| 35 |
+
reaction = RigidBody('reaction')
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class TestForceActuator:
|
| 39 |
+
|
| 40 |
+
@pytest.fixture(autouse=True)
|
| 41 |
+
def _linear_pathway_fixture(self):
|
| 42 |
+
self.force = Symbol('F')
|
| 43 |
+
self.pA = Point('pA')
|
| 44 |
+
self.pB = Point('pB')
|
| 45 |
+
self.pathway = LinearPathway(self.pA, self.pB)
|
| 46 |
+
self.q1 = dynamicsymbols('q1')
|
| 47 |
+
self.q2 = dynamicsymbols('q2')
|
| 48 |
+
self.q3 = dynamicsymbols('q3')
|
| 49 |
+
self.q1d = dynamicsymbols('q1', 1)
|
| 50 |
+
self.q2d = dynamicsymbols('q2', 1)
|
| 51 |
+
self.q3d = dynamicsymbols('q3', 1)
|
| 52 |
+
self.N = ReferenceFrame('N')
|
| 53 |
+
|
| 54 |
+
def test_is_actuator_base_subclass(self):
|
| 55 |
+
assert issubclass(ForceActuator, ActuatorBase)
|
| 56 |
+
|
| 57 |
+
@pytest.mark.parametrize(
|
| 58 |
+
'force, expected_force',
|
| 59 |
+
[
|
| 60 |
+
(1, S.One),
|
| 61 |
+
(S.One, S.One),
|
| 62 |
+
(Symbol('F'), Symbol('F')),
|
| 63 |
+
(dynamicsymbols('F'), dynamicsymbols('F')),
|
| 64 |
+
(Symbol('F')**2 + Symbol('F'), Symbol('F')**2 + Symbol('F')),
|
| 65 |
+
]
|
| 66 |
+
)
|
| 67 |
+
def test_valid_constructor_force(self, force, expected_force):
|
| 68 |
+
instance = ForceActuator(force, self.pathway)
|
| 69 |
+
assert isinstance(instance, ForceActuator)
|
| 70 |
+
assert hasattr(instance, 'force')
|
| 71 |
+
assert isinstance(instance.force, ExprType)
|
| 72 |
+
assert instance.force == expected_force
|
| 73 |
+
|
| 74 |
+
@pytest.mark.parametrize('force', [None, 'F'])
|
| 75 |
+
def test_invalid_constructor_force_not_sympifyable(self, force):
|
| 76 |
+
with pytest.raises(SympifyError):
|
| 77 |
+
_ = ForceActuator(force, self.pathway)
|
| 78 |
+
|
| 79 |
+
@pytest.mark.parametrize(
|
| 80 |
+
'pathway',
|
| 81 |
+
[
|
| 82 |
+
LinearPathway(Point('pA'), Point('pB')),
|
| 83 |
+
]
|
| 84 |
+
)
|
| 85 |
+
def test_valid_constructor_pathway(self, pathway):
|
| 86 |
+
instance = ForceActuator(self.force, pathway)
|
| 87 |
+
assert isinstance(instance, ForceActuator)
|
| 88 |
+
assert hasattr(instance, 'pathway')
|
| 89 |
+
assert isinstance(instance.pathway, LinearPathway)
|
| 90 |
+
assert instance.pathway == pathway
|
| 91 |
+
|
| 92 |
+
def test_invalid_constructor_pathway_not_pathway_base(self):
|
| 93 |
+
with pytest.raises(TypeError):
|
| 94 |
+
_ = ForceActuator(self.force, None)
|
| 95 |
+
|
| 96 |
+
@pytest.mark.parametrize(
|
| 97 |
+
'property_name, fixture_attr_name',
|
| 98 |
+
[
|
| 99 |
+
('force', 'force'),
|
| 100 |
+
('pathway', 'pathway'),
|
| 101 |
+
]
|
| 102 |
+
)
|
| 103 |
+
def test_properties_are_immutable(self, property_name, fixture_attr_name):
|
| 104 |
+
instance = ForceActuator(self.force, self.pathway)
|
| 105 |
+
value = getattr(self, fixture_attr_name)
|
| 106 |
+
with pytest.raises(AttributeError):
|
| 107 |
+
setattr(instance, property_name, value)
|
| 108 |
+
|
| 109 |
+
def test_repr(self):
|
| 110 |
+
actuator = ForceActuator(self.force, self.pathway)
|
| 111 |
+
expected = "ForceActuator(F, LinearPathway(pA, pB))"
|
| 112 |
+
assert repr(actuator) == expected
|
| 113 |
+
|
| 114 |
+
def test_to_loads_static_pathway(self):
|
| 115 |
+
self.pB.set_pos(self.pA, 2*self.N.x)
|
| 116 |
+
actuator = ForceActuator(self.force, self.pathway)
|
| 117 |
+
expected = [
|
| 118 |
+
(self.pA, - self.force*self.N.x),
|
| 119 |
+
(self.pB, self.force*self.N.x),
|
| 120 |
+
]
|
| 121 |
+
assert actuator.to_loads() == expected
|
| 122 |
+
|
| 123 |
+
def test_to_loads_2D_pathway(self):
|
| 124 |
+
self.pB.set_pos(self.pA, 2*self.q1*self.N.x)
|
| 125 |
+
actuator = ForceActuator(self.force, self.pathway)
|
| 126 |
+
expected = [
|
| 127 |
+
(self.pA, - self.force*(self.q1/sqrt(self.q1**2))*self.N.x),
|
| 128 |
+
(self.pB, self.force*(self.q1/sqrt(self.q1**2))*self.N.x),
|
| 129 |
+
]
|
| 130 |
+
assert actuator.to_loads() == expected
|
| 131 |
+
|
| 132 |
+
def test_to_loads_3D_pathway(self):
|
| 133 |
+
self.pB.set_pos(
|
| 134 |
+
self.pA,
|
| 135 |
+
self.q1*self.N.x - self.q2*self.N.y + 2*self.q3*self.N.z,
|
| 136 |
+
)
|
| 137 |
+
actuator = ForceActuator(self.force, self.pathway)
|
| 138 |
+
length = sqrt(self.q1**2 + self.q2**2 + 4*self.q3**2)
|
| 139 |
+
pO_force = (
|
| 140 |
+
- self.force*self.q1*self.N.x/length
|
| 141 |
+
+ self.force*self.q2*self.N.y/length
|
| 142 |
+
- 2*self.force*self.q3*self.N.z/length
|
| 143 |
+
)
|
| 144 |
+
pI_force = (
|
| 145 |
+
self.force*self.q1*self.N.x/length
|
| 146 |
+
- self.force*self.q2*self.N.y/length
|
| 147 |
+
+ 2*self.force*self.q3*self.N.z/length
|
| 148 |
+
)
|
| 149 |
+
expected = [
|
| 150 |
+
(self.pA, pO_force),
|
| 151 |
+
(self.pB, pI_force),
|
| 152 |
+
]
|
| 153 |
+
assert actuator.to_loads() == expected
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
class TestLinearSpring:
|
| 157 |
+
|
| 158 |
+
@pytest.fixture(autouse=True)
|
| 159 |
+
def _linear_spring_fixture(self):
|
| 160 |
+
self.stiffness = Symbol('k')
|
| 161 |
+
self.l = Symbol('l')
|
| 162 |
+
self.pA = Point('pA')
|
| 163 |
+
self.pB = Point('pB')
|
| 164 |
+
self.pathway = LinearPathway(self.pA, self.pB)
|
| 165 |
+
self.q = dynamicsymbols('q')
|
| 166 |
+
self.N = ReferenceFrame('N')
|
| 167 |
+
|
| 168 |
+
def test_is_force_actuator_subclass(self):
|
| 169 |
+
assert issubclass(LinearSpring, ForceActuator)
|
| 170 |
+
|
| 171 |
+
def test_is_actuator_base_subclass(self):
|
| 172 |
+
assert issubclass(LinearSpring, ActuatorBase)
|
| 173 |
+
|
| 174 |
+
@pytest.mark.parametrize(
|
| 175 |
+
(
|
| 176 |
+
'stiffness, '
|
| 177 |
+
'expected_stiffness, '
|
| 178 |
+
'equilibrium_length, '
|
| 179 |
+
'expected_equilibrium_length, '
|
| 180 |
+
'force'
|
| 181 |
+
),
|
| 182 |
+
[
|
| 183 |
+
(
|
| 184 |
+
1,
|
| 185 |
+
S.One,
|
| 186 |
+
0,
|
| 187 |
+
S.Zero,
|
| 188 |
+
-sqrt(dynamicsymbols('q')**2),
|
| 189 |
+
),
|
| 190 |
+
(
|
| 191 |
+
Symbol('k'),
|
| 192 |
+
Symbol('k'),
|
| 193 |
+
0,
|
| 194 |
+
S.Zero,
|
| 195 |
+
-Symbol('k')*sqrt(dynamicsymbols('q')**2),
|
| 196 |
+
),
|
| 197 |
+
(
|
| 198 |
+
Symbol('k'),
|
| 199 |
+
Symbol('k'),
|
| 200 |
+
S.Zero,
|
| 201 |
+
S.Zero,
|
| 202 |
+
-Symbol('k')*sqrt(dynamicsymbols('q')**2),
|
| 203 |
+
),
|
| 204 |
+
(
|
| 205 |
+
Symbol('k'),
|
| 206 |
+
Symbol('k'),
|
| 207 |
+
Symbol('l'),
|
| 208 |
+
Symbol('l'),
|
| 209 |
+
-Symbol('k')*(sqrt(dynamicsymbols('q')**2) - Symbol('l')),
|
| 210 |
+
),
|
| 211 |
+
]
|
| 212 |
+
)
|
| 213 |
+
def test_valid_constructor(
|
| 214 |
+
self,
|
| 215 |
+
stiffness,
|
| 216 |
+
expected_stiffness,
|
| 217 |
+
equilibrium_length,
|
| 218 |
+
expected_equilibrium_length,
|
| 219 |
+
force,
|
| 220 |
+
):
|
| 221 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 222 |
+
spring = LinearSpring(stiffness, self.pathway, equilibrium_length)
|
| 223 |
+
|
| 224 |
+
assert isinstance(spring, LinearSpring)
|
| 225 |
+
|
| 226 |
+
assert hasattr(spring, 'stiffness')
|
| 227 |
+
assert isinstance(spring.stiffness, ExprType)
|
| 228 |
+
assert spring.stiffness == expected_stiffness
|
| 229 |
+
|
| 230 |
+
assert hasattr(spring, 'pathway')
|
| 231 |
+
assert isinstance(spring.pathway, LinearPathway)
|
| 232 |
+
assert spring.pathway == self.pathway
|
| 233 |
+
|
| 234 |
+
assert hasattr(spring, 'equilibrium_length')
|
| 235 |
+
assert isinstance(spring.equilibrium_length, ExprType)
|
| 236 |
+
assert spring.equilibrium_length == expected_equilibrium_length
|
| 237 |
+
|
| 238 |
+
assert hasattr(spring, 'force')
|
| 239 |
+
assert isinstance(spring.force, ExprType)
|
| 240 |
+
assert spring.force == force
|
| 241 |
+
|
| 242 |
+
@pytest.mark.parametrize('stiffness', [None, 'k'])
|
| 243 |
+
def test_invalid_constructor_stiffness_not_sympifyable(self, stiffness):
|
| 244 |
+
with pytest.raises(SympifyError):
|
| 245 |
+
_ = LinearSpring(stiffness, self.pathway, self.l)
|
| 246 |
+
|
| 247 |
+
def test_invalid_constructor_pathway_not_pathway_base(self):
|
| 248 |
+
with pytest.raises(TypeError):
|
| 249 |
+
_ = LinearSpring(self.stiffness, None, self.l)
|
| 250 |
+
|
| 251 |
+
@pytest.mark.parametrize('equilibrium_length', [None, 'l'])
|
| 252 |
+
def test_invalid_constructor_equilibrium_length_not_sympifyable(
|
| 253 |
+
self,
|
| 254 |
+
equilibrium_length,
|
| 255 |
+
):
|
| 256 |
+
with pytest.raises(SympifyError):
|
| 257 |
+
_ = LinearSpring(self.stiffness, self.pathway, equilibrium_length)
|
| 258 |
+
|
| 259 |
+
@pytest.mark.parametrize(
|
| 260 |
+
'property_name, fixture_attr_name',
|
| 261 |
+
[
|
| 262 |
+
('stiffness', 'stiffness'),
|
| 263 |
+
('pathway', 'pathway'),
|
| 264 |
+
('equilibrium_length', 'l'),
|
| 265 |
+
]
|
| 266 |
+
)
|
| 267 |
+
def test_properties_are_immutable(self, property_name, fixture_attr_name):
|
| 268 |
+
spring = LinearSpring(self.stiffness, self.pathway, self.l)
|
| 269 |
+
value = getattr(self, fixture_attr_name)
|
| 270 |
+
with pytest.raises(AttributeError):
|
| 271 |
+
setattr(spring, property_name, value)
|
| 272 |
+
|
| 273 |
+
@pytest.mark.parametrize(
|
| 274 |
+
'equilibrium_length, expected',
|
| 275 |
+
[
|
| 276 |
+
(S.Zero, 'LinearSpring(k, LinearPathway(pA, pB))'),
|
| 277 |
+
(
|
| 278 |
+
Symbol('l'),
|
| 279 |
+
'LinearSpring(k, LinearPathway(pA, pB), equilibrium_length=l)',
|
| 280 |
+
),
|
| 281 |
+
]
|
| 282 |
+
)
|
| 283 |
+
def test_repr(self, equilibrium_length, expected):
|
| 284 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 285 |
+
spring = LinearSpring(self.stiffness, self.pathway, equilibrium_length)
|
| 286 |
+
assert repr(spring) == expected
|
| 287 |
+
|
| 288 |
+
def test_to_loads(self):
|
| 289 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 290 |
+
spring = LinearSpring(self.stiffness, self.pathway, self.l)
|
| 291 |
+
normal = self.q/sqrt(self.q**2)*self.N.x
|
| 292 |
+
pA_force = self.stiffness*(sqrt(self.q**2) - self.l)*normal
|
| 293 |
+
pB_force = -self.stiffness*(sqrt(self.q**2) - self.l)*normal
|
| 294 |
+
expected = [Force(self.pA, pA_force), Force(self.pB, pB_force)]
|
| 295 |
+
loads = spring.to_loads()
|
| 296 |
+
|
| 297 |
+
for load, (point, vector) in zip(loads, expected):
|
| 298 |
+
assert isinstance(load, Force)
|
| 299 |
+
assert load.point == point
|
| 300 |
+
assert (load.vector - vector).simplify() == 0
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
class TestLinearDamper:
|
| 304 |
+
|
| 305 |
+
@pytest.fixture(autouse=True)
|
| 306 |
+
def _linear_damper_fixture(self):
|
| 307 |
+
self.damping = Symbol('c')
|
| 308 |
+
self.l = Symbol('l')
|
| 309 |
+
self.pA = Point('pA')
|
| 310 |
+
self.pB = Point('pB')
|
| 311 |
+
self.pathway = LinearPathway(self.pA, self.pB)
|
| 312 |
+
self.q = dynamicsymbols('q')
|
| 313 |
+
self.dq = dynamicsymbols('q', 1)
|
| 314 |
+
self.u = dynamicsymbols('u')
|
| 315 |
+
self.N = ReferenceFrame('N')
|
| 316 |
+
|
| 317 |
+
def test_is_force_actuator_subclass(self):
|
| 318 |
+
assert issubclass(LinearDamper, ForceActuator)
|
| 319 |
+
|
| 320 |
+
def test_is_actuator_base_subclass(self):
|
| 321 |
+
assert issubclass(LinearDamper, ActuatorBase)
|
| 322 |
+
|
| 323 |
+
def test_valid_constructor(self):
|
| 324 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 325 |
+
damper = LinearDamper(self.damping, self.pathway)
|
| 326 |
+
|
| 327 |
+
assert isinstance(damper, LinearDamper)
|
| 328 |
+
|
| 329 |
+
assert hasattr(damper, 'damping')
|
| 330 |
+
assert isinstance(damper.damping, ExprType)
|
| 331 |
+
assert damper.damping == self.damping
|
| 332 |
+
|
| 333 |
+
assert hasattr(damper, 'pathway')
|
| 334 |
+
assert isinstance(damper.pathway, LinearPathway)
|
| 335 |
+
assert damper.pathway == self.pathway
|
| 336 |
+
|
| 337 |
+
def test_valid_constructor_force(self):
|
| 338 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 339 |
+
damper = LinearDamper(self.damping, self.pathway)
|
| 340 |
+
|
| 341 |
+
expected_force = -self.damping*sqrt(self.q**2)*self.dq/self.q
|
| 342 |
+
assert hasattr(damper, 'force')
|
| 343 |
+
assert isinstance(damper.force, ExprType)
|
| 344 |
+
assert damper.force == expected_force
|
| 345 |
+
|
| 346 |
+
@pytest.mark.parametrize('damping', [None, 'c'])
|
| 347 |
+
def test_invalid_constructor_damping_not_sympifyable(self, damping):
|
| 348 |
+
with pytest.raises(SympifyError):
|
| 349 |
+
_ = LinearDamper(damping, self.pathway)
|
| 350 |
+
|
| 351 |
+
def test_invalid_constructor_pathway_not_pathway_base(self):
|
| 352 |
+
with pytest.raises(TypeError):
|
| 353 |
+
_ = LinearDamper(self.damping, None)
|
| 354 |
+
|
| 355 |
+
@pytest.mark.parametrize(
|
| 356 |
+
'property_name, fixture_attr_name',
|
| 357 |
+
[
|
| 358 |
+
('damping', 'damping'),
|
| 359 |
+
('pathway', 'pathway'),
|
| 360 |
+
]
|
| 361 |
+
)
|
| 362 |
+
def test_properties_are_immutable(self, property_name, fixture_attr_name):
|
| 363 |
+
damper = LinearDamper(self.damping, self.pathway)
|
| 364 |
+
value = getattr(self, fixture_attr_name)
|
| 365 |
+
with pytest.raises(AttributeError):
|
| 366 |
+
setattr(damper, property_name, value)
|
| 367 |
+
|
| 368 |
+
def test_repr(self):
|
| 369 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 370 |
+
damper = LinearDamper(self.damping, self.pathway)
|
| 371 |
+
expected = 'LinearDamper(c, LinearPathway(pA, pB))'
|
| 372 |
+
assert repr(damper) == expected
|
| 373 |
+
|
| 374 |
+
def test_to_loads(self):
|
| 375 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 376 |
+
damper = LinearDamper(self.damping, self.pathway)
|
| 377 |
+
direction = self.q**2/self.q**2*self.N.x
|
| 378 |
+
pA_force = self.damping*self.dq*direction
|
| 379 |
+
pB_force = -self.damping*self.dq*direction
|
| 380 |
+
expected = [Force(self.pA, pA_force), Force(self.pB, pB_force)]
|
| 381 |
+
assert damper.to_loads() == expected
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class TestForcedMassSpringDamperModel():
|
| 385 |
+
r"""A single degree of freedom translational forced mass-spring-damper.
|
| 386 |
+
|
| 387 |
+
Notes
|
| 388 |
+
=====
|
| 389 |
+
|
| 390 |
+
This system is well known to have the governing equation:
|
| 391 |
+
|
| 392 |
+
.. math::
|
| 393 |
+
m \ddot{x} = F - k x - c \dot{x}
|
| 394 |
+
|
| 395 |
+
where $F$ is an externally applied force, $m$ is the mass of the particle
|
| 396 |
+
to which the spring and damper are attached, $k$ is the spring's stiffness,
|
| 397 |
+
$c$ is the dampers damping coefficient, and $x$ is the generalized
|
| 398 |
+
coordinate representing the system's single (translational) degree of
|
| 399 |
+
freedom.
|
| 400 |
+
|
| 401 |
+
"""
|
| 402 |
+
|
| 403 |
+
@pytest.fixture(autouse=True)
|
| 404 |
+
def _force_mass_spring_damper_model_fixture(self):
|
| 405 |
+
self.m = Symbol('m')
|
| 406 |
+
self.k = Symbol('k')
|
| 407 |
+
self.c = Symbol('c')
|
| 408 |
+
self.F = Symbol('F')
|
| 409 |
+
|
| 410 |
+
self.q = dynamicsymbols('q')
|
| 411 |
+
self.dq = dynamicsymbols('q', 1)
|
| 412 |
+
self.u = dynamicsymbols('u')
|
| 413 |
+
|
| 414 |
+
self.frame = ReferenceFrame('N')
|
| 415 |
+
self.origin = Point('pO')
|
| 416 |
+
self.origin.set_vel(self.frame, 0)
|
| 417 |
+
|
| 418 |
+
self.attachment = Point('pA')
|
| 419 |
+
self.attachment.set_pos(self.origin, self.q*self.frame.x)
|
| 420 |
+
|
| 421 |
+
self.mass = Particle('mass', self.attachment, self.m)
|
| 422 |
+
self.pathway = LinearPathway(self.origin, self.attachment)
|
| 423 |
+
|
| 424 |
+
self.kanes_method = KanesMethod(
|
| 425 |
+
self.frame,
|
| 426 |
+
q_ind=[self.q],
|
| 427 |
+
u_ind=[self.u],
|
| 428 |
+
kd_eqs=[self.dq - self.u],
|
| 429 |
+
)
|
| 430 |
+
self.bodies = [self.mass]
|
| 431 |
+
|
| 432 |
+
self.mass_matrix = Matrix([[self.m]])
|
| 433 |
+
self.forcing = Matrix([[self.F - self.c*self.u - self.k*self.q]])
|
| 434 |
+
|
| 435 |
+
def test_force_acuator(self):
|
| 436 |
+
stiffness = -self.k*self.pathway.length
|
| 437 |
+
spring = ForceActuator(stiffness, self.pathway)
|
| 438 |
+
damping = -self.c*self.pathway.extension_velocity
|
| 439 |
+
damper = ForceActuator(damping, self.pathway)
|
| 440 |
+
|
| 441 |
+
loads = [
|
| 442 |
+
(self.attachment, self.F*self.frame.x),
|
| 443 |
+
*spring.to_loads(),
|
| 444 |
+
*damper.to_loads(),
|
| 445 |
+
]
|
| 446 |
+
self.kanes_method.kanes_equations(self.bodies, loads)
|
| 447 |
+
|
| 448 |
+
assert self.kanes_method.mass_matrix == self.mass_matrix
|
| 449 |
+
assert self.kanes_method.forcing == self.forcing
|
| 450 |
+
|
| 451 |
+
def test_linear_spring_linear_damper(self):
|
| 452 |
+
spring = LinearSpring(self.k, self.pathway)
|
| 453 |
+
damper = LinearDamper(self.c, self.pathway)
|
| 454 |
+
|
| 455 |
+
loads = [
|
| 456 |
+
(self.attachment, self.F*self.frame.x),
|
| 457 |
+
*spring.to_loads(),
|
| 458 |
+
*damper.to_loads(),
|
| 459 |
+
]
|
| 460 |
+
self.kanes_method.kanes_equations(self.bodies, loads)
|
| 461 |
+
|
| 462 |
+
assert self.kanes_method.mass_matrix == self.mass_matrix
|
| 463 |
+
assert self.kanes_method.forcing == self.forcing
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
class TestTorqueActuator:
|
| 467 |
+
|
| 468 |
+
@pytest.fixture(autouse=True)
|
| 469 |
+
def _torque_actuator_fixture(self):
|
| 470 |
+
self.torque = Symbol('T')
|
| 471 |
+
self.N = ReferenceFrame('N')
|
| 472 |
+
self.A = ReferenceFrame('A')
|
| 473 |
+
self.axis = self.N.z
|
| 474 |
+
self.target = RigidBody('target', frame=self.N)
|
| 475 |
+
self.reaction = RigidBody('reaction', frame=self.A)
|
| 476 |
+
|
| 477 |
+
def test_is_actuator_base_subclass(self):
|
| 478 |
+
assert issubclass(TorqueActuator, ActuatorBase)
|
| 479 |
+
|
| 480 |
+
@pytest.mark.parametrize(
|
| 481 |
+
'torque',
|
| 482 |
+
[
|
| 483 |
+
Symbol('T'),
|
| 484 |
+
dynamicsymbols('T'),
|
| 485 |
+
Symbol('T')**2 + Symbol('T'),
|
| 486 |
+
]
|
| 487 |
+
)
|
| 488 |
+
@pytest.mark.parametrize(
|
| 489 |
+
'target_frame, reaction_frame',
|
| 490 |
+
[
|
| 491 |
+
(target.frame, reaction.frame),
|
| 492 |
+
(target, reaction.frame),
|
| 493 |
+
(target.frame, reaction),
|
| 494 |
+
(target, reaction),
|
| 495 |
+
]
|
| 496 |
+
)
|
| 497 |
+
def test_valid_constructor_with_reaction(
|
| 498 |
+
self,
|
| 499 |
+
torque,
|
| 500 |
+
target_frame,
|
| 501 |
+
reaction_frame,
|
| 502 |
+
):
|
| 503 |
+
instance = TorqueActuator(
|
| 504 |
+
torque,
|
| 505 |
+
self.axis,
|
| 506 |
+
target_frame,
|
| 507 |
+
reaction_frame,
|
| 508 |
+
)
|
| 509 |
+
assert isinstance(instance, TorqueActuator)
|
| 510 |
+
|
| 511 |
+
assert hasattr(instance, 'torque')
|
| 512 |
+
assert isinstance(instance.torque, ExprType)
|
| 513 |
+
assert instance.torque == torque
|
| 514 |
+
|
| 515 |
+
assert hasattr(instance, 'axis')
|
| 516 |
+
assert isinstance(instance.axis, Vector)
|
| 517 |
+
assert instance.axis == self.axis
|
| 518 |
+
|
| 519 |
+
assert hasattr(instance, 'target_frame')
|
| 520 |
+
assert isinstance(instance.target_frame, ReferenceFrame)
|
| 521 |
+
assert instance.target_frame == target.frame
|
| 522 |
+
|
| 523 |
+
assert hasattr(instance, 'reaction_frame')
|
| 524 |
+
assert isinstance(instance.reaction_frame, ReferenceFrame)
|
| 525 |
+
assert instance.reaction_frame == reaction.frame
|
| 526 |
+
|
| 527 |
+
@pytest.mark.parametrize(
|
| 528 |
+
'torque',
|
| 529 |
+
[
|
| 530 |
+
Symbol('T'),
|
| 531 |
+
dynamicsymbols('T'),
|
| 532 |
+
Symbol('T')**2 + Symbol('T'),
|
| 533 |
+
]
|
| 534 |
+
)
|
| 535 |
+
@pytest.mark.parametrize('target_frame', [target.frame, target])
|
| 536 |
+
def test_valid_constructor_without_reaction(self, torque, target_frame):
|
| 537 |
+
instance = TorqueActuator(torque, self.axis, target_frame)
|
| 538 |
+
assert isinstance(instance, TorqueActuator)
|
| 539 |
+
|
| 540 |
+
assert hasattr(instance, 'torque')
|
| 541 |
+
assert isinstance(instance.torque, ExprType)
|
| 542 |
+
assert instance.torque == torque
|
| 543 |
+
|
| 544 |
+
assert hasattr(instance, 'axis')
|
| 545 |
+
assert isinstance(instance.axis, Vector)
|
| 546 |
+
assert instance.axis == self.axis
|
| 547 |
+
|
| 548 |
+
assert hasattr(instance, 'target_frame')
|
| 549 |
+
assert isinstance(instance.target_frame, ReferenceFrame)
|
| 550 |
+
assert instance.target_frame == target.frame
|
| 551 |
+
|
| 552 |
+
assert hasattr(instance, 'reaction_frame')
|
| 553 |
+
assert instance.reaction_frame is None
|
| 554 |
+
|
| 555 |
+
@pytest.mark.parametrize('torque', [None, 'T'])
|
| 556 |
+
def test_invalid_constructor_torque_not_sympifyable(self, torque):
|
| 557 |
+
with pytest.raises(SympifyError):
|
| 558 |
+
_ = TorqueActuator(torque, self.axis, self.target)
|
| 559 |
+
|
| 560 |
+
@pytest.mark.parametrize('axis', [Symbol('a'), dynamicsymbols('a')])
|
| 561 |
+
def test_invalid_constructor_axis_not_vector(self, axis):
|
| 562 |
+
with pytest.raises(TypeError):
|
| 563 |
+
_ = TorqueActuator(self.torque, axis, self.target, self.reaction)
|
| 564 |
+
|
| 565 |
+
@pytest.mark.parametrize(
|
| 566 |
+
'frames',
|
| 567 |
+
[
|
| 568 |
+
(None, ReferenceFrame('child')),
|
| 569 |
+
(ReferenceFrame('parent'), True),
|
| 570 |
+
(None, RigidBody('child')),
|
| 571 |
+
(RigidBody('parent'), True),
|
| 572 |
+
]
|
| 573 |
+
)
|
| 574 |
+
def test_invalid_constructor_frames_not_frame(self, frames):
|
| 575 |
+
with pytest.raises(TypeError):
|
| 576 |
+
_ = TorqueActuator(self.torque, self.axis, *frames)
|
| 577 |
+
|
| 578 |
+
@pytest.mark.parametrize(
|
| 579 |
+
'property_name, fixture_attr_name',
|
| 580 |
+
[
|
| 581 |
+
('torque', 'torque'),
|
| 582 |
+
('axis', 'axis'),
|
| 583 |
+
('target_frame', 'target'),
|
| 584 |
+
('reaction_frame', 'reaction'),
|
| 585 |
+
]
|
| 586 |
+
)
|
| 587 |
+
def test_properties_are_immutable(self, property_name, fixture_attr_name):
|
| 588 |
+
actuator = TorqueActuator(
|
| 589 |
+
self.torque,
|
| 590 |
+
self.axis,
|
| 591 |
+
self.target,
|
| 592 |
+
self.reaction,
|
| 593 |
+
)
|
| 594 |
+
value = getattr(self, fixture_attr_name)
|
| 595 |
+
with pytest.raises(AttributeError):
|
| 596 |
+
setattr(actuator, property_name, value)
|
| 597 |
+
|
| 598 |
+
def test_repr_without_reaction(self):
|
| 599 |
+
actuator = TorqueActuator(self.torque, self.axis, self.target)
|
| 600 |
+
expected = 'TorqueActuator(T, axis=N.z, target_frame=N)'
|
| 601 |
+
assert repr(actuator) == expected
|
| 602 |
+
|
| 603 |
+
def test_repr_with_reaction(self):
|
| 604 |
+
actuator = TorqueActuator(
|
| 605 |
+
self.torque,
|
| 606 |
+
self.axis,
|
| 607 |
+
self.target,
|
| 608 |
+
self.reaction,
|
| 609 |
+
)
|
| 610 |
+
expected = 'TorqueActuator(T, axis=N.z, target_frame=N, reaction_frame=A)'
|
| 611 |
+
assert repr(actuator) == expected
|
| 612 |
+
|
| 613 |
+
def test_at_pin_joint_constructor(self):
|
| 614 |
+
pin_joint = PinJoint(
|
| 615 |
+
'pin',
|
| 616 |
+
self.target,
|
| 617 |
+
self.reaction,
|
| 618 |
+
coordinates=dynamicsymbols('q'),
|
| 619 |
+
speeds=dynamicsymbols('u'),
|
| 620 |
+
parent_interframe=self.N,
|
| 621 |
+
joint_axis=self.axis,
|
| 622 |
+
)
|
| 623 |
+
instance = TorqueActuator.at_pin_joint(self.torque, pin_joint)
|
| 624 |
+
assert isinstance(instance, TorqueActuator)
|
| 625 |
+
|
| 626 |
+
assert hasattr(instance, 'torque')
|
| 627 |
+
assert isinstance(instance.torque, ExprType)
|
| 628 |
+
assert instance.torque == self.torque
|
| 629 |
+
|
| 630 |
+
assert hasattr(instance, 'axis')
|
| 631 |
+
assert isinstance(instance.axis, Vector)
|
| 632 |
+
assert instance.axis == self.axis
|
| 633 |
+
|
| 634 |
+
assert hasattr(instance, 'target_frame')
|
| 635 |
+
assert isinstance(instance.target_frame, ReferenceFrame)
|
| 636 |
+
assert instance.target_frame == self.A
|
| 637 |
+
|
| 638 |
+
assert hasattr(instance, 'reaction_frame')
|
| 639 |
+
assert isinstance(instance.reaction_frame, ReferenceFrame)
|
| 640 |
+
assert instance.reaction_frame == self.N
|
| 641 |
+
|
| 642 |
+
def test_at_pin_joint_pin_joint_not_pin_joint_invalid(self):
|
| 643 |
+
with pytest.raises(TypeError):
|
| 644 |
+
_ = TorqueActuator.at_pin_joint(self.torque, Symbol('pin'))
|
| 645 |
+
|
| 646 |
+
def test_to_loads_without_reaction(self):
|
| 647 |
+
actuator = TorqueActuator(self.torque, self.axis, self.target)
|
| 648 |
+
expected = [
|
| 649 |
+
(self.N, self.torque*self.axis),
|
| 650 |
+
]
|
| 651 |
+
assert actuator.to_loads() == expected
|
| 652 |
+
|
| 653 |
+
def test_to_loads_with_reaction(self):
|
| 654 |
+
actuator = TorqueActuator(
|
| 655 |
+
self.torque,
|
| 656 |
+
self.axis,
|
| 657 |
+
self.target,
|
| 658 |
+
self.reaction,
|
| 659 |
+
)
|
| 660 |
+
expected = [
|
| 661 |
+
(self.N, self.torque*self.axis),
|
| 662 |
+
(self.A, - self.torque*self.axis),
|
| 663 |
+
]
|
| 664 |
+
assert actuator.to_loads() == expected
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
class NonSympifyable:
|
| 668 |
+
pass
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
class TestDuffingSpring:
|
| 672 |
+
@pytest.fixture(autouse=True)
|
| 673 |
+
# Set up common vairables that will be used in multiple tests
|
| 674 |
+
def _duffing_spring_fixture(self):
|
| 675 |
+
self.linear_stiffness = Symbol('beta')
|
| 676 |
+
self.nonlinear_stiffness = Symbol('alpha')
|
| 677 |
+
self.equilibrium_length = Symbol('l')
|
| 678 |
+
self.pA = Point('pA')
|
| 679 |
+
self.pB = Point('pB')
|
| 680 |
+
self.pathway = LinearPathway(self.pA, self.pB)
|
| 681 |
+
self.q = dynamicsymbols('q')
|
| 682 |
+
self.N = ReferenceFrame('N')
|
| 683 |
+
|
| 684 |
+
# Simples tests to check that DuffingSpring is a subclass of ForceActuator and ActuatorBase
|
| 685 |
+
def test_is_force_actuator_subclass(self):
|
| 686 |
+
assert issubclass(DuffingSpring, ForceActuator)
|
| 687 |
+
|
| 688 |
+
def test_is_actuator_base_subclass(self):
|
| 689 |
+
assert issubclass(DuffingSpring, ActuatorBase)
|
| 690 |
+
|
| 691 |
+
@pytest.mark.parametrize(
|
| 692 |
+
# Create parametrized tests that allows running the same test function multiple times with different sets of arguments
|
| 693 |
+
(
|
| 694 |
+
'linear_stiffness, '
|
| 695 |
+
'expected_linear_stiffness, '
|
| 696 |
+
'nonlinear_stiffness, '
|
| 697 |
+
'expected_nonlinear_stiffness, '
|
| 698 |
+
'equilibrium_length, '
|
| 699 |
+
'expected_equilibrium_length, '
|
| 700 |
+
'force'
|
| 701 |
+
),
|
| 702 |
+
[
|
| 703 |
+
(
|
| 704 |
+
1,
|
| 705 |
+
S.One,
|
| 706 |
+
1,
|
| 707 |
+
S.One,
|
| 708 |
+
0,
|
| 709 |
+
S.Zero,
|
| 710 |
+
-sqrt(dynamicsymbols('q')**2)-(sqrt(dynamicsymbols('q')**2))**3,
|
| 711 |
+
),
|
| 712 |
+
(
|
| 713 |
+
Symbol('beta'),
|
| 714 |
+
Symbol('beta'),
|
| 715 |
+
Symbol('alpha'),
|
| 716 |
+
Symbol('alpha'),
|
| 717 |
+
0,
|
| 718 |
+
S.Zero,
|
| 719 |
+
-Symbol('beta')*sqrt(dynamicsymbols('q')**2)-Symbol('alpha')*(sqrt(dynamicsymbols('q')**2))**3,
|
| 720 |
+
),
|
| 721 |
+
(
|
| 722 |
+
Symbol('beta'),
|
| 723 |
+
Symbol('beta'),
|
| 724 |
+
Symbol('alpha'),
|
| 725 |
+
Symbol('alpha'),
|
| 726 |
+
S.Zero,
|
| 727 |
+
S.Zero,
|
| 728 |
+
-Symbol('beta')*sqrt(dynamicsymbols('q')**2)-Symbol('alpha')*(sqrt(dynamicsymbols('q')**2))**3,
|
| 729 |
+
),
|
| 730 |
+
(
|
| 731 |
+
Symbol('beta'),
|
| 732 |
+
Symbol('beta'),
|
| 733 |
+
Symbol('alpha'),
|
| 734 |
+
Symbol('alpha'),
|
| 735 |
+
Symbol('l'),
|
| 736 |
+
Symbol('l'),
|
| 737 |
+
-Symbol('beta') * (sqrt(dynamicsymbols('q')**2) - Symbol('l')) - Symbol('alpha') * (sqrt(dynamicsymbols('q')**2) - Symbol('l'))**3,
|
| 738 |
+
),
|
| 739 |
+
]
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
# Check if DuffingSpring correctly inializes its attributes
|
| 743 |
+
# It tests various combinations of linear & nonlinear stiffness, equilibriun length, and the resulting force expression
|
| 744 |
+
def test_valid_constructor(
|
| 745 |
+
self,
|
| 746 |
+
linear_stiffness,
|
| 747 |
+
expected_linear_stiffness,
|
| 748 |
+
nonlinear_stiffness,
|
| 749 |
+
expected_nonlinear_stiffness,
|
| 750 |
+
equilibrium_length,
|
| 751 |
+
expected_equilibrium_length,
|
| 752 |
+
force,
|
| 753 |
+
):
|
| 754 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 755 |
+
spring = DuffingSpring(linear_stiffness, nonlinear_stiffness, self.pathway, equilibrium_length)
|
| 756 |
+
|
| 757 |
+
assert isinstance(spring, DuffingSpring)
|
| 758 |
+
|
| 759 |
+
assert hasattr(spring, 'linear_stiffness')
|
| 760 |
+
assert isinstance(spring.linear_stiffness, ExprType)
|
| 761 |
+
assert spring.linear_stiffness == expected_linear_stiffness
|
| 762 |
+
|
| 763 |
+
assert hasattr(spring, 'nonlinear_stiffness')
|
| 764 |
+
assert isinstance(spring.nonlinear_stiffness, ExprType)
|
| 765 |
+
assert spring.nonlinear_stiffness == expected_nonlinear_stiffness
|
| 766 |
+
|
| 767 |
+
assert hasattr(spring, 'pathway')
|
| 768 |
+
assert isinstance(spring.pathway, LinearPathway)
|
| 769 |
+
assert spring.pathway == self.pathway
|
| 770 |
+
|
| 771 |
+
assert hasattr(spring, 'equilibrium_length')
|
| 772 |
+
assert isinstance(spring.equilibrium_length, ExprType)
|
| 773 |
+
assert spring.equilibrium_length == expected_equilibrium_length
|
| 774 |
+
|
| 775 |
+
assert hasattr(spring, 'force')
|
| 776 |
+
assert isinstance(spring.force, ExprType)
|
| 777 |
+
assert spring.force == force
|
| 778 |
+
|
| 779 |
+
@pytest.mark.parametrize('linear_stiffness', [None, NonSympifyable()])
|
| 780 |
+
def test_invalid_constructor_linear_stiffness_not_sympifyable(self, linear_stiffness):
|
| 781 |
+
with pytest.raises(SympifyError):
|
| 782 |
+
_ = DuffingSpring(linear_stiffness, self.nonlinear_stiffness, self.pathway, self.equilibrium_length)
|
| 783 |
+
|
| 784 |
+
@pytest.mark.parametrize('nonlinear_stiffness', [None, NonSympifyable()])
|
| 785 |
+
def test_invalid_constructor_nonlinear_stiffness_not_sympifyable(self, nonlinear_stiffness):
|
| 786 |
+
with pytest.raises(SympifyError):
|
| 787 |
+
_ = DuffingSpring(self.linear_stiffness, nonlinear_stiffness, self.pathway, self.equilibrium_length)
|
| 788 |
+
|
| 789 |
+
def test_invalid_constructor_pathway_not_pathway_base(self):
|
| 790 |
+
with pytest.raises(TypeError):
|
| 791 |
+
_ = DuffingSpring(self.linear_stiffness, self.nonlinear_stiffness, NonSympifyable(), self.equilibrium_length)
|
| 792 |
+
|
| 793 |
+
@pytest.mark.parametrize('equilibrium_length', [None, NonSympifyable()])
|
| 794 |
+
def test_invalid_constructor_equilibrium_length_not_sympifyable(self, equilibrium_length):
|
| 795 |
+
with pytest.raises(SympifyError):
|
| 796 |
+
_ = DuffingSpring(self.linear_stiffness, self.nonlinear_stiffness, self.pathway, equilibrium_length)
|
| 797 |
+
|
| 798 |
+
@pytest.mark.parametrize(
|
| 799 |
+
'property_name, fixture_attr_name',
|
| 800 |
+
[
|
| 801 |
+
('linear_stiffness', 'linear_stiffness'),
|
| 802 |
+
('nonlinear_stiffness', 'nonlinear_stiffness'),
|
| 803 |
+
('pathway', 'pathway'),
|
| 804 |
+
('equilibrium_length', 'equilibrium_length')
|
| 805 |
+
]
|
| 806 |
+
)
|
| 807 |
+
# Check if certain properties of DuffingSpring object are immutable after initialization
|
| 808 |
+
# Ensure that once DuffingSpring is created, its key properties cannot be changed
|
| 809 |
+
def test_properties_are_immutable(self, property_name, fixture_attr_name):
|
| 810 |
+
spring = DuffingSpring(self.linear_stiffness, self.nonlinear_stiffness, self.pathway, self.equilibrium_length)
|
| 811 |
+
with pytest.raises(AttributeError):
|
| 812 |
+
setattr(spring, property_name, getattr(self, fixture_attr_name))
|
| 813 |
+
|
| 814 |
+
@pytest.mark.parametrize(
|
| 815 |
+
'equilibrium_length, expected',
|
| 816 |
+
[
|
| 817 |
+
(0, 'DuffingSpring(beta, alpha, LinearPathway(pA, pB), equilibrium_length=0)'),
|
| 818 |
+
(Symbol('l'), 'DuffingSpring(beta, alpha, LinearPathway(pA, pB), equilibrium_length=l)'),
|
| 819 |
+
]
|
| 820 |
+
)
|
| 821 |
+
# Check the __repr__ method of DuffingSpring class
|
| 822 |
+
# Check if the actual string representation of DuffingSpring instance matches the expected string for each provided parameter values
|
| 823 |
+
def test_repr(self, equilibrium_length, expected):
|
| 824 |
+
spring = DuffingSpring(self.linear_stiffness, self.nonlinear_stiffness, self.pathway, equilibrium_length)
|
| 825 |
+
assert repr(spring) == expected
|
| 826 |
+
|
| 827 |
+
def test_to_loads(self):
|
| 828 |
+
self.pB.set_pos(self.pA, self.q*self.N.x)
|
| 829 |
+
spring = DuffingSpring(self.linear_stiffness, self.nonlinear_stiffness, self.pathway, self.equilibrium_length)
|
| 830 |
+
|
| 831 |
+
# Calculate the displacement from the equilibrium length
|
| 832 |
+
displacement = self.q - self.equilibrium_length
|
| 833 |
+
|
| 834 |
+
# Make sure this matches the computation in DuffingSpring class
|
| 835 |
+
force = -self.linear_stiffness * displacement - self.nonlinear_stiffness * displacement**3
|
| 836 |
+
|
| 837 |
+
# The expected loads on pA and pB due to the spring
|
| 838 |
+
expected_loads = [Force(self.pA, force * self.N.x), Force(self.pB, -force * self.N.x)]
|
| 839 |
+
|
| 840 |
+
# Compare expected loads to what is returned from DuffingSpring.to_loads()
|
| 841 |
+
calculated_loads = spring.to_loads()
|
| 842 |
+
for calculated, expected in zip(calculated_loads, expected_loads):
|
| 843 |
+
assert calculated.point == expected.point
|
| 844 |
+
for dim in self.N: # Assuming self.N is the reference frame
|
| 845 |
+
calculated_component = calculated.vector.dot(dim)
|
| 846 |
+
expected_component = expected.vector.dot(dim)
|
| 847 |
+
# Substitute all symbols with numeric values
|
| 848 |
+
substitutions = {self.q: 1, Symbol('l'): 1, Symbol('alpha'): 1, Symbol('beta'): 1} # Add other necessary symbols as needed
|
| 849 |
+
diff = (calculated_component - expected_component).subs(substitutions).evalf()
|
| 850 |
+
# Check if the absolute value of the difference is below a threshold
|
| 851 |
+
assert Abs(diff) < 1e-9, f"The forces do not match. Difference: {diff}"
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_body.py
ADDED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
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import (Symbol, symbols, sin, cos, Matrix, zeros,
|
| 2 |
+
simplify)
|
| 3 |
+
from sympy.physics.vector import Point, ReferenceFrame, dynamicsymbols, Dyadic
|
| 4 |
+
from sympy.physics.mechanics import inertia, Body
|
| 5 |
+
from sympy.testing.pytest import raises, warns_deprecated_sympy
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_default():
|
| 9 |
+
with warns_deprecated_sympy():
|
| 10 |
+
body = Body('body')
|
| 11 |
+
assert body.name == 'body'
|
| 12 |
+
assert body.loads == []
|
| 13 |
+
point = Point('body_masscenter')
|
| 14 |
+
point.set_vel(body.frame, 0)
|
| 15 |
+
com = body.masscenter
|
| 16 |
+
frame = body.frame
|
| 17 |
+
assert com.vel(frame) == point.vel(frame)
|
| 18 |
+
assert body.mass == Symbol('body_mass')
|
| 19 |
+
ixx, iyy, izz = symbols('body_ixx body_iyy body_izz')
|
| 20 |
+
ixy, iyz, izx = symbols('body_ixy body_iyz body_izx')
|
| 21 |
+
assert body.inertia == (inertia(body.frame, ixx, iyy, izz, ixy, iyz, izx),
|
| 22 |
+
body.masscenter)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_custom_rigid_body():
|
| 26 |
+
# Body with RigidBody.
|
| 27 |
+
rigidbody_masscenter = Point('rigidbody_masscenter')
|
| 28 |
+
rigidbody_mass = Symbol('rigidbody_mass')
|
| 29 |
+
rigidbody_frame = ReferenceFrame('rigidbody_frame')
|
| 30 |
+
body_inertia = inertia(rigidbody_frame, 1, 0, 0)
|
| 31 |
+
with warns_deprecated_sympy():
|
| 32 |
+
rigid_body = Body('rigidbody_body', rigidbody_masscenter,
|
| 33 |
+
rigidbody_mass, rigidbody_frame, body_inertia)
|
| 34 |
+
com = rigid_body.masscenter
|
| 35 |
+
frame = rigid_body.frame
|
| 36 |
+
rigidbody_masscenter.set_vel(rigidbody_frame, 0)
|
| 37 |
+
assert com.vel(frame) == rigidbody_masscenter.vel(frame)
|
| 38 |
+
assert com.pos_from(com) == rigidbody_masscenter.pos_from(com)
|
| 39 |
+
|
| 40 |
+
assert rigid_body.mass == rigidbody_mass
|
| 41 |
+
assert rigid_body.inertia == (body_inertia, rigidbody_masscenter)
|
| 42 |
+
|
| 43 |
+
assert rigid_body.is_rigidbody
|
| 44 |
+
|
| 45 |
+
assert hasattr(rigid_body, 'masscenter')
|
| 46 |
+
assert hasattr(rigid_body, 'mass')
|
| 47 |
+
assert hasattr(rigid_body, 'frame')
|
| 48 |
+
assert hasattr(rigid_body, 'inertia')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def test_particle_body():
|
| 52 |
+
# Body with Particle
|
| 53 |
+
particle_masscenter = Point('particle_masscenter')
|
| 54 |
+
particle_mass = Symbol('particle_mass')
|
| 55 |
+
particle_frame = ReferenceFrame('particle_frame')
|
| 56 |
+
with warns_deprecated_sympy():
|
| 57 |
+
particle_body = Body('particle_body', particle_masscenter,
|
| 58 |
+
particle_mass, particle_frame)
|
| 59 |
+
com = particle_body.masscenter
|
| 60 |
+
frame = particle_body.frame
|
| 61 |
+
particle_masscenter.set_vel(particle_frame, 0)
|
| 62 |
+
assert com.vel(frame) == particle_masscenter.vel(frame)
|
| 63 |
+
assert com.pos_from(com) == particle_masscenter.pos_from(com)
|
| 64 |
+
|
| 65 |
+
assert particle_body.mass == particle_mass
|
| 66 |
+
assert not hasattr(particle_body, "_inertia")
|
| 67 |
+
assert hasattr(particle_body, 'frame')
|
| 68 |
+
assert hasattr(particle_body, 'masscenter')
|
| 69 |
+
assert hasattr(particle_body, 'mass')
|
| 70 |
+
assert particle_body.inertia == (Dyadic(0), particle_body.masscenter)
|
| 71 |
+
assert particle_body.central_inertia == Dyadic(0)
|
| 72 |
+
assert not particle_body.is_rigidbody
|
| 73 |
+
|
| 74 |
+
particle_body.central_inertia = inertia(particle_frame, 1, 1, 1)
|
| 75 |
+
assert particle_body.central_inertia == inertia(particle_frame, 1, 1, 1)
|
| 76 |
+
assert particle_body.is_rigidbody
|
| 77 |
+
|
| 78 |
+
with warns_deprecated_sympy():
|
| 79 |
+
particle_body = Body('particle_body', mass=particle_mass)
|
| 80 |
+
assert not particle_body.is_rigidbody
|
| 81 |
+
point = particle_body.masscenter.locatenew('point', particle_body.x)
|
| 82 |
+
point_inertia = particle_mass * inertia(particle_body.frame, 0, 1, 1)
|
| 83 |
+
particle_body.inertia = (point_inertia, point)
|
| 84 |
+
assert particle_body.inertia == (point_inertia, point)
|
| 85 |
+
assert particle_body.central_inertia == Dyadic(0)
|
| 86 |
+
assert particle_body.is_rigidbody
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def test_particle_body_add_force():
|
| 90 |
+
# Body with Particle
|
| 91 |
+
particle_masscenter = Point('particle_masscenter')
|
| 92 |
+
particle_mass = Symbol('particle_mass')
|
| 93 |
+
particle_frame = ReferenceFrame('particle_frame')
|
| 94 |
+
with warns_deprecated_sympy():
|
| 95 |
+
particle_body = Body('particle_body', particle_masscenter,
|
| 96 |
+
particle_mass, particle_frame)
|
| 97 |
+
|
| 98 |
+
a = Symbol('a')
|
| 99 |
+
force_vector = a * particle_body.frame.x
|
| 100 |
+
particle_body.apply_force(force_vector, particle_body.masscenter)
|
| 101 |
+
assert len(particle_body.loads) == 1
|
| 102 |
+
point = particle_body.masscenter.locatenew(
|
| 103 |
+
particle_body._name + '_point0', 0)
|
| 104 |
+
point.set_vel(particle_body.frame, 0)
|
| 105 |
+
force_point = particle_body.loads[0][0]
|
| 106 |
+
|
| 107 |
+
frame = particle_body.frame
|
| 108 |
+
assert force_point.vel(frame) == point.vel(frame)
|
| 109 |
+
assert force_point.pos_from(force_point) == point.pos_from(force_point)
|
| 110 |
+
|
| 111 |
+
assert particle_body.loads[0][1] == force_vector
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_body_add_force():
|
| 115 |
+
# Body with RigidBody.
|
| 116 |
+
rigidbody_masscenter = Point('rigidbody_masscenter')
|
| 117 |
+
rigidbody_mass = Symbol('rigidbody_mass')
|
| 118 |
+
rigidbody_frame = ReferenceFrame('rigidbody_frame')
|
| 119 |
+
body_inertia = inertia(rigidbody_frame, 1, 0, 0)
|
| 120 |
+
with warns_deprecated_sympy():
|
| 121 |
+
rigid_body = Body('rigidbody_body', rigidbody_masscenter,
|
| 122 |
+
rigidbody_mass, rigidbody_frame, body_inertia)
|
| 123 |
+
|
| 124 |
+
l = Symbol('l')
|
| 125 |
+
Fa = Symbol('Fa')
|
| 126 |
+
point = rigid_body.masscenter.locatenew(
|
| 127 |
+
'rigidbody_body_point0',
|
| 128 |
+
l * rigid_body.frame.x)
|
| 129 |
+
point.set_vel(rigid_body.frame, 0)
|
| 130 |
+
force_vector = Fa * rigid_body.frame.z
|
| 131 |
+
# apply_force with point
|
| 132 |
+
rigid_body.apply_force(force_vector, point)
|
| 133 |
+
assert len(rigid_body.loads) == 1
|
| 134 |
+
force_point = rigid_body.loads[0][0]
|
| 135 |
+
frame = rigid_body.frame
|
| 136 |
+
assert force_point.vel(frame) == point.vel(frame)
|
| 137 |
+
assert force_point.pos_from(force_point) == point.pos_from(force_point)
|
| 138 |
+
assert rigid_body.loads[0][1] == force_vector
|
| 139 |
+
# apply_force without point
|
| 140 |
+
rigid_body.apply_force(force_vector)
|
| 141 |
+
assert len(rigid_body.loads) == 2
|
| 142 |
+
assert rigid_body.loads[1][1] == force_vector
|
| 143 |
+
# passing something else than point
|
| 144 |
+
raises(TypeError, lambda: rigid_body.apply_force(force_vector, 0))
|
| 145 |
+
raises(TypeError, lambda: rigid_body.apply_force(0))
|
| 146 |
+
|
| 147 |
+
def test_body_add_torque():
|
| 148 |
+
with warns_deprecated_sympy():
|
| 149 |
+
body = Body('body')
|
| 150 |
+
torque_vector = body.frame.x
|
| 151 |
+
body.apply_torque(torque_vector)
|
| 152 |
+
|
| 153 |
+
assert len(body.loads) == 1
|
| 154 |
+
assert body.loads[0] == (body.frame, torque_vector)
|
| 155 |
+
raises(TypeError, lambda: body.apply_torque(0))
|
| 156 |
+
|
| 157 |
+
def test_body_masscenter_vel():
|
| 158 |
+
with warns_deprecated_sympy():
|
| 159 |
+
A = Body('A')
|
| 160 |
+
N = ReferenceFrame('N')
|
| 161 |
+
with warns_deprecated_sympy():
|
| 162 |
+
B = Body('B', frame=N)
|
| 163 |
+
A.masscenter.set_vel(N, N.z)
|
| 164 |
+
assert A.masscenter_vel(B) == N.z
|
| 165 |
+
assert A.masscenter_vel(N) == N.z
|
| 166 |
+
|
| 167 |
+
def test_body_ang_vel():
|
| 168 |
+
with warns_deprecated_sympy():
|
| 169 |
+
A = Body('A')
|
| 170 |
+
N = ReferenceFrame('N')
|
| 171 |
+
with warns_deprecated_sympy():
|
| 172 |
+
B = Body('B', frame=N)
|
| 173 |
+
A.frame.set_ang_vel(N, N.y)
|
| 174 |
+
assert A.ang_vel_in(B) == N.y
|
| 175 |
+
assert B.ang_vel_in(A) == -N.y
|
| 176 |
+
assert A.ang_vel_in(N) == N.y
|
| 177 |
+
|
| 178 |
+
def test_body_dcm():
|
| 179 |
+
with warns_deprecated_sympy():
|
| 180 |
+
A = Body('A')
|
| 181 |
+
B = Body('B')
|
| 182 |
+
A.frame.orient_axis(B.frame, B.frame.z, 10)
|
| 183 |
+
assert A.dcm(B) == Matrix([[cos(10), sin(10), 0], [-sin(10), cos(10), 0], [0, 0, 1]])
|
| 184 |
+
assert A.dcm(B.frame) == Matrix([[cos(10), sin(10), 0], [-sin(10), cos(10), 0], [0, 0, 1]])
|
| 185 |
+
|
| 186 |
+
def test_body_axis():
|
| 187 |
+
N = ReferenceFrame('N')
|
| 188 |
+
with warns_deprecated_sympy():
|
| 189 |
+
B = Body('B', frame=N)
|
| 190 |
+
assert B.x == N.x
|
| 191 |
+
assert B.y == N.y
|
| 192 |
+
assert B.z == N.z
|
| 193 |
+
|
| 194 |
+
def test_apply_force_multiple_one_point():
|
| 195 |
+
a, b = symbols('a b')
|
| 196 |
+
P = Point('P')
|
| 197 |
+
with warns_deprecated_sympy():
|
| 198 |
+
B = Body('B')
|
| 199 |
+
f1 = a*B.x
|
| 200 |
+
f2 = b*B.y
|
| 201 |
+
B.apply_force(f1, P)
|
| 202 |
+
assert B.loads == [(P, f1)]
|
| 203 |
+
B.apply_force(f2, P)
|
| 204 |
+
assert B.loads == [(P, f1+f2)]
|
| 205 |
+
|
| 206 |
+
def test_apply_force():
|
| 207 |
+
f, g = symbols('f g')
|
| 208 |
+
q, x, v1, v2 = dynamicsymbols('q x v1 v2')
|
| 209 |
+
P1 = Point('P1')
|
| 210 |
+
P2 = Point('P2')
|
| 211 |
+
with warns_deprecated_sympy():
|
| 212 |
+
B1 = Body('B1')
|
| 213 |
+
B2 = Body('B2')
|
| 214 |
+
N = ReferenceFrame('N')
|
| 215 |
+
|
| 216 |
+
P1.set_vel(B1.frame, v1*B1.x)
|
| 217 |
+
P2.set_vel(B2.frame, v2*B2.x)
|
| 218 |
+
force = f*q*N.z # time varying force
|
| 219 |
+
|
| 220 |
+
B1.apply_force(force, P1, B2, P2) #applying equal and opposite force on moving points
|
| 221 |
+
assert B1.loads == [(P1, force)]
|
| 222 |
+
assert B2.loads == [(P2, -force)]
|
| 223 |
+
|
| 224 |
+
g1 = B1.mass*g*N.y
|
| 225 |
+
g2 = B2.mass*g*N.y
|
| 226 |
+
|
| 227 |
+
B1.apply_force(g1) #applying gravity on B1 masscenter
|
| 228 |
+
B2.apply_force(g2) #applying gravity on B2 masscenter
|
| 229 |
+
|
| 230 |
+
assert B1.loads == [(P1,force), (B1.masscenter, g1)]
|
| 231 |
+
assert B2.loads == [(P2, -force), (B2.masscenter, g2)]
|
| 232 |
+
|
| 233 |
+
force2 = x*N.x
|
| 234 |
+
|
| 235 |
+
B1.apply_force(force2, reaction_body=B2) #Applying time varying force on masscenter
|
| 236 |
+
|
| 237 |
+
assert B1.loads == [(P1, force), (B1.masscenter, force2+g1)]
|
| 238 |
+
assert B2.loads == [(P2, -force), (B2.masscenter, -force2+g2)]
|
| 239 |
+
|
| 240 |
+
def test_apply_torque():
|
| 241 |
+
t = symbols('t')
|
| 242 |
+
q = dynamicsymbols('q')
|
| 243 |
+
with warns_deprecated_sympy():
|
| 244 |
+
B1 = Body('B1')
|
| 245 |
+
B2 = Body('B2')
|
| 246 |
+
N = ReferenceFrame('N')
|
| 247 |
+
torque = t*q*N.x
|
| 248 |
+
|
| 249 |
+
B1.apply_torque(torque, B2) #Applying equal and opposite torque
|
| 250 |
+
assert B1.loads == [(B1.frame, torque)]
|
| 251 |
+
assert B2.loads == [(B2.frame, -torque)]
|
| 252 |
+
|
| 253 |
+
torque2 = t*N.y
|
| 254 |
+
B1.apply_torque(torque2)
|
| 255 |
+
assert B1.loads == [(B1.frame, torque+torque2)]
|
| 256 |
+
|
| 257 |
+
def test_clear_load():
|
| 258 |
+
a = symbols('a')
|
| 259 |
+
P = Point('P')
|
| 260 |
+
with warns_deprecated_sympy():
|
| 261 |
+
B = Body('B')
|
| 262 |
+
force = a*B.z
|
| 263 |
+
B.apply_force(force, P)
|
| 264 |
+
assert B.loads == [(P, force)]
|
| 265 |
+
B.clear_loads()
|
| 266 |
+
assert B.loads == []
|
| 267 |
+
|
| 268 |
+
def test_remove_load():
|
| 269 |
+
P1 = Point('P1')
|
| 270 |
+
P2 = Point('P2')
|
| 271 |
+
with warns_deprecated_sympy():
|
| 272 |
+
B = Body('B')
|
| 273 |
+
f1 = B.x
|
| 274 |
+
f2 = B.y
|
| 275 |
+
B.apply_force(f1, P1)
|
| 276 |
+
B.apply_force(f2, P2)
|
| 277 |
+
assert B.loads == [(P1, f1), (P2, f2)]
|
| 278 |
+
B.remove_load(P2)
|
| 279 |
+
assert B.loads == [(P1, f1)]
|
| 280 |
+
B.apply_torque(f1.cross(f2))
|
| 281 |
+
assert B.loads == [(P1, f1), (B.frame, f1.cross(f2))]
|
| 282 |
+
B.remove_load()
|
| 283 |
+
assert B.loads == [(P1, f1)]
|
| 284 |
+
|
| 285 |
+
def test_apply_loads_on_multi_degree_freedom_holonomic_system():
|
| 286 |
+
"""Example based on: https://pydy.readthedocs.io/en/latest/examples/multidof-holonomic.html"""
|
| 287 |
+
with warns_deprecated_sympy():
|
| 288 |
+
W = Body('W') #Wall
|
| 289 |
+
B = Body('B') #Block
|
| 290 |
+
P = Body('P') #Pendulum
|
| 291 |
+
b = Body('b') #bob
|
| 292 |
+
q1, q2 = dynamicsymbols('q1 q2') #generalized coordinates
|
| 293 |
+
k, c, g, kT = symbols('k c g kT') #constants
|
| 294 |
+
F, T = dynamicsymbols('F T') #Specified forces
|
| 295 |
+
|
| 296 |
+
#Applying forces
|
| 297 |
+
B.apply_force(F*W.x)
|
| 298 |
+
W.apply_force(k*q1*W.x, reaction_body=B) #Spring force
|
| 299 |
+
W.apply_force(c*q1.diff()*W.x, reaction_body=B) #dampner
|
| 300 |
+
P.apply_force(P.mass*g*W.y)
|
| 301 |
+
b.apply_force(b.mass*g*W.y)
|
| 302 |
+
|
| 303 |
+
#Applying torques
|
| 304 |
+
P.apply_torque(kT*q2*W.z, reaction_body=b)
|
| 305 |
+
P.apply_torque(T*W.z)
|
| 306 |
+
|
| 307 |
+
assert B.loads == [(B.masscenter, (F - k*q1 - c*q1.diff())*W.x)]
|
| 308 |
+
assert P.loads == [(P.masscenter, P.mass*g*W.y), (P.frame, (T + kT*q2)*W.z)]
|
| 309 |
+
assert b.loads == [(b.masscenter, b.mass*g*W.y), (b.frame, -kT*q2*W.z)]
|
| 310 |
+
assert W.loads == [(W.masscenter, (c*q1.diff() + k*q1)*W.x)]
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def test_parallel_axis():
|
| 314 |
+
N = ReferenceFrame('N')
|
| 315 |
+
m, Ix, Iy, Iz, a, b = symbols('m, I_x, I_y, I_z, a, b')
|
| 316 |
+
Io = inertia(N, Ix, Iy, Iz)
|
| 317 |
+
# Test RigidBody
|
| 318 |
+
o = Point('o')
|
| 319 |
+
p = o.locatenew('p', a * N.x + b * N.y)
|
| 320 |
+
with warns_deprecated_sympy():
|
| 321 |
+
R = Body('R', masscenter=o, frame=N, mass=m, central_inertia=Io)
|
| 322 |
+
Ip = R.parallel_axis(p)
|
| 323 |
+
Ip_expected = inertia(N, Ix + m * b**2, Iy + m * a**2,
|
| 324 |
+
Iz + m * (a**2 + b**2), ixy=-m * a * b)
|
| 325 |
+
assert Ip == Ip_expected
|
| 326 |
+
# Reference frame from which the parallel axis is viewed should not matter
|
| 327 |
+
A = ReferenceFrame('A')
|
| 328 |
+
A.orient_axis(N, N.z, 1)
|
| 329 |
+
assert simplify(
|
| 330 |
+
(R.parallel_axis(p, A) - Ip_expected).to_matrix(A)) == zeros(3, 3)
|
| 331 |
+
# Test Particle
|
| 332 |
+
o = Point('o')
|
| 333 |
+
p = o.locatenew('p', a * N.x + b * N.y)
|
| 334 |
+
with warns_deprecated_sympy():
|
| 335 |
+
P = Body('P', masscenter=o, mass=m, frame=N)
|
| 336 |
+
Ip = P.parallel_axis(p, N)
|
| 337 |
+
Ip_expected = inertia(N, m * b ** 2, m * a ** 2, m * (a ** 2 + b ** 2),
|
| 338 |
+
ixy=-m * a * b)
|
| 339 |
+
assert not P.is_rigidbody
|
| 340 |
+
assert Ip == Ip_expected
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_functions.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import sin, cos, tan, pi, symbols, Matrix, S, Function
|
| 2 |
+
from sympy.physics.mechanics import (Particle, Point, ReferenceFrame,
|
| 3 |
+
RigidBody)
|
| 4 |
+
from sympy.physics.mechanics import (angular_momentum, dynamicsymbols,
|
| 5 |
+
kinetic_energy, linear_momentum,
|
| 6 |
+
outer, potential_energy, msubs,
|
| 7 |
+
find_dynamicsymbols, Lagrangian)
|
| 8 |
+
|
| 9 |
+
from sympy.physics.mechanics.functions import (
|
| 10 |
+
center_of_mass, _validate_coordinates, _parse_linear_solver)
|
| 11 |
+
from sympy.testing.pytest import raises, warns_deprecated_sympy
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
q1, q2, q3, q4, q5 = symbols('q1 q2 q3 q4 q5')
|
| 15 |
+
N = ReferenceFrame('N')
|
| 16 |
+
A = N.orientnew('A', 'Axis', [q1, N.z])
|
| 17 |
+
B = A.orientnew('B', 'Axis', [q2, A.x])
|
| 18 |
+
C = B.orientnew('C', 'Axis', [q3, B.y])
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_linear_momentum():
|
| 22 |
+
N = ReferenceFrame('N')
|
| 23 |
+
Ac = Point('Ac')
|
| 24 |
+
Ac.set_vel(N, 25 * N.y)
|
| 25 |
+
I = outer(N.x, N.x)
|
| 26 |
+
A = RigidBody('A', Ac, N, 20, (I, Ac))
|
| 27 |
+
P = Point('P')
|
| 28 |
+
Pa = Particle('Pa', P, 1)
|
| 29 |
+
Pa.point.set_vel(N, 10 * N.x)
|
| 30 |
+
raises(TypeError, lambda: linear_momentum(A, A, Pa))
|
| 31 |
+
raises(TypeError, lambda: linear_momentum(N, N, Pa))
|
| 32 |
+
assert linear_momentum(N, A, Pa) == 10 * N.x + 500 * N.y
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_angular_momentum_and_linear_momentum():
|
| 36 |
+
"""A rod with length 2l, centroidal inertia I, and mass M along with a
|
| 37 |
+
particle of mass m fixed to the end of the rod rotate with an angular rate
|
| 38 |
+
of omega about point O which is fixed to the non-particle end of the rod.
|
| 39 |
+
The rod's reference frame is A and the inertial frame is N."""
|
| 40 |
+
m, M, l, I = symbols('m, M, l, I')
|
| 41 |
+
omega = dynamicsymbols('omega')
|
| 42 |
+
N = ReferenceFrame('N')
|
| 43 |
+
a = ReferenceFrame('a')
|
| 44 |
+
O = Point('O')
|
| 45 |
+
Ac = O.locatenew('Ac', l * N.x)
|
| 46 |
+
P = Ac.locatenew('P', l * N.x)
|
| 47 |
+
O.set_vel(N, 0 * N.x)
|
| 48 |
+
a.set_ang_vel(N, omega * N.z)
|
| 49 |
+
Ac.v2pt_theory(O, N, a)
|
| 50 |
+
P.v2pt_theory(O, N, a)
|
| 51 |
+
Pa = Particle('Pa', P, m)
|
| 52 |
+
A = RigidBody('A', Ac, a, M, (I * outer(N.z, N.z), Ac))
|
| 53 |
+
expected = 2 * m * omega * l * N.y + M * l * omega * N.y
|
| 54 |
+
assert linear_momentum(N, A, Pa) == expected
|
| 55 |
+
raises(TypeError, lambda: angular_momentum(N, N, A, Pa))
|
| 56 |
+
raises(TypeError, lambda: angular_momentum(O, O, A, Pa))
|
| 57 |
+
raises(TypeError, lambda: angular_momentum(O, N, O, Pa))
|
| 58 |
+
expected = (I + M * l**2 + 4 * m * l**2) * omega * N.z
|
| 59 |
+
assert angular_momentum(O, N, A, Pa) == expected
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_kinetic_energy():
|
| 63 |
+
m, M, l1 = symbols('m M l1')
|
| 64 |
+
omega = dynamicsymbols('omega')
|
| 65 |
+
N = ReferenceFrame('N')
|
| 66 |
+
O = Point('O')
|
| 67 |
+
O.set_vel(N, 0 * N.x)
|
| 68 |
+
Ac = O.locatenew('Ac', l1 * N.x)
|
| 69 |
+
P = Ac.locatenew('P', l1 * N.x)
|
| 70 |
+
a = ReferenceFrame('a')
|
| 71 |
+
a.set_ang_vel(N, omega * N.z)
|
| 72 |
+
Ac.v2pt_theory(O, N, a)
|
| 73 |
+
P.v2pt_theory(O, N, a)
|
| 74 |
+
Pa = Particle('Pa', P, m)
|
| 75 |
+
I = outer(N.z, N.z)
|
| 76 |
+
A = RigidBody('A', Ac, a, M, (I, Ac))
|
| 77 |
+
raises(TypeError, lambda: kinetic_energy(Pa, Pa, A))
|
| 78 |
+
raises(TypeError, lambda: kinetic_energy(N, N, A))
|
| 79 |
+
assert 0 == (kinetic_energy(N, Pa, A) - (M*l1**2*omega**2/2
|
| 80 |
+
+ 2*l1**2*m*omega**2 + omega**2/2)).expand()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_potential_energy():
|
| 84 |
+
m, M, l1, g, h, H = symbols('m M l1 g h H')
|
| 85 |
+
omega = dynamicsymbols('omega')
|
| 86 |
+
N = ReferenceFrame('N')
|
| 87 |
+
O = Point('O')
|
| 88 |
+
O.set_vel(N, 0 * N.x)
|
| 89 |
+
Ac = O.locatenew('Ac', l1 * N.x)
|
| 90 |
+
P = Ac.locatenew('P', l1 * N.x)
|
| 91 |
+
a = ReferenceFrame('a')
|
| 92 |
+
a.set_ang_vel(N, omega * N.z)
|
| 93 |
+
Ac.v2pt_theory(O, N, a)
|
| 94 |
+
P.v2pt_theory(O, N, a)
|
| 95 |
+
Pa = Particle('Pa', P, m)
|
| 96 |
+
I = outer(N.z, N.z)
|
| 97 |
+
A = RigidBody('A', Ac, a, M, (I, Ac))
|
| 98 |
+
Pa.potential_energy = m * g * h
|
| 99 |
+
A.potential_energy = M * g * H
|
| 100 |
+
assert potential_energy(A, Pa) == m * g * h + M * g * H
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_Lagrangian():
|
| 104 |
+
M, m, g, h = symbols('M m g h')
|
| 105 |
+
N = ReferenceFrame('N')
|
| 106 |
+
O = Point('O')
|
| 107 |
+
O.set_vel(N, 0 * N.x)
|
| 108 |
+
P = O.locatenew('P', 1 * N.x)
|
| 109 |
+
P.set_vel(N, 10 * N.x)
|
| 110 |
+
Pa = Particle('Pa', P, 1)
|
| 111 |
+
Ac = O.locatenew('Ac', 2 * N.y)
|
| 112 |
+
Ac.set_vel(N, 5 * N.y)
|
| 113 |
+
a = ReferenceFrame('a')
|
| 114 |
+
a.set_ang_vel(N, 10 * N.z)
|
| 115 |
+
I = outer(N.z, N.z)
|
| 116 |
+
A = RigidBody('A', Ac, a, 20, (I, Ac))
|
| 117 |
+
Pa.potential_energy = m * g * h
|
| 118 |
+
A.potential_energy = M * g * h
|
| 119 |
+
raises(TypeError, lambda: Lagrangian(A, A, Pa))
|
| 120 |
+
raises(TypeError, lambda: Lagrangian(N, N, Pa))
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_msubs():
|
| 124 |
+
a, b = symbols('a, b')
|
| 125 |
+
x, y, z = dynamicsymbols('x, y, z')
|
| 126 |
+
# Test simple substitution
|
| 127 |
+
expr = Matrix([[a*x + b, x*y.diff() + y],
|
| 128 |
+
[x.diff().diff(), z + sin(z.diff())]])
|
| 129 |
+
sol = Matrix([[a + b, y],
|
| 130 |
+
[x.diff().diff(), 1]])
|
| 131 |
+
sd = {x: 1, z: 1, z.diff(): 0, y.diff(): 0}
|
| 132 |
+
assert msubs(expr, sd) == sol
|
| 133 |
+
# Test smart substitution
|
| 134 |
+
expr = cos(x + y)*tan(x + y) + b*x.diff()
|
| 135 |
+
sd = {x: 0, y: pi/2, x.diff(): 1}
|
| 136 |
+
assert msubs(expr, sd, smart=True) == b + 1
|
| 137 |
+
N = ReferenceFrame('N')
|
| 138 |
+
v = x*N.x + y*N.y
|
| 139 |
+
d = x*(N.x|N.x) + y*(N.y|N.y)
|
| 140 |
+
v_sol = 1*N.y
|
| 141 |
+
d_sol = 1*(N.y|N.y)
|
| 142 |
+
sd = {x: 0, y: 1}
|
| 143 |
+
assert msubs(v, sd) == v_sol
|
| 144 |
+
assert msubs(d, sd) == d_sol
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def test_find_dynamicsymbols():
|
| 148 |
+
a, b = symbols('a, b')
|
| 149 |
+
x, y, z = dynamicsymbols('x, y, z')
|
| 150 |
+
expr = Matrix([[a*x + b, x*y.diff() + y],
|
| 151 |
+
[x.diff().diff(), z + sin(z.diff())]])
|
| 152 |
+
# Test finding all dynamicsymbols
|
| 153 |
+
sol = {x, y.diff(), y, x.diff().diff(), z, z.diff()}
|
| 154 |
+
assert find_dynamicsymbols(expr) == sol
|
| 155 |
+
# Test finding all but those in sym_list
|
| 156 |
+
exclude_list = [x, y, z]
|
| 157 |
+
sol = {y.diff(), x.diff().diff(), z.diff()}
|
| 158 |
+
assert find_dynamicsymbols(expr, exclude=exclude_list) == sol
|
| 159 |
+
# Test finding all dynamicsymbols in a vector with a given reference frame
|
| 160 |
+
d, e, f = dynamicsymbols('d, e, f')
|
| 161 |
+
A = ReferenceFrame('A')
|
| 162 |
+
v = d * A.x + e * A.y + f * A.z
|
| 163 |
+
sol = {d, e, f}
|
| 164 |
+
assert find_dynamicsymbols(v, reference_frame=A) == sol
|
| 165 |
+
# Test if a ValueError is raised on supplying only a vector as input
|
| 166 |
+
raises(ValueError, lambda: find_dynamicsymbols(v))
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# This function tests the center_of_mass() function
|
| 170 |
+
# that was added in PR #14758 to compute the center of
|
| 171 |
+
# mass of a system of bodies.
|
| 172 |
+
def test_center_of_mass():
|
| 173 |
+
a = ReferenceFrame('a')
|
| 174 |
+
m = symbols('m', real=True)
|
| 175 |
+
p1 = Particle('p1', Point('p1_pt'), S.One)
|
| 176 |
+
p2 = Particle('p2', Point('p2_pt'), S(2))
|
| 177 |
+
p3 = Particle('p3', Point('p3_pt'), S(3))
|
| 178 |
+
p4 = Particle('p4', Point('p4_pt'), m)
|
| 179 |
+
b_f = ReferenceFrame('b_f')
|
| 180 |
+
b_cm = Point('b_cm')
|
| 181 |
+
mb = symbols('mb')
|
| 182 |
+
b = RigidBody('b', b_cm, b_f, mb, (outer(b_f.x, b_f.x), b_cm))
|
| 183 |
+
p2.point.set_pos(p1.point, a.x)
|
| 184 |
+
p3.point.set_pos(p1.point, a.x + a.y)
|
| 185 |
+
p4.point.set_pos(p1.point, a.y)
|
| 186 |
+
b.masscenter.set_pos(p1.point, a.y + a.z)
|
| 187 |
+
point_o=Point('o')
|
| 188 |
+
point_o.set_pos(p1.point, center_of_mass(p1.point, p1, p2, p3, p4, b))
|
| 189 |
+
expr = 5/(m + mb + 6)*a.x + (m + mb + 3)/(m + mb + 6)*a.y + mb/(m + mb + 6)*a.z
|
| 190 |
+
assert point_o.pos_from(p1.point)-expr == 0
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_validate_coordinates():
|
| 194 |
+
q1, q2, q3, u1, u2, u3, ua1, ua2, ua3 = dynamicsymbols('q1:4 u1:4 ua1:4')
|
| 195 |
+
s1, s2, s3 = symbols('s1:4')
|
| 196 |
+
# Test normal
|
| 197 |
+
_validate_coordinates([q1, q2, q3], [u1, u2, u3],
|
| 198 |
+
u_auxiliary=[ua1, ua2, ua3])
|
| 199 |
+
# Test not equal number of coordinates and speeds
|
| 200 |
+
_validate_coordinates([q1, q2])
|
| 201 |
+
_validate_coordinates([q1, q2], [u1])
|
| 202 |
+
_validate_coordinates(speeds=[u1, u2])
|
| 203 |
+
# Test duplicate
|
| 204 |
+
_validate_coordinates([q1, q2, q2], [u1, u2, u3], check_duplicates=False)
|
| 205 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 206 |
+
[q1, q2, q2], [u1, u2, u3]))
|
| 207 |
+
_validate_coordinates([q1, q2, q3], [u1, u2, u2], check_duplicates=False)
|
| 208 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 209 |
+
[q1, q2, q3], [u1, u2, u2], check_duplicates=True))
|
| 210 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 211 |
+
[q1, q2, q3], [q1, u2, u3], check_duplicates=True))
|
| 212 |
+
_validate_coordinates([q1, q2, q3], [u1, u2, u3], check_duplicates=False,
|
| 213 |
+
u_auxiliary=[u1, ua2, ua2])
|
| 214 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 215 |
+
[q1, q2, q3], [u1, u2, u3], u_auxiliary=[u1, ua2, ua3]))
|
| 216 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 217 |
+
[q1, q2, q3], [u1, u2, u3], u_auxiliary=[q1, ua2, ua3]))
|
| 218 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 219 |
+
[q1, q2, q3], [u1, u2, u3], u_auxiliary=[ua1, ua2, ua2]))
|
| 220 |
+
# Test is_dynamicsymbols
|
| 221 |
+
_validate_coordinates([q1 + q2, q3], is_dynamicsymbols=False)
|
| 222 |
+
raises(ValueError, lambda: _validate_coordinates([q1 + q2, q3]))
|
| 223 |
+
_validate_coordinates([s1, q1, q2], [0, u1, u2], is_dynamicsymbols=False)
|
| 224 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 225 |
+
[s1, q1, q2], [0, u1, u2], is_dynamicsymbols=True))
|
| 226 |
+
_validate_coordinates([s1 + s2 + s3, q1], [0, u1], is_dynamicsymbols=False)
|
| 227 |
+
raises(ValueError, lambda: _validate_coordinates(
|
| 228 |
+
[s1 + s2 + s3, q1], [0, u1], is_dynamicsymbols=True))
|
| 229 |
+
_validate_coordinates(u_auxiliary=[s1, ua1], is_dynamicsymbols=False)
|
| 230 |
+
raises(ValueError, lambda: _validate_coordinates(u_auxiliary=[s1, ua1]))
|
| 231 |
+
# Test normal function
|
| 232 |
+
t = dynamicsymbols._t
|
| 233 |
+
a = symbols('a')
|
| 234 |
+
f1, f2 = symbols('f1:3', cls=Function)
|
| 235 |
+
_validate_coordinates([f1(a), f2(a)], is_dynamicsymbols=False)
|
| 236 |
+
raises(ValueError, lambda: _validate_coordinates([f1(a), f2(a)]))
|
| 237 |
+
raises(ValueError, lambda: _validate_coordinates(speeds=[f1(a), f2(a)]))
|
| 238 |
+
dynamicsymbols._t = a
|
| 239 |
+
_validate_coordinates([f1(a), f2(a)])
|
| 240 |
+
raises(ValueError, lambda: _validate_coordinates([f1(t), f2(t)]))
|
| 241 |
+
dynamicsymbols._t = t
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_parse_linear_solver():
|
| 245 |
+
A, b = Matrix(3, 3, symbols('a:9')), Matrix(3, 2, symbols('b:6'))
|
| 246 |
+
assert _parse_linear_solver(Matrix.LUsolve) == Matrix.LUsolve # Test callable
|
| 247 |
+
assert _parse_linear_solver('LU')(A, b) == Matrix.LUsolve(A, b)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def test_deprecated_moved_functions():
|
| 251 |
+
from sympy.physics.mechanics.functions import (
|
| 252 |
+
inertia, inertia_of_point_mass, gravity)
|
| 253 |
+
N = ReferenceFrame('N')
|
| 254 |
+
with warns_deprecated_sympy():
|
| 255 |
+
assert inertia(N, 0, 1, 0, 1) == (N.x | N.y) + (N.y | N.x) + (N.y | N.y)
|
| 256 |
+
with warns_deprecated_sympy():
|
| 257 |
+
assert inertia_of_point_mass(1, N.x + N.y, N) == (
|
| 258 |
+
(N.x | N.x) + (N.y | N.y) + 2 * (N.z | N.z) -
|
| 259 |
+
(N.x | N.y) - (N.y | N.x))
|
| 260 |
+
p = Particle('P')
|
| 261 |
+
with warns_deprecated_sympy():
|
| 262 |
+
assert gravity(-2 * N.z, p) == [(p.masscenter, -2 * p.mass * N.z)]
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_kane3.py
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.numbers import pi
|
| 2 |
+
from sympy.core.symbol import symbols
|
| 3 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 4 |
+
from sympy.functions.elementary.trigonometric import acos, sin, cos
|
| 5 |
+
from sympy.matrices.dense import Matrix
|
| 6 |
+
from sympy.physics.mechanics import (ReferenceFrame, dynamicsymbols,
|
| 7 |
+
KanesMethod, inertia, Point, RigidBody,
|
| 8 |
+
dot)
|
| 9 |
+
from sympy.testing.pytest import slow
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@slow
|
| 13 |
+
def test_bicycle():
|
| 14 |
+
# Code to get equations of motion for a bicycle modeled as in:
|
| 15 |
+
# J.P Meijaard, Jim M Papadopoulos, Andy Ruina and A.L Schwab. Linearized
|
| 16 |
+
# dynamics equations for the balance and steer of a bicycle: a benchmark
|
| 17 |
+
# and review. Proceedings of The Royal Society (2007) 463, 1955-1982
|
| 18 |
+
# doi: 10.1098/rspa.2007.1857
|
| 19 |
+
|
| 20 |
+
# Note that this code has been crudely ported from Autolev, which is the
|
| 21 |
+
# reason for some of the unusual naming conventions. It was purposefully as
|
| 22 |
+
# similar as possible in order to aide debugging.
|
| 23 |
+
|
| 24 |
+
# Declare Coordinates & Speeds
|
| 25 |
+
# Simple definitions for qdots - qd = u
|
| 26 |
+
# Speeds are:
|
| 27 |
+
# - u1: yaw frame ang. rate
|
| 28 |
+
# - u2: roll frame ang. rate
|
| 29 |
+
# - u3: rear wheel frame ang. rate (spinning motion)
|
| 30 |
+
# - u4: frame ang. rate (pitching motion)
|
| 31 |
+
# - u5: steering frame ang. rate
|
| 32 |
+
# - u6: front wheel ang. rate (spinning motion)
|
| 33 |
+
# Wheel positions are ignorable coordinates, so they are not introduced.
|
| 34 |
+
q1, q2, q4, q5 = dynamicsymbols('q1 q2 q4 q5')
|
| 35 |
+
q1d, q2d, q4d, q5d = dynamicsymbols('q1 q2 q4 q5', 1)
|
| 36 |
+
u1, u2, u3, u4, u5, u6 = dynamicsymbols('u1 u2 u3 u4 u5 u6')
|
| 37 |
+
u1d, u2d, u3d, u4d, u5d, u6d = dynamicsymbols('u1 u2 u3 u4 u5 u6', 1)
|
| 38 |
+
|
| 39 |
+
# Declare System's Parameters
|
| 40 |
+
WFrad, WRrad, htangle, forkoffset = symbols('WFrad WRrad htangle forkoffset')
|
| 41 |
+
forklength, framelength, forkcg1 = symbols('forklength framelength forkcg1')
|
| 42 |
+
forkcg3, framecg1, framecg3, Iwr11 = symbols('forkcg3 framecg1 framecg3 Iwr11')
|
| 43 |
+
Iwr22, Iwf11, Iwf22, Iframe11 = symbols('Iwr22 Iwf11 Iwf22 Iframe11')
|
| 44 |
+
Iframe22, Iframe33, Iframe31, Ifork11 = symbols('Iframe22 Iframe33 Iframe31 Ifork11')
|
| 45 |
+
Ifork22, Ifork33, Ifork31, g = symbols('Ifork22 Ifork33 Ifork31 g')
|
| 46 |
+
mframe, mfork, mwf, mwr = symbols('mframe mfork mwf mwr')
|
| 47 |
+
|
| 48 |
+
# Set up reference frames for the system
|
| 49 |
+
# N - inertial
|
| 50 |
+
# Y - yaw
|
| 51 |
+
# R - roll
|
| 52 |
+
# WR - rear wheel, rotation angle is ignorable coordinate so not oriented
|
| 53 |
+
# Frame - bicycle frame
|
| 54 |
+
# TempFrame - statically rotated frame for easier reference inertia definition
|
| 55 |
+
# Fork - bicycle fork
|
| 56 |
+
# TempFork - statically rotated frame for easier reference inertia definition
|
| 57 |
+
# WF - front wheel, again posses a ignorable coordinate
|
| 58 |
+
N = ReferenceFrame('N')
|
| 59 |
+
Y = N.orientnew('Y', 'Axis', [q1, N.z])
|
| 60 |
+
R = Y.orientnew('R', 'Axis', [q2, Y.x])
|
| 61 |
+
Frame = R.orientnew('Frame', 'Axis', [q4 + htangle, R.y])
|
| 62 |
+
WR = ReferenceFrame('WR')
|
| 63 |
+
TempFrame = Frame.orientnew('TempFrame', 'Axis', [-htangle, Frame.y])
|
| 64 |
+
Fork = Frame.orientnew('Fork', 'Axis', [q5, Frame.x])
|
| 65 |
+
TempFork = Fork.orientnew('TempFork', 'Axis', [-htangle, Fork.y])
|
| 66 |
+
WF = ReferenceFrame('WF')
|
| 67 |
+
|
| 68 |
+
# Kinematics of the Bicycle First block of code is forming the positions of
|
| 69 |
+
# the relevant points
|
| 70 |
+
# rear wheel contact -> rear wheel mass center -> frame mass center +
|
| 71 |
+
# frame/fork connection -> fork mass center + front wheel mass center ->
|
| 72 |
+
# front wheel contact point
|
| 73 |
+
WR_cont = Point('WR_cont')
|
| 74 |
+
WR_mc = WR_cont.locatenew('WR_mc', WRrad * R.z)
|
| 75 |
+
Steer = WR_mc.locatenew('Steer', framelength * Frame.z)
|
| 76 |
+
Frame_mc = WR_mc.locatenew('Frame_mc', - framecg1 * Frame.x
|
| 77 |
+
+ framecg3 * Frame.z)
|
| 78 |
+
Fork_mc = Steer.locatenew('Fork_mc', - forkcg1 * Fork.x
|
| 79 |
+
+ forkcg3 * Fork.z)
|
| 80 |
+
WF_mc = Steer.locatenew('WF_mc', forklength * Fork.x + forkoffset * Fork.z)
|
| 81 |
+
WF_cont = WF_mc.locatenew('WF_cont', WFrad * (dot(Fork.y, Y.z) * Fork.y -
|
| 82 |
+
Y.z).normalize())
|
| 83 |
+
|
| 84 |
+
# Set the angular velocity of each frame.
|
| 85 |
+
# Angular accelerations end up being calculated automatically by
|
| 86 |
+
# differentiating the angular velocities when first needed.
|
| 87 |
+
# u1 is yaw rate
|
| 88 |
+
# u2 is roll rate
|
| 89 |
+
# u3 is rear wheel rate
|
| 90 |
+
# u4 is frame pitch rate
|
| 91 |
+
# u5 is fork steer rate
|
| 92 |
+
# u6 is front wheel rate
|
| 93 |
+
Y.set_ang_vel(N, u1 * Y.z)
|
| 94 |
+
R.set_ang_vel(Y, u2 * R.x)
|
| 95 |
+
WR.set_ang_vel(Frame, u3 * Frame.y)
|
| 96 |
+
Frame.set_ang_vel(R, u4 * Frame.y)
|
| 97 |
+
Fork.set_ang_vel(Frame, u5 * Fork.x)
|
| 98 |
+
WF.set_ang_vel(Fork, u6 * Fork.y)
|
| 99 |
+
|
| 100 |
+
# Form the velocities of the previously defined points, using the 2 - point
|
| 101 |
+
# theorem (written out by hand here). Accelerations again are calculated
|
| 102 |
+
# automatically when first needed.
|
| 103 |
+
WR_cont.set_vel(N, 0)
|
| 104 |
+
WR_mc.v2pt_theory(WR_cont, N, WR)
|
| 105 |
+
Steer.v2pt_theory(WR_mc, N, Frame)
|
| 106 |
+
Frame_mc.v2pt_theory(WR_mc, N, Frame)
|
| 107 |
+
Fork_mc.v2pt_theory(Steer, N, Fork)
|
| 108 |
+
WF_mc.v2pt_theory(Steer, N, Fork)
|
| 109 |
+
WF_cont.v2pt_theory(WF_mc, N, WF)
|
| 110 |
+
|
| 111 |
+
# Sets the inertias of each body. Uses the inertia frame to construct the
|
| 112 |
+
# inertia dyadics. Wheel inertias are only defined by principle moments of
|
| 113 |
+
# inertia, and are in fact constant in the frame and fork reference frames;
|
| 114 |
+
# it is for this reason that the orientations of the wheels does not need
|
| 115 |
+
# to be defined. The frame and fork inertias are defined in the 'Temp'
|
| 116 |
+
# frames which are fixed to the appropriate body frames; this is to allow
|
| 117 |
+
# easier input of the reference values of the benchmark paper. Note that
|
| 118 |
+
# due to slightly different orientations, the products of inertia need to
|
| 119 |
+
# have their signs flipped; this is done later when entering the numerical
|
| 120 |
+
# value.
|
| 121 |
+
|
| 122 |
+
Frame_I = (inertia(TempFrame, Iframe11, Iframe22, Iframe33, 0, 0, Iframe31), Frame_mc)
|
| 123 |
+
Fork_I = (inertia(TempFork, Ifork11, Ifork22, Ifork33, 0, 0, Ifork31), Fork_mc)
|
| 124 |
+
WR_I = (inertia(Frame, Iwr11, Iwr22, Iwr11), WR_mc)
|
| 125 |
+
WF_I = (inertia(Fork, Iwf11, Iwf22, Iwf11), WF_mc)
|
| 126 |
+
|
| 127 |
+
# Declaration of the RigidBody containers. ::
|
| 128 |
+
|
| 129 |
+
BodyFrame = RigidBody('BodyFrame', Frame_mc, Frame, mframe, Frame_I)
|
| 130 |
+
BodyFork = RigidBody('BodyFork', Fork_mc, Fork, mfork, Fork_I)
|
| 131 |
+
BodyWR = RigidBody('BodyWR', WR_mc, WR, mwr, WR_I)
|
| 132 |
+
BodyWF = RigidBody('BodyWF', WF_mc, WF, mwf, WF_I)
|
| 133 |
+
|
| 134 |
+
# The kinematic differential equations; they are defined quite simply. Each
|
| 135 |
+
# entry in this list is equal to zero.
|
| 136 |
+
kd = [q1d - u1, q2d - u2, q4d - u4, q5d - u5]
|
| 137 |
+
|
| 138 |
+
# The nonholonomic constraints are the velocity of the front wheel contact
|
| 139 |
+
# point dotted into the X, Y, and Z directions; the yaw frame is used as it
|
| 140 |
+
# is "closer" to the front wheel (1 less DCM connecting them). These
|
| 141 |
+
# constraints force the velocity of the front wheel contact point to be 0
|
| 142 |
+
# in the inertial frame; the X and Y direction constraints enforce a
|
| 143 |
+
# "no-slip" condition, and the Z direction constraint forces the front
|
| 144 |
+
# wheel contact point to not move away from the ground frame, essentially
|
| 145 |
+
# replicating the holonomic constraint which does not allow the frame pitch
|
| 146 |
+
# to change in an invalid fashion.
|
| 147 |
+
|
| 148 |
+
conlist_speed = [WF_cont.vel(N) & Y.x, WF_cont.vel(N) & Y.y, WF_cont.vel(N) & Y.z]
|
| 149 |
+
|
| 150 |
+
# The holonomic constraint is that the position from the rear wheel contact
|
| 151 |
+
# point to the front wheel contact point when dotted into the
|
| 152 |
+
# normal-to-ground plane direction must be zero; effectively that the front
|
| 153 |
+
# and rear wheel contact points are always touching the ground plane. This
|
| 154 |
+
# is actually not part of the dynamic equations, but instead is necessary
|
| 155 |
+
# for the lineraization process.
|
| 156 |
+
|
| 157 |
+
conlist_coord = [WF_cont.pos_from(WR_cont) & Y.z]
|
| 158 |
+
|
| 159 |
+
# The force list; each body has the appropriate gravitational force applied
|
| 160 |
+
# at its mass center.
|
| 161 |
+
FL = [(Frame_mc, -mframe * g * Y.z),
|
| 162 |
+
(Fork_mc, -mfork * g * Y.z),
|
| 163 |
+
(WF_mc, -mwf * g * Y.z),
|
| 164 |
+
(WR_mc, -mwr * g * Y.z)]
|
| 165 |
+
BL = [BodyFrame, BodyFork, BodyWR, BodyWF]
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# The N frame is the inertial frame, coordinates are supplied in the order
|
| 169 |
+
# of independent, dependent coordinates, as are the speeds. The kinematic
|
| 170 |
+
# differential equation are also entered here. Here the dependent speeds
|
| 171 |
+
# are specified, in the same order they were provided in earlier, along
|
| 172 |
+
# with the non-holonomic constraints. The dependent coordinate is also
|
| 173 |
+
# provided, with the holonomic constraint. Again, this is only provided
|
| 174 |
+
# for the linearization process.
|
| 175 |
+
|
| 176 |
+
KM = KanesMethod(N, q_ind=[q1, q2, q5],
|
| 177 |
+
q_dependent=[q4], configuration_constraints=conlist_coord,
|
| 178 |
+
u_ind=[u2, u3, u5],
|
| 179 |
+
u_dependent=[u1, u4, u6], velocity_constraints=conlist_speed,
|
| 180 |
+
kd_eqs=kd,
|
| 181 |
+
constraint_solver="CRAMER")
|
| 182 |
+
(fr, frstar) = KM.kanes_equations(BL, FL)
|
| 183 |
+
|
| 184 |
+
# This is the start of entering in the numerical values from the benchmark
|
| 185 |
+
# paper to validate the eigen values of the linearized equations from this
|
| 186 |
+
# model to the reference eigen values. Look at the aforementioned paper for
|
| 187 |
+
# more information. Some of these are intermediate values, used to
|
| 188 |
+
# transform values from the paper into the coordinate systems used in this
|
| 189 |
+
# model.
|
| 190 |
+
PaperRadRear = 0.3
|
| 191 |
+
PaperRadFront = 0.35
|
| 192 |
+
HTA = (pi / 2 - pi / 10).evalf()
|
| 193 |
+
TrailPaper = 0.08
|
| 194 |
+
rake = (-(TrailPaper*sin(HTA)-(PaperRadFront*cos(HTA)))).evalf()
|
| 195 |
+
PaperWb = 1.02
|
| 196 |
+
PaperFrameCgX = 0.3
|
| 197 |
+
PaperFrameCgZ = 0.9
|
| 198 |
+
PaperForkCgX = 0.9
|
| 199 |
+
PaperForkCgZ = 0.7
|
| 200 |
+
FrameLength = (PaperWb*sin(HTA)-(rake-(PaperRadFront-PaperRadRear)*cos(HTA))).evalf()
|
| 201 |
+
FrameCGNorm = ((PaperFrameCgZ - PaperRadRear-(PaperFrameCgX/sin(HTA))*cos(HTA))*sin(HTA)).evalf()
|
| 202 |
+
FrameCGPar = (PaperFrameCgX / sin(HTA) + (PaperFrameCgZ - PaperRadRear - PaperFrameCgX / sin(HTA) * cos(HTA)) * cos(HTA)).evalf()
|
| 203 |
+
tempa = (PaperForkCgZ - PaperRadFront)
|
| 204 |
+
tempb = (PaperWb-PaperForkCgX)
|
| 205 |
+
tempc = (sqrt(tempa**2+tempb**2)).evalf()
|
| 206 |
+
PaperForkL = (PaperWb*cos(HTA)-(PaperRadFront-PaperRadRear)*sin(HTA)).evalf()
|
| 207 |
+
ForkCGNorm = (rake+(tempc * sin(pi/2-HTA-acos(tempa/tempc)))).evalf()
|
| 208 |
+
ForkCGPar = (tempc * cos((pi/2-HTA)-acos(tempa/tempc))-PaperForkL).evalf()
|
| 209 |
+
|
| 210 |
+
# Here is the final assembly of the numerical values. The symbol 'v' is the
|
| 211 |
+
# forward speed of the bicycle (a concept which only makes sense in the
|
| 212 |
+
# upright, static equilibrium case?). These are in a dictionary which will
|
| 213 |
+
# later be substituted in. Again the sign on the *product* of inertia
|
| 214 |
+
# values is flipped here, due to different orientations of coordinate
|
| 215 |
+
# systems.
|
| 216 |
+
v = symbols('v')
|
| 217 |
+
val_dict = {WFrad: PaperRadFront,
|
| 218 |
+
WRrad: PaperRadRear,
|
| 219 |
+
htangle: HTA,
|
| 220 |
+
forkoffset: rake,
|
| 221 |
+
forklength: PaperForkL,
|
| 222 |
+
framelength: FrameLength,
|
| 223 |
+
forkcg1: ForkCGPar,
|
| 224 |
+
forkcg3: ForkCGNorm,
|
| 225 |
+
framecg1: FrameCGNorm,
|
| 226 |
+
framecg3: FrameCGPar,
|
| 227 |
+
Iwr11: 0.0603,
|
| 228 |
+
Iwr22: 0.12,
|
| 229 |
+
Iwf11: 0.1405,
|
| 230 |
+
Iwf22: 0.28,
|
| 231 |
+
Ifork11: 0.05892,
|
| 232 |
+
Ifork22: 0.06,
|
| 233 |
+
Ifork33: 0.00708,
|
| 234 |
+
Ifork31: 0.00756,
|
| 235 |
+
Iframe11: 9.2,
|
| 236 |
+
Iframe22: 11,
|
| 237 |
+
Iframe33: 2.8,
|
| 238 |
+
Iframe31: -2.4,
|
| 239 |
+
mfork: 4,
|
| 240 |
+
mframe: 85,
|
| 241 |
+
mwf: 3,
|
| 242 |
+
mwr: 2,
|
| 243 |
+
g: 9.81,
|
| 244 |
+
q1: 0,
|
| 245 |
+
q2: 0,
|
| 246 |
+
q4: 0,
|
| 247 |
+
q5: 0,
|
| 248 |
+
u1: 0,
|
| 249 |
+
u2: 0,
|
| 250 |
+
u3: v / PaperRadRear,
|
| 251 |
+
u4: 0,
|
| 252 |
+
u5: 0,
|
| 253 |
+
u6: v / PaperRadFront}
|
| 254 |
+
|
| 255 |
+
# Linearizes the forcing vector; the equations are set up as MM udot =
|
| 256 |
+
# forcing, where MM is the mass matrix, udot is the vector representing the
|
| 257 |
+
# time derivatives of the generalized speeds, and forcing is a vector which
|
| 258 |
+
# contains both external forcing terms and internal forcing terms, such as
|
| 259 |
+
# centripital or coriolis forces. This actually returns a matrix with as
|
| 260 |
+
# many rows as *total* coordinates and speeds, but only as many columns as
|
| 261 |
+
# independent coordinates and speeds.
|
| 262 |
+
|
| 263 |
+
A, B, _ = KM.linearize(
|
| 264 |
+
A_and_B=True,
|
| 265 |
+
op_point={
|
| 266 |
+
# Operating points for the accelerations are required for the
|
| 267 |
+
# linearizer to eliminate u' terms showing up in the coefficient
|
| 268 |
+
# matrices.
|
| 269 |
+
u1.diff(): 0,
|
| 270 |
+
u2.diff(): 0,
|
| 271 |
+
u3.diff(): 0,
|
| 272 |
+
u4.diff(): 0,
|
| 273 |
+
u5.diff(): 0,
|
| 274 |
+
u6.diff(): 0,
|
| 275 |
+
u1: 0,
|
| 276 |
+
u2: 0,
|
| 277 |
+
u3: v / PaperRadRear,
|
| 278 |
+
u4: 0,
|
| 279 |
+
u5: 0,
|
| 280 |
+
u6: v / PaperRadFront,
|
| 281 |
+
q1: 0,
|
| 282 |
+
q2: 0,
|
| 283 |
+
q4: 0,
|
| 284 |
+
q5: 0,
|
| 285 |
+
},
|
| 286 |
+
linear_solver="CRAMER",
|
| 287 |
+
)
|
| 288 |
+
# As mentioned above, the size of the linearized forcing terms is expanded
|
| 289 |
+
# to include both q's and u's, so the mass matrix must have this done as
|
| 290 |
+
# well. This will likely be changed to be part of the linearized process,
|
| 291 |
+
# for future reference.
|
| 292 |
+
A_s = A.xreplace(val_dict)
|
| 293 |
+
B_s = B.xreplace(val_dict)
|
| 294 |
+
|
| 295 |
+
A_s = A_s.evalf()
|
| 296 |
+
B_s = B_s.evalf()
|
| 297 |
+
|
| 298 |
+
# Finally, we construct an "A" matrix for the form xdot = A x (x being the
|
| 299 |
+
# state vector, although in this case, the sizes are a little off). The
|
| 300 |
+
# following line extracts only the minimum entries required for eigenvalue
|
| 301 |
+
# analysis, which correspond to rows and columns for lean, steer, lean
|
| 302 |
+
# rate, and steer rate.
|
| 303 |
+
A = A_s.extract([1, 2, 3, 5], [1, 2, 3, 5])
|
| 304 |
+
|
| 305 |
+
# Precomputed for comparison
|
| 306 |
+
Res = Matrix([[ 0, 0, 1.0, 0],
|
| 307 |
+
[ 0, 0, 0, 1.0],
|
| 308 |
+
[9.48977444677355, -0.891197738059089*v**2 - 0.571523173729245, -0.105522449805691*v, -0.330515398992311*v],
|
| 309 |
+
[11.7194768719633, -1.97171508499972*v**2 + 30.9087533932407, 3.67680523332152*v, -3.08486552743311*v]])
|
| 310 |
+
|
| 311 |
+
# Actual eigenvalue comparison
|
| 312 |
+
eps = 1.e-12
|
| 313 |
+
for i in range(6):
|
| 314 |
+
error = Res.subs(v, i) - A.subs(v, i)
|
| 315 |
+
assert all(abs(x) < eps for x in error)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_method.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.physics.mechanics.method import _Methods
|
| 2 |
+
from sympy.testing.pytest import raises
|
| 3 |
+
|
| 4 |
+
def test_method():
|
| 5 |
+
raises(TypeError, lambda: _Methods())
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/mechanics/tests/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.physics.mechanics import Point, ReferenceFrame, Dyadic, RigidBody
|
| 2 |
+
from sympy.physics.mechanics import dynamicsymbols, outer, inertia, Inertia
|
| 3 |
+
from sympy.physics.mechanics import inertia_of_point_mass
|
| 4 |
+
from sympy import expand, zeros, simplify, symbols
|
| 5 |
+
from sympy.testing.pytest import raises, warns_deprecated_sympy
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_rigidbody_default():
|
| 9 |
+
# Test default
|
| 10 |
+
b = RigidBody('B')
|
| 11 |
+
I = inertia(b.frame, *symbols('B_ixx B_iyy B_izz B_ixy B_iyz B_izx'))
|
| 12 |
+
assert b.name == 'B'
|
| 13 |
+
assert b.mass == symbols('B_mass')
|
| 14 |
+
assert b.masscenter.name == 'B_masscenter'
|
| 15 |
+
assert b.inertia == (I, b.masscenter)
|
| 16 |
+
assert b.central_inertia == I
|
| 17 |
+
assert b.frame.name == 'B_frame'
|
| 18 |
+
assert b.__str__() == 'B'
|
| 19 |
+
assert b.__repr__() == (
|
| 20 |
+
"RigidBody('B', masscenter=B_masscenter, frame=B_frame, mass=B_mass, "
|
| 21 |
+
"inertia=Inertia(dyadic=B_ixx*(B_frame.x|B_frame.x) + "
|
| 22 |
+
"B_ixy*(B_frame.x|B_frame.y) + B_izx*(B_frame.x|B_frame.z) + "
|
| 23 |
+
"B_ixy*(B_frame.y|B_frame.x) + B_iyy*(B_frame.y|B_frame.y) + "
|
| 24 |
+
"B_iyz*(B_frame.y|B_frame.z) + B_izx*(B_frame.z|B_frame.x) + "
|
| 25 |
+
"B_iyz*(B_frame.z|B_frame.y) + B_izz*(B_frame.z|B_frame.z), "
|
| 26 |
+
"point=B_masscenter))")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_rigidbody():
|
| 30 |
+
m, m2, v1, v2, v3, omega = symbols('m m2 v1 v2 v3 omega')
|
| 31 |
+
A = ReferenceFrame('A')
|
| 32 |
+
A2 = ReferenceFrame('A2')
|
| 33 |
+
P = Point('P')
|
| 34 |
+
P2 = Point('P2')
|
| 35 |
+
I = Dyadic(0)
|
| 36 |
+
I2 = Dyadic(0)
|
| 37 |
+
B = RigidBody('B', P, A, m, (I, P))
|
| 38 |
+
assert B.mass == m
|
| 39 |
+
assert B.frame == A
|
| 40 |
+
assert B.masscenter == P
|
| 41 |
+
assert B.inertia == (I, B.masscenter)
|
| 42 |
+
|
| 43 |
+
B.mass = m2
|
| 44 |
+
B.frame = A2
|
| 45 |
+
B.masscenter = P2
|
| 46 |
+
B.inertia = (I2, B.masscenter)
|
| 47 |
+
raises(TypeError, lambda: RigidBody(P, P, A, m, (I, P)))
|
| 48 |
+
raises(TypeError, lambda: RigidBody('B', P, P, m, (I, P)))
|
| 49 |
+
raises(TypeError, lambda: RigidBody('B', P, A, m, (P, P)))
|
| 50 |
+
raises(TypeError, lambda: RigidBody('B', P, A, m, (I, I)))
|
| 51 |
+
assert B.__str__() == 'B'
|
| 52 |
+
assert B.mass == m2
|
| 53 |
+
assert B.frame == A2
|
| 54 |
+
assert B.masscenter == P2
|
| 55 |
+
assert B.inertia == (I2, B.masscenter)
|
| 56 |
+
assert isinstance(B.inertia, Inertia)
|
| 57 |
+
|
| 58 |
+
# Testing linear momentum function assuming A2 is the inertial frame
|
| 59 |
+
N = ReferenceFrame('N')
|
| 60 |
+
P2.set_vel(N, v1 * N.x + v2 * N.y + v3 * N.z)
|
| 61 |
+
assert B.linear_momentum(N) == m2 * (v1 * N.x + v2 * N.y + v3 * N.z)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_rigidbody2():
|
| 65 |
+
M, v, r, omega, g, h = dynamicsymbols('M v r omega g h')
|
| 66 |
+
N = ReferenceFrame('N')
|
| 67 |
+
b = ReferenceFrame('b')
|
| 68 |
+
b.set_ang_vel(N, omega * b.x)
|
| 69 |
+
P = Point('P')
|
| 70 |
+
I = outer(b.x, b.x)
|
| 71 |
+
Inertia_tuple = (I, P)
|
| 72 |
+
B = RigidBody('B', P, b, M, Inertia_tuple)
|
| 73 |
+
P.set_vel(N, v * b.x)
|
| 74 |
+
assert B.angular_momentum(P, N) == omega * b.x
|
| 75 |
+
O = Point('O')
|
| 76 |
+
O.set_vel(N, v * b.x)
|
| 77 |
+
P.set_pos(O, r * b.y)
|
| 78 |
+
assert B.angular_momentum(O, N) == omega * b.x - M*v*r*b.z
|
| 79 |
+
B.potential_energy = M * g * h
|
| 80 |
+
assert B.potential_energy == M * g * h
|
| 81 |
+
assert expand(2 * B.kinetic_energy(N)) == omega**2 + M * v**2
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_rigidbody3():
|
| 85 |
+
q1, q2, q3, q4 = dynamicsymbols('q1:5')
|
| 86 |
+
p1, p2, p3 = symbols('p1:4')
|
| 87 |
+
m = symbols('m')
|
| 88 |
+
|
| 89 |
+
A = ReferenceFrame('A')
|
| 90 |
+
B = A.orientnew('B', 'axis', [q1, A.x])
|
| 91 |
+
O = Point('O')
|
| 92 |
+
O.set_vel(A, q2*A.x + q3*A.y + q4*A.z)
|
| 93 |
+
P = O.locatenew('P', p1*B.x + p2*B.y + p3*B.z)
|
| 94 |
+
P.v2pt_theory(O, A, B)
|
| 95 |
+
I = outer(B.x, B.x)
|
| 96 |
+
|
| 97 |
+
rb1 = RigidBody('rb1', P, B, m, (I, P))
|
| 98 |
+
# I_S/O = I_S/S* + I_S*/O
|
| 99 |
+
rb2 = RigidBody('rb2', P, B, m,
|
| 100 |
+
(I + inertia_of_point_mass(m, P.pos_from(O), B), O))
|
| 101 |
+
|
| 102 |
+
assert rb1.central_inertia == rb2.central_inertia
|
| 103 |
+
assert rb1.angular_momentum(O, A) == rb2.angular_momentum(O, A)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_pendulum_angular_momentum():
|
| 107 |
+
"""Consider a pendulum of length OA = 2a, of mass m as a rigid body of
|
| 108 |
+
center of mass G (OG = a) which turn around (O,z). The angle between the
|
| 109 |
+
reference frame R and the rod is q. The inertia of the body is I =
|
| 110 |
+
(G,0,ma^2/3,ma^2/3). """
|
| 111 |
+
|
| 112 |
+
m, a = symbols('m, a')
|
| 113 |
+
q = dynamicsymbols('q')
|
| 114 |
+
|
| 115 |
+
R = ReferenceFrame('R')
|
| 116 |
+
R1 = R.orientnew('R1', 'Axis', [q, R.z])
|
| 117 |
+
R1.set_ang_vel(R, q.diff() * R.z)
|
| 118 |
+
|
| 119 |
+
I = inertia(R1, 0, m * a**2 / 3, m * a**2 / 3)
|
| 120 |
+
|
| 121 |
+
O = Point('O')
|
| 122 |
+
|
| 123 |
+
A = O.locatenew('A', 2*a * R1.x)
|
| 124 |
+
G = O.locatenew('G', a * R1.x)
|
| 125 |
+
|
| 126 |
+
S = RigidBody('S', G, R1, m, (I, G))
|
| 127 |
+
|
| 128 |
+
O.set_vel(R, 0)
|
| 129 |
+
A.v2pt_theory(O, R, R1)
|
| 130 |
+
G.v2pt_theory(O, R, R1)
|
| 131 |
+
|
| 132 |
+
assert (4 * m * a**2 / 3 * q.diff() * R.z -
|
| 133 |
+
S.angular_momentum(O, R).express(R)) == 0
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_rigidbody_inertia():
|
| 137 |
+
N = ReferenceFrame('N')
|
| 138 |
+
m, Ix, Iy, Iz, a, b = symbols('m, I_x, I_y, I_z, a, b')
|
| 139 |
+
Io = inertia(N, Ix, Iy, Iz)
|
| 140 |
+
o = Point('o')
|
| 141 |
+
p = o.locatenew('p', a * N.x + b * N.y)
|
| 142 |
+
R = RigidBody('R', o, N, m, (Io, p))
|
| 143 |
+
I_check = inertia(N, Ix - b ** 2 * m, Iy - a ** 2 * m,
|
| 144 |
+
Iz - m * (a ** 2 + b ** 2), m * a * b)
|
| 145 |
+
assert isinstance(R.inertia, Inertia)
|
| 146 |
+
assert R.inertia == (Io, p)
|
| 147 |
+
assert R.central_inertia == I_check
|
| 148 |
+
R.central_inertia = Io
|
| 149 |
+
assert R.inertia == (Io, o)
|
| 150 |
+
assert R.central_inertia == Io
|
| 151 |
+
R.inertia = (Io, p)
|
| 152 |
+
assert R.inertia == (Io, p)
|
| 153 |
+
assert R.central_inertia == I_check
|
| 154 |
+
# parse Inertia object
|
| 155 |
+
R.inertia = Inertia(Io, o)
|
| 156 |
+
assert R.inertia == (Io, o)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def test_parallel_axis():
|
| 160 |
+
N = ReferenceFrame('N')
|
| 161 |
+
m, Ix, Iy, Iz, a, b = symbols('m, I_x, I_y, I_z, a, b')
|
| 162 |
+
Io = inertia(N, Ix, Iy, Iz)
|
| 163 |
+
o = Point('o')
|
| 164 |
+
p = o.locatenew('p', a * N.x + b * N.y)
|
| 165 |
+
R = RigidBody('R', o, N, m, (Io, o))
|
| 166 |
+
Ip = R.parallel_axis(p)
|
| 167 |
+
Ip_expected = inertia(N, Ix + m * b**2, Iy + m * a**2,
|
| 168 |
+
Iz + m * (a**2 + b**2), ixy=-m * a * b)
|
| 169 |
+
assert Ip == Ip_expected
|
| 170 |
+
# Reference frame from which the parallel axis is viewed should not matter
|
| 171 |
+
A = ReferenceFrame('A')
|
| 172 |
+
A.orient_axis(N, N.z, 1)
|
| 173 |
+
assert simplify(
|
| 174 |
+
(R.parallel_axis(p, A) - Ip_expected).to_matrix(A)) == zeros(3, 3)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def test_deprecated_set_potential_energy():
|
| 178 |
+
m, g, h = symbols('m g h')
|
| 179 |
+
A = ReferenceFrame('A')
|
| 180 |
+
P = Point('P')
|
| 181 |
+
I = Dyadic(0)
|
| 182 |
+
B = RigidBody('B', P, A, m, (I, P))
|
| 183 |
+
with warns_deprecated_sympy():
|
| 184 |
+
B.set_potential_energy(m*g*h)
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/m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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Geometry objects for use by wrapping pathways."""
|
| 2 |
+
|
| 3 |
+
from abc import ABC, abstractmethod
|
| 4 |
+
|
| 5 |
+
from sympy import Integer, acos, pi, sqrt, sympify, tan
|
| 6 |
+
from sympy.core.relational import Eq
|
| 7 |
+
from sympy.functions.elementary.trigonometric import atan2
|
| 8 |
+
from sympy.polys.polytools import cancel
|
| 9 |
+
from sympy.physics.vector import Vector, dot
|
| 10 |
+
from sympy.simplify.simplify import trigsimp
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
__all__ = [
|
| 14 |
+
'WrappingGeometryBase',
|
| 15 |
+
'WrappingCylinder',
|
| 16 |
+
'WrappingSphere',
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class WrappingGeometryBase(ABC):
|
| 21 |
+
"""Abstract base class for all geometry classes to inherit from.
|
| 22 |
+
|
| 23 |
+
Notes
|
| 24 |
+
=====
|
| 25 |
+
|
| 26 |
+
Instances of this class cannot be directly instantiated by users. However,
|
| 27 |
+
it can be used to created custom geometry types through subclassing.
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
@property
|
| 32 |
+
@abstractmethod
|
| 33 |
+
def point(cls):
|
| 34 |
+
"""The point with which the geometry is associated."""
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
@abstractmethod
|
| 38 |
+
def point_on_surface(self, point):
|
| 39 |
+
"""Returns ``True`` if a point is on the geometry's surface.
|
| 40 |
+
|
| 41 |
+
Parameters
|
| 42 |
+
==========
|
| 43 |
+
point : Point
|
| 44 |
+
The point for which it's to be ascertained if it's on the
|
| 45 |
+
geometry's surface or not.
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
@abstractmethod
|
| 51 |
+
def geodesic_length(self, point_1, point_2):
|
| 52 |
+
"""Returns the shortest distance between two points on a geometry's
|
| 53 |
+
surface.
|
| 54 |
+
|
| 55 |
+
Parameters
|
| 56 |
+
==========
|
| 57 |
+
|
| 58 |
+
point_1 : Point
|
| 59 |
+
The point from which the geodesic length should be calculated.
|
| 60 |
+
point_2 : Point
|
| 61 |
+
The point to which the geodesic length should be calculated.
|
| 62 |
+
|
| 63 |
+
"""
|
| 64 |
+
pass
|
| 65 |
+
|
| 66 |
+
@abstractmethod
|
| 67 |
+
def geodesic_end_vectors(self, point_1, point_2):
|
| 68 |
+
"""The vectors parallel to the geodesic at the two end points.
|
| 69 |
+
|
| 70 |
+
Parameters
|
| 71 |
+
==========
|
| 72 |
+
|
| 73 |
+
point_1 : Point
|
| 74 |
+
The point from which the geodesic originates.
|
| 75 |
+
point_2 : Point
|
| 76 |
+
The point at which the geodesic terminates.
|
| 77 |
+
|
| 78 |
+
"""
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
def __repr__(self):
|
| 82 |
+
"""Default representation of a geometry object."""
|
| 83 |
+
return f'{self.__class__.__name__}()'
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class WrappingSphere(WrappingGeometryBase):
|
| 87 |
+
"""A solid spherical object.
|
| 88 |
+
|
| 89 |
+
Explanation
|
| 90 |
+
===========
|
| 91 |
+
|
| 92 |
+
A wrapping geometry that allows for circular arcs to be defined between
|
| 93 |
+
pairs of points. These paths are always geodetic (the shortest possible).
|
| 94 |
+
|
| 95 |
+
Examples
|
| 96 |
+
========
|
| 97 |
+
|
| 98 |
+
To create a ``WrappingSphere`` instance, a ``Symbol`` denoting its radius
|
| 99 |
+
and ``Point`` at which its center will be located are needed:
|
| 100 |
+
|
| 101 |
+
>>> from sympy import symbols
|
| 102 |
+
>>> from sympy.physics.mechanics import Point, WrappingSphere
|
| 103 |
+
>>> r = symbols('r')
|
| 104 |
+
>>> pO = Point('pO')
|
| 105 |
+
|
| 106 |
+
A sphere with radius ``r`` centered on ``pO`` can be instantiated with:
|
| 107 |
+
|
| 108 |
+
>>> WrappingSphere(r, pO)
|
| 109 |
+
WrappingSphere(radius=r, point=pO)
|
| 110 |
+
|
| 111 |
+
Parameters
|
| 112 |
+
==========
|
| 113 |
+
|
| 114 |
+
radius : Symbol
|
| 115 |
+
Radius of the sphere. This symbol must represent a value that is
|
| 116 |
+
positive and constant, i.e. it cannot be a dynamic symbol, nor can it
|
| 117 |
+
be an expression.
|
| 118 |
+
point : Point
|
| 119 |
+
A point at which the sphere is centered.
|
| 120 |
+
|
| 121 |
+
See Also
|
| 122 |
+
========
|
| 123 |
+
|
| 124 |
+
WrappingCylinder: Cylindrical geometry where the wrapping direction can be
|
| 125 |
+
defined.
|
| 126 |
+
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
def __init__(self, radius, point):
|
| 130 |
+
"""Initializer for ``WrappingSphere``.
|
| 131 |
+
|
| 132 |
+
Parameters
|
| 133 |
+
==========
|
| 134 |
+
|
| 135 |
+
radius : Symbol
|
| 136 |
+
The radius of the sphere.
|
| 137 |
+
point : Point
|
| 138 |
+
A point on which the sphere is centered.
|
| 139 |
+
|
| 140 |
+
"""
|
| 141 |
+
self.radius = radius
|
| 142 |
+
self.point = point
|
| 143 |
+
|
| 144 |
+
@property
|
| 145 |
+
def radius(self):
|
| 146 |
+
"""Radius of the sphere."""
|
| 147 |
+
return self._radius
|
| 148 |
+
|
| 149 |
+
@radius.setter
|
| 150 |
+
def radius(self, radius):
|
| 151 |
+
self._radius = radius
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def point(self):
|
| 155 |
+
"""A point on which the sphere is centered."""
|
| 156 |
+
return self._point
|
| 157 |
+
|
| 158 |
+
@point.setter
|
| 159 |
+
def point(self, point):
|
| 160 |
+
self._point = point
|
| 161 |
+
|
| 162 |
+
def point_on_surface(self, point):
|
| 163 |
+
"""Returns ``True`` if a point is on the sphere's surface.
|
| 164 |
+
|
| 165 |
+
Parameters
|
| 166 |
+
==========
|
| 167 |
+
|
| 168 |
+
point : Point
|
| 169 |
+
The point for which it's to be ascertained if it's on the sphere's
|
| 170 |
+
surface or not. This point's position relative to the sphere's
|
| 171 |
+
center must be a simple expression involving the radius of the
|
| 172 |
+
sphere, otherwise this check will likely not work.
|
| 173 |
+
|
| 174 |
+
"""
|
| 175 |
+
point_vector = point.pos_from(self.point)
|
| 176 |
+
if isinstance(point_vector, Vector):
|
| 177 |
+
point_radius_squared = dot(point_vector, point_vector)
|
| 178 |
+
else:
|
| 179 |
+
point_radius_squared = point_vector**2
|
| 180 |
+
return Eq(point_radius_squared, self.radius**2) == True
|
| 181 |
+
|
| 182 |
+
def geodesic_length(self, point_1, point_2):
|
| 183 |
+
r"""Returns the shortest distance between two points on the sphere's
|
| 184 |
+
surface.
|
| 185 |
+
|
| 186 |
+
Explanation
|
| 187 |
+
===========
|
| 188 |
+
|
| 189 |
+
The geodesic length, i.e. the shortest arc along the surface of a
|
| 190 |
+
sphere, connecting two points can be calculated using the formula:
|
| 191 |
+
|
| 192 |
+
.. math::
|
| 193 |
+
|
| 194 |
+
l = \arccos\left(\mathbf{v}_1 \cdot \mathbf{v}_2\right)
|
| 195 |
+
|
| 196 |
+
where $\mathbf{v}_1$ and $\mathbf{v}_2$ are the unit vectors from the
|
| 197 |
+
sphere's center to the first and second points on the sphere's surface
|
| 198 |
+
respectively. Note that the actual path that the geodesic will take is
|
| 199 |
+
undefined when the two points are directly opposite one another.
|
| 200 |
+
|
| 201 |
+
Examples
|
| 202 |
+
========
|
| 203 |
+
|
| 204 |
+
A geodesic length can only be calculated between two points on the
|
| 205 |
+
sphere's surface. Firstly, a ``WrappingSphere`` instance must be
|
| 206 |
+
created along with two points that will lie on its surface:
|
| 207 |
+
|
| 208 |
+
>>> from sympy import symbols
|
| 209 |
+
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
|
| 210 |
+
... WrappingSphere)
|
| 211 |
+
>>> N = ReferenceFrame('N')
|
| 212 |
+
>>> r = symbols('r')
|
| 213 |
+
>>> pO = Point('pO')
|
| 214 |
+
>>> pO.set_vel(N, 0)
|
| 215 |
+
>>> sphere = WrappingSphere(r, pO)
|
| 216 |
+
>>> p1 = Point('p1')
|
| 217 |
+
>>> p2 = Point('p2')
|
| 218 |
+
|
| 219 |
+
Let's assume that ``p1`` lies at a distance of ``r`` in the ``N.x``
|
| 220 |
+
direction from ``pO`` and that ``p2`` is located on the sphere's
|
| 221 |
+
surface in the ``N.y + N.z`` direction from ``pO``. These positions can
|
| 222 |
+
be set with:
|
| 223 |
+
|
| 224 |
+
>>> p1.set_pos(pO, r*N.x)
|
| 225 |
+
>>> p1.pos_from(pO)
|
| 226 |
+
r*N.x
|
| 227 |
+
>>> p2.set_pos(pO, r*(N.y + N.z).normalize())
|
| 228 |
+
>>> p2.pos_from(pO)
|
| 229 |
+
sqrt(2)*r/2*N.y + sqrt(2)*r/2*N.z
|
| 230 |
+
|
| 231 |
+
The geodesic length, which is in this case is a quarter of the sphere's
|
| 232 |
+
circumference, can be calculated using the ``geodesic_length`` method:
|
| 233 |
+
|
| 234 |
+
>>> sphere.geodesic_length(p1, p2)
|
| 235 |
+
pi*r/2
|
| 236 |
+
|
| 237 |
+
If the ``geodesic_length`` method is passed an argument, the ``Point``
|
| 238 |
+
that doesn't lie on the sphere's surface then a ``ValueError`` is
|
| 239 |
+
raised because it's not possible to calculate a value in this case.
|
| 240 |
+
|
| 241 |
+
Parameters
|
| 242 |
+
==========
|
| 243 |
+
|
| 244 |
+
point_1 : Point
|
| 245 |
+
Point from which the geodesic length should be calculated.
|
| 246 |
+
point_2 : Point
|
| 247 |
+
Point to which the geodesic length should be calculated.
|
| 248 |
+
|
| 249 |
+
"""
|
| 250 |
+
for point in (point_1, point_2):
|
| 251 |
+
if not self.point_on_surface(point):
|
| 252 |
+
msg = (
|
| 253 |
+
f'Geodesic length cannot be calculated as point {point} '
|
| 254 |
+
f'with radius {point.pos_from(self.point).magnitude()} '
|
| 255 |
+
f'from the sphere\'s center {self.point} does not lie on '
|
| 256 |
+
f'the surface of {self} with radius {self.radius}.'
|
| 257 |
+
)
|
| 258 |
+
raise ValueError(msg)
|
| 259 |
+
point_1_vector = point_1.pos_from(self.point).normalize()
|
| 260 |
+
point_2_vector = point_2.pos_from(self.point).normalize()
|
| 261 |
+
central_angle = acos(point_2_vector.dot(point_1_vector))
|
| 262 |
+
geodesic_length = self.radius*central_angle
|
| 263 |
+
return geodesic_length
|
| 264 |
+
|
| 265 |
+
def geodesic_end_vectors(self, point_1, point_2):
|
| 266 |
+
"""The vectors parallel to the geodesic at the two end points.
|
| 267 |
+
|
| 268 |
+
Parameters
|
| 269 |
+
==========
|
| 270 |
+
|
| 271 |
+
point_1 : Point
|
| 272 |
+
The point from which the geodesic originates.
|
| 273 |
+
point_2 : Point
|
| 274 |
+
The point at which the geodesic terminates.
|
| 275 |
+
|
| 276 |
+
"""
|
| 277 |
+
pA, pB = point_1, point_2
|
| 278 |
+
pO = self.point
|
| 279 |
+
pA_vec = pA.pos_from(pO)
|
| 280 |
+
pB_vec = pB.pos_from(pO)
|
| 281 |
+
|
| 282 |
+
if pA_vec.cross(pB_vec) == 0:
|
| 283 |
+
msg = (
|
| 284 |
+
f'Can\'t compute geodesic end vectors for the pair of points '
|
| 285 |
+
f'{pA} and {pB} on a sphere {self} as they are diametrically '
|
| 286 |
+
f'opposed, thus the geodesic is not defined.'
|
| 287 |
+
)
|
| 288 |
+
raise ValueError(msg)
|
| 289 |
+
|
| 290 |
+
return (
|
| 291 |
+
pA_vec.cross(pB.pos_from(pA)).cross(pA_vec).normalize(),
|
| 292 |
+
pB_vec.cross(pA.pos_from(pB)).cross(pB_vec).normalize(),
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
def __repr__(self):
|
| 296 |
+
"""Representation of a ``WrappingSphere``."""
|
| 297 |
+
return (
|
| 298 |
+
f'{self.__class__.__name__}(radius={self.radius}, '
|
| 299 |
+
f'point={self.point})'
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
class WrappingCylinder(WrappingGeometryBase):
|
| 304 |
+
"""A solid (infinite) cylindrical object.
|
| 305 |
+
|
| 306 |
+
Explanation
|
| 307 |
+
===========
|
| 308 |
+
|
| 309 |
+
A wrapping geometry that allows for circular arcs to be defined between
|
| 310 |
+
pairs of points. These paths are always geodetic (the shortest possible) in
|
| 311 |
+
the sense that they will be a straight line on the unwrapped cylinder's
|
| 312 |
+
surface. However, it is also possible for a direction to be specified, i.e.
|
| 313 |
+
paths can be influenced such that they either wrap along the shortest side
|
| 314 |
+
or the longest side of the cylinder. To define these directions, rotations
|
| 315 |
+
are in the positive direction following the right-hand rule.
|
| 316 |
+
|
| 317 |
+
Examples
|
| 318 |
+
========
|
| 319 |
+
|
| 320 |
+
To create a ``WrappingCylinder`` instance, a ``Symbol`` denoting its
|
| 321 |
+
radius, a ``Vector`` defining its axis, and a ``Point`` through which its
|
| 322 |
+
axis passes are needed:
|
| 323 |
+
|
| 324 |
+
>>> from sympy import symbols
|
| 325 |
+
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
|
| 326 |
+
... WrappingCylinder)
|
| 327 |
+
>>> N = ReferenceFrame('N')
|
| 328 |
+
>>> r = symbols('r')
|
| 329 |
+
>>> pO = Point('pO')
|
| 330 |
+
>>> ax = N.x
|
| 331 |
+
|
| 332 |
+
A cylinder with radius ``r``, and axis parallel to ``N.x`` passing through
|
| 333 |
+
``pO`` can be instantiated with:
|
| 334 |
+
|
| 335 |
+
>>> WrappingCylinder(r, pO, ax)
|
| 336 |
+
WrappingCylinder(radius=r, point=pO, axis=N.x)
|
| 337 |
+
|
| 338 |
+
Parameters
|
| 339 |
+
==========
|
| 340 |
+
|
| 341 |
+
radius : Symbol
|
| 342 |
+
The radius of the cylinder.
|
| 343 |
+
point : Point
|
| 344 |
+
A point through which the cylinder's axis passes.
|
| 345 |
+
axis : Vector
|
| 346 |
+
The axis along which the cylinder is aligned.
|
| 347 |
+
|
| 348 |
+
See Also
|
| 349 |
+
========
|
| 350 |
+
|
| 351 |
+
WrappingSphere: Spherical geometry where the wrapping direction is always
|
| 352 |
+
geodetic.
|
| 353 |
+
|
| 354 |
+
"""
|
| 355 |
+
|
| 356 |
+
def __init__(self, radius, point, axis):
|
| 357 |
+
"""Initializer for ``WrappingCylinder``.
|
| 358 |
+
|
| 359 |
+
Parameters
|
| 360 |
+
==========
|
| 361 |
+
|
| 362 |
+
radius : Symbol
|
| 363 |
+
The radius of the cylinder. This symbol must represent a value that
|
| 364 |
+
is positive and constant, i.e. it cannot be a dynamic symbol.
|
| 365 |
+
point : Point
|
| 366 |
+
A point through which the cylinder's axis passes.
|
| 367 |
+
axis : Vector
|
| 368 |
+
The axis along which the cylinder is aligned.
|
| 369 |
+
|
| 370 |
+
"""
|
| 371 |
+
self.radius = radius
|
| 372 |
+
self.point = point
|
| 373 |
+
self.axis = axis
|
| 374 |
+
|
| 375 |
+
@property
|
| 376 |
+
def radius(self):
|
| 377 |
+
"""Radius of the cylinder."""
|
| 378 |
+
return self._radius
|
| 379 |
+
|
| 380 |
+
@radius.setter
|
| 381 |
+
def radius(self, radius):
|
| 382 |
+
self._radius = radius
|
| 383 |
+
|
| 384 |
+
@property
|
| 385 |
+
def point(self):
|
| 386 |
+
"""A point through which the cylinder's axis passes."""
|
| 387 |
+
return self._point
|
| 388 |
+
|
| 389 |
+
@point.setter
|
| 390 |
+
def point(self, point):
|
| 391 |
+
self._point = point
|
| 392 |
+
|
| 393 |
+
@property
|
| 394 |
+
def axis(self):
|
| 395 |
+
"""Axis along which the cylinder is aligned."""
|
| 396 |
+
return self._axis
|
| 397 |
+
|
| 398 |
+
@axis.setter
|
| 399 |
+
def axis(self, axis):
|
| 400 |
+
self._axis = axis.normalize()
|
| 401 |
+
|
| 402 |
+
def point_on_surface(self, point):
|
| 403 |
+
"""Returns ``True`` if a point is on the cylinder's surface.
|
| 404 |
+
|
| 405 |
+
Parameters
|
| 406 |
+
==========
|
| 407 |
+
|
| 408 |
+
point : Point
|
| 409 |
+
The point for which it's to be ascertained if it's on the
|
| 410 |
+
cylinder's surface or not. This point's position relative to the
|
| 411 |
+
cylinder's axis must be a simple expression involving the radius of
|
| 412 |
+
the sphere, otherwise this check will likely not work.
|
| 413 |
+
|
| 414 |
+
"""
|
| 415 |
+
relative_position = point.pos_from(self.point)
|
| 416 |
+
parallel = relative_position.dot(self.axis) * self.axis
|
| 417 |
+
point_vector = relative_position - parallel
|
| 418 |
+
if isinstance(point_vector, Vector):
|
| 419 |
+
point_radius_squared = dot(point_vector, point_vector)
|
| 420 |
+
else:
|
| 421 |
+
point_radius_squared = point_vector**2
|
| 422 |
+
return Eq(trigsimp(point_radius_squared), self.radius**2) == True
|
| 423 |
+
|
| 424 |
+
def geodesic_length(self, point_1, point_2):
|
| 425 |
+
"""The shortest distance between two points on a geometry's surface.
|
| 426 |
+
|
| 427 |
+
Explanation
|
| 428 |
+
===========
|
| 429 |
+
|
| 430 |
+
The geodesic length, i.e. the shortest arc along the surface of a
|
| 431 |
+
cylinder, connecting two points. It can be calculated using Pythagoras'
|
| 432 |
+
theorem. The first short side is the distance between the two points on
|
| 433 |
+
the cylinder's surface parallel to the cylinder's axis. The second
|
| 434 |
+
short side is the arc of a circle between the two points of the
|
| 435 |
+
cylinder's surface perpendicular to the cylinder's axis. The resulting
|
| 436 |
+
hypotenuse is the geodesic length.
|
| 437 |
+
|
| 438 |
+
Examples
|
| 439 |
+
========
|
| 440 |
+
|
| 441 |
+
A geodesic length can only be calculated between two points on the
|
| 442 |
+
cylinder's surface. Firstly, a ``WrappingCylinder`` instance must be
|
| 443 |
+
created along with two points that will lie on its surface:
|
| 444 |
+
|
| 445 |
+
>>> from sympy import symbols, cos, sin
|
| 446 |
+
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
|
| 447 |
+
... WrappingCylinder, dynamicsymbols)
|
| 448 |
+
>>> N = ReferenceFrame('N')
|
| 449 |
+
>>> r = symbols('r')
|
| 450 |
+
>>> pO = Point('pO')
|
| 451 |
+
>>> pO.set_vel(N, 0)
|
| 452 |
+
>>> cylinder = WrappingCylinder(r, pO, N.x)
|
| 453 |
+
>>> p1 = Point('p1')
|
| 454 |
+
>>> p2 = Point('p2')
|
| 455 |
+
|
| 456 |
+
Let's assume that ``p1`` is located at ``N.x + r*N.y`` relative to
|
| 457 |
+
``pO`` and that ``p2`` is located at ``r*(cos(q)*N.y + sin(q)*N.z)``
|
| 458 |
+
relative to ``pO``, where ``q(t)`` is a generalized coordinate
|
| 459 |
+
specifying the angle rotated around the ``N.x`` axis according to the
|
| 460 |
+
right-hand rule where ``N.y`` is zero. These positions can be set with:
|
| 461 |
+
|
| 462 |
+
>>> q = dynamicsymbols('q')
|
| 463 |
+
>>> p1.set_pos(pO, N.x + r*N.y)
|
| 464 |
+
>>> p1.pos_from(pO)
|
| 465 |
+
N.x + r*N.y
|
| 466 |
+
>>> p2.set_pos(pO, r*(cos(q)*N.y + sin(q)*N.z).normalize())
|
| 467 |
+
>>> p2.pos_from(pO).simplify()
|
| 468 |
+
r*cos(q(t))*N.y + r*sin(q(t))*N.z
|
| 469 |
+
|
| 470 |
+
The geodesic length, which is in this case a is the hypotenuse of a
|
| 471 |
+
right triangle where the other two side lengths are ``1`` (parallel to
|
| 472 |
+
the cylinder's axis) and ``r*q(t)`` (parallel to the cylinder's cross
|
| 473 |
+
section), can be calculated using the ``geodesic_length`` method:
|
| 474 |
+
|
| 475 |
+
>>> cylinder.geodesic_length(p1, p2).simplify()
|
| 476 |
+
sqrt(r**2*q(t)**2 + 1)
|
| 477 |
+
|
| 478 |
+
If the ``geodesic_length`` method is passed an argument ``Point`` that
|
| 479 |
+
doesn't lie on the sphere's surface then a ``ValueError`` is raised
|
| 480 |
+
because it's not possible to calculate a value in this case.
|
| 481 |
+
|
| 482 |
+
Parameters
|
| 483 |
+
==========
|
| 484 |
+
|
| 485 |
+
point_1 : Point
|
| 486 |
+
Point from which the geodesic length should be calculated.
|
| 487 |
+
point_2 : Point
|
| 488 |
+
Point to which the geodesic length should be calculated.
|
| 489 |
+
|
| 490 |
+
"""
|
| 491 |
+
for point in (point_1, point_2):
|
| 492 |
+
if not self.point_on_surface(point):
|
| 493 |
+
msg = (
|
| 494 |
+
f'Geodesic length cannot be calculated as point {point} '
|
| 495 |
+
f'with radius {point.pos_from(self.point).magnitude()} '
|
| 496 |
+
f'from the cylinder\'s center {self.point} does not lie on '
|
| 497 |
+
f'the surface of {self} with radius {self.radius} and axis '
|
| 498 |
+
f'{self.axis}.'
|
| 499 |
+
)
|
| 500 |
+
raise ValueError(msg)
|
| 501 |
+
|
| 502 |
+
relative_position = point_2.pos_from(point_1)
|
| 503 |
+
parallel_length = relative_position.dot(self.axis)
|
| 504 |
+
|
| 505 |
+
point_1_relative_position = point_1.pos_from(self.point)
|
| 506 |
+
point_1_perpendicular_vector = (
|
| 507 |
+
point_1_relative_position
|
| 508 |
+
- point_1_relative_position.dot(self.axis)*self.axis
|
| 509 |
+
).normalize()
|
| 510 |
+
|
| 511 |
+
point_2_relative_position = point_2.pos_from(self.point)
|
| 512 |
+
point_2_perpendicular_vector = (
|
| 513 |
+
point_2_relative_position
|
| 514 |
+
- point_2_relative_position.dot(self.axis)*self.axis
|
| 515 |
+
).normalize()
|
| 516 |
+
|
| 517 |
+
central_angle = _directional_atan(
|
| 518 |
+
cancel(point_1_perpendicular_vector
|
| 519 |
+
.cross(point_2_perpendicular_vector)
|
| 520 |
+
.dot(self.axis)),
|
| 521 |
+
cancel(point_1_perpendicular_vector.dot(point_2_perpendicular_vector)),
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
planar_arc_length = self.radius*central_angle
|
| 525 |
+
geodesic_length = sqrt(parallel_length**2 + planar_arc_length**2)
|
| 526 |
+
return geodesic_length
|
| 527 |
+
|
| 528 |
+
def geodesic_end_vectors(self, point_1, point_2):
|
| 529 |
+
"""The vectors parallel to the geodesic at the two end points.
|
| 530 |
+
|
| 531 |
+
Parameters
|
| 532 |
+
==========
|
| 533 |
+
|
| 534 |
+
point_1 : Point
|
| 535 |
+
The point from which the geodesic originates.
|
| 536 |
+
point_2 : Point
|
| 537 |
+
The point at which the geodesic terminates.
|
| 538 |
+
|
| 539 |
+
"""
|
| 540 |
+
point_1_from_origin_point = point_1.pos_from(self.point)
|
| 541 |
+
point_2_from_origin_point = point_2.pos_from(self.point)
|
| 542 |
+
|
| 543 |
+
if point_1_from_origin_point == point_2_from_origin_point:
|
| 544 |
+
msg = (
|
| 545 |
+
f'Cannot compute geodesic end vectors for coincident points '
|
| 546 |
+
f'{point_1} and {point_2} as no geodesic exists.'
|
| 547 |
+
)
|
| 548 |
+
raise ValueError(msg)
|
| 549 |
+
|
| 550 |
+
point_1_parallel = point_1_from_origin_point.dot(self.axis) * self.axis
|
| 551 |
+
point_2_parallel = point_2_from_origin_point.dot(self.axis) * self.axis
|
| 552 |
+
point_1_normal = (point_1_from_origin_point - point_1_parallel)
|
| 553 |
+
point_2_normal = (point_2_from_origin_point - point_2_parallel)
|
| 554 |
+
|
| 555 |
+
if point_1_normal == point_2_normal:
|
| 556 |
+
point_1_perpendicular = Vector(0)
|
| 557 |
+
point_2_perpendicular = Vector(0)
|
| 558 |
+
else:
|
| 559 |
+
point_1_perpendicular = self.axis.cross(point_1_normal).normalize()
|
| 560 |
+
point_2_perpendicular = -self.axis.cross(point_2_normal).normalize()
|
| 561 |
+
|
| 562 |
+
geodesic_length = self.geodesic_length(point_1, point_2)
|
| 563 |
+
relative_position = point_2.pos_from(point_1)
|
| 564 |
+
parallel_length = relative_position.dot(self.axis)
|
| 565 |
+
planar_arc_length = sqrt(geodesic_length**2 - parallel_length**2)
|
| 566 |
+
|
| 567 |
+
point_1_vector = (
|
| 568 |
+
planar_arc_length * point_1_perpendicular
|
| 569 |
+
+ parallel_length * self.axis
|
| 570 |
+
).normalize()
|
| 571 |
+
point_2_vector = (
|
| 572 |
+
planar_arc_length * point_2_perpendicular
|
| 573 |
+
- parallel_length * self.axis
|
| 574 |
+
).normalize()
|
| 575 |
+
|
| 576 |
+
return (point_1_vector, point_2_vector)
|
| 577 |
+
|
| 578 |
+
def __repr__(self):
|
| 579 |
+
"""Representation of a ``WrappingCylinder``."""
|
| 580 |
+
return (
|
| 581 |
+
f'{self.__class__.__name__}(radius={self.radius}, '
|
| 582 |
+
f'point={self.point}, axis={self.axis})'
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
def _directional_atan(numerator, denominator):
|
| 587 |
+
"""Compute atan in a directional sense as required for geodesics.
|
| 588 |
+
|
| 589 |
+
Explanation
|
| 590 |
+
===========
|
| 591 |
+
|
| 592 |
+
To be able to control the direction of the geodesic length along the
|
| 593 |
+
surface of a cylinder a dedicated arctangent function is needed that
|
| 594 |
+
properly handles the directionality of different case. This function
|
| 595 |
+
ensures that the central angle is always positive but shifting the case
|
| 596 |
+
where ``atan2`` would return a negative angle to be centered around
|
| 597 |
+
``2*pi``.
|
| 598 |
+
|
| 599 |
+
Notes
|
| 600 |
+
=====
|
| 601 |
+
|
| 602 |
+
This function only handles very specific cases, i.e. the ones that are
|
| 603 |
+
expected to be encountered when calculating symbolic geodesics on uniformly
|
| 604 |
+
curved surfaces. As such, ``NotImplemented`` errors can be raised in many
|
| 605 |
+
cases. This function is named with a leader underscore to indicate that it
|
| 606 |
+
only aims to provide very specific functionality within the private scope
|
| 607 |
+
of this module.
|
| 608 |
+
|
| 609 |
+
"""
|
| 610 |
+
|
| 611 |
+
if numerator.is_number and denominator.is_number:
|
| 612 |
+
angle = atan2(numerator, denominator)
|
| 613 |
+
if angle < 0:
|
| 614 |
+
angle += 2 * pi
|
| 615 |
+
elif numerator.is_number:
|
| 616 |
+
msg = (
|
| 617 |
+
f'Cannot compute a directional atan when the numerator {numerator} '
|
| 618 |
+
f'is numeric and the denominator {denominator} is symbolic.'
|
| 619 |
+
)
|
| 620 |
+
raise NotImplementedError(msg)
|
| 621 |
+
elif denominator.is_number:
|
| 622 |
+
msg = (
|
| 623 |
+
f'Cannot compute a directional atan when the numerator {numerator} '
|
| 624 |
+
f'is symbolic and the denominator {denominator} is numeric.'
|
| 625 |
+
)
|
| 626 |
+
raise NotImplementedError(msg)
|
| 627 |
+
else:
|
| 628 |
+
ratio = sympify(trigsimp(numerator / denominator))
|
| 629 |
+
if isinstance(ratio, tan):
|
| 630 |
+
angle = ratio.args[0]
|
| 631 |
+
elif (
|
| 632 |
+
ratio.is_Mul
|
| 633 |
+
and ratio.args[0] == Integer(-1)
|
| 634 |
+
and isinstance(ratio.args[1], tan)
|
| 635 |
+
):
|
| 636 |
+
angle = 2 * pi - ratio.args[1].args[0]
|
| 637 |
+
else:
|
| 638 |
+
msg = f'Cannot compute a directional atan for the value {ratio}.'
|
| 639 |
+
raise NotImplementedError(msg)
|
| 640 |
+
|
| 641 |
+
return angle
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (185 Bytes). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/sympy/physics/optics/tests/__pycache__/test_polarization.cpython-310.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_backward.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_backward_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
}
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_chunk_cat_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _chunk_cat(at::TensorList tensors, int64_t dim, int64_t num_chunks);
|
| 21 |
+
TORCH_API at::Tensor & _chunk_cat_out(at::Tensor & out, at::TensorList tensors, int64_t dim, int64_t num_chunks);
|
| 22 |
+
TORCH_API at::Tensor & _chunk_cat_outf(at::TensorList tensors, int64_t dim, int64_t num_chunks, at::Tensor & out);
|
| 23 |
+
|
| 24 |
+
} // namespace compositeexplicitautograd
|
| 25 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_convolution.h
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_convolution_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_convolution(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) -> Tensor
|
| 26 |
+
inline at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 27 |
+
return at::_ops::_convolution::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32);
|
| 28 |
+
}
|
| 29 |
+
namespace symint {
|
| 30 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 31 |
+
at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 32 |
+
return at::_ops::_convolution::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// aten::_convolution(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) -> Tensor
|
| 37 |
+
inline at::Tensor _convolution_symint(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 38 |
+
return at::_ops::_convolution::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32);
|
| 39 |
+
}
|
| 40 |
+
namespace symint {
|
| 41 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 42 |
+
at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 43 |
+
return at::_ops::_convolution::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
// aten::_convolution.deprecated(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, int[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled) -> Tensor
|
| 48 |
+
inline at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled) {
|
| 49 |
+
return at::_ops::_convolution_deprecated::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled);
|
| 50 |
+
}
|
| 51 |
+
namespace symint {
|
| 52 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 53 |
+
at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled) {
|
| 54 |
+
return at::_ops::_convolution_deprecated::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// aten::_convolution.deprecated(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, int[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled) -> Tensor
|
| 59 |
+
inline at::Tensor _convolution_symint(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled) {
|
| 60 |
+
return at::_ops::_convolution_deprecated::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled);
|
| 61 |
+
}
|
| 62 |
+
namespace symint {
|
| 63 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 64 |
+
at::Tensor _convolution(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled) {
|
| 65 |
+
return at::_ops::_convolution_deprecated::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// aten::_convolution.out(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, *, Tensor(a!) out) -> Tensor(a!)
|
| 70 |
+
inline at::Tensor & _convolution_out(at::Tensor & out, const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 71 |
+
return at::_ops::_convolution_out::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 72 |
+
}
|
| 73 |
+
namespace symint {
|
| 74 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 75 |
+
at::Tensor & _convolution_out(at::Tensor & out, const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 76 |
+
return at::_ops::_convolution_out::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// aten::_convolution.out(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, *, Tensor(a!) out) -> Tensor(a!)
|
| 81 |
+
inline at::Tensor & _convolution_outf(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, at::Tensor & out) {
|
| 82 |
+
return at::_ops::_convolution_out::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 83 |
+
}
|
| 84 |
+
namespace symint {
|
| 85 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 86 |
+
at::Tensor & _convolution_outf(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, at::Tensor & out) {
|
| 87 |
+
return at::_ops::_convolution_out::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), transposed, c10::fromIntArrayRefSlow(output_padding), groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// aten::_convolution.out(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, *, Tensor(a!) out) -> Tensor(a!)
|
| 92 |
+
inline at::Tensor & _convolution_symint_out(at::Tensor & out, const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 93 |
+
return at::_ops::_convolution_out::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 94 |
+
}
|
| 95 |
+
namespace symint {
|
| 96 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 97 |
+
at::Tensor & _convolution_out(at::Tensor & out, const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32) {
|
| 98 |
+
return at::_ops::_convolution_out::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// aten::_convolution.out(Tensor input, Tensor weight, Tensor? bias, SymInt[] stride, SymInt[] padding, SymInt[] dilation, bool transposed, SymInt[] output_padding, SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, *, Tensor(a!) out) -> Tensor(a!)
|
| 103 |
+
inline at::Tensor & _convolution_symint_outf(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, at::Tensor & out) {
|
| 104 |
+
return at::_ops::_convolution_out::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 105 |
+
}
|
| 106 |
+
namespace symint {
|
| 107 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 108 |
+
at::Tensor & _convolution_outf(const at::Tensor & input, const at::Tensor & weight, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, bool transposed, c10::SymIntArrayRef output_padding, c10::SymInt groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, at::Tensor & out) {
|
| 109 |
+
return at::_ops::_convolution_out::call(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32, out);
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
}
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_embedding_bag_dense_backward_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & _embedding_bag_dense_backward_out(at::Tensor & out, const at::Tensor & grad, const at::Tensor & indices, const at::Tensor & offset2bag, const at::Tensor & bag_size, const at::Tensor & maximum_indices, int64_t num_weights, bool scale_grad_by_freq, int64_t mode, const c10::optional<at::Tensor> & per_sample_weights, int64_t padding_idx=-1);
|
| 21 |
+
TORCH_API at::Tensor & _embedding_bag_dense_backward_outf(const at::Tensor & grad, const at::Tensor & indices, const at::Tensor & offset2bag, const at::Tensor & bag_size, const at::Tensor & maximum_indices, int64_t num_weights, bool scale_grad_by_freq, int64_t mode, const c10::optional<at::Tensor> & per_sample_weights, int64_t padding_idx, at::Tensor & out);
|
| 22 |
+
TORCH_API at::Tensor & _embedding_bag_dense_backward_symint_out(at::Tensor & out, const at::Tensor & grad, const at::Tensor & indices, const at::Tensor & offset2bag, const at::Tensor & bag_size, const at::Tensor & maximum_indices, c10::SymInt num_weights, bool scale_grad_by_freq, int64_t mode, const c10::optional<at::Tensor> & per_sample_weights, int64_t padding_idx=-1);
|
| 23 |
+
TORCH_API at::Tensor & _embedding_bag_dense_backward_symint_outf(const at::Tensor & grad, const at::Tensor & indices, const at::Tensor & offset2bag, const at::Tensor & bag_size, const at::Tensor & maximum_indices, c10::SymInt num_weights, bool scale_grad_by_freq, int64_t mode, const c10::optional<at::Tensor> & per_sample_weights, int64_t padding_idx, at::Tensor & out);
|
| 24 |
+
|
| 25 |
+
} // namespace compositeexplicitautograd
|
| 26 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_lazy_clone_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _lazy_clone(const at::Tensor & self);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeexplicitautograd
|
| 23 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_linalg_slogdet_compositeexplicitautogradnonfunctional_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautogradnonfunctional {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor> _linalg_slogdet(const at::Tensor & A);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeexplicitautogradnonfunctional
|
| 23 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_unique2_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> _unique2(const at::Tensor & self, bool sorted=true, bool return_inverse=false, bool return_counts=false);
|
| 21 |
+
|
| 22 |
+
} // namespace cuda
|
| 23 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_meta.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeMetaFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/TensorIterator.h>
|
| 13 |
+
#include <ATen/TensorMeta.h>
|
| 14 |
+
#include <tuple>
|
| 15 |
+
#include <vector>
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
struct TORCH_API structured__upsample_bicubic2d_aa_backward : public at::impl::MetaBase {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
void meta(const at::Tensor & grad_output, at::ArrayRef<int64_t> output_size, at::ArrayRef<int64_t> input_size, bool align_corners, c10::optional<double> scales_h, c10::optional<double> scales_w);
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
} // namespace native
|
| 27 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_nearest_exact1d_backward_compositeexplicitautogradnonfunctional_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautogradnonfunctional {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _upsample_nearest_exact1d_backward(const at::Tensor & grad_output, at::IntArrayRef output_size, at::IntArrayRef input_size, c10::optional<double> scales=c10::nullopt);
|
| 21 |
+
TORCH_API at::Tensor _upsample_nearest_exact1d_backward_symint(const at::Tensor & grad_output, c10::SymIntArrayRef output_size, c10::SymIntArrayRef input_size, c10::optional<double> scales=c10::nullopt);
|
| 22 |
+
|
| 23 |
+
} // namespace compositeexplicitautogradnonfunctional
|
| 24 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/_use_cudnn_ctc_loss_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _use_cudnn_ctc_loss {
|
| 18 |
+
using schema = bool (const at::Tensor &, const at::Tensor &, at::IntArrayRef, at::IntArrayRef, int64_t);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_use_cudnn_ctc_loss")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_use_cudnn_ctc_loss(Tensor log_probs, Tensor targets, int[] input_lengths, int[] target_lengths, int blank) -> bool")
|
| 24 |
+
static bool call(const at::Tensor & log_probs, const at::Tensor & targets, at::IntArrayRef input_lengths, at::IntArrayRef target_lengths, int64_t blank);
|
| 25 |
+
static bool redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & log_probs, const at::Tensor & targets, at::IntArrayRef input_lengths, at::IntArrayRef target_lengths, int64_t blank);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _use_cudnn_ctc_loss_Tensor {
|
| 29 |
+
using schema = bool (const at::Tensor &, const at::Tensor &, const at::Tensor &, const at::Tensor &, int64_t);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_use_cudnn_ctc_loss")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_use_cudnn_ctc_loss.Tensor(Tensor log_probs, Tensor targets, Tensor input_lengths, Tensor target_lengths, int blank) -> bool")
|
| 35 |
+
static bool call(const at::Tensor & log_probs, const at::Tensor & targets, const at::Tensor & input_lengths, const at::Tensor & target_lengths, int64_t blank);
|
| 36 |
+
static bool redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & log_probs, const at::Tensor & targets, const at::Tensor & input_lengths, const at::Tensor & target_lengths, int64_t blank);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/cholesky_solve_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API cholesky_solve_out {
|
| 18 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, bool, at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cholesky_solve")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cholesky_solve.out(Tensor self, Tensor input2, bool upper=False, *, Tensor(a!) out) -> Tensor(a!)")
|
| 24 |
+
static at::Tensor & call(const at::Tensor & self, const at::Tensor & input2, bool upper, at::Tensor & out);
|
| 25 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & input2, bool upper, at::Tensor & out);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API cholesky_solve {
|
| 29 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &, bool);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cholesky_solve")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cholesky_solve(Tensor self, Tensor input2, bool upper=False) -> Tensor")
|
| 35 |
+
static at::Tensor call(const at::Tensor & self, const at::Tensor & input2, bool upper);
|
| 36 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & input2, bool upper);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/conv_depthwise3d_native.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor & conv_depthwise3d_out_symint(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef kernel_size, const c10::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, at::Tensor & out);
|
| 20 |
+
TORCH_API at::Tensor conv_depthwise3d_cuda(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef kernel_size, const c10::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation);
|
| 21 |
+
} // namespace native
|
| 22 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/cummaxmin_backward.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/cummaxmin_backward_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::cummaxmin_backward(Tensor grad, Tensor input, Tensor indices, int dim) -> Tensor
|
| 26 |
+
inline at::Tensor cummaxmin_backward(const at::Tensor & grad, const at::Tensor & input, const at::Tensor & indices, int64_t dim) {
|
| 27 |
+
return at::_ops::cummaxmin_backward::call(grad, input, indices, dim);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/div_meta_dispatch.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor div(const at::Tensor & self, const at::Tensor & other);
|
| 21 |
+
TORCH_API at::Tensor & div_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other);
|
| 22 |
+
TORCH_API at::Tensor & div_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & div_(at::Tensor & self, const at::Tensor & other);
|
| 24 |
+
TORCH_API at::Tensor div(const at::Tensor & self, const at::Tensor & other, c10::optional<c10::string_view> rounding_mode);
|
| 25 |
+
TORCH_API at::Tensor & div_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other, c10::optional<c10::string_view> rounding_mode);
|
| 26 |
+
TORCH_API at::Tensor & div_outf(const at::Tensor & self, const at::Tensor & other, c10::optional<c10::string_view> rounding_mode, at::Tensor & out);
|
| 27 |
+
TORCH_API at::Tensor & div_(at::Tensor & self, const at::Tensor & other, c10::optional<c10::string_view> rounding_mode);
|
| 28 |
+
|
| 29 |
+
} // namespace meta
|
| 30 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/erf_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor erf(const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & erf_out(at::Tensor & out, const at::Tensor & self);
|
| 22 |
+
TORCH_API at::Tensor & erf_outf(const at::Tensor & self, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & erf_(at::Tensor & self);
|
| 24 |
+
|
| 25 |
+
} // namespace cuda
|
| 26 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/fft_ihfft_compositeimplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeimplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor fft_ihfft(const at::Tensor & self, c10::optional<int64_t> n=c10::nullopt, int64_t dim=-1, c10::optional<c10::string_view> norm=c10::nullopt);
|
| 21 |
+
TORCH_API at::Tensor fft_ihfft_symint(const at::Tensor & self, c10::optional<c10::SymInt> n=c10::nullopt, int64_t dim=-1, c10::optional<c10::string_view> norm=c10::nullopt);
|
| 22 |
+
TORCH_API at::Tensor & fft_ihfft_out(at::Tensor & out, const at::Tensor & self, c10::optional<int64_t> n=c10::nullopt, int64_t dim=-1, c10::optional<c10::string_view> norm=c10::nullopt);
|
| 23 |
+
TORCH_API at::Tensor & fft_ihfft_outf(const at::Tensor & self, c10::optional<int64_t> n, int64_t dim, c10::optional<c10::string_view> norm, at::Tensor & out);
|
| 24 |
+
TORCH_API at::Tensor & fft_ihfft_symint_out(at::Tensor & out, const at::Tensor & self, c10::optional<c10::SymInt> n=c10::nullopt, int64_t dim=-1, c10::optional<c10::string_view> norm=c10::nullopt);
|
| 25 |
+
TORCH_API at::Tensor & fft_ihfft_symint_outf(const at::Tensor & self, c10::optional<c10::SymInt> n, int64_t dim, c10::optional<c10::string_view> norm, at::Tensor & out);
|
| 26 |
+
|
| 27 |
+
} // namespace compositeimplicitautograd
|
| 28 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/hstack_native.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor hstack(at::TensorList tensors);
|
| 20 |
+
TORCH_API at::Tensor & hstack_out(at::TensorList tensors, at::Tensor & out);
|
| 21 |
+
} // namespace native
|
| 22 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/kron_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API kron {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::kron")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "kron(Tensor self, Tensor other) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & self, const at::Tensor & other);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API kron_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::kron")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "kron.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/linear_backward_native.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &,at::Tensor &> linear_backward_out(const at::Tensor & self, const at::Tensor & grad_output, const at::Tensor & weight, ::std::array<bool,3> output_mask, at::Tensor & out0, at::Tensor & out1, at::Tensor & out2);
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor,at::Tensor> nested_linear_backward(const at::Tensor & self, const at::Tensor & grad_output, const at::Tensor & weight, ::std::array<bool,3> output_mask);
|
| 21 |
+
} // namespace native
|
| 22 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/log_normal_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & log_normal_(at::Tensor & self, double mean=1, double std=2, c10::optional<at::Generator> generator=c10::nullopt);
|
| 21 |
+
|
| 22 |
+
} // namespace cuda
|
| 23 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/logaddexp_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor logaddexp(const at::Tensor & self, const at::Tensor & other);
|
| 21 |
+
TORCH_API at::Tensor & logaddexp_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other);
|
| 22 |
+
TORCH_API at::Tensor & logaddexp_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 23 |
+
|
| 24 |
+
} // namespace cuda
|
| 25 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/logdet_compositeimplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeimplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor logdet(const at::Tensor & self);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeimplicitautograd
|
| 23 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/lshift.h
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/lshift_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::__lshift__.Scalar(Tensor self, Scalar other) -> Tensor
|
| 26 |
+
inline at::Tensor __lshift__(const at::Tensor & self, const at::Scalar & other) {
|
| 27 |
+
return at::_ops::__lshift___Scalar::call(self, other);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::__lshift__.Tensor(Tensor self, Tensor other) -> Tensor
|
| 31 |
+
inline at::Tensor __lshift__(const at::Tensor & self, const at::Tensor & other) {
|
| 32 |
+
return at::_ops::__lshift___Tensor::call(self, other);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// aten::__lshift__.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
|
| 36 |
+
inline at::Tensor & __lshift___out(at::Tensor & out, const at::Tensor & self, const at::Scalar & other) {
|
| 37 |
+
return at::_ops::__lshift___Scalar_out::call(self, other, out);
|
| 38 |
+
}
|
| 39 |
+
// aten::__lshift__.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
|
| 40 |
+
inline at::Tensor & __lshift___outf(const at::Tensor & self, const at::Scalar & other, at::Tensor & out) {
|
| 41 |
+
return at::_ops::__lshift___Scalar_out::call(self, other, out);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// aten::__lshift__.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 45 |
+
inline at::Tensor & __lshift___out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other) {
|
| 46 |
+
return at::_ops::__lshift___Tensor_out::call(self, other, out);
|
| 47 |
+
}
|
| 48 |
+
// aten::__lshift__.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 49 |
+
inline at::Tensor & __lshift___outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out) {
|
| 50 |
+
return at::_ops::__lshift___Tensor_out::call(self, other, out);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
}
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/masked_fill_meta_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & masked_fill_(at::Tensor & self, const at::Tensor & mask, const at::Scalar & value);
|
| 21 |
+
TORCH_API at::Tensor & masked_fill_(at::Tensor & self, const at::Tensor & mask, const at::Tensor & value);
|
| 22 |
+
|
| 23 |
+
} // namespace meta
|
| 24 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/max_pool3d_with_indices_backward_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor max_pool3d_with_indices_backward(const at::Tensor & grad_output, const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool ceil_mode, const at::Tensor & indices);
|
| 21 |
+
TORCH_API at::Tensor & max_pool3d_with_indices_backward_out(at::Tensor & grad_input, const at::Tensor & grad_output, const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool ceil_mode, const at::Tensor & indices);
|
| 22 |
+
TORCH_API at::Tensor & max_pool3d_with_indices_backward_outf(const at::Tensor & grad_output, const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool ceil_mode, const at::Tensor & indices, at::Tensor & grad_input);
|
| 23 |
+
|
| 24 |
+
} // namespace cuda
|
| 25 |
+
} // namespace at
|
falcon/lib/python3.10/site-packages/torch/include/ATen/ops/miopen_rnn_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API miopen_rnn {
|
| 18 |
+
using schema = ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor,at::Tensor> (const at::Tensor &, at::TensorList, int64_t, const at::Tensor &, const c10::optional<at::Tensor> &, int64_t, int64_t, int64_t, bool, double, bool, bool, at::IntArrayRef, const c10::optional<at::Tensor> &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::miopen_rnn")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "miopen_rnn(Tensor input, Tensor[] weight, int weight_stride0, Tensor hx, Tensor? cx, int mode, int hidden_size, int num_layers, bool batch_first, float dropout, bool train, bool bidirectional, int[] batch_sizes, Tensor? dropout_state) -> (Tensor, Tensor, Tensor, Tensor, Tensor)")
|
| 24 |
+
static ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor,at::Tensor> call(const at::Tensor & input, at::TensorList weight, int64_t weight_stride0, const at::Tensor & hx, const c10::optional<at::Tensor> & cx, int64_t mode, int64_t hidden_size, int64_t num_layers, bool batch_first, double dropout, bool train, bool bidirectional, at::IntArrayRef batch_sizes, const c10::optional<at::Tensor> & dropout_state);
|
| 25 |
+
static ::std::tuple<at::Tensor,at::Tensor,at::Tensor,at::Tensor,at::Tensor> redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & input, at::TensorList weight, int64_t weight_stride0, const at::Tensor & hx, const c10::optional<at::Tensor> & cx, int64_t mode, int64_t hidden_size, int64_t num_layers, bool batch_first, double dropout, bool train, bool bidirectional, at::IntArrayRef batch_sizes, const c10::optional<at::Tensor> & dropout_state);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API miopen_rnn_out {
|
| 29 |
+
using schema = ::std::tuple<at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &> (const at::Tensor &, at::TensorList, int64_t, const at::Tensor &, const c10::optional<at::Tensor> &, int64_t, int64_t, int64_t, bool, double, bool, bool, at::IntArrayRef, const c10::optional<at::Tensor> &, at::Tensor &, at::Tensor &, at::Tensor &, at::Tensor &, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::miopen_rnn")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "miopen_rnn.out(Tensor input, Tensor[] weight, int weight_stride0, Tensor hx, Tensor? cx, int mode, int hidden_size, int num_layers, bool batch_first, float dropout, bool train, bool bidirectional, int[] batch_sizes, Tensor? dropout_state, *, Tensor(a!) out0, Tensor(b!) out1, Tensor(c!) out2, Tensor(d!) out3, Tensor(e!) out4) -> (Tensor(a!), Tensor(b!), Tensor(c!), Tensor(d!), Tensor(e!))")
|
| 35 |
+
static ::std::tuple<at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &> call(const at::Tensor & input, at::TensorList weight, int64_t weight_stride0, const at::Tensor & hx, const c10::optional<at::Tensor> & cx, int64_t mode, int64_t hidden_size, int64_t num_layers, bool batch_first, double dropout, bool train, bool bidirectional, at::IntArrayRef batch_sizes, const c10::optional<at::Tensor> & dropout_state, at::Tensor & out0, at::Tensor & out1, at::Tensor & out2, at::Tensor & out3, at::Tensor & out4);
|
| 36 |
+
static ::std::tuple<at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &,at::Tensor &> redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & input, at::TensorList weight, int64_t weight_stride0, const at::Tensor & hx, const c10::optional<at::Tensor> & cx, int64_t mode, int64_t hidden_size, int64_t num_layers, bool batch_first, double dropout, bool train, bool bidirectional, at::IntArrayRef batch_sizes, const c10::optional<at::Tensor> & dropout_state, at::Tensor & out0, at::Tensor & out1, at::Tensor & out2, at::Tensor & out3, at::Tensor & out4);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|