SAPCoupler#

The SAPCoupler resolves cross-solver contact with the Semi-Analytic Primal (SAP) contact solver used in Drake. It targets accurate rigid-deformable contact, including hydroelastic contact against implicit FEM bodies. Select it by passing gs.options.SAPCouplerOptions to the scene.

Options#

class genesis.options.solvers.SAPCouplerOptions(*, n_sap_iterations: int = 5, n_pcg_iterations: int = 100, n_linesearch_iterations: int = 10, sap_convergence_atol: float = 1e-06, sap_convergence_rtol: float = 1e-05, sap_taud: float = 0.1, sap_beta: float = 1.0, sap_sigma: float = 0.001, pcg_threshold: float = 1e-06, linesearch_ftol: float = 1e-06, linesearch_max_step_size: float = 1.5, hydroelastic_stiffness: float = 100000000.0, point_contact_stiffness: float = 100000000.0, fem_floor_contact_type: Literal['tet', 'vert', 'none'] = 'tet', enable_fem_self_tet_contact: bool = True, rigid_floor_contact_type: Literal['tet', 'vert', 'none'] = 'tet', enable_rigid_fem_contact: bool = True, rigid_rigid_contact_type: Literal['tet', 'vert', 'none'] = 'tet') None[source]#

Options configuring the inter-solver coupling for the Semi-Analytic Primal (SAP) contact solver used in Drake.

Parameters:
  • n_sap_iterations (int, optional) – Number of iterations for the SAP solver. Defaults to 5.

  • n_pcg_iterations (int, optional) – Number of iterations for the Preconditioned Conjugate Gradient solver. Defaults to 100.

  • n_linesearch_iterations (int, optional) – Max number of iterations for the line search solver. Defaults to 10.

  • sap_convergence_atol (float, optional) – Absolute tolerance for SAP convergence. Defaults to 1e-6.

  • sap_convergence_rtol (float, optional) – Relative tolerance for SAP convergence. Defaults to 1e-5.

  • sap_taud (float, optional) – Dissipation time scale for SAP. Defaults to 0.1.

  • sap_beta (float, optional) – Normal regularization parameter for SAP. Defaults to 1.0.

  • sap_sigma (float, optional) – Friction regularization parameter for SAP. Defaults to 1e-3.

  • pcg_threshold (float, optional) – Threshold for the Preconditioned Conjugate Gradient solver. Defaults to 1e-6.

  • linesearch_ftol (float, optional) – Line search sufficient value close to zero for exact linesearch. Defaults to 1e-6.

  • linesearch_max_step_size (float, optional) – Maximum step size for exact linesearch. Defaults to 1.5.

  • hydroelastic_stiffness (float, optional) – Stiffness for hydroelastic contact. Defaults to 1e8.

  • point_contact_stiffness (float, optional) – Stiffness for point contact. Defaults to 1e8.

  • fem_floor_contact_type (str, optional) – Type of contact against the floor. Defaults to “tet”. Can be “tet”, “vert”, or “none”. TET would be the default choice for most cases. VERT would be preferable when the mesh is very coarse, such as a single cube or a tetrahedron.

  • enable_fem_self_tet_contact (bool, optional) – Whether to use tetrahedral based self-contact. Defaults to True.

  • rigid_rigid_type (str, optional) – Type of contact between rigid bodies. Defaults to “tet”. Can be “tet”, “vert”, or “none”.

  • rigid_floor_contact_type (str, optional) – Type of contact against the floor. Defaults to “tet”. Can be “tet”, “vert”, or “none”. Tet would be the default choice for most cases. Vert would be preferable when the mesh is very coarse, such as a single cube or a tetrahedron.

  • enable_rigid_fem_contact (bool, optional) – Whether to enable coupling between rigid and FEM solvers. Defaults to True.

SAPCoupler#

class genesis.engine.couplers.sap_coupler.SAPCoupler(simulator: Simulator, options: SAPCouplerOptions)[source]#

Bases: RBC

This class handles all the coupling between different solvers using the Semi-Analytic Primal (SAP) contact solver used in Drake.

Note

For now all batches have the same constraints, such as joint equality constraints are consistent among all batches. Paper reference: https://arxiv.org/abs/2110.10107 Drake reference: https://drake.mit.edu/release_notes/v1.5.0.html Code reference: RobotLocomotion/drake

build() None[source]#
reset(envs_idx=None)[source]#
rigid_update_volume_verts_pressure_gradient(geoms_state: GeomsState)[source]#
rigid_compute_pressure_gradient_rest()[source]#
preprocess(i_step)[source]#
precompute(i_step)[source]#
update_contact(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, links_info: ~genesis.utils.array_class.LinksInfo, faces_info: ~genesis.utils.array_class.FacesInfo, verts_info: ~genesis.utils.array_class.VertsInfo, free_verts_state: ~genesis.utils.array_class.VertsState, fixed_verts_state: ~genesis.utils.array_class.VertsState, geoms_info: ~genesis.utils.array_class.GeomsInfo, dofs_state: ~genesis.utils.array_class.DofsState, links_state: ~genesis.utils.array_class.LinksState) tuple[bool, bool][source]#
couple(i_step)[source]#
couple_grad(i_step)[source]#
update_vel(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, dofs_state: ~genesis.utils.array_class.DofsState)[source]#
update_fem_vel(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
update_rigid_vel(dofs_state: DofsState)[source]#
fem_compute_pressure_gradient(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
update_bvh(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
update_fem_surface_tet_bvh(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
update_rigid_tri_bvh()[source]#
update_rigid_tet_bvh()[source]#
compute_fem_surface_tet_aabb(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_rigid_tri_aabb(faces_info: FacesInfo, free_verts_state: VertsState, fixed_verts_state: VertsState, verts_info: VertsInfo)[source]#
compute_rigid_tet_aabb()[source]#
sap_solve(i_step)[source]#
check_sap_convergence(rigid_info: RigidInfo)[source]#
clear_sap_norms()[source]#
add_fem_norms()[source]#
add_rigid_norms(rigid_info: RigidInfo)[source]#
update_batch_active()[source]#
compute_regularization(dofs_state: DofsState, entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
compute_unconstrained_gradient_diag(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, iter: int)[source]#
init_unconstrained_gradient_diag(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
init_fem_unconstrained_gradient_diag(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
init_rigid_unconstrained_gradient(dofs_state: DofsState)[source]#
compute_unconstrained_gradient()[source]#
compute_fem_unconstrained_gradient()[source]#
compute_rigid_unconstrained_gradient(rigid_info: RigidInfo)[source]#
compute_constraint_contact_gradient_hessian_diag_prec()[source]#
clear_impulses()[source]#
clear_fem_impulses()[source]#
clear_rigid_impulses()[source]#
compute_preconditioner()[source]#
compute_fem_preconditioner()[source]#
compute_fem_pcg_matrix_vector_product()[source]#
compute_rigid_pcg_matrix_vector_product(rigid_info: RigidInfo)[source]#
compute_elastic_products(i_b, i_e, S, i_vs, src)[source]#
compute_fem_matrix_vector_product(src, dst, active)[source]#

Compute the FEM matrix-vector product, including mass matrix and elasticity stiffness matrix.

init_pcg_solve(entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
init_pcg_state()[source]#
init_fem_pcg_solve()[source]#
compute_rigid_mass_mat_vec_product(vec, out, active, rigid_info: RigidInfo)[source]#

Compute the rigid mass matrix-vector product.

rigid_solve_pcg(vec, out, entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
rigid_solve_jacobian(vec, out, n_contact_pairs, i_bs, dim, entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
init_rigid_pcg_solve(entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
init_pcg_active()[source]#
one_pcg_iter()[source]#
compute_pcg_matrix_vector_product(rigid_info: RigidInfo)[source]#

Compute the matrix-vector product Ap used in the Preconditioned Conjugate Gradient method.

clear_pcg_state()[source]#
compute_pcg_pTAp()[source]#

Compute the product p^T @ A @ p used in the Preconditioned Conjugate Gradient method.

Notes

Reference: https://en.wikipedia.org/wiki/Conjugate_gradient_method#The_preconditioned_conjugate_gradient_method

compute_fem_pcg_pTAp()[source]#
compute_rigid_pcg_pTAp()[source]#
compute_alpha()[source]#
compute_pcg_state(entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
compute_fem_pcg_state()[source]#
compute_rigid_pcg_state(entities_info: EntitiesInfo, rigid_info: RigidInfo)[source]#
check_pcg_convergence()[source]#
compute_p()[source]#
compute_fem_p()[source]#
compute_rigid_p()[source]#
pcg_solve()[source]#
compute_total_energy(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, energy: <quadrants.types.annotations.Template object at 0x797f487713a0>, dofs_state: ~genesis.utils.array_class.DofsState, rigid_info: ~genesis.utils.array_class.RigidInfo)[source]#
compute_fem_energy(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, energy: <quadrants.types.annotations.Template object at 0x797f48380ec0>)[source]#
compute_rigid_energy(energy: <quadrants.types.annotations.Template object at 0x797f4838b140>, dofs_state: ~genesis.utils.array_class.DofsState, rigid_info: ~genesis.utils.array_class.RigidInfo)[source]#
init_exact_linesearch(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, dofs_state: ~genesis.utils.array_class.DofsState, rigid_info: ~genesis.utils.array_class.RigidInfo)[source]#
init_newton_linesearch()[source]#
compute_line_energy_gradient_hessian(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, dofs_state: ~genesis.utils.array_class.DofsState)[source]#
init_linesearch_energy_gradient_hessian()[source]#
compute_fem_gradient_alpha(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_rigid_gradient_alpha(dofs_state: DofsState)[source]#
compute_fem_energy_alpha(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, energy: <quadrants.types.annotations.Template object at 0x797f4838af30>)[source]#
compute_rigid_energy_alpha(energy: <quadrants.types.annotations.Template object at 0x797f487e47a0>, dofs_state: ~genesis.utils.array_class.DofsState)[source]#
prepare_search_direction_data(rigid_info: RigidInfo)[source]#
compute_d2ellA_dalpha2()[source]#
compute_fem_d2ellA_dalpha2()[source]#
compute_rigid_d2ellA_dalpha2()[source]#
prepare_fem_search_direction_data()[source]#
prepare_rigid_search_direction_data(rigid_info: RigidInfo)[source]#
check_initial_exact_linesearch_convergence()[source]#
update_initial_fem_state()[source]#
update_initial_rigid_state()[source]#
one_linesearch_iter(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
update_velocity_linesearch()[source]#
update_fem_velocity_linesearch()[source]#
update_rigid_velocity_linesearch()[source]#
exact_linesearch(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#

Note

Exact line search using rtsafe RobotLocomotion/drake

one_exact_linesearch_iter(i_step: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, dofs_state: ~genesis.utils.array_class.DofsState)[source]#
compute_f_df_bracket()[source]#

Compute the function (derivative of total energy) value and its derivative to alpha. Update the bracket for the next step size.

The bracket is defined by [alpha_min, alpha_max] which is the range that contains the root of df/dalpha = 0.

find_next_step_size()[source]#
property active_solvers#

All the active solvers managed by the scene’s simulator.

See also#

  • Couplers: coupler overview and how to choose one.

  • Coupling: the theory behind each coupler.