Bullet Collision Detection & Physics Library
btReducedDeformableBodySolver.cpp
Go to the documentation of this file.
3
5{
6 m_ascendOrder = true;
7 m_reducedSolver = true;
10 m_gravity = btVector3(0, 0, 0);
11}
12
14{
16}
17
19{
21 bool nodeUpdated = updateNodes();
22
23 if (nodeUpdated)
24 {
29 }
30
31 // need to setZero here as resize only set value for newly allocated items
32 for (int i = 0; i < m_numNodes; ++i)
33 {
34 m_dv[i].setZero();
35 m_ddv[i].setZero();
36 m_residual[i].setZero();
37 }
38
39 if (dt > 0)
40 {
41 m_dt = dt;
42 }
44
45 int N = bodies.size();
46 if (nodeUpdated)
47 {
50 // m_faceRigidConstraints.resize(N);
51 }
52 for (int i = 0; i < N; ++i)
53 {
56 // m_faceRigidConstraints[i].clear();
57 }
58
59 for (int i = 0; i < m_softBodies.size(); ++i)
60 {
63 }
64
65 // set node index offsets
66 int sum = 0;
67 for (int i = 0; i < m_softBodies.size(); ++i)
68 {
71 sum += rsb->m_nodes.size();
72 }
73
75}
76
78{
80
81 // predict new mesh location
83
84 //TODO: check if there is anything missed from btDeformableBodySolver::predictDeformableMotion
85}
86
88{
89 for (int i = 0; i < m_softBodies.size(); ++i)
90 {
92 if (!rsb->isActive())
93 {
94 continue;
95 }
96
97 // clear contacts variables
98 rsb->m_nodeRigidContacts.resize(0);
99 rsb->m_faceRigidContacts.resize(0);
100 rsb->m_faceNodeContacts.resize(0);
101
102 // calculate inverse mass matrix for all nodes
103 for (int j = 0; j < rsb->m_nodes.size(); ++j)
104 {
105 if (rsb->m_nodes[j].m_im > 0)
106 {
107 rsb->m_nodes[j].m_effectiveMass_inv = rsb->m_nodes[j].m_effectiveMass.inverse();
108 }
109 }
110
111 // rigid motion: t, R at time^*
112 rsb->predictIntegratedTransform(solverdt, rsb->getInterpolationWorldTransform());
113
114 // update reduced dofs at time^*
115 // rsb->updateReducedDofs(solverdt);
116
117 // update local moment arm at time^*
118 // rsb->updateLocalMomentArm();
119 // rsb->updateExternalForceProjectMatrix(true);
120
121 // predict full space velocity at time^* (needed for constraints)
122 rsb->mapToFullVelocity(rsb->getInterpolationWorldTransform());
123
124 // update full space nodal position at time^*
125 rsb->mapToFullPosition(rsb->getInterpolationWorldTransform());
126
127 // update bounding box
128 rsb->updateBounds();
129
130 // update tree
131 rsb->updateNodeTree(true, true);
132 if (!rsb->m_fdbvt.empty())
133 {
134 rsb->updateFaceTree(true, true);
135 }
136 }
137}
138
140{
141 for (int i = 0; i < m_softBodies.size(); ++i)
142 {
144
145 // apply gravity to the rigid frame, get m_linearVelocity at time^*
147
148 if (!rsb->isReducedModesOFF())
149 {
150 // add internal force (elastic force & damping force)
151 rsb->applyReducedElasticForce(rsb->m_reducedDofsBuffer);
152 rsb->applyReducedDampingForce(rsb->m_reducedVelocityBuffer);
153
154 // get reduced velocity at time^*
155 rsb->updateReducedVelocity(solverdt);
156 }
157
158 // apply damping (no need at this point)
159 // rsb->applyDamping(solverdt);
160 }
161}
162
164{
165 for (int i = 0; i < m_softBodies.size(); ++i)
166 {
168
169 // rigid motion
170 rsb->proceedToTransform(timeStep, true);
171
172 if (!rsb->isReducedModesOFF())
173 {
174 // update reduced dofs for time^n+1
175 rsb->updateReducedDofs(timeStep);
176
177 // update local moment arm for time^n+1
178 rsb->updateLocalMomentArm();
179 rsb->updateExternalForceProjectMatrix(true);
180 }
181
182 // update mesh nodal positions for time^n+1
183 rsb->mapToFullPosition(rsb->getRigidTransform());
184
185 // update mesh nodal velocity
186 rsb->mapToFullVelocity(rsb->getRigidTransform());
187
188 // end of time step clean up and update
189 rsb->endOfTimeStepZeroing();
190
191 // update the rendering mesh
192 rsb->interpolateRenderMesh();
193 }
194}
195
197{
198 for (int i = 0; i < m_softBodies.size(); ++i)
199 {
201 if (!rsb->isActive())
202 {
203 continue;
204 }
205
206 // set fixed constraints
207 for (int j = 0; j < rsb->m_fixedNodes.size(); ++j)
208 {
209 int i_node = rsb->m_fixedNodes[j];
210 if (rsb->m_nodes[i_node].m_im == 0)
211 {
212 for (int k = 0; k < 3; ++k)
213 {
214 btVector3 dir(0, 0, 0);
215 dir[k] = 1;
218 }
219 }
220 }
221 btAssert(rsb->m_fixedNodes.size() * 3 == m_staticConstraints[i].size());
222
223 // set Deformable Node vs. Rigid constraint
224 for (int j = 0; j < rsb->m_nodeRigidContacts.size(); ++j)
225 {
226 const btSoftBody::DeformableNodeRigidContact& contact = rsb->m_nodeRigidContacts[j];
227 // skip fixed points
228 if (contact.m_node->m_im == 0)
229 {
230 continue;
231 }
234 rsb->m_contactNodesList.push_back(contact.m_node->index - rsb->m_nodeIndexOffset);
235 }
236 // std::cout << "contact node list size: " << rsb->m_contactNodesList.size() << "\n";
237 // std::cout << "#contact nodes: " << m_nodeRigidConstraints[i].size() << "\n";
238
239 }
240}
241
243{
245
246 for (int i = 0; i < m_softBodies.size(); ++i)
247 {
248 btAlignedObjectArray<int> m_orderNonContactConstraintPool;
250
252
253 // shuffle the order of applying constraint
254 m_orderNonContactConstraintPool.resize(m_staticConstraints[i].size());
256 if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER)
257 {
258 // fixed constraint order
259 for (int j = 0; j < m_staticConstraints[i].size(); ++j)
260 {
261 m_orderNonContactConstraintPool[j] = m_ascendOrder ? j : m_staticConstraints[i].size() - 1 - j;
262 }
263 // contact constraint order
264 for (int j = 0; j < m_nodeRigidConstraints[i].size(); ++j)
265 {
267 }
268
270 }
271 else
272 {
273 for (int j = 0; j < m_staticConstraints[i].size(); ++j)
274 {
275 m_orderNonContactConstraintPool[j] = j;
276 }
277 // contact constraint order
278 for (int j = 0; j < m_nodeRigidConstraints[i].size(); ++j)
279 {
281 }
282 }
283
284 // handle fixed constraint
285 for (int k = 0; k < m_staticConstraints[i].size(); ++k)
286 {
287 btReducedDeformableStaticConstraint& constraint = m_staticConstraints[i][m_orderNonContactConstraintPool[k]];
290 }
291
292 // handle contact constraint
293
294 // node vs rigid contact
295 // std::cout << "!!#contact_nodes: " << m_nodeRigidConstraints[i].size() << '\n';
296 for (int k = 0; k < m_nodeRigidConstraints[i].size(); ++k)
297 {
301 }
302
303 // face vs rigid contact
304 // for (int k = 0; k < m_faceRigidConstraints[i].size(); ++k)
305 // {
306 // btReducedDeformableFaceRigidContactConstraint& constraint = m_faceRigidConstraints[i][k];
307 // btScalar localResidualSquare = constraint.solveConstraint(infoGlobal);
308 // residualSquare = btMax(residualSquare, localResidualSquare);
309 // }
310 }
311
312
313 return residualSquare;
314}
315
317{
318 // reduced deformable update
319 for (int i = 0; i < m_softBodies.size(); ++i)
320 {
323 }
324 m_ascendOrder = true;
325}
@ SOLVER_RANDMIZE_ORDER
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define btAssert(x)
Definition btScalar.h:153
static T sum(const btAlignedObjectArray< T > &items)
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int size() const
return the number of elements in the array
void copyFromArray(const btAlignedObjectArray &otherArray)
void resize(int newsize, const T &fillData=T())
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void push_back(const T &_Val)
btCollisionObject can be used to manage collision detection objects.
virtual void updateSoftBodies()
Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes.
btDeformableBackwardEulerObjective * m_objective
btAlignedObjectArray< btSoftBody * > m_softBodies
virtual void predictMotion(btScalar solverdt)
Predict motion of soft bodies into next timestep.
virtual btScalar solveContactConstraints(btCollisionObject **deformableBodies, int numDeformableBodies, const btContactSolverInfo &infoGlobal)
virtual void setConstraints(const btContactSolverInfo &infoGlobal)
virtual void setGravity(const btVector3 &gravity)
btAlignedObjectArray< btAlignedObjectArray< btReducedDeformableNodeRigidContactConstraint > > m_nodeRigidConstraints
virtual void reinitialize(const btAlignedObjectArray< btSoftBody * > &bodies, btScalar dt)
btAlignedObjectArray< btAlignedObjectArray< btReducedDeformableStaticConstraint > > m_staticConstraints
virtual void applyTransforms(btScalar timeStep)
void predictReduceDeformableMotion(btScalar solverdt)
btAlignedObjectArray< int > m_fixedNodes
void applyRigidGravity(const btVector3 &gravity, btScalar dt)
void proceedToTransform(btScalar dt, bool end_of_time_step)
btAlignedObjectArray< int > m_contactNodesList
btAlignedObjectArray< DeformableNodeRigidContact > m_nodeRigidContacts
Definition btSoftBody.h:825
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82