Marine systems simulation
JointConstraint.h
1#pragma once
2
3#include "ConstraintSet.h"
4#include<Eigen/StdVector>
5
6namespace CoRiBoDynamics{
7
17{
18public:
19 explicit JointConstraint(ConstraintSolver* solver);
20 virtual ~JointConstraint();
21
22 virtual void ComputeConstraints(const double T, const double * const X);
23
28 void addBallJointCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, double Beta, double Alpha, double Gamma);
29
36 void addHingeCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, vec3 axisA, vec3 axisB, double Beta, double Alpha, double Gamma, double AlphaFriction, double GammaFriction);
37
45 void addRigidCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, double BetaN, double AlphaN, double GammaN, const Quat& nullAngle, const Quat& BetaM, const Quat& AlphaM, const Quat& GammaM);
46
53 int addExternalBallJointCoupling(int element, vec3 vector, double Beta, double Alpha, double Gamma, const double* Position, const double* Velocity);
54
59 void updateExternalBallJointCoupling(int ballJointCoupling, const double* Position, const double* Velocity);
60
65 vec3 getExternalBallJointCouplingForce(int ballJointCoupling);
66
73 int addExternalRigidCoupling(int element, vec3 vectorExternalObject, vec3 vectorInternalObject, double BetaN, double AlphaN, double GammaN, const Quat& nullAngle, const Quat& BetaM, const Quat& AlphaM, const Quat& GammaM, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity);
74
79 void updateExternalRigidCoupling(int rigidCoupling, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity);
80
85 vec6 getExternalRigidCouplingForce(int rigidCoupling);
86
87 /*
88 PA + QA(vectorA) - PB - QB(vectorB) = 0
89 QA(axisA) - QB(axisB) = 0
90 */
92 int elementA; // index of element A
93 int elementB; // index of element B
94 vec3 vectorA; // body space vector from A center to hinge
95 vec3 vectorB; // body space vector from B center to hinge
96 vec3 axisA; // body space vector of hinge rotation. Both hinge axes must have same length. Longer vectors will give stronger restoring.
97 vec3 axisB; // body space vector of hinge rotation.
98 double Beta2; // Beta^2 of axial forces and hinge restoring
99 double Alpha2; // 2*Alpha of axial forces and hinge restoring
100 double Gamma; // Gamma value for axial forces and hinge restoring
101 double Alpha2Friction; // 2*Alpha for hinge rotational friction
102 double GammaFriction; // Gamma for hinge rotational friction
103 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
104 };
105
106
107 /*
108 PA + QA(vectorA) - PB - QB(vectorB) = 0
109 */
111 int elementA; // index of element A
112 int elementB; // index of element B
113 vec3 vectorA; // body space vector from A center to joint
114 vec3 vectorB; // body space vector from B center to joint
115 double Beta2; // Beta^2 of axial forces
116 double Alpha2;// 2*Alpha of axial forces
117 double Gamma; // Gamma value for axial forces
118 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
119 };
120
121 /*
122 PA + QA(vectorA) - PB - QB(vectorB) = 0
123 QA^-1 * QB - nullAngle = 0
124 */
126 int elementA; // index of element A
127 int elementB; // index of element B
128 vec3 vectorA; // body space vector from A center to joint
129 vec3 vectorB; // body space vector from B center to joint
130 double BetaN2; // Beta^2 of axial forces
131 double Alpha2N;// 2*Alpha of axial forces
132 double GammaN; // Gamma value for axial forces
133 Quat nullAngle; // "relative orientation of zero static torque"
134 Quat BetaM2; // 4 x Beta^2 for torque
135 Quat Alpha2M;// 4 x 2*Alpha of torque
136 Quat GammaM; // 4 x Gamma value for torque
137 vec6 ReactionForce; // resulting reaction force. Must add in force X vector to get correct torque for each element
138 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
139 };
140
142 int element;
143 vec3 vector;
144 double Beta2;
145 double Alpha2;
146 double Gamma;
147 const double* extPos;
148 const double* extVel;
150 ExternalBallJointCoupling(int i, vec3 v, double B, double A, double G){element = i; vector = v; Beta2 = B; Alpha2 = A; Gamma = G;}
151 void SetStates(const double* E_P, const double* E_V){extPos = E_P; extVel = E_V;}
152 vec3 ReactionForce; // Constraint force from perspective of external object. The force should be adjusted with the baseMatrix*internal_element_acceleration
153 mat36 baseMatrix; // Response matrix to adjust reaction force with element acceleration
154 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
155 };
156
158 int element;
159 vec3 vectorExt;
160 vec3 vectorInt;
161 double BetaN2;
162 double Alpha2N;
163 double GammaN;
164 Quat nullAngle;
165 Quat BetaM2;
166 Quat Alpha2M;
167 Quat GammaM;
168 vec6 ReactionForce; // Constraint force from perspective of external object. The force should be adjusted with the baseMatrix*internal_element_acceleration
169 mat6 baseMatrix; // Response matrix to adjust reaction force with element acceleration
170 const double* extPos;
171 const double* extVel;
172 const double* extQuat;
173 const double* extOmega;
174 void SetValues(int i, vec3 vExt, vec3 vInt, const Quat& e, double BN2, double A2N, double GN, const Quat& BM2, const Quat& A2M, const Quat& GM){element = i; vectorExt = vExt; vectorInt = vInt; nullAngle = e; BetaN2 = BN2; Alpha2N = A2N; GammaN = GN; BetaM2 = BM2; Alpha2M = A2M; GammaM = GM;}
175 void SetStates(const double* E_P, const double* E_V, const double* E_Q, const double* E_W){extPos = E_P; extVel = E_V; extQuat = E_Q; extOmega = E_W;}
176 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
177 };
178
181
182protected:
183 static mat4 QuaternionConstraint_Jacobian(const Quat& q);
184 static mat43 Quaternion_Kinematics(const Quat& q);
185
186 std::vector<HingeCoupling ,Eigen::aligned_allocator<HingeCoupling > > m_HingeCoupling;
187 std::vector<BallJointCoupling ,Eigen::aligned_allocator<BallJointCoupling > > m_BallJointCoupling;
188 std::vector<RigidCoupling ,Eigen::aligned_allocator<RigidCoupling > > m_RigidCoupling;
189
190 std::vector<ExternalBallJointCoupling,Eigen::aligned_allocator<ExternalBallJointCoupling>> m_ExternalBallJointCoupling;
191 std::vector<ExternalRigidCoupling,Eigen::aligned_allocator<ExternalRigidCoupling> > m_ExternalRigidCoupling;
192
193 void ComputeHingeCoupling ( HingeCoupling& Constraint );
194 void ComputeBallJointCoupling ( BallJointCoupling& Constraint );
195 void ComputeRigidCoupling ( RigidCoupling& Constraint );
196
197 void ComputeExternalBallJointCoupling( ExternalBallJointCoupling& Constraint );
198 void ComputeExternalVaryingBallJointCoupling( ExternalBallJointCoupling& Constraint, double vector_length_changerate );
199 void ComputeExternalRigidCoupling( ExternalRigidCoupling& Constraint );
200};
201
202}
Definition: ConstraintSet.h:24
Definition: ConstraintSolver.h:31
Definition: JointConstraint.h:17
std::vector< ExternalBallJointCoupling, Eigen::aligned_allocator< ExternalBallJointCoupling > > m_ExternalBallJointCoupling
Rigid Coupling.
Definition: JointConstraint.h:190
std::vector< RigidCoupling,Eigen::aligned_allocator< RigidCoupling > > m_RigidCoupling
BallJoint Coupling.
Definition: JointConstraint.h:188
void addBallJointCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, double Beta, double Alpha, double Gamma)
std::vector< ExternalRigidCoupling, Eigen::aligned_allocator< ExternalRigidCoupling > > m_ExternalRigidCoupling
External Ball Joint Coupling.
Definition: JointConstraint.h:191
int addExternalBallJointCoupling(int element, vec3 vector, double Beta, double Alpha, double Gamma, const double *Position, const double *Velocity)
void addRigidCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, double BetaN, double AlphaN, double GammaN, const Quat &nullAngle, const Quat &BetaM, const Quat &AlphaM, const Quat &GammaM)
vec6 getExternalRigidCouplingForce(int rigidCoupling)
std::vector< BallJointCoupling,Eigen::aligned_allocator< BallJointCoupling > > m_BallJointCoupling
BallJoint Coupling.
Definition: JointConstraint.h:187
void updateExternalBallJointCoupling(int ballJointCoupling, const double *Position, const double *Velocity)
int addExternalRigidCoupling(int element, vec3 vectorExternalObject, vec3 vectorInternalObject, double BetaN, double AlphaN, double GammaN, const Quat &nullAngle, const Quat &BetaM, const Quat &AlphaM, const Quat &GammaM, const double *Position, const double *Velocity, const double *Orientation, const double *AngularVelocity)
virtual void ComputeConstraints(const double T, const double *const X)
void addHingeCoupling(int elementA, int elementB, vec3 vectorA, vec3 vectorB, vec3 axisA, vec3 axisB, double Beta, double Alpha, double Gamma, double AlphaFriction, double GammaFriction)
void updateExternalRigidCoupling(int rigidCoupling, const double *Position, const double *Velocity, const double *Orientation, const double *AngularVelocity)
vec3 getExternalBallJointCouplingForce(int ballJointCoupling)
Definition: CollisionManager.h:6
Definition: JointConstraint.h:91
Definition: JointConstraint.h:125