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

Adding Interaction plane to slithering snake example #107

Closed
matei1996 opened this issue Jun 10, 2022 · 14 comments
Closed

Adding Interaction plane to slithering snake example #107

matei1996 opened this issue Jun 10, 2022 · 14 comments
Labels
help wanted Extra attention is needed

Comments

@matei1996
Copy link

Dear PyElastica Team,

I am currently trying to add an Interaction plane (or any arbitrary obstacle) to the slithering snake example, so that the snake "bounces of" the plane and continues to move into a different direction. However, I wasn't able to find out the correct way to do it. I tried adding the following code into the example

side_plane = np.array([0.0, 0.0, 3.0])
side_normal = np.array([0.0, 0.0, 1.0])
surface_tol=1e-4

plane_sim = InteractionPlane(k=1.0,nu=1e-6,plane_origin=side_plane,plane_normal=normal_plane)

I do not obtain any error messages. Unfortunately, the code does not seem to have any effect on the snake. I am thankful for any tips. I am very new to the PyElastica (and Github) implementation, however I think this is a great project!

@matei1996 matei1996 added the help wanted Extra attention is needed label Jun 10, 2022
@armantekinalp
Copy link
Contributor

Hi @matei1996

You cannot add InteractionPlane class to the simulator since it is parent class of AnisotropicFrictionalPlane. Because of that you don't see any difference in your simulation with/without InteractionPlane.

If you want to add obstacles, you can add rigid cylinders and set contact between rod and cylinders. Here you can see the examples how to do.

Let me know if this helps.

@matei1996
Copy link
Author

Hi @armantekinalp

Thanks a lot. Yes this helps me for now. Is it also possible to use something else than a cylinder as obstacle? I would like to into interaction with a plane or letting the rod start inside the cylinder.

Best regards,
Matei

@armantekinalp
Copy link
Contributor

No, currently we only support contact between rod-cylinder and rod with flat plane (AnisotropicFrictionalPlane). However, you can extend the contact and interaction classes based on your problem requirements.

@matei1996
Copy link
Author

Ok, thank you! One other question. Is it possible to integrate multiple cylinders? Through my first attempts it seems to be the case. However, I still have problems with the plot_cylinder_rod_position, since it only takes as argument cylinder_history of 1 cylinder. I tried using further "plot_cylinder_rod_position" functions with different cylinders but that didn't work as intended. Can I use only one function for all cylinders?

@matei1996
Copy link
Author

Hi again,

I am also trying to rotate the cylinder by the changing the normal and the directional vector, however it does not seem work. Do you have any idea why this might be the case? If I should open a new issue please let me know. I am unsure...

Best regards,
Matei

@armantekinalp
Copy link
Contributor

Ok, thank you! One other question. Is it possible to integrate multiple cylinders? Through my first attempts it seems to be the case. However, I still have problems with the plot_cylinder_rod_position, since it only takes as argument cylinder_history of 1 cylinder. I tried using further "plot_cylinder_rod_position" functions with different cylinders but that didn't work as intended. Can I use only one function for all cylinders?

You need to define callback functions for all cylinders that are append to the simulation, so you can record their time history. For plotting you need to update the plotting scripts.

@armantekinalp
Copy link
Contributor

Are you changing normal and direction during the simulation or at initialization step? If you want to rotate cylinder during the simulation then you should update the director_collection accordingly. You can update director_collection using a custom boundary condition class for your problem, I suggest checking HelicalBucklingBC in this case we change the rod end position and directors. Since cylinder has one director you only need to change that.

@matei1996
Copy link
Author

Thanks. I was able to plot multiple rods now.

Regarding the position of the cylinder: Right not I am only trying to change the direction and normal of the rod at initialization. However, this does not work yet as intended. The cylinders do not change compared to the original position in the example.
(#107)

Furthermore, I noticed that some specific interactions of the rod lead to the following error message:

:95: UserWarning: Z contains NaN values. This may result in rendering artifacts.
surf = ax.plot_surface(XC, YC, ZC, color="g", alpha=0.5)

I assume it depends on the contact position of the rod with the cylinder. Usually the error occurs if the rod is hitting the cylinder "further to the middle" and therefore is deflected stronger as opposed to hitting it on the upper or lower edges.
Is there an explanation for this?

@armantekinalp
Copy link
Contributor

Regarding the position of the cylinder: Right not I am only trying to change the direction and normal of the rod at initialization. However, this does not work yet as intended. The cylinders do not change compared to the original position in the example. (#107)

Can you share me how you initialize the cylinder? Cylinder should rotate but the plotting might have issues.

I assume it depends on the contact position of the rod with the cylinder. Usually the error occurs if the rod is hitting the cylinder "further to the middle" and therefore is deflected stronger as opposed to hitting it on the upper or lower edges. Is there an explanation for this?

Do you have any videos or some plots? I am currently working on improving the rod-cylinder contact model and there should be a PR soon. Maybe that can fix the problem you have.

@matei1996
Copy link
Author

To initialize the cylinder i use the same code that is used in the example you mentioned above. (#107)

I initialize it using

cylinder_start = np.array([0.3, 0.0, 0.0])
cylinder_direction = np.array([0.0, 1.0, 0.0])
cylinder_normal = np.array([0.0, 0.0, 1.0])
cylinder_height = 0.9
cylinder_radius = 10.0 * base_radius
density_rod=10

cylinder = Cylinder(
cylinder_start,
cylinder_direction,
cylinder_normal,
cylinder_height,
cylinder_radius,
density_rod,
)

and then change the parameters. I would like to have the cylinder pointing upwards.

For the second problem I can only attach a video where everything is working, when I get an error message, no video is created.

2D_mult_cylinder_rod_collision_2.mp4

@matei1996
Copy link
Author

Hi, I have one more different question. I don't know if I should open a new request. If yes please let me know.

We are trying right now to model a long rod that enters an environment(like the above one with multiple cylinders) through some narrow entry. So we would like to have some boundary conditions at the entrance, for example at the point (0,0), where the rod is fixed and can not change. Is there an example where something similar is done?

We would need moving BC where the values are time dependent, meaning we would like to have BC at a specific element of the rod and after some time shift the BC to the next element.
If something like this isn't possible yet, do you know which part of the source code has to be modified to achieve this result?

@armantekinalp
Copy link
Contributor

I initialize it using

cylinder_start = np.array([0.3, 0.0, 0.0]) cylinder_direction = np.array([0.0, 1.0, 0.0]) cylinder_normal = np.array([0.0, 0.0, 1.0]) cylinder_height = 0.9 cylinder_radius = 10.0 * base_radius density_rod=10

cylinder = Cylinder( cylinder_start, cylinder_direction, cylinder_normal, cylinder_height, cylinder_radius, density_rod, )

It seems there is an issue in plotting script and not the initialization of cylinder. You can check the tangent of cylinder as printing out the cylinder.director_collection[2,:,0] and it should be different if you change cylinder_direction.

@armantekinalp
Copy link
Contributor

For the second problem I can only attach a video where everything is working, when I get an error message, no video is created.

It seems you have a numerical problem. Have you tried the contact with smaller contact constant?

@armantekinalp
Copy link
Contributor

Hi, I have one more different question. I don't know if I should open a new request. If yes please let me know.

We are trying right now to model a long rod that enters an environment(like the above one with multiple cylinders) through some narrow entry. So we would like to have some boundary conditions at the entrance, for example at the point (0,0), where the rod is fixed and can not change. Is there an example where something similar is done?

We would need moving BC where the values are time dependent, meaning we would like to have BC at a specific element of the rod and after some time shift the BC to the next element. If something like this isn't possible yet, do you know which part of the source code has to be modified to achieve this result?

We don't have a boundary condition exactly for your needs so you need to write your own custom boundary condition class. I think HelicalBucklingBC is a good example for you to start. This BC class slowly rotates the ends of the rods and pulls it by changing the angular and translational velocity. So there are time-dependency, and modifying the position of end node/elements.

pppprub pushed a commit to pppprub/PyElastica that referenced this issue Sep 4, 2022
Fix incorrect assertion of indices while forming connections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants