warp-lang 1.9.0__py3-none-win_amd64.whl → 1.10.0rc2__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (350) hide show
  1. warp/__init__.py +301 -287
  2. warp/__init__.pyi +2220 -313
  3. warp/_src/__init__.py +14 -0
  4. warp/_src/autograd.py +1075 -0
  5. warp/_src/build.py +618 -0
  6. warp/_src/build_dll.py +640 -0
  7. warp/{builtins.py → _src/builtins.py} +1497 -226
  8. warp/_src/codegen.py +4359 -0
  9. warp/{config.py → _src/config.py} +178 -169
  10. warp/_src/constants.py +57 -0
  11. warp/_src/context.py +8294 -0
  12. warp/_src/dlpack.py +462 -0
  13. warp/_src/fabric.py +355 -0
  14. warp/_src/fem/__init__.py +14 -0
  15. warp/_src/fem/adaptivity.py +508 -0
  16. warp/_src/fem/cache.py +687 -0
  17. warp/_src/fem/dirichlet.py +188 -0
  18. warp/{fem → _src/fem}/domain.py +40 -30
  19. warp/_src/fem/field/__init__.py +131 -0
  20. warp/_src/fem/field/field.py +701 -0
  21. warp/{fem → _src/fem}/field/nodal_field.py +30 -15
  22. warp/{fem → _src/fem}/field/restriction.py +1 -1
  23. warp/{fem → _src/fem}/field/virtual.py +53 -27
  24. warp/_src/fem/geometry/__init__.py +32 -0
  25. warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +77 -163
  26. warp/_src/fem/geometry/closest_point.py +97 -0
  27. warp/{fem → _src/fem}/geometry/deformed_geometry.py +14 -22
  28. warp/{fem → _src/fem}/geometry/element.py +32 -10
  29. warp/{fem → _src/fem}/geometry/geometry.py +48 -20
  30. warp/{fem → _src/fem}/geometry/grid_2d.py +12 -23
  31. warp/{fem → _src/fem}/geometry/grid_3d.py +12 -23
  32. warp/{fem → _src/fem}/geometry/hexmesh.py +40 -63
  33. warp/{fem → _src/fem}/geometry/nanogrid.py +255 -248
  34. warp/{fem → _src/fem}/geometry/partition.py +121 -63
  35. warp/{fem → _src/fem}/geometry/quadmesh.py +26 -45
  36. warp/{fem → _src/fem}/geometry/tetmesh.py +40 -63
  37. warp/{fem → _src/fem}/geometry/trimesh.py +26 -45
  38. warp/{fem → _src/fem}/integrate.py +164 -158
  39. warp/_src/fem/linalg.py +383 -0
  40. warp/_src/fem/operator.py +396 -0
  41. warp/_src/fem/polynomial.py +229 -0
  42. warp/{fem → _src/fem}/quadrature/pic_quadrature.py +15 -20
  43. warp/{fem → _src/fem}/quadrature/quadrature.py +95 -47
  44. warp/_src/fem/space/__init__.py +248 -0
  45. warp/{fem → _src/fem}/space/basis_function_space.py +20 -11
  46. warp/_src/fem/space/basis_space.py +679 -0
  47. warp/{fem → _src/fem}/space/dof_mapper.py +3 -3
  48. warp/{fem → _src/fem}/space/function_space.py +14 -13
  49. warp/{fem → _src/fem}/space/grid_2d_function_space.py +4 -7
  50. warp/{fem → _src/fem}/space/grid_3d_function_space.py +4 -4
  51. warp/{fem → _src/fem}/space/hexmesh_function_space.py +4 -10
  52. warp/{fem → _src/fem}/space/nanogrid_function_space.py +3 -9
  53. warp/{fem → _src/fem}/space/partition.py +117 -60
  54. warp/{fem → _src/fem}/space/quadmesh_function_space.py +4 -10
  55. warp/{fem → _src/fem}/space/restriction.py +66 -33
  56. warp/_src/fem/space/shape/__init__.py +152 -0
  57. warp/{fem → _src/fem}/space/shape/cube_shape_function.py +9 -9
  58. warp/{fem → _src/fem}/space/shape/shape_function.py +8 -9
  59. warp/{fem → _src/fem}/space/shape/square_shape_function.py +6 -6
  60. warp/{fem → _src/fem}/space/shape/tet_shape_function.py +3 -3
  61. warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +3 -3
  62. warp/{fem → _src/fem}/space/tetmesh_function_space.py +3 -9
  63. warp/_src/fem/space/topology.py +459 -0
  64. warp/{fem → _src/fem}/space/trimesh_function_space.py +3 -9
  65. warp/_src/fem/types.py +112 -0
  66. warp/_src/fem/utils.py +486 -0
  67. warp/_src/jax.py +186 -0
  68. warp/_src/jax_experimental/__init__.py +14 -0
  69. warp/_src/jax_experimental/custom_call.py +387 -0
  70. warp/_src/jax_experimental/ffi.py +1284 -0
  71. warp/_src/jax_experimental/xla_ffi.py +656 -0
  72. warp/_src/marching_cubes.py +708 -0
  73. warp/_src/math.py +414 -0
  74. warp/_src/optim/__init__.py +14 -0
  75. warp/_src/optim/adam.py +163 -0
  76. warp/_src/optim/linear.py +1606 -0
  77. warp/_src/optim/sgd.py +112 -0
  78. warp/_src/paddle.py +406 -0
  79. warp/_src/render/__init__.py +14 -0
  80. warp/_src/render/imgui_manager.py +289 -0
  81. warp/_src/render/render_opengl.py +3636 -0
  82. warp/_src/render/render_usd.py +937 -0
  83. warp/_src/render/utils.py +160 -0
  84. warp/_src/sparse.py +2716 -0
  85. warp/_src/tape.py +1206 -0
  86. warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
  87. warp/_src/torch.py +391 -0
  88. warp/_src/types.py +5870 -0
  89. warp/_src/utils.py +1693 -0
  90. warp/autograd.py +12 -1054
  91. warp/bin/warp-clang.dll +0 -0
  92. warp/bin/warp.dll +0 -0
  93. warp/build.py +8 -588
  94. warp/build_dll.py +6 -471
  95. warp/codegen.py +6 -4246
  96. warp/constants.py +6 -39
  97. warp/context.py +12 -7851
  98. warp/dlpack.py +6 -444
  99. warp/examples/distributed/example_jacobi_mpi.py +4 -5
  100. warp/examples/fem/example_adaptive_grid.py +1 -1
  101. warp/examples/fem/example_apic_fluid.py +1 -1
  102. warp/examples/fem/example_burgers.py +8 -8
  103. warp/examples/fem/example_diffusion.py +1 -1
  104. warp/examples/fem/example_distortion_energy.py +1 -1
  105. warp/examples/fem/example_mixed_elasticity.py +2 -2
  106. warp/examples/fem/example_navier_stokes.py +1 -1
  107. warp/examples/fem/example_nonconforming_contact.py +7 -7
  108. warp/examples/fem/example_stokes.py +1 -1
  109. warp/examples/fem/example_stokes_transfer.py +1 -1
  110. warp/examples/fem/utils.py +2 -2
  111. warp/examples/interop/example_jax_callable.py +1 -1
  112. warp/examples/interop/example_jax_ffi_callback.py +1 -1
  113. warp/examples/interop/example_jax_kernel.py +3 -2
  114. warp/examples/tile/example_tile_mcgp.py +191 -0
  115. warp/fabric.py +6 -337
  116. warp/fem/__init__.py +159 -97
  117. warp/fem/adaptivity.py +7 -489
  118. warp/fem/cache.py +9 -648
  119. warp/fem/dirichlet.py +6 -184
  120. warp/fem/field/__init__.py +8 -109
  121. warp/fem/field/field.py +7 -652
  122. warp/fem/geometry/__init__.py +7 -18
  123. warp/fem/geometry/closest_point.py +11 -77
  124. warp/fem/linalg.py +18 -366
  125. warp/fem/operator.py +11 -369
  126. warp/fem/polynomial.py +9 -209
  127. warp/fem/space/__init__.py +5 -211
  128. warp/fem/space/basis_space.py +6 -662
  129. warp/fem/space/shape/__init__.py +41 -118
  130. warp/fem/space/topology.py +6 -437
  131. warp/fem/types.py +6 -81
  132. warp/fem/utils.py +11 -444
  133. warp/jax.py +8 -165
  134. warp/jax_experimental/__init__.py +14 -1
  135. warp/jax_experimental/custom_call.py +8 -342
  136. warp/jax_experimental/ffi.py +17 -853
  137. warp/jax_experimental/xla_ffi.py +5 -596
  138. warp/marching_cubes.py +5 -689
  139. warp/math.py +16 -393
  140. warp/native/array.h +385 -37
  141. warp/native/builtin.h +316 -39
  142. warp/native/bvh.cpp +43 -9
  143. warp/native/bvh.cu +62 -27
  144. warp/native/bvh.h +310 -309
  145. warp/native/clang/clang.cpp +102 -97
  146. warp/native/coloring.cpp +0 -1
  147. warp/native/crt.h +208 -0
  148. warp/native/exports.h +156 -0
  149. warp/native/hashgrid.cu +2 -0
  150. warp/native/intersect.h +24 -1
  151. warp/native/intersect_tri.h +44 -35
  152. warp/native/mat.h +1456 -276
  153. warp/native/mesh.cpp +4 -4
  154. warp/native/mesh.cu +4 -2
  155. warp/native/mesh.h +176 -61
  156. warp/native/quat.h +0 -52
  157. warp/native/scan.cu +2 -0
  158. warp/native/sort.cu +22 -13
  159. warp/native/sort.h +2 -0
  160. warp/native/sparse.cu +7 -3
  161. warp/native/spatial.h +12 -0
  162. warp/native/tile.h +837 -70
  163. warp/native/tile_radix_sort.h +1 -1
  164. warp/native/tile_reduce.h +394 -46
  165. warp/native/tile_scan.h +4 -4
  166. warp/native/vec.h +469 -53
  167. warp/native/version.h +23 -0
  168. warp/native/volume.cpp +1 -1
  169. warp/native/volume.cu +1 -0
  170. warp/native/volume.h +1 -1
  171. warp/native/volume_builder.cu +2 -0
  172. warp/native/warp.cpp +60 -32
  173. warp/native/warp.cu +313 -201
  174. warp/native/warp.h +14 -11
  175. warp/optim/__init__.py +6 -3
  176. warp/optim/adam.py +6 -145
  177. warp/optim/linear.py +14 -1585
  178. warp/optim/sgd.py +6 -94
  179. warp/paddle.py +6 -388
  180. warp/render/__init__.py +8 -4
  181. warp/render/imgui_manager.py +7 -267
  182. warp/render/render_opengl.py +6 -3616
  183. warp/render/render_usd.py +6 -918
  184. warp/render/utils.py +6 -142
  185. warp/sparse.py +37 -2563
  186. warp/tape.py +6 -1188
  187. warp/tests/__main__.py +1 -1
  188. warp/tests/cuda/test_async.py +4 -4
  189. warp/tests/cuda/test_conditional_captures.py +1 -1
  190. warp/tests/cuda/test_multigpu.py +1 -1
  191. warp/tests/cuda/test_streams.py +58 -1
  192. warp/tests/geometry/test_bvh.py +157 -22
  193. warp/tests/geometry/test_hash_grid.py +38 -0
  194. warp/tests/geometry/test_marching_cubes.py +0 -1
  195. warp/tests/geometry/test_mesh.py +5 -3
  196. warp/tests/geometry/test_mesh_query_aabb.py +5 -12
  197. warp/tests/geometry/test_mesh_query_point.py +5 -2
  198. warp/tests/geometry/test_mesh_query_ray.py +15 -3
  199. warp/tests/geometry/test_volume_write.py +5 -5
  200. warp/tests/interop/test_dlpack.py +14 -14
  201. warp/tests/interop/test_jax.py +1382 -79
  202. warp/tests/interop/test_paddle.py +1 -1
  203. warp/tests/test_adam.py +0 -1
  204. warp/tests/test_arithmetic.py +9 -9
  205. warp/tests/test_array.py +529 -100
  206. warp/tests/test_array_reduce.py +3 -3
  207. warp/tests/test_atomic.py +12 -8
  208. warp/tests/test_atomic_bitwise.py +209 -0
  209. warp/tests/test_atomic_cas.py +4 -4
  210. warp/tests/test_bool.py +2 -2
  211. warp/tests/test_builtins_resolution.py +5 -571
  212. warp/tests/test_codegen.py +34 -15
  213. warp/tests/test_conditional.py +1 -1
  214. warp/tests/test_context.py +6 -6
  215. warp/tests/test_copy.py +242 -161
  216. warp/tests/test_ctypes.py +3 -3
  217. warp/tests/test_devices.py +24 -2
  218. warp/tests/test_examples.py +16 -84
  219. warp/tests/test_fabricarray.py +35 -35
  220. warp/tests/test_fast_math.py +0 -2
  221. warp/tests/test_fem.py +60 -14
  222. warp/tests/test_fixedarray.py +3 -3
  223. warp/tests/test_func.py +8 -5
  224. warp/tests/test_generics.py +1 -1
  225. warp/tests/test_indexedarray.py +24 -24
  226. warp/tests/test_intersect.py +39 -9
  227. warp/tests/test_large.py +1 -1
  228. warp/tests/test_lerp.py +3 -1
  229. warp/tests/test_linear_solvers.py +1 -1
  230. warp/tests/test_map.py +49 -4
  231. warp/tests/test_mat.py +52 -62
  232. warp/tests/test_mat_constructors.py +4 -5
  233. warp/tests/test_mat_lite.py +1 -1
  234. warp/tests/test_mat_scalar_ops.py +121 -121
  235. warp/tests/test_math.py +34 -0
  236. warp/tests/test_module_aot.py +4 -4
  237. warp/tests/test_modules_lite.py +28 -2
  238. warp/tests/test_print.py +11 -11
  239. warp/tests/test_quat.py +93 -58
  240. warp/tests/test_runlength_encode.py +1 -1
  241. warp/tests/test_scalar_ops.py +38 -10
  242. warp/tests/test_smoothstep.py +1 -1
  243. warp/tests/test_sparse.py +126 -15
  244. warp/tests/test_spatial.py +105 -87
  245. warp/tests/test_special_values.py +6 -6
  246. warp/tests/test_static.py +7 -7
  247. warp/tests/test_struct.py +13 -2
  248. warp/tests/test_triangle_closest_point.py +48 -1
  249. warp/tests/test_tuple.py +96 -0
  250. warp/tests/test_types.py +82 -9
  251. warp/tests/test_utils.py +52 -52
  252. warp/tests/test_vec.py +29 -29
  253. warp/tests/test_vec_constructors.py +5 -5
  254. warp/tests/test_vec_scalar_ops.py +97 -97
  255. warp/tests/test_version.py +75 -0
  256. warp/tests/tile/test_tile.py +239 -0
  257. warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
  258. warp/tests/tile/test_tile_cholesky.py +7 -4
  259. warp/tests/tile/test_tile_load.py +26 -2
  260. warp/tests/tile/test_tile_mathdx.py +3 -3
  261. warp/tests/tile/test_tile_matmul.py +1 -1
  262. warp/tests/tile/test_tile_mlp.py +2 -4
  263. warp/tests/tile/test_tile_reduce.py +214 -13
  264. warp/tests/unittest_suites.py +6 -14
  265. warp/tests/unittest_utils.py +10 -9
  266. warp/tests/walkthrough_debug.py +3 -1
  267. warp/torch.py +6 -373
  268. warp/types.py +29 -5750
  269. warp/utils.py +10 -1659
  270. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0rc2.dist-info}/METADATA +47 -103
  271. warp_lang-1.10.0rc2.dist-info/RECORD +468 -0
  272. warp_lang-1.10.0rc2.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
  273. warp_lang-1.10.0rc2.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
  274. warp_lang-1.10.0rc2.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
  275. warp_lang-1.10.0rc2.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
  276. warp_lang-1.10.0rc2.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
  277. warp_lang-1.10.0rc2.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
  278. warp_lang-1.10.0rc2.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
  279. warp_lang-1.10.0rc2.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
  280. warp_lang-1.10.0rc2.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
  281. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
  282. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
  283. warp_lang-1.10.0rc2.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
  284. warp_lang-1.10.0rc2.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
  285. warp_lang-1.10.0rc2.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
  286. warp_lang-1.10.0rc2.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
  287. warp/examples/assets/cartpole.urdf +0 -110
  288. warp/examples/assets/crazyflie.usd +0 -0
  289. warp/examples/assets/nv_ant.xml +0 -92
  290. warp/examples/assets/nv_humanoid.xml +0 -183
  291. warp/examples/assets/quadruped.urdf +0 -268
  292. warp/examples/optim/example_bounce.py +0 -266
  293. warp/examples/optim/example_cloth_throw.py +0 -228
  294. warp/examples/optim/example_drone.py +0 -870
  295. warp/examples/optim/example_inverse_kinematics.py +0 -182
  296. warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
  297. warp/examples/optim/example_softbody_properties.py +0 -400
  298. warp/examples/optim/example_spring_cage.py +0 -245
  299. warp/examples/optim/example_trajectory.py +0 -227
  300. warp/examples/sim/example_cartpole.py +0 -143
  301. warp/examples/sim/example_cloth.py +0 -225
  302. warp/examples/sim/example_cloth_self_contact.py +0 -316
  303. warp/examples/sim/example_granular.py +0 -130
  304. warp/examples/sim/example_granular_collision_sdf.py +0 -202
  305. warp/examples/sim/example_jacobian_ik.py +0 -244
  306. warp/examples/sim/example_particle_chain.py +0 -124
  307. warp/examples/sim/example_quadruped.py +0 -203
  308. warp/examples/sim/example_rigid_chain.py +0 -203
  309. warp/examples/sim/example_rigid_contact.py +0 -195
  310. warp/examples/sim/example_rigid_force.py +0 -133
  311. warp/examples/sim/example_rigid_gyroscopic.py +0 -115
  312. warp/examples/sim/example_rigid_soft_contact.py +0 -140
  313. warp/examples/sim/example_soft_body.py +0 -196
  314. warp/examples/tile/example_tile_walker.py +0 -327
  315. warp/sim/__init__.py +0 -74
  316. warp/sim/articulation.py +0 -793
  317. warp/sim/collide.py +0 -2570
  318. warp/sim/graph_coloring.py +0 -307
  319. warp/sim/import_mjcf.py +0 -791
  320. warp/sim/import_snu.py +0 -227
  321. warp/sim/import_urdf.py +0 -579
  322. warp/sim/import_usd.py +0 -898
  323. warp/sim/inertia.py +0 -357
  324. warp/sim/integrator.py +0 -245
  325. warp/sim/integrator_euler.py +0 -2000
  326. warp/sim/integrator_featherstone.py +0 -2101
  327. warp/sim/integrator_vbd.py +0 -2487
  328. warp/sim/integrator_xpbd.py +0 -3295
  329. warp/sim/model.py +0 -4821
  330. warp/sim/particles.py +0 -121
  331. warp/sim/render.py +0 -431
  332. warp/sim/utils.py +0 -431
  333. warp/tests/sim/disabled_kinematics.py +0 -244
  334. warp/tests/sim/test_cloth.py +0 -863
  335. warp/tests/sim/test_collision.py +0 -743
  336. warp/tests/sim/test_coloring.py +0 -347
  337. warp/tests/sim/test_inertia.py +0 -161
  338. warp/tests/sim/test_model.py +0 -226
  339. warp/tests/sim/test_sim_grad.py +0 -287
  340. warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
  341. warp/tests/sim/test_sim_kinematics.py +0 -98
  342. warp/thirdparty/__init__.py +0 -0
  343. warp_lang-1.9.0.dist-info/RECORD +0 -456
  344. /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
  345. /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
  346. /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
  347. /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
  348. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0rc2.dist-info}/WHEEL +0 -0
  349. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0rc2.dist-info}/licenses/LICENSE.md +0 -0
  350. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0rc2.dist-info}/top_level.txt +0 -0
warp/sim/inertia.py DELETED
@@ -1,357 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
- # SPDX-License-Identifier: Apache-2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- """Helper functions for computing rigid body inertia properties."""
17
-
18
- from __future__ import annotations
19
-
20
- import numpy as np
21
-
22
- import warp as wp
23
-
24
-
25
- def compute_sphere_inertia(density: float, r: float) -> tuple[float, wp.vec3, wp.mat33]:
26
- """Helper to compute mass and inertia of a solid sphere
27
-
28
- Args:
29
- density: The sphere density
30
- r: The sphere radius
31
-
32
- Returns:
33
-
34
- A tuple of (mass, inertia) with inertia specified around the origin
35
- """
36
-
37
- v = 4.0 / 3.0 * wp.pi * r * r * r
38
-
39
- m = density * v
40
- Ia = 2.0 / 5.0 * m * r * r
41
-
42
- I = wp.mat33([[Ia, 0.0, 0.0], [0.0, Ia, 0.0], [0.0, 0.0, Ia]])
43
-
44
- return (m, wp.vec3(), I)
45
-
46
-
47
- def compute_capsule_inertia(density: float, r: float, h: float) -> tuple[float, wp.vec3, wp.mat33]:
48
- """Helper to compute mass and inertia of a solid capsule extending along the y-axis
49
-
50
- Args:
51
- density: The capsule density
52
- r: The capsule radius
53
- h: The capsule height (full height of the interior cylinder)
54
-
55
- Returns:
56
-
57
- A tuple of (mass, inertia) with inertia specified around the origin
58
- """
59
-
60
- ms = density * (4.0 / 3.0) * wp.pi * r * r * r
61
- mc = density * wp.pi * r * r * h
62
-
63
- # total mass
64
- m = ms + mc
65
-
66
- # adapted from ODE
67
- Ia = mc * (0.25 * r * r + (1.0 / 12.0) * h * h) + ms * (0.4 * r * r + 0.375 * r * h + 0.25 * h * h)
68
- Ib = (mc * 0.5 + ms * 0.4) * r * r
69
-
70
- I = wp.mat33([[Ia, 0.0, 0.0], [0.0, Ib, 0.0], [0.0, 0.0, Ia]])
71
-
72
- return (m, wp.vec3(), I)
73
-
74
-
75
- def compute_cylinder_inertia(density: float, r: float, h: float) -> tuple[float, wp.vec3, wp.mat33]:
76
- """Helper to compute mass and inertia of a solid cylinder extending along the y-axis
77
-
78
- Args:
79
- density: The cylinder density
80
- r: The cylinder radius
81
- h: The cylinder height (extent along the y-axis)
82
-
83
- Returns:
84
-
85
- A tuple of (mass, inertia) with inertia specified around the origin
86
- """
87
-
88
- m = density * wp.pi * r * r * h
89
-
90
- Ia = 1 / 12 * m * (3 * r * r + h * h)
91
- Ib = 1 / 2 * m * r * r
92
-
93
- I = wp.mat33([[Ia, 0.0, 0.0], [0.0, Ib, 0.0], [0.0, 0.0, Ia]])
94
-
95
- return (m, wp.vec3(), I)
96
-
97
-
98
- def compute_cone_inertia(density: float, r: float, h: float) -> tuple[float, wp.vec3, wp.mat33]:
99
- """Helper to compute mass and inertia of a solid cone extending along the y-axis
100
-
101
- Args:
102
- density: The cone density
103
- r: The cone radius
104
- h: The cone height (extent along the y-axis)
105
-
106
- Returns:
107
-
108
- A tuple of (mass, inertia) with inertia specified around the origin
109
- """
110
-
111
- m = density * wp.pi * r * r * h / 3.0
112
-
113
- Ia = 1 / 20 * m * (3 * r * r + 2 * h * h)
114
- Ib = 3 / 10 * m * r * r
115
-
116
- I = wp.mat33([[Ia, 0.0, 0.0], [0.0, Ib, 0.0], [0.0, 0.0, Ia]])
117
-
118
- return (m, wp.vec3(), I)
119
-
120
-
121
- def compute_box_inertia(density: float, w: float, h: float, d: float) -> tuple[float, wp.vec3, wp.mat33]:
122
- """Helper to compute mass and inertia of a solid box
123
-
124
- Args:
125
- density: The box density
126
- w: The box width along the x-axis
127
- h: The box height along the y-axis
128
- d: The box depth along the z-axis
129
-
130
- Returns:
131
-
132
- A tuple of (mass, inertia) with inertia specified around the origin
133
- """
134
-
135
- v = w * h * d
136
- m = density * v
137
-
138
- Ia = 1.0 / 12.0 * m * (h * h + d * d)
139
- Ib = 1.0 / 12.0 * m * (w * w + d * d)
140
- Ic = 1.0 / 12.0 * m * (w * w + h * h)
141
-
142
- I = wp.mat33([[Ia, 0.0, 0.0], [0.0, Ib, 0.0], [0.0, 0.0, Ic]])
143
-
144
- return (m, wp.vec3(), I)
145
-
146
-
147
- @wp.func
148
- def triangle_inertia(
149
- v0: wp.vec3,
150
- v1: wp.vec3,
151
- v2: wp.vec3,
152
- ):
153
- vol = wp.dot(v0, wp.cross(v1, v2)) / 6.0 # tetra volume (0,v0,v1,v2)
154
- first = vol * (v0 + v1 + v2) / 4.0 # first-order integral
155
-
156
- # second-order integral (symmetric)
157
- o00, o11, o22 = wp.outer(v0, v0), wp.outer(v1, v1), wp.outer(v2, v2)
158
- o01, o02, o12 = wp.outer(v0, v1), wp.outer(v0, v2), wp.outer(v1, v2)
159
- o01t, o02t, o12t = wp.transpose(o01), wp.transpose(o02), wp.transpose(o12)
160
-
161
- second = (vol / 10.0) * (o00 + o11 + o22)
162
- second += (vol / 20.0) * (o01 + o01t + o02 + o02t + o12 + o12t)
163
-
164
- return vol, first, second
165
-
166
-
167
- @wp.kernel
168
- def compute_solid_mesh_inertia(
169
- indices: wp.array(dtype=int),
170
- vertices: wp.array(dtype=wp.vec3),
171
- # outputs
172
- volume: wp.array(dtype=float),
173
- first: wp.array(dtype=wp.vec3),
174
- second: wp.array(dtype=wp.mat33),
175
- ):
176
- i = wp.tid()
177
- p = vertices[indices[i * 3 + 0]]
178
- q = vertices[indices[i * 3 + 1]]
179
- r = vertices[indices[i * 3 + 2]]
180
-
181
- v, f, s = triangle_inertia(p, q, r)
182
- wp.atomic_add(volume, 0, v)
183
- wp.atomic_add(first, 0, f)
184
- wp.atomic_add(second, 0, s)
185
-
186
-
187
- @wp.kernel
188
- def compute_hollow_mesh_inertia(
189
- indices: wp.array(dtype=int),
190
- vertices: wp.array(dtype=wp.vec3),
191
- thickness: wp.array(dtype=float),
192
- # outputs
193
- volume: wp.array(dtype=float),
194
- first: wp.array(dtype=wp.vec3),
195
- second: wp.array(dtype=wp.mat33),
196
- ):
197
- tid = wp.tid()
198
- i = indices[tid * 3 + 0]
199
- j = indices[tid * 3 + 1]
200
- k = indices[tid * 3 + 2]
201
-
202
- vi = vertices[i]
203
- vj = vertices[j]
204
- vk = vertices[k]
205
-
206
- normal = -wp.normalize(wp.cross(vj - vi, vk - vi))
207
- ti = normal * thickness[i]
208
- tj = normal * thickness[j]
209
- tk = normal * thickness[k]
210
-
211
- # wedge vertices
212
- vi0 = vi - ti
213
- vi1 = vi + ti
214
- vj0 = vj - tj
215
- vj1 = vj + tj
216
- vk0 = vk - tk
217
- vk1 = vk + tk
218
-
219
- v_total = 0.0
220
- f_total = wp.vec3(0.0)
221
- s_total = wp.mat33(0.0)
222
-
223
- v, f, s = triangle_inertia(vi0, vj0, vk0)
224
- v_total += v
225
- f_total += f
226
- s_total += s
227
- v, f, s = triangle_inertia(vj0, vk1, vk0)
228
- v_total += v
229
- f_total += f
230
- s_total += s
231
- v, f, s = triangle_inertia(vj0, vj1, vk1)
232
- v_total += v
233
- f_total += f
234
- s_total += s
235
- v, f, s = triangle_inertia(vj0, vi1, vj1)
236
- v_total += v
237
- f_total += f
238
- s_total += s
239
- v, f, s = triangle_inertia(vj0, vi0, vi1)
240
- v_total += v
241
- f_total += f
242
- s_total += s
243
- v, f, s = triangle_inertia(vj1, vi1, vk1)
244
- v_total += v
245
- f_total += f
246
- s_total += s
247
- v, f, s = triangle_inertia(vi1, vi0, vk0)
248
- v_total += v
249
- f_total += f
250
- s_total += s
251
- v, f, s = triangle_inertia(vi1, vk0, vk1)
252
- v_total += v
253
- f_total += f
254
- s_total += s
255
-
256
- wp.atomic_add(volume, 0, v_total)
257
- wp.atomic_add(first, 0, f_total)
258
- wp.atomic_add(second, 0, s_total)
259
-
260
-
261
- def compute_mesh_inertia(
262
- density: float,
263
- vertices: list,
264
- indices: list,
265
- is_solid: bool = True,
266
- thickness: list[float] | float = 0.001,
267
- ) -> tuple[float, wp.vec3, wp.mat33, float]:
268
- """
269
- Compute the mass, center of mass, inertia, and volume of a triangular mesh.
270
-
271
- Args:
272
- density: The density of the mesh material.
273
- vertices: A list of vertex positions (3D coordinates).
274
- indices: A list of triangle indices (each triangle is defined by 3 vertex indices).
275
- is_solid: If True, compute inertia for a solid mesh; if False, for a hollow mesh using the given thickness.
276
- thickness: Thickness of the mesh if it is hollow. Can be a single value or a list of values for each vertex.
277
-
278
- Returns:
279
- A tuple containing:
280
- - mass: The mass of the mesh.
281
- - com: The center of mass (3D coordinates).
282
- - I: The inertia tensor (3x3 matrix).
283
- - volume: The signed volume of the mesh.
284
- """
285
-
286
- indices = np.array(indices).flatten()
287
- num_tris = len(indices) // 3
288
-
289
- # Allocating for mass and inertia
290
- com_warp = wp.zeros(1, dtype=wp.vec3)
291
- I_warp = wp.zeros(1, dtype=wp.mat33)
292
- vol_warp = wp.zeros(1, dtype=float)
293
-
294
- wp_vertices = wp.array(vertices, dtype=wp.vec3)
295
- wp_indices = wp.array(indices, dtype=int)
296
-
297
- if is_solid:
298
- wp.launch(
299
- kernel=compute_solid_mesh_inertia,
300
- dim=num_tris,
301
- inputs=[
302
- wp_indices,
303
- wp_vertices,
304
- ],
305
- outputs=[
306
- vol_warp,
307
- com_warp,
308
- I_warp,
309
- ],
310
- )
311
- else:
312
- if isinstance(thickness, float):
313
- thickness = [thickness] * len(vertices)
314
- wp.launch(
315
- kernel=compute_hollow_mesh_inertia,
316
- dim=num_tris,
317
- inputs=[
318
- wp_indices,
319
- wp_vertices,
320
- wp.array(thickness, dtype=float),
321
- ],
322
- outputs=[
323
- vol_warp,
324
- com_warp,
325
- I_warp,
326
- ],
327
- )
328
-
329
- V_tot = float(vol_warp.numpy()[0]) # signed volume
330
- F_tot = com_warp.numpy()[0] # first moment
331
- S_tot = I_warp.numpy()[0] # second moment
332
-
333
- # If the winding is inward, flip signs
334
- if V_tot < 0:
335
- V_tot = -V_tot
336
- F_tot = -F_tot
337
- S_tot = -S_tot
338
-
339
- mass = density * V_tot
340
- if V_tot > 0.0:
341
- com = F_tot / V_tot
342
- else:
343
- com = F_tot
344
-
345
- S_tot *= density # include density
346
- I_origin = np.trace(S_tot) * np.eye(3) - S_tot # inertia about origin
347
- r = com
348
- I_com = I_origin - mass * ((r @ r) * np.eye(3) - np.outer(r, r))
349
-
350
- return mass, wp.vec3(*com), wp.mat33(*I_com), V_tot
351
-
352
-
353
- def transform_inertia(m, I, p, q) -> wp.mat33:
354
- R = wp.quat_to_matrix(q)
355
-
356
- # Steiner's theorem
357
- return R @ I @ wp.transpose(R) + m * (wp.dot(p, p) * wp.mat33(np.eye(3)) - wp.outer(p, p))
warp/sim/integrator.py DELETED
@@ -1,245 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
- # SPDX-License-Identifier: Apache-2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- import warp as wp
17
-
18
- from .model import PARTICLE_FLAG_ACTIVE, Control, Model, State
19
-
20
-
21
- @wp.kernel
22
- def integrate_particles(
23
- x: wp.array(dtype=wp.vec3),
24
- v: wp.array(dtype=wp.vec3),
25
- f: wp.array(dtype=wp.vec3),
26
- w: wp.array(dtype=float),
27
- particle_flags: wp.array(dtype=wp.uint32),
28
- gravity: wp.vec3,
29
- dt: float,
30
- v_max: float,
31
- x_new: wp.array(dtype=wp.vec3),
32
- v_new: wp.array(dtype=wp.vec3),
33
- ):
34
- tid = wp.tid()
35
- x0 = x[tid]
36
- v0 = v[tid]
37
-
38
- if (particle_flags[tid] & PARTICLE_FLAG_ACTIVE) == 0:
39
- x_new[tid] = x0
40
- v_new[tid] = wp.vec3(0.0)
41
- return
42
-
43
- f0 = f[tid]
44
-
45
- inv_mass = w[tid]
46
-
47
- # simple semi-implicit Euler. v1 = v0 + a dt, x1 = x0 + v1 dt
48
- v1 = v0 + (f0 * inv_mass + gravity * wp.step(-inv_mass)) * dt
49
- # enforce velocity limit to prevent instability
50
- v1_mag = wp.length(v1)
51
- if v1_mag > v_max:
52
- v1 *= v_max / v1_mag
53
- x1 = x0 + v1 * dt
54
-
55
- x_new[tid] = x1
56
- v_new[tid] = v1
57
-
58
-
59
- @wp.func
60
- def integrate_rigid_body(
61
- q: wp.transform,
62
- qd: wp.spatial_vector,
63
- f: wp.spatial_vector,
64
- com: wp.vec3,
65
- inertia: wp.mat33,
66
- inv_mass: float,
67
- inv_inertia: wp.mat33,
68
- gravity: wp.vec3,
69
- angular_damping: float,
70
- dt: float,
71
- ):
72
- # unpack transform
73
- x0 = wp.transform_get_translation(q)
74
- r0 = wp.transform_get_rotation(q)
75
-
76
- # unpack spatial twist
77
- w0 = wp.spatial_top(qd)
78
- v0 = wp.spatial_bottom(qd)
79
-
80
- # unpack spatial wrench
81
- t0 = wp.spatial_top(f)
82
- f0 = wp.spatial_bottom(f)
83
-
84
- x_com = x0 + wp.quat_rotate(r0, com)
85
-
86
- # linear part
87
- v1 = v0 + (f0 * inv_mass + gravity * wp.nonzero(inv_mass)) * dt
88
- x1 = x_com + v1 * dt
89
-
90
- # angular part (compute in body frame)
91
- wb = wp.quat_rotate_inv(r0, w0)
92
- tb = wp.quat_rotate_inv(r0, t0) - wp.cross(wb, inertia * wb) # coriolis forces
93
-
94
- w1 = wp.quat_rotate(r0, wb + inv_inertia * tb * dt)
95
- r1 = wp.normalize(r0 + wp.quat(w1, 0.0) * r0 * 0.5 * dt)
96
-
97
- # angular damping
98
- w1 *= 1.0 - angular_damping * dt
99
-
100
- q_new = wp.transform(x1 - wp.quat_rotate(r1, com), r1)
101
- qd_new = wp.spatial_vector(w1, v1)
102
-
103
- return q_new, qd_new
104
-
105
-
106
- # semi-implicit Euler integration
107
- @wp.kernel
108
- def integrate_bodies(
109
- body_q: wp.array(dtype=wp.transform),
110
- body_qd: wp.array(dtype=wp.spatial_vector),
111
- body_f: wp.array(dtype=wp.spatial_vector),
112
- body_com: wp.array(dtype=wp.vec3),
113
- m: wp.array(dtype=float),
114
- I: wp.array(dtype=wp.mat33),
115
- inv_m: wp.array(dtype=float),
116
- inv_I: wp.array(dtype=wp.mat33),
117
- gravity: wp.vec3,
118
- angular_damping: float,
119
- dt: float,
120
- # outputs
121
- body_q_new: wp.array(dtype=wp.transform),
122
- body_qd_new: wp.array(dtype=wp.spatial_vector),
123
- ):
124
- tid = wp.tid()
125
-
126
- # positions
127
- q = body_q[tid]
128
- qd = body_qd[tid]
129
- f = body_f[tid]
130
-
131
- # masses
132
- inv_mass = inv_m[tid] # 1 / mass
133
-
134
- inertia = I[tid]
135
- inv_inertia = inv_I[tid] # inverse of 3x3 inertia matrix
136
-
137
- com = body_com[tid]
138
-
139
- q_new, qd_new = integrate_rigid_body(
140
- q,
141
- qd,
142
- f,
143
- com,
144
- inertia,
145
- inv_mass,
146
- inv_inertia,
147
- gravity,
148
- angular_damping,
149
- dt,
150
- )
151
-
152
- body_q_new[tid] = q_new
153
- body_qd_new[tid] = qd_new
154
-
155
-
156
- class Integrator:
157
- """
158
- Generic base class for integrators. Provides methods to integrate rigid bodies and particles.
159
- """
160
-
161
- def integrate_bodies(
162
- self,
163
- model: Model,
164
- state_in: State,
165
- state_out: State,
166
- dt: float,
167
- angular_damping: float = 0.0,
168
- ):
169
- """
170
- Integrate the rigid bodies of the model.
171
-
172
- Args:
173
- model (Model): The model to integrate.
174
- state_in (State): The input state.
175
- state_out (State): The output state.
176
- dt (float): The time step (typically in seconds).
177
- angular_damping (float, optional): The angular damping factor. Defaults to 0.0.
178
- """
179
- if model.body_count:
180
- wp.launch(
181
- kernel=integrate_bodies,
182
- dim=model.body_count,
183
- inputs=[
184
- state_in.body_q,
185
- state_in.body_qd,
186
- state_in.body_f,
187
- model.body_com,
188
- model.body_mass,
189
- model.body_inertia,
190
- model.body_inv_mass,
191
- model.body_inv_inertia,
192
- model.gravity,
193
- angular_damping,
194
- dt,
195
- ],
196
- outputs=[state_out.body_q, state_out.body_qd],
197
- device=model.device,
198
- )
199
-
200
- def integrate_particles(
201
- self,
202
- model: Model,
203
- state_in: State,
204
- state_out: State,
205
- dt: float,
206
- ):
207
- """
208
- Integrate the particles of the model.
209
-
210
- Args:
211
- model (Model): The model to integrate.
212
- state_in (State): The input state.
213
- state_out (State): The output state.
214
- dt (float): The time step (typically in seconds).
215
- """
216
- if model.particle_count:
217
- wp.launch(
218
- kernel=integrate_particles,
219
- dim=model.particle_count,
220
- inputs=[
221
- state_in.particle_q,
222
- state_in.particle_qd,
223
- state_in.particle_f,
224
- model.particle_inv_mass,
225
- model.particle_flags,
226
- model.gravity,
227
- dt,
228
- model.particle_max_velocity,
229
- ],
230
- outputs=[state_out.particle_q, state_out.particle_qd],
231
- device=model.device,
232
- )
233
-
234
- def simulate(self, model: Model, state_in: State, state_out: State, dt: float, control: Control = None):
235
- """
236
- Simulate the model for a given time step using the given control input.
237
-
238
- Args:
239
- model (Model): The model to simulate.
240
- state_in (State): The input state.
241
- state_out (State): The output state.
242
- dt (float): The time step (typically in seconds).
243
- control (Control): The control input. Defaults to `None` which means the control values from the :class:`Model` are used.
244
- """
245
- raise NotImplementedError()