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"
26#include "btPreconditioner.h"
29
31{
32public:
42
44
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
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
86 {
87 BT_PROFILE("project");
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
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
132};
133
134#endif /* btBackwardEulerObjective_h */
#define BT_PROFILE(name)
Definition: btQuickprof.h:198
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
int size() const
return the number of elements in the array
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void push_back(const T &_Val)
btDeformableBackwardEulerObjective(btAlignedObjectArray< btSoftBody * > &softBodies, const TVStack &backup_v)
void precondition(const TVStack &x, TVStack &b)
void computeResidual(btScalar dt, TVStack &residual)
btAlignedObjectArray< btDeformableLagrangianForce * > m_lf
void computeStep(TVStack &dv, const TVStack &residual, const btScalar &dt)
const btAlignedObjectArray< btSoftBody::Node * > * getIndices() const
void initialGuess(TVStack &dv, const TVStack &residual)
btScalar computeNorm(const TVStack &residual) const
void multiply(const TVStack &x, TVStack &b) const
btAlignedObjectArray< btSoftBody * > & m_softBodies
void reinitialize(bool nodeUpdated, btScalar dt)
btAlignedObjectArray< btSoftBody::Node * > m_nodes
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:73
tFaceArray m_faces
Definition: btSoftBody.h:780
tNodeArray m_nodes
Definition: btSoftBody.h:777