1
1
#pragma once
2
2
3
3
#include < memory>
4
+ #include < string>
4
5
#include < vector>
5
6
6
7
#include " drake/common/drake_copyable.h"
19
20
namespace drake {
20
21
namespace multibody {
21
22
23
+ // TODO(xuchenhan-tri): Derive from MultibodyElement.
22
24
template <typename T>
23
25
class DeformableBody {
24
26
public:
25
- DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN (DeformableBody);
26
-
27
27
/* * Returns this element's unique index. */
28
28
DeformableBodyIndex index () const { return index_; }
29
29
30
30
/* * Returns the unique body id. */
31
31
DeformableBodyId body_id () const { return id_; }
32
32
33
- /* * Returns physical parameters of this deformable body. */
34
- const fem::DeformableBodyConfig<T>& config () const { return config_; }
35
-
36
- /* * Returns the number of degrees of freedom (DoFs) of this body. */
37
- int num_dofs () const { return fem_model_->num_dofs (); }
33
+ /* * Returns the name of the body. */
34
+ const std::string& name () const { return name_; }
38
35
39
36
/* * Returns the geometry id of the deformable geometry used to simulate this
40
37
deformable body. */
@@ -43,13 +40,21 @@ class DeformableBody {
43
40
/* * Returns the model instance index of this deformable body. */
44
41
ModelInstanceIndex model_instance () const { return model_instance_; }
45
42
43
+ /* * Returns physical parameters of this deformable body. */
44
+ const fem::DeformableBodyConfig<T>& config () const { return config_; }
45
+
46
+ /* * Returns the number of degrees of freedom (DoFs) of this body. */
47
+ int num_dofs () const { return fem_model_->num_dofs (); }
48
+
46
49
/* * Returns the reference positions of the vertices of the deformable body
47
50
identified by the given `id`.
48
51
The reference positions are represented as a VectorX with 3N values where N
49
52
is the number of vertices. The x-, y-, and z-positions (measured and
50
53
expressed in the world frame) of the j-th vertex are 3j, 3j + 1, and 3j + 2
51
54
in the VectorX. */
52
- const VectorX<T>& reference_positions () const { return reference_positions_; }
55
+ const VectorX<double >& reference_positions () const {
56
+ return reference_positions_;
57
+ }
53
58
54
59
/* * Returns the FemModel for this deformable body. */
55
60
const fem::FemModel<T>& fem_model () const { return *fem_model_; }
@@ -195,12 +200,17 @@ class DeformableBody {
195
200
void Enable (systems::Context<T>* context) const ;
196
201
197
202
private:
203
+ DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN (DeformableBody)
204
+
198
205
template <typename U>
199
206
friend class DeformableModel ;
207
+ template <typename U>
208
+ friend class DeformableBody ;
200
209
201
210
/* Private constructor exposed only to DeformableModel.
202
211
@param index Unique DeformableBodyIndex
203
212
@param id Unique DeformableBodyId
213
+ @param name Name of the body
204
214
@param geometry_id GeometryId of the simulated geometry.
205
215
@param model_instance ModelInstanceIndex for this body.
206
216
@param mesh_G The simulated volume mesh in the geometry's frame.
@@ -211,13 +221,26 @@ class DeformableBody {
211
221
@pre `plant` is not nullptr.
212
222
@pre `plant` is not finalized. */
213
223
DeformableBody (DeformableBodyIndex index, DeformableBodyId id,
214
- geometry::GeometryId geometry_id,
224
+ std::string name, geometry::GeometryId geometry_id,
215
225
ModelInstanceIndex model_instance,
216
226
const geometry::VolumeMesh<double >& mesh_G,
217
227
const math::RigidTransform<double >& X_WG,
218
228
const fem::DeformableBodyConfig<T>& config,
219
229
const MultibodyPlant<T>* plant);
220
230
231
+ std::unique_ptr<DeformableBody<double >> CloneToDouble (
232
+ const MultibodyPlant<double >* plant) const {
233
+ if constexpr (!std::is_same_v<T, double >) {
234
+ /* A none double body shouldn't exist in the first place. */
235
+ DRAKE_UNREACHABLE ();
236
+ } else {
237
+ auto clone = std::unique_ptr<DeformableBody<double >>(
238
+ new DeformableBody<double >(*this ));
239
+ clone->plant_ = plant;
240
+ return clone;
241
+ }
242
+ }
243
+
221
244
/* Private setter accessible to DeformableModel. */
222
245
void set_discrete_state_index (systems::DiscreteStateIndex index) {
223
246
discrete_state_index_ = index;
@@ -240,33 +263,39 @@ class DeformableBody {
240
263
single quadrature point. The reference positions as well as the connectivity
241
264
of the elements are given by `mesh`, and physical properties of the body are
242
265
given by `config`. */
243
- void BuildLinearVolumetricModel (const geometry::VolumeMesh<double >& mesh,
244
- const fem::DeformableBodyConfig<T>& config);
266
+ template <typename T1 = T>
267
+ typename std::enable_if_t <std::is_same_v<T1, double >, void >
268
+ BuildLinearVolumetricModel (const geometry::VolumeMesh<double >& mesh,
269
+ const fem::DeformableBodyConfig<T>& config);
245
270
246
271
/* Helper for BuildLinearVolumetricModel templated on constitutive model. */
247
- template <template <class > class Model >
248
- void BuildLinearVolumetricModelHelper (
249
- const geometry::VolumeMesh<double >& mesh,
250
- const fem::DeformableBodyConfig<T>& config);
272
+ template <template <class > class Model , typename T1 = T >
273
+ typename std:: enable_if_t <std::is_same_v<T1, double >, void >
274
+ BuildLinearVolumetricModelHelper ( const geometry::VolumeMesh<double >& mesh,
275
+ const fem::DeformableBodyConfig<T>& config);
251
276
252
277
DeformableBodyIndex index_{};
253
278
DeformableBodyId id_{};
279
+ std::string name_;
254
280
geometry::GeometryId geometry_id_{};
255
281
ModelInstanceIndex model_instance_{};
282
+ /* The mesh of the deformable geometry (in its reference configuration) in its
283
+ geometry frame. */
284
+ geometry::VolumeMesh<double > mesh_G_;
256
285
/* The pose of the deformable geometry (in its reference configuration) in the
257
286
world frame. */
258
287
math::RigidTransform<double > X_WG_;
259
288
fem::DeformableBodyConfig<T> config_;
260
289
const MultibodyPlant<T>* plant_{};
261
- VectorX<T > reference_positions_;
262
- std::unique_ptr <fem::FemModel<T>> fem_model_;
290
+ VectorX<double > reference_positions_;
291
+ copyable_unique_ptr <fem::FemModel<T>> fem_model_;
263
292
systems::DiscreteStateIndex discrete_state_index_{};
264
293
systems::AbstractParameterIndex is_enabled_parameter_index_{};
265
294
std::vector<internal::DeformableRigidFixedConstraintSpec>
266
295
fixed_constraint_specs_;
267
296
/* External forces and constraints. */
268
297
/* Owned gravity force. */
269
- std::unique_ptr <ForceDensityField<T>> gravity_force_;
298
+ copyable_unique_ptr <ForceDensityField<T>> gravity_force_;
270
299
/* All external forces affecting this body (including the owned gravity). */
271
300
std::vector<const ForceDensityField<T>*> external_forces_;
272
301
};
0 commit comments