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 */
Preconditioner
Definition: btPreconditioner.h:19
MassPreconditioner::MassPreconditioner
MassPreconditioner(const btAlignedObjectArray< btSoftBody * > &softBodies)
Definition: btPreconditioner.h:49
Preconditioner::reinitialize
virtual void reinitialize(bool nodeUpdated)=0
MassPreconditioner::operator()
virtual void operator()(const TVStack &x, TVStack &b)
Definition: btPreconditioner.h:68
Preconditioner::operator()
virtual void operator()(const TVStack &x, TVStack &b)=0
btAlignedObjectArray::clear
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
Definition: btAlignedObjectArray.h:176
Preconditioner::~Preconditioner
virtual ~Preconditioner()
Definition: btPreconditioner.h:25
btAssert
#define btAssert(x)
Definition: btScalar.h:153
MassPreconditioner::m_inv_mass
btAlignedObjectArray< btScalar > m_inv_mass
Definition: btPreconditioner.h:46
MassPreconditioner::m_softBodies
const btAlignedObjectArray< btSoftBody * > & m_softBodies
Definition: btPreconditioner.h:47
DefaultPreconditioner::reinitialize
virtual void reinitialize(bool nodeUpdated)
Definition: btPreconditioner.h:37
DefaultPreconditioner::~DefaultPreconditioner
virtual ~DefaultPreconditioner()
Definition: btPreconditioner.h:41
Preconditioner::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition: btPreconditioner.h:22
btAlignedObjectArray< btVector3 >
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:72
MassPreconditioner
Definition: btPreconditioner.h:44
MassPreconditioner::reinitialize
virtual void reinitialize(bool nodeUpdated)
Definition: btPreconditioner.h:54
btAlignedObjectArray::push_back
void push_back(const T &_Val)
Definition: btAlignedObjectArray.h:257
DefaultPreconditioner::operator()
virtual void operator()(const TVStack &x, TVStack &b)
Definition: btPreconditioner.h:31
DefaultPreconditioner
Definition: btPreconditioner.h:28
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