Skip to content

[deformable] Add DeformableBody class #23029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions multibody/plant/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ drake_cc_package_library(
":contact_jacobians",
":contact_results",
":coulomb_friction",
":deformable_ids",
":desired_state_input",
":discrete_contact_data",
":discrete_contact_pair",
Expand All @@ -43,7 +42,6 @@ drake_cc_library(
"constraint_specs.h",
],
deps = [
":deformable_ids",
"//multibody/tree:multibody_tree_indexes",
],
)
Expand Down Expand Up @@ -105,7 +103,6 @@ drake_cc_library(
hdrs = [
"compliant_contact_manager.h",
"deformable_driver.h",
"deformable_ids.h",
"deformable_model.h",
"discrete_step_memory.h",
"discrete_update_manager.h",
Expand All @@ -128,7 +125,6 @@ drake_cc_library(
":contact_jacobians",
":contact_results",
":coulomb_friction",
":deformable_ids",
":desired_state_input",
":discrete_contact_data",
":discrete_contact_pair",
Expand Down Expand Up @@ -262,16 +258,6 @@ drake_cc_library(
],
)

drake_cc_library(
name = "deformable_ids",
hdrs = [
"deformable_ids.h",
],
deps = [
"//common:identifier",
],
)

drake_cc_library(
name = "desired_state_input",
srcs = [
Expand Down
3 changes: 1 addition & 2 deletions multibody/plant/constraint_specs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <vector>

#include "drake/math/rigid_transform.h"
#include "drake/multibody/plant/deformable_ids.h"
#include "drake/multibody/tree/multibody_tree_indexes.h"

namespace drake {
Expand Down Expand Up @@ -101,7 +100,7 @@ struct WeldConstraintSpec {
// body A.
struct DeformableRigidFixedConstraintSpec {
bool operator==(const DeformableRigidFixedConstraintSpec&) const = default;
DeformableBodyId body_A; // Index of the deformable body A.
DeformableBodyId body_A; // Id of the deformable body A.
BodyIndex body_B; // Index of the rigid body B.
std::vector<int> vertices; // Indices of the Pᵢ in the deformable body A.
std::vector<Vector3<double>>
Expand Down
35 changes: 15 additions & 20 deletions multibody/plant/deformable_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,18 +631,17 @@ void DeformableDriver<T>::AppendDeformableRigidFixedConstraintKinematics(
.template Eval<geometry::GeometryConfigurationVector<T>>(context);
for (DeformableBodyIndex index(0); index < deformable_model_->num_bodies();
++index) {
DeformableBodyId body_id = deformable_model_->GetBodyId(index);
if (!deformable_model_->is_enabled(body_id, context) ||
!deformable_model_->HasConstraint(body_id)) {
const DeformableBody<T>& body = deformable_model_->GetBody(index);
if (!body.is_enabled(context) || !body.has_fixed_constraint()) {
continue;
}

const FemModel<T>& fem_model = deformable_model_->GetFemModel(body_id);
const FemModel<T>& fem_model = body.fem_model();
const DirichletBoundaryCondition<T>& bc =
fem_model.dirichlet_boundary_condition();

/* Returns true iff for the deformable body with `body_id`, the given vertex
index is under boundary condition. */
/* Returns true iff for the deformable body, the given vertex index is under
boundary condition. */
auto is_under_bc = [&](int vertex_index) {
return bc.index_to_boundary_state().count(
multibody::fem::FemNodeIndex(vertex_index)) > 0;
Expand All @@ -653,15 +652,13 @@ void DeformableDriver<T>::AppendDeformableRigidFixedConstraintKinematics(
// Each deformable body forms its own clique and are indexed in inceasing
// DeformableBodyIndex order and placed after all rigid cliques.
const TreeIndex clique_index_A(tree_topology.num_trees() + index);
GeometryId geometry_id = deformable_model_->GetGeometryId(body_id);
const GeometryId geometry_id = body.geometry_id();
const PartialPermutation& vertex_permutation =
EvalVertexPermutation(context, geometry_id);
const VectorX<T>& p_WVs = configurations.value(geometry_id);

for (const MultibodyConstraintId& constraint_id :
deformable_model_->fixed_constraint_ids(body_id)) {
const DeformableRigidFixedConstraintSpec& spec =
deformable_model_->fixed_constraint_spec(constraint_id);
for (const DeformableRigidFixedConstraintSpec& spec :
body.fixed_constraint_specs()) {
const int num_vertices_in_constraint = ssize(spec.vertices);
/* The Jacobian block for the deformable body A. */
Block3x3SparseMatrix<T> negative_Jv_v_WAp(
Expand Down Expand Up @@ -1056,23 +1053,21 @@ void DeformableDriver<T>::CalcDeformableContact(
/* Complete the result with information on constraints other than contact. */
for (DeformableBodyIndex body_index(0);
body_index < deformable_model_->num_bodies(); ++body_index) {
DeformableBodyId body_id = deformable_model_->GetBodyId(body_index);
const DeformableBody<T>& body = deformable_model_->GetBody(body_index);
/* Add in constraints. */
if (deformable_model_->HasConstraint(body_id)) {
if (body.has_fixed_constraint()) {
std::unordered_set<int> fixed_vertices;
for (const MultibodyConstraintId& constraint_id :
deformable_model_->fixed_constraint_ids(body_id)) {
const DeformableRigidFixedConstraintSpec& spec =
deformable_model_->fixed_constraint_spec(constraint_id);
for (const DeformableRigidFixedConstraintSpec& spec :
body.fixed_constraint_specs()) {
fixed_vertices.insert(spec.vertices.begin(), spec.vertices.end());
}
/* Register the geometry in case it hasn't been registered because it's
not participating in contact but is participating in other types of
constraints. */
GeometryId geometry_id = deformable_model_->GetGeometryId(body_id);
GeometryId geometry_id = body.geometry_id();
if (!result->IsRegistered(geometry_id)) {
result->RegisterDeformableGeometry(
geometry_id, deformable_model_->GetFemModel(body_id).num_nodes());
result->RegisterDeformableGeometry(geometry_id,
body.fem_model().num_nodes());
}
result->Participate(geometry_id, fixed_vertices);
}
Expand Down
18 changes: 0 additions & 18 deletions multibody/plant/deformable_ids.h

This file was deleted.

Loading