warp-lang 1.1.0__py3-none-macosx_10_13_universal2.whl → 1.2.1__py3-none-macosx_10_13_universal2.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.
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +10 -37
- warp/build_dll.py +2 -2
- warp/builtins.py +274 -6
- warp/codegen.py +51 -4
- warp/config.py +2 -2
- warp/constants.py +4 -0
- warp/context.py +422 -203
- warp/examples/benchmarks/benchmark_api.py +0 -2
- warp/examples/benchmarks/benchmark_cloth_warp.py +0 -1
- warp/examples/benchmarks/benchmark_launches.py +0 -2
- warp/examples/core/example_dem.py +0 -2
- warp/examples/core/example_fluid.py +0 -2
- warp/examples/core/example_graph_capture.py +0 -2
- warp/examples/core/example_marching_cubes.py +0 -2
- warp/examples/core/example_mesh.py +0 -2
- warp/examples/core/example_mesh_intersect.py +0 -2
- warp/examples/core/example_nvdb.py +0 -2
- warp/examples/core/example_raycast.py +0 -2
- warp/examples/core/example_raymarch.py +0 -2
- warp/examples/core/example_render_opengl.py +0 -2
- warp/examples/core/example_sph.py +0 -2
- warp/examples/core/example_torch.py +0 -3
- warp/examples/core/example_wave.py +0 -2
- warp/examples/fem/example_apic_fluid.py +140 -115
- warp/examples/fem/example_burgers.py +262 -0
- warp/examples/fem/example_convection_diffusion.py +0 -2
- warp/examples/fem/example_convection_diffusion_dg.py +0 -2
- warp/examples/fem/example_deformed_geometry.py +0 -2
- warp/examples/fem/example_diffusion.py +0 -2
- warp/examples/fem/example_diffusion_3d.py +5 -4
- warp/examples/fem/example_diffusion_mgpu.py +0 -2
- warp/examples/fem/example_mixed_elasticity.py +0 -2
- warp/examples/fem/example_navier_stokes.py +0 -2
- warp/examples/fem/example_stokes.py +0 -2
- warp/examples/fem/example_stokes_transfer.py +0 -2
- warp/examples/optim/example_bounce.py +0 -2
- warp/examples/optim/example_cloth_throw.py +0 -2
- warp/examples/optim/example_diffray.py +0 -2
- warp/examples/optim/example_drone.py +0 -2
- warp/examples/optim/example_inverse_kinematics.py +0 -2
- warp/examples/optim/example_inverse_kinematics_torch.py +0 -2
- warp/examples/optim/example_spring_cage.py +0 -2
- warp/examples/optim/example_trajectory.py +0 -2
- warp/examples/optim/example_walker.py +0 -2
- warp/examples/sim/example_cartpole.py +0 -2
- warp/examples/sim/example_cloth.py +0 -2
- warp/examples/sim/example_granular.py +0 -2
- warp/examples/sim/example_granular_collision_sdf.py +0 -2
- warp/examples/sim/example_jacobian_ik.py +0 -2
- warp/examples/sim/example_particle_chain.py +0 -2
- warp/examples/sim/example_quadruped.py +0 -2
- warp/examples/sim/example_rigid_chain.py +0 -2
- warp/examples/sim/example_rigid_contact.py +0 -2
- warp/examples/sim/example_rigid_force.py +0 -2
- warp/examples/sim/example_rigid_gyroscopic.py +0 -2
- warp/examples/sim/example_rigid_soft_contact.py +0 -2
- warp/examples/sim/example_soft_body.py +0 -2
- warp/fem/__init__.py +1 -0
- warp/fem/cache.py +3 -1
- warp/fem/geometry/__init__.py +1 -0
- warp/fem/geometry/element.py +4 -0
- warp/fem/geometry/grid_3d.py +0 -4
- warp/fem/geometry/nanogrid.py +455 -0
- warp/fem/integrate.py +63 -9
- warp/fem/space/__init__.py +43 -158
- warp/fem/space/basis_space.py +34 -0
- warp/fem/space/collocated_function_space.py +1 -1
- warp/fem/space/grid_2d_function_space.py +13 -132
- warp/fem/space/grid_3d_function_space.py +16 -154
- warp/fem/space/hexmesh_function_space.py +37 -134
- warp/fem/space/nanogrid_function_space.py +202 -0
- warp/fem/space/quadmesh_2d_function_space.py +12 -119
- warp/fem/space/restriction.py +4 -1
- warp/fem/space/shape/__init__.py +77 -0
- warp/fem/space/shape/cube_shape_function.py +5 -15
- warp/fem/space/tetmesh_function_space.py +6 -76
- warp/fem/space/trimesh_2d_function_space.py +6 -76
- warp/native/array.h +12 -3
- warp/native/builtin.h +48 -5
- warp/native/bvh.cpp +14 -10
- warp/native/bvh.cu +23 -15
- warp/native/bvh.h +1 -0
- warp/native/clang/clang.cpp +2 -1
- warp/native/crt.cpp +11 -1
- warp/native/crt.h +18 -1
- warp/native/exports.h +187 -0
- warp/native/mat.h +47 -0
- warp/native/mesh.cpp +1 -1
- warp/native/mesh.cu +1 -2
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +3999 -2157
- warp/native/nanovdb/PNanoVDB.h +936 -99
- warp/native/quat.h +28 -1
- warp/native/rand.h +5 -1
- warp/native/vec.h +45 -1
- warp/native/volume.cpp +335 -103
- warp/native/volume.cu +39 -13
- warp/native/volume.h +725 -303
- warp/native/volume_builder.cu +381 -360
- warp/native/volume_builder.h +16 -1
- warp/native/volume_impl.h +61 -0
- warp/native/warp.cu +8 -2
- warp/native/warp.h +15 -7
- warp/render/render_opengl.py +191 -52
- warp/sim/integrator_featherstone.py +10 -3
- warp/sim/integrator_xpbd.py +16 -22
- warp/sparse.py +89 -27
- warp/stubs.py +83 -0
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/aux_test_dependent.py +0 -2
- warp/tests/aux_test_grad_customs.py +0 -2
- warp/tests/aux_test_reference.py +0 -2
- warp/tests/aux_test_reference_reference.py +0 -2
- warp/tests/aux_test_square.py +0 -2
- warp/tests/disabled_kinematics.py +0 -2
- warp/tests/test_adam.py +0 -2
- warp/tests/test_arithmetic.py +0 -36
- warp/tests/test_array.py +9 -11
- warp/tests/test_array_reduce.py +0 -2
- warp/tests/test_async.py +0 -2
- warp/tests/test_atomic.py +0 -2
- warp/tests/test_bool.py +58 -50
- warp/tests/test_builtins_resolution.py +0 -2
- warp/tests/test_bvh.py +0 -2
- warp/tests/test_closest_point_edge_edge.py +0 -1
- warp/tests/test_codegen.py +0 -4
- warp/tests/test_compile_consts.py +130 -10
- warp/tests/test_conditional.py +0 -2
- warp/tests/test_copy.py +0 -2
- warp/tests/test_ctypes.py +6 -8
- warp/tests/test_dense.py +0 -2
- warp/tests/test_devices.py +0 -2
- warp/tests/test_dlpack.py +9 -11
- warp/tests/test_examples.py +42 -39
- warp/tests/test_fabricarray.py +0 -3
- warp/tests/test_fast_math.py +0 -2
- warp/tests/test_fem.py +75 -54
- warp/tests/test_fp16.py +0 -2
- warp/tests/test_func.py +0 -2
- warp/tests/test_generics.py +27 -2
- warp/tests/test_grad.py +147 -8
- warp/tests/test_grad_customs.py +0 -2
- warp/tests/test_hash_grid.py +1 -3
- warp/tests/test_import.py +0 -2
- warp/tests/test_indexedarray.py +0 -2
- warp/tests/test_intersect.py +0 -2
- warp/tests/test_jax.py +0 -2
- warp/tests/test_large.py +11 -9
- warp/tests/test_launch.py +0 -2
- warp/tests/test_lerp.py +10 -54
- warp/tests/test_linear_solvers.py +3 -5
- warp/tests/test_lvalue.py +0 -2
- warp/tests/test_marching_cubes.py +0 -2
- warp/tests/test_mat.py +0 -2
- warp/tests/test_mat_lite.py +0 -2
- warp/tests/test_mat_scalar_ops.py +0 -2
- warp/tests/test_math.py +0 -2
- warp/tests/test_matmul.py +35 -37
- warp/tests/test_matmul_lite.py +29 -31
- warp/tests/test_mempool.py +0 -2
- warp/tests/test_mesh.py +0 -3
- warp/tests/test_mesh_query_aabb.py +0 -2
- warp/tests/test_mesh_query_point.py +0 -2
- warp/tests/test_mesh_query_ray.py +0 -2
- warp/tests/test_mlp.py +0 -2
- warp/tests/test_model.py +0 -2
- warp/tests/test_module_hashing.py +111 -0
- warp/tests/test_modules_lite.py +0 -3
- warp/tests/test_multigpu.py +0 -2
- warp/tests/test_noise.py +0 -4
- warp/tests/test_operators.py +0 -2
- warp/tests/test_options.py +0 -2
- warp/tests/test_peer.py +0 -2
- warp/tests/test_pinned.py +0 -2
- warp/tests/test_print.py +0 -2
- warp/tests/test_quat.py +0 -2
- warp/tests/test_rand.py +41 -5
- warp/tests/test_reload.py +0 -10
- warp/tests/test_rounding.py +0 -2
- warp/tests/test_runlength_encode.py +0 -2
- warp/tests/test_sim_grad.py +0 -2
- warp/tests/test_sim_kinematics.py +0 -2
- warp/tests/test_smoothstep.py +0 -2
- warp/tests/test_snippet.py +0 -2
- warp/tests/test_sparse.py +0 -2
- warp/tests/test_spatial.py +0 -2
- warp/tests/test_special_values.py +362 -0
- warp/tests/test_streams.py +0 -2
- warp/tests/test_struct.py +0 -2
- warp/tests/test_tape.py +0 -2
- warp/tests/test_torch.py +0 -2
- warp/tests/test_transient_module.py +0 -2
- warp/tests/test_types.py +0 -2
- warp/tests/test_utils.py +0 -2
- warp/tests/test_vec.py +0 -2
- warp/tests/test_vec_lite.py +0 -2
- warp/tests/test_vec_scalar_ops.py +0 -2
- warp/tests/test_verify_fp.py +0 -2
- warp/tests/test_volume.py +237 -13
- warp/tests/test_volume_write.py +86 -3
- warp/tests/unittest_serial.py +10 -9
- warp/tests/unittest_suites.py +6 -2
- warp/tests/unittest_utils.py +2 -171
- warp/tests/unused_test_misc.py +0 -2
- warp/tests/walkthrough_debug.py +1 -1
- warp/thirdparty/unittest_parallel.py +37 -40
- warp/types.py +526 -85
- {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/METADATA +61 -31
- warp_lang-1.2.1.dist-info/RECORD +359 -0
- warp/examples/fem/example_convection_diffusion_dg0.py +0 -204
- warp/native/nanovdb/PNanoVDBWrite.h +0 -295
- warp_lang-1.1.0.dist-info/RECORD +0 -352
- {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/LICENSE.md +0 -0
- {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/WHEEL +0 -0
- {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()
|
|
@@ -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",
|
warp/fem/__init__.py
CHANGED
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
|
-
|
|
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
|
warp/fem/geometry/__init__.py
CHANGED
warp/fem/geometry/element.py
CHANGED
|
@@ -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:
|
warp/fem/geometry/grid_3d.py
CHANGED
|
@@ -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()
|