Bullet Collision Detection & Physics Library
btReducedDeformableBody.h
Go to the documentation of this file.
1#ifndef BT_REDUCED_SOFT_BODY_H
2#define BT_REDUCED_SOFT_BODY_H
3
4#include "../btSoftBody.h"
9
10// Reduced deformable body is a simplified deformable object embedded in a rigid frame.
12{
13 public:
14 //
15 // Typedefs
16 //
18 // typedef btAlignedObjectArray<btMatrix3x3> tBlockDiagMatrix;
21
22 private:
23 // flag to turn off the reduced modes
25
26 // Flags for transform. Once transform is applied, users cannot scale the mesh or change its total mass.
28
29 // scaling factors
30 btScalar m_rhoScale; // mass density scale
31 btScalar m_ksScale; // stiffness scale
32
33 // projection matrix
34 tDenseMatrix m_projPA; // Eqn. 4.11 from Rahul Sheth's thesis
38
40
44
45 btVector3 m_linearVelocityFromReduced; // contribution to the linear velocity from reduced velocity
46 btVector3 m_angularVelocityFromReduced; // contribution to the angular velocity from reduced velocity
48
49 protected:
50 // rigid frame
51 btScalar m_mass; // total mass of the rigid frame
52 btScalar m_inverseMass; // inverse of the total mass of the rigid frame
55 btScalar m_linearDamping; // linear damping coefficient
56 btScalar m_angularDamping; // angular damping coefficient
59 // btVector3 m_invInertiaLocal;
65 btVector3 m_initialCoM; // initial center of mass (original of the m_rigidTransformWorld)
66
67 // damping
70
71 public:
72 //
73 // Fields
74 //
75
76 // reduced space
79 tDenseMatrix m_modes; // modes of the reduced deformable model. Each inner array is a mode, outer array size = n_modes
80 tDenseArray m_reducedDofs; // Reduced degree of freedom
81 tDenseArray m_reducedDofsBuffer; // Reduced degree of freedom at t^n
82 tDenseArray m_reducedVelocity; // Reduced velocity array
83 tDenseArray m_reducedVelocityBuffer; // Reduced velocity array at t^n
84 tDenseArray m_reducedForceExternal; // reduced external force
85 tDenseArray m_reducedForceElastic; // reduced internal elastic force
86 tDenseArray m_reducedForceDamping; // reduced internal damping force
87 tDenseArray m_eigenvalues; // eigenvalues of the reduce deformable model
88 tDenseArray m_Kr; // reduced stiffness matrix
89
90 // full space
91 TVStack m_x0; // Rest position
92 tDenseArray m_nodalMass; // Mass on each node
93 btAlignedObjectArray<int> m_fixedNodes; // index of the fixed nodes
94 int m_nodeIndexOffset; // offset of the node index needed for contact solver when there are multiple reduced deformable body in the world.
95
96 // contacts
98
99 //
100 // Api
101 //
102 btReducedDeformableBody(btSoftBodyWorldInfo* worldInfo, int node_count, const btVector3* x, const btScalar* m);
103
105
106 //
107 // initializing helpers
108 //
110
111 void setReducedModes(int num_modes, int full_size);
112
113 void setMassProps(const tDenseArray& mass_array);
114
115 void setInertiaProps();
116
117 void setRigidVelocity(const btVector3& v);
118
119 void setRigidAngularVelocity(const btVector3& omega);
120
121 void setStiffnessScale(const btScalar ks);
122
123 void setMassScale(const btScalar rho);
124
125 void setFixedNodes(const int n_node);
126
127 void setDamping(const btScalar alpha, const btScalar beta);
128
129 void disableReducedModes(const bool rigid_only);
130
131 virtual void setTotalMass(btScalar mass, bool fromfaces = false);
132
133 //
134 // various internal updates
135 //
136 virtual void transformTo(const btTransform& trs);
137 virtual void transform(const btTransform& trs);
138 // caution:
139 // need to use scale before using transform, because the scale is performed in the local frame
140 // (i.e., may have some rotation already, but the m_rigidTransformWorld doesn't have this info)
141 virtual void scale(const btVector3& scl);
142
143 private:
145
146 void updateInitialInertiaTensor(const btMatrix3x3& rotation);
147
149
150 void updateInertiaTensor();
151
152 void updateModesByRotation(const btMatrix3x3& rotation);
153
154 public:
156
157 void predictIntegratedTransform(btScalar dt, btTransform& predictedTransform);
158
159 // update the external force projection matrix
160 void updateExternalForceProjectMatrix(bool initialized);
161
163
165
166 //
167 // position and velocity update related
168 //
169
170 // compute reduced degree of freedoms
171 void updateReducedDofs(btScalar solverdt);
172
173 // compute reduced velocity update (for explicit time stepping)
174 void updateReducedVelocity(btScalar solverdt);
175
176 // map to full degree of freedoms
177 void mapToFullPosition(const btTransform& ref_trans);
178
179 // compute full space velocity from the reduced velocity
180 void mapToFullVelocity(const btTransform& ref_trans);
181
182 // compute total angular momentum
184
185 // get a single node's full space velocity from the reduced velocity
186 const btVector3 computeNodeFullVelocity(const btTransform& ref_trans, int n_node) const;
187
188 // get a single node's all delta velocity
189 const btVector3 internalComputeNodeDeltaVelocity(const btTransform& ref_trans, int n_node) const;
190
191 //
192 // rigid motion related
193 //
194 void applyDamping(btScalar timeStep);
195
196 void applyCentralImpulse(const btVector3& impulse);
197
198 void applyTorqueImpulse(const btVector3& torque);
199
200 void proceedToTransform(btScalar dt, bool end_of_time_step);
201
202 //
203 // force related
204 //
205
206 // apply impulse to the rigid frame
207 void internalApplyRigidImpulse(const btVector3& impulse, const btVector3& rel_pos);
208
209 // apply impulse to nodes in the full space
210 void internalApplyFullSpaceImpulse(const btVector3& impulse, const btVector3& rel_pos, int n_node, btScalar dt);
211
212 // apply nodal external force in the full space
213 void applyFullSpaceNodalForce(const btVector3& f_ext, int n_node);
214
215 // apply gravity to the rigid frame
216 void applyRigidGravity(const btVector3& gravity, btScalar dt);
217
218 // apply reduced elastic force
219 void applyReducedElasticForce(const tDenseArray& reduce_dofs);
220
221 // apply reduced damping force
222 void applyReducedDampingForce(const tDenseArray& reduce_vel);
223
224 // calculate the impulse factor
225 virtual btMatrix3x3 getImpulseFactor(int n_node);
226
227 // get relative position from a node to the CoM of the rigid frame
228 btVector3 getRelativePos(int n_node);
229
230 //
231 // accessors
232 //
233 bool isReducedModesOFF() const;
234 btScalar getTotalMass() const;
236 const btVector3& getLinearVelocity() const;
237 const btVector3& getAngularVelocity() const;
238
239 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
240 void clampVelocity(btVector3& v) const {
241 v.setX(
242 fmax(-BT_CLAMP_VELOCITY_TO,
243 fmin(BT_CLAMP_VELOCITY_TO, v.getX()))
244 );
245 v.setY(
246 fmax(-BT_CLAMP_VELOCITY_TO,
247 fmin(BT_CLAMP_VELOCITY_TO, v.getY()))
248 );
249 v.setZ(
250 fmax(-BT_CLAMP_VELOCITY_TO,
251 fmin(BT_CLAMP_VELOCITY_TO, v.getZ()))
252 );
253 }
254 #endif
255};
256
257#endif // BT_REDUCED_SOFT_BODY_H
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
void applyFullSpaceNodalForce(const btVector3 &f_ext, int n_node)
void predictIntegratedTransform(btScalar dt, btTransform &predictedTransform)
void applyTorqueImpulse(const btVector3 &torque)
btAlignedObjectArray< btScalar > tDenseArray
const btVector3 computeNodeFullVelocity(const btTransform &ref_trans, int n_node) const
btMatrix3x3 m_interpolateInvInertiaTensorWorld
btVector3 getRelativePos(int n_node)
btAlignedObjectArray< int > m_fixedNodes
btReducedDeformableBody(btSoftBodyWorldInfo *worldInfo, int node_count, const btVector3 *x, const btScalar *m)
virtual void transform(const btTransform &trs)
void mapToFullVelocity(const btTransform &ref_trans)
const btVector3 & getAngularVelocity() const
btVector3 m_internalDeltaAngularVelocityFromReduced
void setRigidAngularVelocity(const btVector3 &omega)
void setReducedModes(int num_modes, int full_size)
void updateReducedVelocity(btScalar solverdt)
void disableReducedModes(const bool rigid_only)
btAlignedObjectArray< btVector3 > TVStack
const btVector3 & getLinearVelocity() const
void updateModesByRotation(const btMatrix3x3 &rotation)
virtual btMatrix3x3 getImpulseFactor(int n_node)
void setRigidVelocity(const btVector3 &v)
const btVector3 internalComputeNodeDeltaVelocity(const btTransform &ref_trans, int n_node) const
const btVector3 computeTotalAngularMomentum() const
btAlignedObjectArray< btAlignedObjectArray< btScalar > > tDenseMatrix
void applyCentralImpulse(const btVector3 &impulse)
void updateExternalForceProjectMatrix(bool initialized)
void applyReducedElasticForce(const tDenseArray &reduce_dofs)
void internalApplyFullSpaceImpulse(const btVector3 &impulse, const btVector3 &rel_pos, int n_node, btScalar dt)
void applyReducedDampingForce(const tDenseArray &reduce_vel)
void setDamping(const btScalar alpha, const btScalar beta)
void setStiffnessScale(const btScalar ks)
void setMassScale(const btScalar rho)
void applyDamping(btScalar timeStep)
void updateInitialInertiaTensor(const btMatrix3x3 &rotation)
void internalApplyRigidImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
void setFixedNodes(const int n_node)
void setMassProps(const tDenseArray &mass_array)
virtual void transformTo(const btTransform &trs)
virtual void scale(const btVector3 &scl)
void applyRigidGravity(const btVector3 &gravity, btScalar dt)
void updateReducedDofs(btScalar solverdt)
void proceedToTransform(btScalar dt, bool end_of_time_step)
void mapToFullPosition(const btTransform &ref_trans)
btAlignedObjectArray< int > m_contactNodesList
virtual void setTotalMass(btScalar mass, bool fromfaces=false)
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:565
void setZ(btScalar _z)
Set the z value.
Definition: btVector3.h:571
void setY(btScalar _y)
Set the y value.
Definition: btVector3.h:569
void setX(btScalar _x)
Set the x value.
Definition: btVector3.h:567
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:563
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:561