@@ -114,6 +114,7 @@ def build_cpu_sim(
114114 poisson_ratio : float ,
115115 gravitational_acc : float ,
116116 time_step : float ,
117+ include_external_loads : bool = True ,
117118) -> tuple [MultiSnakeReferenceSimulator , list [ea .CosseratRod ]]:
118119 b_coeff = default_b_coeff ()
119120 normal = np .array ([0.0 , 1.0 , 0.0 ], dtype = np .float64 )
@@ -125,11 +126,12 @@ def build_cpu_sim(
125126
126127 sim = MultiSnakeReferenceSimulator ()
127128 rods : list [ea .CosseratRod ] = []
128- ground_plane = ea .Plane (
129- plane_origin = np .array ([0.0 , - base_length * 0.011 , 0.0 ], dtype = np .float64 ),
130- plane_normal = normal ,
131- )
132- sim .append (ground_plane )
129+ if include_external_loads :
130+ ground_plane = ea .Plane (
131+ plane_origin = np .array ([0.0 , - base_length * 0.011 , 0.0 ], dtype = np .float64 ),
132+ plane_normal = normal ,
133+ )
134+ sim .append (ground_plane )
133135
134136 for idx in range (n_snakes ):
135137 rod = build_rod (
@@ -142,35 +144,36 @@ def build_cpu_sim(
142144 start = snake_start (idx , spacing )
143145 rod .position_collection [...] = rod .position_collection + start [:, None ]
144146 sim .append (rod )
145- sim .add_forcing_to (rod ).using (
146- ea .GravityForces ,
147- acc_gravity = np .array ([0.0 , gravitational_acc , 0.0 ], dtype = np .float64 ),
148- )
149- sim .add_forcing_to (rod ).using (
150- ea .MuscleTorques ,
151- base_length = base_length ,
152- b_coeff = b_coeff [:- 1 ],
153- period = period ,
154- wave_number = 2.0 * np .pi / wave_length ,
155- phase_shift = 0.0 ,
156- rest_lengths = rod .rest_lengths ,
157- ramp_up_time = period ,
158- direction = normal ,
159- with_spline = True ,
160- )
161- sim .detect_contact_between (rod , ground_plane ).using (
162- ea .RodPlaneContactWithAnisotropicFriction ,
163- k = 1.0 ,
164- nu = 1.0e-6 ,
165- slip_velocity_tol = 1.0e-8 ,
166- static_mu_array = static_mu_array ,
167- kinetic_mu_array = kinetic_mu_array ,
168- )
169- sim .dampen (rod ).using (
170- ea .AnalyticalLinearDamper ,
171- damping_constant = DEFAULT_DAMPING ,
172- time_step = time_step ,
173- )
147+ if include_external_loads :
148+ sim .add_forcing_to (rod ).using (
149+ ea .GravityForces ,
150+ acc_gravity = np .array ([0.0 , gravitational_acc , 0.0 ], dtype = np .float64 ),
151+ )
152+ sim .add_forcing_to (rod ).using (
153+ ea .MuscleTorques ,
154+ base_length = base_length ,
155+ b_coeff = b_coeff [:- 1 ],
156+ period = period ,
157+ wave_number = 2.0 * np .pi / wave_length ,
158+ phase_shift = 0.0 ,
159+ rest_lengths = rod .rest_lengths ,
160+ ramp_up_time = period ,
161+ direction = normal ,
162+ with_spline = True ,
163+ )
164+ sim .detect_contact_between (rod , ground_plane ).using (
165+ ea .RodPlaneContactWithAnisotropicFriction ,
166+ k = 1.0 ,
167+ nu = 1.0e-6 ,
168+ slip_velocity_tol = 1.0e-8 ,
169+ static_mu_array = static_mu_array ,
170+ kinetic_mu_array = kinetic_mu_array ,
171+ )
172+ sim .dampen (rod ).using (
173+ ea .AnalyticalLinearDamper ,
174+ damping_constant = DEFAULT_DAMPING ,
175+ time_step = time_step ,
176+ )
174177 rods .append (rod )
175178
176179 sim .finalize ()
@@ -190,6 +193,7 @@ def build_jax_sim(
190193 poisson_ratio : float ,
191194 gravitational_acc : float ,
192195 time_step : float ,
196+ include_external_loads : bool = True ,
193197) -> tuple [MultiSnakeJAXSimulator , ea .MemoryBlockCosseratRodJax ]:
194198 b_coeff = default_b_coeff ()
195199 mu = base_length / (period * period * np .abs (gravitational_acc ) * DEFAULT_FROUDE )
@@ -213,28 +217,31 @@ def build_jax_sim(
213217 start = snake_start (idx , spacing )
214218 rod .position_collection [...] = rod .position_collection + start [:, None ]
215219 sim .append (rod )
216- sim .using (rod ).operate (
217- SnakeMuscleTorquesJax ,
218- b_coeff = b_coeff ,
219- period = period ,
220- base_length = base_length ,
221- gravitational_acc = gravitational_acc ,
222- )
223- sim .using (rod ).operate (
224- SnakePlaneContactJax ,
225- plane_origin = np .array ([0.0 , - base_length * 0.011 , 0.0 ], dtype = np .float64 ),
226- plane_normal = np .array ([0.0 , 1.0 , 0.0 ], dtype = np .float64 ),
227- slip_velocity_tol = 1.0e-8 ,
228- k = 1.0 ,
229- nu = 1.0e-6 ,
230- static_mu_array = static_mu_array ,
231- kinetic_mu_array = kinetic_mu_array ,
232- )
233- sim .using (rod ).operate (
234- ea .AnalyticalLinearDamperJax ,
235- time_step = np .float64 (time_step ),
236- damping_constant = DEFAULT_DAMPING ,
237- )
220+ if include_external_loads :
221+ sim .using (rod ).operate (
222+ SnakeMuscleTorquesJax ,
223+ b_coeff = b_coeff ,
224+ period = period ,
225+ base_length = base_length ,
226+ gravitational_acc = gravitational_acc ,
227+ )
228+ sim .using (rod ).operate (
229+ SnakePlaneContactJax ,
230+ plane_origin = np .array (
231+ [0.0 , - base_length * 0.011 , 0.0 ], dtype = np .float64
232+ ),
233+ plane_normal = np .array ([0.0 , 1.0 , 0.0 ], dtype = np .float64 ),
234+ slip_velocity_tol = 1.0e-8 ,
235+ k = 1.0 ,
236+ nu = 1.0e-6 ,
237+ static_mu_array = static_mu_array ,
238+ kinetic_mu_array = kinetic_mu_array ,
239+ )
240+ sim .using (rod ).operate (
241+ ea .AnalyticalLinearDamperJax ,
242+ time_step = np .float64 (time_step ),
243+ damping_constant = DEFAULT_DAMPING ,
244+ )
238245
239246 sim .finalize ()
240247 block = tuple (sim .final_systems ())[0 ]
@@ -348,6 +355,7 @@ def benchmark_config(
348355 n_snakes : int ,
349356 n_elem : int ,
350357 dt : float ,
358+ include_external_loads : bool = True ,
351359) -> dict [str , Any ]:
352360 return {
353361 "n_snakes" : n_snakes ,
@@ -359,4 +367,5 @@ def benchmark_config(
359367 "poisson_ratio" : DEFAULT_POISSON_RATIO ,
360368 "gravitational_acc" : DEFAULT_GRAVITY ,
361369 "time_step" : dt ,
370+ "include_external_loads" : include_external_loads ,
362371 }
0 commit comments