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.
- docs/conf.py +17 -5
- examples/env/env_ant.py +1 -1
- examples/env/env_cartpole.py +1 -1
- examples/env/env_humanoid.py +1 -1
- examples/env/env_usd.py +4 -1
- examples/env/environment.py +8 -9
- examples/example_dem.py +34 -33
- examples/example_diffray.py +364 -337
- examples/example_fluid.py +32 -23
- examples/example_jacobian_ik.py +97 -93
- examples/example_marching_cubes.py +6 -16
- examples/example_mesh.py +6 -16
- examples/example_mesh_intersect.py +16 -14
- examples/example_nvdb.py +14 -16
- examples/example_raycast.py +14 -13
- examples/example_raymarch.py +16 -23
- examples/example_render_opengl.py +19 -10
- examples/example_sim_cartpole.py +82 -78
- examples/example_sim_cloth.py +45 -48
- examples/example_sim_fk_grad.py +51 -44
- examples/example_sim_fk_grad_torch.py +47 -40
- examples/example_sim_grad_bounce.py +108 -133
- examples/example_sim_grad_cloth.py +99 -113
- examples/example_sim_granular.py +5 -6
- examples/{example_sim_sdf_shape.py → example_sim_granular_collision_sdf.py} +37 -26
- examples/example_sim_neo_hookean.py +51 -55
- examples/example_sim_particle_chain.py +4 -4
- examples/example_sim_quadruped.py +126 -81
- examples/example_sim_rigid_chain.py +54 -61
- examples/example_sim_rigid_contact.py +66 -70
- examples/example_sim_rigid_fem.py +3 -3
- examples/example_sim_rigid_force.py +1 -1
- examples/example_sim_rigid_gyroscopic.py +3 -4
- examples/example_sim_rigid_kinematics.py +28 -39
- examples/example_sim_trajopt.py +112 -110
- examples/example_sph.py +9 -8
- examples/example_wave.py +7 -7
- examples/fem/bsr_utils.py +30 -17
- examples/fem/example_apic_fluid.py +85 -69
- examples/fem/example_convection_diffusion.py +97 -93
- examples/fem/example_convection_diffusion_dg.py +142 -149
- examples/fem/example_convection_diffusion_dg0.py +141 -136
- examples/fem/example_deformed_geometry.py +146 -0
- examples/fem/example_diffusion.py +115 -84
- examples/fem/example_diffusion_3d.py +116 -86
- examples/fem/example_diffusion_mgpu.py +102 -79
- examples/fem/example_mixed_elasticity.py +139 -100
- examples/fem/example_navier_stokes.py +175 -162
- examples/fem/example_stokes.py +143 -111
- examples/fem/example_stokes_transfer.py +186 -157
- examples/fem/mesh_utils.py +59 -97
- examples/fem/plot_utils.py +138 -17
- tools/ci/publishing/build_nodes_info.py +54 -0
- warp/__init__.py +4 -3
- warp/__init__.pyi +1 -0
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +5 -3
- warp/build_dll.py +29 -9
- warp/builtins.py +836 -492
- warp/codegen.py +864 -553
- warp/config.py +3 -1
- warp/context.py +389 -172
- warp/fem/__init__.py +24 -6
- warp/fem/cache.py +318 -25
- warp/fem/dirichlet.py +7 -3
- warp/fem/domain.py +14 -0
- warp/fem/field/__init__.py +30 -38
- warp/fem/field/field.py +149 -0
- warp/fem/field/nodal_field.py +244 -138
- warp/fem/field/restriction.py +8 -6
- warp/fem/field/test.py +127 -59
- warp/fem/field/trial.py +117 -60
- warp/fem/geometry/__init__.py +5 -1
- warp/fem/geometry/deformed_geometry.py +271 -0
- warp/fem/geometry/element.py +24 -1
- warp/fem/geometry/geometry.py +86 -14
- warp/fem/geometry/grid_2d.py +112 -54
- warp/fem/geometry/grid_3d.py +134 -65
- warp/fem/geometry/hexmesh.py +953 -0
- warp/fem/geometry/partition.py +85 -33
- warp/fem/geometry/quadmesh_2d.py +532 -0
- warp/fem/geometry/tetmesh.py +451 -115
- warp/fem/geometry/trimesh_2d.py +197 -92
- warp/fem/integrate.py +534 -268
- warp/fem/operator.py +58 -31
- warp/fem/polynomial.py +11 -0
- warp/fem/quadrature/__init__.py +1 -1
- warp/fem/quadrature/pic_quadrature.py +150 -58
- warp/fem/quadrature/quadrature.py +209 -57
- warp/fem/space/__init__.py +230 -53
- warp/fem/space/basis_space.py +489 -0
- warp/fem/space/collocated_function_space.py +105 -0
- warp/fem/space/dof_mapper.py +49 -2
- warp/fem/space/function_space.py +90 -39
- warp/fem/space/grid_2d_function_space.py +149 -496
- warp/fem/space/grid_3d_function_space.py +173 -538
- warp/fem/space/hexmesh_function_space.py +352 -0
- warp/fem/space/partition.py +129 -76
- warp/fem/space/quadmesh_2d_function_space.py +369 -0
- warp/fem/space/restriction.py +46 -34
- warp/fem/space/shape/__init__.py +15 -0
- warp/fem/space/shape/cube_shape_function.py +738 -0
- warp/fem/space/shape/shape_function.py +103 -0
- warp/fem/space/shape/square_shape_function.py +611 -0
- warp/fem/space/shape/tet_shape_function.py +567 -0
- warp/fem/space/shape/triangle_shape_function.py +429 -0
- warp/fem/space/tetmesh_function_space.py +132 -1039
- warp/fem/space/topology.py +295 -0
- warp/fem/space/trimesh_2d_function_space.py +104 -742
- warp/fem/types.py +13 -11
- warp/fem/utils.py +335 -60
- warp/native/array.h +120 -34
- warp/native/builtin.h +101 -72
- warp/native/bvh.cpp +73 -325
- warp/native/bvh.cu +406 -23
- warp/native/bvh.h +22 -40
- warp/native/clang/clang.cpp +1 -0
- warp/native/crt.h +2 -0
- warp/native/cuda_util.cpp +8 -3
- warp/native/cuda_util.h +1 -0
- warp/native/exports.h +1522 -1243
- warp/native/intersect.h +19 -4
- warp/native/intersect_adj.h +8 -8
- warp/native/mat.h +76 -17
- warp/native/mesh.cpp +33 -108
- warp/native/mesh.cu +114 -18
- warp/native/mesh.h +395 -40
- warp/native/noise.h +272 -329
- warp/native/quat.h +51 -8
- warp/native/rand.h +44 -34
- warp/native/reduce.cpp +1 -1
- warp/native/sparse.cpp +4 -4
- warp/native/sparse.cu +163 -155
- warp/native/spatial.h +2 -2
- warp/native/temp_buffer.h +18 -14
- warp/native/vec.h +103 -21
- warp/native/warp.cpp +2 -1
- warp/native/warp.cu +28 -3
- warp/native/warp.h +4 -3
- warp/render/render_opengl.py +261 -109
- warp/sim/__init__.py +1 -2
- warp/sim/articulation.py +385 -185
- warp/sim/import_mjcf.py +59 -48
- warp/sim/import_urdf.py +15 -15
- warp/sim/import_usd.py +174 -102
- warp/sim/inertia.py +17 -18
- warp/sim/integrator_xpbd.py +4 -3
- warp/sim/model.py +330 -250
- warp/sim/render.py +1 -1
- warp/sparse.py +625 -152
- warp/stubs.py +341 -309
- warp/tape.py +9 -6
- warp/tests/__main__.py +3 -6
- warp/tests/assets/curlnoise_golden.npy +0 -0
- warp/tests/assets/pnoise_golden.npy +0 -0
- warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
- warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
- warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
- warp/tests/aux_test_unresolved_func.py +14 -0
- warp/tests/aux_test_unresolved_symbol.py +14 -0
- warp/tests/disabled_kinematics.py +239 -0
- warp/tests/run_coverage_serial.py +31 -0
- warp/tests/test_adam.py +103 -106
- warp/tests/test_arithmetic.py +94 -74
- warp/tests/test_array.py +82 -101
- warp/tests/test_array_reduce.py +57 -23
- warp/tests/test_atomic.py +64 -28
- warp/tests/test_bool.py +22 -12
- warp/tests/test_builtins_resolution.py +1292 -0
- warp/tests/test_bvh.py +18 -18
- warp/tests/test_closest_point_edge_edge.py +54 -57
- warp/tests/test_codegen.py +165 -134
- warp/tests/test_compile_consts.py +28 -20
- warp/tests/test_conditional.py +108 -24
- warp/tests/test_copy.py +10 -12
- warp/tests/test_ctypes.py +112 -88
- warp/tests/test_dense.py +21 -14
- warp/tests/test_devices.py +98 -0
- warp/tests/test_dlpack.py +75 -75
- warp/tests/test_examples.py +237 -0
- warp/tests/test_fabricarray.py +22 -24
- warp/tests/test_fast_math.py +15 -11
- warp/tests/test_fem.py +1034 -124
- warp/tests/test_fp16.py +23 -16
- warp/tests/test_func.py +187 -86
- warp/tests/test_generics.py +194 -49
- warp/tests/test_grad.py +123 -181
- warp/tests/test_grad_customs.py +176 -0
- warp/tests/test_hash_grid.py +35 -34
- warp/tests/test_import.py +10 -23
- warp/tests/test_indexedarray.py +24 -25
- warp/tests/test_intersect.py +18 -9
- warp/tests/test_large.py +141 -0
- warp/tests/test_launch.py +14 -41
- warp/tests/test_lerp.py +64 -65
- warp/tests/test_lvalue.py +493 -0
- warp/tests/test_marching_cubes.py +12 -13
- warp/tests/test_mat.py +517 -2898
- warp/tests/test_mat_lite.py +115 -0
- warp/tests/test_mat_scalar_ops.py +2889 -0
- warp/tests/test_math.py +103 -9
- warp/tests/test_matmul.py +304 -69
- warp/tests/test_matmul_lite.py +410 -0
- warp/tests/test_mesh.py +60 -22
- warp/tests/test_mesh_query_aabb.py +21 -25
- warp/tests/test_mesh_query_point.py +111 -22
- warp/tests/test_mesh_query_ray.py +12 -24
- warp/tests/test_mlp.py +30 -22
- warp/tests/test_model.py +92 -89
- warp/tests/test_modules_lite.py +39 -0
- warp/tests/test_multigpu.py +88 -114
- warp/tests/test_noise.py +12 -11
- warp/tests/test_operators.py +16 -20
- warp/tests/test_options.py +11 -11
- warp/tests/test_pinned.py +17 -18
- warp/tests/test_print.py +32 -11
- warp/tests/test_quat.py +275 -129
- warp/tests/test_rand.py +18 -16
- warp/tests/test_reload.py +38 -34
- warp/tests/test_rounding.py +50 -43
- warp/tests/test_runlength_encode.py +168 -20
- warp/tests/test_smoothstep.py +9 -11
- warp/tests/test_snippet.py +143 -0
- warp/tests/test_sparse.py +261 -63
- warp/tests/test_spatial.py +276 -243
- warp/tests/test_streams.py +110 -85
- warp/tests/test_struct.py +268 -63
- warp/tests/test_tape.py +39 -21
- warp/tests/test_torch.py +90 -86
- warp/tests/test_transient_module.py +10 -12
- warp/tests/test_types.py +363 -0
- warp/tests/test_utils.py +451 -0
- warp/tests/test_vec.py +354 -2050
- warp/tests/test_vec_lite.py +73 -0
- warp/tests/test_vec_scalar_ops.py +2099 -0
- warp/tests/test_volume.py +418 -376
- warp/tests/test_volume_write.py +124 -134
- warp/tests/unittest_serial.py +35 -0
- warp/tests/unittest_suites.py +291 -0
- warp/tests/unittest_utils.py +342 -0
- warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
- warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
- warp/thirdparty/appdirs.py +36 -45
- warp/thirdparty/unittest_parallel.py +589 -0
- warp/types.py +622 -211
- warp/utils.py +54 -393
- warp_lang-1.0.0b6.dist-info/METADATA +238 -0
- warp_lang-1.0.0b6.dist-info/RECORD +409 -0
- {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
- examples/example_cache_management.py +0 -40
- examples/example_multigpu.py +0 -54
- examples/example_struct.py +0 -65
- examples/fem/example_stokes_transfer_3d.py +0 -210
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/fem/field/discrete_field.py +0 -80
- warp/fem/space/nodal_function_space.py +0 -233
- warp/tests/test_all.py +0 -223
- warp/tests/test_array_scan.py +0 -60
- warp/tests/test_base.py +0 -208
- warp/tests/test_unresolved_func.py +0 -7
- warp/tests/test_unresolved_symbol.py +0 -7
- warp_lang-1.0.0b2.dist-info/METADATA +0 -26
- warp_lang-1.0.0b2.dist-info/RECORD +0 -380
- /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
- /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
- /warp/tests/{test_square.py → aux_test_square.py} +0 -0
- {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
- {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
warp/fem/types.py
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import warp as wp
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
vec4i = wp.types.vector(length=4, dtype=wp.int32)
|
|
8
|
-
vec8i = wp.types.vector(length=8, dtype=wp.int32)
|
|
9
|
-
|
|
10
|
-
vec6 = wp.types.vector(length=6, dtype=wp.float32)
|
|
3
|
+
# kept to avoid breaking existing example code, no longer used internally
|
|
4
|
+
vec2i = wp.vec2i
|
|
5
|
+
vec3i = wp.vec3i
|
|
6
|
+
vec4i = wp.vec4i
|
|
11
7
|
|
|
12
8
|
Coords = wp.vec3
|
|
13
9
|
OUTSIDE = wp.constant(-1.0e8)
|
|
@@ -20,7 +16,7 @@ NULL_ELEMENT_INDEX = wp.constant(-1)
|
|
|
20
16
|
NULL_QP_INDEX = wp.constant(-1)
|
|
21
17
|
NULL_NODE_INDEX = wp.constant(-1)
|
|
22
18
|
|
|
23
|
-
DofIndex = vec2i
|
|
19
|
+
DofIndex = wp.vec2i
|
|
24
20
|
"""Opaque descriptor for indexing degrees of freedom within elements"""
|
|
25
21
|
NULL_DOF_INDEX = wp.constant(DofIndex(-1, -1))
|
|
26
22
|
|
|
@@ -59,12 +55,18 @@ class Sample:
|
|
|
59
55
|
"""For bilinear form assembly, index of the trial degree-of-freedom currently being considered"""
|
|
60
56
|
|
|
61
57
|
|
|
58
|
+
@wp.func
|
|
59
|
+
def make_free_sample(element_index: ElementIndex, element_coords: Coords):
|
|
60
|
+
"""Returns a :class:`Sample` that is not associated to any quadrature point or dof"""
|
|
61
|
+
return Sample(element_index, element_coords, NULL_QP_INDEX, 0.0, NULL_DOF_INDEX, NULL_DOF_INDEX)
|
|
62
|
+
|
|
63
|
+
|
|
62
64
|
class Field:
|
|
63
65
|
"""
|
|
64
66
|
Tag for field-like integrand arguments
|
|
65
67
|
"""
|
|
66
68
|
|
|
67
|
-
call_operator: "
|
|
69
|
+
call_operator: "warp.fem.operator.Operator" = None # Set in operator.py
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
class Domain:
|
|
@@ -72,4 +74,4 @@ class Domain:
|
|
|
72
74
|
Tag for domain-like integrand arguments
|
|
73
75
|
"""
|
|
74
76
|
|
|
75
|
-
call_operator: "
|
|
77
|
+
call_operator: "warp.fem.operator.Operator" = None # Set in operator.py
|
warp/fem/utils.py
CHANGED
|
@@ -1,83 +1,123 @@
|
|
|
1
1
|
from typing import Any, Tuple
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
from warp.utils import radix_sort_pairs, runlength_encode, array_scan
|
|
3
|
+
import numpy as np
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import warp as wp
|
|
6
|
+
from warp.fem.cache import (
|
|
7
|
+
Temporary,
|
|
8
|
+
TemporaryStore,
|
|
9
|
+
borrow_temporary,
|
|
10
|
+
borrow_temporary_like,
|
|
11
|
+
)
|
|
12
|
+
from warp.utils import array_scan, radix_sort_pairs, runlength_encode
|
|
7
13
|
|
|
8
14
|
|
|
9
15
|
@wp.func
|
|
10
|
-
def generalized_outer(x: Any, y:
|
|
16
|
+
def generalized_outer(x: Any, y: Any):
|
|
17
|
+
"""Generalized outer product allowing for the first argument to be a scalar"""
|
|
11
18
|
return wp.outer(x, y)
|
|
12
19
|
|
|
13
20
|
|
|
14
21
|
@wp.func
|
|
15
|
-
def generalized_outer(x:
|
|
16
|
-
return
|
|
22
|
+
def generalized_outer(x: wp.float32, y: wp.vec2):
|
|
23
|
+
return x * y
|
|
17
24
|
|
|
18
25
|
|
|
19
26
|
@wp.func
|
|
20
|
-
def generalized_outer(x:
|
|
27
|
+
def generalized_outer(x: wp.float32, y: wp.vec3):
|
|
21
28
|
return x * y
|
|
22
29
|
|
|
23
30
|
|
|
24
31
|
@wp.func
|
|
25
|
-
def
|
|
26
|
-
|
|
32
|
+
def generalized_inner(x: Any, y: Any):
|
|
33
|
+
"""Generalized inner product allowing for the first argument to be a tensor"""
|
|
34
|
+
return wp.dot(x, y)
|
|
27
35
|
|
|
28
36
|
|
|
29
37
|
@wp.func
|
|
30
|
-
def
|
|
31
|
-
|
|
32
|
-
t[coord] = 1.0
|
|
33
|
-
return t
|
|
38
|
+
def generalized_inner(x: wp.mat22, y: wp.vec2):
|
|
39
|
+
return x[0] * y[0] + x[1] * y[1]
|
|
34
40
|
|
|
35
41
|
|
|
36
42
|
@wp.func
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
def generalized_inner(x: wp.mat33, y: wp.vec3):
|
|
44
|
+
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@wp.func
|
|
48
|
+
def apply_right(x: Any, y: Any):
|
|
49
|
+
"""Performs x y multiplication with y a square matrix and x either a row-vector or a matrix.
|
|
50
|
+
Will be removed once native @ operator is implemented.
|
|
51
|
+
"""
|
|
52
|
+
return x * y
|
|
41
53
|
|
|
42
54
|
|
|
43
55
|
@wp.func
|
|
44
|
-
def
|
|
45
|
-
|
|
56
|
+
def apply_right(x: wp.vec2, y: wp.mat22):
|
|
57
|
+
return x[0] * y[0] + x[1] * y[1]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@wp.func
|
|
61
|
+
def apply_right(x: wp.vec3, y: wp.mat33):
|
|
62
|
+
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@wp.func
|
|
66
|
+
def unit_element(template_type: Any, coord: int):
|
|
67
|
+
"""Returns a instance of `template_type` with a single coordinate set to 1 in the canonical basis"""
|
|
68
|
+
|
|
69
|
+
t = type(template_type)(0.0)
|
|
46
70
|
t[coord] = 1.0
|
|
47
71
|
return t
|
|
48
72
|
|
|
49
73
|
|
|
74
|
+
@wp.func
|
|
75
|
+
def unit_element(template_type: wp.float32, coord: int):
|
|
76
|
+
return 1.0
|
|
77
|
+
|
|
78
|
+
|
|
50
79
|
@wp.func
|
|
51
80
|
def unit_element(template_type: wp.mat22, coord: int):
|
|
52
81
|
t = wp.mat22(0.0)
|
|
53
|
-
|
|
82
|
+
row = coord // 2
|
|
83
|
+
col = coord - 2 * row
|
|
84
|
+
t[row, col] = 1.0
|
|
54
85
|
return t
|
|
55
86
|
|
|
56
87
|
|
|
57
88
|
@wp.func
|
|
58
89
|
def unit_element(template_type: wp.mat33, coord: int):
|
|
59
|
-
t = wp.
|
|
60
|
-
|
|
90
|
+
t = wp.mat33(0.0)
|
|
91
|
+
row = coord // 3
|
|
92
|
+
col = coord - 3 * row
|
|
93
|
+
t[row, col] = 1.0
|
|
61
94
|
return t
|
|
62
95
|
|
|
63
96
|
|
|
64
97
|
@wp.func
|
|
65
|
-
def symmetric_part(x:
|
|
66
|
-
|
|
67
|
-
return
|
|
98
|
+
def symmetric_part(x: Any):
|
|
99
|
+
"""Symmetric part of a square tensor"""
|
|
100
|
+
return 0.5 * (x + wp.transpose(x))
|
|
68
101
|
|
|
69
102
|
|
|
70
103
|
@wp.func
|
|
71
|
-
def
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
def skew_part(x: wp.mat22):
|
|
105
|
+
"""Skew part of a 2x2 tensor as corresponding rotation angle"""
|
|
106
|
+
return 0.5 * (x[1, 0] - x[0, 1])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@wp.func
|
|
110
|
+
def skew_part(x: wp.mat33):
|
|
111
|
+
"""Skew part of a 3x3 tensor as the corresponding rotation vector"""
|
|
112
|
+
a = 0.5 * (x[2, 1] - x[1, 2])
|
|
113
|
+
b = 0.5 * (x[0, 2] - x[2, 0])
|
|
114
|
+
c = 0.5 * (x[1, 0] - x[0, 1])
|
|
115
|
+
return wp.vec3(a, b, c)
|
|
76
116
|
|
|
77
117
|
|
|
78
118
|
def compress_node_indices(
|
|
79
|
-
node_count: int, node_indices: wp.array(dtype=int)
|
|
80
|
-
) -> Tuple[
|
|
119
|
+
node_count: int, node_indices: wp.array(dtype=int), temporary_store: TemporaryStore = None
|
|
120
|
+
) -> Tuple[Temporary, Temporary, int, Temporary]:
|
|
81
121
|
"""
|
|
82
122
|
Compress an unsorted list of node indices into:
|
|
83
123
|
- a node_offsets array, giving for each node the start offset of corresponding indices in sorted_array_indices
|
|
@@ -87,8 +127,14 @@ def compress_node_indices(
|
|
|
87
127
|
"""
|
|
88
128
|
|
|
89
129
|
index_count = node_indices.size
|
|
90
|
-
|
|
91
|
-
|
|
130
|
+
|
|
131
|
+
sorted_node_indices_temp = borrow_temporary(
|
|
132
|
+
temporary_store, shape=2 * index_count, dtype=int, device=node_indices.device
|
|
133
|
+
)
|
|
134
|
+
sorted_array_indices_temp = borrow_temporary_like(sorted_node_indices_temp, temporary_store)
|
|
135
|
+
|
|
136
|
+
sorted_node_indices = sorted_node_indices_temp.array
|
|
137
|
+
sorted_array_indices = sorted_array_indices_temp.array
|
|
92
138
|
|
|
93
139
|
wp.copy(dest=sorted_node_indices, src=node_indices, count=index_count)
|
|
94
140
|
|
|
@@ -104,14 +150,44 @@ def compress_node_indices(
|
|
|
104
150
|
radix_sort_pairs(sorted_node_indices, sorted_array_indices, count=index_count)
|
|
105
151
|
|
|
106
152
|
# Build prefix sum of number of elements per node
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
153
|
+
unique_node_indices_temp = borrow_temporary(
|
|
154
|
+
temporary_store, shape=index_count, dtype=int, device=node_indices.device
|
|
155
|
+
)
|
|
156
|
+
node_element_counts_temp = borrow_temporary(
|
|
157
|
+
temporary_store, shape=index_count, dtype=int, device=node_indices.device
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
unique_node_indices = unique_node_indices_temp.array
|
|
161
|
+
node_element_counts = node_element_counts_temp.array
|
|
162
|
+
|
|
163
|
+
unique_node_count_dev = borrow_temporary(temporary_store, shape=(1,), dtype=int, device=sorted_node_indices.device)
|
|
164
|
+
runlength_encode(
|
|
165
|
+
sorted_node_indices,
|
|
166
|
+
unique_node_indices,
|
|
167
|
+
node_element_counts,
|
|
168
|
+
value_count=index_count,
|
|
169
|
+
run_count=unique_node_count_dev.array,
|
|
111
170
|
)
|
|
112
171
|
|
|
172
|
+
# Transfer unique node count to host
|
|
173
|
+
if node_indices.device.is_cuda:
|
|
174
|
+
unique_node_count_host = borrow_temporary(temporary_store, shape=(1,), dtype=int, pinned=True, device="cpu")
|
|
175
|
+
wp.copy(src=unique_node_count_dev.array, dest=unique_node_count_host.array, count=1)
|
|
176
|
+
wp.synchronize_stream(wp.get_stream(node_indices.device))
|
|
177
|
+
unique_node_count_dev.release()
|
|
178
|
+
unique_node_count = int(unique_node_count_host.array.numpy()[0])
|
|
179
|
+
unique_node_count_host.release()
|
|
180
|
+
else:
|
|
181
|
+
unique_node_count = int(unique_node_count_dev.array.numpy()[0])
|
|
182
|
+
unique_node_count_dev.release()
|
|
183
|
+
|
|
113
184
|
# Scatter seen run counts to global array of element count per node
|
|
114
|
-
|
|
185
|
+
node_offsets_temp = borrow_temporary(
|
|
186
|
+
temporary_store, shape=(node_count + 1), device=node_element_counts.device, dtype=int
|
|
187
|
+
)
|
|
188
|
+
node_offsets = node_offsets_temp.array
|
|
189
|
+
|
|
190
|
+
node_offsets.zero_()
|
|
115
191
|
wp.launch(
|
|
116
192
|
kernel=_scatter_node_counts,
|
|
117
193
|
dim=unique_node_count,
|
|
@@ -122,51 +198,47 @@ def compress_node_indices(
|
|
|
122
198
|
# Prefix sum of number of elements per node
|
|
123
199
|
array_scan(node_offsets, node_offsets, inclusive=True)
|
|
124
200
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
_pinned_temp_count_buffer = {}
|
|
129
|
-
|
|
201
|
+
sorted_node_indices_temp.release()
|
|
202
|
+
node_element_counts_temp.release()
|
|
130
203
|
|
|
131
|
-
|
|
132
|
-
device = str(device)
|
|
133
|
-
if device not in _pinned_temp_count_buffer:
|
|
134
|
-
_pinned_temp_count_buffer[device] = wp.empty(shape=(1,), dtype=int, pinned=True, device="cpu")
|
|
204
|
+
return node_offsets_temp, sorted_array_indices_temp, unique_node_count, unique_node_indices_temp
|
|
135
205
|
|
|
136
|
-
return _pinned_temp_count_buffer[device]
|
|
137
206
|
|
|
138
|
-
|
|
139
|
-
|
|
207
|
+
def masked_indices(
|
|
208
|
+
mask: wp.array, missing_index=-1, temporary_store: TemporaryStore = None
|
|
209
|
+
) -> Tuple[Temporary, Temporary]:
|
|
140
210
|
"""
|
|
141
211
|
From an array of boolean masks (must be either 0 or 1), returns:
|
|
142
212
|
- The list of indices for which the mask is 1
|
|
143
213
|
- A map associating to each element of the input mask array its local index if non-zero, or missing_index if zero.
|
|
144
214
|
"""
|
|
145
215
|
|
|
146
|
-
|
|
216
|
+
offsets_temp = borrow_temporary_like(mask, temporary_store)
|
|
217
|
+
offsets = offsets_temp.array
|
|
147
218
|
|
|
148
219
|
wp.utils.array_scan(mask, offsets, inclusive=True)
|
|
149
220
|
|
|
150
221
|
# Get back total counts on host
|
|
151
222
|
if offsets.device.is_cuda:
|
|
152
|
-
|
|
153
|
-
wp.copy(dest=
|
|
154
|
-
wp.synchronize_stream(wp.get_stream())
|
|
155
|
-
masked_count = int(
|
|
223
|
+
masked_count_temp = borrow_temporary(temporary_store, shape=1, dtype=int, pinned=True, device="cpu")
|
|
224
|
+
wp.copy(dest=masked_count_temp.array, src=offsets, src_offset=offsets.shape[0] - 1, count=1)
|
|
225
|
+
wp.synchronize_stream(wp.get_stream(offsets.device))
|
|
226
|
+
masked_count = int(masked_count_temp.array.numpy()[0])
|
|
227
|
+
masked_count_temp.release()
|
|
156
228
|
else:
|
|
157
229
|
masked_count = int(offsets.numpy()[-1])
|
|
158
230
|
|
|
159
231
|
# Convert counts to indices
|
|
160
|
-
|
|
232
|
+
indices_temp = borrow_temporary(temporary_store, shape=masked_count, device=mask.device, dtype=int)
|
|
161
233
|
|
|
162
234
|
wp.launch(
|
|
163
235
|
kernel=_masked_indices_kernel,
|
|
164
236
|
dim=offsets.shape,
|
|
165
|
-
inputs=[missing_index, mask, offsets,
|
|
237
|
+
inputs=[missing_index, mask, offsets, indices_temp.array, offsets],
|
|
166
238
|
device=mask.device,
|
|
167
239
|
)
|
|
168
240
|
|
|
169
|
-
return
|
|
241
|
+
return indices_temp, offsets_temp
|
|
170
242
|
|
|
171
243
|
|
|
172
244
|
def array_axpy(x: wp.array, y: wp.array, alpha: float = 1.0, beta: float = 1.0):
|
|
@@ -177,7 +249,7 @@ def array_axpy(x: wp.array, y: wp.array, alpha: float = 1.0, beta: float = 1.0):
|
|
|
177
249
|
alpha = dtype(alpha)
|
|
178
250
|
beta = dtype(beta)
|
|
179
251
|
|
|
180
|
-
if x.dtype
|
|
252
|
+
if not wp.types.types_equal(x.dtype, y.dtype) or x.shape != y.shape or x.device != y.device:
|
|
181
253
|
raise ValueError("x and y arrays must have same dat atype, shape and device")
|
|
182
254
|
|
|
183
255
|
wp.launch(kernel=_array_axpy_kernel, dim=x.shape, device=x.device, inputs=[x, y, alpha, beta])
|
|
@@ -218,3 +290,206 @@ def _masked_indices_kernel(
|
|
|
218
290
|
def _array_axpy_kernel(x: wp.array(dtype=Any), y: wp.array(dtype=Any), alpha: Any, beta: Any):
|
|
219
291
|
i = wp.tid()
|
|
220
292
|
y[i] = beta * y[i] + alpha * x[i]
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def grid_to_tris(Nx: int, Ny: int):
|
|
296
|
+
"""Constructs a triangular mesh topology by dividing each cell of a dense 2D grid into two triangles.
|
|
297
|
+
|
|
298
|
+
The resulting triangles will be oriented counter-clockwise assuming that `y` is the fastest moving index direction
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
Nx: Resolution of the grid along `x` dimension
|
|
302
|
+
Ny: Resolution of the grid along `y` dimension
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
Array of shape (2 * Nx * Ny, 3) containing vertex indices for each triangle
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
cx, cy = np.meshgrid(np.arange(Nx, dtype=int), np.arange(Ny, dtype=int), indexing="ij")
|
|
309
|
+
|
|
310
|
+
vidx = np.transpose(
|
|
311
|
+
np.array(
|
|
312
|
+
[
|
|
313
|
+
(Ny + 1) * cx + cy,
|
|
314
|
+
(Ny + 1) * (cx + 1) + cy,
|
|
315
|
+
(Ny + 1) * (cx + 1) + (cy + 1),
|
|
316
|
+
(Ny + 1) * cx + cy,
|
|
317
|
+
(Ny + 1) * (cx + 1) + (cy + 1),
|
|
318
|
+
(Ny + 1) * (cx) + (cy + 1),
|
|
319
|
+
]
|
|
320
|
+
)
|
|
321
|
+
).reshape((-1, 3))
|
|
322
|
+
|
|
323
|
+
return vidx
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def grid_to_tets(Nx: int, Ny: int, Nz: int):
|
|
327
|
+
"""Constructs a tetrahedral mesh topology by diving each cell of a dense 3D grid into five tetrahedrons
|
|
328
|
+
|
|
329
|
+
The resulting tets have positive volume assuming that `z` is the fastest moving index direction
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
Nx: Resolution of the grid along `x` dimension
|
|
333
|
+
Ny: Resolution of the grid along `y` dimension
|
|
334
|
+
Nz: Resolution of the grid along `z` dimension
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
Array of shape (5 * Nx * Ny * Nz, 4) containing vertex indices for each tet
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
# Global node indices for each cell
|
|
341
|
+
cx, cy, cz = np.meshgrid(
|
|
342
|
+
np.arange(Nx, dtype=int), np.arange(Ny, dtype=int), np.arange(Nz, dtype=int), indexing="ij"
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
grid_vidx = np.array(
|
|
346
|
+
[
|
|
347
|
+
(Ny + 1) * (Nz + 1) * cx + (Nz + 1) * cy + cz,
|
|
348
|
+
(Ny + 1) * (Nz + 1) * cx + (Nz + 1) * cy + cz + 1,
|
|
349
|
+
(Ny + 1) * (Nz + 1) * cx + (Nz + 1) * (cy + 1) + cz,
|
|
350
|
+
(Ny + 1) * (Nz + 1) * cx + (Nz + 1) * (cy + 1) + cz + 1,
|
|
351
|
+
(Ny + 1) * (Nz + 1) * (cx + 1) + (Nz + 1) * cy + cz,
|
|
352
|
+
(Ny + 1) * (Nz + 1) * (cx + 1) + (Nz + 1) * cy + cz + 1,
|
|
353
|
+
(Ny + 1) * (Nz + 1) * (cx + 1) + (Nz + 1) * (cy + 1) + cz,
|
|
354
|
+
(Ny + 1) * (Nz + 1) * (cx + 1) + (Nz + 1) * (cy + 1) + cz + 1,
|
|
355
|
+
]
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
# decompose grid cells into 5 tets
|
|
359
|
+
tet_vidx = np.array(
|
|
360
|
+
[
|
|
361
|
+
[0, 1, 2, 4],
|
|
362
|
+
[3, 2, 1, 7],
|
|
363
|
+
[5, 1, 7, 4],
|
|
364
|
+
[6, 7, 4, 2],
|
|
365
|
+
[4, 1, 2, 7],
|
|
366
|
+
]
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
# Convert to 3d index coordinates
|
|
370
|
+
vidx_coords = np.array(
|
|
371
|
+
[
|
|
372
|
+
[0, 0, 0],
|
|
373
|
+
[0, 0, 1],
|
|
374
|
+
[0, 1, 0],
|
|
375
|
+
[0, 1, 1],
|
|
376
|
+
[1, 0, 0],
|
|
377
|
+
[1, 0, 1],
|
|
378
|
+
[1, 1, 0],
|
|
379
|
+
[1, 1, 1],
|
|
380
|
+
]
|
|
381
|
+
)
|
|
382
|
+
tet_coords = vidx_coords[tet_vidx]
|
|
383
|
+
|
|
384
|
+
# Symmetry bits for each cell
|
|
385
|
+
ox, oy, oz = np.meshgrid(
|
|
386
|
+
np.arange(Nx, dtype=int) % 2, np.arange(Ny, dtype=int) % 2, np.arange(Nz, dtype=int) % 2, indexing="ij"
|
|
387
|
+
)
|
|
388
|
+
tet_coords = np.broadcast_to(tet_coords, shape=(*ox.shape, *tet_coords.shape))
|
|
389
|
+
|
|
390
|
+
# Flip coordinates according to symmetry
|
|
391
|
+
ox_bk = np.broadcast_to(ox.reshape(*ox.shape, 1, 1), tet_coords.shape[:-1])
|
|
392
|
+
oy_bk = np.broadcast_to(oy.reshape(*oy.shape, 1, 1), tet_coords.shape[:-1])
|
|
393
|
+
oz_bk = np.broadcast_to(oz.reshape(*oz.shape, 1, 1), tet_coords.shape[:-1])
|
|
394
|
+
|
|
395
|
+
tet_coords_x = tet_coords[..., 0] ^ ox_bk
|
|
396
|
+
tet_coords_y = tet_coords[..., 1] ^ oy_bk
|
|
397
|
+
tet_coords_z = tet_coords[..., 2] ^ oz_bk
|
|
398
|
+
|
|
399
|
+
# Back to local vertex indices
|
|
400
|
+
corner_indices = 4 * tet_coords_x + 2 * tet_coords_y + tet_coords_z
|
|
401
|
+
|
|
402
|
+
# Now go from cell-local to global node indices
|
|
403
|
+
# There must be a nicer way than this, but for small grids this works
|
|
404
|
+
|
|
405
|
+
corner_indices = corner_indices.reshape(-1, 4)
|
|
406
|
+
|
|
407
|
+
grid_vidx = grid_vidx.reshape((8, -1, 1))
|
|
408
|
+
grid_vidx = np.broadcast_to(grid_vidx, shape=(8, grid_vidx.shape[1], 5))
|
|
409
|
+
grid_vidx = grid_vidx.reshape((8, -1))
|
|
410
|
+
|
|
411
|
+
node_indices = np.arange(corner_indices.shape[0])
|
|
412
|
+
tet_grid_vidx = np.transpose(
|
|
413
|
+
[
|
|
414
|
+
grid_vidx[corner_indices[:, 0], node_indices],
|
|
415
|
+
grid_vidx[corner_indices[:, 1], node_indices],
|
|
416
|
+
grid_vidx[corner_indices[:, 2], node_indices],
|
|
417
|
+
grid_vidx[corner_indices[:, 3], node_indices],
|
|
418
|
+
]
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
return tet_grid_vidx
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def grid_to_quads(Nx: int, Ny: int):
|
|
425
|
+
"""Constructs a quadrilateral mesh topology from a dense 2D grid
|
|
426
|
+
|
|
427
|
+
The resulting quads will be indexed counter-clockwise
|
|
428
|
+
|
|
429
|
+
Args:
|
|
430
|
+
Nx: Resolution of the grid along `x` dimension
|
|
431
|
+
Ny: Resolution of the grid along `y` dimension
|
|
432
|
+
|
|
433
|
+
Returns:
|
|
434
|
+
Array of shape (Nx * Ny, 4) containing vertex indices for each quadrilateral
|
|
435
|
+
"""
|
|
436
|
+
|
|
437
|
+
quad_vtx = np.array(
|
|
438
|
+
[
|
|
439
|
+
[0, 0],
|
|
440
|
+
[1, 0],
|
|
441
|
+
[1, 1],
|
|
442
|
+
[0, 1],
|
|
443
|
+
]
|
|
444
|
+
).T
|
|
445
|
+
|
|
446
|
+
quads = np.stack(np.meshgrid(np.arange(0, Nx), np.arange(0, Ny), indexing="ij"))
|
|
447
|
+
|
|
448
|
+
quads_vtx_shape = (*quads.shape, quad_vtx.shape[1])
|
|
449
|
+
quads_vtx = np.broadcast_to(quads.reshape(*quads.shape, 1), quads_vtx_shape) + np.broadcast_to(
|
|
450
|
+
quad_vtx.reshape(2, 1, 1, quad_vtx.shape[1]), quads_vtx_shape
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
quad_vtx_indices = quads_vtx[0] * (Ny + 1) + quads_vtx[1]
|
|
454
|
+
|
|
455
|
+
return quad_vtx_indices.reshape(-1, 4)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def grid_to_hexes(Nx: int, Ny: int, Nz: int):
|
|
459
|
+
"""Constructs a hexahedral mesh topology from a dense 3D grid
|
|
460
|
+
|
|
461
|
+
The resulting hexes will be indexed following usual convention assuming that `z` is the fastest moving index direction
|
|
462
|
+
(counter-clockwise bottom vertices, then counter-clockwise top vertices)
|
|
463
|
+
|
|
464
|
+
Args:
|
|
465
|
+
Nx: Resolution of the grid along `x` dimension
|
|
466
|
+
Ny: Resolution of the grid along `y` dimension
|
|
467
|
+
Nz: Resolution of the grid along `z` dimension
|
|
468
|
+
|
|
469
|
+
Returns:
|
|
470
|
+
Array of shape (Nx * Ny * Nz, 8) containing vertex indices for each hexaedron
|
|
471
|
+
"""
|
|
472
|
+
|
|
473
|
+
hex_vtx = np.array(
|
|
474
|
+
[
|
|
475
|
+
[0, 0, 0],
|
|
476
|
+
[1, 0, 0],
|
|
477
|
+
[1, 1, 0],
|
|
478
|
+
[0, 1, 0],
|
|
479
|
+
[0, 0, 1],
|
|
480
|
+
[1, 0, 1],
|
|
481
|
+
[1, 1, 1],
|
|
482
|
+
[0, 1, 1],
|
|
483
|
+
]
|
|
484
|
+
).T
|
|
485
|
+
|
|
486
|
+
hexes = np.stack(np.meshgrid(np.arange(0, Nx), np.arange(0, Ny), np.arange(0, Nz), indexing="ij"))
|
|
487
|
+
|
|
488
|
+
hexes_vtx_shape = (*hexes.shape, hex_vtx.shape[1])
|
|
489
|
+
hexes_vtx = np.broadcast_to(hexes.reshape(*hexes.shape, 1), hexes_vtx_shape) + np.broadcast_to(
|
|
490
|
+
hex_vtx.reshape(3, 1, 1, 1, hex_vtx.shape[1]), hexes_vtx_shape
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
hexes_vtx_indices = hexes_vtx[0] * (Nz + 1) * (Ny + 1) + hexes_vtx[1] * (Nz + 1) + hexes_vtx[2]
|
|
494
|
+
|
|
495
|
+
return hexes_vtx_indices.reshape(-1, 8)
|