Bullet Collision Detection & Physics Library
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"
24#include "btConjugateResidual.h"
25#include "btConjugateGradient.h"
29
31{
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
41 TVStack m_backupVelocity; // backed up v, equals v_n for implicit, equals v_{n+1}^* for explicit
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
49public:
50 // handles data related to objective function
53
55
57
58 virtual SolverTypes getSolverType() const
59 {
60 return DEFORMABLE_SOLVER;
61 }
62
63 // update soft body normals
64 virtual void updateSoftBodies();
65
66 virtual btScalar solveContactConstraints(btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
67
68 // solve the momentum equation
69 virtual void solveDeformableConstraints(btScalar solverdt);
70
71 // resize/clear data structures
73
74 // set up contact constraints
75 void setConstraints(const btContactSolverInfo& infoGlobal);
76
77 // add in elastic forces and gravity to obtain v_{n+1}^* and calls predictDeformableMotion
78 virtual void predictMotion(btScalar solverdt);
79
80 // move to temporary position x_{n+1}^* = x_n + dt * v_{n+1}^*
81 // x_{n+1}^* is stored in m_q
83
84 // save the current velocity to m_backupVelocity
85 void backupVelocity();
86
87 // set m_dv and m_backupVelocity to desired value to prepare for momentum solve
88 void setupDeformableSolve(bool implicit);
89
90 // set the current velocity to that backed up in m_backupVelocity
91 void revertVelocity();
92
93 // set velocity to m_dv + m_backupVelocity
94 void updateVelocity();
95
96 // update the node count
97 bool updateNodes();
98
99 // calculate the change in dv resulting from the momentum solve
100 void computeStep(TVStack& ddv, const TVStack& residual);
101
102 // calculate the change in dv resulting from the momentum solve when line search is turned on
103 btScalar computeDescentStep(TVStack& ddv, const TVStack& residual, bool verbose = false);
104
105 virtual void copySoftBodyToVertexBuffer(const btSoftBody* const softBody, btVertexBufferDescriptor* vertexBuffer) {}
106
107 // process collision between deformable and rigid
108 virtual void processCollision(btSoftBody* softBody, const btCollisionObjectWrapper* collisionObjectWrap)
109 {
110 softBody->defaultCollisionHandler(collisionObjectWrap);
111 }
112
113 // process collision between deformable and deformable
114 virtual void processCollision(btSoftBody* softBody, btSoftBody* otherSoftBody)
115 {
116 softBody->defaultCollisionHandler(otherSoftBody);
117 }
118
119 // If true, implicit time stepping scheme is used.
120 // Otherwise, explicit time stepping scheme is used
121 void setImplicit(bool implicit);
122
123 // If true, newton's method with line search is used when implicit time stepping scheme is turned on
124 void setLineSearch(bool lineSearch);
125
126 // set temporary position x^* = x_n + dt * v
127 // update the deformation gradient at position x^*
128 void updateState();
129
130 // set dv = dv + scale * ddv
131 void updateDv(btScalar scale = 1);
132
133 // set temporary position x^* = x_n + dt * v^*
134 void updateTempPosition();
135
136 // save the current dv to m_backup_dv;
137 void backupDv();
138
139 // set dv to the backed-up value
140 void revertDv();
141
142 // set dv = dv + scale * ddv
143 // set v^* = v_n + dv
144 // set temporary position x^* = x_n + dt * v^*
145 // update the deformation gradient at position x^*
146 void updateEnergy(btScalar scale);
147
148 // calculates the appropriately scaled kinetic energy in the system, which is
149 // 1/2 * dv^T * M * dv
150 // used in line search
152
153 // unused functions
154 virtual void optimize(btAlignedObjectArray<btSoftBody*>& softBodies, bool forceUpdate = false) {}
155 virtual void solveConstraints(btScalar dt) {}
156 virtual bool checkInitialized() { return true; }
157 virtual void copyBackToSoftBodies(bool bMove = true) {}
158};
159
160#endif /* btDeformableBodySolver_h */
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btCollisionObject can be used to manage collision detection objects.
virtual void processCollision(btSoftBody *softBody, btSoftBody *otherSoftBody)
Process a collision between two soft bodies.
virtual void updateSoftBodies()
Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes.
virtual void solveDeformableConstraints(btScalar solverdt)
void updateEnergy(btScalar scale)
virtual SolverTypes getSolverType() const
Return the type of the solver.
virtual bool checkInitialized()
Ensure that this solver is initialized.
void setConstraints(const btContactSolverInfo &infoGlobal)
virtual void processCollision(btSoftBody *softBody, const btCollisionObjectWrapper *collisionObjectWrap)
btDeformableBackwardEulerObjective * m_objective
btScalar computeDescentStep(TVStack &ddv, const TVStack &residual, bool verbose=false)
virtual void copyBackToSoftBodies(bool bMove=true)
Copy necessary data back to the original soft body source objects.
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
void predictDeformableMotion(btSoftBody *psb, btScalar dt)
virtual void optimize(btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate=false)
Optimize soft bodies in this solver.
btConjugateResidual< btDeformableBackwardEulerObjective > m_cr
btConjugateGradient< btDeformableBackwardEulerObjective > m_cg
void reinitialize(const btAlignedObjectArray< btSoftBody * > &softBodies, btScalar dt)
void setupDeformableSolve(bool implicit)
void setLineSearch(bool lineSearch)
btAlignedObjectArray< btSoftBody * > m_softBodies
virtual btScalar solveContactConstraints(btCollisionObject **deformableBodies, int numDeformableBodies, const btContactSolverInfo &infoGlobal)
virtual void solveConstraints(btScalar dt)
Solve constraints for a set of soft bodies.
btAlignedObjectArray< btVector3 > TVStack
virtual void predictMotion(btScalar solverdt)
Predict motion of soft bodies into next timestep.
void computeStep(TVStack &ddv, const TVStack &residual)
void updateDv(btScalar scale=1)
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)