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{
15 m_gravity = gravity;
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 }
43 m_objective->reinitialize(nodeUpdated, dt);
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{
79 applyExplicitForce(solverdt);
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^*
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)
123
124 // update full space nodal position at time^*
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^*
146 rsb->applyRigidGravity(m_gravity, solverdt);
147
148 if (!rsb->isReducedModesOFF())
149 {
150 // add internal force (elastic force & damping force)
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
180 }
181
182 // update mesh nodal positions for time^n+1
184
185 // update mesh nodal velocity
187
188 // end of time step clean up and update
190
191 // update the rendering mesh
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;
216 btReducedDeformableStaticConstraint static_constraint(rsb, &rsb->m_nodes[i_node], rsb->getRelativePos(i_node), rsb->m_x0[i_node], dir, infoGlobal, m_dt);
217 m_staticConstraints[i].push_back(static_constraint);
218 }
219 }
220 }
222
223 // set Deformable Node vs. Rigid constraint
224 for (int j = 0; j < rsb->m_nodeRigidContacts.size(); ++j)
225 {
227 // skip fixed points
228 if (contact.m_node->m_im == 0)
229 {
230 continue;
231 }
232 btReducedDeformableNodeRigidContactConstraint constraint(rsb, contact, infoGlobal, m_dt);
233 m_nodeRigidConstraints[i].push_back(constraint);
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{
244 btScalar residualSquare = 0;
245
246 for (int i = 0; i < m_softBodies.size(); ++i)
247 {
248 btAlignedObjectArray<int> m_orderNonContactConstraintPool;
249 btAlignedObjectArray<int> m_orderContactConstraintPool;
250
252
253 // shuffle the order of applying constraint
254 m_orderNonContactConstraintPool.resize(m_staticConstraints[i].size());
255 m_orderContactConstraintPool.resize(m_nodeRigidConstraints[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 {
266 m_orderContactConstraintPool[j] = m_ascendOrder ? j : m_nodeRigidConstraints[i].size() - 1 - j;
267 }
268
269 m_ascendOrder = m_ascendOrder ? false : true;
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 {
280 m_orderContactConstraintPool[j] = j;
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]];
288 btScalar localResidualSquare = constraint.solveConstraint(infoGlobal);
289 residualSquare = btMax(residualSquare, localResidualSquare);
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 {
298 btReducedDeformableNodeRigidContactConstraint& constraint = m_nodeRigidConstraints[i][m_orderContactConstraintPool[k]];
299 btScalar localResidualSquare = constraint.solveConstraint(infoGlobal);
300 residualSquare = btMax(residualSquare, localResidualSquare);
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)
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.
const btTransform & getInterpolationWorldTransform() const
void reinitialize(bool nodeUpdated, btScalar dt)
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)
void predictIntegratedTransform(btScalar dt, btTransform &predictedTransform)
btVector3 getRelativePos(int n_node)
btAlignedObjectArray< int > m_fixedNodes
void mapToFullVelocity(const btTransform &ref_trans)
void updateReducedVelocity(btScalar solverdt)
void updateExternalForceProjectMatrix(bool initialized)
void applyReducedElasticForce(const tDenseArray &reduce_dofs)
void applyReducedDampingForce(const tDenseArray &reduce_vel)
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 btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
virtual btScalar solveConstraint(const btContactSolverInfo &infoGlobal)
void interpolateRenderMesh()
void updateFaceTree(bool use_velocity, bool margin)
Definition: btSoftBody.h:1300
void updateNodeTree(bool use_velocity, bool margin)
Definition: btSoftBody.h:1257
btAlignedObjectArray< DeformableFaceNodeContact > m_faceNodeContacts
Definition: btSoftBody.h:826
btAlignedObjectArray< DeformableFaceRigidContact > m_faceRigidContacts
Definition: btSoftBody.h:827
btAlignedObjectArray< DeformableNodeRigidContact > m_nodeRigidContacts
Definition: btSoftBody.h:825
btDbvt m_fdbvt
Definition: btSoftBody.h:836
tNodeArray m_nodes
Definition: btSoftBody.h:814
void updateBounds()
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
bool empty() const
Definition: btDbvt.h:314