FEMSolver#

The FEMSolver implements the Finite Element Method for simulating deformable solids on tetrahedral meshes. It supports several constitutive models (linear, stable Neo-Hookean, linear corotated), handles large deformations, and integrates explicitly unless use_implicit_solver selects the implicit solver, which stays stable at larger time steps. The materials it supports are listed in FEM. For usage, see Beyond rigid bodies and, for muscle-driven bodies, Soft robots.

Options#

class genesis.options.solvers.FEMOptions(*, dt: float | None = None, gravity: tuple[float, float, float] | None = None, damping: float = 0.0, floor_height: float | None = None, use_implicit_solver: bool = False, n_newton_iterations: int = 1, n_pcg_iterations: int = 500, n_linesearch_iterations: int = 0, newton_dx_threshold: float = 1e-06, pcg_threshold: float = 1e-06, linesearch_c: float = 0.0001, linesearch_tau: float = 0.5, damping_alpha: float = 0.5, damping_beta: float = 0.0005, enable_vertex_constraints: bool = False) None[source]#

Options configuring the FEMSolver.

Note

  • Damping coefficients are used to control the damping effect in the simulation.

They are used in the Rayleigh Damping model, which is a common damping model in FEM simulations. Reference: https://doc.comsol.com/5.5/doc/com.comsol.help.sme/sme_ug_modeling.05.083.html - TODO Move it to material parameters in the future instead of solver options.

Parameters:
  • damping (float, optional) – Damping factor. Defaults to 0.0.

  • floor_height (float, optional) – Height of the floor in meters. If none, it will inherit from SimOptions. Defaults to None.

  • use_implicit_solver (bool, optional) – Whether to use the implicit solver. Defaults to False. Implicit solver is a more stable solver for FEM. It can be used with a large time step.

  • n_newton_iterations (int, optional) – Maximum number of Newton iterations. Defaults to 1. Only used when use_implicit_solver is True.

  • n_pcg_iterations (int, optional) – Maximum number of PCG iterations. Defaults to 500. Only used when use_implicit_solver is True.

  • n_linesearch_iterations (int, optional) – Maximum number of line search iterations. Defaults to 0. Only used when use_implicit_solver is True.

  • newton_dx_threshold (float, optional) – Threshold for the Newton solver. Defaults to 1e-6. Only used when use_implicit_solver is True.

  • pcg_threshold (float, optional) – Threshold for the PCG solver. Defaults to 1e-6. Only used when use_implicit_solver is True.

  • linesearch_c (float, optional) – Line search sufficient decrease parameter. Defaults to 1e-4. Only used when use_implicit_solver is True.

  • linesearch_tau (float, optional) – Line search step size reduction factor. Defaults to 0.5. Only used when use_implicit_solver is True.

  • damping_alpha (float, optional) – Rayleigh Damping factor for the implicit solver. Defaults to 0.5. Only used when use_implicit_solver is True.

  • damping_beta (float, optional) – Rayleigh Damping factor for the implicit solver. Defaults to 5e-4. Only used when use_implicit_solver is True.

  • enable_vertex_constraints (bool, optional) – Whether to enable vertex constraints. Defaults to False.

FEMSolver#

class genesis.engine.solvers.fem_solver.FEMSolver(scene, sim, options)[source]#

Bases: GravityMixin, TimeBasedMixin, Solver

material_cls#

alias of Base

setup_boundary()[source]#
init_batch_fields()[source]#
init_element_fields()[source]#
init_surface_fields()[source]#
init_vvert_fields()[source]#

Allocate the render geometry of every visual geom of every entity, laid out back-to-back.

Several vverts may stand for a single simulated vertex, so each one carries its own UVs and gathers its position through ‘vert_idx’ (see ‘FEMVisGeom’). A contiguous layout lets a renderer consume positions, UVs and topology as three flat arrays.

compute_surface_vertices()[source]#
compute_surface_elements()[source]#
init_ckpt()[source]#
init_constraints()[source]#
reset_grad()[source]#
build()[source]#
property is_active#
add_entity(idx, material, morph, surface, visualize_contact=False, name: str | None = None, desc=None) FEMEntity[source]#
init_pos_and_vel(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_vel(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
apply_uniform_force(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_pos(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
precompute_material_data(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
init_pos_and_inertia(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_ele_hessian_gradient(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
accumulate_vertex_force_preconditioner(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
compute_Ap()[source]#
init_pcg_solve()[source]#
one_pcg_iter()[source]#
pcg_solve()[source]#
init_linesearch(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
one_linesearch_iter(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
skip_linesearch(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
linesearch(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
batch_solve(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
setup_pos_vel(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
process_input(in_backward=False)[source]#
process_input_grad()[source]#
substep_pre_coupling(f)[source]#
substep_pre_coupling_grad(f)[source]#
substep_post_coupling(f)[source]#
substep_post_coupling_grad(f)[source]#
copy_frame(source: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, target: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
copy_grad(source: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>, target: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
reset_grad_till_frame(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#
collect_output_grads()[source]#
add_grad_from_state(state)[source]#
save_ckpt(ckpt_name)[source]#
load_ckpt(ckpt_name)[source]#
set_state(f, state, envs_idx=None)[source]#
get_state(f)[source]#
get_state_render(f)[source]#

Refresh and return the render geometry of every visual geom, laid out contiguously.

Returns:

(vverts_pos, vverts_uvs, vfaces_indices) - environment-offset render vertex positions with shape (n_vverts, B), their UV coordinates, and the render triangles in global render vertex space.

Return type:

tuple

get_forces()[source]#

Get forces on all vertices.

Returns:

shape (B, n_vertices, 3) where B is batch size

Return type:

torch.Tensor

property floor_height#
property damping#
property n_vertices#
property n_elements#
property n_surfaces#
property n_vverts#
property n_vfaces#
property n_vertices_max#
property n_elements_max#
property vol_scale#
property n_surface_vertices#
property n_surface_elements#
apply_hard_constraints(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#

Apply hard constraints by directly overriding positions and velocities.

apply_soft_constraints(f: <quadrants._lib.core.quadrants_python.DataTypeCxx object at 0x798033d1b9b0>)[source]#

Apply soft constraints as spring forces for explicit solver.

See also#