1 |
tim |
1232 |
#ifndef _RATTLE_H_
|
2 |
|
|
#define _RATTLE_H_ |
3 |
|
|
|
4 |
|
|
#include "Shake.hpp" |
5 |
|
|
#include "ConstraintPair.hpp"
|
6 |
|
|
|
7 |
|
|
//Rattle Constraint Algorithn
|
8 |
|
|
//Reference
|
9 |
|
|
//H.C. Andersen, J. Comput. Phys. 54, 24(1983)
|
10 |
|
|
|
11 |
tim |
1254 |
class DCRattleAFunctor : public CallbackFunctor{
|
12 |
|
|
public: |
13 |
|
|
DCRattleAFunctor(SimInfo* rhs) : CallbackFunctor(rhs){}
|
14 |
|
|
protected: |
15 |
|
|
virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); |
16 |
|
|
virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); |
17 |
|
|
virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2);
|
18 |
|
|
}; |
19 |
|
|
|
20 |
|
|
class JCRattleAFunctor : public CallbackFunctor{
|
21 |
|
|
public: |
22 |
|
|
JCRattleAFunctor(SimInfo* rhs) : CallbackFunctor(rhs){}
|
23 |
|
|
protected: |
24 |
|
|
virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); |
25 |
|
|
virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); |
26 |
|
|
virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2); |
27 |
|
|
}; |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
//SHAKE constraint algorithm |
31 |
|
|
//Reference: |
32 |
|
|
//[1] J.P. Ryckaert, G.Ciccotti and H.J.C. Berendsen, J. Comput. Phys., 23, 327 (1977) |
33 |
|
|
//[2] |
34 |
|
|
//[3] |
35 |
|
|
class RattleA : public ConstraintAlgorithm{
|
36 |
|
|
public: |
37 |
|
|
RattleA(SimInfo* rhs) : ConstraintAlgorithm(rhs){
|
38 |
|
|
registerCallback(typeid(DistanceConstraintPair), new DCRattleAFunctor(rhs));
|
39 |
|
|
registerCallback(typeid(JointConstraintPair), new JCRattleAFunctor(rhs));
|
40 |
|
|
} |
41 |
|
|
};
|
42 |
|
|
|
43 |
tim |
1232 |
////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
//Declaration of DCRattleBFunctor
|
45 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
class DCRattleBFunctor : public CallbackFunctor{
|
47 |
|
|
public:
|
48 |
|
|
DCRattleBFunctor(SimInfo* rhs) : CallbackFunctor(rhs){}
|
49 |
|
|
protected:
|
50 |
|
|
virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2);
|
51 |
|
|
virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB);
|
52 |
|
|
virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2);
|
53 |
|
|
}; |
54 |
|
|
|
55 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
//Declaration of JCRattleBFunctor
|
57 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
class JCRattleBFunctor : public CallbackFunctor{
|
59 |
|
|
public:
|
60 |
|
|
JCRattleBFunctor(SimInfo* rhs) : CallbackFunctor(rhs){}
|
61 |
|
|
protected:
|
62 |
|
|
virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2);
|
63 |
|
|
virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB);
|
64 |
|
|
virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2);
|
65 |
|
|
};
|
66 |
|
|
|
67 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
//Declaration of RattleB
|
69 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
class RattleB : public ConstraintAlgorithm{ |
71 |
|
|
public:
|
72 |
|
|
RattleB(SimInfo* rhs) : ConstraintAlgorithm(rhs){
|
73 |
|
|
registerCallback(typeid(DistanceConstraintPair), new DCRattleBFunctor(rhs));
|
74 |
|
|
registerCallback(typeid(JointConstraintPair), new JCRattleBFunctor(rhs));
|
75 |
|
|
}
|
76 |
|
|
};
|
77 |
|
|
|
78 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
//Declaration of RattleAlgorithm
|
80 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
//class RattleAlgorithm will encapsulate preConstraint, RattleA and RattleB
|
82 |
tim |
1254 |
//actually, we could use factory pattern to seperate the creation process
|
83 |
tim |
1268 |
class RattleFramework : public VelVerletConsFramework{
|
84 |
tim |
1232 |
public:
|
85 |
tim |
1268 |
RattleFramework(SimInfo* rhs) : VelVerletConsFramework(rhs){
|
86 |
tim |
1232 |
raAlgo = new RattleA(rhs);
|
87 |
|
|
rbAlgo = new RattleB(rhs);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
~RattleFramework(){
|
91 |
|
|
delete raAlgo;
|
92 |
|
|
delete rbAlgo;
|
93 |
|
|
}
|
94 |
|
|
|
95 |
tim |
1268 |
virtual int doConstrainA(){
|
96 |
tim |
1232 |
raAlgo->doConstrain();
|
97 |
tim |
1248 |
return raAlgo->haveError()? -1 : 1;
|
98 |
|
|
|
99 |
tim |
1232 |
}
|
100 |
|
|
|
101 |
tim |
1268 |
virtual int doConstrainB(){
|
102 |
tim |
1232 |
rbAlgo->doConstrain();
|
103 |
tim |
1248 |
return rbAlgo->haveError()? -1 : 1;
|
104 |
|
|
|
105 |
tim |
1232 |
}
|
106 |
|
|
private:
|
107 |
|
|
RattleA* raAlgo;
|
108 |
|
|
RattleB* rbAlgo;
|
109 |
|
|
};
|
110 |
|
|
#endif //ifndef _RATTLE_H_ |