<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""This module contains some sample symbolic models used for testing and
examples."""

# external libraries
from sympy import symbols
import sympy.physics.mechanics as me


def generate_mass_spring_damper_equations_of_motion(external_force=True, kane=False):
    """Returns the symbolic equations of motion and associated variables for a
    simple one degree of freedom mass, spring, damper system with gravity
    and an optional external specified force.

      / / / / / / / /
     ----------------
      |    |     |   | g
      \   | |    |   V
    k /   --- c  |
      |    |     | x, v
     --------    V
     |  m   | -----
     --------
        | F
        V

    Returns
    -------
    mass_matrix : sympy.MutableMatrix, shape(2,2)
        The symbolic mass matrix of the system which are linear in
        derivatives of the states.
    forcing_vector : sympy.MutableMatrix, shape(2,1)
        The forcing vector of the system.
    constants : tuple, len(4)
        A sequence of all the symbols which are constants in the equations
        of motion, i.e. m, k, c, g.
    coordinates : tuple, len(1)
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the configuration of the system, i.e. x.
    speeds : tuple, len(1)
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the generalized speeds of the system, i.e v.
    specified : tuple, len(1) or None
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the specified variables of the system, i.e F. If
        `external_force` is False, then None is returned.
    external_force : boolean, default=True
        If true a specifed force will be added to the system.

    """

    mass, stiffness, damping, gravity = symbols('m, k, c, g')

    position, speed = me.dynamicsymbols('x v')
    positiond = me.dynamicsymbols('x', 1)
    force = me.dynamicsymbols('F')

    ceiling = me.ReferenceFrame('N')

    origin = me.Point('origin')
    origin.set_vel(ceiling, 0)

    center = origin.locatenew('center', position * ceiling.x)
    center.set_vel(ceiling, speed * ceiling.x)

    block = me.Particle('block', center, mass)

    kinematic_equations = [speed - positiond]

    total_force = mass * gravity - stiffness * position - damping * speed
    if external_force is True:
        total_force += force
    forces = [(center, total_force * ceiling.x)]

    particles = [block]

    kane = me.KanesMethod(ceiling, q_ind=[position], u_ind=[speed],
                          kd_eqs=kinematic_equations)
    kane.kanes_equations(forces, particles)

    mass_matrix = kane.mass_matrix_full
    forcing_vector = kane.forcing_full
    constants = (mass, stiffness, damping, gravity)
    coordinates = (position,)
    speeds = (speed,)
    if external_force is True:
        specified = (force,)
    else:
        specified = None

    if kane:
        return kane
    else:
        return (mass_matrix, forcing_vector, constants, coordinates, speeds,<commit_msg>Fix bug with mass spring damper kwarg.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""This module contains some sample symbolic models used for testing and
examples."""

# external libraries
from sympy import symbols
import sympy.physics.mechanics as me


def generate_mass_spring_damper_equations_of_motion(external_force=True,
        only_return_kane=False):
    """Returns the symbolic equations of motion and associated variables for a
    simple one degree of freedom mass, spring, damper system with gravity
    and an optional external specified force.

      / / / / / / / /
     ----------------
      |    |     |   | g
      \   | |    |   V
    k /   --- c  |
      |    |     | x, v
     --------    V
     |  m   | -----
     --------
        | F
        V

    Parameters
    ----------
    only_return_kane : bool, optional (default: False)
        If True, this method only returns the KanesMethod object.

    Returns
    -------
    kane : KanesMethod
        If the keyword argument `only_return_kane` is True, this is the only
        object returned.
    mass_matrix : sympy.MutableMatrix, shape(2,2)
        The symbolic mass matrix of the system which are linear in
        derivatives of the states.
    forcing_vector : sympy.MutableMatrix, shape(2,1)
        The forcing vector of the system.
    constants : tuple, len(4)
        A sequence of all the symbols which are constants in the equations
        of motion, i.e. m, k, c, g.
    coordinates : tuple, len(1)
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the configuration of the system, i.e. x.
    speeds : tuple, len(1)
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the generalized speeds of the system, i.e v.
    specified : tuple, len(1) or None
        A sequence of all the dynamic symbols, i.e. functions of time, which
        describe the specified variables of the system, i.e F. If
        `external_force` is False, then None is returned.
    external_force : boolean, default=True
        If true a specifed force will be added to the system.

    """

    mass, stiffness, damping, gravity = symbols('m, k, c, g')

    position, speed = me.dynamicsymbols('x v')
    positiond = me.dynamicsymbols('x', 1)
    force = me.dynamicsymbols('F')

    ceiling = me.ReferenceFrame('N')

    origin = me.Point('origin')
    origin.set_vel(ceiling, 0)

    center = origin.locatenew('center', position * ceiling.x)
    center.set_vel(ceiling, speed * ceiling.x)

    block = me.Particle('block', center, mass)

    kinematic_equations = [speed - positiond]

    total_force = mass * gravity - stiffness * position - damping * speed
    if external_force is True:
        total_force += force
    forces = [(center, total_force * ceiling.x)]

    particles = [block]

    kane = me.KanesMethod(ceiling, q_ind=[position], u_ind=[speed],
                          kd_eqs=kinematic_equations)
    kane.kanes_equations(forces, particles)

    mass_matrix = kane.mass_matrix_full
    forcing_vector = kane.forcing_full
    constants = (mass, stiffness, damping, gravity)
    coordinates = (position,)
    speeds = (speed,)
    if external_force is True:
        specified = (force,)
    else:
        specified = None

    if only_return_kane:
        return kane
    else:
        return (mass_matrix, forcing_vector, constants, coordinates, speeds,
{'fraction_non_alphanumeric': 0.10292772186642268, 'fraction_numerical': 0.003354681305275999, 'mean_word_length': 2.3430173292558614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3717303', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1870, 'n_words': 651}