warp-lang 1.0.1__py3-none-macosx_10_13_universal2.whl → 1.1.0__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/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +115 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3425 -3354
- warp/codegen.py +2878 -2792
- warp/config.py +40 -36
- warp/constants.py +45 -45
- warp/context.py +5194 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +383 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -279
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +146 -146
- warp/examples/benchmarks/benchmark_launches.py +295 -295
- warp/examples/browse.py +29 -28
- warp/examples/core/example_dem.py +234 -221
- warp/examples/core/example_fluid.py +293 -267
- warp/examples/core/example_graph_capture.py +144 -129
- warp/examples/core/example_marching_cubes.py +188 -176
- warp/examples/core/example_mesh.py +174 -154
- warp/examples/core/example_mesh_intersect.py +205 -193
- warp/examples/core/example_nvdb.py +176 -169
- warp/examples/core/example_raycast.py +105 -89
- warp/examples/core/example_raymarch.py +199 -178
- warp/examples/core/example_render_opengl.py +185 -141
- warp/examples/core/example_sph.py +405 -389
- warp/examples/core/example_torch.py +222 -181
- warp/examples/core/example_wave.py +263 -249
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +407 -391
- warp/examples/fem/example_convection_diffusion.py +182 -168
- warp/examples/fem/example_convection_diffusion_dg.py +219 -209
- warp/examples/fem/example_convection_diffusion_dg0.py +204 -194
- warp/examples/fem/example_deformed_geometry.py +177 -159
- warp/examples/fem/example_diffusion.py +201 -173
- warp/examples/fem/example_diffusion_3d.py +177 -152
- warp/examples/fem/example_diffusion_mgpu.py +221 -214
- warp/examples/fem/example_mixed_elasticity.py +244 -222
- warp/examples/fem/example_navier_stokes.py +259 -243
- warp/examples/fem/example_stokes.py +220 -192
- warp/examples/fem/example_stokes_transfer.py +265 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +260 -248
- warp/examples/optim/example_cloth_throw.py +222 -210
- warp/examples/optim/example_diffray.py +566 -535
- warp/examples/optim/example_drone.py +864 -835
- warp/examples/optim/example_inverse_kinematics.py +176 -169
- warp/examples/optim/example_inverse_kinematics_torch.py +185 -170
- warp/examples/optim/example_spring_cage.py +239 -234
- warp/examples/optim/example_trajectory.py +223 -201
- warp/examples/optim/example_walker.py +306 -292
- warp/examples/sim/example_cartpole.py +139 -128
- warp/examples/sim/example_cloth.py +196 -184
- warp/examples/sim/example_granular.py +124 -113
- warp/examples/sim/example_granular_collision_sdf.py +197 -185
- warp/examples/sim/example_jacobian_ik.py +236 -213
- warp/examples/sim/example_particle_chain.py +118 -106
- warp/examples/sim/example_quadruped.py +193 -179
- warp/examples/sim/example_rigid_chain.py +197 -189
- warp/examples/sim/example_rigid_contact.py +189 -176
- warp/examples/sim/example_rigid_force.py +127 -126
- warp/examples/sim/example_rigid_gyroscopic.py +109 -97
- warp/examples/sim/example_rigid_soft_contact.py +134 -124
- warp/examples/sim/example_soft_body.py +190 -178
- warp/fabric.py +337 -335
- warp/fem/__init__.py +60 -27
- warp/fem/cache.py +401 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +15 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +744 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +441 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1630 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +294 -292
- warp/fem/space/basis_space.py +488 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +267 -267
- warp/fem/space/grid_3d_function_space.py +305 -306
- warp/fem/space/hexmesh_function_space.py +350 -352
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +368 -369
- warp/fem/space/restriction.py +158 -160
- warp/fem/space/shape/__init__.py +13 -15
- warp/fem/space/shape/cube_shape_function.py +738 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +294 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +223 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1072 -1025
- warp/native/builtin.h +1560 -1560
- warp/native/bvh.cpp +398 -398
- warp/native/bvh.cu +525 -525
- warp/native/bvh.h +429 -429
- warp/native/clang/clang.cpp +495 -464
- warp/native/crt.cpp +31 -31
- warp/native/crt.h +334 -334
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1498 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +293 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/NanoVDB.h +4782 -4782
- warp/native/nanovdb/PNanoVDB.h +2553 -2553
- warp/native/nanovdb/PNanoVDBWrite.h +294 -294
- warp/native/noise.h +850 -850
- warp/native/quat.h +1084 -1084
- warp/native/rand.h +299 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1132 -1132
- warp/native/volume.cpp +297 -297
- warp/native/volume.cu +32 -32
- warp/native/volume.h +538 -538
- warp/native/volume_builder.cu +425 -425
- warp/native/volume_builder.h +19 -19
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2943 -2828
- warp/native/warp.h +313 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3217 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1910 -1991
- warp/sim/integrator_xpbd.py +3294 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1227 -1227
- warp/stubs.py +2109 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +22 -22
- warp/tests/aux_test_grad_customs.py +23 -23
- warp/tests/aux_test_reference.py +11 -11
- warp/tests/aux_test_reference_reference.py +10 -10
- warp/tests/aux_test_square.py +17 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +239 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +157 -157
- warp/tests/test_arithmetic.py +1124 -1124
- warp/tests/test_array.py +2417 -2326
- warp/tests/test_array_reduce.py +150 -150
- warp/tests/test_async.py +668 -656
- warp/tests/test_atomic.py +141 -141
- warp/tests/test_bool.py +204 -149
- warp/tests/test_builtins_resolution.py +1292 -1292
- warp/tests/test_bvh.py +164 -171
- warp/tests/test_closest_point_edge_edge.py +228 -228
- warp/tests/test_codegen.py +566 -553
- warp/tests/test_compile_consts.py +97 -101
- warp/tests/test_conditional.py +246 -246
- warp/tests/test_copy.py +232 -215
- warp/tests/test_ctypes.py +632 -632
- warp/tests/test_dense.py +67 -67
- warp/tests/test_devices.py +91 -98
- warp/tests/test_dlpack.py +530 -529
- warp/tests/test_examples.py +400 -378
- warp/tests/test_fabricarray.py +955 -955
- warp/tests/test_fast_math.py +62 -54
- warp/tests/test_fem.py +1277 -1278
- warp/tests/test_fp16.py +130 -130
- warp/tests/test_func.py +338 -337
- warp/tests/test_generics.py +571 -571
- warp/tests/test_grad.py +746 -640
- warp/tests/test_grad_customs.py +333 -336
- warp/tests/test_hash_grid.py +210 -164
- warp/tests/test_import.py +39 -39
- warp/tests/test_indexedarray.py +1134 -1134
- warp/tests/test_intersect.py +67 -67
- warp/tests/test_jax.py +307 -307
- warp/tests/test_large.py +167 -164
- warp/tests/test_launch.py +354 -354
- warp/tests/test_lerp.py +261 -261
- warp/tests/test_linear_solvers.py +191 -171
- warp/tests/test_lvalue.py +421 -493
- warp/tests/test_marching_cubes.py +65 -65
- warp/tests/test_mat.py +1801 -1827
- warp/tests/test_mat_lite.py +115 -115
- warp/tests/test_mat_scalar_ops.py +2907 -2889
- warp/tests/test_math.py +126 -193
- warp/tests/test_matmul.py +500 -499
- warp/tests/test_matmul_lite.py +410 -410
- warp/tests/test_mempool.py +188 -190
- warp/tests/test_mesh.py +284 -324
- warp/tests/test_mesh_query_aabb.py +228 -241
- warp/tests/test_mesh_query_point.py +692 -702
- warp/tests/test_mesh_query_ray.py +292 -303
- warp/tests/test_mlp.py +276 -276
- warp/tests/test_model.py +110 -110
- warp/tests/test_modules_lite.py +39 -39
- warp/tests/test_multigpu.py +163 -163
- warp/tests/test_noise.py +248 -248
- warp/tests/test_operators.py +250 -250
- warp/tests/test_options.py +123 -125
- warp/tests/test_peer.py +133 -137
- warp/tests/test_pinned.py +78 -78
- warp/tests/test_print.py +54 -54
- warp/tests/test_quat.py +2086 -2086
- warp/tests/test_rand.py +288 -288
- warp/tests/test_reload.py +217 -217
- warp/tests/test_rounding.py +179 -179
- warp/tests/test_runlength_encode.py +190 -190
- warp/tests/test_sim_grad.py +243 -0
- warp/tests/test_sim_kinematics.py +91 -97
- warp/tests/test_smoothstep.py +168 -168
- warp/tests/test_snippet.py +305 -266
- warp/tests/test_sparse.py +468 -460
- warp/tests/test_spatial.py +2148 -2148
- warp/tests/test_streams.py +486 -473
- warp/tests/test_struct.py +710 -675
- warp/tests/test_tape.py +173 -148
- warp/tests/test_torch.py +743 -743
- warp/tests/test_transient_module.py +87 -87
- warp/tests/test_types.py +556 -659
- warp/tests/test_utils.py +490 -499
- warp/tests/test_vec.py +1264 -1268
- warp/tests/test_vec_lite.py +73 -73
- warp/tests/test_vec_scalar_ops.py +2099 -2099
- warp/tests/test_verify_fp.py +94 -94
- warp/tests/test_volume.py +737 -736
- warp/tests/test_volume_write.py +255 -265
- warp/tests/unittest_serial.py +37 -37
- warp/tests/unittest_suites.py +363 -359
- warp/tests/unittest_utils.py +603 -578
- warp/tests/unused_test_misc.py +71 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +566 -561
- warp/torch.py +321 -295
- warp/types.py +4504 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/METADATA +338 -400
- warp_lang-1.1.0.dist-info/RECORD +352 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp_lang-1.0.1.dist-info/RECORD +0 -352
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/top_level.txt +0 -0
warp/fem/integrate.py
CHANGED
|
@@ -1,1615 +1,1630 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
from warp.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
modules.append(node.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
operator
|
|
98
|
-
|
|
99
|
-
call
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
self.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
#
|
|
141
|
-
|
|
142
|
-
for arg in args:
|
|
143
|
-
|
|
144
|
-
if
|
|
145
|
-
call_site_field_args.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
self.
|
|
338
|
-
self.
|
|
339
|
-
self.
|
|
340
|
-
self.
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
self.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
# print(ast.dump(call, indent=4))
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
):
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
def
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
)
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
def
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
)
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
)
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
)
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
kernel_suffix
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
)
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
)
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
)
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
if
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
if
|
|
1170
|
-
raise ValueError("
|
|
1171
|
-
|
|
1172
|
-
if
|
|
1173
|
-
raise ValueError(
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
)
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
kernel_suffix =
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
)
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
)
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
)
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
domain=domain
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1
|
+
import ast
|
|
2
|
+
from typing import Any, Dict, List, Optional, Set, Union
|
|
3
|
+
|
|
4
|
+
import warp as wp
|
|
5
|
+
from warp.codegen import get_annotations
|
|
6
|
+
from warp.fem import cache
|
|
7
|
+
from warp.fem.domain import GeometryDomain
|
|
8
|
+
from warp.fem.field import (
|
|
9
|
+
DiscreteField,
|
|
10
|
+
FieldLike,
|
|
11
|
+
FieldRestriction,
|
|
12
|
+
TestField,
|
|
13
|
+
TrialField,
|
|
14
|
+
make_restriction,
|
|
15
|
+
)
|
|
16
|
+
from warp.fem.operator import Integrand, Operator
|
|
17
|
+
from warp.fem.quadrature import Quadrature, RegularQuadrature
|
|
18
|
+
from warp.fem.types import NULL_DOF_INDEX, OUTSIDE, DofIndex, Domain, Field, Sample, make_free_sample
|
|
19
|
+
from warp.sparse import BsrMatrix, bsr_set_from_triplets, bsr_zeros
|
|
20
|
+
from warp.types import type_length
|
|
21
|
+
from warp.utils import array_cast
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _resolve_path(func, node):
|
|
25
|
+
"""
|
|
26
|
+
Resolves variable and path from ast node/attribute (adapted from warp.codegen)
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
modules = []
|
|
30
|
+
|
|
31
|
+
while isinstance(node, ast.Attribute):
|
|
32
|
+
modules.append(node.attr)
|
|
33
|
+
node = node.value
|
|
34
|
+
|
|
35
|
+
if isinstance(node, ast.Name):
|
|
36
|
+
modules.append(node.id)
|
|
37
|
+
|
|
38
|
+
# reverse list since ast presents it backward order
|
|
39
|
+
path = [*reversed(modules)]
|
|
40
|
+
|
|
41
|
+
if len(path) == 0:
|
|
42
|
+
return None, path
|
|
43
|
+
|
|
44
|
+
# try and evaluate object path
|
|
45
|
+
try:
|
|
46
|
+
# Look up the closure info and append it to adj.func.__globals__
|
|
47
|
+
# in case you want to define a kernel inside a function and refer
|
|
48
|
+
# to variables you've declared inside that function:
|
|
49
|
+
capturedvars = dict(zip(func.__code__.co_freevars, [c.cell_contents for c in (func.__closure__ or [])]))
|
|
50
|
+
|
|
51
|
+
vars_dict = {**func.__globals__, **capturedvars}
|
|
52
|
+
func = eval(".".join(path), vars_dict)
|
|
53
|
+
return func, path
|
|
54
|
+
except (NameError, AttributeError):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
return None, path
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _path_to_ast_attribute(name: str) -> ast.Attribute:
|
|
61
|
+
path = name.split(".")
|
|
62
|
+
path.reverse()
|
|
63
|
+
|
|
64
|
+
node = ast.Name(id=path.pop(), ctx=ast.Load())
|
|
65
|
+
while len(path):
|
|
66
|
+
node = ast.Attribute(
|
|
67
|
+
value=node,
|
|
68
|
+
attr=path.pop(),
|
|
69
|
+
ctx=ast.Load(),
|
|
70
|
+
)
|
|
71
|
+
return node
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class IntegrandTransformer(ast.NodeTransformer):
|
|
75
|
+
def __init__(self, integrand: Integrand, field_args: Dict[str, FieldLike]):
|
|
76
|
+
self._integrand = integrand
|
|
77
|
+
self._field_args = field_args
|
|
78
|
+
|
|
79
|
+
def visit_Call(self, call: ast.Call):
|
|
80
|
+
call = self.generic_visit(call)
|
|
81
|
+
|
|
82
|
+
callee = getattr(call.func, "id", None)
|
|
83
|
+
if callee in self._field_args:
|
|
84
|
+
# Shortcut for evaluating fields as f(x...)
|
|
85
|
+
field = self._field_args[callee]
|
|
86
|
+
|
|
87
|
+
arg_type = self._integrand.argspec.annotations[callee]
|
|
88
|
+
operator = arg_type.call_operator
|
|
89
|
+
|
|
90
|
+
call.func = ast.Attribute(
|
|
91
|
+
value=_path_to_ast_attribute(f"{arg_type.__module__}.{arg_type.__qualname__}"),
|
|
92
|
+
attr="call_operator",
|
|
93
|
+
ctx=ast.Load(),
|
|
94
|
+
)
|
|
95
|
+
call.args = [ast.Name(id=callee, ctx=ast.Load())] + call.args
|
|
96
|
+
|
|
97
|
+
self._replace_call_func(call, operator, field)
|
|
98
|
+
|
|
99
|
+
return call
|
|
100
|
+
|
|
101
|
+
func, _ = _resolve_path(self._integrand.func, call.func)
|
|
102
|
+
|
|
103
|
+
if isinstance(func, Operator) and len(call.args) > 0:
|
|
104
|
+
# Evaluating operators as op(field, x, ...)
|
|
105
|
+
callee = getattr(call.args[0], "id", None)
|
|
106
|
+
if callee in self._field_args:
|
|
107
|
+
field = self._field_args[callee]
|
|
108
|
+
self._replace_call_func(call, func, field)
|
|
109
|
+
|
|
110
|
+
if isinstance(func, Integrand):
|
|
111
|
+
key = self._translate_callee(func, call.args)
|
|
112
|
+
call.func = ast.Attribute(
|
|
113
|
+
value=call.func,
|
|
114
|
+
attr=key,
|
|
115
|
+
ctx=ast.Load(),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# print(ast.dump(call, indent=4))
|
|
119
|
+
|
|
120
|
+
return call
|
|
121
|
+
|
|
122
|
+
def _replace_call_func(self, call: ast.Call, operator: Operator, field: FieldLike):
|
|
123
|
+
try:
|
|
124
|
+
pointer = operator.resolver(field)
|
|
125
|
+
setattr(operator, pointer.key, pointer)
|
|
126
|
+
except AttributeError as e:
|
|
127
|
+
raise ValueError(f"Operator {operator.func.__name__} is not defined for field {field.name}") from e
|
|
128
|
+
call.func = ast.Attribute(value=call.func, attr=pointer.key, ctx=ast.Load())
|
|
129
|
+
|
|
130
|
+
def _translate_callee(self, callee: Integrand, args: List[ast.AST]):
|
|
131
|
+
# Get field types for call site arguments
|
|
132
|
+
call_site_field_args = []
|
|
133
|
+
for arg in args:
|
|
134
|
+
name = getattr(arg, "id", None)
|
|
135
|
+
if name in self._field_args:
|
|
136
|
+
call_site_field_args.append(self._field_args[name])
|
|
137
|
+
|
|
138
|
+
call_site_field_args.reverse()
|
|
139
|
+
|
|
140
|
+
# Pass to callee in same order
|
|
141
|
+
callee_field_args = {}
|
|
142
|
+
for arg in callee.argspec.args:
|
|
143
|
+
arg_type = callee.argspec.annotations[arg]
|
|
144
|
+
if arg_type in (Field, Domain):
|
|
145
|
+
callee_field_args[arg] = call_site_field_args.pop()
|
|
146
|
+
|
|
147
|
+
return _translate_integrand(callee, callee_field_args).key
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _translate_integrand(integrand: Integrand, field_args: Dict[str, FieldLike]) -> wp.Function:
|
|
151
|
+
# Specialize field argument types
|
|
152
|
+
argspec = integrand.argspec
|
|
153
|
+
annotations = {}
|
|
154
|
+
for arg in argspec.args:
|
|
155
|
+
arg_type = argspec.annotations[arg]
|
|
156
|
+
if arg_type == Field:
|
|
157
|
+
annotations[arg] = field_args[arg].ElementEvalArg
|
|
158
|
+
elif arg_type == Domain:
|
|
159
|
+
annotations[arg] = field_args[arg].ElementArg
|
|
160
|
+
else:
|
|
161
|
+
annotations[arg] = arg_type
|
|
162
|
+
|
|
163
|
+
# Transform field evaluation calls
|
|
164
|
+
transformer = IntegrandTransformer(integrand, field_args)
|
|
165
|
+
|
|
166
|
+
suffix = "_".join([f.name for f in field_args.values()])
|
|
167
|
+
|
|
168
|
+
func = cache.get_integrand_function(
|
|
169
|
+
integrand=integrand,
|
|
170
|
+
suffix=suffix,
|
|
171
|
+
annotations=annotations,
|
|
172
|
+
code_transformers=[transformer],
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
key = func.key
|
|
176
|
+
setattr(integrand, key, integrand.module.functions[key])
|
|
177
|
+
|
|
178
|
+
return getattr(integrand, key)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _get_integrand_field_arguments(
|
|
182
|
+
integrand: Integrand,
|
|
183
|
+
fields: Dict[str, FieldLike],
|
|
184
|
+
domain: GeometryDomain = None,
|
|
185
|
+
):
|
|
186
|
+
# parse argument types
|
|
187
|
+
field_args = {}
|
|
188
|
+
value_args = {}
|
|
189
|
+
|
|
190
|
+
domain_name = None
|
|
191
|
+
sample_name = None
|
|
192
|
+
|
|
193
|
+
argspec = integrand.argspec
|
|
194
|
+
for arg in argspec.args:
|
|
195
|
+
arg_type = argspec.annotations[arg]
|
|
196
|
+
if arg_type == Field:
|
|
197
|
+
if arg not in fields:
|
|
198
|
+
raise ValueError(f"Missing field for argument '{arg}'")
|
|
199
|
+
field_args[arg] = fields[arg]
|
|
200
|
+
elif arg_type == Domain:
|
|
201
|
+
domain_name = arg
|
|
202
|
+
field_args[arg] = domain
|
|
203
|
+
elif arg_type == Sample:
|
|
204
|
+
sample_name = arg
|
|
205
|
+
else:
|
|
206
|
+
value_args[arg] = arg_type
|
|
207
|
+
|
|
208
|
+
return field_args, value_args, domain_name, sample_name
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _get_test_and_trial_fields(
|
|
212
|
+
fields: Dict[str, FieldLike],
|
|
213
|
+
):
|
|
214
|
+
test = None
|
|
215
|
+
trial = None
|
|
216
|
+
test_name = None
|
|
217
|
+
trial_name = None
|
|
218
|
+
|
|
219
|
+
for name, field in fields.items():
|
|
220
|
+
if isinstance(field, TestField):
|
|
221
|
+
if test is not None:
|
|
222
|
+
raise ValueError("Duplicate test field argument")
|
|
223
|
+
test = field
|
|
224
|
+
test_name = name
|
|
225
|
+
elif isinstance(field, TrialField):
|
|
226
|
+
if trial is not None:
|
|
227
|
+
raise ValueError("Duplicate test field argument")
|
|
228
|
+
trial = field
|
|
229
|
+
trial_name = name
|
|
230
|
+
|
|
231
|
+
if trial is not None:
|
|
232
|
+
if test is None:
|
|
233
|
+
raise ValueError("A trial field cannot be provided without a test field")
|
|
234
|
+
|
|
235
|
+
if test.domain != trial.domain:
|
|
236
|
+
raise ValueError("Incompatible test and trial domains")
|
|
237
|
+
|
|
238
|
+
return test, test_name, trial, trial_name
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _gen_field_struct(field_args: Dict[str, FieldLike]):
|
|
242
|
+
class Fields:
|
|
243
|
+
pass
|
|
244
|
+
|
|
245
|
+
annotations = get_annotations(Fields)
|
|
246
|
+
|
|
247
|
+
for name, arg in field_args.items():
|
|
248
|
+
if isinstance(arg, GeometryDomain):
|
|
249
|
+
continue
|
|
250
|
+
setattr(Fields, name, arg.EvalArg())
|
|
251
|
+
annotations[name] = arg.EvalArg
|
|
252
|
+
|
|
253
|
+
try:
|
|
254
|
+
Fields.__annotations__ = annotations
|
|
255
|
+
except AttributeError:
|
|
256
|
+
Fields.__dict__.__annotations__ = annotations
|
|
257
|
+
|
|
258
|
+
suffix = "_".join([f"{name}_{arg_struct.cls.__qualname__}" for name, arg_struct in annotations.items()])
|
|
259
|
+
|
|
260
|
+
return cache.get_struct(Fields, suffix=suffix)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _gen_value_struct(value_args: Dict[str, type]):
|
|
264
|
+
class Values:
|
|
265
|
+
pass
|
|
266
|
+
|
|
267
|
+
annotations = get_annotations(Values)
|
|
268
|
+
|
|
269
|
+
for name, arg_type in value_args.items():
|
|
270
|
+
setattr(Values, name, None)
|
|
271
|
+
annotations[name] = arg_type
|
|
272
|
+
|
|
273
|
+
def arg_type_name(arg_type):
|
|
274
|
+
if isinstance(arg_type, wp.codegen.Struct):
|
|
275
|
+
return arg_type_name(arg_type.cls)
|
|
276
|
+
return getattr(arg_type, "__name__", str(arg_type))
|
|
277
|
+
|
|
278
|
+
def arg_type_name(arg_type):
|
|
279
|
+
if isinstance(arg_type, wp.codegen.Struct):
|
|
280
|
+
return arg_type_name(arg_type.cls)
|
|
281
|
+
return getattr(arg_type, "__name__", str(arg_type))
|
|
282
|
+
|
|
283
|
+
try:
|
|
284
|
+
Values.__annotations__ = annotations
|
|
285
|
+
except AttributeError:
|
|
286
|
+
Values.__dict__.__annotations__ = annotations
|
|
287
|
+
|
|
288
|
+
suffix = "_".join([f"{name}_{arg_type_name(arg_type)}" for name, arg_type in annotations.items()])
|
|
289
|
+
|
|
290
|
+
return cache.get_struct(Values, suffix=suffix)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _get_trial_arg():
|
|
294
|
+
pass
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _get_test_arg():
|
|
298
|
+
pass
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
class _FieldWrappers:
|
|
302
|
+
pass
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _register_integrand_field_wrappers(integrand_func: wp.Function, fields: Dict[str, FieldLike]):
|
|
306
|
+
integrand_func._field_wrappers = _FieldWrappers()
|
|
307
|
+
for name, field in fields.items():
|
|
308
|
+
setattr(integrand_func._field_wrappers, name, field.ElementEvalArg)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class PassFieldArgsToIntegrand(ast.NodeTransformer):
|
|
312
|
+
def __init__(
|
|
313
|
+
self,
|
|
314
|
+
arg_names: List[str],
|
|
315
|
+
field_args: Set[str],
|
|
316
|
+
value_args: Set[str],
|
|
317
|
+
sample_name: str,
|
|
318
|
+
domain_name: str,
|
|
319
|
+
test_name: str = None,
|
|
320
|
+
trial_name: str = None,
|
|
321
|
+
func_name: str = "integrand_func",
|
|
322
|
+
fields_var_name: str = "fields",
|
|
323
|
+
values_var_name: str = "values",
|
|
324
|
+
domain_var_name: str = "domain_arg",
|
|
325
|
+
sample_var_name: str = "sample",
|
|
326
|
+
field_wrappers_attr: str = "_field_wrappers",
|
|
327
|
+
):
|
|
328
|
+
self._arg_names = arg_names
|
|
329
|
+
self._field_args = field_args
|
|
330
|
+
self._value_args = value_args
|
|
331
|
+
self._domain_name = domain_name
|
|
332
|
+
self._sample_name = sample_name
|
|
333
|
+
self._func_name = func_name
|
|
334
|
+
self._test_name = test_name
|
|
335
|
+
self._trial_name = trial_name
|
|
336
|
+
self._fields_var_name = fields_var_name
|
|
337
|
+
self._values_var_name = values_var_name
|
|
338
|
+
self._domain_var_name = domain_var_name
|
|
339
|
+
self._sample_var_name = sample_var_name
|
|
340
|
+
self._field_wrappers_attr = field_wrappers_attr
|
|
341
|
+
|
|
342
|
+
def visit_Call(self, call: ast.Call):
|
|
343
|
+
call = self.generic_visit(call)
|
|
344
|
+
|
|
345
|
+
callee = getattr(call.func, "id", None)
|
|
346
|
+
|
|
347
|
+
if callee == self._func_name:
|
|
348
|
+
# Replace function arguments with ours generated structs
|
|
349
|
+
call.args.clear()
|
|
350
|
+
for arg in self._arg_names:
|
|
351
|
+
if arg == self._domain_name:
|
|
352
|
+
call.args.append(
|
|
353
|
+
ast.Name(id=self._domain_var_name, ctx=ast.Load()),
|
|
354
|
+
)
|
|
355
|
+
elif arg == self._sample_name:
|
|
356
|
+
call.args.append(
|
|
357
|
+
ast.Name(id=self._sample_var_name, ctx=ast.Load()),
|
|
358
|
+
)
|
|
359
|
+
elif arg in self._field_args:
|
|
360
|
+
call.args.append(
|
|
361
|
+
ast.Call(
|
|
362
|
+
func=ast.Attribute(
|
|
363
|
+
value=ast.Attribute(
|
|
364
|
+
value=ast.Name(id=self._func_name, ctx=ast.Load()),
|
|
365
|
+
attr=self._field_wrappers_attr,
|
|
366
|
+
ctx=ast.Load(),
|
|
367
|
+
),
|
|
368
|
+
attr=arg,
|
|
369
|
+
ctx=ast.Load(),
|
|
370
|
+
),
|
|
371
|
+
args=[
|
|
372
|
+
ast.Name(id=self._domain_var_name, ctx=ast.Load()),
|
|
373
|
+
ast.Attribute(
|
|
374
|
+
value=ast.Name(id=self._fields_var_name, ctx=ast.Load()),
|
|
375
|
+
attr=arg,
|
|
376
|
+
ctx=ast.Load(),
|
|
377
|
+
),
|
|
378
|
+
],
|
|
379
|
+
keywords=[],
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
elif arg in self._value_args:
|
|
383
|
+
call.args.append(
|
|
384
|
+
ast.Attribute(
|
|
385
|
+
value=ast.Name(id=self._values_var_name, ctx=ast.Load()),
|
|
386
|
+
attr=arg,
|
|
387
|
+
ctx=ast.Load(),
|
|
388
|
+
)
|
|
389
|
+
)
|
|
390
|
+
else:
|
|
391
|
+
raise RuntimeError(f"Unhandled argument {arg}")
|
|
392
|
+
# print(ast.dump(call, indent=4))
|
|
393
|
+
elif callee == _get_test_arg.__name__:
|
|
394
|
+
# print(ast.dump(call, indent=4))
|
|
395
|
+
call = ast.Attribute(
|
|
396
|
+
value=ast.Name(id=self._fields_var_name, ctx=ast.Load()),
|
|
397
|
+
attr=self._test_name,
|
|
398
|
+
ctx=ast.Load(),
|
|
399
|
+
)
|
|
400
|
+
elif callee == _get_trial_arg.__name__:
|
|
401
|
+
# print(ast.dump(call, indent=4))
|
|
402
|
+
call = ast.Attribute(
|
|
403
|
+
value=ast.Name(id=self._fields_var_name, ctx=ast.Load()),
|
|
404
|
+
attr=self._trial_name,
|
|
405
|
+
ctx=ast.Load(),
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
return call
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def get_integrate_constant_kernel(
|
|
412
|
+
integrand_func: wp.Function,
|
|
413
|
+
domain: GeometryDomain,
|
|
414
|
+
quadrature: Quadrature,
|
|
415
|
+
FieldStruct: wp.codegen.Struct,
|
|
416
|
+
ValueStruct: wp.codegen.Struct,
|
|
417
|
+
accumulate_dtype,
|
|
418
|
+
):
|
|
419
|
+
def integrate_kernel_fn(
|
|
420
|
+
qp_arg: quadrature.Arg,
|
|
421
|
+
domain_arg: domain.ElementArg,
|
|
422
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
423
|
+
fields: FieldStruct,
|
|
424
|
+
values: ValueStruct,
|
|
425
|
+
result: wp.array(dtype=accumulate_dtype),
|
|
426
|
+
):
|
|
427
|
+
element_index = domain.element_index(domain_index_arg, wp.tid())
|
|
428
|
+
elem_sum = accumulate_dtype(0.0)
|
|
429
|
+
|
|
430
|
+
test_dof_index = NULL_DOF_INDEX
|
|
431
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
432
|
+
|
|
433
|
+
qp_point_count = quadrature.point_count(domain_arg, qp_arg, element_index)
|
|
434
|
+
for k in range(qp_point_count):
|
|
435
|
+
qp_index = quadrature.point_index(domain_arg, qp_arg, element_index, k)
|
|
436
|
+
coords = quadrature.point_coords(domain_arg, qp_arg, element_index, k)
|
|
437
|
+
qp_weight = quadrature.point_weight(domain_arg, qp_arg, element_index, k)
|
|
438
|
+
|
|
439
|
+
sample = Sample(element_index, coords, qp_index, qp_weight, test_dof_index, trial_dof_index)
|
|
440
|
+
vol = domain.element_measure(domain_arg, sample)
|
|
441
|
+
|
|
442
|
+
val = integrand_func(sample, fields, values)
|
|
443
|
+
|
|
444
|
+
elem_sum += accumulate_dtype(qp_weight * vol * val)
|
|
445
|
+
|
|
446
|
+
wp.atomic_add(result, 0, elem_sum)
|
|
447
|
+
|
|
448
|
+
return integrate_kernel_fn
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def get_integrate_linear_kernel(
|
|
452
|
+
integrand_func: wp.Function,
|
|
453
|
+
domain: GeometryDomain,
|
|
454
|
+
quadrature: Quadrature,
|
|
455
|
+
FieldStruct: wp.codegen.Struct,
|
|
456
|
+
ValueStruct: wp.codegen.Struct,
|
|
457
|
+
test: TestField,
|
|
458
|
+
output_dtype,
|
|
459
|
+
accumulate_dtype,
|
|
460
|
+
):
|
|
461
|
+
def integrate_kernel_fn(
|
|
462
|
+
qp_arg: quadrature.Arg,
|
|
463
|
+
domain_arg: domain.ElementArg,
|
|
464
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
465
|
+
test_arg: test.space_restriction.NodeArg,
|
|
466
|
+
fields: FieldStruct,
|
|
467
|
+
values: ValueStruct,
|
|
468
|
+
result: wp.array2d(dtype=output_dtype),
|
|
469
|
+
):
|
|
470
|
+
local_node_index, test_dof = wp.tid()
|
|
471
|
+
node_index = test.space_restriction.node_partition_index(test_arg, local_node_index)
|
|
472
|
+
element_count = test.space_restriction.node_element_count(test_arg, local_node_index)
|
|
473
|
+
|
|
474
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
475
|
+
|
|
476
|
+
val_sum = accumulate_dtype(0.0)
|
|
477
|
+
|
|
478
|
+
for n in range(element_count):
|
|
479
|
+
node_element_index = test.space_restriction.node_element_index(test_arg, local_node_index, n)
|
|
480
|
+
element_index = domain.element_index(domain_index_arg, node_element_index.domain_element_index)
|
|
481
|
+
|
|
482
|
+
test_dof_index = DofIndex(node_element_index.node_index_in_element, test_dof)
|
|
483
|
+
|
|
484
|
+
qp_point_count = quadrature.point_count(domain_arg, qp_arg, element_index)
|
|
485
|
+
for k in range(qp_point_count):
|
|
486
|
+
qp_index = quadrature.point_index(domain_arg, qp_arg, element_index, k)
|
|
487
|
+
qp_coords = quadrature.point_coords(domain_arg, qp_arg, element_index, k)
|
|
488
|
+
qp_weight = quadrature.point_weight(domain_arg, qp_arg, element_index, k)
|
|
489
|
+
|
|
490
|
+
vol = domain.element_measure(domain_arg, make_free_sample(element_index, qp_coords))
|
|
491
|
+
|
|
492
|
+
sample = Sample(element_index, qp_coords, qp_index, qp_weight, test_dof_index, trial_dof_index)
|
|
493
|
+
val = integrand_func(sample, fields, values)
|
|
494
|
+
|
|
495
|
+
val_sum += accumulate_dtype(qp_weight * vol * val)
|
|
496
|
+
|
|
497
|
+
result[node_index, test_dof] = output_dtype(val_sum)
|
|
498
|
+
|
|
499
|
+
return integrate_kernel_fn
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def get_integrate_linear_nodal_kernel(
|
|
503
|
+
integrand_func: wp.Function,
|
|
504
|
+
domain: GeometryDomain,
|
|
505
|
+
FieldStruct: wp.codegen.Struct,
|
|
506
|
+
ValueStruct: wp.codegen.Struct,
|
|
507
|
+
test: TestField,
|
|
508
|
+
output_dtype,
|
|
509
|
+
accumulate_dtype,
|
|
510
|
+
):
|
|
511
|
+
def integrate_kernel_fn(
|
|
512
|
+
domain_arg: domain.ElementArg,
|
|
513
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
514
|
+
test_restriction_arg: test.space_restriction.NodeArg,
|
|
515
|
+
fields: FieldStruct,
|
|
516
|
+
values: ValueStruct,
|
|
517
|
+
result: wp.array2d(dtype=output_dtype),
|
|
518
|
+
):
|
|
519
|
+
local_node_index, dof = wp.tid()
|
|
520
|
+
|
|
521
|
+
node_index = test.space_restriction.node_partition_index(test_restriction_arg, local_node_index)
|
|
522
|
+
element_count = test.space_restriction.node_element_count(test_restriction_arg, local_node_index)
|
|
523
|
+
|
|
524
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
525
|
+
|
|
526
|
+
val_sum = accumulate_dtype(0.0)
|
|
527
|
+
|
|
528
|
+
for n in range(element_count):
|
|
529
|
+
node_element_index = test.space_restriction.node_element_index(test_restriction_arg, local_node_index, n)
|
|
530
|
+
element_index = domain.element_index(domain_index_arg, node_element_index.domain_element_index)
|
|
531
|
+
|
|
532
|
+
coords = test.space.node_coords_in_element(
|
|
533
|
+
domain_arg,
|
|
534
|
+
_get_test_arg(),
|
|
535
|
+
element_index,
|
|
536
|
+
node_element_index.node_index_in_element,
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
if coords[0] != OUTSIDE:
|
|
540
|
+
node_weight = test.space.node_quadrature_weight(
|
|
541
|
+
domain_arg,
|
|
542
|
+
_get_test_arg(),
|
|
543
|
+
element_index,
|
|
544
|
+
node_element_index.node_index_in_element,
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
test_dof_index = DofIndex(node_element_index.node_index_in_element, dof)
|
|
548
|
+
|
|
549
|
+
sample = Sample(
|
|
550
|
+
element_index,
|
|
551
|
+
coords,
|
|
552
|
+
node_index,
|
|
553
|
+
node_weight,
|
|
554
|
+
test_dof_index,
|
|
555
|
+
trial_dof_index,
|
|
556
|
+
)
|
|
557
|
+
vol = domain.element_measure(domain_arg, sample)
|
|
558
|
+
val = integrand_func(sample, fields, values)
|
|
559
|
+
|
|
560
|
+
val_sum += accumulate_dtype(node_weight * vol * val)
|
|
561
|
+
|
|
562
|
+
result[node_index, dof] = output_dtype(val_sum)
|
|
563
|
+
|
|
564
|
+
return integrate_kernel_fn
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def get_integrate_bilinear_kernel(
|
|
568
|
+
integrand_func: wp.Function,
|
|
569
|
+
domain: GeometryDomain,
|
|
570
|
+
quadrature: Quadrature,
|
|
571
|
+
FieldStruct: wp.codegen.Struct,
|
|
572
|
+
ValueStruct: wp.codegen.Struct,
|
|
573
|
+
test: TestField,
|
|
574
|
+
trial: TrialField,
|
|
575
|
+
output_dtype,
|
|
576
|
+
accumulate_dtype,
|
|
577
|
+
):
|
|
578
|
+
NODES_PER_ELEMENT = trial.space.topology.NODES_PER_ELEMENT
|
|
579
|
+
|
|
580
|
+
def integrate_kernel_fn(
|
|
581
|
+
qp_arg: quadrature.Arg,
|
|
582
|
+
domain_arg: domain.ElementArg,
|
|
583
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
584
|
+
test_arg: test.space_restriction.NodeArg,
|
|
585
|
+
trial_partition_arg: trial.space_partition.PartitionArg,
|
|
586
|
+
trial_topology_arg: trial.space_partition.space_topology.TopologyArg,
|
|
587
|
+
fields: FieldStruct,
|
|
588
|
+
values: ValueStruct,
|
|
589
|
+
row_offsets: wp.array(dtype=int),
|
|
590
|
+
triplet_rows: wp.array(dtype=int),
|
|
591
|
+
triplet_cols: wp.array(dtype=int),
|
|
592
|
+
triplet_values: wp.array3d(dtype=output_dtype),
|
|
593
|
+
):
|
|
594
|
+
test_local_node_index, trial_node, test_dof, trial_dof = wp.tid()
|
|
595
|
+
|
|
596
|
+
element_count = test.space_restriction.node_element_count(test_arg, test_local_node_index)
|
|
597
|
+
test_node_index = test.space_restriction.node_partition_index(test_arg, test_local_node_index)
|
|
598
|
+
|
|
599
|
+
trial_dof_index = DofIndex(trial_node, trial_dof)
|
|
600
|
+
|
|
601
|
+
for element in range(element_count):
|
|
602
|
+
test_element_index = test.space_restriction.node_element_index(test_arg, test_local_node_index, element)
|
|
603
|
+
element_index = domain.element_index(domain_index_arg, test_element_index.domain_element_index)
|
|
604
|
+
qp_point_count = quadrature.point_count(domain_arg, qp_arg, element_index)
|
|
605
|
+
|
|
606
|
+
test_dof_index = DofIndex(
|
|
607
|
+
test_element_index.node_index_in_element,
|
|
608
|
+
test_dof,
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
val_sum = accumulate_dtype(0.0)
|
|
612
|
+
|
|
613
|
+
for k in range(qp_point_count):
|
|
614
|
+
qp_index = quadrature.point_index(domain_arg, qp_arg, element_index, k)
|
|
615
|
+
coords = quadrature.point_coords(domain_arg, qp_arg, element_index, k)
|
|
616
|
+
|
|
617
|
+
qp_weight = quadrature.point_weight(domain_arg, qp_arg, element_index, k)
|
|
618
|
+
vol = domain.element_measure(domain_arg, make_free_sample(element_index, coords))
|
|
619
|
+
|
|
620
|
+
sample = Sample(
|
|
621
|
+
element_index,
|
|
622
|
+
coords,
|
|
623
|
+
qp_index,
|
|
624
|
+
qp_weight,
|
|
625
|
+
test_dof_index,
|
|
626
|
+
trial_dof_index,
|
|
627
|
+
)
|
|
628
|
+
val = integrand_func(sample, fields, values)
|
|
629
|
+
val_sum += accumulate_dtype(qp_weight * vol * val)
|
|
630
|
+
|
|
631
|
+
block_offset = (row_offsets[test_node_index] + element) * NODES_PER_ELEMENT + trial_node
|
|
632
|
+
triplet_values[block_offset, test_dof, trial_dof] = output_dtype(val_sum)
|
|
633
|
+
|
|
634
|
+
# Set row and column indices
|
|
635
|
+
if test_dof == 0 and trial_dof == 0:
|
|
636
|
+
trial_node_index = trial.space_partition.partition_node_index(
|
|
637
|
+
trial_partition_arg,
|
|
638
|
+
trial.space.topology.element_node_index(domain_arg, trial_topology_arg, element_index, trial_node),
|
|
639
|
+
)
|
|
640
|
+
triplet_rows[block_offset] = test_node_index
|
|
641
|
+
triplet_cols[block_offset] = trial_node_index
|
|
642
|
+
|
|
643
|
+
return integrate_kernel_fn
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def get_integrate_bilinear_nodal_kernel(
|
|
647
|
+
integrand_func: wp.Function,
|
|
648
|
+
domain: GeometryDomain,
|
|
649
|
+
FieldStruct: wp.codegen.Struct,
|
|
650
|
+
ValueStruct: wp.codegen.Struct,
|
|
651
|
+
test: TestField,
|
|
652
|
+
output_dtype,
|
|
653
|
+
accumulate_dtype,
|
|
654
|
+
):
|
|
655
|
+
def integrate_kernel_fn(
|
|
656
|
+
domain_arg: domain.ElementArg,
|
|
657
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
658
|
+
test_restriction_arg: test.space_restriction.NodeArg,
|
|
659
|
+
fields: FieldStruct,
|
|
660
|
+
values: ValueStruct,
|
|
661
|
+
triplet_rows: wp.array(dtype=int),
|
|
662
|
+
triplet_cols: wp.array(dtype=int),
|
|
663
|
+
triplet_values: wp.array3d(dtype=output_dtype),
|
|
664
|
+
):
|
|
665
|
+
local_node_index, test_dof, trial_dof = wp.tid()
|
|
666
|
+
|
|
667
|
+
element_count = test.space_restriction.node_element_count(test_restriction_arg, local_node_index)
|
|
668
|
+
node_index = test.space_restriction.node_partition_index(test_restriction_arg, local_node_index)
|
|
669
|
+
|
|
670
|
+
val_sum = accumulate_dtype(0.0)
|
|
671
|
+
|
|
672
|
+
for n in range(element_count):
|
|
673
|
+
node_element_index = test.space_restriction.node_element_index(test_restriction_arg, local_node_index, n)
|
|
674
|
+
element_index = domain.element_index(domain_index_arg, node_element_index.domain_element_index)
|
|
675
|
+
|
|
676
|
+
coords = test.space.node_coords_in_element(
|
|
677
|
+
domain_arg,
|
|
678
|
+
_get_test_arg(),
|
|
679
|
+
element_index,
|
|
680
|
+
node_element_index.node_index_in_element,
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
if coords[0] != OUTSIDE:
|
|
684
|
+
node_weight = test.space.node_quadrature_weight(
|
|
685
|
+
domain_arg,
|
|
686
|
+
_get_test_arg(),
|
|
687
|
+
element_index,
|
|
688
|
+
node_element_index.node_index_in_element,
|
|
689
|
+
)
|
|
690
|
+
|
|
691
|
+
test_dof_index = DofIndex(node_element_index.node_index_in_element, test_dof)
|
|
692
|
+
trial_dof_index = DofIndex(node_element_index.node_index_in_element, trial_dof)
|
|
693
|
+
|
|
694
|
+
sample = Sample(
|
|
695
|
+
element_index,
|
|
696
|
+
coords,
|
|
697
|
+
node_index,
|
|
698
|
+
node_weight,
|
|
699
|
+
test_dof_index,
|
|
700
|
+
trial_dof_index,
|
|
701
|
+
)
|
|
702
|
+
vol = domain.element_measure(domain_arg, sample)
|
|
703
|
+
val = integrand_func(sample, fields, values)
|
|
704
|
+
|
|
705
|
+
val_sum += accumulate_dtype(node_weight * vol * val)
|
|
706
|
+
|
|
707
|
+
triplet_values[local_node_index, test_dof, trial_dof] = output_dtype(val_sum)
|
|
708
|
+
triplet_rows[local_node_index] = node_index
|
|
709
|
+
triplet_cols[local_node_index] = node_index
|
|
710
|
+
|
|
711
|
+
return integrate_kernel_fn
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
def _generate_integrate_kernel(
|
|
715
|
+
integrand: Integrand,
|
|
716
|
+
domain: GeometryDomain,
|
|
717
|
+
nodal: bool,
|
|
718
|
+
quadrature: Quadrature,
|
|
719
|
+
test: Optional[TestField],
|
|
720
|
+
test_name: str,
|
|
721
|
+
trial: Optional[TrialField],
|
|
722
|
+
trial_name: str,
|
|
723
|
+
fields: Dict[str, FieldLike],
|
|
724
|
+
output_dtype: type,
|
|
725
|
+
accumulate_dtype: type,
|
|
726
|
+
kernel_options: Optional[Dict[str, Any]] = None,
|
|
727
|
+
) -> wp.Kernel:
|
|
728
|
+
if kernel_options is None:
|
|
729
|
+
kernel_options = {}
|
|
730
|
+
|
|
731
|
+
output_dtype = wp.types.type_scalar_type(output_dtype)
|
|
732
|
+
|
|
733
|
+
# Extract field arguments from integrand
|
|
734
|
+
field_args, value_args, domain_name, sample_name = _get_integrand_field_arguments(
|
|
735
|
+
integrand, fields=fields, domain=domain
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
FieldStruct = _gen_field_struct(field_args)
|
|
739
|
+
ValueStruct = _gen_value_struct(value_args)
|
|
740
|
+
|
|
741
|
+
# Check if kernel exist in cache
|
|
742
|
+
kernel_suffix = f"_itg_{wp.types.type_typestr(output_dtype)}{wp.types.type_typestr(accumulate_dtype)}_{domain.name}_{FieldStruct.key}"
|
|
743
|
+
if nodal:
|
|
744
|
+
kernel_suffix += "_nodal"
|
|
745
|
+
else:
|
|
746
|
+
kernel_suffix += quadrature.name
|
|
747
|
+
|
|
748
|
+
if test:
|
|
749
|
+
kernel_suffix += f"_test_{test.space_partition.name}_{test.space.name}"
|
|
750
|
+
if trial:
|
|
751
|
+
kernel_suffix += f"_trial_{trial.space_partition.name}_{trial.space.name}"
|
|
752
|
+
|
|
753
|
+
kernel = cache.get_integrand_kernel(
|
|
754
|
+
integrand=integrand,
|
|
755
|
+
suffix=kernel_suffix,
|
|
756
|
+
)
|
|
757
|
+
if kernel is not None:
|
|
758
|
+
return kernel, FieldStruct, ValueStruct
|
|
759
|
+
|
|
760
|
+
# Not found in cache, transform integrand and generate kernel
|
|
761
|
+
|
|
762
|
+
integrand_func = _translate_integrand(
|
|
763
|
+
integrand,
|
|
764
|
+
field_args,
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
_register_integrand_field_wrappers(integrand_func, fields)
|
|
768
|
+
|
|
769
|
+
if test is None and trial is None:
|
|
770
|
+
integrate_kernel_fn = get_integrate_constant_kernel(
|
|
771
|
+
integrand_func,
|
|
772
|
+
domain,
|
|
773
|
+
quadrature,
|
|
774
|
+
FieldStruct,
|
|
775
|
+
ValueStruct,
|
|
776
|
+
accumulate_dtype=accumulate_dtype,
|
|
777
|
+
)
|
|
778
|
+
elif trial is None:
|
|
779
|
+
if nodal:
|
|
780
|
+
integrate_kernel_fn = get_integrate_linear_nodal_kernel(
|
|
781
|
+
integrand_func,
|
|
782
|
+
domain,
|
|
783
|
+
FieldStruct,
|
|
784
|
+
ValueStruct,
|
|
785
|
+
test=test,
|
|
786
|
+
output_dtype=output_dtype,
|
|
787
|
+
accumulate_dtype=accumulate_dtype,
|
|
788
|
+
)
|
|
789
|
+
else:
|
|
790
|
+
integrate_kernel_fn = get_integrate_linear_kernel(
|
|
791
|
+
integrand_func,
|
|
792
|
+
domain,
|
|
793
|
+
quadrature,
|
|
794
|
+
FieldStruct,
|
|
795
|
+
ValueStruct,
|
|
796
|
+
test=test,
|
|
797
|
+
output_dtype=output_dtype,
|
|
798
|
+
accumulate_dtype=accumulate_dtype,
|
|
799
|
+
)
|
|
800
|
+
else:
|
|
801
|
+
if nodal:
|
|
802
|
+
integrate_kernel_fn = get_integrate_bilinear_nodal_kernel(
|
|
803
|
+
integrand_func,
|
|
804
|
+
domain,
|
|
805
|
+
FieldStruct,
|
|
806
|
+
ValueStruct,
|
|
807
|
+
test=test,
|
|
808
|
+
output_dtype=output_dtype,
|
|
809
|
+
accumulate_dtype=accumulate_dtype,
|
|
810
|
+
)
|
|
811
|
+
else:
|
|
812
|
+
integrate_kernel_fn = get_integrate_bilinear_kernel(
|
|
813
|
+
integrand_func,
|
|
814
|
+
domain,
|
|
815
|
+
quadrature,
|
|
816
|
+
FieldStruct,
|
|
817
|
+
ValueStruct,
|
|
818
|
+
test=test,
|
|
819
|
+
trial=trial,
|
|
820
|
+
output_dtype=output_dtype,
|
|
821
|
+
accumulate_dtype=accumulate_dtype,
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
kernel = cache.get_integrand_kernel(
|
|
825
|
+
integrand=integrand,
|
|
826
|
+
kernel_fn=integrate_kernel_fn,
|
|
827
|
+
suffix=kernel_suffix,
|
|
828
|
+
kernel_options=kernel_options,
|
|
829
|
+
code_transformers=[
|
|
830
|
+
PassFieldArgsToIntegrand(
|
|
831
|
+
arg_names=integrand.argspec.args,
|
|
832
|
+
field_args=field_args.keys(),
|
|
833
|
+
value_args=value_args.keys(),
|
|
834
|
+
sample_name=sample_name,
|
|
835
|
+
domain_name=domain_name,
|
|
836
|
+
test_name=test_name,
|
|
837
|
+
trial_name=trial_name,
|
|
838
|
+
)
|
|
839
|
+
],
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
return kernel, FieldStruct, ValueStruct
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
def _launch_integrate_kernel(
|
|
846
|
+
kernel: wp.Kernel,
|
|
847
|
+
FieldStruct: wp.codegen.Struct,
|
|
848
|
+
ValueStruct: wp.codegen.Struct,
|
|
849
|
+
domain: GeometryDomain,
|
|
850
|
+
nodal: bool,
|
|
851
|
+
quadrature: Quadrature,
|
|
852
|
+
test: Optional[TestField],
|
|
853
|
+
trial: Optional[TrialField],
|
|
854
|
+
fields: Dict[str, FieldLike],
|
|
855
|
+
values: Dict[str, Any],
|
|
856
|
+
accumulate_dtype: type,
|
|
857
|
+
temporary_store: Optional[cache.TemporaryStore],
|
|
858
|
+
output_dtype: type,
|
|
859
|
+
output: Optional[Union[wp.array, BsrMatrix]],
|
|
860
|
+
device,
|
|
861
|
+
):
|
|
862
|
+
# Set-up launch arguments
|
|
863
|
+
domain_elt_arg = domain.element_arg_value(device=device)
|
|
864
|
+
domain_elt_index_arg = domain.element_index_arg_value(device=device)
|
|
865
|
+
|
|
866
|
+
if quadrature is not None:
|
|
867
|
+
qp_arg = quadrature.arg_value(device=device)
|
|
868
|
+
|
|
869
|
+
field_arg_values = FieldStruct()
|
|
870
|
+
for k, v in fields.items():
|
|
871
|
+
setattr(field_arg_values, k, v.eval_arg_value(device=device))
|
|
872
|
+
|
|
873
|
+
value_struct_values = ValueStruct()
|
|
874
|
+
for k, v in values.items():
|
|
875
|
+
setattr(value_struct_values, k, v)
|
|
876
|
+
|
|
877
|
+
# Constant form
|
|
878
|
+
if test is None and trial is None:
|
|
879
|
+
if output is not None and output.dtype == accumulate_dtype:
|
|
880
|
+
if output.size < 1:
|
|
881
|
+
raise RuntimeError("Output array must be of size at least 1")
|
|
882
|
+
accumulate_array = output
|
|
883
|
+
else:
|
|
884
|
+
accumulate_temporary = cache.borrow_temporary(
|
|
885
|
+
shape=(1),
|
|
886
|
+
device=device,
|
|
887
|
+
dtype=accumulate_dtype,
|
|
888
|
+
temporary_store=temporary_store,
|
|
889
|
+
requires_grad=output is not None and output.requires_grad,
|
|
890
|
+
)
|
|
891
|
+
accumulate_array = accumulate_temporary.array
|
|
892
|
+
|
|
893
|
+
accumulate_array.zero_()
|
|
894
|
+
wp.launch(
|
|
895
|
+
kernel=kernel,
|
|
896
|
+
dim=domain.element_count(),
|
|
897
|
+
inputs=[
|
|
898
|
+
qp_arg,
|
|
899
|
+
domain_elt_arg,
|
|
900
|
+
domain_elt_index_arg,
|
|
901
|
+
field_arg_values,
|
|
902
|
+
value_struct_values,
|
|
903
|
+
accumulate_array,
|
|
904
|
+
],
|
|
905
|
+
device=device,
|
|
906
|
+
)
|
|
907
|
+
|
|
908
|
+
if output == accumulate_array:
|
|
909
|
+
return output
|
|
910
|
+
elif output is None:
|
|
911
|
+
return accumulate_array.numpy()[0]
|
|
912
|
+
else:
|
|
913
|
+
array_cast(in_array=accumulate_array, out_array=output)
|
|
914
|
+
return output
|
|
915
|
+
|
|
916
|
+
test_arg = test.space_restriction.node_arg(device=device)
|
|
917
|
+
|
|
918
|
+
# Linear form
|
|
919
|
+
if trial is None:
|
|
920
|
+
# If an output array is provided with the correct type, accumulate directly into it
|
|
921
|
+
# Otherwise, grab a temporary array
|
|
922
|
+
if output is None:
|
|
923
|
+
if type_length(output_dtype) == test.space.VALUE_DOF_COUNT:
|
|
924
|
+
output_shape = (test.space_partition.node_count(),)
|
|
925
|
+
elif type_length(output_dtype) == 1:
|
|
926
|
+
output_shape = (test.space_partition.node_count(), test.space.VALUE_DOF_COUNT)
|
|
927
|
+
else:
|
|
928
|
+
raise RuntimeError(
|
|
929
|
+
f"Incompatible output type {wp.types.type_repr(output_dtype)}, must be scalar or vector of length {test.space.VALUE_DOF_COUNT}"
|
|
930
|
+
)
|
|
931
|
+
|
|
932
|
+
output_temporary = cache.borrow_temporary(
|
|
933
|
+
temporary_store=temporary_store,
|
|
934
|
+
shape=output_shape,
|
|
935
|
+
dtype=output_dtype,
|
|
936
|
+
device=device,
|
|
937
|
+
)
|
|
938
|
+
|
|
939
|
+
output = output_temporary.array
|
|
940
|
+
|
|
941
|
+
else:
|
|
942
|
+
output_temporary = None
|
|
943
|
+
|
|
944
|
+
if output.shape[0] < test.space_partition.node_count():
|
|
945
|
+
raise RuntimeError(f"Output array must have at least {test.space_partition.node_count()} rows")
|
|
946
|
+
|
|
947
|
+
output_dtype = output.dtype
|
|
948
|
+
if type_length(output_dtype) != test.space.VALUE_DOF_COUNT:
|
|
949
|
+
if type_length(output_dtype) != 1:
|
|
950
|
+
raise RuntimeError(
|
|
951
|
+
f"Incompatible output type {wp.types.type_repr(output_dtype)}, must be scalar or vector of length {test.space.VALUE_DOF_COUNT}"
|
|
952
|
+
)
|
|
953
|
+
if output.ndim != 2 and output.shape[1] != test.space.VALUE_DOF_COUNT:
|
|
954
|
+
raise RuntimeError(
|
|
955
|
+
f"Incompatible output array shape, last dimension must be of size {test.space.VALUE_DOF_COUNT}"
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
# Launch the integration on the kernel on a 2d scalar view of the actual array
|
|
959
|
+
output.zero_()
|
|
960
|
+
|
|
961
|
+
def as_2d_array(array):
|
|
962
|
+
return wp.array(
|
|
963
|
+
data=None,
|
|
964
|
+
ptr=array.ptr,
|
|
965
|
+
capacity=array.capacity,
|
|
966
|
+
device=array.device,
|
|
967
|
+
shape=(test.space_partition.node_count(), test.space.VALUE_DOF_COUNT),
|
|
968
|
+
dtype=wp.types.type_scalar_type(output_dtype),
|
|
969
|
+
grad=None if array.grad is None else as_2d_array(array.grad),
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
output_view = output if output.ndim == 2 else as_2d_array(output)
|
|
973
|
+
|
|
974
|
+
if nodal:
|
|
975
|
+
wp.launch(
|
|
976
|
+
kernel=kernel,
|
|
977
|
+
dim=(test.space_restriction.node_count(), test.space.VALUE_DOF_COUNT),
|
|
978
|
+
inputs=[
|
|
979
|
+
domain_elt_arg,
|
|
980
|
+
domain_elt_index_arg,
|
|
981
|
+
test_arg,
|
|
982
|
+
field_arg_values,
|
|
983
|
+
value_struct_values,
|
|
984
|
+
output_view,
|
|
985
|
+
],
|
|
986
|
+
device=device,
|
|
987
|
+
)
|
|
988
|
+
else:
|
|
989
|
+
wp.launch(
|
|
990
|
+
kernel=kernel,
|
|
991
|
+
dim=(test.space_restriction.node_count(), test.space.VALUE_DOF_COUNT),
|
|
992
|
+
inputs=[
|
|
993
|
+
qp_arg,
|
|
994
|
+
domain_elt_arg,
|
|
995
|
+
domain_elt_index_arg,
|
|
996
|
+
test_arg,
|
|
997
|
+
field_arg_values,
|
|
998
|
+
value_struct_values,
|
|
999
|
+
output_view,
|
|
1000
|
+
],
|
|
1001
|
+
device=device,
|
|
1002
|
+
)
|
|
1003
|
+
|
|
1004
|
+
if output_temporary is not None:
|
|
1005
|
+
return output_temporary.detach()
|
|
1006
|
+
|
|
1007
|
+
return output
|
|
1008
|
+
|
|
1009
|
+
# Bilinear form
|
|
1010
|
+
|
|
1011
|
+
if test.space.VALUE_DOF_COUNT == 1 and trial.space.VALUE_DOF_COUNT == 1:
|
|
1012
|
+
block_type = output_dtype
|
|
1013
|
+
else:
|
|
1014
|
+
block_type = cache.cached_mat_type(
|
|
1015
|
+
shape=(test.space.VALUE_DOF_COUNT, trial.space.VALUE_DOF_COUNT), dtype=output_dtype
|
|
1016
|
+
)
|
|
1017
|
+
|
|
1018
|
+
if nodal:
|
|
1019
|
+
nnz = test.space_restriction.node_count()
|
|
1020
|
+
else:
|
|
1021
|
+
nnz = test.space_restriction.total_node_element_count() * trial.space.topology.NODES_PER_ELEMENT
|
|
1022
|
+
|
|
1023
|
+
triplet_rows_temp = cache.borrow_temporary(temporary_store, shape=(nnz,), dtype=int, device=device)
|
|
1024
|
+
triplet_cols_temp = cache.borrow_temporary(temporary_store, shape=(nnz,), dtype=int, device=device)
|
|
1025
|
+
triplet_values_temp = cache.borrow_temporary(
|
|
1026
|
+
temporary_store,
|
|
1027
|
+
shape=(
|
|
1028
|
+
nnz,
|
|
1029
|
+
test.space.VALUE_DOF_COUNT,
|
|
1030
|
+
trial.space.VALUE_DOF_COUNT,
|
|
1031
|
+
),
|
|
1032
|
+
dtype=output_dtype,
|
|
1033
|
+
device=device,
|
|
1034
|
+
)
|
|
1035
|
+
triplet_cols = triplet_cols_temp.array
|
|
1036
|
+
triplet_rows = triplet_rows_temp.array
|
|
1037
|
+
triplet_values = triplet_values_temp.array
|
|
1038
|
+
|
|
1039
|
+
triplet_values.zero_()
|
|
1040
|
+
|
|
1041
|
+
if nodal:
|
|
1042
|
+
wp.launch(
|
|
1043
|
+
kernel=kernel,
|
|
1044
|
+
dim=triplet_values.shape,
|
|
1045
|
+
inputs=[
|
|
1046
|
+
domain_elt_arg,
|
|
1047
|
+
domain_elt_index_arg,
|
|
1048
|
+
test_arg,
|
|
1049
|
+
field_arg_values,
|
|
1050
|
+
value_struct_values,
|
|
1051
|
+
triplet_rows,
|
|
1052
|
+
triplet_cols,
|
|
1053
|
+
triplet_values,
|
|
1054
|
+
],
|
|
1055
|
+
device=device,
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
else:
|
|
1059
|
+
offsets = test.space_restriction.partition_element_offsets()
|
|
1060
|
+
|
|
1061
|
+
trial_partition_arg = trial.space_partition.partition_arg_value(device)
|
|
1062
|
+
trial_topology_arg = trial.space_partition.space_topology.topo_arg_value(device)
|
|
1063
|
+
wp.launch(
|
|
1064
|
+
kernel=kernel,
|
|
1065
|
+
dim=(
|
|
1066
|
+
test.space_restriction.node_count(),
|
|
1067
|
+
trial.space.topology.NODES_PER_ELEMENT,
|
|
1068
|
+
test.space.VALUE_DOF_COUNT,
|
|
1069
|
+
trial.space.VALUE_DOF_COUNT,
|
|
1070
|
+
),
|
|
1071
|
+
inputs=[
|
|
1072
|
+
qp_arg,
|
|
1073
|
+
domain_elt_arg,
|
|
1074
|
+
domain_elt_index_arg,
|
|
1075
|
+
test_arg,
|
|
1076
|
+
trial_partition_arg,
|
|
1077
|
+
trial_topology_arg,
|
|
1078
|
+
field_arg_values,
|
|
1079
|
+
value_struct_values,
|
|
1080
|
+
offsets,
|
|
1081
|
+
triplet_rows,
|
|
1082
|
+
triplet_cols,
|
|
1083
|
+
triplet_values,
|
|
1084
|
+
],
|
|
1085
|
+
device=device,
|
|
1086
|
+
)
|
|
1087
|
+
|
|
1088
|
+
if output is not None:
|
|
1089
|
+
if output.nrow != test.space_partition.node_count() or output.ncol != trial.space_partition.node_count():
|
|
1090
|
+
raise RuntimeError(
|
|
1091
|
+
f"Output matrix must have {test.space_partition.node_count()} rows and {trial.space_partition.node_count()} columns of blocks"
|
|
1092
|
+
)
|
|
1093
|
+
|
|
1094
|
+
else:
|
|
1095
|
+
output = bsr_zeros(
|
|
1096
|
+
rows_of_blocks=test.space_partition.node_count(),
|
|
1097
|
+
cols_of_blocks=trial.space_partition.node_count(),
|
|
1098
|
+
block_type=block_type,
|
|
1099
|
+
device=device,
|
|
1100
|
+
)
|
|
1101
|
+
|
|
1102
|
+
bsr_set_from_triplets(output, triplet_rows, triplet_cols, triplet_values)
|
|
1103
|
+
|
|
1104
|
+
# Do not wait for garbage collection
|
|
1105
|
+
triplet_values_temp.release()
|
|
1106
|
+
triplet_rows_temp.release()
|
|
1107
|
+
triplet_cols_temp.release()
|
|
1108
|
+
|
|
1109
|
+
return output
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
def integrate(
|
|
1113
|
+
integrand: Integrand,
|
|
1114
|
+
domain: Optional[GeometryDomain] = None,
|
|
1115
|
+
quadrature: Optional[Quadrature] = None,
|
|
1116
|
+
nodal: bool = False,
|
|
1117
|
+
fields: Optional[Dict[str, FieldLike]] = None,
|
|
1118
|
+
values: Optional[Dict[str, Any]] = None,
|
|
1119
|
+
accumulate_dtype: type = wp.float64,
|
|
1120
|
+
output_dtype: Optional[type] = None,
|
|
1121
|
+
output: Optional[Union[BsrMatrix, wp.array]] = None,
|
|
1122
|
+
device=None,
|
|
1123
|
+
temporary_store: Optional[cache.TemporaryStore] = None,
|
|
1124
|
+
kernel_options: Optional[Dict[str, Any]] = None,
|
|
1125
|
+
):
|
|
1126
|
+
"""
|
|
1127
|
+
Integrates a constant, linear or bilinear form, and returns a scalar, array, or sparse matrix, respectively.
|
|
1128
|
+
|
|
1129
|
+
Args:
|
|
1130
|
+
integrand: Form to be integrated, must have :func:`integrand` decorator
|
|
1131
|
+
domain: Integration domain. If None, deduced from fields
|
|
1132
|
+
quadrature: Quadrature formula. If None, deduced from domain and fields degree.
|
|
1133
|
+
nodal: For linear or bilinear form only, use the test function nodes as the quadrature points. Assumes Lagrange interpolation functions are used, and no differential or DG operator is evaluated on the test or trial functions.
|
|
1134
|
+
fields: Discrete, test, and trial fields to be passed to the integrand. Keys in the dictionary must match integrand parameter names.
|
|
1135
|
+
values: Additional variable values to be passed to the integrand, can be of any type accepted by warp kernel launches. Keys in the dictionary must match integrand parameter names.
|
|
1136
|
+
temporary_store: shared pool from which to allocate temporary arrays
|
|
1137
|
+
accumulate_dtype: Scalar type to be used for accumulating integration samples
|
|
1138
|
+
output: Sparse matrix or warp array into which to store the result of the integration
|
|
1139
|
+
output_dtype: Scalar type for returned results in `output` is not provided. If None, defaults to `accumulate_dtype`
|
|
1140
|
+
device: Device on which to perform the integration
|
|
1141
|
+
kernel_options: Overloaded options to be passed to the kernel builder (e.g, ``{"enable_backward": True}``)
|
|
1142
|
+
"""
|
|
1143
|
+
if fields is None:
|
|
1144
|
+
fields = {}
|
|
1145
|
+
|
|
1146
|
+
if values is None:
|
|
1147
|
+
values = {}
|
|
1148
|
+
|
|
1149
|
+
if kernel_options is None:
|
|
1150
|
+
kernel_options = {}
|
|
1151
|
+
|
|
1152
|
+
if not isinstance(integrand, Integrand):
|
|
1153
|
+
raise ValueError("integrand must be tagged with @warp.fem.integrand decorator")
|
|
1154
|
+
|
|
1155
|
+
test, test_name, trial, trial_name = _get_test_and_trial_fields(fields)
|
|
1156
|
+
|
|
1157
|
+
if domain is None:
|
|
1158
|
+
if quadrature is not None:
|
|
1159
|
+
domain = quadrature.domain
|
|
1160
|
+
elif test is not None:
|
|
1161
|
+
domain = test.domain
|
|
1162
|
+
|
|
1163
|
+
if domain is None:
|
|
1164
|
+
raise ValueError("Must provide at least one of domain, quadrature, or test field")
|
|
1165
|
+
if test is not None and domain != test.domain:
|
|
1166
|
+
raise NotImplementedError("Mixing integration and test domain is not supported yet")
|
|
1167
|
+
|
|
1168
|
+
if nodal:
|
|
1169
|
+
if quadrature is not None:
|
|
1170
|
+
raise ValueError("Cannot specify quadrature for nodal integration")
|
|
1171
|
+
|
|
1172
|
+
if test is None:
|
|
1173
|
+
raise ValueError("Nodal integration requires specifying a test function")
|
|
1174
|
+
|
|
1175
|
+
if trial is not None and test.space_partition != trial.space_partition:
|
|
1176
|
+
raise ValueError(
|
|
1177
|
+
"Bilinear nodal integration requires test and trial to be defined on the same function space"
|
|
1178
|
+
)
|
|
1179
|
+
else:
|
|
1180
|
+
if quadrature is None:
|
|
1181
|
+
order = sum(field.degree for field in fields.values())
|
|
1182
|
+
quadrature = RegularQuadrature(domain=domain, order=order)
|
|
1183
|
+
elif domain != quadrature.domain:
|
|
1184
|
+
raise ValueError("Incompatible integration and quadrature domain")
|
|
1185
|
+
|
|
1186
|
+
# Canonicalize types
|
|
1187
|
+
accumulate_dtype = wp.types.type_to_warp(accumulate_dtype)
|
|
1188
|
+
if output is not None:
|
|
1189
|
+
if isinstance(output, BsrMatrix):
|
|
1190
|
+
output_dtype = output.scalar_type
|
|
1191
|
+
else:
|
|
1192
|
+
output_dtype = output.dtype
|
|
1193
|
+
elif output_dtype is None:
|
|
1194
|
+
output_dtype = accumulate_dtype
|
|
1195
|
+
else:
|
|
1196
|
+
output_dtype = wp.types.type_to_warp(output_dtype)
|
|
1197
|
+
|
|
1198
|
+
kernel, FieldStruct, ValueStruct = _generate_integrate_kernel(
|
|
1199
|
+
integrand=integrand,
|
|
1200
|
+
domain=domain,
|
|
1201
|
+
nodal=nodal,
|
|
1202
|
+
quadrature=quadrature,
|
|
1203
|
+
test=test,
|
|
1204
|
+
test_name=test_name,
|
|
1205
|
+
trial=trial,
|
|
1206
|
+
trial_name=trial_name,
|
|
1207
|
+
fields=fields,
|
|
1208
|
+
accumulate_dtype=accumulate_dtype,
|
|
1209
|
+
output_dtype=output_dtype,
|
|
1210
|
+
kernel_options=kernel_options,
|
|
1211
|
+
)
|
|
1212
|
+
|
|
1213
|
+
return _launch_integrate_kernel(
|
|
1214
|
+
kernel=kernel,
|
|
1215
|
+
FieldStruct=FieldStruct,
|
|
1216
|
+
ValueStruct=ValueStruct,
|
|
1217
|
+
domain=domain,
|
|
1218
|
+
nodal=nodal,
|
|
1219
|
+
quadrature=quadrature,
|
|
1220
|
+
test=test,
|
|
1221
|
+
trial=trial,
|
|
1222
|
+
fields=fields,
|
|
1223
|
+
values=values,
|
|
1224
|
+
accumulate_dtype=accumulate_dtype,
|
|
1225
|
+
temporary_store=temporary_store,
|
|
1226
|
+
output_dtype=output_dtype,
|
|
1227
|
+
output=output,
|
|
1228
|
+
device=device,
|
|
1229
|
+
)
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
def get_interpolate_to_field_function(
|
|
1233
|
+
integrand_func: wp.Function,
|
|
1234
|
+
domain: GeometryDomain,
|
|
1235
|
+
FieldStruct: wp.codegen.Struct,
|
|
1236
|
+
ValueStruct: wp.codegen.Struct,
|
|
1237
|
+
dest: FieldRestriction,
|
|
1238
|
+
):
|
|
1239
|
+
value_type = dest.space.dtype
|
|
1240
|
+
|
|
1241
|
+
def interpolate_to_field_fn(
|
|
1242
|
+
local_node_index: int,
|
|
1243
|
+
domain_arg: domain.ElementArg,
|
|
1244
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
1245
|
+
dest_node_arg: dest.space_restriction.NodeArg,
|
|
1246
|
+
dest_eval_arg: dest.field.EvalArg,
|
|
1247
|
+
fields: FieldStruct,
|
|
1248
|
+
values: ValueStruct,
|
|
1249
|
+
):
|
|
1250
|
+
node_index = dest.space_restriction.node_partition_index(dest_node_arg, local_node_index)
|
|
1251
|
+
element_count = dest.space_restriction.node_element_count(dest_node_arg, local_node_index)
|
|
1252
|
+
|
|
1253
|
+
test_dof_index = NULL_DOF_INDEX
|
|
1254
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
1255
|
+
node_weight = 1.0
|
|
1256
|
+
|
|
1257
|
+
# Volume-weighted average across elements
|
|
1258
|
+
# Superfluous if the interpolated function is continuous, but helpful for visualizing discontinuous spaces
|
|
1259
|
+
|
|
1260
|
+
val_sum = value_type(0.0)
|
|
1261
|
+
vol_sum = float(0.0)
|
|
1262
|
+
|
|
1263
|
+
for n in range(element_count):
|
|
1264
|
+
node_element_index = dest.space_restriction.node_element_index(dest_node_arg, local_node_index, n)
|
|
1265
|
+
element_index = domain.element_index(domain_index_arg, node_element_index.domain_element_index)
|
|
1266
|
+
|
|
1267
|
+
coords = dest.space.node_coords_in_element(
|
|
1268
|
+
domain_arg,
|
|
1269
|
+
dest_eval_arg.space_arg,
|
|
1270
|
+
element_index,
|
|
1271
|
+
node_element_index.node_index_in_element,
|
|
1272
|
+
)
|
|
1273
|
+
|
|
1274
|
+
if coords[0] != OUTSIDE:
|
|
1275
|
+
sample = Sample(
|
|
1276
|
+
element_index,
|
|
1277
|
+
coords,
|
|
1278
|
+
node_index,
|
|
1279
|
+
node_weight,
|
|
1280
|
+
test_dof_index,
|
|
1281
|
+
trial_dof_index,
|
|
1282
|
+
)
|
|
1283
|
+
vol = domain.element_measure(domain_arg, sample)
|
|
1284
|
+
val = integrand_func(sample, fields, values)
|
|
1285
|
+
|
|
1286
|
+
vol_sum += vol
|
|
1287
|
+
val_sum += vol * val
|
|
1288
|
+
|
|
1289
|
+
return val_sum, vol_sum
|
|
1290
|
+
|
|
1291
|
+
return interpolate_to_field_fn
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
def get_interpolate_to_field_kernel(
|
|
1295
|
+
interpolate_to_field_fn: wp.Function,
|
|
1296
|
+
domain: GeometryDomain,
|
|
1297
|
+
FieldStruct: wp.codegen.Struct,
|
|
1298
|
+
ValueStruct: wp.codegen.Struct,
|
|
1299
|
+
dest: FieldRestriction,
|
|
1300
|
+
):
|
|
1301
|
+
def interpolate_to_field_kernel_fn(
|
|
1302
|
+
domain_arg: domain.ElementArg,
|
|
1303
|
+
domain_index_arg: domain.ElementIndexArg,
|
|
1304
|
+
dest_node_arg: dest.space_restriction.NodeArg,
|
|
1305
|
+
dest_eval_arg: dest.field.EvalArg,
|
|
1306
|
+
fields: FieldStruct,
|
|
1307
|
+
values: ValueStruct,
|
|
1308
|
+
):
|
|
1309
|
+
local_node_index = wp.tid()
|
|
1310
|
+
|
|
1311
|
+
val_sum, vol_sum = interpolate_to_field_fn(
|
|
1312
|
+
local_node_index, domain_arg, domain_index_arg, dest_node_arg, dest_eval_arg, fields, values
|
|
1313
|
+
)
|
|
1314
|
+
|
|
1315
|
+
if vol_sum > 0.0:
|
|
1316
|
+
node_index = dest.space_restriction.node_partition_index(dest_node_arg, local_node_index)
|
|
1317
|
+
dest.field.set_node_value(dest_eval_arg, node_index, val_sum / vol_sum)
|
|
1318
|
+
|
|
1319
|
+
return interpolate_to_field_kernel_fn
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
def get_interpolate_to_array_kernel(
|
|
1323
|
+
integrand_func: wp.Function,
|
|
1324
|
+
domain: GeometryDomain,
|
|
1325
|
+
quadrature: Quadrature,
|
|
1326
|
+
FieldStruct: wp.codegen.Struct,
|
|
1327
|
+
ValueStruct: wp.codegen.Struct,
|
|
1328
|
+
value_type: type,
|
|
1329
|
+
):
|
|
1330
|
+
def interpolate_to_array_kernel_fn(
|
|
1331
|
+
qp_arg: quadrature.Arg,
|
|
1332
|
+
domain_arg: quadrature.domain.ElementArg,
|
|
1333
|
+
domain_index_arg: quadrature.domain.ElementIndexArg,
|
|
1334
|
+
fields: FieldStruct,
|
|
1335
|
+
values: ValueStruct,
|
|
1336
|
+
result: wp.array(dtype=value_type),
|
|
1337
|
+
):
|
|
1338
|
+
element_index = domain.element_index(domain_index_arg, wp.tid())
|
|
1339
|
+
|
|
1340
|
+
test_dof_index = NULL_DOF_INDEX
|
|
1341
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
1342
|
+
|
|
1343
|
+
qp_point_count = quadrature.point_count(domain_arg, qp_arg, element_index)
|
|
1344
|
+
for k in range(qp_point_count):
|
|
1345
|
+
qp_index = quadrature.point_index(domain_arg, qp_arg, element_index, k)
|
|
1346
|
+
coords = quadrature.point_coords(domain_arg, qp_arg, element_index, k)
|
|
1347
|
+
qp_weight = quadrature.point_weight(domain_arg, qp_arg, element_index, k)
|
|
1348
|
+
|
|
1349
|
+
sample = Sample(element_index, coords, qp_index, qp_weight, test_dof_index, trial_dof_index)
|
|
1350
|
+
|
|
1351
|
+
result[qp_index] = integrand_func(sample, fields, values)
|
|
1352
|
+
|
|
1353
|
+
return interpolate_to_array_kernel_fn
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
def get_interpolate_nonvalued_kernel(
|
|
1357
|
+
integrand_func: wp.Function,
|
|
1358
|
+
domain: GeometryDomain,
|
|
1359
|
+
quadrature: Quadrature,
|
|
1360
|
+
FieldStruct: wp.codegen.Struct,
|
|
1361
|
+
ValueStruct: wp.codegen.Struct,
|
|
1362
|
+
):
|
|
1363
|
+
def interpolate_nonvalued_kernel_fn(
|
|
1364
|
+
qp_arg: quadrature.Arg,
|
|
1365
|
+
domain_arg: quadrature.domain.ElementArg,
|
|
1366
|
+
domain_index_arg: quadrature.domain.ElementIndexArg,
|
|
1367
|
+
fields: FieldStruct,
|
|
1368
|
+
values: ValueStruct,
|
|
1369
|
+
):
|
|
1370
|
+
element_index = domain.element_index(domain_index_arg, wp.tid())
|
|
1371
|
+
|
|
1372
|
+
test_dof_index = NULL_DOF_INDEX
|
|
1373
|
+
trial_dof_index = NULL_DOF_INDEX
|
|
1374
|
+
|
|
1375
|
+
qp_point_count = quadrature.point_count(domain_arg, qp_arg, element_index)
|
|
1376
|
+
for k in range(qp_point_count):
|
|
1377
|
+
qp_index = quadrature.point_index(domain_arg, qp_arg, element_index, k)
|
|
1378
|
+
coords = quadrature.point_coords(domain_arg, qp_arg, element_index, k)
|
|
1379
|
+
qp_weight = quadrature.point_weight(domain_arg, qp_arg, element_index, k)
|
|
1380
|
+
|
|
1381
|
+
sample = Sample(element_index, coords, qp_index, qp_weight, test_dof_index, trial_dof_index)
|
|
1382
|
+
integrand_func(sample, fields, values)
|
|
1383
|
+
|
|
1384
|
+
return interpolate_nonvalued_kernel_fn
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
def _generate_interpolate_kernel(
|
|
1388
|
+
integrand: Integrand,
|
|
1389
|
+
domain: GeometryDomain,
|
|
1390
|
+
dest: Optional[Union[FieldLike, wp.array]],
|
|
1391
|
+
quadrature: Optional[Quadrature],
|
|
1392
|
+
fields: Dict[str, FieldLike],
|
|
1393
|
+
kernel_options: Optional[Dict[str, Any]] = None,
|
|
1394
|
+
) -> wp.Kernel:
|
|
1395
|
+
if kernel_options is None:
|
|
1396
|
+
kernel_options = {}
|
|
1397
|
+
|
|
1398
|
+
# Extract field arguments from integrand
|
|
1399
|
+
field_args, value_args, domain_name, sample_name = _get_integrand_field_arguments(
|
|
1400
|
+
integrand, fields=fields, domain=domain
|
|
1401
|
+
)
|
|
1402
|
+
|
|
1403
|
+
# Generate field struct
|
|
1404
|
+
integrand_func = _translate_integrand(
|
|
1405
|
+
integrand,
|
|
1406
|
+
field_args,
|
|
1407
|
+
)
|
|
1408
|
+
|
|
1409
|
+
_register_integrand_field_wrappers(integrand_func, fields)
|
|
1410
|
+
|
|
1411
|
+
FieldStruct = _gen_field_struct(field_args)
|
|
1412
|
+
ValueStruct = _gen_value_struct(value_args)
|
|
1413
|
+
|
|
1414
|
+
# Check if kernel exist in cache
|
|
1415
|
+
if isinstance(dest, FieldRestriction):
|
|
1416
|
+
kernel_suffix = (
|
|
1417
|
+
f"_itp_{FieldStruct.key}_{dest.domain.name}_{dest.space_restriction.space_partition.name}_{dest.space.name}"
|
|
1418
|
+
)
|
|
1419
|
+
elif wp.types.is_array(dest):
|
|
1420
|
+
kernel_suffix = f"_itp_{FieldStruct.key}_{quadrature.name}_{wp.types.type_repr(dest.dtype)}"
|
|
1421
|
+
else:
|
|
1422
|
+
kernel_suffix = f"_itp_{FieldStruct.key}_{quadrature.name}"
|
|
1423
|
+
|
|
1424
|
+
kernel = cache.get_integrand_kernel(
|
|
1425
|
+
integrand=integrand,
|
|
1426
|
+
suffix=kernel_suffix,
|
|
1427
|
+
)
|
|
1428
|
+
if kernel is not None:
|
|
1429
|
+
return kernel, FieldStruct, ValueStruct
|
|
1430
|
+
|
|
1431
|
+
# Generate interpolation kernel
|
|
1432
|
+
if isinstance(dest, FieldRestriction):
|
|
1433
|
+
# need to split into kernel + function for diffferentiability
|
|
1434
|
+
interpolate_fn = get_interpolate_to_field_function(
|
|
1435
|
+
integrand_func,
|
|
1436
|
+
domain,
|
|
1437
|
+
dest=dest,
|
|
1438
|
+
FieldStruct=FieldStruct,
|
|
1439
|
+
ValueStruct=ValueStruct,
|
|
1440
|
+
)
|
|
1441
|
+
|
|
1442
|
+
interpolate_fn = cache.get_integrand_function(
|
|
1443
|
+
integrand=integrand,
|
|
1444
|
+
func=interpolate_fn,
|
|
1445
|
+
suffix=kernel_suffix,
|
|
1446
|
+
code_transformers=[
|
|
1447
|
+
PassFieldArgsToIntegrand(
|
|
1448
|
+
arg_names=integrand.argspec.args,
|
|
1449
|
+
field_args=field_args.keys(),
|
|
1450
|
+
value_args=value_args.keys(),
|
|
1451
|
+
sample_name=sample_name,
|
|
1452
|
+
domain_name=domain_name,
|
|
1453
|
+
)
|
|
1454
|
+
],
|
|
1455
|
+
)
|
|
1456
|
+
|
|
1457
|
+
interpolate_kernel_fn = get_interpolate_to_field_kernel(
|
|
1458
|
+
interpolate_fn,
|
|
1459
|
+
domain,
|
|
1460
|
+
dest=dest,
|
|
1461
|
+
FieldStruct=FieldStruct,
|
|
1462
|
+
ValueStruct=ValueStruct,
|
|
1463
|
+
)
|
|
1464
|
+
elif wp.types.is_array(dest):
|
|
1465
|
+
interpolate_kernel_fn = get_interpolate_to_array_kernel(
|
|
1466
|
+
integrand_func,
|
|
1467
|
+
domain=domain,
|
|
1468
|
+
quadrature=quadrature,
|
|
1469
|
+
value_type=dest.dtype,
|
|
1470
|
+
FieldStruct=FieldStruct,
|
|
1471
|
+
ValueStruct=ValueStruct,
|
|
1472
|
+
)
|
|
1473
|
+
else:
|
|
1474
|
+
interpolate_kernel_fn = get_interpolate_nonvalued_kernel(
|
|
1475
|
+
integrand_func,
|
|
1476
|
+
domain=domain,
|
|
1477
|
+
quadrature=quadrature,
|
|
1478
|
+
FieldStruct=FieldStruct,
|
|
1479
|
+
ValueStruct=ValueStruct,
|
|
1480
|
+
)
|
|
1481
|
+
|
|
1482
|
+
kernel = cache.get_integrand_kernel(
|
|
1483
|
+
integrand=integrand,
|
|
1484
|
+
kernel_fn=interpolate_kernel_fn,
|
|
1485
|
+
suffix=kernel_suffix,
|
|
1486
|
+
kernel_options=kernel_options,
|
|
1487
|
+
code_transformers=[
|
|
1488
|
+
PassFieldArgsToIntegrand(
|
|
1489
|
+
arg_names=integrand.argspec.args,
|
|
1490
|
+
field_args=field_args.keys(),
|
|
1491
|
+
value_args=value_args.keys(),
|
|
1492
|
+
sample_name=sample_name,
|
|
1493
|
+
domain_name=domain_name,
|
|
1494
|
+
)
|
|
1495
|
+
],
|
|
1496
|
+
)
|
|
1497
|
+
|
|
1498
|
+
return kernel, FieldStruct, ValueStruct
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
def _launch_interpolate_kernel(
|
|
1502
|
+
kernel: wp.kernel,
|
|
1503
|
+
FieldStruct: wp.codegen.Struct,
|
|
1504
|
+
ValueStruct: wp.codegen.Struct,
|
|
1505
|
+
domain: GeometryDomain,
|
|
1506
|
+
dest: Optional[Union[FieldRestriction, wp.array]],
|
|
1507
|
+
quadrature: Optional[Quadrature],
|
|
1508
|
+
fields: Dict[str, FieldLike],
|
|
1509
|
+
values: Dict[str, Any],
|
|
1510
|
+
device,
|
|
1511
|
+
) -> wp.Kernel:
|
|
1512
|
+
# Set-up launch arguments
|
|
1513
|
+
elt_arg = domain.element_arg_value(device=device)
|
|
1514
|
+
elt_index_arg = domain.element_index_arg_value(device=device)
|
|
1515
|
+
|
|
1516
|
+
field_arg_values = FieldStruct()
|
|
1517
|
+
for k, v in fields.items():
|
|
1518
|
+
setattr(field_arg_values, k, v.eval_arg_value(device=device))
|
|
1519
|
+
|
|
1520
|
+
value_struct_values = ValueStruct()
|
|
1521
|
+
for k, v in values.items():
|
|
1522
|
+
setattr(value_struct_values, k, v)
|
|
1523
|
+
|
|
1524
|
+
if isinstance(dest, FieldRestriction):
|
|
1525
|
+
dest_node_arg = dest.space_restriction.node_arg(device=device)
|
|
1526
|
+
dest_eval_arg = dest.field.eval_arg_value(device=device)
|
|
1527
|
+
|
|
1528
|
+
wp.launch(
|
|
1529
|
+
kernel=kernel,
|
|
1530
|
+
dim=dest.space_restriction.node_count(),
|
|
1531
|
+
inputs=[
|
|
1532
|
+
elt_arg,
|
|
1533
|
+
elt_index_arg,
|
|
1534
|
+
dest_node_arg,
|
|
1535
|
+
dest_eval_arg,
|
|
1536
|
+
field_arg_values,
|
|
1537
|
+
value_struct_values,
|
|
1538
|
+
],
|
|
1539
|
+
device=device,
|
|
1540
|
+
)
|
|
1541
|
+
elif wp.types.is_array(dest):
|
|
1542
|
+
qp_arg = quadrature.arg_value(device)
|
|
1543
|
+
wp.launch(
|
|
1544
|
+
kernel=kernel,
|
|
1545
|
+
dim=domain.element_count(),
|
|
1546
|
+
inputs=[qp_arg, elt_arg, elt_index_arg, field_arg_values, value_struct_values, dest],
|
|
1547
|
+
device=device,
|
|
1548
|
+
)
|
|
1549
|
+
else:
|
|
1550
|
+
qp_arg = quadrature.arg_value(device)
|
|
1551
|
+
wp.launch(
|
|
1552
|
+
kernel=kernel,
|
|
1553
|
+
dim=domain.element_count(),
|
|
1554
|
+
inputs=[qp_arg, elt_arg, elt_index_arg, field_arg_values, value_struct_values],
|
|
1555
|
+
device=device,
|
|
1556
|
+
)
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
def interpolate(
|
|
1560
|
+
integrand: Integrand,
|
|
1561
|
+
dest: Optional[Union[DiscreteField, FieldRestriction, wp.array]] = None,
|
|
1562
|
+
quadrature: Optional[Quadrature] = None,
|
|
1563
|
+
fields: Optional[Dict[str, FieldLike]] = None,
|
|
1564
|
+
values: Optional[Dict[str, Any]] = None,
|
|
1565
|
+
device=None,
|
|
1566
|
+
kernel_options: Optional[Dict[str, Any]] = None,
|
|
1567
|
+
):
|
|
1568
|
+
"""
|
|
1569
|
+
Interpolates a function at a finite set of sample points and optionally assigns the result to a discrete field or a raw warp array.
|
|
1570
|
+
|
|
1571
|
+
Args:
|
|
1572
|
+
integrand: Function to be interpolated, must have :func:`integrand` decorator
|
|
1573
|
+
dest: Where to store the interpolation result. Can be either
|
|
1574
|
+
|
|
1575
|
+
- a :class:`DiscreteField`, or restriction of a discrete field to a domain (from :func:`make_restriction`). In this case, interpolation will be performed at each node.
|
|
1576
|
+
- a normal warp array. In this case, the `quadrature` argument defining the interpolation locations must be provided and the result of the `integrand` at each quadrature point will be assigned to the array.
|
|
1577
|
+
- ``None``. In this case, the `quadrature` argument must also be provided and the `integrand` function is responsible for dealing with the interpolation result.
|
|
1578
|
+
quadrature: Quadrature formula defining the interpolation samples if `dest` is not a discrete field or field restriction.
|
|
1579
|
+
fields: Discrete fields to be passed to the integrand. Keys in the dictionary must match integrand parameters names.
|
|
1580
|
+
values: Additional variable values to be passed to the integrand, can be of any type accepted by warp kernel launches. Keys in the dictionary must match integrand parameter names.
|
|
1581
|
+
device: Device on which to perform the interpolation
|
|
1582
|
+
kernel_options: Overloaded options to be passed to the kernel builder (e.g, ``{"enable_backward": True}``)
|
|
1583
|
+
"""
|
|
1584
|
+
if fields is None:
|
|
1585
|
+
fields = {}
|
|
1586
|
+
|
|
1587
|
+
if values is None:
|
|
1588
|
+
values = {}
|
|
1589
|
+
|
|
1590
|
+
if kernel_options is None:
|
|
1591
|
+
kernel_options = {}
|
|
1592
|
+
|
|
1593
|
+
if not isinstance(integrand, Integrand):
|
|
1594
|
+
raise ValueError("integrand must be tagged with @integrand decorator")
|
|
1595
|
+
|
|
1596
|
+
test, _, trial, __ = _get_test_and_trial_fields(fields)
|
|
1597
|
+
if test is not None or trial is not None:
|
|
1598
|
+
raise ValueError("Test or Trial fields should not be used for interpolation")
|
|
1599
|
+
|
|
1600
|
+
if isinstance(dest, DiscreteField):
|
|
1601
|
+
dest = make_restriction(dest)
|
|
1602
|
+
|
|
1603
|
+
if isinstance(dest, FieldRestriction):
|
|
1604
|
+
domain = dest.domain
|
|
1605
|
+
else:
|
|
1606
|
+
if quadrature is None:
|
|
1607
|
+
raise ValueError("When not interpolating to a field, a quadrature formula must be provided")
|
|
1608
|
+
|
|
1609
|
+
domain = quadrature.domain
|
|
1610
|
+
|
|
1611
|
+
kernel, FieldStruct, ValueStruct = _generate_interpolate_kernel(
|
|
1612
|
+
integrand=integrand,
|
|
1613
|
+
domain=domain,
|
|
1614
|
+
dest=dest,
|
|
1615
|
+
quadrature=quadrature,
|
|
1616
|
+
fields=fields,
|
|
1617
|
+
kernel_options=kernel_options,
|
|
1618
|
+
)
|
|
1619
|
+
|
|
1620
|
+
return _launch_interpolate_kernel(
|
|
1621
|
+
kernel=kernel,
|
|
1622
|
+
FieldStruct=FieldStruct,
|
|
1623
|
+
ValueStruct=ValueStruct,
|
|
1624
|
+
domain=domain,
|
|
1625
|
+
dest=dest,
|
|
1626
|
+
quadrature=quadrature,
|
|
1627
|
+
fields=fields,
|
|
1628
|
+
values=values,
|
|
1629
|
+
device=device,
|
|
1630
|
+
)
|