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

Bullet Collision Detection & Physics Library

btDeformableBackwardEulerObjective.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_BACKWARD_EULER_OBJECTIVE_H
17 #define BT_BACKWARD_EULER_OBJECTIVE_H
18 #include "btConjugateGradient.h"
19 #include "btDeformableLagrangianForce.h"
20 #include "btDeformableMassSpringForce.h"
21 #include "btDeformableGravityForce.h"
22 #include "btDeformableCorotatedForce.h"
23 #include "btDeformableLinearElasticityForce.h"
24 #include "btDeformableNeoHookeanForce.h"
25 #include "btDeformableContactProjection.h"
26 #include "btPreconditioner.h"
27 #include "btDeformableMultiBodyDynamicsWorld.h"
28 #include "LinearMath/btQuickprof.h"
29
30 class btDeformableBackwardEulerObjective
31 {
32 public:
33 typedef btAlignedObjectArray<btVector3> TVStack;
34 btScalar m_dt;
35 btAlignedObjectArray<btDeformableLagrangianForce*> m_lf;
36 btAlignedObjectArray<btSoftBody *>& m_softBodies;
37 Preconditioner* m_preconditioner;
38 btDeformableContactProjection m_projection;
39 const TVStack& m_backupVelocity;
40 btAlignedObjectArray<btSoftBody::Node* > m_nodes;
41 bool m_implicit;
42
43 btDeformableBackwardEulerObjective(btAlignedObjectArray<btSoftBody *>& softBodies, const TVStack& backup_v);
44
45 virtual ~btDeformableBackwardEulerObjective();
46
47 void initialize(){}
48
49 // compute the rhs for CG solve, i.e, add the dt scaled implicit force to residual
50 void computeResidual(btScalar dt, TVStack& residual);
51
52 // add explicit force to the velocity
53 void applyExplicitForce(TVStack& force);
54
55 // apply force to velocity and optionally reset the force to zero
56 void applyForce(TVStack& force, bool setZero);
57
58 // compute the norm of the residual
59 btScalar computeNorm(const TVStack& residual) const;
60
61 // compute one step of the solve (there is only one solve if the system is linear)
62 void computeStep(TVStack& dv, const TVStack& residual, const btScalar& dt);
63
64 // perform A*x = b
65 void multiply(const TVStack& x, TVStack& b) const;
66
67 // set initial guess for CG solve
68 void initialGuess(TVStack& dv, const TVStack& residual);
69
70 // reset data structure and reset dt
71 void reinitialize(bool nodeUpdated, btScalar dt);
72
73 void setDt(btScalar dt);
74
75 // add friction force to residual
76 void applyDynamicFriction(TVStack& r);
77
78 // add dv to velocity
79 void updateVelocity(const TVStack& dv);
80
81 //set constraints as projections
82 void setConstraints();
83
84 // update the projections and project the residual
85 void project(TVStack& r)
86 {
87 BT_PROFILE("project");
88 m_projection.project(r);
89 }
90
91 // perform precondition M^(-1) x = b
92 void precondition(const TVStack& x, TVStack& b)
93 {
94 m_preconditioner->operator()(x,b);
95 }
96
97 // reindex all the vertices
98 virtual void updateId()
99 {
100 size_t node_id = 0;
101 size_t face_id = 0;
102 m_nodes.clear();
103 for (int i = 0; i < m_softBodies.size(); ++i)
104 {
105 btSoftBody* psb = m_softBodies[i];
106 for (int j = 0; j < psb->m_nodes.size(); ++j)
107 {
108 psb->m_nodes[j].index = node_id;
109 m_nodes.push_back(&psb->m_nodes[j]);
110 ++node_id;
111 }
112 for (int j = 0; j < psb->m_faces.size(); ++j)
113 {
114 psb->m_faces[j].m_index = face_id;
115 ++face_id;
116 }
117 }
118 }
119
120 const btAlignedObjectArray<btSoftBody::Node*>* getIndices() const
121 {
122 return &m_nodes;
123 }
124
125 void setImplicit(bool implicit)
126 {
127 m_implicit = implicit;
128 }
129
130 // Calculate the total potential energy in the system
131 btScalar totalEnergy(btScalar dt);
132 };
133
134 #endif /* btBackwardEulerObjective_h */
Preconditioner
Definition: btPreconditioner.h:20
btDeformableBackwardEulerObjective::precondition
void precondition(const TVStack &x, TVStack &b)
Definition: btDeformableBackwardEulerObjective.h:92
btDeformableBackwardEulerObjective::m_lf
btAlignedObjectArray< btDeformableLagrangianForce * > m_lf
Definition: btDeformableBackwardEulerObjective.h:35
btDeformableBackwardEulerObjective::getIndices
const btAlignedObjectArray< btSoftBody::Node * > * getIndices() const
Definition: btDeformableBackwardEulerObjective.h:120
btConjugateGradient.h
btDeformableMassSpringForce.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btDeformableBackwardEulerObjective::setDt
void setDt(btScalar dt)
Definition: btDeformableBackwardEulerObjective.cpp:53
btDeformableBackwardEulerObjective::applyForce
void applyForce(TVStack &force, bool setZero)
Definition: btDeformableBackwardEulerObjective.cpp:98
btDeformableContactProjection
Definition: btDeformableContactProjection.h:26
btDeformableBackwardEulerObjective::m_implicit
bool m_implicit
Definition: btDeformableBackwardEulerObjective.h:41
btAlignedObjectArray::clear
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
Definition: btAlignedObjectArray.h:176
btDeformableBackwardEulerObjective::m_projection
btDeformableContactProjection m_projection
Definition: btDeformableBackwardEulerObjective.h:38
btDeformableBackwardEulerObjective::btDeformableBackwardEulerObjective
btDeformableBackwardEulerObjective(btAlignedObjectArray< btSoftBody * > &softBodies, const TVStack &backup_v)
Definition: btDeformableBackwardEulerObjective.cpp:20
btSoftBody::m_faces
tFaceArray m_faces
Definition: btSoftBody.h:780
btDeformableBackwardEulerObjective::m_dt
btScalar m_dt
Definition: btDeformableBackwardEulerObjective.h:34
btDeformableBackwardEulerObjective::reinitialize
void reinitialize(bool nodeUpdated, btScalar dt)
Definition: btDeformableBackwardEulerObjective.cpp:34
btDeformableBackwardEulerObjective::m_preconditioner
Preconditioner * m_preconditioner
Definition: btDeformableBackwardEulerObjective.h:37
btDeformableBackwardEulerObjective::setConstraints
void setConstraints()
Definition: btDeformableBackwardEulerObjective.cpp:189
btDeformableBackwardEulerObjective
Definition: btDeformableBackwardEulerObjective.h:31
btDeformableBackwardEulerObjective::applyDynamicFriction
void applyDynamicFriction(TVStack &r)
Definition: btDeformableBackwardEulerObjective.cpp:194
btDeformableBackwardEulerObjective::m_nodes
btAlignedObjectArray< btSoftBody::Node * > m_nodes
Definition: btDeformableBackwardEulerObjective.h:40
btDeformableBackwardEulerObjective::updateId
virtual void updateId()
Definition: btDeformableBackwardEulerObjective.h:98
btDeformableBackwardEulerObjective::updateVelocity
void updateVelocity(const TVStack &dv)
Definition: btDeformableBackwardEulerObjective.cpp:85
btDeformableBackwardEulerObjective::computeResidual
void computeResidual(btScalar dt, TVStack &residual)
Definition: btDeformableBackwardEulerObjective.cpp:122
btDeformableLinearElasticityForce.h
btDeformableMultiBodyDynamicsWorld.h
btDeformableBackwardEulerObjective::setImplicit
void setImplicit(bool implicit)
Definition: btDeformableBackwardEulerObjective.h:125
btDeformableBackwardEulerObjective::computeNorm
btScalar computeNorm(const TVStack &residual) const
Definition: btDeformableBackwardEulerObjective.cpp:140
btDeformableBackwardEulerObjective::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition: btDeformableBackwardEulerObjective.h:33
btDeformableContactProjection::project
virtual void project(TVStack &x)
Definition: btDeformableContactProjection.cpp:206
btDeformableBackwardEulerObjective::initialGuess
void initialGuess(TVStack &dv, const TVStack &residual)
Definition: btDeformableBackwardEulerObjective.cpp:174
btAlignedObjectArray< btVector3 >
btDeformableBackwardEulerObjective::~btDeformableBackwardEulerObjective
virtual ~btDeformableBackwardEulerObjective()
Definition: btDeformableBackwardEulerObjective.cpp:29
btDeformableBackwardEulerObjective::multiply
void multiply(const TVStack &x, TVStack &b) const
Definition: btDeformableBackwardEulerObjective.cpp:58
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:73
btDeformableBackwardEulerObjective::totalEnergy
btScalar totalEnergy(btScalar dt)
Definition: btDeformableBackwardEulerObjective.cpp:150
btDeformableBackwardEulerObjective::m_backupVelocity
const TVStack & m_backupVelocity
Definition: btDeformableBackwardEulerObjective.h:39
btQuickprof.h
btDeformableBackwardEulerObjective::m_softBodies
btAlignedObjectArray< btSoftBody * > & m_softBodies
Definition: btDeformableBackwardEulerObjective.h:36
btDeformableContactProjection.h
btDeformableBackwardEulerObjective::computeStep
void computeStep(TVStack &dv, const TVStack &residual, const btScalar &dt)
btDeformableBackwardEulerObjective::applyExplicitForce
void applyExplicitForce(TVStack &force)
Definition: btDeformableBackwardEulerObjective.cpp:160
btDeformableNeoHookeanForce.h
btDeformableGravityForce.h
btDeformableBackwardEulerObjective::project
void project(TVStack &r)
Definition: btDeformableBackwardEulerObjective.h:85
btAlignedObjectArray::push_back
void push_back(const T &_Val)
Definition: btAlignedObjectArray.h:257
btDeformableBackwardEulerObjective::initialize
void initialize()
Definition: btDeformableBackwardEulerObjective.h:47
btDeformableLagrangianForce.h
btPreconditioner.h
BT_PROFILE
#define BT_PROFILE(name)
Definition: btQuickprof.h:198
btDeformableCorotatedForce.h
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:142
btSoftBody::m_nodes
tNodeArray m_nodes
Definition: btSoftBody.h:777