Bullet Collision Detection & Physics Library
btPreconditioner.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_PRECONDITIONER_H
17 #define BT_PRECONDITIONER_H
18 
20 {
21 public:
23  virtual void operator()(const TVStack& x, TVStack& b) = 0;
24  virtual void reinitialize(bool nodeUpdated) = 0;
25  virtual ~Preconditioner(){}
26 };
27 
29 {
30 public:
31  virtual void operator()(const TVStack& x, TVStack& b)
32  {
33  btAssert(b.size() == x.size());
34  for (int i = 0; i < b.size(); ++i)
35  b[i] = x[i];
36  }
37  virtual void reinitialize(bool nodeUpdated)
38  {
39  }
40 
42 };
43 
45 {
48 public:
50  : m_softBodies(softBodies)
51  {
52  }
53 
54  virtual void reinitialize(bool nodeUpdated)
55  {
56  if (nodeUpdated)
57  {
58  m_inv_mass.clear();
59  for (int i = 0; i < m_softBodies.size(); ++i)
60  {
61  btSoftBody* psb = m_softBodies[i];
62  for (int j = 0; j < psb->m_nodes.size(); ++j)
63  m_inv_mass.push_back(psb->m_nodes[j].m_im);
64  }
65  }
66  }
67 
68  virtual void operator()(const TVStack& x, TVStack& b)
69  {
70  btAssert(b.size() == x.size());
71  btAssert(m_inv_mass.size() == x.size());
72  for (int i = 0; i < b.size(); ++i)
73  {
74  b[i] = x[i] * m_inv_mass[i];
75  }
76  }
77 };
78 
79 #endif /* BT_PRECONDITIONER_H */
#define btAssert(x)
Definition: btScalar.h:153
virtual void operator()(const TVStack &x, TVStack &b)
virtual void reinitialize(bool nodeUpdated)
virtual ~DefaultPreconditioner()
virtual void reinitialize(bool nodeUpdated)
MassPreconditioner(const btAlignedObjectArray< btSoftBody * > &softBodies)
virtual void operator()(const TVStack &x, TVStack &b)
btAlignedObjectArray< btScalar > m_inv_mass
const btAlignedObjectArray< btSoftBody * > & m_softBodies
virtual void reinitialize(bool nodeUpdated)=0
btAlignedObjectArray< btVector3 > TVStack
virtual ~Preconditioner()
virtual void operator()(const TVStack &x, TVStack &b)=0
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)
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:73
tNodeArray m_nodes
Definition: btSoftBody.h:777