Comments (8)
Yes, thanks!
from pyelastica.
Hi @SHITIANYU-hue,
Can you provide us with more detail on the rest of the simulation to figure out exactly what is wrong here, like what forces are you applying, how are you plotting you results, and what are you trying to achieve?
The screenshot you posted looks like it is showing the simulation at 8.6s, so depending on what your doing with you simulation the length of your rod could change from its initial length of 10.
from pyelastica.
Hello @Ali-7800 , thanks for your reply! i applied the force like this: %matplotlib inline
time = 0
class PendulumSimulator(BaseSystemCollection, Constraints, Forcing, Damping):
pass
Pendulum_Sim = PendulumSimulator()
Create Rod
n_elem = 50
density = 75000
nu = 0.1 #damping constant
E = 1.2e9
poisson_ratio = 10
shear_modulus = E / (poisson_ratio + 1.0)
start = np.array([0.0,0.0,1.1])
direction = np.array([0.0, 1.0, 0.0])
normal = np.array([1.0, 0.0, 0.0])
base_length = 1
base_radius = 1/83
base_area = np.pi * base_radius**2
origin_force = np.array([0.0, 0.0, 0.0])
end_force = np.array([0.0, 3, 3])
ramp_up_time = 0.1
shearable_rod = CosseratRod.straight_rod(
n_elem,
start,
direction,
normal,
base_length,
base_radius,
density,
youngs_modulus=E,
shear_modulus = shear_modulus,
)
dl = base_length / n_elem
dt = 0.0002 * dl
Pendulum_Sim.append(shearable_rod)
Pendulum_Sim.dampen(shearable_rod).using(
AnalyticalLinearDamper,
damping_constant = nu,
time_step = dt,
)
Pendulum_Sim.constrain(shearable_rod).using(
OneEndFixedRod,constrained_position_idx = (0,), constrained_director_idx= (0,)
)
print("One end of the rod is now fixed in place")
Pendulum_Sim.add_forcing_to(shearable_rod).using(
GravityForces, acc_gravity = np.array([0.0,0.0,-9.8])
)
Pendulum_Sim.add_forcing_to(shearable_rod).using(
EndpointForces, origin_force, end_force, ramp_up_time = ramp_up_time
)
print("Forces added to the rod")
Pendulum_Sim.finalize()
print("System finalized")
#integrate(timestepper, Pendulum_Sim, final_time, total_steps)
def run_and_update_plot(simulator, dt, start_time, stop_time, ax):
timestepper = PositionVerlet()
do_step, stages_and_updates = extend_stepper_interface(timestepper, simulator)
n_steps = int((stop_time - start_time)/ dt)
time = start_time
for i in range(n_steps):
time = do_step(timestepper, stages_and_updates, simulator, time, dt)
plot_pendulum_dynamic(shearable_rod, time, ax)
return time
def plot_pendulum_dynamic(rod1, time, ax):
ax.clear()
ax.grid(which="major", color="grey", linestyle="-", linewidth=0.25)
ax.plot(
rod1.position_collection[1,:],
rod1.position_collection[2,:],
"b-",
label = "shearable rod",
)
ax.legend(prop={"size":12}, loc="lower left")
ax.set_ylabel("Y Position (1mm)", fontsize=12)
ax.set_xlabel("X Position (1mm)", fontsize=12)
ax.set_title(f"Simulation Time: {time:.2f} seconds")
ax.set_ylim([-2,2])
ax.set_xlim([-2,2])
Based on my understanding, the rod should not be Infinitely extended, but I observed in the simulation, it is Infinitely extended, may I know if the simulation collapsed? But if i changed another set of density and E , the rod will not be Infinitely extended,
from pyelastica.
Hi @SHITIANYU-hue,
What timestep are you using when you call run_and_update_plot? when I use dt = 0.0002 * dl, I get:
Here's a video of the whole simulation:
pendulum.mp4
from pyelastica.
Hi @Ali-7800 , i am really sorry I used another set of parameters, and thanks for running experiment, i add my full code below:
import numpy as np
import matplotlib.pyplot as plt
from IPython import display
# Import modules
from elastica.modules import BaseSystemCollection, Constraints, Forcing, Damping
# Import Cosserat Rod Class
from elastica.rod.cosserat_rod import CosseratRod
# Import Damping Class
from elastica.dissipation import AnalyticalLinearDamper
# Import Boundary Condition Classes
from elastica.boundary_conditions import OneEndFixedRod, FreeRod
from elastica.external_forces import EndpointForces
from elastica.external_forces import GravityForces
# Import Timestepping Functions
from elastica.timestepper.symplectic_steppers import PositionVerlet
from elastica.timestepper import extend_stepper_interface
from elastica.timestepper import integrate
%matplotlib inline
time = 0
class PendulumSimulator(BaseSystemCollection, Constraints, Forcing, Damping):
pass
Pendulum_Sim = PendulumSimulator()
# Create Rod
n_elem = 50
density = 7500000
nu = 0.1 #damping constant
E = 1.2e9
poisson_ratio = 10
shear_modulus = E / (poisson_ratio + 1.0)
start = np.array([0.0,0.0,1.1])
direction = np.array([0.0, 1.0, 0.0])
normal = np.array([1.0, 0.0, 0.0])
base_length = 10
base_radius = 1/83
base_area = np.pi * base_radius**2
origin_force = np.array([0.0, 0.0, 0.0])
end_force = np.array([0.0, 3, 3])
ramp_up_time = 0.1
shearable_rod = CosseratRod.straight_rod(
n_elem,
start,
direction,
normal,
base_length,
base_radius,
density,
youngs_modulus=E,
shear_modulus = shear_modulus,
)
dl = base_length / n_elem
dt = 0.0002 * dl
Pendulum_Sim.append(shearable_rod)
Pendulum_Sim.dampen(shearable_rod).using(
AnalyticalLinearDamper,
damping_constant = nu,
time_step = dt,
)
Pendulum_Sim.constrain(shearable_rod).using(
OneEndFixedRod,constrained_position_idx = (0,), constrained_director_idx= (0,)
)
print("One end of the rod is now fixed in place")
Pendulum_Sim.add_forcing_to(shearable_rod).using(
GravityForces, acc_gravity = np.array([0.0,0.0,-9.8])
)
Pendulum_Sim.add_forcing_to(shearable_rod).using(
EndpointForces, origin_force, end_force, ramp_up_time = ramp_up_time
)
print("Forces added to the rod")
Pendulum_Sim.finalize()
print("System finalized")
#integrate(timestepper, Pendulum_Sim, final_time, total_steps)
def run_and_update_plot(simulator, dt, start_time, stop_time, ax):
timestepper = PositionVerlet()
do_step, stages_and_updates = extend_stepper_interface(timestepper, simulator)
n_steps = int((stop_time - start_time)/ dt)
time = start_time
for i in range(n_steps):
time = do_step(timestepper, stages_and_updates, simulator, time, dt)
plot_pendulum_dynamic(shearable_rod, time, ax)
return time
def plot_pendulum_dynamic(rod1, time, ax):
ax.clear()
ax.grid(which="major", color="grey", linestyle="-", linewidth=0.25)
ax.plot(
rod1.position_collection[1,:],
rod1.position_collection[2,:],
"b-",
label = "shearable rod",
)
ax.legend(prop={"size":12}, loc="lower left")
ax.set_ylabel("Y Position (1mm)", fontsize=12)
ax.set_xlabel("X Position (1mm)", fontsize=12)
ax.set_title(f"Simulation Time: {time:.2f} seconds")
ax.set_ylim([-40,40])
ax.set_xlim([-10,10])
%matplotlib inline
evolve_for_time = 15.0
update_interval = 1.0e-1
import cv2,os
# update the plot every 0.1 second
fig = plt.figure(figsize=(5,4), frameon=True, dpi=150)
ax = fig.add_subplot(111)
plt.savefig('Pendulum.jpg')
video_name = 'Pendulum.mp4'
frame = cv2.imread('Pendulum.jpg')
height, width, layers = frame.shape
fourcc = cv2.VideoWriter_fourcc('M','P','4','V') # 解码器
video = cv2.VideoWriter(video_name,fourcc,1,(width,height))
first_interval_time = update_interval + time
last_interval_time = time + evolve_for_time
for stop_time in np.arange(
first_interval_time, last_interval_time+dt, update_interval
):
time = run_and_update_plot(Pendulum_Sim, dt, time, stop_time, ax)
display.clear_output(wait=True)
image = plt.gcf()
display.display(image)
plt.savefig('Pendulum.jpg')
video.write(cv2.imread("Pendulum.jpg"))
plt.close()
cv2.destroyAllWindows()
video.release()
This is my simulation:
video.mov
from pyelastica.
Hi @SHITIANYU-hue,
May I ask what exactly are you trying to simulate here, so I can better understand how to help you? Because depending on the units/dimensions you use you will get a different simulation and you might need to change the timestepping accordingly.
Also, is there a particular reason that you are not using the callback module for the plotting? I think it would be easier to do something similar to the ContinuumSnakeCase example where we do the entire simulation then plot the video instead of what you are doing.
from pyelastica.
Thanks for your reply! i understand i need to change the time-stepping accordingly, i will also try to use callback module for the plotting. I am working on the project similar to this issue: #310
I think in another repository build upon your work also discussed about the numerical simulation difficulties in Pyelasitca: alantes/RL-for-MSRs#2 .
from pyelastica.
@SHITIANYU-hue has the issue been resolved? Or else we shall close the issue due to inactivity in a few days.
from pyelastica.
Related Issues (20)
- Reproducing snake diffraction results from your Nat Comm Paper HOT 7
- Failure for Helix under Gravity Case HOT 2
- Can PyElastica support GPU acceleration? HOT 3
- Do PyElastica support to simulate a rod containing two segments? HOT 3
- Replicating side-winding results from your Nat-comm snake paper HOT 29
- Instant controler and simulation HOT 6
- Small scale rod simulation HOT 11
- Updating muscle forces mid-simulation - how does it work? HOT 1
- Small-scale simulation problem 2 HOT 1
- OneEndFixedBC didn't work for applying a external torque HOT 4
- Adding force and torque at same time HOT 5
- How to using PyElastica data to visualize in 3D models? HOT 1
- `FileNotFoundError` `python continuum_snake.py` HOT 1
- Bug and fix in 2_Slithering_Snake.ipynb HOT 1
- Task 1: Utilizing Python to clean and convert data from Elastica into a format recognizable by Blender. HOT 1
- Avoid having randomized unittest HOT 17
- [GSOC project 3] Binding PyElastica with Elastica++ HOT 1
- GSoC interest in Optimizing backend kernels in PyElastica HOT 1
- Examples not running due to modules not being found HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyelastica.