7 |
|
//Rattle Constraint Algorithn |
8 |
|
//Reference |
9 |
|
//H.C. Andersen, J. Comput. Phys. 54, 24(1983) |
10 |
– |
//RattleA and Shake are identical |
11 |
– |
typedef Shake RattleA; |
10 |
|
|
11 |
+ |
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 |
|
//////////////////////////////////////////////////////////////////////////////// |
44 |
|
//Declaration of DCRattleBFunctor |
45 |
|
//////////////////////////////////////////////////////////////////////////////// |
79 |
|
//Declaration of RattleAlgorithm |
80 |
|
//////////////////////////////////////////////////////////////////////////////// |
81 |
|
//class RattleAlgorithm will encapsulate preConstraint, RattleA and RattleB |
82 |
< |
class RattleFramework : public ConsAlgoFramework{ |
82 |
> |
//actually, we could use factory pattern to seperate the creation process |
83 |
> |
class RattleFramework : public VelVerletConsFramework{ |
84 |
|
public: |
85 |
< |
RattleFramework(SimInfo* rhs) : ConsAlgoFramework(rhs){ |
85 |
> |
RattleFramework(SimInfo* rhs) : VelVerletConsFramework(rhs){ |
86 |
|
raAlgo = new RattleA(rhs); |
87 |
|
rbAlgo = new RattleB(rhs); |
88 |
|
} |
92 |
|
delete rbAlgo; |
93 |
|
} |
94 |
|
|
95 |
< |
void doRattleA(){ |
95 |
> |
virtual int doConstrainA(){ |
96 |
|
raAlgo->doConstrain(); |
97 |
+ |
return raAlgo->haveError()? -1 : 1; |
98 |
+ |
|
99 |
|
} |
100 |
|
|
101 |
< |
void doRattleB(){ |
101 |
> |
virtual int doConstrainB(){ |
102 |
|
rbAlgo->doConstrain(); |
103 |
+ |
return rbAlgo->haveError()? -1 : 1; |
104 |
+ |
|
105 |
|
} |
106 |
|
private: |
107 |
|
RattleA* raAlgo; |