Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting nodal velocities to element velocities #80

Closed
armantekinalp opened this issue May 11, 2022 · 1 comment · Fixed by #98
Closed

Converting nodal velocities to element velocities #80

armantekinalp opened this issue May 11, 2022 · 1 comment · Fixed by #98
Assignees
Labels
bug Something isn't working
Milestone

Comments

@armantekinalp
Copy link
Contributor

armantekinalp commented May 11, 2022

In PyElastica we store velocity on nodes and for some computations (i.e. rod damping, plane damping or stokes flow) we have to convert velocity from nodes to elements. Currently we are averaging the neigboring node velocity to compute element velocity using the following function.

def node_to_element_pos_or_vel(vector_in_node_frame):
"""
This function computes the velocity of the elements.
Here we define a separate function because benchmark results
showed that using Numba, we get more than 3 times faster calculation.
Parameters
----------
vector_in_node_frame: numpy.ndarray
2D (dim, blocksize) array containing data with 'float' type.
Returns
-------
vector_in_element_frame: numpy.ndarray
2D (dim, blocksize) array containing data with 'float' type.
"""
"""
Developer Notes
-----
Benchmark results, for a blocksize of 100,
Python version: 3.5 µs ± 149 ns per loop
This version: 729 ns ± 14.3 ns per loop
"""
n_elem = vector_in_node_frame.shape[1] - 1
vector_in_element_frame = np.empty((3, n_elem))
for k in range(n_elem):
vector_in_element_frame[0, k] = 0.5 * (
vector_in_node_frame[0, k + 1] + vector_in_node_frame[0, k]
)
vector_in_element_frame[1, k] = 0.5 * (
vector_in_node_frame[1, k + 1] + vector_in_node_frame[1, k]
)
vector_in_element_frame[2, k] = 0.5 * (
vector_in_node_frame[2, k + 1] + vector_in_node_frame[2, k]
)
return vector_in_element_frame

Although this function is correct for uniform rods (uniform cross-section, element length and density) for tapered rods, momentum is not conserved since neighboring node masses are not the same. Thus, we have to first compute the total momentum of element and divide by the element mass to compute element velocity.

How to fix :

  1. Use the following function to compute element velocities
def node_to_element_velocity(mass, velocity_collection):
    """
    """
    n_elem = velocity_collection.shape[1] - 1
    element_velocity = np.empty((3, n_elem))
    for k in range(n_elem):
        element_velocity[0, k] = (
            mass[k+1] * velocity_collection[0, k + 1] + mass[k] * velocity_collection[0, k]
        )
        element_velocity[1, k] = (
            mass[k+1] * velocity_collection[1, k + 1] + mass[k] * velocity_collection[1, k]
        )
        element_velocity[2, k] =(
            mass[k+1] * velocity_collection[2, k + 1] + mass[k] * velocity_collection[2, k]
        )
        element_velocity[:,k] /= (mass[k+1] + mass[k])


    return element_velocity
  1. Rename the function node_to_element_pos_or_vel as node_to_element_position, since this will be only used to compute the element positions.
@armantekinalp armantekinalp added the bug Something isn't working label May 11, 2022
@armantekinalp armantekinalp added this to the Version 0.3 milestone May 11, 2022
@bhosale2 bhosale2 self-assigned this May 17, 2022
@bhosale2 bhosale2 linked a pull request Jun 1, 2022 that will close this issue
armantekinalp added a commit that referenced this issue Jun 1, 2022
@bhosale2
Copy link
Collaborator

bhosale2 commented Jun 1, 2022

Closed by #98.

@bhosale2 bhosale2 closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants