diffneusim 1.0.0__py3-none-any.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.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1208 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
// D16 muscle stage (2026-11-02): the CPU reference of the muscle stage in the new
|
|
3
|
+
// layout, written as host / device templates so the GPU stage reuses it (the core/soft/*.h pattern). Lane = muscle.
|
|
4
|
+
//
|
|
5
|
+
// Per muscle m, in the order today's engine runs a substep (gpu_fullbody_vec_env.py: activation, then the step):
|
|
6
|
+
// 1. a = activation_step(u, a_prev, dt) a copy of core/mtu/activation.h (gmath below)
|
|
7
|
+
// 2. the via polyline p_j (fixed sites and moving sites, whose offset is a quartic in one joint angle) and l_MTU
|
|
8
|
+
// 3. the moment-arm row r_m = dl_m/dq on the muscle's own dofs D_m (below)
|
|
9
|
+
// 4. the fibre: Geyer 2010 backward-Euler equilibrium by Newton from the warm start (mtu_solve's Song branch,
|
|
10
|
+
// operation for operation, so a niter-40 run is bitwise today's), or the rigid-tendon closed form
|
|
11
|
+
// 5. tau -= F_m r_m, summed over muscles in model order by the caller (fixed order, no atomics)
|
|
12
|
+
//
|
|
13
|
+
// The row. With g_j = dl/dp_j = u_{j-1} - u_j (u_s the unit vector of segment s, u_{-1} = u_{n-1} = 0), a joint J moves
|
|
14
|
+
// the sites below it rigidly, so its entry is a . sum_{j below J} (p_j - c) x g_j for a hinge (world axis a, anchor c),
|
|
15
|
+
// a . sum g_j for a slide, and the body-frame components of sum (p_j - c) x g_j for a ball. A coupled joint adds its
|
|
16
|
+
// entry times theta'(q_master) to its master's slot. A moving site adds g_j . R_b off'(theta) to its cdof's slot.
|
|
17
|
+
// A joint that moves EVERY site of the muscle contributes exactly zero (sum_j g_j = 0 and sum_j p_j x g_j = 0 for a
|
|
18
|
+
// polyline), so the generator leaves it out: the free root always, and the common chain above the muscle. D_m is
|
|
19
|
+
// therefore model-sized and small (myoLeg26 mean 2.3, max 4; 14x mean 2.9, max 5).
|
|
20
|
+
//
|
|
21
|
+
// Model values are read through the hook-2 accessor mv.at(field, p) with p written exactly as the load
|
|
22
|
+
// (core/soft/EXTENSION_HOOKS.md), the view being the ModelView<Policy> (host and device; MVShared by default).
|
|
23
|
+
//
|
|
24
|
+
// Scope (fail fast at the generator): Geyer 2010 or Millard 2013 muscles, one law per model; via polylines only (today's
|
|
25
|
+
// engine has no wrapping), no compound joints.
|
|
26
|
+
//
|
|
27
|
+
// The law (2026-11-05; tools/d16_x14adj/MILLARD14_DESIGN.md). Geyer 2010 is today's code, unchanged. Millard 2013's damped
|
|
28
|
+
// equilibrium (Millard et al. 2013 Eq. 8, with Eq. 7's fibre lower bound, and Eqs. 14-15 for a rigid tendon) is the section
|
|
29
|
+
// "4m" below, ported operation for operation from core/mtu/solve.h (millard_eval, mtu_solve's l_ce Newton and rigid branch,
|
|
30
|
+
// mtu_solve_vjp), which stays its oracle. Its fields in MuscleTables exist under JS_MUS_MILLARD: always on the host (the CPU
|
|
31
|
+
// references read either law and dispatch on t.law), and on the device only in a build with -DD16_X14_MILLARD (engine14
|
|
32
|
+
// compiles a Millard case's extension with it). A Geyer device build therefore preprocesses to today's source.
|
|
33
|
+
#if !defined(__CUDACC__) || defined(D16_X14_MILLARD)
|
|
34
|
+
#define JS_MUS_MILLARD 1
|
|
35
|
+
#endif
|
|
36
|
+
#include <cassert>
|
|
37
|
+
#include "diffneusim/macros.h"
|
|
38
|
+
#include "../math/so3.h"
|
|
39
|
+
#include "../kin/kinematic_tree.h"
|
|
40
|
+
#include "gpu/model_view.cuh"
|
|
41
|
+
|
|
42
|
+
// rigid = 2 (2026-11-04, the review for the jump pair's J2-clean; tools/d16_14x/RIGID_TENDON_ASSESSMENT.md): a third value of the
|
|
43
|
+
// per-muscle rigid table, the rigid closed form with the old engine's fix (ea5f010f, DN_GEYER_RIGID_FIX): the fibre damping
|
|
44
|
+
// beta v0 and the force floored at 0 (no clamp: lce_min is 0 for Geyer, and gate (a) never reached it). Values 0 and 1 keep
|
|
45
|
+
// today's expressions. On the device the branch is compiled only with -DD16_RIGID2 (engine14's X14_RIGID2=1), so production
|
|
46
|
+
// builds carry no new code; the host refuses a case with rigid = 2 on a build without it (engine14.init_model).
|
|
47
|
+
#if !defined(__CUDA_ARCH__) || defined(D16_RIGID2)
|
|
48
|
+
#define D16_RIGID2_ON 1
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
namespace js::soft {
|
|
52
|
+
|
|
53
|
+
// Loops over a muscle's sites (j < NS) and row slots (k < KD) run to the compile-time bound with a guard (j < n), so that
|
|
54
|
+
// on the GPU every index into p[], g[] and r[] is a constant after unrolling and the arrays live in registers, not in
|
|
55
|
+
// local memory (ITEM4_FIX1_PREREG.md). The same operations run in the same order as a runtime-bounded loop.
|
|
56
|
+
#if defined(__CUDA_ARCH__)
|
|
57
|
+
#define JS_MUS_UNROLL _Pragma("unroll")
|
|
58
|
+
#else
|
|
59
|
+
#define JS_MUS_UNROLL
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
// r[slot] = r[slot] + a * b and r[slot] = r[slot] + v at a runtime slot, written as a select over the compile-time slots
|
|
63
|
+
template <int KD, class S> DN_HOST_DEVICE void row_axpy(S* r, int slot, S a, S b) {
|
|
64
|
+
JS_MUS_UNROLL
|
|
65
|
+
for (int k = 0; k < KD; ++k)
|
|
66
|
+
if (k == slot) r[k] = r[k] + a * b;
|
|
67
|
+
}
|
|
68
|
+
template <int KD, class S> DN_HOST_DEVICE void row_add(S* r, int slot, S v) {
|
|
69
|
+
JS_MUS_UNROLL
|
|
70
|
+
for (int k = 0; k < KD; ++k)
|
|
71
|
+
if (k == slot) r[k] = r[k] + v;
|
|
72
|
+
}
|
|
73
|
+
template <int KD, class S> DN_HOST_DEVICE S row_get(const S* r, int slot) {
|
|
74
|
+
S v = r[0];
|
|
75
|
+
JS_MUS_UNROLL
|
|
76
|
+
for (int k = 1; k < KD; ++k)
|
|
77
|
+
if (k == slot) v = r[k];
|
|
78
|
+
return v;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
82
|
+
// The Geyer 2010 curves and MuJoCo's activation dynamics, copied operation for operation from core/mtu/curves.h and
|
|
83
|
+
// core/mtu/activation.h (P1a gates the copies bitwise against those originals). Two changes, value-neutral for double:
|
|
84
|
+
// the math calls are unqualified (so a forward-mode Dual finds its overloads by ADL; curves.h calls so3::js_exp
|
|
85
|
+
// qualified, which a Dual cannot use), and `x <= y` is written `y >= x` (the Dual type defines >= on two Duals, not <=).
|
|
86
|
+
namespace gmath {
|
|
87
|
+
using so3::js_exp;
|
|
88
|
+
|
|
89
|
+
// R3 (ITEM4_ENTRY_ARMS_PREREG.md, adopted 19:4x after G3 passed on both models): on the device in f32 the fibre's variable
|
|
90
|
+
// divisions, 1 / |d| and the force-length exp use the fast intrinsics (-DF_MUS_EXACT turns them off); on the host and in
|
|
91
|
+
// f64 they are the plain expressions, so the CPU references and the f64 gate build are unchanged.
|
|
92
|
+
template <class S> DN_HOST_DEVICE inline S fdiv(S a, S b) { return a / b; }
|
|
93
|
+
template <class S> DN_HOST_DEVICE inline S fexp(S x) { return js_exp(x); }
|
|
94
|
+
#if defined(__CUDA_ARCH__) && !defined(F_MUS_EXACT)
|
|
95
|
+
__device__ inline float fdiv(float a, float b) { return __fdividef(a, b); }
|
|
96
|
+
__device__ inline float fexp(float x) { return __expf(x); }
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
template <class S> DN_HOST_DEVICE S f_lce0(S l0, S C, S W, S* dval = nullptr) {
|
|
100
|
+
S u = (l0 - S(1)) / W;
|
|
101
|
+
S au = u < S(0) ? -u : u;
|
|
102
|
+
S v = js_exp(C * au * au * au);
|
|
103
|
+
if (dval) *dval = v * (S(3) * C) * (u * au) / W;
|
|
104
|
+
return v;
|
|
105
|
+
}
|
|
106
|
+
template <class S> DN_HOST_DEVICE S f_p0(S x, S e, S* dval = nullptr) {
|
|
107
|
+
if (x > S(1)) {
|
|
108
|
+
S t = (x - S(1)) / e;
|
|
109
|
+
if (dval) *dval = S(2) * t / e;
|
|
110
|
+
return t * t;
|
|
111
|
+
}
|
|
112
|
+
if (dval) *dval = S(0);
|
|
113
|
+
return S(0);
|
|
114
|
+
}
|
|
115
|
+
template <class S> DN_HOST_DEVICE S f_pe0(S x, S rest, S e, S* dval = nullptr) {
|
|
116
|
+
if (x > rest) {
|
|
117
|
+
S t = (x - rest) / e;
|
|
118
|
+
if (dval) *dval = S(2) * t / e;
|
|
119
|
+
return t * t;
|
|
120
|
+
}
|
|
121
|
+
if (dval) *dval = S(0);
|
|
122
|
+
return S(0);
|
|
123
|
+
}
|
|
124
|
+
template <class S> DN_HOST_DEVICE S f_p0_ext(S x, S e, S e2, S* dval = nullptr) {
|
|
125
|
+
if (x < e2) {
|
|
126
|
+
S t = (x - e2) / e;
|
|
127
|
+
if (dval) *dval = S(2) * t / e;
|
|
128
|
+
return t * t;
|
|
129
|
+
}
|
|
130
|
+
if (dval) *dval = S(0);
|
|
131
|
+
return S(0);
|
|
132
|
+
}
|
|
133
|
+
template <class S> DN_HOST_DEVICE S f_vce0(S v0, S K, S N, S* dval = nullptr) {
|
|
134
|
+
if (S(0) >= v0) {
|
|
135
|
+
S den = S(1) - K * v0;
|
|
136
|
+
if (dval) *dval = fdiv(S(1) + K, den * den);
|
|
137
|
+
return fdiv(S(1) + v0, den);
|
|
138
|
+
}
|
|
139
|
+
const S c = S(1) - S(7.56) * K;
|
|
140
|
+
const S b = c * v0 - S(2);
|
|
141
|
+
if (dval) *dval = fdiv(S(2) - c, b * b);
|
|
142
|
+
return N - fdiv(v0 - S(1), b);
|
|
143
|
+
}
|
|
144
|
+
// The same curves with the constant denominator's reciprocal passed in (ie = 1 / e): a / e becomes a * ie (fix 2).
|
|
145
|
+
template <class S> DN_HOST_DEVICE S f_lce0_i(S l0, S C, S iW, S* dval = nullptr) {
|
|
146
|
+
S u = (l0 - S(1)) * iW;
|
|
147
|
+
S au = u < S(0) ? -u : u;
|
|
148
|
+
S v = fexp(C * au * au * au);
|
|
149
|
+
if (dval) *dval = v * (S(3) * C) * (u * au) * iW;
|
|
150
|
+
return v;
|
|
151
|
+
}
|
|
152
|
+
template <class S> DN_HOST_DEVICE S f_p0_i(S x, S ie, S* dval = nullptr) {
|
|
153
|
+
if (x > S(1)) {
|
|
154
|
+
S t = (x - S(1)) * ie;
|
|
155
|
+
if (dval) *dval = S(2) * t * ie;
|
|
156
|
+
return t * t;
|
|
157
|
+
}
|
|
158
|
+
if (dval) *dval = S(0);
|
|
159
|
+
return S(0);
|
|
160
|
+
}
|
|
161
|
+
template <class S> DN_HOST_DEVICE S f_pe0_i(S x, S rest, S ie, S* dval = nullptr) {
|
|
162
|
+
if (x > rest) {
|
|
163
|
+
S t = (x - rest) * ie;
|
|
164
|
+
if (dval) *dval = S(2) * t * ie;
|
|
165
|
+
return t * t;
|
|
166
|
+
}
|
|
167
|
+
if (dval) *dval = S(0);
|
|
168
|
+
return S(0);
|
|
169
|
+
}
|
|
170
|
+
template <class S> DN_HOST_DEVICE S f_p0_ext_i(S x, S ie, S e2, S* dval = nullptr) {
|
|
171
|
+
if (x < e2) {
|
|
172
|
+
S t = (x - e2) * ie;
|
|
173
|
+
if (dval) *dval = S(2) * t * ie;
|
|
174
|
+
return t * t;
|
|
175
|
+
}
|
|
176
|
+
if (dval) *dval = S(0);
|
|
177
|
+
return S(0);
|
|
178
|
+
}
|
|
179
|
+
template <class S> DN_HOST_DEVICE S act_clip01(S x) {
|
|
180
|
+
return x < S(0) ? S(0) : (x > S(1) ? S(1) : x);
|
|
181
|
+
}
|
|
182
|
+
template <class S> DN_HOST_DEVICE S act_sigmoid(S x) {
|
|
183
|
+
if (S(0) >= x) return S(0);
|
|
184
|
+
if (x >= S(1)) return S(1);
|
|
185
|
+
return x * x * x * (S(3) * x * (S(2) * x - S(5)) + S(10));
|
|
186
|
+
}
|
|
187
|
+
template <class S> DN_HOST_DEVICE S muscle_dynamics(S u, S a, S tau_act, S tau_deact, S tausmooth) {
|
|
188
|
+
S uc = act_clip01(u), ac = act_clip01(a);
|
|
189
|
+
S ta = tau_act * (S(0.5) + S(1.5) * ac);
|
|
190
|
+
S td = tau_deact / (S(0.5) + S(1.5) * ac);
|
|
191
|
+
S dctrl = uc - a;
|
|
192
|
+
S tau = (tausmooth < S(1e-12)) ? (dctrl > S(0) ? ta : td)
|
|
193
|
+
: td + (ta - td) * act_sigmoid(dctrl / tausmooth + S(0.5));
|
|
194
|
+
return dctrl / (tau > S(1e-12) ? tau : S(1e-12));
|
|
195
|
+
}
|
|
196
|
+
template <class S> DN_HOST_DEVICE S activation_step(S u, S a_prev, S dt, S tau_act, S tau_deact, S tausmooth) {
|
|
197
|
+
return act_clip01(a_prev + dt * muscle_dynamics(u, a_prev, tau_act, tau_deact, tausmooth));
|
|
198
|
+
}
|
|
199
|
+
// activation_step's VJP, from core/mtu/activation.h activation_step_vjp operation for operation, with ONE deliberate change:
|
|
200
|
+
// the clip gates are CLOSED intervals, u in [0, 1] (and a_prev, a_pre), the branch the forward's act_clip01 takes at an exact
|
|
201
|
+
// boundary (x < 0 ? 0 : (x > 1 ? 1 : x) is the identity at 0 and 1). Today's adjoint uses open intervals, so at an exact
|
|
202
|
+
// boundary it drops a derivative its own forward has (item 3's T2 found it on the constructed u = 0 / 1 states). Equal to
|
|
203
|
+
// today's everywhere else. ACCUMULATES into u_bar and a_prev_bar.
|
|
204
|
+
template <class S> DN_HOST_DEVICE S act_sigmoid_d(S x) {
|
|
205
|
+
return (x > S(0) && x < S(1)) ? S(30) * x * x * (x - S(1)) * (x - S(1)) : S(0);
|
|
206
|
+
}
|
|
207
|
+
template <class S>
|
|
208
|
+
DN_HOST_DEVICE void activation_step_vjp(S u, S a_prev, S dt, S tau_act, S tau_deact, S tausmooth, S a_new_bar,
|
|
209
|
+
S& u_bar, S& a_prev_bar) {
|
|
210
|
+
S uc = act_clip01(u), cu = (u >= S(0) && S(1) >= u) ? S(1) : S(0);
|
|
211
|
+
S ac = act_clip01(a_prev), ca = (a_prev >= S(0) && S(1) >= a_prev) ? S(1) : S(0);
|
|
212
|
+
S denom = S(0.5) + S(1.5) * ac;
|
|
213
|
+
S ta = tau_act * denom, dta_da = tau_act * S(1.5) * ca;
|
|
214
|
+
S td = tau_deact / denom, dtd_da = -tau_deact * S(1.5) * ca / (denom * denom);
|
|
215
|
+
S dctrl = uc - a_prev;
|
|
216
|
+
S tau, dtau_du, dtau_da;
|
|
217
|
+
if (tausmooth < S(1e-12)) {
|
|
218
|
+
bool activating = dctrl > S(0);
|
|
219
|
+
tau = activating ? ta : td;
|
|
220
|
+
dtau_du = S(0);
|
|
221
|
+
dtau_da = activating ? dta_da : dtd_da;
|
|
222
|
+
} else {
|
|
223
|
+
S z = dctrl / tausmooth + S(0.5);
|
|
224
|
+
S sig = act_sigmoid(z), sigp = act_sigmoid_d(z);
|
|
225
|
+
tau = td + (ta - td) * sig;
|
|
226
|
+
dtau_du = (ta - td) * sigp * (cu / tausmooth);
|
|
227
|
+
dtau_da = dtd_da + (dta_da - dtd_da) * sig - (ta - td) * sigp / tausmooth;
|
|
228
|
+
}
|
|
229
|
+
S taum = tau > S(1e-12) ? tau : S(1e-12);
|
|
230
|
+
S g = dctrl / taum;
|
|
231
|
+
S dg_du = cu / taum - dctrl / (taum * taum) * dtau_du;
|
|
232
|
+
S dg_da = S(-1) / taum - dctrl / (taum * taum) * dtau_da;
|
|
233
|
+
S a_pre = a_prev + dt * g;
|
|
234
|
+
S c = (a_pre >= S(0) && S(1) >= a_pre) ? S(1) : S(0);
|
|
235
|
+
u_bar = u_bar + a_new_bar * c * dt * dg_du;
|
|
236
|
+
a_prev_bar = a_prev_bar + a_new_bar * c * (S(1) + dt * dg_da);
|
|
237
|
+
}
|
|
238
|
+
} // namespace gmath
|
|
239
|
+
|
|
240
|
+
// hook-2 field ids of the muscle stage (the ModelField, core/soft/gpu/model_view.cuh); the view is ModelView<Policy>
|
|
241
|
+
using gpu::kFieldMuscleFmax; using gpu::kFieldMuscleLopt; using gpu::kFieldMuscleLslack; using gpu::kFieldMuscleVmax;
|
|
242
|
+
using gpu::kFieldMuscleCurve; using gpu::kFieldMuscleAct; using gpu::kFieldMuscleSite;
|
|
243
|
+
|
|
244
|
+
enum MuscleJointType : int { kMJFixed = 0, kMJHinge = 1, kMJSlide = 2, kMJBall = 3, kMJFree = 4 };
|
|
245
|
+
|
|
246
|
+
// The generated model tables (structure + values). P is the value type (double for the reference, float for f32).
|
|
247
|
+
template <class P> struct MuscleTables {
|
|
248
|
+
int nm = 0, nsite = 0, nbody = 0, nv = 0, nq = 0;
|
|
249
|
+
// per muscle [nm]: Geyer 2010 parameters (MtuParams' fields; pe_rest / pe_eps already resolved from pe_own)
|
|
250
|
+
const P *fmax, *lopt, *lslack, *vmax, *W, *C, *N, *K, *eref, *pe_rest, *pe_eps, *beta;
|
|
251
|
+
const P *tau_act, *tau_deact, *tausmooth;
|
|
252
|
+
const int* rigid; // 1: rigid-tendon routing (mtu_rigid: the source's flag or l_slack < 0.05 l_opt)
|
|
253
|
+
const int* site_off; // [nm + 1]
|
|
254
|
+
const int* row_off; // [nm + 1] into row_dof: the muscle's dof list D_m, ascending
|
|
255
|
+
const int* row_dof;
|
|
256
|
+
const int* jent_off; // [nm + 1] into the joint entries, ascending body index
|
|
257
|
+
const int* jent_body; // the joint's body
|
|
258
|
+
const int* jent_mask; // bit j: the muscle's site j moves with this joint
|
|
259
|
+
const int* jent_slot; // the row slot of the joint's first dof (a ball's three are consecutive)
|
|
260
|
+
// per site [nsite]
|
|
261
|
+
const int* site_body;
|
|
262
|
+
const P* site_off3; // [3 nsite] fixed offset in the body frame
|
|
263
|
+
const int* site_moving;
|
|
264
|
+
const int* site_cdof_q; // moving: theta = q[cdof_q]
|
|
265
|
+
const int* site_slot; // moving: the row slot of its cdof; -1 for a fixed site
|
|
266
|
+
const P* site_coef; // [15 nsite] moving: off(theta) = sum_k coef[k] theta^k, coef[k][axis] at 3 k + axis
|
|
267
|
+
// per body [nbody]
|
|
268
|
+
const int* body_jtype; // MuscleJointType
|
|
269
|
+
const P* body_jaxis; // [3 nbody] hinge / slide axis in the body frame
|
|
270
|
+
const int* body_cpl_qadr; // coupled joint: the master's q index; -1 uncoupled
|
|
271
|
+
const P* body_cpl_coef; // [5 nbody] theta = sum_k c_k q_master^k
|
|
272
|
+
#ifdef JS_MUS_MILLARD
|
|
273
|
+
// Millard 2013 (law == kLawMillard; section 4m). The model's curve sets (core/io/dnmodel.h bake_millard_block: the "millard"
|
|
274
|
+
// block and each "millard_sets" entry) are baked tables, four curves per set in the loader's order (kMCurve*); a muscle reads
|
|
275
|
+
// the set mset[m]. The Geyer fields above stay present and unread (fmax, lopt, lslack, vmax, beta, the activation's and
|
|
276
|
+
// rigid are shared by both laws).
|
|
277
|
+
int law = 0, nmset = 0; // MuscleLaw; the number of curve sets
|
|
278
|
+
const int* mset = nullptr; // [nm] the muscle's curve set
|
|
279
|
+
const P* pen_h = nullptr; // [nm] fixed-width pennation height l_opt sin(alpha_opt) (0: unpennated)
|
|
280
|
+
const P* lce_min = nullptr; // [nm] Eq. 7's fibre lower bound
|
|
281
|
+
const P* pfl_a = nullptr; // [nm] the passive curve's per-muscle affine abscissa map u = a l0 + b
|
|
282
|
+
const P* pfl_b = nullptr;
|
|
283
|
+
int ncurve = 0; // the curves: 4 per set (index 4 k + c), then the muscles' own passive curves
|
|
284
|
+
const int* pfl_curve = nullptr; // [nm] the curve the muscle's passive force reads: its set's (4 k + kMCurvePFL) or its own
|
|
285
|
+
// (the review, 11-05: exact per-muscle tables where the loader's affine map is not the identity)
|
|
286
|
+
const int* mc_i = nullptr; // [2 ncurve]: curve i starts at knot mc_i[2 i] and has mc_i[2 i + 1] knots
|
|
287
|
+
const P* mc_f = nullptr; // [8 ncurve]: x0, x1, dx, inv_dx, a_y0, a_d0, a_y1, a_d1 (core/mtu/curve_table.h's view)
|
|
288
|
+
const P* mc_knot = nullptr; // [3 knots]: per knot y, dy/dx, d2y/dx2 (interleaved, so a cell's two knots are 6 consecutive values)
|
|
289
|
+
const P* mc_sinmax = nullptr; // [nmset] sin(phi_max) of the set's maximum_pennation_angle
|
|
290
|
+
#endif
|
|
291
|
+
};
|
|
292
|
+
#ifdef JS_MUS_MILLARD
|
|
293
|
+
enum MuscleLaw : int { kLawGeyer = 0, kLawMillard = 1 };
|
|
294
|
+
#endif
|
|
295
|
+
|
|
296
|
+
template <class S> struct GeyerPar {
|
|
297
|
+
S fmax, lopt, lslack, vmax, W, C, N, K, eref, pe_rest, pe_eps, beta;
|
|
298
|
+
int rigid;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
template <class S, class P, class MV>
|
|
302
|
+
DN_HOST_DEVICE GeyerPar<S> muscle_par(const MuscleTables<P>& t, const MV& mv, int m) {
|
|
303
|
+
GeyerPar<S> p;
|
|
304
|
+
p.fmax = S(mv.at(kFieldMuscleFmax, t.fmax + m));
|
|
305
|
+
p.lopt = S(mv.at(kFieldMuscleLopt, t.lopt + m));
|
|
306
|
+
p.lslack = S(mv.at(kFieldMuscleLslack, t.lslack + m));
|
|
307
|
+
p.vmax = S(mv.at(kFieldMuscleVmax, t.vmax + m));
|
|
308
|
+
p.W = S(mv.at(kFieldMuscleCurve, t.W + m));
|
|
309
|
+
p.C = S(mv.at(kFieldMuscleCurve, t.C + m));
|
|
310
|
+
p.N = S(mv.at(kFieldMuscleCurve, t.N + m));
|
|
311
|
+
p.K = S(mv.at(kFieldMuscleCurve, t.K + m));
|
|
312
|
+
p.eref = S(mv.at(kFieldMuscleCurve, t.eref + m));
|
|
313
|
+
p.pe_rest = S(mv.at(kFieldMuscleCurve, t.pe_rest + m));
|
|
314
|
+
p.pe_eps = S(mv.at(kFieldMuscleCurve, t.pe_eps + m));
|
|
315
|
+
p.beta = S(mv.at(kFieldMuscleCurve, t.beta + m));
|
|
316
|
+
p.rigid = t.rigid[m];
|
|
317
|
+
return p;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
321
|
+
// 1. activation (the same function as today's mtu_activation_step_kernel)
|
|
322
|
+
template <class S, class P, class MV>
|
|
323
|
+
DN_HOST_DEVICE S muscle_activation(const MuscleTables<P>& t, const MV& mv, int m, S u, S a_prev, S dt) {
|
|
324
|
+
return gmath::activation_step<S>(u, a_prev, dt, S(mv.at(kFieldMuscleAct, t.tau_act + m)),
|
|
325
|
+
S(mv.at(kFieldMuscleAct, t.tau_deact + m)),
|
|
326
|
+
S(mv.at(kFieldMuscleAct, t.tausmooth + m)));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
330
|
+
// 2. the path: site world positions p[0..n) and l_MTU. The same operations as pvia_world / poly_lmtu.
|
|
331
|
+
template <class S, class P, class MV>
|
|
332
|
+
DN_HOST_DEVICE so3::Vec3<S> muscle_site_world(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose,
|
|
333
|
+
const S* q, int s) {
|
|
334
|
+
so3::Vec3<S> o;
|
|
335
|
+
if (t.site_moving[s]) {
|
|
336
|
+
const P* c = t.site_coef + 15 * s;
|
|
337
|
+
S th = q[t.site_cdof_q[s]];
|
|
338
|
+
S cx = S(mv.at(kFieldMuscleSite, c + 12)), cy = S(mv.at(kFieldMuscleSite, c + 13)),
|
|
339
|
+
cz = S(mv.at(kFieldMuscleSite, c + 14));
|
|
340
|
+
for (int k = 3; k >= 0; --k) {
|
|
341
|
+
cx = cx * th + S(mv.at(kFieldMuscleSite, c + 3 * k));
|
|
342
|
+
cy = cy * th + S(mv.at(kFieldMuscleSite, c + 3 * k + 1));
|
|
343
|
+
cz = cz * th + S(mv.at(kFieldMuscleSite, c + 3 * k + 2));
|
|
344
|
+
}
|
|
345
|
+
o = {cx, cy, cz};
|
|
346
|
+
} else {
|
|
347
|
+
const P* f = t.site_off3 + 3 * s;
|
|
348
|
+
o = {S(mv.at(kFieldMuscleSite, f)), S(mv.at(kFieldMuscleSite, f + 1)), S(mv.at(kFieldMuscleSite, f + 2))};
|
|
349
|
+
}
|
|
350
|
+
const kin::Pose<S>& pb = pose[t.site_body[s]];
|
|
351
|
+
return so3::add(pb.p, so3::quat_rotate(pb.q, o));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
template <int NS, class S, class P, class MV>
|
|
355
|
+
DN_HOST_DEVICE S muscle_path(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q, int m,
|
|
356
|
+
so3::Vec3<S>* p, int& n) {
|
|
357
|
+
const int s0 = t.site_off[m];
|
|
358
|
+
n = t.site_off[m + 1] - s0;
|
|
359
|
+
assert(n >= 2 && n <= NS);
|
|
360
|
+
p[0] = muscle_site_world<S>(t, mv, pose, q, s0);
|
|
361
|
+
S L = S(0);
|
|
362
|
+
JS_MUS_UNROLL
|
|
363
|
+
for (int j = 1; j < NS; ++j) {
|
|
364
|
+
if (j < n) {
|
|
365
|
+
p[j] = muscle_site_world<S>(t, mv, pose, q, s0 + j);
|
|
366
|
+
L = L + so3::norm(so3::sub(p[j], p[j - 1]));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return L;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// g_j = dl/dp_j for the polyline p[0..n)
|
|
373
|
+
template <int NS, class S>
|
|
374
|
+
DN_HOST_DEVICE void muscle_path_grad(const so3::Vec3<S>* p, int n, so3::Vec3<S>* g) {
|
|
375
|
+
JS_MUS_UNROLL
|
|
376
|
+
for (int j = 0; j < NS; ++j)
|
|
377
|
+
if (j < n) g[j] = so3::Vec3<S>{S(0), S(0), S(0)};
|
|
378
|
+
JS_MUS_UNROLL
|
|
379
|
+
for (int s = 0; s < NS - 1; ++s) {
|
|
380
|
+
if (s < n - 1) {
|
|
381
|
+
so3::Vec3<S> d = so3::sub(p[s + 1], p[s]);
|
|
382
|
+
so3::Vec3<S> u = so3::scale(d, gmath::fdiv(S(1), so3::norm(d)));
|
|
383
|
+
g[s] = so3::sub(g[s], u);
|
|
384
|
+
g[s + 1] = so3::add(g[s + 1], u);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
390
|
+
// 3. the moment-arm row r[0..nd) on the muscle's dofs row_dof[row_off[m] ..]. Slot order: joint entries in ascending
|
|
391
|
+
// body order, then moving sites in site order.
|
|
392
|
+
template <int NS, int KD, class S, class P, class MV>
|
|
393
|
+
DN_HOST_DEVICE int muscle_row(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q, int m,
|
|
394
|
+
const so3::Vec3<S>* p, const so3::Vec3<S>* g, int n, S* r) {
|
|
395
|
+
using V = so3::Vec3<S>;
|
|
396
|
+
const int nd = t.row_off[m + 1] - t.row_off[m];
|
|
397
|
+
assert(nd <= KD);
|
|
398
|
+
JS_MUS_UNROLL
|
|
399
|
+
for (int k = 0; k < KD; ++k)
|
|
400
|
+
if (k < nd) r[k] = S(0);
|
|
401
|
+
for (int e = t.jent_off[m]; e < t.jent_off[m + 1]; ++e) {
|
|
402
|
+
const int b = t.jent_body[e], mask = t.jent_mask[e], slot = t.jent_slot[e];
|
|
403
|
+
const kin::Pose<S>& pb = pose[b];
|
|
404
|
+
const int jt = t.body_jtype[b];
|
|
405
|
+
S scale = S(1);
|
|
406
|
+
if (t.body_cpl_qadr[b] >= 0) { // coupled: theta = poly(q_master), d theta / d q_master
|
|
407
|
+
const P* c = t.body_cpl_coef + 5 * b;
|
|
408
|
+
const S qm = q[t.body_cpl_qadr[b]];
|
|
409
|
+
scale = S(c[1]) + qm * (S(2) * S(c[2]) + qm * (S(3) * S(c[3]) + qm * S(4) * S(c[4])));
|
|
410
|
+
}
|
|
411
|
+
if (jt == kMJSlide) {
|
|
412
|
+
V f{S(0), S(0), S(0)};
|
|
413
|
+
JS_MUS_UNROLL
|
|
414
|
+
for (int j = 0; j < NS; ++j)
|
|
415
|
+
if (j < n && ((mask >> j) & 1)) f = so3::add(f, g[j]);
|
|
416
|
+
const P* ax = t.body_jaxis + 3 * b;
|
|
417
|
+
const V a = so3::quat_rotate(pb.q, V{S(ax[0]), S(ax[1]), S(ax[2])});
|
|
418
|
+
row_axpy<KD>(r, slot, scale, so3::dot(a, f));
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
V mom{S(0), S(0), S(0)};
|
|
422
|
+
JS_MUS_UNROLL
|
|
423
|
+
for (int j = 0; j < NS; ++j)
|
|
424
|
+
if (j < n && ((mask >> j) & 1)) mom = so3::add(mom, so3::cross(so3::sub(p[j], pb.p), g[j]));
|
|
425
|
+
if (jt == kMJHinge) {
|
|
426
|
+
const P* ax = t.body_jaxis + 3 * b;
|
|
427
|
+
const V a = so3::quat_rotate(pb.q, V{S(ax[0]), S(ax[1]), S(ax[2])});
|
|
428
|
+
row_axpy<KD>(r, slot, scale, so3::dot(a, mom));
|
|
429
|
+
} else {
|
|
430
|
+
assert(jt == kMJBall); // the free root is always a common joint, never an entry
|
|
431
|
+
const V ml = so3::quat_rotate(so3::quat_conj(pb.q), mom);
|
|
432
|
+
row_add<KD>(r, slot, ml.x);
|
|
433
|
+
row_add<KD>(r, slot + 1, ml.y);
|
|
434
|
+
row_add<KD>(r, slot + 2, ml.z);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const int s0 = t.site_off[m];
|
|
438
|
+
JS_MUS_UNROLL
|
|
439
|
+
for (int j = 0; j < NS; ++j) {
|
|
440
|
+
if (j >= n) continue;
|
|
441
|
+
const int s = s0 + j;
|
|
442
|
+
if (!t.site_moving[s]) continue;
|
|
443
|
+
const P* c = t.site_coef + 15 * s;
|
|
444
|
+
const S th = q[t.site_cdof_q[s]];
|
|
445
|
+
S dx = S(4) * S(mv.at(kFieldMuscleSite, c + 12)), dy = S(4) * S(mv.at(kFieldMuscleSite, c + 13)),
|
|
446
|
+
dz = S(4) * S(mv.at(kFieldMuscleSite, c + 14));
|
|
447
|
+
for (int k = 3; k >= 1; --k) {
|
|
448
|
+
dx = dx * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k));
|
|
449
|
+
dy = dy * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k + 1));
|
|
450
|
+
dz = dz * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k + 2));
|
|
451
|
+
}
|
|
452
|
+
const V slide = so3::quat_rotate(pose[t.site_body[s]].q, V{dx, dy, dz});
|
|
453
|
+
row_add<KD>(r, t.site_slot[s], so3::dot(g[j], slide));
|
|
454
|
+
}
|
|
455
|
+
return nd;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// muscle_row with one cross product per joint entry (fix 4, ITEM4_FIX4_PREREG.md): an entry's moment
|
|
459
|
+
// sum_{j in M} (p_j - c) x g_j is formed as P(M) - c x G(M), with P(M) = sum_{j in M} p_j x g_j and G(M) = sum_{j in M} g_j.
|
|
460
|
+
// P and G are formed once per run of equal masks along the entry order (p_j x g_j inside the sum: no per-site array,
|
|
461
|
+
// which cost residency in fix 4; fix 4b). The same math as
|
|
462
|
+
// muscle_row with different rounding (the P1 path keeps muscle_row); the slide branch's sum G(M) is muscle_row's, bitwise.
|
|
463
|
+
template <int NS, int KD, class S, class P, class MV>
|
|
464
|
+
DN_HOST_DEVICE int muscle_row_ms(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q, int m,
|
|
465
|
+
const so3::Vec3<S>* p, const so3::Vec3<S>* g, int n, S* r) {
|
|
466
|
+
using V = so3::Vec3<S>;
|
|
467
|
+
const int nd = t.row_off[m + 1] - t.row_off[m];
|
|
468
|
+
assert(nd <= KD);
|
|
469
|
+
JS_MUS_UNROLL
|
|
470
|
+
for (int k = 0; k < KD; ++k)
|
|
471
|
+
if (k < nd) r[k] = S(0);
|
|
472
|
+
int last = -1;
|
|
473
|
+
V Pm{S(0), S(0), S(0)}, Gm{S(0), S(0), S(0)};
|
|
474
|
+
for (int e = t.jent_off[m]; e < t.jent_off[m + 1]; ++e) {
|
|
475
|
+
const int b = t.jent_body[e], mask = t.jent_mask[e], slot = t.jent_slot[e];
|
|
476
|
+
if (mask != last) {
|
|
477
|
+
Pm = V{S(0), S(0), S(0)}; Gm = V{S(0), S(0), S(0)};
|
|
478
|
+
JS_MUS_UNROLL
|
|
479
|
+
for (int j = 0; j < NS; ++j)
|
|
480
|
+
if (j < n && ((mask >> j) & 1)) { Pm = so3::add(Pm, so3::cross(p[j], g[j])); Gm = so3::add(Gm, g[j]); }
|
|
481
|
+
last = mask;
|
|
482
|
+
}
|
|
483
|
+
const kin::Pose<S>& pb = pose[b];
|
|
484
|
+
const int jt = t.body_jtype[b];
|
|
485
|
+
S scale = S(1);
|
|
486
|
+
if (t.body_cpl_qadr[b] >= 0) { // coupled: theta = poly(q_master), d theta / d q_master
|
|
487
|
+
const P* c = t.body_cpl_coef + 5 * b;
|
|
488
|
+
const S qm = q[t.body_cpl_qadr[b]];
|
|
489
|
+
scale = S(c[1]) + qm * (S(2) * S(c[2]) + qm * (S(3) * S(c[3]) + qm * S(4) * S(c[4])));
|
|
490
|
+
}
|
|
491
|
+
if (jt == kMJSlide) {
|
|
492
|
+
const P* ax = t.body_jaxis + 3 * b;
|
|
493
|
+
const V a = so3::quat_rotate(pb.q, V{S(ax[0]), S(ax[1]), S(ax[2])});
|
|
494
|
+
row_axpy<KD>(r, slot, scale, so3::dot(a, Gm));
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
const V mom = so3::sub(Pm, so3::cross(pb.p, Gm));
|
|
498
|
+
if (jt == kMJHinge) {
|
|
499
|
+
const P* ax = t.body_jaxis + 3 * b;
|
|
500
|
+
const V a = so3::quat_rotate(pb.q, V{S(ax[0]), S(ax[1]), S(ax[2])});
|
|
501
|
+
row_axpy<KD>(r, slot, scale, so3::dot(a, mom));
|
|
502
|
+
} else {
|
|
503
|
+
assert(jt == kMJBall);
|
|
504
|
+
const V ml = so3::quat_rotate(so3::quat_conj(pb.q), mom);
|
|
505
|
+
row_add<KD>(r, slot, ml.x);
|
|
506
|
+
row_add<KD>(r, slot + 1, ml.y);
|
|
507
|
+
row_add<KD>(r, slot + 2, ml.z);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const int s0 = t.site_off[m];
|
|
511
|
+
JS_MUS_UNROLL
|
|
512
|
+
for (int j = 0; j < NS; ++j) {
|
|
513
|
+
if (j >= n) continue;
|
|
514
|
+
const int s = s0 + j;
|
|
515
|
+
if (!t.site_moving[s]) continue;
|
|
516
|
+
const P* c = t.site_coef + 15 * s;
|
|
517
|
+
const S th = q[t.site_cdof_q[s]];
|
|
518
|
+
S dx = S(4) * S(mv.at(kFieldMuscleSite, c + 12)), dy = S(4) * S(mv.at(kFieldMuscleSite, c + 13)),
|
|
519
|
+
dz = S(4) * S(mv.at(kFieldMuscleSite, c + 14));
|
|
520
|
+
for (int k = 3; k >= 1; --k) {
|
|
521
|
+
dx = dx * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k));
|
|
522
|
+
dy = dy * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k + 1));
|
|
523
|
+
dz = dz * th + S(k) * S(mv.at(kFieldMuscleSite, c + 3 * k + 2));
|
|
524
|
+
}
|
|
525
|
+
const V slide = so3::quat_rotate(pose[t.site_body[s]].q, V{dx, dy, dz});
|
|
526
|
+
row_add<KD>(r, t.site_slot[s], so3::dot(g[j], slide));
|
|
527
|
+
}
|
|
528
|
+
return nd;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
532
|
+
// 4. the fibre. geyer_residual is mtu_residual's Song branch operation for operation (core/mtu/solve.h), so the
|
|
533
|
+
// niter-40 solve below is bitwise today's mtu_solve<double> on a Geyer 2010 muscle.
|
|
534
|
+
// f_v multiplies the parallel elastic force as in the primary source: Geyer & Herr 2010 (IEEE TNSRE 18(3)), Appendix II, p. 8:
|
|
535
|
+
// "Fm = Fse = Fce + Fpe - Fbe", "Fpe = Fmax((lce - lopt)/(lopt eps_pe))^2 fv(vce) with the PE reference strain eps_pe = w", which "allows
|
|
536
|
+
// to rewrite fv(vce) = (Fse + Fbe)/(A Fmax fl(lce) + F*pe)" (checked 2026-11-10 against the paper's PDF). The beta * v0 fibre damping term
|
|
537
|
+
// is this law's addition (the muscle's beta_damp), not the paper's.
|
|
538
|
+
template <class S>
|
|
539
|
+
DN_HOST_DEVICE S geyer_residual(S l_ce, S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, S* dR) {
|
|
540
|
+
S l_se0 = (l_mtu - l_ce) / p.lslack;
|
|
541
|
+
S l0 = l_ce / p.lopt;
|
|
542
|
+
S v0 = (l_ce - l_ce_prev) / (dt * (p.vmax * p.lopt));
|
|
543
|
+
S dse, dpe, dbe, dfl, dfv;
|
|
544
|
+
S f_se = gmath::f_p0(l_se0, p.eref, &dse);
|
|
545
|
+
S f_pe = gmath::f_pe0(l0, p.pe_rest, p.pe_eps, &dpe);
|
|
546
|
+
S f_be = gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W, &dbe);
|
|
547
|
+
S f_l = gmath::f_lce0(l0, p.C, p.W, &dfl);
|
|
548
|
+
S f_v = gmath::f_vce0(v0, p.K, p.N, &dfv);
|
|
549
|
+
if (dR) {
|
|
550
|
+
S d_se = dse * (S(-1) / p.lslack) + dbe * (S(1) / p.lopt);
|
|
551
|
+
S d_fib = f_v * (dpe + A * dfl) * (S(1) / p.lopt)
|
|
552
|
+
+ dfv * (S(1) / (dt * (p.vmax * p.lopt))) * (f_pe + A * f_l)
|
|
553
|
+
+ p.beta * (S(1) / (dt * (p.vmax * p.lopt)));
|
|
554
|
+
*dR = d_se - d_fib;
|
|
555
|
+
}
|
|
556
|
+
return (f_se + f_be) - (f_v * (f_pe + A * f_l) + p.beta * v0);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// mtu_solve's Song rigid-tendon closed form: l_ce = l_mtu - l_slack, nothing to solve (and, as today, no beta term).
|
|
560
|
+
// rigid = 2 (D16_RIGID2_ON): the same with ea5f010f's fix, f + beta v0 and F floored at 0, in its order.
|
|
561
|
+
template <class S>
|
|
562
|
+
DN_HOST_DEVICE S geyer_rigid(S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, S* F) {
|
|
563
|
+
S l_ce = l_mtu - p.lslack;
|
|
564
|
+
S l0 = l_ce / p.lopt, v0 = (l_ce - l_ce_prev) / (dt * (p.vmax * p.lopt));
|
|
565
|
+
S f = gmath::f_vce0(v0, p.K, p.N) * (gmath::f_pe0(l0, p.pe_rest, p.pe_eps) + A * gmath::f_lce0(l0, p.C, p.W))
|
|
566
|
+
- gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W);
|
|
567
|
+
#ifdef D16_RIGID2_ON
|
|
568
|
+
if (p.rigid == 2) {
|
|
569
|
+
f = f + p.beta * v0;
|
|
570
|
+
const S F2 = p.fmax * f;
|
|
571
|
+
*F = F2 > S(0) ? F2 : S(0);
|
|
572
|
+
return l_ce;
|
|
573
|
+
}
|
|
574
|
+
#endif
|
|
575
|
+
*F = p.fmax * f;
|
|
576
|
+
return l_ce;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// The Newton from the warm start; tol 0 runs niter iterations (today's production), tol > 0 stops at |R| < tol.
|
|
580
|
+
// Returns l_ce; F and the iteration count out.
|
|
581
|
+
template <class S>
|
|
582
|
+
DN_HOST_DEVICE S muscle_fiber(S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, int niter, S tol, S* F,
|
|
583
|
+
int* iters = nullptr) {
|
|
584
|
+
if (p.rigid) {
|
|
585
|
+
if (iters) *iters = 0;
|
|
586
|
+
return geyer_rigid<S>(l_mtu, l_ce_prev, A, dt, p, F);
|
|
587
|
+
}
|
|
588
|
+
S l_ce = l_ce_prev, dR = S(1);
|
|
589
|
+
int it = 0;
|
|
590
|
+
for (; it < niter; ++it) {
|
|
591
|
+
S R = geyer_residual(l_ce, l_mtu, l_ce_prev, A, dt, p, &dR);
|
|
592
|
+
if (R == S(0)) break;
|
|
593
|
+
if (tol > S(0) && R < tol && R > -tol) break;
|
|
594
|
+
l_ce = l_ce - R / dR;
|
|
595
|
+
}
|
|
596
|
+
if (iters) *iters = it;
|
|
597
|
+
*F = p.fmax * gmath::f_p0((l_mtu - l_ce) / p.lslack, p.eref);
|
|
598
|
+
return l_ce;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// The fibre's tangent by the IFT at a converged primal root lce (a plain scalar): the derivative the adjoint computes.
|
|
602
|
+
// SD is a forward-mode Dual; the branches are the primal's (the Dual compares its value).
|
|
603
|
+
template <class SD, class S>
|
|
604
|
+
DN_HOST_DEVICE SD muscle_fiber_ift(S lce, SD l_mtu, SD l_ce_prev, SD A, S dt, const GeyerPar<SD>& p, SD* F) {
|
|
605
|
+
if (p.rigid) return geyer_rigid<SD>(l_mtu, l_ce_prev, A, SD(dt), p, F);
|
|
606
|
+
SD dR;
|
|
607
|
+
SD R = geyer_residual<SD>(SD(lce), l_mtu, l_ce_prev, A, SD(dt), p, &dR);
|
|
608
|
+
SD l_ce = SD(lce);
|
|
609
|
+
for (int i = 0; i < int(sizeof(l_ce.d) / sizeof(l_ce.d[0])); ++i) l_ce.d[i] = -R.d[i] / dR.v;
|
|
610
|
+
*F = p.fmax * gmath::f_p0((l_mtu - l_ce) / p.lslack, p.eref);
|
|
611
|
+
return l_ce;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// The f32 path: Newton in the normalized velocity x = (l_ce - l_ce_prev) / (dt v_max l_opt) (mtu_residual_x's Song
|
|
615
|
+
// branch, fiber_reparam), which keeps the update resolvable in f32.
|
|
616
|
+
template <class S>
|
|
617
|
+
DN_HOST_DEVICE S geyer_residual_x(S x, S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, S* dR_dx) {
|
|
618
|
+
S dtv = dt * (p.vmax * p.lopt);
|
|
619
|
+
S l_ce = l_ce_prev + x * dtv;
|
|
620
|
+
S l_se0 = (l_mtu - l_ce) / p.lslack;
|
|
621
|
+
S l0 = l_ce / p.lopt;
|
|
622
|
+
S dse, dpe, dbe, dfl, dfv;
|
|
623
|
+
S f_se = gmath::f_p0(l_se0, p.eref, &dse);
|
|
624
|
+
S f_pe = gmath::f_pe0(l0, p.pe_rest, p.pe_eps, &dpe);
|
|
625
|
+
S f_be = gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W, &dbe);
|
|
626
|
+
S f_l = gmath::f_lce0(l0, p.C, p.W, &dfl);
|
|
627
|
+
S f_v = gmath::f_vce0(x, p.K, p.N, &dfv);
|
|
628
|
+
if (dR_dx) {
|
|
629
|
+
S d_se = dse * (-dtv / p.lslack) + dbe * (dtv / p.lopt);
|
|
630
|
+
S d_fib = f_v * (dpe + A * dfl) * (dtv / p.lopt) + dfv * (f_pe + A * f_l) + p.beta;
|
|
631
|
+
*dR_dx = d_se - d_fib;
|
|
632
|
+
}
|
|
633
|
+
return (f_se + f_be) - (f_v * (f_pe + A * f_l) + p.beta * x);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
template <class S>
|
|
637
|
+
DN_HOST_DEVICE S muscle_fiber_x(S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, int niter, S tol, S* F,
|
|
638
|
+
int* iters = nullptr) {
|
|
639
|
+
if (p.rigid) return muscle_fiber<S>(l_mtu, l_ce_prev, A, dt, p, 0, S(0), F, iters);
|
|
640
|
+
S dtv = dt * (p.vmax * p.lopt);
|
|
641
|
+
S x = S(0), dR_dx = S(1);
|
|
642
|
+
int it = 0;
|
|
643
|
+
for (; it < niter; ++it) {
|
|
644
|
+
S R = geyer_residual_x(x, l_mtu, l_ce_prev, A, dt, p, &dR_dx);
|
|
645
|
+
if (R == S(0)) break;
|
|
646
|
+
if (tol > S(0) && R < tol && R > -tol) break;
|
|
647
|
+
x = x - R / dR_dx;
|
|
648
|
+
}
|
|
649
|
+
if (iters) *iters = it;
|
|
650
|
+
S l_ce = l_ce_prev + x * dtv;
|
|
651
|
+
*F = p.fmax * gmath::f_p0((l_mtu - l_ce) / p.lslack, p.eref);
|
|
652
|
+
return l_ce;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
#ifdef JS_MUS_MILLARD
|
|
656
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
657
|
+
// 4m. The Millard 2013 fibre (Millard, Uchida, Seth, Delp 2013, J Biomech Eng 135:021005), backward Euler in l_ce:
|
|
658
|
+
// R(l_ce) = f_T(l_T / l_s) - cos(phi) [A f_L(l0) f_V(v0) + f_PE(a_m l0 + b_m) + beta v0], F = F_max f_T(l_T / l_s)
|
|
659
|
+
// with fixed-width pennation (sin(phi) = h / l_ce, clamped at sin(phi_max)) and l_T = l_mtu - l_ce cos(phi): core/mtu/solve.h's
|
|
660
|
+
// millard_eval, mtu_solve and mtu_solve_vjp, operation for operation, so a niter-N solve here is bitwise mtu_solve<double>'s
|
|
661
|
+
// on the same muscle (gate 2). The curves are the loader's baked quintic-Hermite tables (core/mtu/curve_table.h's evaluator,
|
|
662
|
+
// the same arithmetic on the tables' interleaved layout). S is the arithmetic type (T, or a forward-mode Dual for the IFT);
|
|
663
|
+
// P the tables'.
|
|
664
|
+
enum MCurve : int { kMCurveAFL = 0, kMCurvePFL = 1, kMCurveTFL = 2, kMCurveFV = 3 }; // dnmodel.h's push order
|
|
665
|
+
|
|
666
|
+
// the primal value of a scalar or a Dual (whose .v is the value)
|
|
667
|
+
DN_HOST_DEVICE inline double mus_prim(double x) { return x; }
|
|
668
|
+
DN_HOST_DEVICE inline float mus_prim(float x) { return x; }
|
|
669
|
+
template <class S> DN_HOST_DEVICE auto mus_prim(const S& x) -> decltype(mus_prim(x.v)) { return mus_prim(x.v); }
|
|
670
|
+
|
|
671
|
+
// a model-level table value (shared by every world): read-only cached on the device
|
|
672
|
+
template <class P> DN_HOST_DEVICE inline P mus_ldg(const P* p) {
|
|
673
|
+
#if defined(__CUDA_ARCH__)
|
|
674
|
+
return __ldg(p);
|
|
675
|
+
#else
|
|
676
|
+
return *p;
|
|
677
|
+
#endif
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
template <class S> struct MillardPar {
|
|
681
|
+
S fmax, lopt, lslack, vmax, beta, pen_h, lce_min, pfl_a, pfl_b, sinmax;
|
|
682
|
+
int rigid, set, pfl; // pfl: the passive curve's index (MuscleTables::pfl_curve)
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
template <class S, class P, class MV>
|
|
686
|
+
DN_HOST_DEVICE MillardPar<S> millard_par(const MuscleTables<P>& t, const MV& mv, int m) {
|
|
687
|
+
MillardPar<S> p;
|
|
688
|
+
p.fmax = S(mv.at(kFieldMuscleFmax, t.fmax + m));
|
|
689
|
+
p.lopt = S(mv.at(kFieldMuscleLopt, t.lopt + m));
|
|
690
|
+
p.lslack = S(mv.at(kFieldMuscleLslack, t.lslack + m));
|
|
691
|
+
p.vmax = S(mv.at(kFieldMuscleVmax, t.vmax + m));
|
|
692
|
+
p.beta = S(mv.at(kFieldMuscleCurve, t.beta + m));
|
|
693
|
+
p.pen_h = S(mv.at(kFieldMuscleCurve, t.pen_h + m));
|
|
694
|
+
p.lce_min = S(mv.at(kFieldMuscleCurve, t.lce_min + m));
|
|
695
|
+
p.pfl_a = S(mv.at(kFieldMuscleCurve, t.pfl_a + m));
|
|
696
|
+
p.pfl_b = S(mv.at(kFieldMuscleCurve, t.pfl_b + m));
|
|
697
|
+
p.rigid = t.rigid[m];
|
|
698
|
+
p.set = t.mset[m];
|
|
699
|
+
p.pfl = t.pfl_curve[m];
|
|
700
|
+
p.sinmax = S(mus_ldg(t.mc_sinmax + p.set));
|
|
701
|
+
return p;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// curve ci at x: value and slope (curve_table_eval's arithmetic, operation for operation; either output may be null)
|
|
705
|
+
template <class S, class P>
|
|
706
|
+
DN_HOST_DEVICE void millard_curve_i(const MuscleTables<P>& t, int ci, S x, S* y, S* dydx) {
|
|
707
|
+
const P* f = t.mc_f + 8 * ci;
|
|
708
|
+
const P x0 = mus_ldg(f), x1 = mus_ldg(f + 1);
|
|
709
|
+
if (mus_prim(x) <= x0) { // linear extrapolation, exact (the branches compare the primal)
|
|
710
|
+
const S a_y0 = S(mus_ldg(f + 4)), a_d0 = S(mus_ldg(f + 5));
|
|
711
|
+
if (y) *y = a_y0 + a_d0 * (x - S(x0));
|
|
712
|
+
if (dydx) *dydx = a_d0;
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (mus_prim(x) >= x1) {
|
|
716
|
+
const S a_y1 = S(mus_ldg(f + 6)), a_d1 = S(mus_ldg(f + 7));
|
|
717
|
+
if (y) *y = a_y1 + a_d1 * (x - S(x1));
|
|
718
|
+
if (dydx) *dydx = a_d1;
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
const int k0 = mus_ldg(t.mc_i + 2 * ci), n = mus_ldg(t.mc_i + 2 * ci + 1);
|
|
722
|
+
const S inv_dx = S(mus_ldg(f + 3));
|
|
723
|
+
const S s = (x - S(x0)) * inv_dx;
|
|
724
|
+
int i = static_cast<int>(mus_prim(s)); // floor for s >= 0, which holds here
|
|
725
|
+
if (i < 0) i = 0;
|
|
726
|
+
if (i > n - 2) i = n - 2;
|
|
727
|
+
const S u = s - S(static_cast<P>(i));
|
|
728
|
+
const S u2 = u * u, u3 = u2 * u, u4 = u3 * u, u5 = u4 * u;
|
|
729
|
+
const S h = S(mus_ldg(f + 2));
|
|
730
|
+
const P* kn = t.mc_knot + 3 * (k0 + i);
|
|
731
|
+
const S y_i = S(mus_ldg(kn)), y_j = S(mus_ldg(kn + 3));
|
|
732
|
+
const S d_i = S(mus_ldg(kn + 1)), d_j = S(mus_ldg(kn + 4));
|
|
733
|
+
const S e_i = S(mus_ldg(kn + 2)), e_j = S(mus_ldg(kn + 5));
|
|
734
|
+
if (y) {
|
|
735
|
+
const S H0 = S(1) - S(10) * u3 + S(15) * u4 - S(6) * u5;
|
|
736
|
+
const S H1 = u - S(6) * u3 + S(8) * u4 - S(3) * u5;
|
|
737
|
+
const S H2 = S(0.5) * u2 - S(1.5) * u3 + S(1.5) * u4 - S(0.5) * u5;
|
|
738
|
+
const S G0 = S(10) * u3 - S(15) * u4 + S(6) * u5;
|
|
739
|
+
const S G1 = -S(4) * u3 + S(7) * u4 - S(3) * u5;
|
|
740
|
+
const S G2 = S(0.5) * u3 - u4 + S(0.5) * u5;
|
|
741
|
+
*y = H0 * y_i + H1 * h * d_i + H2 * h * h * e_i + G0 * y_j + G1 * h * d_j + G2 * h * h * e_j;
|
|
742
|
+
}
|
|
743
|
+
if (dydx) {
|
|
744
|
+
const S P0 = -S(30) * u2 + S(60) * u3 - S(30) * u4;
|
|
745
|
+
const S P1 = S(1) - S(18) * u2 + S(32) * u3 - S(15) * u4;
|
|
746
|
+
const S P2 = u - S(4.5) * u2 + S(6) * u3 - S(2.5) * u4;
|
|
747
|
+
const S Q0 = S(30) * u2 - S(60) * u3 + S(30) * u4;
|
|
748
|
+
const S Q1 = -S(12) * u2 + S(28) * u3 - S(15) * u4;
|
|
749
|
+
const S Q2 = S(1.5) * u2 - S(4) * u3 + S(2.5) * u4;
|
|
750
|
+
*dydx = (P0 * y_i + Q0 * y_j) * inv_dx + P1 * d_i + Q1 * d_j + (P2 * e_i + Q2 * e_j) * h;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
// curve c of set k
|
|
754
|
+
template <class S, class P>
|
|
755
|
+
DN_HOST_DEVICE void millard_curve(const MuscleTables<P>& t, int k, int c, S x, S* y, S* dydx) {
|
|
756
|
+
millard_curve_i<S>(t, 4 * k + c, x, y, dydx);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// solve.h's MillardEval: the residual, its dR/dl_ce and the partials the IFT reads, at one l_ce
|
|
760
|
+
template <class S> struct MillardEvalM {
|
|
761
|
+
S cos_phi, sin_phi, dphi; // pennation and dphi/dl_ce
|
|
762
|
+
S l_T, dlT, dcos; // tendon length, dl_T/dl_ce, dcos(phi)/dl_ce
|
|
763
|
+
S l0, v0, dtv; // normalized fibre length, normalized velocity, dt v_max l_opt
|
|
764
|
+
S f_se, d_se; // tendon curve: value and slope in l_T / l_s
|
|
765
|
+
S f_l, d_l, f_pe, d_pe; // active and passive F-L: value and slope in l0
|
|
766
|
+
S f_v, d_v; // F-V: value and slope in v0
|
|
767
|
+
S fib; // A f_L f_V + f_PE + beta v0
|
|
768
|
+
S R, dR; // residual and dR/dl_ce
|
|
769
|
+
S sn; // dR/dl_mtu = d_se / l_s
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// pennation at l_ce (solve.h millard_eval's block): cos, sin and dphi/dl_ce
|
|
773
|
+
template <class S>
|
|
774
|
+
DN_HOST_DEVICE void millard_pennation(S l_ce, const MillardPar<S>& p, S& cos_phi, S& sin_phi, S& dphi) {
|
|
775
|
+
using so3::js_sqrt;
|
|
776
|
+
cos_phi = S(1); sin_phi = S(0); dphi = S(0);
|
|
777
|
+
if (p.pen_h > S(0)) {
|
|
778
|
+
S sp = p.pen_h / l_ce;
|
|
779
|
+
if (sp > p.sinmax) {
|
|
780
|
+
sp = p.sinmax; // phi_max clamp; dphi stays 0 while it is active
|
|
781
|
+
} else {
|
|
782
|
+
const S r = S(1) - sp * sp;
|
|
783
|
+
dphi = -(sp / l_ce) / (r > S(0) ? js_sqrt(r) : S(1));
|
|
784
|
+
}
|
|
785
|
+
sin_phi = sp;
|
|
786
|
+
cos_phi = js_sqrt(S(1) - sp * sp);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
template <class S, class P>
|
|
791
|
+
DN_HOST_DEVICE MillardEvalM<S> millard_eval(const MuscleTables<P>& t, S l_ce, S l_mtu, S l_ce_prev, S A, S dt,
|
|
792
|
+
const MillardPar<S>& p) {
|
|
793
|
+
MillardEvalM<S> e;
|
|
794
|
+
e.l0 = l_ce / p.lopt;
|
|
795
|
+
e.dtv = dt * (p.vmax * p.lopt);
|
|
796
|
+
e.v0 = (l_ce - l_ce_prev) / e.dtv;
|
|
797
|
+
millard_pennation<S>(l_ce, p, e.cos_phi, e.sin_phi, e.dphi);
|
|
798
|
+
e.l_T = l_mtu - l_ce * e.cos_phi;
|
|
799
|
+
e.dlT = l_ce * e.sin_phi * e.dphi - e.cos_phi;
|
|
800
|
+
e.dcos = -e.sin_phi * e.dphi;
|
|
801
|
+
millard_curve<S>(t, p.set, kMCurveTFL, e.l_T / p.lslack, &e.f_se, &e.d_se);
|
|
802
|
+
millard_curve<S>(t, p.set, kMCurveAFL, e.l0, &e.f_l, &e.d_l);
|
|
803
|
+
millard_curve_i<S>(t, p.pfl, p.pfl_a * e.l0 + p.pfl_b, &e.f_pe, &e.d_pe); // the muscle's passive curve (own: a = 1, b = 0)
|
|
804
|
+
e.d_pe = e.d_pe * p.pfl_a;
|
|
805
|
+
millard_curve<S>(t, p.set, kMCurveFV, e.v0, &e.f_v, &e.d_v);
|
|
806
|
+
e.fib = A * e.f_l * e.f_v + e.f_pe + p.beta * e.v0;
|
|
807
|
+
const S d_fib = A * (e.d_l * e.f_v / p.lopt + e.f_l * e.d_v / e.dtv) + e.d_pe / p.lopt + p.beta / e.dtv;
|
|
808
|
+
e.sn = e.d_se / p.lslack;
|
|
809
|
+
e.R = e.f_se - e.cos_phi * e.fib;
|
|
810
|
+
e.dR = e.d_se * (e.dlT / p.lslack) - (e.dcos * e.fib + e.cos_phi * d_fib);
|
|
811
|
+
return e;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// the tendon force at (l_mtu, l_ce): F_max f_T(l_T / l_s), millard_eval's pennation and tendon lookup only (the same
|
|
815
|
+
// operations, so the same value as millard_eval's f_se; solve.h millard_force)
|
|
816
|
+
template <class S, class P>
|
|
817
|
+
DN_HOST_DEVICE S millard_tendon_force(const MuscleTables<P>& t, S l_mtu, S l_ce, const MillardPar<S>& p) {
|
|
818
|
+
S c, s, d;
|
|
819
|
+
millard_pennation<S>(l_ce, p, c, s, d);
|
|
820
|
+
S f;
|
|
821
|
+
millard_curve<S>(t, p.set, kMCurveTFL, (l_mtu - l_ce * c) / p.lslack, &f, static_cast<S*>(nullptr));
|
|
822
|
+
return p.fmax * f;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// the rigid tendon (Eqs. 9-15; mtu_solve's Millard rigid branch): l_ce = hypot(l_mtu - l_s, h), clamped at lce_min where the
|
|
826
|
+
// tendon carries no force; F = F_max (A f_L f_V + f_PE + beta v0) cos(phi), floored at 0. Nothing is solved.
|
|
827
|
+
template <class S, class P>
|
|
828
|
+
DN_HOST_DEVICE S millard_rigid(const MuscleTables<P>& t, S l_mtu, S l_ce_prev, S A, S dt, const MillardPar<S>& p, S* F) {
|
|
829
|
+
using so3::js_sqrt;
|
|
830
|
+
const S lt = l_mtu - p.lslack;
|
|
831
|
+
S l_ce = p.pen_h > S(0) ? js_sqrt(lt * lt + p.pen_h * p.pen_h) : lt;
|
|
832
|
+
bool clamped = false;
|
|
833
|
+
if (!(l_ce > p.lce_min)) { l_ce = p.lce_min; clamped = true; }
|
|
834
|
+
S sp = p.pen_h > S(0) ? p.pen_h / l_ce : S(0);
|
|
835
|
+
if (sp > p.sinmax) sp = p.sinmax;
|
|
836
|
+
const S cos_phi = js_sqrt(S(1) - sp * sp);
|
|
837
|
+
const MillardEvalM<S> e = millard_eval<S>(t, l_ce, l_mtu, l_ce_prev, A, dt, p);
|
|
838
|
+
const S fib = A * e.f_l * e.f_v + e.f_pe + p.beta * e.v0;
|
|
839
|
+
const S Fr = clamped ? S(0) : p.fmax * fib * cos_phi;
|
|
840
|
+
*F = Fr > S(0) ? Fr : S(0);
|
|
841
|
+
return l_ce;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// The Newton from the warm start, every iterate projected onto [lce_min, inf) (OpenSim's estimateMuscleFiberState; a fibre
|
|
845
|
+
// pushed below the bound from the bound stays on it). tol 0 runs niter iterations; tol > 0 stops at |R| < tol.
|
|
846
|
+
template <class S, class P>
|
|
847
|
+
DN_HOST_DEVICE S millard_fiber(const MuscleTables<P>& t, S l_mtu, S l_ce_prev, S A, S dt, const MillardPar<S>& p, int niter,
|
|
848
|
+
S tol, S* F, int* iters = nullptr) {
|
|
849
|
+
if (p.rigid) {
|
|
850
|
+
if (iters) *iters = 0;
|
|
851
|
+
return millard_rigid<S>(t, l_mtu, l_ce_prev, A, dt, p, F);
|
|
852
|
+
}
|
|
853
|
+
S l_ce = l_ce_prev;
|
|
854
|
+
if (l_ce < p.lce_min) l_ce = p.lce_min;
|
|
855
|
+
int it = 0;
|
|
856
|
+
for (; it < niter; ++it) {
|
|
857
|
+
const MillardEvalM<S> e = millard_eval<S>(t, l_ce, l_mtu, l_ce_prev, A, dt, p);
|
|
858
|
+
if (e.R == S(0)) break;
|
|
859
|
+
if (tol > S(0) && e.R < tol && e.R > -tol) break;
|
|
860
|
+
S next = l_ce - e.R / e.dR;
|
|
861
|
+
if (next < p.lce_min) {
|
|
862
|
+
if (l_ce == p.lce_min) break; // on the bound and still pushed below it: the fibre is AT its bound
|
|
863
|
+
next = p.lce_min;
|
|
864
|
+
}
|
|
865
|
+
l_ce = next;
|
|
866
|
+
}
|
|
867
|
+
if (iters) *iters = it;
|
|
868
|
+
*F = millard_tendon_force<S>(t, l_mtu, l_ce, p);
|
|
869
|
+
return l_ce;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// F from (l_mtu, l_ce): the adjoint's recompute of the forward's force (rigid: the closed form)
|
|
873
|
+
template <class S, class P>
|
|
874
|
+
DN_HOST_DEVICE S millard_force(const MuscleTables<P>& t, S l_mtu, S l_ce, S l_ce_prev, S A, S dt, const MillardPar<S>& p) {
|
|
875
|
+
if (p.rigid) { S F; (void)millard_rigid<S>(t, l_mtu, l_ce_prev, A, dt, p, &F); return F; }
|
|
876
|
+
return millard_tendon_force<S>(t, l_mtu, l_ce, p);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// The fibre's VJP at the stored root lce (mtu_solve_vjp's Millard branches). Compliant: mu = (lce_bar + F_bar dF/dl_ce) / R_lce,
|
|
880
|
+
// l_bar = F_bar sP - mu R_l, lp_bar = -mu R_lp, A_bar = -mu R_A; at the lower bound (l_ce = lce_min with R < 0) l_ce is a
|
|
881
|
+
// constant and only the tendon sees l. Rigid: the closed form's chain rule; a clamped fibre and a floored force carry no
|
|
882
|
+
// force path. ACCUMULATES into l_bar, lp_bar and A_bar.
|
|
883
|
+
template <class S, class P>
|
|
884
|
+
DN_HOST_DEVICE void millard_fiber_vjp(const MuscleTables<P>& t, S lce, S l, S lp, S A, S dt, const MillardPar<S>& p, S F_bar,
|
|
885
|
+
S lce_bar, S& l_bar, S& lp_bar, S& A_bar) {
|
|
886
|
+
const MillardEvalM<S> e = millard_eval<S>(t, lce, l, lp, A, dt, p);
|
|
887
|
+
if (p.rigid) {
|
|
888
|
+
if (!(lce > p.lce_min)) return;
|
|
889
|
+
const S lt = l - p.lslack;
|
|
890
|
+
const S dlce = p.pen_h > S(0) ? lt / lce : S(1); // dl_ce/dl_mtu of the closed form
|
|
891
|
+
l_bar = l_bar + lce_bar * dlce; // the fibre-state path
|
|
892
|
+
if (!(p.fmax * e.fib * e.cos_phi > S(0))) return; // the tendon floor: no force, no force path
|
|
893
|
+
const S d_fib = A * (e.d_l * e.f_v / p.lopt + e.f_l * e.d_v / e.dtv) + e.d_pe / p.lopt + p.beta / e.dtv;
|
|
894
|
+
const S dF_dlce = p.fmax * (d_fib * e.cos_phi + e.fib * e.dcos);
|
|
895
|
+
l_bar = l_bar + F_bar * dF_dlce * dlce;
|
|
896
|
+
A_bar = A_bar + F_bar * p.fmax * e.f_l * e.f_v * e.cos_phi;
|
|
897
|
+
lp_bar = lp_bar + -F_bar * p.fmax * e.cos_phi * (A * e.f_l * e.d_v + p.beta) / e.dtv;
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const S sP = p.fmax * e.sn; // dF/dl_mtu (direct, l_ce fixed)
|
|
901
|
+
if (!(lce > p.lce_min) && e.R < S(0)) { // the fibre AT its lower bound
|
|
902
|
+
l_bar = l_bar + F_bar * sP;
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const S lce_adj = lce_bar + F_bar * sP * e.dlT; // the state path + the force-through-l_ce path
|
|
906
|
+
if (e.dR == S(0)) { // flat / singular root: the direct term only
|
|
907
|
+
l_bar = l_bar + F_bar * sP;
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
const S mu = lce_adj / e.dR;
|
|
911
|
+
l_bar = l_bar + (F_bar * sP - mu * e.sn);
|
|
912
|
+
A_bar = A_bar + mu * e.cos_phi * e.f_l * e.f_v;
|
|
913
|
+
lp_bar = lp_bar + -mu * e.cos_phi * (A * e.f_l * e.d_v + p.beta) / e.dtv;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// The fibre's tangent by the IFT at a converged primal root lce (the derivative millard_fiber_vjp transposes). SD is a
|
|
917
|
+
// forward-mode Dual; the branches are the primal's. At the bound, and at an exact dR = 0, l_ce is a constant.
|
|
918
|
+
template <class SD, class S, class P>
|
|
919
|
+
DN_HOST_DEVICE SD millard_fiber_ift(const MuscleTables<P>& t, S lce, SD l_mtu, SD l_ce_prev, SD A, S dt,
|
|
920
|
+
const MillardPar<SD>& p, SD* F) {
|
|
921
|
+
if (p.rigid) return millard_rigid<SD>(t, l_mtu, l_ce_prev, A, SD(dt), p, F);
|
|
922
|
+
const MillardEvalM<SD> e = millard_eval<SD>(t, SD(lce), l_mtu, l_ce_prev, A, SD(dt), p);
|
|
923
|
+
SD l_ce = SD(lce);
|
|
924
|
+
const bool at_bound = !(lce > mus_prim(p.lce_min)) && mus_prim(e.R) < S(0);
|
|
925
|
+
if (!at_bound && !(mus_prim(e.dR) == S(0)))
|
|
926
|
+
for (int i = 0; i < int(sizeof(l_ce.d) / sizeof(l_ce.d[0])); ++i) l_ce.d[i] = -e.R.d[i] / e.dR.v;
|
|
927
|
+
*F = millard_tendon_force<SD>(t, l_mtu, l_ce, p);
|
|
928
|
+
return l_ce;
|
|
929
|
+
}
|
|
930
|
+
#endif // JS_MUS_MILLARD
|
|
931
|
+
|
|
932
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
933
|
+
// One lane: activation, path, row, fibre. The caller reduces tau and the wrenches in model order.
|
|
934
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
935
|
+
// Fix 2 (ITEM4_FIX2_PREREG.md): the fibre with its per-muscle reciprocals hoisted out of the Newton iteration. The same
|
|
936
|
+
// residual and Newton step, with a / c written a * (1 / c) for every constant c; only the rounding differs from
|
|
937
|
+
// geyer_residual / muscle_fiber, which stay bitwise today's mtu_solve (the P1 parity path).
|
|
938
|
+
template <class S> struct GeyerInv {
|
|
939
|
+
S lslack, lopt, dtvl, eref, pe_eps, hW, W; // 1 / l_slack, 1 / l_opt, 1 / (dt v_max l_opt), 1 / e_ref, 1 / pe_eps, 1 / (W / 2), 1 / W
|
|
940
|
+
};
|
|
941
|
+
template <class S>
|
|
942
|
+
DN_HOST_DEVICE GeyerInv<S> geyer_inv(const GeyerPar<S>& p, S dt) {
|
|
943
|
+
GeyerInv<S> i;
|
|
944
|
+
i.lslack = S(1) / p.lslack; i.lopt = S(1) / p.lopt; i.dtvl = S(1) / (dt * (p.vmax * p.lopt));
|
|
945
|
+
i.eref = S(1) / p.eref; i.pe_eps = S(1) / p.pe_eps; i.hW = S(1) / (S(0.5) * p.W); i.W = S(1) / p.W;
|
|
946
|
+
return i;
|
|
947
|
+
}
|
|
948
|
+
template <class S>
|
|
949
|
+
DN_HOST_DEVICE S geyer_residual_h(S l_ce, S l_mtu, S l_ce_prev, S A, const GeyerPar<S>& p, const GeyerInv<S>& iv, S* dR) {
|
|
950
|
+
S l_se0 = (l_mtu - l_ce) * iv.lslack;
|
|
951
|
+
S l0 = l_ce * iv.lopt;
|
|
952
|
+
S v0 = (l_ce - l_ce_prev) * iv.dtvl;
|
|
953
|
+
S dse, dpe, dbe, dfl, dfv;
|
|
954
|
+
S f_se = gmath::f_p0_i(l_se0, iv.eref, &dse);
|
|
955
|
+
S f_pe = gmath::f_pe0_i(l0, p.pe_rest, iv.pe_eps, &dpe);
|
|
956
|
+
S f_be = gmath::f_p0_ext_i(l0, iv.hW, S(1) - p.W, &dbe);
|
|
957
|
+
S f_l = gmath::f_lce0_i(l0, p.C, iv.W, &dfl);
|
|
958
|
+
S f_v = gmath::f_vce0(v0, p.K, p.N, &dfv);
|
|
959
|
+
if (dR) {
|
|
960
|
+
S d_se = dse * (-iv.lslack) + dbe * iv.lopt;
|
|
961
|
+
S d_fib = f_v * (dpe + A * dfl) * iv.lopt + dfv * iv.dtvl * (f_pe + A * f_l) + p.beta * iv.dtvl;
|
|
962
|
+
*dR = d_se - d_fib;
|
|
963
|
+
}
|
|
964
|
+
return (f_se + f_be) - (f_v * (f_pe + A * f_l) + p.beta * v0);
|
|
965
|
+
}
|
|
966
|
+
// F from (l_mtu, l_ce): the hoisted fibre's closed form (the forward returns it, the adjoint recomputes it)
|
|
967
|
+
template <class S>
|
|
968
|
+
DN_HOST_DEVICE S geyer_force_h(S l_mtu, S l_ce, const GeyerPar<S>& p, const GeyerInv<S>& iv) {
|
|
969
|
+
return p.fmax * gmath::f_p0_i((l_mtu - l_ce) * iv.lslack, iv.eref);
|
|
970
|
+
}
|
|
971
|
+
template <class S>
|
|
972
|
+
DN_HOST_DEVICE S muscle_fiber_h(S l_mtu, S l_ce_prev, S A, S dt, const GeyerPar<S>& p, int niter, S tol, S* F,
|
|
973
|
+
int* iters = nullptr) {
|
|
974
|
+
if (p.rigid) {
|
|
975
|
+
if (iters) *iters = 0;
|
|
976
|
+
return geyer_rigid<S>(l_mtu, l_ce_prev, A, dt, p, F);
|
|
977
|
+
}
|
|
978
|
+
const GeyerInv<S> iv = geyer_inv<S>(p, dt);
|
|
979
|
+
S l_ce = l_ce_prev, dR = S(1);
|
|
980
|
+
int it = 0;
|
|
981
|
+
for (; it < niter; ++it) {
|
|
982
|
+
S R = geyer_residual_h(l_ce, l_mtu, l_ce_prev, A, p, iv, &dR);
|
|
983
|
+
if (R == S(0)) break;
|
|
984
|
+
if (tol > S(0) && R < tol && R > -tol) break;
|
|
985
|
+
l_ce = l_ce - gmath::fdiv(R, dR);
|
|
986
|
+
}
|
|
987
|
+
if (iters) *iters = it;
|
|
988
|
+
*F = geyer_force_h<S>(l_mtu, l_ce, p, iv);
|
|
989
|
+
return l_ce;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
template <class S, int NS, int KD> struct MuscleLaneOut {
|
|
993
|
+
S a, l, lce, F;
|
|
994
|
+
S r[KD];
|
|
995
|
+
int nd, n, iters;
|
|
996
|
+
so3::Vec3<S> p[NS], g[NS];
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
template <int NS, int KD, class S, class P, class MV>
|
|
1000
|
+
DN_HOST_DEVICE void muscle_lane(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q,
|
|
1001
|
+
S dt, int m, S u, S a_prev, S lce_prev, int niter, S tol,
|
|
1002
|
+
MuscleLaneOut<S, NS, KD>& o) {
|
|
1003
|
+
o.a = muscle_activation<S>(t, mv, m, u, a_prev, dt);
|
|
1004
|
+
o.l = muscle_path<NS, S>(t, mv, pose, q, m, o.p, o.n);
|
|
1005
|
+
muscle_path_grad<NS, S>(o.p, o.n, o.g);
|
|
1006
|
+
o.nd = muscle_row<NS, KD, S>(t, mv, pose, q, m, o.p, o.g, o.n, o.r);
|
|
1007
|
+
#ifdef JS_MUS_MILLARD
|
|
1008
|
+
if (t.law == kLawMillard) { // the CPU references' dispatch (section 4m)
|
|
1009
|
+
o.lce = millard_fiber<S>(t, o.l, lce_prev, o.a, dt, millard_par<S>(t, mv, m), niter, tol, &o.F, &o.iters);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
#endif
|
|
1013
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1014
|
+
o.lce = muscle_fiber<S>(o.l, lce_prev, o.a, dt, gp, niter, tol, &o.F, &o.iters);
|
|
1015
|
+
}
|
|
1016
|
+
// the same lane with the hoisted fibre (fix 2: the GPU kernels' form)
|
|
1017
|
+
template <int NS, int KD, class S, class P, class MV>
|
|
1018
|
+
DN_HOST_DEVICE void muscle_lane_h(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q,
|
|
1019
|
+
S dt, int m, S u, S a_prev, S lce_prev, int niter, S tol,
|
|
1020
|
+
MuscleLaneOut<S, NS, KD>& o) {
|
|
1021
|
+
o.a = muscle_activation<S>(t, mv, m, u, a_prev, dt);
|
|
1022
|
+
o.l = muscle_path<NS, S>(t, mv, pose, q, m, o.p, o.n);
|
|
1023
|
+
muscle_path_grad<NS, S>(o.p, o.n, o.g);
|
|
1024
|
+
o.nd = muscle_row<NS, KD, S>(t, mv, pose, q, m, o.p, o.g, o.n, o.r);
|
|
1025
|
+
#ifdef JS_MUS_MILLARD
|
|
1026
|
+
if (t.law == kLawMillard) { // the CPU references' dispatch (section 4m)
|
|
1027
|
+
o.lce = millard_fiber<S>(t, o.l, lce_prev, o.a, dt, millard_par<S>(t, mv, m), niter, tol, &o.F, &o.iters);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
#endif
|
|
1031
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1032
|
+
o.lce = muscle_fiber_h<S>(o.l, lce_prev, o.a, dt, gp, niter, tol, &o.F, &o.iters);
|
|
1033
|
+
}
|
|
1034
|
+
// the GPU kernels' lane (fixes 2 and 4): the hoisted fibre and muscle_row_ms
|
|
1035
|
+
template <int NS, int KD, class S, class P, class MV>
|
|
1036
|
+
DN_HOST_DEVICE void muscle_lane_p(const MuscleTables<P>& t, const MV& mv, const kin::Pose<S>* pose, const S* q,
|
|
1037
|
+
S dt, int m, S u, S a_prev, S lce_prev, int niter, S tol,
|
|
1038
|
+
MuscleLaneOut<S, NS, KD>& o) {
|
|
1039
|
+
o.a = muscle_activation<S>(t, mv, m, u, a_prev, dt);
|
|
1040
|
+
o.l = muscle_path<NS, S>(t, mv, pose, q, m, o.p, o.n);
|
|
1041
|
+
muscle_path_grad<NS, S>(o.p, o.n, o.g);
|
|
1042
|
+
o.nd = muscle_row_ms<NS, KD, S>(t, mv, pose, q, m, o.p, o.g, o.n, o.r);
|
|
1043
|
+
#ifdef JS_MUS_MILLARD
|
|
1044
|
+
if (t.law == kLawMillard) { // the CPU references' dispatch (section 4m)
|
|
1045
|
+
o.lce = millard_fiber<S>(t, o.l, lce_prev, o.a, dt, millard_par<S>(t, mv, m), niter, tol, &o.F, &o.iters);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
#endif
|
|
1049
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1050
|
+
o.lce = muscle_fiber_h<S>(o.l, lce_prev, o.a, dt, gp, niter, tol, &o.F, &o.iters);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// tau[dof] -= F r, in the row's slot order (call per muscle in model order)
|
|
1054
|
+
template <class S, class P>
|
|
1055
|
+
DN_HOST_DEVICE void muscle_tau_add(const MuscleTables<P>& t, int m, S F, const S* r, S* tau) {
|
|
1056
|
+
const int r0 = t.row_off[m];
|
|
1057
|
+
for (int k = 0; k < t.row_off[m + 1] - r0; ++k) tau[t.row_dof[r0 + k]] = tau[t.row_dof[r0 + k]] - F * r[k];
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// world wrench about the world origin per body: the site force f_j = -F g_j at p_j (call per muscle in model order)
|
|
1061
|
+
template <class S, class P>
|
|
1062
|
+
DN_HOST_DEVICE void muscle_wrench_add(const MuscleTables<P>& t, int m, S F, const so3::Vec3<S>* p,
|
|
1063
|
+
const so3::Vec3<S>* g, int n, so3::Vec3<S>* Wf, so3::Vec3<S>* Wn) {
|
|
1064
|
+
const int s0 = t.site_off[m];
|
|
1065
|
+
for (int j = 0; j < n; ++j) {
|
|
1066
|
+
const int b = t.site_body[s0 + j];
|
|
1067
|
+
const so3::Vec3<S> f = so3::scale(g[j], -F);
|
|
1068
|
+
Wf[b] = so3::add(Wf[b], f);
|
|
1069
|
+
Wn[b] = so3::add(Wn[b], so3::cross(p[j], f));
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1074
|
+
// The muscle VJP's per-lane pieces (item 3). The geometry's second-order part (J_r tau_bar and the ball term) is in the
|
|
1075
|
+
// caller, which owns the poses.
|
|
1076
|
+
|
|
1077
|
+
template <class S, class P, class MV>
|
|
1078
|
+
DN_HOST_DEVICE void muscle_activation_vjp(const MuscleTables<P>& t, const MV& mv, int m, S u, S a_prev, S dt,
|
|
1079
|
+
S a_new_bar, S& u_bar, S& a_prev_bar) {
|
|
1080
|
+
gmath::activation_step_vjp<S>(u, a_prev, dt, S(mv.at(kFieldMuscleAct, t.tau_act + m)),
|
|
1081
|
+
S(mv.at(kFieldMuscleAct, t.tau_deact + m)), S(mv.at(kFieldMuscleAct, t.tausmooth + m)),
|
|
1082
|
+
a_new_bar, u_bar, a_prev_bar);
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
// The fibre's VJP at the stored root lce (the substep's lce_new). Compliant: R(lce, l, lce_prev, A) = 0 and
|
|
1086
|
+
// F = F_max f_p0((l - lce) / l_slack); s = dF/dl at fixed lce; w = (lce_bar - s F_bar) / R_lce; then
|
|
1087
|
+
// l_bar = s F_bar - w R_l, lce_prev_bar = -w R_lp, A_bar = -w R_A. Rigid: l_ce = l - l_slack and F in closed form.
|
|
1088
|
+
// ACCUMULATES into l_bar, lce_prev_bar and A_bar.
|
|
1089
|
+
template <class S>
|
|
1090
|
+
DN_HOST_DEVICE void muscle_fiber_vjp(S lce, S l, S lp, S A, S dt, const GeyerPar<S>& p, S F_bar, S lce_bar,
|
|
1091
|
+
S& l_bar, S& lp_bar, S& A_bar) {
|
|
1092
|
+
const S idtv = S(1) / (dt * (p.vmax * p.lopt));
|
|
1093
|
+
if (p.rigid) { // F = F_max [f_v(v0) (f_pe(l0) + A f_l(l0)) - f_be(l0)], l0 = lce / l_opt, v0 = (lce - lp) idtv, lce = l - l_slack
|
|
1094
|
+
const S l0 = lce / p.lopt, v0 = (lce - lp) / (dt * (p.vmax * p.lopt)); // the forward's expression: it decides the branch
|
|
1095
|
+
S dpe, dfl, dbe, dfv;
|
|
1096
|
+
const S fpe = gmath::f_pe0(l0, p.pe_rest, p.pe_eps, &dpe), fl = gmath::f_lce0(l0, p.C, p.W, &dfl);
|
|
1097
|
+
#ifdef D16_RIGID2_ON
|
|
1098
|
+
const S fbe = gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W, &dbe);
|
|
1099
|
+
#else
|
|
1100
|
+
(void)gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W, &dbe);
|
|
1101
|
+
#endif
|
|
1102
|
+
const S fv = gmath::f_vce0(v0, p.K, p.N, &dfv);
|
|
1103
|
+
#ifdef D16_RIGID2_ON
|
|
1104
|
+
if (p.rigid == 2) { // ea5f010f's fixed branch: F = F_max [f_v (f_pe + A f_l) - f_be + beta v0], floored at 0
|
|
1105
|
+
const S fib = fv * (fpe + A * fl) - fbe + p.beta * v0; // the forward's expression, in its order: it decides the floor
|
|
1106
|
+
if (!(p.fmax * fib > S(0))) { l_bar = l_bar + lce_bar; return; } // on the floor: only the fibre-state path
|
|
1107
|
+
const S dF_dlce2 = p.fmax * (dfv * idtv * (fpe + A * fl) + fv * (dpe + A * dfl) / p.lopt - dbe / p.lopt + p.beta * idtv);
|
|
1108
|
+
const S dF_dlp2 = -p.fmax * (dfv * idtv * (fpe + A * fl) + p.beta * idtv);
|
|
1109
|
+
l_bar = l_bar + (F_bar * dF_dlce2 + lce_bar);
|
|
1110
|
+
lp_bar = lp_bar + F_bar * dF_dlp2;
|
|
1111
|
+
A_bar = A_bar + F_bar * (p.fmax * fv * fl);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
#endif
|
|
1115
|
+
const S dF_dlce = p.fmax * (dfv * idtv * (fpe + A * fl) + fv * (dpe + A * dfl) / p.lopt - dbe / p.lopt);
|
|
1116
|
+
const S dF_dlp = -p.fmax * dfv * idtv * (fpe + A * fl);
|
|
1117
|
+
const S dF_dA = p.fmax * fv * fl;
|
|
1118
|
+
l_bar = l_bar + (F_bar * dF_dlce + lce_bar); // lce = l - l_slack: d/dl reaches F through lce and lce itself
|
|
1119
|
+
lp_bar = lp_bar + F_bar * dF_dlp;
|
|
1120
|
+
A_bar = A_bar + F_bar * dF_dA;
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
// the branch-deciding values with the forward's exact expressions (geyer_residual), so the adjoint takes its branches
|
|
1124
|
+
const S l_se0 = (l - lce) / p.lslack, l0 = lce / p.lopt, v0 = (lce - lp) / (dt * (p.vmax * p.lopt));
|
|
1125
|
+
S dse, dpe, dbe, dfl, dfv;
|
|
1126
|
+
(void)gmath::f_p0(l_se0, p.eref, &dse);
|
|
1127
|
+
const S fpe = gmath::f_pe0(l0, p.pe_rest, p.pe_eps, &dpe);
|
|
1128
|
+
(void)gmath::f_p0_ext(l0, S(0.5) * p.W, S(1) - p.W, &dbe);
|
|
1129
|
+
const S fl = gmath::f_lce0(l0, p.C, p.W, &dfl);
|
|
1130
|
+
const S fv = gmath::f_vce0(v0, p.K, p.N, &dfv);
|
|
1131
|
+
// R = (f_se + f_be) - (f_v (f_pe + A f_l) + beta v0)
|
|
1132
|
+
const S R_lce = -dse / p.lslack + dbe / p.lopt - (fv * (dpe + A * dfl) / p.lopt + dfv * idtv * (fpe + A * fl) + p.beta * idtv);
|
|
1133
|
+
const S R_l = dse / p.lslack;
|
|
1134
|
+
const S R_lp = (dfv * (fpe + A * fl) + p.beta) * idtv;
|
|
1135
|
+
const S R_A = -fv * fl;
|
|
1136
|
+
const S s = p.fmax * dse / p.lslack; // dF/dl at fixed lce (F = F_max f_p0(l_se0))
|
|
1137
|
+
const S w = (lce_bar - s * F_bar) / R_lce;
|
|
1138
|
+
l_bar = l_bar + (s * F_bar - w * R_l);
|
|
1139
|
+
lp_bar = lp_bar - w * R_lp;
|
|
1140
|
+
A_bar = A_bar - w * R_A;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// muscle_fiber_vjp for the hoisted fibre: the IFT of geyer_residual_h at its root, with the branch-deciding values
|
|
1144
|
+
// computed by the hoisted forward's expressions. The rigid closed form is not hoisted (geyer_rigid is shared).
|
|
1145
|
+
template <class S>
|
|
1146
|
+
DN_HOST_DEVICE void muscle_fiber_vjp_h(S lce, S l, S lp, S A, S dt, const GeyerPar<S>& p, S F_bar, S lce_bar,
|
|
1147
|
+
S& l_bar, S& lp_bar, S& A_bar) {
|
|
1148
|
+
if (p.rigid) { muscle_fiber_vjp<S>(lce, l, lp, A, dt, p, F_bar, lce_bar, l_bar, lp_bar, A_bar); return; }
|
|
1149
|
+
const GeyerInv<S> iv = geyer_inv<S>(p, dt);
|
|
1150
|
+
const S idtv = iv.dtvl;
|
|
1151
|
+
const S l_se0 = (l - lce) * iv.lslack, l0 = lce * iv.lopt, v0 = (lce - lp) * iv.dtvl;
|
|
1152
|
+
S dse, dpe, dbe, dfl, dfv;
|
|
1153
|
+
(void)gmath::f_p0_i(l_se0, iv.eref, &dse);
|
|
1154
|
+
const S fpe = gmath::f_pe0_i(l0, p.pe_rest, iv.pe_eps, &dpe);
|
|
1155
|
+
(void)gmath::f_p0_ext_i(l0, iv.hW, S(1) - p.W, &dbe);
|
|
1156
|
+
const S fl = gmath::f_lce0_i(l0, p.C, iv.W, &dfl);
|
|
1157
|
+
const S fv = gmath::f_vce0(v0, p.K, p.N, &dfv);
|
|
1158
|
+
const S R_lce = -dse * iv.lslack + dbe * iv.lopt - (fv * (dpe + A * dfl) * iv.lopt + dfv * idtv * (fpe + A * fl) + p.beta * idtv);
|
|
1159
|
+
const S R_l = dse * iv.lslack;
|
|
1160
|
+
const S R_lp = (dfv * (fpe + A * fl) + p.beta) * idtv;
|
|
1161
|
+
const S R_A = -fv * fl;
|
|
1162
|
+
const S s = p.fmax * dse * iv.lslack;
|
|
1163
|
+
const S w = gmath::fdiv(lce_bar - s * F_bar, R_lce);
|
|
1164
|
+
l_bar = l_bar + (s * F_bar - w * R_l);
|
|
1165
|
+
lp_bar = lp_bar - w * R_lp;
|
|
1166
|
+
A_bar = A_bar - w * R_A;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
#ifdef JS_MUS_MILLARD
|
|
1170
|
+
// The law dispatch for the CPU references (muscle_ref_gate, mus14_capi): one entry per fibre operation, on t.law. Geyer takes
|
|
1171
|
+
// today's functions (hoist: fix 2's hoisted forms, the GPU kernels'); Millard has one form. The device kernels select the
|
|
1172
|
+
// law at compile time instead (k_mus.cuh), so they carry no runtime branch on it.
|
|
1173
|
+
template <class S, class P, class MV>
|
|
1174
|
+
DN_HOST_DEVICE S mus_fiber(const MuscleTables<P>& t, const MV& mv, int m, S l, S lp, S A, S dt, int niter, S tol, S* F,
|
|
1175
|
+
int* iters, bool hoist) {
|
|
1176
|
+
if (t.law == kLawMillard) return millard_fiber<S>(t, l, lp, A, dt, millard_par<S>(t, mv, m), niter, tol, F, iters);
|
|
1177
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1178
|
+
return hoist ? muscle_fiber_h<S>(l, lp, A, dt, gp, niter, tol, F, iters) : muscle_fiber<S>(l, lp, A, dt, gp, niter, tol, F, iters);
|
|
1179
|
+
}
|
|
1180
|
+
template <class S, class P, class MV>
|
|
1181
|
+
DN_HOST_DEVICE S mus_force(const MuscleTables<P>& t, const MV& mv, int m, S l, S lnew, S lp, S A, S dt, bool hoist) {
|
|
1182
|
+
if (t.law == kLawMillard) return millard_force<S>(t, l, lnew, lp, A, dt, millard_par<S>(t, mv, m));
|
|
1183
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1184
|
+
S F;
|
|
1185
|
+
if (gp.rigid) (void)geyer_rigid<S>(l, lp, A, dt, gp, &F);
|
|
1186
|
+
else if (hoist) F = geyer_force_h<S>(l, lnew, gp, geyer_inv<S>(gp, dt));
|
|
1187
|
+
else F = gp.fmax * gmath::f_p0((l - lnew) / gp.lslack, gp.eref);
|
|
1188
|
+
return F;
|
|
1189
|
+
}
|
|
1190
|
+
template <class S, class P, class MV>
|
|
1191
|
+
DN_HOST_DEVICE void mus_fiber_vjp(const MuscleTables<P>& t, const MV& mv, int m, S lce, S l, S lp, S A, S dt, S F_bar,
|
|
1192
|
+
S lce_bar, S& l_bar, S& lp_bar, S& A_bar, bool hoist) {
|
|
1193
|
+
if (t.law == kLawMillard) {
|
|
1194
|
+
millard_fiber_vjp<S>(t, lce, l, lp, A, dt, millard_par<S>(t, mv, m), F_bar, lce_bar, l_bar, lp_bar, A_bar);
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
const GeyerPar<S> gp = muscle_par<S>(t, mv, m);
|
|
1198
|
+
if (hoist) muscle_fiber_vjp_h<S>(lce, l, lp, A, dt, gp, F_bar, lce_bar, l_bar, lp_bar, A_bar);
|
|
1199
|
+
else muscle_fiber_vjp<S>(lce, l, lp, A, dt, gp, F_bar, lce_bar, l_bar, lp_bar, A_bar);
|
|
1200
|
+
}
|
|
1201
|
+
template <class SD, class S, class P, class MV>
|
|
1202
|
+
DN_HOST_DEVICE SD mus_fiber_ift(const MuscleTables<P>& t, const MV& mv, int m, S lce, SD l, SD lp, SD A, S dt, SD* F) {
|
|
1203
|
+
if (t.law == kLawMillard) return millard_fiber_ift<SD, S>(t, lce, l, lp, A, dt, millard_par<SD>(t, mv, m), F);
|
|
1204
|
+
return muscle_fiber_ift<SD, S>(lce, l, lp, A, dt, muscle_par<SD>(t, mv, m), F);
|
|
1205
|
+
}
|
|
1206
|
+
#endif // JS_MUS_MILLARD
|
|
1207
|
+
|
|
1208
|
+
} // namespace js::soft
|