Blender  V3.3
btDeformableCorotatedForce.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_COROTATED_H
17 #define BT_COROTATED_H
18 
21 
22 static inline int PolarDecomposition(const btMatrix3x3& m, btMatrix3x3& q, btMatrix3x3& s)
23 {
24  static const btPolarDecomposition polar;
25  return polar.decompose(m, q, s);
26 }
27 
29 {
30 public:
34  {
35  }
36 
38  {
39  }
40 
41  virtual void addScaledForces(btScalar scale, TVStack& force)
42  {
43  addScaledElasticForce(scale, force);
44  }
45 
46  virtual void addScaledExplicitForce(btScalar scale, TVStack& force)
47  {
48  addScaledElasticForce(scale, force);
49  }
50 
51  virtual void addScaledDampingForce(btScalar scale, TVStack& force)
52  {
53  }
54 
55  virtual void addScaledElasticForce(btScalar scale, TVStack& force)
56  {
57  int numNodes = getNumNodes();
58  btAssert(numNodes <= force.size());
59  btVector3 grad_N_hat_1st_col = btVector3(-1, -1, -1);
60  for (int i = 0; i < m_softBodies.size(); ++i)
61  {
62  btSoftBody* psb = m_softBodies[i];
63  for (int j = 0; j < psb->m_tetras.size(); ++j)
64  {
65  btSoftBody::Tetra& tetra = psb->m_tetras[j];
66  btMatrix3x3 P;
67  firstPiola(tetra.m_F, P);
68  btVector3 force_on_node0 = P * (tetra.m_Dm_inverse.transpose() * grad_N_hat_1st_col);
69  btMatrix3x3 force_on_node123 = P * tetra.m_Dm_inverse.transpose();
70 
71  btSoftBody::Node* node0 = tetra.m_n[0];
72  btSoftBody::Node* node1 = tetra.m_n[1];
73  btSoftBody::Node* node2 = tetra.m_n[2];
74  btSoftBody::Node* node3 = tetra.m_n[3];
75  size_t id0 = node0->index;
76  size_t id1 = node1->index;
77  size_t id2 = node2->index;
78  size_t id3 = node3->index;
79 
80  // elastic force
81  // explicit elastic force
82  btScalar scale1 = scale * tetra.m_element_measure;
83  force[id0] -= scale1 * force_on_node0;
84  force[id1] -= scale1 * force_on_node123.getColumn(0);
85  force[id2] -= scale1 * force_on_node123.getColumn(1);
86  force[id3] -= scale1 * force_on_node123.getColumn(2);
87  }
88  }
89  }
90 
92  {
93  // btMatrix3x3 JFinvT = F.adjoint();
94  btScalar J = F.determinant();
95  P = F.adjoint().transpose() * (m_lambda * (J - 1));
96  if (m_mu > SIMD_EPSILON)
97  {
98  btMatrix3x3 R, S;
99  if (J < 1024 * SIMD_EPSILON)
100  R.setIdentity();
101  else
102  PolarDecomposition(F, R, S); // this QR is not robust, consider using implicit shift svd
103  /*https://fuchuyuan.github.io/research/svd/paper.pdf*/
104  P += (F - R) * 2 * m_mu;
105  }
106  }
107 
108  virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack& dx, TVStack& df)
109  {
110  }
111 
112  virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack& dv, TVStack& df)
113  {
114  }
115 
117 
119  {
120  return BT_COROTATED_FORCE;
121  }
122 };
123 
124 #endif /* btCorotated_h */
static int PolarDecomposition(const btMatrix3x3 &m, btMatrix3x3 &q, btMatrix3x3 &s)
btDeformableLagrangianForceType
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define SIMD_EPSILON
Definition: btScalar.h:543
#define btAssert(x)
Definition: btScalar.h:295
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
virtual void addScaledElasticForce(btScalar scale, TVStack &force)
virtual void buildDampingForceDifferentialDiagonal(btScalar scale, TVStack &diagA)
virtual void addScaledDampingForceDifferential(btScalar scale, const TVStack &dv, TVStack &df)
virtual btDeformableLagrangianForceType getForceType()
virtual void addScaledDampingForce(btScalar scale, TVStack &force)
btAlignedObjectArray< btVector3 > TVStack
virtual void addScaledForces(btScalar scale, TVStack &force)
void firstPiola(const btMatrix3x3 &F, btMatrix3x3 &P)
virtual void addScaledElasticForceDifferential(btScalar scale, const TVStack &dx, TVStack &df)
virtual void addScaledExplicitForce(btScalar scale, TVStack &force)
btDeformableCorotatedForce(btScalar mu, btScalar lambda)
btAlignedObjectArray< btSoftBody * > m_softBodies
unsigned int decompose(const btMatrix3x3 &a, btMatrix3x3 &u, btMatrix3x3 &h) const
tTetraArray m_tetras
Definition: btSoftBody.h:804
static float P(float k)
Definition: math_interp.c:25
#define F
#define R
btScalar m_element_measure
Definition: btSoftBody.h:315
btMatrix3x3 m_Dm_inverse
Definition: btSoftBody.h:313
btMatrix3x3 m_F
Definition: btSoftBody.h:314