22Axial Stretching
33================
44
5- This case tests the axial stretching of a rod. A rod is fixed at one end and
6- a force is applied at the other end. The rod stretches and the displacement
7- of the tip is compared with the analytical solution.
5+ This case tests the axial stretching of a rod.
6+ The expected behavior is supposed to be like a spring-gravity motion, but
7+ with a rod. A rod is fixed at one end and a force is applied at the other
8+ end. The rod stretches and the displacement of the tip is compared with
9+ the analytical solution.
810"""
911
1012# isort:skip_file
1517import elastica as ea
1618
1719# %%
18- # First, we define a simulator class that inherits from the necessary mixins.
19- # This makes it easy to add constraints, forces, and damping to the system.
20+ # Simulation Setup
21+ # ----------------
22+ # We define a simulator class that inherits from the necessary mixins.
23+ # This makes constraints, forces, and damping evailable to the system.
2024
2125
2226class StretchingBeamSimulator (
@@ -29,9 +33,13 @@ class StretchingBeamSimulator(
2933final_time = 200.0
3034
3135# %%
32- # Next, we set up the test parameters for the simulation. This includes the
36+ # Rod Setup
37+ # ---------
38+ # Next, we set up the test parameters for the simulating rods. This includes the
3339# number of elements, the start position, direction, normal, length, radius,
3440# density, and Young's modulus of the rod.
41+ # For this case, we have fixed boundary condition at one end, and we apply external
42+ # force at the other end.
3543
3644# setting up test params
3745n_elem = 19
@@ -47,10 +55,6 @@ class StretchingBeamSimulator(
4755poisson_ratio = 0.5
4856shear_modulus = youngs_modulus / (poisson_ratio + 1.0 )
4957
50- # %%
51- # Now we can create the `CosseratRod` object. We use the `straight_rod` method
52- # to create a straight rod with the specified parameters.
53-
5458stretchable_rod = ea .CosseratRod .straight_rod (
5559 n_elem ,
5660 start ,
@@ -65,18 +69,10 @@ class StretchingBeamSimulator(
6569
6670stretch_sim .append (stretchable_rod )
6771
68- # %%
69- # We then apply a boundary condition to fix one end of the rod. We use the
70- # `OneEndFixedBC` constraint to fix the position and director of the first node.
71-
7272stretch_sim .constrain (stretchable_rod ).using (
7373 ea .OneEndFixedBC , constrained_position_idx = (0 ,), constrained_director_idx = (0 ,)
7474)
7575
76- # %%
77- # A force is applied to the other end of the rod. We use the `EndpointForces`
78- # forcing to apply a force in the x-direction.
79-
8076end_force_x = 1.0
8177end_force = np .array ([end_force_x , 0.0 , 0.0 ])
8278stretch_sim .add_forcing_to (stretchable_rod ).using (
@@ -99,7 +95,9 @@ class StretchingBeamSimulator(
9995
10096
10197# %%
102- # We define a callback class to record the position and velocity of the rod
98+ # Callbacks
99+ # ---------
100+ # A callback object is passed to the simulator to record states of the rod
103101# during the simulation. This is useful for post-processing the results.
104102
105103
@@ -137,16 +135,15 @@ def make_callback(
137135)
138136
139137# %%
138+ # Finalize and Run
139+ # ----------------
140140# We finalize the simulator and create the time-stepper. The `PositionVerlet`
141141# time-stepper is used to integrate the system.
142142
143143stretch_sim .finalize ()
144144timestepper : ea .typing .StepperProtocol = ea .PositionVerlet ()
145145# timestepper = PEFRL()
146146
147- # %%
148- # The simulation is run for the specified `final_time`.
149-
150147total_steps = int (final_time / dt )
151148print ("Total steps" , total_steps )
152149dt = final_time / total_steps
@@ -155,6 +152,8 @@ def make_callback(
155152 time = timestepper .step (stretch_sim , time , dt )
156153
157154# %%
155+ # Post-Processing
156+ # ---------------
158157# Finally, we plot the results and compare them with the analytical solution.
159158# The analytical solution is calculated using the first-order theory with
160159# both the base length and the modified length.
0 commit comments