@@ -87,72 +87,67 @@ void __global__ CUDA_CalcSBForce_Kelvin_kernel(
8787 if (!_bondActivities[i]) continue ;
8888
8989 // relative angle velocity of contact partners
90- CVector3 relAngleVel = _partAnglVels[_bondLeftIDs[i]] - _partAnglVels[_bondRightIDs[i]];
90+ const CVector3 relAngleVel = _partAnglVels[_bondLeftIDs[i]] - _partAnglVels[_bondRightIDs[i]];
9191
9292 // the bond in the global coordinate system
93- CVector3 currentBond = GetSolidBond (_partCoords[_bondRightIDs[i]], _partCoords[_bondLeftIDs[i]], PBC);
94- double dDistanceBetweenCenters = currentBond.Length ();
95-
96- double dBondInitLength = _bondInitialLengths[i];
93+ const CVector3 currentBond = GetSolidBond (_partCoords[_bondRightIDs[i]], _partCoords[_bondLeftIDs[i]], PBC);
94+ double distanceBetweenCenters = currentBond.Length ();
9795
9896 // optimized
99- CVector3 sumAngleVelocity = _partAnglVels[_bondLeftIDs[i]] + _partAnglVels[_bondRightIDs[i]];
100- CVector3 relativeVelocity = _partVels[_bondLeftIDs[i]] - _partVels[_bondRightIDs[i]] - sumAngleVelocity* currentBond* 0.5 ;
97+ const CVector3 sumAngleVelocity = _partAnglVels[_bondLeftIDs[i]] + _partAnglVels[_bondRightIDs[i]];
98+ const CVector3 relativeVelocity = _partVels[_bondLeftIDs[i]] - _partVels[_bondRightIDs[i]] - sumAngleVelocity * currentBond * 0.5 ;
10199
102- CVector3 currentContact = currentBond / dDistanceBetweenCenters ;
103- CVector3 tempVector = _bondPrevBonds[i] * currentBond;
100+ const CVector3 currentContact = currentBond / distanceBetweenCenters ;
101+ const CVector3 tempVector = _bondPrevBonds[i] * currentBond;
104102
105- CVector3 Phi = currentContact* (DotProduct (sumAngleVelocity, currentContact)* _timeStep* 0.5 );
103+ const CVector3 phi = currentContact * (DotProduct (sumAngleVelocity, currentContact) * _timeStep * 0.5 );
106104
107- CMatrix3 M ( 1 + tempVector.z *Phi .z + tempVector.y *Phi .y , Phi .z - tempVector.z - tempVector.y *Phi .x , -Phi .y - tempVector.z *Phi .x + tempVector.y ,
108- tempVector.z - Phi .z - tempVector.x *Phi .y , tempVector.z *Phi .z + 1 + tempVector.x *Phi .x , -tempVector.z *Phi .y + Phi .x - tempVector.x ,
109- -tempVector.y - tempVector.x *Phi .z + Phi .y , -tempVector.y *Phi .z + tempVector.x - Phi .x , tempVector.y *Phi .y + tempVector.x *Phi .x + 1 );
105+ const CMatrix3 M (1 + tempVector.z * phi .z + tempVector.y * phi .y , phi .z - tempVector.z - tempVector.y * phi .x , -phi .y - tempVector.z * phi .x + tempVector.y ,
106+ tempVector.z - phi .z - tempVector.x * phi .y , tempVector.z * phi .z + 1 + tempVector.x * phi .x , -tempVector.z * phi .y + phi .x - tempVector.x ,
107+ -tempVector.y - tempVector.x * phi .z + phi .y , -tempVector.y * phi .z + tempVector.x - phi .x , tempVector.y * phi .y + tempVector.x * phi .x + 1 );
110108
111- CVector3 normalVelocity = currentContact * DotProduct (currentContact, relativeVelocity);
112- CVector3 tangentialVelocity = relativeVelocity - normalVelocity;
109+ const CVector3 normalVelocity = currentContact * DotProduct (currentContact, relativeVelocity);
110+ const CVector3 tangentialVelocity = relativeVelocity - normalVelocity;
113111
114112 // normal angle velocity
115- CVector3 normalAngleVel = currentContact* DotProduct (currentContact, relAngleVel);
116- CVector3 tangAngleVel = relAngleVel - normalAngleVel;
113+ const CVector3 normalAngleVel = currentContact * DotProduct (currentContact, relAngleVel);
114+ const CVector3 tangAngleVel = relAngleVel - normalAngleVel;
117115
118116 // calculate the force
119- double dStrainTotal = (dDistanceBetweenCenters-dBondInitLength) / dBondInitLength;
120- CVector3 vNormalForce = currentContact * (-1 *_bondCrossCuts[i] * _bondNormalStiffnesses[i] * dStrainTotal);
121-
122- double dMu = _bondViscosities[i];
117+ const double strainTotal = (distanceBetweenCenters - _bondInitialLengths[i]) / _bondInitialLengths[i];
118+ const CVector3 normalForce = currentContact * (-1 * _bondCrossCuts[i] * _bondNormalStiffnesses[i] * strainTotal);
123119
124- CVector3 vDampingForce = -dMu * normalVelocity* _bondCrossCuts[i] * _bondNormalStiffnesses[i] *fabs (dStrainTotal );
125- if (vDampingForce .Length () > 0.5 *vNormalForce .Length ())
126- vDampingForce *= 0.5 *vNormalForce .Length () / vDampingForce .Length ();
120+ CVector3 dampingForceNorm = -_bondViscosities[i] * normalVelocity * _bondCrossCuts[i] * _bondNormalStiffnesses[i] * fabs (strainTotal );
121+ if (dampingForceNorm .Length () > 0.5 * normalForce .Length ())
122+ dampingForceNorm *= 0.5 * normalForce .Length () / dampingForceNorm .Length ();
127123
128124 _bondTangentialOverlaps[i] = M * _bondTangentialOverlaps[i] - tangentialVelocity * _timeStep;
129- const CVector3 vTangentialForce = _bondTangentialOverlaps[i] * (_bondTangentialStiffnesses[i] * _bondCrossCuts[i] / dBondInitLength);
130-
131- CVector3 vDampingTangForce = -dMu * tangentialVelocity*_bondTangentialOverlaps[i].Length () *(_bondTangentialStiffnesses[i] * _bondCrossCuts[i] / dBondInitLength);
132- if (vDampingTangForce.Length () > 0.5 *vTangentialForce.Length ())
133- vDampingTangForce *= 0.5 *vTangentialForce.Length () / vDampingTangForce.Length ();
125+ const CVector3 tangentialForce = _bondTangentialOverlaps[i] * (_bondTangentialStiffnesses[i] * _bondCrossCuts[i] / _bondInitialLengths[i]);
134126
135- const CVector3 vBondNormalMoment = M * _bondNormalMoments[i] - normalAngleVel * (_timeStep * 2 * _bondAxialMoments[i] * _bondTangentialStiffnesses[i] / dBondInitLength);
136- const CVector3 vBondTangentialMoment = M * _bondTangentialMoments[i] - tangAngleVel * (_timeStep * _bondNormalStiffnesses[i] * _bondAxialMoments[i] / dBondInitLength);
127+ CVector3 dampingForceTang = -_bondViscosities[i] * tangentialVelocity * _bondTangentialOverlaps[i].Length () * (_bondTangentialStiffnesses[i] * _bondCrossCuts[i] / _bondInitialLengths[i]);
128+ if (dampingForceTang.Length () > 0.5 * tangentialForce.Length ())
129+ dampingForceTang *= 0.5 * tangentialForce.Length () / dampingForceTang.Length ();
137130
138- _bondNormalMoments[i] = vBondNormalMoment;
139- _bondTangentialMoments[i] = vBondTangentialMoment;
131+ const CVector3 bondNormalMoment = M * _bondNormalMoments[i] - normalAngleVel * (_timeStep * 2 * _bondAxialMoments[i] * _bondTangentialStiffnesses[i] / _bondInitialLengths[i]);
132+ const CVector3 bondTangentialMoment = M * _bondTangentialMoments[i] - tangAngleVel * (_timeStep * _bondNormalStiffnesses[i] * _bondAxialMoments[i] / _bondInitialLengths[i]);
133+ const CVector3 bondUnsymMoment = currentBond * 0.5 * tangentialForce;
140134
141- const CVector3 vUnsymMoment = currentBond*0.5 * vTangentialForce;
135+ _bondNormalMoments[i] = bondNormalMoment;
136+ _bondTangentialMoments[i] = bondTangentialMoment;
142137 _bondPrevBonds[i] = currentBond;
143- _bondTotalForces[i] = vNormalForce + vTangentialForce + vDampingForce + vDampingTangForce ;
138+ _bondTotalForces[i] = normalForce + tangentialForce + dampingForceNorm + dampingForceTang ;
144139
145140 if (m_vConstantModelParameters[0 ])
146141 {
147- double dForceLength = vNormalForce .Length ();
148- if (dStrainTotal <= 0 ) // compression
149- dForceLength *= -1 ;
142+ double forceLength = normalForce .Length ();
143+ if (strainTotal <= 0 ) // compression
144+ forceLength *= -1 ;
150145
151146 // check the bond destruction
152- double dMaxStress = dForceLength / _bondCrossCuts[i] + vBondTangentialMoment .Length () * _bondDiameters[i] / (2 * _bondAxialMoments[i]);
153- double dMaxTorque = vTangentialForce .Length () / _bondCrossCuts[i] + vBondNormalMoment .Length () * _bondDiameters[i] / (4 * _bondAxialMoments[i]);
147+ const double maxStress = forceLength / _bondCrossCuts[i] + bondTangentialMoment .Length () * _bondDiameters[i] / (2 * _bondAxialMoments[i]);
148+ const double maxTorque = tangentialForce .Length () / _bondCrossCuts[i] + bondNormalMoment .Length () * _bondDiameters[i] / (4 * _bondAxialMoments[i]);
154149
155- if (dMaxStress >= _bondNormalStrengths[i] || dMaxTorque >= _bondTangentialStrengths[i])
150+ if (maxStress >= _bondNormalStrengths[i] || maxTorque >= _bondTangentialStrengths[i])
156151 {
157152 _bondActivities[i] = false ;
158153 _bondEndActivities[i] = _time;
@@ -161,9 +156,9 @@ void __global__ CUDA_CalcSBForce_Kelvin_kernel(
161156 }
162157
163158 // apply forces and moments directly to particles, only if bond is not broken
164- const CVector3 partForce = vNormalForce + vTangentialForce + vDampingForce + vDampingTangForce ;
165- const CVector3 partMoment1 = vBondNormalMoment + vBondTangentialMoment - vUnsymMoment ;
166- const CVector3 partMoment2 = vBondNormalMoment + vBondTangentialMoment + vUnsymMoment ;
159+ const CVector3 partForce = normalForce + tangentialForce + dampingForceNorm + dampingForceTang ;
160+ const CVector3 partMoment1 = bondNormalMoment + bondTangentialMoment - bondUnsymMoment ;
161+ const CVector3 partMoment2 = bondNormalMoment + bondTangentialMoment + bondUnsymMoment ;
167162 CUDA_VECTOR3_ATOMIC_ADD (_partForces[_bondLeftIDs[i]], partForce);
168163 CUDA_VECTOR3_ATOMIC_ADD (_partMoments[_bondLeftIDs[i]], partMoment1);
169164 CUDA_VECTOR3_ATOMIC_SUB (_partForces[_bondRightIDs[i]], partForce);
0 commit comments