Bullet Collision Detection & Physics Library: btDeformableBodySolver.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btDeformableBodySolver.h
Go to the documentation of this file.
1/*
2 Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
3
4 Bullet Continuous Collision Detection and Physics Library
5 Copyright (c) 2019 Google Inc. http://bulletphysics.org
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it freely,
10 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16#ifndef BT_DEFORMABLE_BODY_SOLVERS_H
17#define BT_DEFORMABLE_BODY_SOLVERS_H
18
19#include "btSoftBodySolvers.h"
20#include "btDeformableBackwardEulerObjective.h"
21#include "btDeformableMultiBodyDynamicsWorld.h"
22#include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
23#include "BulletDynamics/Featherstone/btMultiBodyConstraint.h"
24#include "btConjugateResidual.h"
25#include "btConjugateGradient.h"
26struct btCollisionObjectWrapper;
27// class btDeformableBackwardEulerObjective;
28// class btDeformableMultiBodyDynamicsWorld;
29
30 class btDeformableBodySolver : public btSoftBodySolver
31{
32 typedef btAlignedObjectArray<btVector3> TVStack;
33
34protected:
35 int m_numNodes; // total number of deformable body nodes
36 TVStack m_dv; // v_{n+1} - v_n
37 TVStack m_backup_dv; // backed up dv
38 TVStack m_ddv; // incremental dv
39 TVStack m_residual; // rhs of the linear solve
40 btAlignedObjectArray<btSoftBody*> m_softBodies; // all deformable bodies
41 TVStack m_backupVelocity; // backed up v, equals v_n for implicit, equals v_{n+1}^* for explicit
42 btScalar m_dt; // dt
43 btConjugateGradient<btDeformableBackwardEulerObjective> m_cg; // CG solver
44 btConjugateResidual<btDeformableBackwardEulerObjective> m_cr; // CR solver
45 bool m_implicit; // use implicit scheme if true, explicit scheme if false
46 int m_maxNewtonIterations; // max number of newton iterations
47 btScalar m_newtonTolerance; // stop newton iterations if f(x) < m_newtonTolerance
48 bool m_lineSearch; // If true, use newton's method with line search under implicit scheme
49 bool m_reducedSolver; // flag for reduced soft body solver
50public:
51 // handles data related to objective function
52 btDeformableBackwardEulerObjective* m_objective;
53 bool m_useProjection;
54
55 btDeformableBodySolver();
56
57 virtual ~btDeformableBodySolver();
58
59 virtual SolverTypes getSolverType() const
60 {
61 return DEFORMABLE_SOLVER;
62 }
63
64 // update soft body normals
65 virtual void updateSoftBodies();
66
67 virtual btScalar solveContactConstraints(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
68
69 // solve the momentum equation
70 virtual void solveDeformableConstraints(btScalar solverdt);
71
72 // set gravity (get from deformable world)
73 virtual void setGravity(const btVector3& gravity)
74 {
75 // for full deformable object, we don't store gravity in the solver
76 // this function is overriden in the reduced deformable object
77 }
78
79 // resize/clear data structures
80 virtual void reinitialize(const btAlignedObjectArray<btSoftBody*>& softBodies, btScalar dt);
81
82 // set up contact constraints
83 virtual void setConstraints(const btContactSolverInfo& infoGlobal);
84
85 // add in elastic forces and gravity to obtain v_{n+1}^* and calls predictDeformableMotion
86 virtual void predictMotion(btScalar solverdt);
87
88 // move to temporary position x_{n+1}^* = x_n + dt * v_{n+1}^*
89 // x_{n+1}^* is stored in m_q
90 void predictDeformableMotion(btSoftBody* psb, btScalar dt);
91
92 // save the current velocity to m_backupVelocity
93 void backupVelocity();
94
95 // set m_dv and m_backupVelocity to desired value to prepare for momentum solve
96 virtual void setupDeformableSolve(bool implicit);
97
98 // set the current velocity to that backed up in m_backupVelocity
99 void revertVelocity();
100
101 // set velocity to m_dv + m_backupVelocity
102 void updateVelocity();
103
104 // update the node count
105 bool updateNodes();
106
107 // calculate the change in dv resulting from the momentum solve
108 void computeStep(TVStack& ddv, const TVStack& residual);
109
110 // calculate the change in dv resulting from the momentum solve when line search is turned on
111 btScalar computeDescentStep(TVStack& ddv, const TVStack& residual, bool verbose = false);
112
113 virtual void copySoftBodyToVertexBuffer(const btSoftBody* const softBody, btVertexBufferDescriptor* vertexBuffer) {}
114
115 // process collision between deformable and rigid
116 virtual void processCollision(btSoftBody* softBody, const btCollisionObjectWrapper* collisionObjectWrap)
117 {
118 softBody->defaultCollisionHandler(collisionObjectWrap);
119 }
120
121 // process collision between deformable and deformable
122 virtual void processCollision(btSoftBody* softBody, btSoftBody* otherSoftBody)
123 {
124 softBody->defaultCollisionHandler(otherSoftBody);
125 }
126
127 // If true, implicit time stepping scheme is used.
128 // Otherwise, explicit time stepping scheme is used
129 void setImplicit(bool implicit);
130
131 // If true, newton's method with line search is used when implicit time stepping scheme is turned on
132 void setLineSearch(bool lineSearch);
133
134 // set temporary position x^* = x_n + dt * v
135 // update the deformation gradient at position x^*
136 void updateState();
137
138 // set dv = dv + scale * ddv
139 void updateDv(btScalar scale = 1);
140
141 // set temporary position x^* = x_n + dt * v^*
142 void updateTempPosition();
143
144 // save the current dv to m_backup_dv;
145 void backupDv();
146
147 // set dv to the backed-up value
148 void revertDv();
149
150 // set dv = dv + scale * ddv
151 // set v^* = v_n + dv
152 // set temporary position x^* = x_n + dt * v^*
153 // update the deformation gradient at position x^*
154 void updateEnergy(btScalar scale);
155
156 // calculates the appropriately scaled kinetic energy in the system, which is
157 // 1/2 * dv^T * M * dv
158 // used in line search
159 btScalar kineticEnergy();
160
161 // add explicit force to the velocity in the objective class
162 virtual void applyExplicitForce();
163
164 // execute position/velocity update and apply anchor constraints in the integrateTransforms from the Dynamics world
165 virtual void applyTransforms(btScalar timeStep);
166
167 virtual void setStrainLimiting(bool opt)
168 {
169 m_objective->m_projection.m_useStrainLimiting = opt;
170 }
171
172 virtual void setPreconditioner(int opt)
173 {
174 switch (opt)
175 {
176 case btDeformableBackwardEulerObjective::Mass_preconditioner:
177 m_objective->m_preconditioner = m_objective->m_massPreconditioner;
178 break;
179
180 case btDeformableBackwardEulerObjective::KKT_preconditioner:
181 m_objective->m_preconditioner = m_objective->m_KKTPreconditioner;
182 break;
183
184 default:
185 btAssert(false);
186 break;
187 }
188 }
189
190 virtual btAlignedObjectArray<btDeformableLagrangianForce*>* getLagrangianForceArray()
191 {
192 return &(m_objective->m_lf);
193 }
194
195 virtual const btAlignedObjectArray<btSoftBody::Node*>* getIndices()
196 {
197 return m_objective->getIndices();
198 }
199
200 virtual void setProjection()
201 {
202 m_objective->m_projection.setProjection();
203 }
204
205 virtual void setLagrangeMultiplier()
206 {
207 m_objective->m_projection.setLagrangeMultiplier();
208 }
209
210 virtual bool isReducedSolver()
211 {
212 return m_reducedSolver;
213 }
214
215 virtual void deformableBodyInternalWriteBack() {}
216
217 // unused functions
218 virtual void optimize(btAlignedObjectArray<btSoftBody*>& softBodies, bool forceUpdate = false) {}
219 virtual void solveConstraints(btScalar dt) {}
220 virtual bool checkInitialized() { return true; }
221 virtual void copyBackToSoftBodies(bool bMove = true) {}
222};
223
224#endif /* btDeformableBodySolver_h */
btConjugateGradient.h
btConjugateResidual.h
btDeformableBackwardEulerObjective.h
btDeformableMultiBodyDynamicsWorld.h
btMultiBodyConstraint.h
btMultiBodyLinkCollider.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btAssert
#define btAssert(x)
Definition: btScalar.h:153
btSoftBodySolvers.h
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:46
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:51
btConjugateGradient
Definition: btConjugateGradient.h:21
btConjugateResidual
Definition: btConjugateResidual.h:22
btDeformableBackwardEulerObjective
Definition: btDeformableBackwardEulerObjective.h:32
btDeformableBackwardEulerObjective::m_projection
btDeformableContactProjection m_projection
Definition: btDeformableBackwardEulerObjective.h:45
btDeformableBackwardEulerObjective::m_lf
btAlignedObjectArray< btDeformableLagrangianForce * > m_lf
Definition: btDeformableBackwardEulerObjective.h:42
btDeformableBackwardEulerObjective::m_massPreconditioner
MassPreconditioner * m_massPreconditioner
Definition: btDeformableBackwardEulerObjective.h:49
btDeformableBackwardEulerObjective::getIndices
const btAlignedObjectArray< btSoftBody::Node * > * getIndices() const
Definition: btDeformableBackwardEulerObjective.h:129
btDeformableBackwardEulerObjective::m_preconditioner
Preconditioner * m_preconditioner
Definition: btDeformableBackwardEulerObjective.h:44
btDeformableBackwardEulerObjective::KKT_preconditioner
@ KKT_preconditioner
Definition: btDeformableBackwardEulerObjective.h:37
btDeformableBackwardEulerObjective::Mass_preconditioner
@ Mass_preconditioner
Definition: btDeformableBackwardEulerObjective.h:36
btDeformableBackwardEulerObjective::m_KKTPreconditioner
KKTPreconditioner * m_KKTPreconditioner
Definition: btDeformableBackwardEulerObjective.h:50
btDeformableBodySolver
Definition: btDeformableBodySolver.h:31
btDeformableBodySolver::processCollision
virtual void processCollision(btSoftBody *softBody, btSoftBody *otherSoftBody)
Process a collision between two soft bodies.
Definition: btDeformableBodySolver.h:122
btDeformableBodySolver::m_ddv
TVStack m_ddv
Definition: btDeformableBodySolver.h:38
btDeformableBodySolver::updateSoftBodies
virtual void updateSoftBodies()
Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes.
Definition: btDeformableBodySolver.cpp:485
btDeformableBodySolver::btDeformableBodySolver
btDeformableBodySolver()
Definition: btDeformableBodySolver.cpp:22
btDeformableBodySolver::solveDeformableConstraints
virtual void solveDeformableConstraints(btScalar solverdt)
Definition: btDeformableBodySolver.cpp:34
btDeformableBodySolver::m_numNodes
int m_numNodes
Definition: btDeformableBodySolver.h:35
btDeformableBodySolver::updateEnergy
void updateEnergy(btScalar scale)
Definition: btDeformableBodySolver.cpp:157
btDeformableBodySolver::revertVelocity
void revertVelocity()
Definition: btDeformableBodySolver.cpp:362
btDeformableBodySolver::getSolverType
virtual SolverTypes getSolverType() const
Return the type of the solver.
Definition: btDeformableBodySolver.h:59
btDeformableBodySolver::checkInitialized
virtual bool checkInitialized()
Ensure that this solver is initialized.
Definition: btDeformableBodySolver.h:220
btDeformableBodySolver::setConstraints
virtual void setConstraints(const btContactSolverInfo &infoGlobal)
Definition: btDeformableBodySolver.cpp:251
btDeformableBodySolver::processCollision
virtual void processCollision(btSoftBody *softBody, const btCollisionObjectWrapper *collisionObjectWrap)
Definition: btDeformableBodySolver.h:116
btDeformableBodySolver::~btDeformableBodySolver
virtual ~btDeformableBodySolver()
Definition: btDeformableBodySolver.cpp:29
btDeformableBodySolver::m_objective
btDeformableBackwardEulerObjective * m_objective
Definition: btDeformableBodySolver.h:52
btDeformableBodySolver::updateNodes
bool updateNodes()
Definition: btDeformableBodySolver.cpp:375
btDeformableBodySolver::applyTransforms
virtual void applyTransforms(btScalar timeStep)
Definition: btDeformableBodySolver.cpp:514
btDeformableBodySolver::setStrainLimiting
virtual void setStrainLimiting(bool opt)
Definition: btDeformableBodySolver.h:167
btDeformableBodySolver::updateState
void updateState()
Definition: btDeformableBodySolver.cpp:200
btDeformableBodySolver::setPreconditioner
virtual void setPreconditioner(int opt)
Definition: btDeformableBodySolver.h:172
btDeformableBodySolver::setProjection
virtual void setProjection()
Definition: btDeformableBodySolver.h:200
btDeformableBodySolver::m_maxNewtonIterations
int m_maxNewtonIterations
Definition: btDeformableBodySolver.h:46
btDeformableBodySolver::computeDescentStep
btScalar computeDescentStep(TVStack &ddv, const TVStack &residual, bool verbose=false)
Definition: btDeformableBodySolver.cpp:166
btDeformableBodySolver::m_reducedSolver
bool m_reducedSolver
Definition: btDeformableBodySolver.h:49
btDeformableBodySolver::copyBackToSoftBodies
virtual void copyBackToSoftBodies(bool bMove=true)
Copy necessary data back to the original soft body source objects.
Definition: btDeformableBodySolver.h:221
btDeformableBodySolver::copySoftBodyToVertexBuffer
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
Definition: btDeformableBodySolver.h:113
btDeformableBodySolver::predictDeformableMotion
void predictDeformableMotion(btSoftBody *psb, btScalar dt)
Definition: btDeformableBodySolver.cpp:422
btDeformableBodySolver::optimize
virtual void optimize(btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate=false)
Optimize soft bodies in this solver.
Definition: btDeformableBodySolver.h:218
btDeformableBodySolver::m_cr
btConjugateResidual< btDeformableBackwardEulerObjective > m_cr
Definition: btDeformableBodySolver.h:44
btDeformableBodySolver::m_backup_dv
TVStack m_backup_dv
Definition: btDeformableBodySolver.h:37
btDeformableBodySolver::m_cg
btConjugateGradient< btDeformableBackwardEulerObjective > m_cg
Definition: btDeformableBodySolver.h:43
btDeformableBodySolver::backupVelocity
void backupVelocity()
Definition: btDeformableBodySolver.cpp:317
btDeformableBodySolver::getLagrangianForceArray
virtual btAlignedObjectArray< btDeformableLagrangianForce * > * getLagrangianForceArray()
Definition: btDeformableBodySolver.h:190
btDeformableBodySolver::m_dv
TVStack m_dv
Definition: btDeformableBodySolver.h:36
btDeformableBodySolver::revertDv
void revertDv()
Definition: btDeformableBodySolver.cpp:149
btDeformableBodySolver::reinitialize
virtual void reinitialize(const btAlignedObjectArray< btSoftBody * > &softBodies, btScalar dt)
Definition: btDeformableBodySolver.cpp:222
btDeformableBodySolver::setupDeformableSolve
virtual void setupDeformableSolve(bool implicit)
Definition: btDeformableBodySolver.cpp:330
btDeformableBodySolver::m_residual
TVStack m_residual
Definition: btDeformableBodySolver.h:39
btDeformableBodySolver::setLineSearch
void setLineSearch(bool lineSearch)
Definition: btDeformableBodySolver.cpp:504
btDeformableBodySolver::getIndices
virtual const btAlignedObjectArray< btSoftBody::Node * > * getIndices()
Definition: btDeformableBodySolver.h:195
btDeformableBodySolver::m_softBodies
btAlignedObjectArray< btSoftBody * > m_softBodies
Definition: btDeformableBodySolver.h:40
btDeformableBodySolver::isReducedSolver
virtual bool isReducedSolver()
Definition: btDeformableBodySolver.h:210
btDeformableBodySolver::solveContactConstraints
virtual btScalar solveContactConstraints(btCollisionObject **deformableBodies, int numDeformableBodies, const btContactSolverInfo &infoGlobal)
Definition: btDeformableBodySolver.cpp:257
btDeformableBodySolver::m_dt
btScalar m_dt
Definition: btDeformableBodySolver.h:42
btDeformableBodySolver::updateVelocity
void updateVelocity()
Definition: btDeformableBodySolver.cpp:264
btDeformableBodySolver::solveConstraints
virtual void solveConstraints(btScalar dt)
Solve constraints for a set of soft bodies.
Definition: btDeformableBodySolver.h:219
btDeformableBodySolver::kineticEnergy
btScalar kineticEnergy()
Definition: btDeformableBodySolver.cpp:122
btDeformableBodySolver::m_implicit
bool m_implicit
Definition: btDeformableBodySolver.h:45
btDeformableBodySolver::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition: btDeformableBodySolver.h:32
btDeformableBodySolver::m_useProjection
bool m_useProjection
Definition: btDeformableBodySolver.h:53
btDeformableBodySolver::m_newtonTolerance
btScalar m_newtonTolerance
Definition: btDeformableBodySolver.h:47
btDeformableBodySolver::predictMotion
virtual void predictMotion(btScalar solverdt)
Predict motion of soft bodies into next timestep.
Definition: btDeformableBodySolver.cpp:388
btDeformableBodySolver::m_lineSearch
bool m_lineSearch
Definition: btDeformableBodySolver.h:48
btDeformableBodySolver::backupDv
void backupDv()
Definition: btDeformableBodySolver.cpp:140
btDeformableBodySolver::setImplicit
void setImplicit(bool implicit)
Definition: btDeformableBodySolver.cpp:498
btDeformableBodySolver::computeStep
void computeStep(TVStack &ddv, const TVStack &residual)
Definition: btDeformableBodySolver.cpp:214
btDeformableBodySolver::setLagrangeMultiplier
virtual void setLagrangeMultiplier()
Definition: btDeformableBodySolver.h:205
btDeformableBodySolver::updateTempPosition
void updateTempPosition()
Definition: btDeformableBodySolver.cpp:297
btDeformableBodySolver::m_backupVelocity
TVStack m_backupVelocity
Definition: btDeformableBodySolver.h:41
btDeformableBodySolver::applyExplicitForce
virtual void applyExplicitForce()
Definition: btDeformableBodySolver.cpp:509
btDeformableBodySolver::setGravity
virtual void setGravity(const btVector3 &gravity)
Definition: btDeformableBodySolver.h:73
btDeformableBodySolver::deformableBodyInternalWriteBack
virtual void deformableBodyInternalWriteBack()
Definition: btDeformableBodySolver.h:215
btDeformableBodySolver::updateDv
void updateDv(btScalar scale=1)
Definition: btDeformableBodySolver.cpp:206
btDeformableContactProjection::setLagrangeMultiplier
virtual void setLagrangeMultiplier()
Definition: btDeformableContactProjection.cpp:460
btDeformableContactProjection::m_useStrainLimiting
bool m_useStrainLimiting
Definition: btDeformableContactProjection.h:65
btDeformableContactProjection::setProjection
virtual void setProjection()
Definition: btDeformableContactProjection.cpp:202
btSoftBodySolver
Definition: btSoftBodySolvers.h:29
btSoftBodySolver::SolverTypes
SolverTypes
Definition: btSoftBodySolvers.h:32
btSoftBodySolver::DEFORMABLE_SOLVER
@ DEFORMABLE_SOLVER
Definition: btSoftBodySolvers.h:39
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
btSoftBody::defaultCollisionHandler
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)
Definition: btSoftBody.cpp:4085
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVertexBufferDescriptor
Definition: btSoftBodySolverVertexBuffer.h:20
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:18
btContactSolverInfo
Definition: btContactSolverInfo.h:76