warp-lang 1.1.0__py3-none-win_amd64.whl → 1.2.1__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 (218) hide show
  1. warp/bin/warp-clang.dll +0 -0
  2. warp/bin/warp.dll +0 -0
  3. warp/build.py +10 -37
  4. warp/build_dll.py +2 -2
  5. warp/builtins.py +274 -6
  6. warp/codegen.py +51 -4
  7. warp/config.py +2 -2
  8. warp/constants.py +4 -0
  9. warp/context.py +422 -203
  10. warp/examples/benchmarks/benchmark_api.py +0 -2
  11. warp/examples/benchmarks/benchmark_cloth_warp.py +0 -1
  12. warp/examples/benchmarks/benchmark_launches.py +0 -2
  13. warp/examples/core/example_dem.py +0 -2
  14. warp/examples/core/example_fluid.py +0 -2
  15. warp/examples/core/example_graph_capture.py +0 -2
  16. warp/examples/core/example_marching_cubes.py +0 -2
  17. warp/examples/core/example_mesh.py +0 -2
  18. warp/examples/core/example_mesh_intersect.py +0 -2
  19. warp/examples/core/example_nvdb.py +0 -2
  20. warp/examples/core/example_raycast.py +0 -2
  21. warp/examples/core/example_raymarch.py +0 -2
  22. warp/examples/core/example_render_opengl.py +0 -2
  23. warp/examples/core/example_sph.py +0 -2
  24. warp/examples/core/example_torch.py +0 -3
  25. warp/examples/core/example_wave.py +0 -2
  26. warp/examples/fem/example_apic_fluid.py +140 -115
  27. warp/examples/fem/example_burgers.py +262 -0
  28. warp/examples/fem/example_convection_diffusion.py +0 -2
  29. warp/examples/fem/example_convection_diffusion_dg.py +0 -2
  30. warp/examples/fem/example_deformed_geometry.py +0 -2
  31. warp/examples/fem/example_diffusion.py +0 -2
  32. warp/examples/fem/example_diffusion_3d.py +5 -4
  33. warp/examples/fem/example_diffusion_mgpu.py +0 -2
  34. warp/examples/fem/example_mixed_elasticity.py +0 -2
  35. warp/examples/fem/example_navier_stokes.py +0 -2
  36. warp/examples/fem/example_stokes.py +0 -2
  37. warp/examples/fem/example_stokes_transfer.py +0 -2
  38. warp/examples/optim/example_bounce.py +0 -2
  39. warp/examples/optim/example_cloth_throw.py +0 -2
  40. warp/examples/optim/example_diffray.py +0 -2
  41. warp/examples/optim/example_drone.py +0 -2
  42. warp/examples/optim/example_inverse_kinematics.py +0 -2
  43. warp/examples/optim/example_inverse_kinematics_torch.py +0 -2
  44. warp/examples/optim/example_spring_cage.py +0 -2
  45. warp/examples/optim/example_trajectory.py +0 -2
  46. warp/examples/optim/example_walker.py +0 -2
  47. warp/examples/sim/example_cartpole.py +0 -2
  48. warp/examples/sim/example_cloth.py +0 -2
  49. warp/examples/sim/example_granular.py +0 -2
  50. warp/examples/sim/example_granular_collision_sdf.py +0 -2
  51. warp/examples/sim/example_jacobian_ik.py +0 -2
  52. warp/examples/sim/example_particle_chain.py +0 -2
  53. warp/examples/sim/example_quadruped.py +0 -2
  54. warp/examples/sim/example_rigid_chain.py +0 -2
  55. warp/examples/sim/example_rigid_contact.py +0 -2
  56. warp/examples/sim/example_rigid_force.py +0 -2
  57. warp/examples/sim/example_rigid_gyroscopic.py +0 -2
  58. warp/examples/sim/example_rigid_soft_contact.py +0 -2
  59. warp/examples/sim/example_soft_body.py +0 -2
  60. warp/fem/__init__.py +1 -0
  61. warp/fem/cache.py +3 -1
  62. warp/fem/geometry/__init__.py +1 -0
  63. warp/fem/geometry/element.py +4 -0
  64. warp/fem/geometry/grid_3d.py +0 -4
  65. warp/fem/geometry/nanogrid.py +455 -0
  66. warp/fem/integrate.py +63 -9
  67. warp/fem/space/__init__.py +43 -158
  68. warp/fem/space/basis_space.py +34 -0
  69. warp/fem/space/collocated_function_space.py +1 -1
  70. warp/fem/space/grid_2d_function_space.py +13 -132
  71. warp/fem/space/grid_3d_function_space.py +16 -154
  72. warp/fem/space/hexmesh_function_space.py +37 -134
  73. warp/fem/space/nanogrid_function_space.py +202 -0
  74. warp/fem/space/quadmesh_2d_function_space.py +12 -119
  75. warp/fem/space/restriction.py +4 -1
  76. warp/fem/space/shape/__init__.py +77 -0
  77. warp/fem/space/shape/cube_shape_function.py +5 -15
  78. warp/fem/space/tetmesh_function_space.py +6 -76
  79. warp/fem/space/trimesh_2d_function_space.py +6 -76
  80. warp/native/array.h +12 -3
  81. warp/native/builtin.h +48 -5
  82. warp/native/bvh.cpp +14 -10
  83. warp/native/bvh.cu +23 -15
  84. warp/native/bvh.h +1 -0
  85. warp/native/clang/clang.cpp +2 -1
  86. warp/native/crt.cpp +11 -1
  87. warp/native/crt.h +18 -1
  88. warp/native/exports.h +187 -0
  89. warp/native/mat.h +47 -0
  90. warp/native/mesh.cpp +1 -1
  91. warp/native/mesh.cu +1 -2
  92. warp/native/nanovdb/GridHandle.h +366 -0
  93. warp/native/nanovdb/HostBuffer.h +590 -0
  94. warp/native/nanovdb/NanoVDB.h +3999 -2157
  95. warp/native/nanovdb/PNanoVDB.h +936 -99
  96. warp/native/quat.h +28 -1
  97. warp/native/rand.h +5 -1
  98. warp/native/vec.h +45 -1
  99. warp/native/volume.cpp +335 -103
  100. warp/native/volume.cu +39 -13
  101. warp/native/volume.h +725 -303
  102. warp/native/volume_builder.cu +381 -360
  103. warp/native/volume_builder.h +16 -1
  104. warp/native/volume_impl.h +61 -0
  105. warp/native/warp.cu +8 -2
  106. warp/native/warp.h +15 -7
  107. warp/render/render_opengl.py +191 -52
  108. warp/sim/integrator_featherstone.py +10 -3
  109. warp/sim/integrator_xpbd.py +16 -22
  110. warp/sparse.py +89 -27
  111. warp/stubs.py +83 -0
  112. warp/tests/assets/test_index_grid.nvdb +0 -0
  113. warp/tests/aux_test_dependent.py +0 -2
  114. warp/tests/aux_test_grad_customs.py +0 -2
  115. warp/tests/aux_test_reference.py +0 -2
  116. warp/tests/aux_test_reference_reference.py +0 -2
  117. warp/tests/aux_test_square.py +0 -2
  118. warp/tests/disabled_kinematics.py +0 -2
  119. warp/tests/test_adam.py +0 -2
  120. warp/tests/test_arithmetic.py +0 -36
  121. warp/tests/test_array.py +9 -11
  122. warp/tests/test_array_reduce.py +0 -2
  123. warp/tests/test_async.py +0 -2
  124. warp/tests/test_atomic.py +0 -2
  125. warp/tests/test_bool.py +58 -50
  126. warp/tests/test_builtins_resolution.py +0 -2
  127. warp/tests/test_bvh.py +0 -2
  128. warp/tests/test_closest_point_edge_edge.py +0 -1
  129. warp/tests/test_codegen.py +0 -4
  130. warp/tests/test_compile_consts.py +130 -10
  131. warp/tests/test_conditional.py +0 -2
  132. warp/tests/test_copy.py +0 -2
  133. warp/tests/test_ctypes.py +6 -8
  134. warp/tests/test_dense.py +0 -2
  135. warp/tests/test_devices.py +0 -2
  136. warp/tests/test_dlpack.py +9 -11
  137. warp/tests/test_examples.py +42 -39
  138. warp/tests/test_fabricarray.py +0 -3
  139. warp/tests/test_fast_math.py +0 -2
  140. warp/tests/test_fem.py +75 -54
  141. warp/tests/test_fp16.py +0 -2
  142. warp/tests/test_func.py +0 -2
  143. warp/tests/test_generics.py +27 -2
  144. warp/tests/test_grad.py +147 -8
  145. warp/tests/test_grad_customs.py +0 -2
  146. warp/tests/test_hash_grid.py +1 -3
  147. warp/tests/test_import.py +0 -2
  148. warp/tests/test_indexedarray.py +0 -2
  149. warp/tests/test_intersect.py +0 -2
  150. warp/tests/test_jax.py +0 -2
  151. warp/tests/test_large.py +11 -9
  152. warp/tests/test_launch.py +0 -2
  153. warp/tests/test_lerp.py +10 -54
  154. warp/tests/test_linear_solvers.py +3 -5
  155. warp/tests/test_lvalue.py +0 -2
  156. warp/tests/test_marching_cubes.py +0 -2
  157. warp/tests/test_mat.py +0 -2
  158. warp/tests/test_mat_lite.py +0 -2
  159. warp/tests/test_mat_scalar_ops.py +0 -2
  160. warp/tests/test_math.py +0 -2
  161. warp/tests/test_matmul.py +35 -37
  162. warp/tests/test_matmul_lite.py +29 -31
  163. warp/tests/test_mempool.py +0 -2
  164. warp/tests/test_mesh.py +0 -3
  165. warp/tests/test_mesh_query_aabb.py +0 -2
  166. warp/tests/test_mesh_query_point.py +0 -2
  167. warp/tests/test_mesh_query_ray.py +0 -2
  168. warp/tests/test_mlp.py +0 -2
  169. warp/tests/test_model.py +0 -2
  170. warp/tests/test_module_hashing.py +111 -0
  171. warp/tests/test_modules_lite.py +0 -3
  172. warp/tests/test_multigpu.py +0 -2
  173. warp/tests/test_noise.py +0 -4
  174. warp/tests/test_operators.py +0 -2
  175. warp/tests/test_options.py +0 -2
  176. warp/tests/test_peer.py +0 -2
  177. warp/tests/test_pinned.py +0 -2
  178. warp/tests/test_print.py +0 -2
  179. warp/tests/test_quat.py +0 -2
  180. warp/tests/test_rand.py +41 -5
  181. warp/tests/test_reload.py +0 -10
  182. warp/tests/test_rounding.py +0 -2
  183. warp/tests/test_runlength_encode.py +0 -2
  184. warp/tests/test_sim_grad.py +0 -2
  185. warp/tests/test_sim_kinematics.py +0 -2
  186. warp/tests/test_smoothstep.py +0 -2
  187. warp/tests/test_snippet.py +0 -2
  188. warp/tests/test_sparse.py +0 -2
  189. warp/tests/test_spatial.py +0 -2
  190. warp/tests/test_special_values.py +362 -0
  191. warp/tests/test_streams.py +0 -2
  192. warp/tests/test_struct.py +0 -2
  193. warp/tests/test_tape.py +0 -2
  194. warp/tests/test_torch.py +0 -2
  195. warp/tests/test_transient_module.py +0 -2
  196. warp/tests/test_types.py +0 -2
  197. warp/tests/test_utils.py +0 -2
  198. warp/tests/test_vec.py +0 -2
  199. warp/tests/test_vec_lite.py +0 -2
  200. warp/tests/test_vec_scalar_ops.py +0 -2
  201. warp/tests/test_verify_fp.py +0 -2
  202. warp/tests/test_volume.py +237 -13
  203. warp/tests/test_volume_write.py +86 -3
  204. warp/tests/unittest_serial.py +10 -9
  205. warp/tests/unittest_suites.py +6 -2
  206. warp/tests/unittest_utils.py +2 -171
  207. warp/tests/unused_test_misc.py +0 -2
  208. warp/tests/walkthrough_debug.py +1 -1
  209. warp/thirdparty/unittest_parallel.py +37 -40
  210. warp/types.py +526 -85
  211. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/METADATA +61 -31
  212. warp_lang-1.2.1.dist-info/RECORD +359 -0
  213. warp/examples/fem/example_convection_diffusion_dg0.py +0 -204
  214. warp/native/nanovdb/PNanoVDBWrite.h +0 -295
  215. warp_lang-1.1.0.dist-info/RECORD +0 -352
  216. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/LICENSE.md +0 -0
  217. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/WHEEL +0 -0
  218. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,262 @@
1
+ # Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
2
+ # NVIDIA CORPORATION and its licensors retain all intellectual property
3
+ # and proprietary rights in and to this software, related documentation
4
+ # and any modifications thereto. Any use, reproduction, disclosure or
5
+ # distribution of this software and related documentation without an express
6
+ # license agreement from NVIDIA CORPORATION is strictly prohibited.
7
+
8
+ ###########################################################################
9
+ # Example Burgers
10
+ #
11
+ # This example simulates an inviscid non-conservative Burgers PDE using
12
+ # Discontinuous Galerkin with minmod slope limiter
13
+ #
14
+ # d u /dt + (u . grad) u = 0
15
+ #
16
+ ###########################################################################
17
+
18
+ import warp as wp
19
+ import warp.fem as fem
20
+ import warp.sparse as sp
21
+
22
+ # Import example utilities
23
+ # Make sure that works both when imported as module and run as standalone file
24
+ try:
25
+ from .bsr_utils import invert_diagonal_bsr_mass_matrix
26
+ from .plot_utils import Plot
27
+ except ImportError:
28
+ from bsr_utils import invert_diagonal_bsr_mass_matrix
29
+ from plot_utils import Plot
30
+
31
+
32
+ @fem.integrand
33
+ def vel_mass_form(
34
+ s: fem.Sample,
35
+ u: fem.Field,
36
+ v: fem.Field,
37
+ ):
38
+ return wp.dot(v(s), u(s))
39
+
40
+
41
+ @fem.integrand
42
+ def upwind_transport_form(s: fem.Sample, domain: fem.Domain, u: fem.Field, v: fem.Field, w: fem.Field):
43
+ # Upwinding transport with discontinuous convection velocity,
44
+ # using jump(w v) = jump(w) avg(v) + avg(w) jump(w)
45
+
46
+ nor = fem.normal(domain, s)
47
+ w_avg_n = wp.dot(fem.average(w, s), nor)
48
+ w_jump_n = wp.dot(fem.jump(w, s), nor)
49
+
50
+ x = domain(s)
51
+ v_avg = fem.average(v, s)
52
+ if x[0] <= 0.0 or x[0] >= 1.0: # out
53
+ # if x[0] >= 1.0: # out
54
+ v_jump = v(s)
55
+ else:
56
+ v_jump = fem.jump(v, s)
57
+
58
+ u_avg = fem.average(u, s)
59
+ u_jump = fem.jump(u, s)
60
+
61
+ return wp.dot(u_avg, v_jump * w_avg_n + v_avg * w_jump_n) + 0.5 * wp.dot(v_jump, u_jump) * (
62
+ wp.abs(w_avg_n) + 0.5 * wp.abs(w_jump_n)
63
+ )
64
+
65
+
66
+ @fem.integrand
67
+ def cell_transport_form(s: fem.Sample, domain: fem.Domain, u: fem.Field, v: fem.Field, w: fem.Field):
68
+ # ((w . grad) u) . v = v^T (grad u) w = grad(u) : (v w^T)
69
+ # with integration by parts
70
+ # u . Div (w v^T) = u^T grad(v) w + u^T v div (w)
71
+
72
+ return -wp.dot(fem.div(w, s) * v(s) + fem.grad(v, s) * w(s), u(s))
73
+
74
+
75
+ @fem.integrand
76
+ def initial_condition(s: fem.Sample, domain: fem.Domain):
77
+ x = domain(s)[0] * 2.0
78
+ wave = wp.sin(x * wp.pi)
79
+ return wp.vec2(wp.select(x <= 1.0, 0.0, wave), 0.0)
80
+
81
+
82
+ @fem.integrand
83
+ def velocity_norm(s: fem.Sample, u: fem.Field):
84
+ return wp.length(u(s))
85
+
86
+
87
+ @wp.func
88
+ def minmod(a: float, b: float):
89
+ sa = wp.sign(a)
90
+ sb = wp.sign(b)
91
+ return wp.select(sa == sb, 0.0, sa * wp.min(wp.abs(a), wp.abs(b)))
92
+
93
+
94
+ @fem.integrand
95
+ def slope_limiter(domain: fem.Domain, s: fem.Sample, u: fem.Field, dx: wp.vec2):
96
+ # Minmod slope limiter against P0 discretization (evaluation at cell centers)
97
+ # Assumes regular grid topology
98
+
99
+ center_coords = fem.Coords(0.5, 0.5, 0.0)
100
+ cell_center = fem.types.make_free_sample(s.element_index, center_coords)
101
+ center_pos = domain(cell_center)
102
+
103
+ u_center = u(cell_center)
104
+
105
+ delta_coords = s.element_coords - center_coords
106
+
107
+ neighbour_xp = fem.lookup(domain, center_pos + wp.vec2(dx[0], 0.0))
108
+ neighbour_yp = fem.lookup(domain, center_pos + wp.vec2(0.0, dx[1]))
109
+ neighbour_xm = fem.lookup(domain, center_pos - wp.vec2(dx[0], 0.0))
110
+ neighbour_ym = fem.lookup(domain, center_pos - wp.vec2(0.0, dx[1]))
111
+
112
+ u_nxp = u(neighbour_xp)
113
+ u_nyp = u(neighbour_yp)
114
+ u_nxm = u(neighbour_xm)
115
+ u_nym = u(neighbour_ym)
116
+
117
+ gx = minmod(u_nxp[0] - u_center[0], u_center[0] - u_nxm[0]) * delta_coords[0]
118
+ gy = minmod(u_nyp[1] - u_center[1], u_center[1] - u_nym[1]) * delta_coords[1]
119
+
120
+ delta_u = u(s) - u_center
121
+ return u_center + wp.vec2(minmod(gx, delta_u[0]), minmod(gy, delta_u[1]))
122
+
123
+
124
+ class Example:
125
+ def __init__(self, quiet=False, resolution=50, degree=1):
126
+ self._quiet = quiet
127
+
128
+ res = resolution
129
+ self.sim_dt = 1.0 / res
130
+ self.current_frame = 0
131
+
132
+ geo = fem.Grid2D(res=wp.vec2i(resolution))
133
+
134
+ domain = fem.Cells(geometry=geo)
135
+ sides = fem.Sides(geo)
136
+
137
+ basis_space = fem.make_polynomial_basis_space(geo, degree=degree, discontinuous=True)
138
+ vector_space = fem.make_collocated_function_space(basis_space, dtype=wp.vec2)
139
+ scalar_space = fem.make_collocated_function_space(basis_space, dtype=float)
140
+
141
+ # Test function for ou vector space
142
+ self._test = fem.make_test(space=vector_space, domain=domain)
143
+ # Test function for integration on sides
144
+ self._side_test = fem.make_test(space=vector_space, domain=sides)
145
+
146
+ # Inertia matrix
147
+ # For simplicity, use nodal integration so that inertia matrix is diagonal
148
+ trial = fem.make_trial(space=vector_space, domain=domain)
149
+ matrix_inertia = fem.integrate(
150
+ vel_mass_form, fields={"u": trial, "v": self._test}, output_dtype=wp.float32, nodal=True
151
+ )
152
+ self._inv_mass_matrix = sp.bsr_copy(matrix_inertia)
153
+ invert_diagonal_bsr_mass_matrix(self._inv_mass_matrix)
154
+
155
+ # Initial condition
156
+ self.velocity_field = vector_space.make_field()
157
+ fem.interpolate(initial_condition, dest=self.velocity_field)
158
+
159
+ # Velocity nor field -- for visualization purposes
160
+ self.velocity_norm_field = scalar_space.make_field()
161
+ fem.interpolate(velocity_norm, dest=self.velocity_norm_field, fields={"u": self.velocity_field})
162
+
163
+ self.renderer = Plot()
164
+ self.renderer.add_surface("u_norm", self.velocity_norm_field)
165
+
166
+ def _velocity_delta(self, trial_velocity):
167
+ # Integration on sides
168
+ rhs = fem.integrate(
169
+ upwind_transport_form,
170
+ fields={"u": trial_velocity.trace(), "v": self._side_test, "w": trial_velocity.trace()},
171
+ output_dtype=wp.vec2,
172
+ )
173
+
174
+ if self.velocity_field.space.degree > 0:
175
+ # Integration on cells (if not piecewise-constant)
176
+ fem.utils.array_axpy(
177
+ x=fem.integrate(
178
+ cell_transport_form,
179
+ fields={"u": trial_velocity, "v": self._test, "w": trial_velocity},
180
+ output_dtype=wp.vec2,
181
+ quadrature=fem.RegularQuadrature(
182
+ order=3, domain=self._test.domain, family=fem.Polynomial.LOBATTO_GAUSS_LEGENDRE
183
+ ),
184
+ ),
185
+ y=rhs,
186
+ alpha=1.0,
187
+ beta=1.0,
188
+ )
189
+ return sp.bsr_mv(self._inv_mass_matrix, rhs)
190
+
191
+ def step(self):
192
+ self.current_frame += 1
193
+
194
+ # Third-order Strong Stability Preserving Runge-Kutta (SSPRK3)
195
+
196
+ k1 = self._velocity_delta(self.velocity_field)
197
+
198
+ # tmp = v0 - dt * k1
199
+ tmp = self.velocity_field.space.make_field()
200
+ fem.utils.array_axpy(y=tmp.dof_values, x=self.velocity_field.dof_values, alpha=1.0, beta=0.0)
201
+ fem.utils.array_axpy(y=tmp.dof_values, x=k1, alpha=-self.sim_dt, beta=1.0)
202
+ k2 = self._velocity_delta(tmp)
203
+
204
+ # tmp = v0 - dt * (0.25 * k1 + 0.25 * k2)
205
+ fem.utils.array_axpy(y=tmp.dof_values, x=k1, alpha=0.75 * self.sim_dt, beta=1.0)
206
+ fem.utils.array_axpy(y=tmp.dof_values, x=k2, alpha=-0.25 * self.sim_dt, beta=1.0)
207
+ k3 = self._velocity_delta(tmp)
208
+
209
+ # v = v0 - dt * (1/6 * k1 + 1/6 * k2 + 2/3 * k3)
210
+ fem.utils.array_axpy(y=self.velocity_field.dof_values, x=k1, alpha=-1.0 / 6.0 * self.sim_dt, beta=1.0)
211
+ fem.utils.array_axpy(y=self.velocity_field.dof_values, x=k2, alpha=-1.0 / 6.0 * self.sim_dt, beta=1.0)
212
+ fem.utils.array_axpy(y=self.velocity_field.dof_values, x=k3, alpha=-2.0 / 3.0 * self.sim_dt, beta=1.0)
213
+
214
+ # Apply slope limiter
215
+ if self.velocity_field.space.degree > 0:
216
+ res = self.velocity_field.space.geometry.res
217
+ dx = wp.vec2(1.0 / res[0], 1.0 / res[1])
218
+ fem.interpolate(slope_limiter, dest=tmp, fields={"u": self.velocity_field}, values={"dx": dx})
219
+ wp.copy(src=tmp.dof_values, dest=self.velocity_field.dof_values)
220
+
221
+ # Update velocity norm (for visualization)
222
+ fem.interpolate(velocity_norm, dest=self.velocity_norm_field, fields={"u": self.velocity_field})
223
+
224
+ def render(self):
225
+ self.renderer.begin_frame(time=self.current_frame * self.sim_dt)
226
+ self.renderer.add_surface("u_norm", self.velocity_norm_field)
227
+ self.renderer.end_frame()
228
+
229
+
230
+ if __name__ == "__main__":
231
+ import argparse
232
+
233
+ wp.set_module_options({"enable_backward": False})
234
+
235
+ parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
236
+ parser.add_argument("--device", type=str, default=None, help="Override the default Warp device.")
237
+ parser.add_argument("--resolution", type=int, default=50, help="Grid resolution.")
238
+ parser.add_argument("--num_frames", type=int, default=250, help="Total number of frames.")
239
+ parser.add_argument("--degree", choices=(0, 1), type=int, default=1, help="Discretization order.")
240
+ parser.add_argument(
241
+ "--headless",
242
+ action="store_true",
243
+ help="Run in headless mode, suppressing the opening of any graphical windows.",
244
+ )
245
+ parser.add_argument("--quiet", action="store_true")
246
+
247
+ args = parser.parse_known_args()[0]
248
+
249
+ with wp.ScopedDevice(args.device):
250
+ example = Example(
251
+ quiet=args.quiet,
252
+ resolution=args.resolution,
253
+ degree=args.degree,
254
+ )
255
+
256
+ for k in range(args.num_frames):
257
+ print(f"Frame {k}:")
258
+ example.step()
259
+ example.render()
260
+
261
+ if not args.headless:
262
+ example.renderer.plot()
@@ -28,8 +28,6 @@ except ImportError:
28
28
  from mesh_utils import gen_trimesh
29
29
  from plot_utils import Plot
30
30
 
31
- wp.init()
32
-
33
31
 
34
32
  @fem.integrand
35
33
  def initial_condition(domain: fem.Domain, s: fem.Sample):
@@ -41,8 +41,6 @@ except ImportError:
41
41
  from mesh_utils import gen_quadmesh, gen_trimesh
42
42
  from plot_utils import Plot
43
43
 
44
- wp.init()
45
-
46
44
 
47
45
  # Standard transport term, on cells' interior
48
46
  @fem.integrand
@@ -32,8 +32,6 @@ except ImportError:
32
32
  from mesh_utils import gen_quadmesh, gen_trimesh
33
33
  from plot_utils import Plot
34
34
 
35
- wp.init()
36
-
37
35
 
38
36
  @fem.integrand
39
37
  def deformation_field_expr(
@@ -32,8 +32,6 @@ except ImportError:
32
32
  from mesh_utils import gen_quadmesh, gen_trimesh
33
33
  from plot_utils import Plot
34
34
 
35
- wp.init()
36
-
37
35
 
38
36
  @fem.integrand
39
37
  def linear_form(
@@ -25,7 +25,7 @@ from warp.sparse import bsr_axpy
25
25
  try:
26
26
  from .bsr_utils import bsr_cg
27
27
  from .example_diffusion import diffusion_form, linear_form
28
- from .mesh_utils import gen_tetmesh
28
+ from .mesh_utils import gen_hexmesh, gen_tetmesh
29
29
  from .plot_utils import Plot
30
30
  except ImportError:
31
31
  from bsr_utils import bsr_cg
@@ -33,8 +33,6 @@ except ImportError:
33
33
  from mesh_utils import gen_hexmesh, gen_tetmesh
34
34
  from plot_utils import Plot
35
35
 
36
- wp.init()
37
-
38
36
 
39
37
  @fem.integrand
40
38
  def vert_boundary_projector_form(
@@ -80,6 +78,9 @@ class Example:
80
78
  bounds_hi=wp.vec3(1.0, 0.5, 2.0),
81
79
  )
82
80
  self._geo = fem.Hexmesh(hex_vtx_indices, pos)
81
+ elif mesh == "nano":
82
+ volume = wp.Volume.allocate(min=[0, 0, 0], max=[1.0, 0.5, 2.0], voxel_size=1.0 / res[0], bg_value=None)
83
+ self._geo = fem.Nanogrid(volume)
83
84
  else:
84
85
  self._geo = fem.Grid3D(
85
86
  res=res,
@@ -149,7 +150,7 @@ if __name__ == "__main__":
149
150
  parser.add_argument(
150
151
  "--boundary_compliance", type=float, default=0.0, help="Dirichlet boundary condition compliance."
151
152
  )
152
- parser.add_argument("--mesh", choices=("grid", "tet", "hex"), default="grid", help="Mesh type.")
153
+ parser.add_argument("--mesh", choices=("grid", "tet", "hex", "nano"), default="grid", help="Mesh type.")
153
154
  parser.add_argument(
154
155
  "--headless",
155
156
  action="store_true",
@@ -30,8 +30,6 @@ except ImportError:
30
30
  from example_diffusion import diffusion_form, linear_form
31
31
  from plot_utils import Plot
32
32
 
33
- wp.init()
34
-
35
33
 
36
34
  @fem.integrand
37
35
  def mass_form(
@@ -32,8 +32,6 @@ except ImportError:
32
32
  from mesh_utils import gen_quadmesh, gen_trimesh
33
33
  from plot_utils import Plot
34
34
 
35
- wp.init()
36
-
37
35
 
38
36
  @wp.func
39
37
  def compute_stress(tau: wp.mat22, E: wp.mat33):
@@ -31,8 +31,6 @@ except ImportError:
31
31
  from mesh_utils import gen_trimesh
32
32
  from plot_utils import Plot
33
33
 
34
- wp.init()
35
-
36
34
 
37
35
  @fem.integrand
38
36
  def u_boundary_value(s: fem.Sample, domain: fem.Domain, v: fem.Field, top_vel: float):
@@ -30,8 +30,6 @@ except ImportError:
30
30
  from mesh_utils import gen_quadmesh, gen_trimesh
31
31
  from plot_utils import Plot
32
32
 
33
- wp.init()
34
-
35
33
 
36
34
  @fem.integrand
37
35
  def constant_form(val: wp.vec2):
@@ -33,8 +33,6 @@ except ImportError:
33
33
  from bsr_utils import bsr_cg
34
34
  from plot_utils import Plot
35
35
 
36
- wp.init()
37
-
38
36
 
39
37
  @fem.integrand
40
38
  def vel_from_particles_form(s: fem.Sample, particle_vel: wp.array(dtype=wp.vec2), v: fem.Field):
@@ -23,8 +23,6 @@ import warp as wp
23
23
  import warp.sim
24
24
  import warp.sim.render
25
25
 
26
- wp.init()
27
-
28
26
 
29
27
  @wp.kernel
30
28
  def loss_kernel(pos: wp.array(dtype=wp.vec3), target: wp.vec3, loss: wp.array(dtype=float)):
@@ -23,8 +23,6 @@ import warp as wp
23
23
  import warp.sim
24
24
  import warp.sim.render
25
25
 
26
- wp.init()
27
-
28
26
 
29
27
  @wp.kernel
30
28
  def com_kernel(positions: wp.array(dtype=wp.vec3), n: int, com: wp.array(dtype=wp.vec3)):
@@ -23,8 +23,6 @@ import warp as wp
23
23
  import warp.examples
24
24
  from warp.optim import SGD
25
25
 
26
- wp.init()
27
-
28
26
 
29
27
  class RenderMode:
30
28
  """Rendering modes
@@ -28,8 +28,6 @@ from warp.sim.collide import box_sdf, capsule_sdf, cone_sdf, cylinder_sdf, mesh_
28
28
 
29
29
  DEFAULT_DRONE_PATH = os.path.join(warp.examples.get_asset_directory(), "crazyflie.usd") # Path to input drone asset
30
30
 
31
- wp.init()
32
-
33
31
 
34
32
  @wp.struct
35
33
  class Propeller:
@@ -19,8 +19,6 @@ import warp as wp
19
19
  import warp.sim
20
20
  import warp.sim.render
21
21
 
22
- wp.init()
23
-
24
22
  TARGET = wp.constant(wp.vec3(2.0, 1.0, 0.0))
25
23
 
26
24
 
@@ -21,8 +21,6 @@ import warp as wp
21
21
  import warp.sim
22
22
  import warp.sim.render
23
23
 
24
- wp.init()
25
-
26
24
 
27
25
  class ForwardKinematics(torch.autograd.Function):
28
26
  @staticmethod
@@ -20,8 +20,6 @@ import warp as wp
20
20
  import warp.sim
21
21
  import warp.sim.render
22
22
 
23
- wp.init()
24
-
25
23
 
26
24
  @wp.kernel
27
25
  def compute_loss_kernel(
@@ -20,8 +20,6 @@ import warp.sim
20
20
  import warp.sim.render
21
21
  from warp.optim import Adam
22
22
 
23
- wp.init()
24
-
25
23
 
26
24
  @wp.kernel
27
25
  def loss_l2(
@@ -29,8 +29,6 @@ import warp.optim
29
29
  import warp.sim
30
30
  import warp.sim.render
31
31
 
32
- wp.init()
33
-
34
32
 
35
33
  @wp.kernel
36
34
  def loss_kernel(com: wp.array(dtype=wp.vec3), loss: wp.array(dtype=float)):
@@ -24,8 +24,6 @@ import warp.examples
24
24
  import warp.sim
25
25
  import warp.sim.render
26
26
 
27
- wp.init()
28
-
29
27
 
30
28
  class Example:
31
29
  def __init__(self, stage_path="example_cartpole.usd", num_envs=8):
@@ -25,8 +25,6 @@ import warp.examples
25
25
  import warp.sim
26
26
  import warp.sim.render
27
27
 
28
- wp.init()
29
-
30
28
 
31
29
  class IntegratorType(Enum):
32
30
  EULER = "euler"
@@ -17,8 +17,6 @@ import warp as wp
17
17
  import warp.sim
18
18
  import warp.sim.render
19
19
 
20
- wp.init()
21
-
22
20
 
23
21
  class Example:
24
22
  def __init__(self, stage_path="example_granular.usd"):
@@ -25,8 +25,6 @@ import warp.examples
25
25
  import warp.sim
26
26
  import warp.sim.render
27
27
 
28
- wp.init()
29
-
30
28
 
31
29
  class Example:
32
30
  def __init__(self, stage_path="example_granular_collision_sdf.usd"):
@@ -26,8 +26,6 @@ import warp.examples
26
26
  import warp.sim
27
27
  import warp.sim.render
28
28
 
29
- wp.init()
30
-
31
29
 
32
30
  @wp.kernel
33
31
  def compute_endeffector_position(
@@ -19,8 +19,6 @@ import warp as wp
19
19
  import warp.sim
20
20
  import warp.sim.render
21
21
 
22
- wp.init()
23
-
24
22
 
25
23
  class Example:
26
24
  def __init__(self, stage_path="example_particle_chain.usd"):
@@ -24,8 +24,6 @@ import warp.examples
24
24
  import warp.sim
25
25
  import warp.sim.render
26
26
 
27
- wp.init()
28
-
29
27
 
30
28
  # Taken from env/environment.py
31
29
  def compute_env_offsets(num_envs, env_offset=(5.0, 0.0, 5.0), up_axis="Y"):
@@ -20,8 +20,6 @@ import warp as wp
20
20
  import warp.sim
21
21
  import warp.sim.render
22
22
 
23
- wp.init()
24
-
25
23
 
26
24
  class Example:
27
25
  def __init__(self, stage_path="example_rigid_chain.usd"):
@@ -24,8 +24,6 @@ import warp.examples
24
24
  import warp.sim
25
25
  import warp.sim.render
26
26
 
27
- wp.init()
28
-
29
27
 
30
28
  class Example:
31
29
  def __init__(self, stage_path="example_rigid_contact.usd"):
@@ -17,8 +17,6 @@ import warp as wp
17
17
  import warp.sim
18
18
  import warp.sim.render
19
19
 
20
- wp.init()
21
-
22
20
 
23
21
  class Example:
24
22
  def __init__(self, stage_path="example_rigid_force.usd", use_opengl=False):
@@ -17,8 +17,6 @@ import warp as wp
17
17
  import warp.sim
18
18
  import warp.sim.render
19
19
 
20
- wp.init()
21
-
22
20
 
23
21
  class Example:
24
22
  def __init__(self, stage_path="example_rigid_gyroscopic.usd"):
@@ -17,8 +17,6 @@ import warp as wp
17
17
  import warp.sim
18
18
  import warp.sim.render
19
19
 
20
- wp.init()
21
-
22
20
 
23
21
  class Example:
24
22
  def __init__(self, stage_path="example_rigid_soft_contact.usd"):
@@ -18,8 +18,6 @@ import warp as wp
18
18
  import warp.sim
19
19
  import warp.sim.render
20
20
 
21
- wp.init()
22
-
23
21
 
24
22
  @wp.kernel
25
23
  def twist_points(
warp/fem/__init__.py CHANGED
@@ -10,6 +10,7 @@ from .geometry import (
10
10
  Grid3D,
11
11
  Hexmesh,
12
12
  LinearGeometryPartition,
13
+ Nanogrid,
13
14
  Quadmesh2D,
14
15
  Tetmesh,
15
16
  Trimesh2D,
warp/fem/cache.py CHANGED
@@ -228,7 +228,7 @@ class Temporary:
228
228
 
229
229
  def _view_as(self, shape, dtype) -> "Temporary":
230
230
  def _view_reshaped_truncated(array):
231
- return wp.types.array(
231
+ view = wp.types.array(
232
232
  ptr=array.ptr,
233
233
  dtype=dtype,
234
234
  shape=shape,
@@ -238,6 +238,8 @@ class Temporary:
238
238
  copy=False,
239
239
  grad=None if array.grad is None else _view_reshaped_truncated(array.grad),
240
240
  )
241
+ view._ref = array
242
+ return view
241
243
 
242
244
  self._array_view = _view_reshaped_truncated(self._raw_array)
243
245
  return self
@@ -4,6 +4,7 @@ from .geometry import Geometry
4
4
  from .grid_2d import Grid2D
5
5
  from .grid_3d import Grid3D
6
6
  from .hexmesh import Hexmesh
7
+ from .nanogrid import Nanogrid
7
8
  from .partition import (
8
9
  ExplicitGeometryPartition,
9
10
  GeometryPartition,
@@ -14,6 +14,10 @@ class Element:
14
14
  """Returns a quadrature of a given order for a prototypical element"""
15
15
  raise NotImplementedError
16
16
 
17
+ def center(self) -> Tuple[float]:
18
+ coords, _ = self.instantiate_quadrature(order=0, family=None)
19
+ return coords[0]
20
+
17
21
 
18
22
  def _point_count_from_order(order: int, family: Polynomial):
19
23
  if family == Polynomial.GAUSS_LEGENDRE:
@@ -263,10 +263,6 @@ class Grid3D(Geometry):
263
263
  def cell_normal(args: CellArg, s: Sample):
264
264
  return wp.vec3(0.0)
265
265
 
266
- @wp.func
267
- def cell_transform_reference_gradient(args: CellArg, cell_index: ElementIndex, coords: Coords, ref_grad: wp.vec3):
268
- return wp.cw_div(ref_grad, args.cell_size)
269
-
270
266
  @cached_arg_value
271
267
  def side_arg_value(self, device) -> SideArg:
272
268
  args = self.SideArg()