warp-lang 1.0.0b2__py3-none-win_amd64.whl → 1.0.0b6__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 (271) hide show
  1. docs/conf.py +17 -5
  2. examples/env/env_ant.py +1 -1
  3. examples/env/env_cartpole.py +1 -1
  4. examples/env/env_humanoid.py +1 -1
  5. examples/env/env_usd.py +4 -1
  6. examples/env/environment.py +8 -9
  7. examples/example_dem.py +34 -33
  8. examples/example_diffray.py +364 -337
  9. examples/example_fluid.py +32 -23
  10. examples/example_jacobian_ik.py +97 -93
  11. examples/example_marching_cubes.py +6 -16
  12. examples/example_mesh.py +6 -16
  13. examples/example_mesh_intersect.py +16 -14
  14. examples/example_nvdb.py +14 -16
  15. examples/example_raycast.py +14 -13
  16. examples/example_raymarch.py +16 -23
  17. examples/example_render_opengl.py +19 -10
  18. examples/example_sim_cartpole.py +82 -78
  19. examples/example_sim_cloth.py +45 -48
  20. examples/example_sim_fk_grad.py +51 -44
  21. examples/example_sim_fk_grad_torch.py +47 -40
  22. examples/example_sim_grad_bounce.py +108 -133
  23. examples/example_sim_grad_cloth.py +99 -113
  24. examples/example_sim_granular.py +5 -6
  25. examples/{example_sim_sdf_shape.py → example_sim_granular_collision_sdf.py} +37 -26
  26. examples/example_sim_neo_hookean.py +51 -55
  27. examples/example_sim_particle_chain.py +4 -4
  28. examples/example_sim_quadruped.py +126 -81
  29. examples/example_sim_rigid_chain.py +54 -61
  30. examples/example_sim_rigid_contact.py +66 -70
  31. examples/example_sim_rigid_fem.py +3 -3
  32. examples/example_sim_rigid_force.py +1 -1
  33. examples/example_sim_rigid_gyroscopic.py +3 -4
  34. examples/example_sim_rigid_kinematics.py +28 -39
  35. examples/example_sim_trajopt.py +112 -110
  36. examples/example_sph.py +9 -8
  37. examples/example_wave.py +7 -7
  38. examples/fem/bsr_utils.py +30 -17
  39. examples/fem/example_apic_fluid.py +85 -69
  40. examples/fem/example_convection_diffusion.py +97 -93
  41. examples/fem/example_convection_diffusion_dg.py +142 -149
  42. examples/fem/example_convection_diffusion_dg0.py +141 -136
  43. examples/fem/example_deformed_geometry.py +146 -0
  44. examples/fem/example_diffusion.py +115 -84
  45. examples/fem/example_diffusion_3d.py +116 -86
  46. examples/fem/example_diffusion_mgpu.py +102 -79
  47. examples/fem/example_mixed_elasticity.py +139 -100
  48. examples/fem/example_navier_stokes.py +175 -162
  49. examples/fem/example_stokes.py +143 -111
  50. examples/fem/example_stokes_transfer.py +186 -157
  51. examples/fem/mesh_utils.py +59 -97
  52. examples/fem/plot_utils.py +138 -17
  53. tools/ci/publishing/build_nodes_info.py +54 -0
  54. warp/__init__.py +4 -3
  55. warp/__init__.pyi +1 -0
  56. warp/bin/warp-clang.dll +0 -0
  57. warp/bin/warp.dll +0 -0
  58. warp/build.py +5 -3
  59. warp/build_dll.py +29 -9
  60. warp/builtins.py +836 -492
  61. warp/codegen.py +864 -553
  62. warp/config.py +3 -1
  63. warp/context.py +389 -172
  64. warp/fem/__init__.py +24 -6
  65. warp/fem/cache.py +318 -25
  66. warp/fem/dirichlet.py +7 -3
  67. warp/fem/domain.py +14 -0
  68. warp/fem/field/__init__.py +30 -38
  69. warp/fem/field/field.py +149 -0
  70. warp/fem/field/nodal_field.py +244 -138
  71. warp/fem/field/restriction.py +8 -6
  72. warp/fem/field/test.py +127 -59
  73. warp/fem/field/trial.py +117 -60
  74. warp/fem/geometry/__init__.py +5 -1
  75. warp/fem/geometry/deformed_geometry.py +271 -0
  76. warp/fem/geometry/element.py +24 -1
  77. warp/fem/geometry/geometry.py +86 -14
  78. warp/fem/geometry/grid_2d.py +112 -54
  79. warp/fem/geometry/grid_3d.py +134 -65
  80. warp/fem/geometry/hexmesh.py +953 -0
  81. warp/fem/geometry/partition.py +85 -33
  82. warp/fem/geometry/quadmesh_2d.py +532 -0
  83. warp/fem/geometry/tetmesh.py +451 -115
  84. warp/fem/geometry/trimesh_2d.py +197 -92
  85. warp/fem/integrate.py +534 -268
  86. warp/fem/operator.py +58 -31
  87. warp/fem/polynomial.py +11 -0
  88. warp/fem/quadrature/__init__.py +1 -1
  89. warp/fem/quadrature/pic_quadrature.py +150 -58
  90. warp/fem/quadrature/quadrature.py +209 -57
  91. warp/fem/space/__init__.py +230 -53
  92. warp/fem/space/basis_space.py +489 -0
  93. warp/fem/space/collocated_function_space.py +105 -0
  94. warp/fem/space/dof_mapper.py +49 -2
  95. warp/fem/space/function_space.py +90 -39
  96. warp/fem/space/grid_2d_function_space.py +149 -496
  97. warp/fem/space/grid_3d_function_space.py +173 -538
  98. warp/fem/space/hexmesh_function_space.py +352 -0
  99. warp/fem/space/partition.py +129 -76
  100. warp/fem/space/quadmesh_2d_function_space.py +369 -0
  101. warp/fem/space/restriction.py +46 -34
  102. warp/fem/space/shape/__init__.py +15 -0
  103. warp/fem/space/shape/cube_shape_function.py +738 -0
  104. warp/fem/space/shape/shape_function.py +103 -0
  105. warp/fem/space/shape/square_shape_function.py +611 -0
  106. warp/fem/space/shape/tet_shape_function.py +567 -0
  107. warp/fem/space/shape/triangle_shape_function.py +429 -0
  108. warp/fem/space/tetmesh_function_space.py +132 -1039
  109. warp/fem/space/topology.py +295 -0
  110. warp/fem/space/trimesh_2d_function_space.py +104 -742
  111. warp/fem/types.py +13 -11
  112. warp/fem/utils.py +335 -60
  113. warp/native/array.h +120 -34
  114. warp/native/builtin.h +101 -72
  115. warp/native/bvh.cpp +73 -325
  116. warp/native/bvh.cu +406 -23
  117. warp/native/bvh.h +22 -40
  118. warp/native/clang/clang.cpp +1 -0
  119. warp/native/crt.h +2 -0
  120. warp/native/cuda_util.cpp +8 -3
  121. warp/native/cuda_util.h +1 -0
  122. warp/native/exports.h +1522 -1243
  123. warp/native/intersect.h +19 -4
  124. warp/native/intersect_adj.h +8 -8
  125. warp/native/mat.h +76 -17
  126. warp/native/mesh.cpp +33 -108
  127. warp/native/mesh.cu +114 -18
  128. warp/native/mesh.h +395 -40
  129. warp/native/noise.h +272 -329
  130. warp/native/quat.h +51 -8
  131. warp/native/rand.h +44 -34
  132. warp/native/reduce.cpp +1 -1
  133. warp/native/sparse.cpp +4 -4
  134. warp/native/sparse.cu +163 -155
  135. warp/native/spatial.h +2 -2
  136. warp/native/temp_buffer.h +18 -14
  137. warp/native/vec.h +103 -21
  138. warp/native/warp.cpp +2 -1
  139. warp/native/warp.cu +28 -3
  140. warp/native/warp.h +4 -3
  141. warp/render/render_opengl.py +261 -109
  142. warp/sim/__init__.py +1 -2
  143. warp/sim/articulation.py +385 -185
  144. warp/sim/import_mjcf.py +59 -48
  145. warp/sim/import_urdf.py +15 -15
  146. warp/sim/import_usd.py +174 -102
  147. warp/sim/inertia.py +17 -18
  148. warp/sim/integrator_xpbd.py +4 -3
  149. warp/sim/model.py +330 -250
  150. warp/sim/render.py +1 -1
  151. warp/sparse.py +625 -152
  152. warp/stubs.py +341 -309
  153. warp/tape.py +9 -6
  154. warp/tests/__main__.py +3 -6
  155. warp/tests/assets/curlnoise_golden.npy +0 -0
  156. warp/tests/assets/pnoise_golden.npy +0 -0
  157. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  158. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  159. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  160. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  161. warp/tests/aux_test_unresolved_func.py +14 -0
  162. warp/tests/aux_test_unresolved_symbol.py +14 -0
  163. warp/tests/disabled_kinematics.py +239 -0
  164. warp/tests/run_coverage_serial.py +31 -0
  165. warp/tests/test_adam.py +103 -106
  166. warp/tests/test_arithmetic.py +94 -74
  167. warp/tests/test_array.py +82 -101
  168. warp/tests/test_array_reduce.py +57 -23
  169. warp/tests/test_atomic.py +64 -28
  170. warp/tests/test_bool.py +22 -12
  171. warp/tests/test_builtins_resolution.py +1292 -0
  172. warp/tests/test_bvh.py +18 -18
  173. warp/tests/test_closest_point_edge_edge.py +54 -57
  174. warp/tests/test_codegen.py +165 -134
  175. warp/tests/test_compile_consts.py +28 -20
  176. warp/tests/test_conditional.py +108 -24
  177. warp/tests/test_copy.py +10 -12
  178. warp/tests/test_ctypes.py +112 -88
  179. warp/tests/test_dense.py +21 -14
  180. warp/tests/test_devices.py +98 -0
  181. warp/tests/test_dlpack.py +75 -75
  182. warp/tests/test_examples.py +237 -0
  183. warp/tests/test_fabricarray.py +22 -24
  184. warp/tests/test_fast_math.py +15 -11
  185. warp/tests/test_fem.py +1034 -124
  186. warp/tests/test_fp16.py +23 -16
  187. warp/tests/test_func.py +187 -86
  188. warp/tests/test_generics.py +194 -49
  189. warp/tests/test_grad.py +123 -181
  190. warp/tests/test_grad_customs.py +176 -0
  191. warp/tests/test_hash_grid.py +35 -34
  192. warp/tests/test_import.py +10 -23
  193. warp/tests/test_indexedarray.py +24 -25
  194. warp/tests/test_intersect.py +18 -9
  195. warp/tests/test_large.py +141 -0
  196. warp/tests/test_launch.py +14 -41
  197. warp/tests/test_lerp.py +64 -65
  198. warp/tests/test_lvalue.py +493 -0
  199. warp/tests/test_marching_cubes.py +12 -13
  200. warp/tests/test_mat.py +517 -2898
  201. warp/tests/test_mat_lite.py +115 -0
  202. warp/tests/test_mat_scalar_ops.py +2889 -0
  203. warp/tests/test_math.py +103 -9
  204. warp/tests/test_matmul.py +304 -69
  205. warp/tests/test_matmul_lite.py +410 -0
  206. warp/tests/test_mesh.py +60 -22
  207. warp/tests/test_mesh_query_aabb.py +21 -25
  208. warp/tests/test_mesh_query_point.py +111 -22
  209. warp/tests/test_mesh_query_ray.py +12 -24
  210. warp/tests/test_mlp.py +30 -22
  211. warp/tests/test_model.py +92 -89
  212. warp/tests/test_modules_lite.py +39 -0
  213. warp/tests/test_multigpu.py +88 -114
  214. warp/tests/test_noise.py +12 -11
  215. warp/tests/test_operators.py +16 -20
  216. warp/tests/test_options.py +11 -11
  217. warp/tests/test_pinned.py +17 -18
  218. warp/tests/test_print.py +32 -11
  219. warp/tests/test_quat.py +275 -129
  220. warp/tests/test_rand.py +18 -16
  221. warp/tests/test_reload.py +38 -34
  222. warp/tests/test_rounding.py +50 -43
  223. warp/tests/test_runlength_encode.py +168 -20
  224. warp/tests/test_smoothstep.py +9 -11
  225. warp/tests/test_snippet.py +143 -0
  226. warp/tests/test_sparse.py +261 -63
  227. warp/tests/test_spatial.py +276 -243
  228. warp/tests/test_streams.py +110 -85
  229. warp/tests/test_struct.py +268 -63
  230. warp/tests/test_tape.py +39 -21
  231. warp/tests/test_torch.py +90 -86
  232. warp/tests/test_transient_module.py +10 -12
  233. warp/tests/test_types.py +363 -0
  234. warp/tests/test_utils.py +451 -0
  235. warp/tests/test_vec.py +354 -2050
  236. warp/tests/test_vec_lite.py +73 -0
  237. warp/tests/test_vec_scalar_ops.py +2099 -0
  238. warp/tests/test_volume.py +418 -376
  239. warp/tests/test_volume_write.py +124 -134
  240. warp/tests/unittest_serial.py +35 -0
  241. warp/tests/unittest_suites.py +291 -0
  242. warp/tests/unittest_utils.py +342 -0
  243. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  244. warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
  245. warp/thirdparty/appdirs.py +36 -45
  246. warp/thirdparty/unittest_parallel.py +589 -0
  247. warp/types.py +622 -211
  248. warp/utils.py +54 -393
  249. warp_lang-1.0.0b6.dist-info/METADATA +238 -0
  250. warp_lang-1.0.0b6.dist-info/RECORD +409 -0
  251. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  252. examples/example_cache_management.py +0 -40
  253. examples/example_multigpu.py +0 -54
  254. examples/example_struct.py +0 -65
  255. examples/fem/example_stokes_transfer_3d.py +0 -210
  256. warp/bin/warp-clang.so +0 -0
  257. warp/bin/warp.so +0 -0
  258. warp/fem/field/discrete_field.py +0 -80
  259. warp/fem/space/nodal_function_space.py +0 -233
  260. warp/tests/test_all.py +0 -223
  261. warp/tests/test_array_scan.py +0 -60
  262. warp/tests/test_base.py +0 -208
  263. warp/tests/test_unresolved_func.py +0 -7
  264. warp/tests/test_unresolved_symbol.py +0 -7
  265. warp_lang-1.0.0b2.dist-info/METADATA +0 -26
  266. warp_lang-1.0.0b2.dist-info/RECORD +0 -380
  267. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  268. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  269. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  270. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  271. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,271 @@
1
+ from typing import Any
2
+
3
+ import warp as wp
4
+
5
+ from .geometry import Geometry
6
+
7
+ from warp.fem.types import Sample, ElementIndex, Coords, make_free_sample
8
+ from warp.fem import cache
9
+
10
+ _mat32 = wp.mat(shape=(3, 2), dtype=float)
11
+
12
+
13
+ class DeformedGeometry(Geometry):
14
+ def __init__(self, field):
15
+ """Constructs a Deformed Geometry from a displacement field defined over a base geometry"""
16
+
17
+ from warp.fem.field import DiscreteField
18
+
19
+ self.field: DiscreteField = field
20
+ self.base = self.field.space.geometry
21
+ self.dimension = self.base.dimension
22
+
23
+ if not wp.types.type_is_vector(field.dtype) or wp.types.type_length(field.dtype) != self.dimension:
24
+ raise ValueError("Invalid value type for position field")
25
+
26
+ self.CellArg = self.field.ElementEvalArg
27
+
28
+ self.field_trace = field.trace()
29
+ self.SideArg = self._make_side_arg()
30
+ self.SideIndexArg = self.base.SideIndexArg
31
+
32
+ self.cell_count = self.base.cell_count
33
+ self.vertex_count = self.base.vertex_count
34
+ self.side_count = self.base.side_count
35
+ self.boundary_side_count = self.base.boundary_side_count
36
+ self.reference_cell = self.base.reference_cell
37
+ self.reference_side = self.base.reference_side
38
+
39
+ self.side_index_arg_value = self.base.side_index_arg_value
40
+
41
+ self.cell_position = self._make_cell_position()
42
+ self.cell_deformation_gradient = self._make_cell_deformation_gradient()
43
+ self.cell_inverse_deformation_gradient = self._make_cell_inverse_deformation_gradient()
44
+ self.cell_measure = self._make_cell_measure()
45
+
46
+ self.boundary_side_index = self.base.boundary_side_index
47
+
48
+ self.side_to_cell_arg = self._make_side_to_cell_arg()
49
+ self.side_position = self._make_side_position()
50
+ self.side_deformation_gradient = self._make_side_deformation_gradient()
51
+ self.side_inner_cell_index = self._make_side_inner_cell_index()
52
+ self.side_outer_cell_index = self._make_side_outer_cell_index()
53
+ self.side_inner_cell_coords = self._make_side_inner_cell_coords()
54
+ self.side_outer_cell_coords = self._make_side_outer_cell_coords()
55
+ self.side_from_cell_coords = self._make_side_from_cell_coords()
56
+ self.side_inner_inverse_deformation_gradient = self._make_side_inner_inverse_deformation_gradient()
57
+ self.side_outer_inverse_deformation_gradient = self._make_side_outer_inverse_deformation_gradient()
58
+ self.side_measure = self._make_side_measure()
59
+ self.side_measure_ratio = self._make_side_measure_ratio()
60
+ self.side_normal = self._make_side_normal()
61
+
62
+ @property
63
+ def name(self):
64
+ return f"DefGeo_{self.field.name}"
65
+
66
+ # Geometry device interface
67
+
68
+ @cache.cached_arg_value
69
+ def cell_arg_value(self, device) -> "DeformedGeometry.CellArg":
70
+ args = self.CellArg()
71
+
72
+ args.elt_arg = self.base.cell_arg_value(device)
73
+ args.eval_arg = self.field.eval_arg_value(device)
74
+
75
+ return args
76
+
77
+ def _make_cell_position(self):
78
+ @cache.dynamic_func(suffix=self.name)
79
+ def cell_position(cell_arg: self.CellArg, s: Sample):
80
+ return self.field.eval_inner(cell_arg, s) + self.base.cell_position(cell_arg.elt_arg, s)
81
+
82
+ return cell_position
83
+
84
+ def _make_cell_deformation_gradient(self):
85
+ @cache.dynamic_func(suffix=self.name)
86
+ def cell_deformation_gradient(cell_arg: self.CellArg, s: Sample):
87
+ return self.field.eval_reference_grad_inner(cell_arg, s) + self.base.cell_deformation_gradient(
88
+ cell_arg.elt_arg, s
89
+ )
90
+
91
+ return cell_deformation_gradient
92
+
93
+ def _make_cell_inverse_deformation_gradient(self):
94
+ @cache.dynamic_func(suffix=self.name)
95
+ def cell_inverse_deformation_gradient(cell_arg: self.CellArg, s: Sample):
96
+ return wp.inverse(self.cell_deformation_gradient(cell_arg, s))
97
+
98
+ return cell_inverse_deformation_gradient
99
+
100
+ def _make_cell_measure(self):
101
+ REF_MEASURE = wp.constant(self.reference_cell().measure())
102
+
103
+ @cache.dynamic_func(suffix=self.name)
104
+ def cell_measure(args: self.CellArg, s: Sample):
105
+ return wp.abs(wp.determinant(self.cell_deformation_gradient(args, s))) * REF_MEASURE
106
+
107
+ return cell_measure
108
+
109
+ @wp.func
110
+ def cell_normal(args: Any, s: Sample):
111
+ return wp.vec2(0.0)
112
+
113
+ def _make_side_arg(self):
114
+ @cache.dynamic_struct(suffix=self.name)
115
+ class SideArg:
116
+ base_arg: self.base.SideArg
117
+ trace_arg: self.field_trace.EvalArg
118
+ field_arg: self.field.EvalArg
119
+
120
+ return SideArg
121
+
122
+ @cache.cached_arg_value
123
+ def side_arg_value(self, device) -> "DeformedGeometry.SideArg":
124
+ args = self.SideArg()
125
+
126
+ args.base_arg = self.base.side_arg_value(device)
127
+ args.field_arg = self.field.eval_arg_value(device)
128
+ args.trace_arg = self.field_trace.eval_arg_value(device)
129
+
130
+ return args
131
+
132
+ def _make_side_position(self):
133
+ @cache.dynamic_func(suffix=self.name)
134
+ def side_position(args: self.SideArg, s: Sample):
135
+ trace_arg = self.field_trace.ElementEvalArg(args.base_arg, args.trace_arg)
136
+ return self.field_trace.eval_inner(trace_arg, s) + self.base.side_position(args.base_arg, s)
137
+
138
+ return side_position
139
+
140
+ def _make_side_deformation_gradient(self):
141
+ @cache.dynamic_func(suffix=self.name)
142
+ def side_deformation_gradient(args: self.SideArg, s: Sample):
143
+ base_def_grad = self.base.side_deformation_gradient(args.base_arg, s)
144
+ trace_arg = self.field_trace.ElementEvalArg(args.base_arg, args.trace_arg)
145
+
146
+ Du = self.field_trace.eval_grad_inner(trace_arg, s)
147
+ return base_def_grad + Du * base_def_grad
148
+
149
+ return side_deformation_gradient
150
+
151
+ def _make_side_inner_inverse_deformation_gradient(self):
152
+ @cache.dynamic_func(suffix=self.name)
153
+ def side_inner_inverse_deformation_gradient(args: self.SideArg, s: Sample):
154
+ cell_index = self.side_inner_cell_index(args, s.element_index)
155
+ cell_coords = self.side_inner_cell_coords(args, s.element_index, s.element_coords)
156
+ cell_arg = self.side_to_cell_arg(args)
157
+ return self.cell_inverse_deformation_gradient(cell_arg, make_free_sample(cell_index, cell_coords))
158
+
159
+ def _make_side_outer_inverse_deformation_gradient(self):
160
+ @cache.dynamic_func(suffix=self.name)
161
+ def side_outer_inverse_deformation_gradient(args: self.SideArg, s: Sample):
162
+ cell_index = self.side_outer_cell_index(args, s.element_index)
163
+ cell_coords = self.side_outer_cell_coords(args, s.element_index, s.element_coords)
164
+ cell_arg = self.side_to_cell_arg(args)
165
+ return self.cell_inverse_deformation_gradient(cell_arg, make_free_sample(cell_index, cell_coords))
166
+
167
+ @wp.func
168
+ def _side_measure(F: wp.vec2):
169
+ return wp.length(F)
170
+
171
+ @wp.func
172
+ def _side_measure(F: _mat32):
173
+ Fcross = wp.vec3(
174
+ F[1, 0] * F[2, 1] - F[2, 0] * F[1, 1],
175
+ F[2, 0] * F[0, 1] - F[0, 0] * F[2, 1],
176
+ F[0, 0] * F[1, 1] - F[1, 0] * F[0, 1],
177
+ )
178
+ return wp.length(Fcross)
179
+
180
+ @wp.func
181
+ def _side_normal(F: wp.vec2):
182
+ return wp.normalize(wp.vec2(-F[1], F[0]))
183
+
184
+ @wp.func
185
+ def _side_normal(F: _mat32):
186
+ Fcross = wp.vec3(
187
+ F[1, 0] * F[2, 1] - F[2, 0] * F[1, 1],
188
+ F[2, 0] * F[0, 1] - F[0, 0] * F[2, 1],
189
+ F[0, 0] * F[1, 1] - F[1, 0] * F[0, 1],
190
+ )
191
+ return wp.normalize(Fcross)
192
+
193
+ def _make_side_measure(self):
194
+ REF_MEASURE = wp.constant(self.reference_side().measure())
195
+
196
+ @cache.dynamic_func(suffix=self.name)
197
+ def side_measure(args: self.SideArg, s: Sample):
198
+ F = self.side_deformation_gradient(args, s)
199
+ return DeformedGeometry._side_measure(F) * REF_MEASURE
200
+
201
+ return side_measure
202
+
203
+ def _make_side_measure_ratio(self):
204
+ @cache.dynamic_func(suffix=self.name)
205
+ def side_measure_ratio(args: self.SideArg, s: Sample):
206
+ inner = self.side_inner_cell_index(args, s.element_index)
207
+ outer = self.side_outer_cell_index(args, s.element_index)
208
+ inner_coords = self.side_inner_cell_coords(args, s.element_index, s.element_coords)
209
+ outer_coords = self.side_outer_cell_coords(args, s.element_index, s.element_coords)
210
+ cell_arg = self.side_to_cell_arg(args)
211
+ return self.side_measure(args, s) / wp.min(
212
+ self.cell_measure(cell_arg, make_free_sample(inner, inner_coords)),
213
+ self.cell_measure(cell_arg, make_free_sample(outer, outer_coords)),
214
+ )
215
+
216
+ return side_measure_ratio
217
+
218
+ def _make_side_normal(self):
219
+ @cache.dynamic_func(suffix=self.name)
220
+ def side_normal(args: self.SideArg, s: Sample):
221
+ F = self.side_deformation_gradient(args, s)
222
+ return DeformedGeometry._side_normal(F)
223
+
224
+ return side_normal
225
+
226
+ def _make_side_inner_cell_index(self):
227
+ @cache.dynamic_func(suffix=self.name)
228
+ def side_inner_cell_index(args: self.SideArg, side_index: ElementIndex):
229
+ return self.base.side_inner_cell_index(args.base_arg, side_index)
230
+
231
+ return side_inner_cell_index
232
+
233
+ def _make_side_outer_cell_index(self):
234
+ @cache.dynamic_func(suffix=self.name)
235
+ def side_outer_cell_index(args: self.SideArg, side_index: ElementIndex):
236
+ return self.base.side_outer_cell_index(args.base_arg, side_index)
237
+
238
+ return side_outer_cell_index
239
+
240
+ def _make_side_inner_cell_coords(self):
241
+ @cache.dynamic_func(suffix=self.name)
242
+ def side_inner_cell_coords(args: self.SideArg, side_index: ElementIndex, side_coords: Coords):
243
+ return self.base.side_inner_cell_coords(args.base_arg, side_index, side_coords)
244
+
245
+ return side_inner_cell_coords
246
+
247
+ def _make_side_outer_cell_coords(self):
248
+ @cache.dynamic_func(suffix=self.name)
249
+ def side_outer_cell_coords(args: self.SideArg, side_index: ElementIndex, side_coords: Coords):
250
+ return self.base.side_outer_cell_coords(args.base_arg, side_index, side_coords)
251
+
252
+ return side_outer_cell_coords
253
+
254
+ def _make_side_from_cell_coords(self):
255
+ @cache.dynamic_func(suffix=self.name)
256
+ def side_from_cell_coords(
257
+ args: self.SideArg,
258
+ side_index: ElementIndex,
259
+ cell_index: ElementIndex,
260
+ cell_coords: Coords,
261
+ ):
262
+ return self.base.side_from_cell_coords(args.base_arg, side_index, cell_index, cell_coords)
263
+
264
+ return side_from_cell_coords
265
+
266
+ def _make_side_to_cell_arg(self):
267
+ @cache.dynamic_func(suffix=self.name)
268
+ def side_to_cell_arg(side_arg: self.SideArg):
269
+ return self.CellArg(self.base.side_to_cell_arg(side_arg.base_arg), side_arg.field_arg)
270
+
271
+ return side_to_cell_arg
@@ -5,6 +5,10 @@ from warp.fem.polynomial import Polynomial, quadrature_1d
5
5
 
6
6
 
7
7
  class Element:
8
+ def measure() -> float:
9
+ """Measure (area, volume, ...) of the reference element"""
10
+ raise NotImplementedError
11
+
8
12
  @staticmethod
9
13
  def instantiate_quadrature(order: int, family: Polynomial) -> Tuple[List[Coords], List[float]]:
10
14
  """Returns a quadrature of a given order for a prototypical element"""
@@ -25,6 +29,10 @@ def _point_count_from_order(order: int, family: Polynomial):
25
29
 
26
30
 
27
31
  class Cube(Element):
32
+ @staticmethod
33
+ def measure() -> float:
34
+ return 1.0
35
+
28
36
  @staticmethod
29
37
  def instantiate_quadrature(order: int, family: Polynomial):
30
38
  if family is None:
@@ -40,6 +48,10 @@ class Cube(Element):
40
48
 
41
49
 
42
50
  class Square(Element):
51
+ @staticmethod
52
+ def measure() -> float:
53
+ return 1.0
54
+
43
55
  @staticmethod
44
56
  def instantiate_quadrature(order: int, family: Polynomial):
45
57
  if family is None:
@@ -55,6 +67,10 @@ class Square(Element):
55
67
 
56
68
 
57
69
  class LinearEdge(Element):
70
+ @staticmethod
71
+ def measure() -> float:
72
+ return 1.0
73
+
58
74
  @staticmethod
59
75
  def instantiate_quadrature(order: int, family: Polynomial):
60
76
  if family is None:
@@ -68,6 +84,10 @@ class LinearEdge(Element):
68
84
 
69
85
 
70
86
  class Triangle(Element):
87
+ @staticmethod
88
+ def measure() -> float:
89
+ return 0.5
90
+
71
91
  @staticmethod
72
92
  def instantiate_quadrature(order: int, family: Polynomial):
73
93
  if family is not None:
@@ -406,6 +426,10 @@ class Triangle(Element):
406
426
 
407
427
 
408
428
  class Tetrahedron(Element):
429
+ @staticmethod
430
+ def measure() -> float:
431
+ return 1.0 / 6.0
432
+
409
433
  @staticmethod
410
434
  def instantiate_quadrature(order: int, family: Polynomial):
411
435
  if family is not None:
@@ -436,7 +460,6 @@ class Tetrahedron(Element):
436
460
 
437
461
  # TODO: add Witherden and Vincent 2015,
438
462
 
439
-
440
463
  if order <= 1:
441
464
  weights = [1.0]
442
465
  coords = [Coords(1.0 / 4.0, 1.0 / 4.0, 1.0 / 4.0)]
@@ -3,6 +3,8 @@ from typing import Any
3
3
  import warp as wp
4
4
 
5
5
  from warp.fem.types import Sample, ElementIndex, Coords
6
+ from warp.fem import cache
7
+
6
8
  from .element import Element
7
9
 
8
10
 
@@ -16,12 +18,15 @@ class Geometry:
16
18
  dimension: int = 0
17
19
 
18
20
  def cell_count(self):
21
+ """Number of cells in the geometry"""
19
22
  raise NotImplementedError
20
23
 
21
24
  def side_count(self):
25
+ """Number of sides in the geometry"""
22
26
  raise NotImplementedError
23
27
 
24
28
  def boundary_side_count(self):
29
+ """Number of boundary sides (sides with a single neighbour cell) in the geometry"""
25
30
  raise NotImplementedError
26
31
 
27
32
  def reference_cell(self) -> Element:
@@ -40,75 +45,142 @@ class Geometry:
40
45
  return self.name
41
46
 
42
47
  CellArg: wp.codegen.Struct
43
- """Structure containing arguments to be passed to device function evaluating cell-related quantities"""
48
+ """Structure containing arguments to be passed to device functions evaluating cell-related quantities"""
44
49
 
45
50
  SideArg: wp.codegen.Struct
46
- """Structure containing arguments to be passed to device function evaluating side-related quantities"""
51
+ """Structure containing arguments to be passed to device functions evaluating side-related quantities"""
52
+
53
+ SideIndexArg: wp.codegen.Struct
54
+ """Structure containing arguments to be passed to device functions for indexing sides"""
47
55
 
56
+ @staticmethod
48
57
  def cell_arg_value(self, device) -> "Geometry.CellArg":
49
58
  """Value of the arguments to be passed to cell-related device functions"""
50
59
  raise NotImplementedError
51
60
 
61
+ @staticmethod
52
62
  def cell_position(args: "Geometry.CellArg", s: "Sample"):
53
- """Device function returning the cell position at a sample point"""
63
+ """Device function returning the world position of a cell sample point"""
64
+ raise NotImplementedError
65
+
66
+ @staticmethod
67
+ def cell_deformation_gradient(args: "Geometry.CellArg", s: "Sample"):
68
+ """Device function returning the transpose of the gradient of world position with respect to reference cell"""
54
69
  raise NotImplementedError
55
70
 
71
+ @staticmethod
72
+ def cell_inverse_deformation_gradient(args: "Geometry.CellArg", cell_index: ElementIndex, coords: Coords):
73
+ """Device function returning the matrix right-transforming a gradient w.r.t. cell space to a gradient w.r.t. world space
74
+ (i.e. the inverse deformation gradient)
75
+ """
76
+ raise NotImplementedError
77
+
78
+ @staticmethod
56
79
  def cell_lookup(args: "Geometry.CellArg", pos: Any):
57
80
  """Device function returning the cell sample point corresponding to a world position"""
58
81
  raise NotImplementedError
59
82
 
83
+ @staticmethod
60
84
  def cell_lookup(args: "Geometry.CellArg", pos: Any, guess: "Sample"):
61
85
  """Device function returning the cell sample point corresponding to a world position. Can use guess for faster lookup"""
62
86
  raise NotImplementedError
63
87
 
64
- def cell_measure(args: "Geometry.CellArg", cell_index: ElementIndex, coords: Coords):
65
- """Device function returning the measure determinant (e.g. volume, area) at a given point"""
66
- raise NotImplementedError
67
-
88
+ @staticmethod
68
89
  def cell_measure(args: "Geometry.CellArg", s: "Sample"):
69
90
  """Device function returning the measure determinant (e.g. volume, area) at a given point"""
70
91
  raise NotImplementedError
71
92
 
72
- def cell_measure_ratio(args: "Geometry.CellArg", s: "Sample"):
73
- """Device function returning the ratio of the measure of a side to that of its neighbour cells"""
74
- raise NotImplementedError
93
+ @wp.func
94
+ def cell_measure_ratio(args: Any, s: Sample):
95
+ return 1.0
75
96
 
97
+ @staticmethod
76
98
  def cell_normal(args: "Geometry.CellArg", s: "Sample"):
77
- """Device function returning the element normal at a sample point"""
99
+ """Device function returning the element normal at a sample point.
100
+
101
+ For elements with the same dimension as the embedding space, this will be zero."""
78
102
  raise NotImplementedError
79
103
 
104
+ @staticmethod
80
105
  def side_arg_value(self, device) -> "Geometry.SideArg":
81
106
  """Value of the arguments to be passed to side-related device functions"""
82
107
  raise NotImplementedError
83
108
 
84
- def boundary_side_index(args: "Geometry.SideArg", boundary_side_index: int):
109
+ @staticmethod
110
+ def boundary_side_index(args: "Geometry.SideIndexArg", boundary_side_index: int):
85
111
  """Device function returning the side index corresponding to a boundary side"""
86
112
  raise NotImplementedError
87
113
 
114
+ @staticmethod
88
115
  def side_position(args: "Geometry.SideArg", s: "Sample"):
89
116
  """Device function returning the side position at a sample point"""
90
117
  raise NotImplementedError
91
118
 
92
- def side_measure(args: "Geometry.SideArg", cell_index: ElementIndex, coords: Coords):
93
- """Device function returning the measure determinant (e.g. volume, area) at a given point"""
119
+ @staticmethod
120
+ def side_deformation_gradient(args: "Geometry.CellArg", s: "Sample"):
121
+ """Device function returning the gradient of world position with respect to reference cell"""
122
+ raise NotImplementedError
123
+
124
+ @staticmethod
125
+ def side_inner_inverse_deformation_gradient(args: "Geometry.CellArg", side_index: ElementIndex, coords: Coords):
126
+ """Device function returning the matrix right-transforming a gradient w.r.t. inner cell space to a gradient w.r.t. world space
127
+ (i.e. the inverse deformation gradient)
128
+ """
94
129
  raise NotImplementedError
95
130
 
131
+ @staticmethod
132
+ def side_outer_inverse_deformation_gradient(args: "Geometry.CellArg", side_index: ElementIndex, coords: Coords):
133
+ """Device function returning the matrix right-transforming a gradient w.r.t. outer cell space to a gradient w.r.t. world space
134
+ (i.e. the inverse deformation gradient)
135
+ """
136
+ raise NotImplementedError
137
+
138
+ @staticmethod
96
139
  def side_measure(args: "Geometry.SideArg", s: "Sample"):
97
140
  """Device function returning the measure determinant (e.g. volume, area) at a given point"""
98
141
  raise NotImplementedError
99
142
 
143
+ @staticmethod
100
144
  def side_measure_ratio(args: "Geometry.SideArg", s: "Sample"):
101
145
  """Device function returning the ratio of the measure of a side to that of its neighbour cells"""
102
146
  raise NotImplementedError
103
147
 
148
+ @staticmethod
104
149
  def side_normal(args: "Geometry.SideArg", s: "Sample"):
105
150
  """Device function returning the element normal at a sample point"""
106
151
  raise NotImplementedError
107
152
 
153
+ @staticmethod
108
154
  def side_inner_cell_index(args: "Geometry.SideArg", side_index: ElementIndex):
109
155
  """Device function returning the inner cell index for a given side"""
110
156
  raise NotImplementedError
111
157
 
158
+ @staticmethod
112
159
  def side_outer_cell_index(args: "Geometry.SideArg", side_index: ElementIndex):
113
160
  """Device function returning the outer cell index for a given side"""
114
161
  raise NotImplementedError
162
+
163
+ @staticmethod
164
+ def side_inner_cell_coords(args: "Geometry.SideArg", side_index: ElementIndex, side_coords: Coords):
165
+ """Device function returning the coordinates of a point on a side in the inner cell"""
166
+ raise NotImplementedError
167
+
168
+ @staticmethod
169
+ def side_outer_cell_coords(args: "Geometry.SideArg", side_index: ElementIndex, side_coords: Coords):
170
+ """Device function returning the coordinates of a point on a side in the outer cell"""
171
+ raise NotImplementedError
172
+
173
+ @staticmethod
174
+ def side_from_cell_coords(
175
+ args: "Geometry.SideArg",
176
+ side_index: ElementIndex,
177
+ element_index: ElementIndex,
178
+ element_coords: Coords,
179
+ ):
180
+ """Device function converting coordinates on a cell to coordinates on a side, or ``OUTSIDE``"""
181
+ raise NotImplementedError
182
+
183
+ @staticmethod
184
+ def side_to_cell_arg(side_arg: "Geometry.SideArg"):
185
+ """Device function converting a side-related argument value to a cell-related argument value, for promoting trace samples to the full space"""
186
+ raise NotImplementedError