From 67553d7eb99410d84b704198c503ebf5a67a8554 Mon Sep 17 00:00:00 2001 From: Seung Hyun Kim Date: Sat, 8 Jun 2024 14:03:53 +0900 Subject: [PATCH] add timoshenko example using elastica_blender --- examples/README.md | 7 ++++ examples/timoshenko.py | 84 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 examples/timoshenko.py diff --git a/examples/README.md b/examples/README.md index b7465d9..c4de47a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -25,3 +25,10 @@ Examples can serve as a starting template for customized usages. * __Purpose__: Illustration case for Rod module * __Features__: Rod * [RigidRodSpringMotion3D](./single_rigid_rod_spring_action_3D.py) + * __Purpose__: In 3D motion + +## Case with External Simulator + +* [TimoshenkoBeamCase](./TimoshenkoBeamCase) + * __Purpose__: Example of `elastica_blender` module on simple Timoshenko beam. + * __Features__: elastica_blender.BlenderRodCallback diff --git a/examples/timoshenko.py b/examples/timoshenko.py new file mode 100644 index 0000000..df486fb --- /dev/null +++ b/examples/timoshenko.py @@ -0,0 +1,84 @@ +# Originally from PyElastica example case + +import elastica as ea +import numpy as np + +import bsr +from elastica_blender import BlenderRodCallback + + +class TimoshenkoBeamSimulator( + ea.BaseSystemCollection, + ea.Constraints, + ea.Forcing, + ea.CallBacks, + ea.Damping, +): + pass + + +timoshenko_sim = TimoshenkoBeamSimulator() +final_time = 5000.0 + +# setting up test params +n_elem = 100 +start = np.zeros((3,)) +direction = np.array([0.0, 0.0, 1.0]) +normal = np.array([0.0, 1.0, 0.0]) +base_length = 3.0 +base_radius = 0.25 +base_area = np.pi * base_radius**2 +density = 5000 +nu = 0.1 / 7 / density / base_area +E = 1e6 +# For shear modulus of 1e4, nu is 99! +poisson_ratio = 99 +shear_modulus = E / (poisson_ratio + 1.0) + +shearable_rod = ea.CosseratRod.straight_rod( + n_elem, + start, + direction, + normal, + base_length, + base_radius, + density, + youngs_modulus=E, + shear_modulus=shear_modulus, +) + +timoshenko_sim.append(shearable_rod) +# add damping +dl = base_length / n_elem +dt = 0.07 * dl +timoshenko_sim.dampen(shearable_rod).using( + ea.AnalyticalLinearDamper, + damping_constant=nu, + time_step=dt, +) + +timoshenko_sim.constrain(shearable_rod).using( + ea.OneEndFixedBC, + constrained_position_idx=(0,), + constrained_director_idx=(0,), +) + +end_force = np.array([-15.0, 0.0, 0.0]) +timoshenko_sim.add_forcing_to(shearable_rod).using( + ea.EndpointForces, 0.0 * end_force, end_force, ramp_up_time=final_time / 2.0 +) + +# Use elastica_blender.BlenderRodCallback to render rod-video +timoshenko_sim.collect_diagnostics(shearable_rod).using( + BlenderRodCallback, + step_skip=500, +) + +timoshenko_sim.finalize() +timestepper = ea.PositionVerlet() + +total_steps = int(final_time / dt) +ea.integrate(timestepper, timoshenko_sim, final_time, total_steps) + +# Save as .blend file +bsr.save("timoshenko_beam.blend")