17 #ifndef AGX_WIRE_CONTACT_SOLVER_H 18 #define AGX_WIRE_CONTACT_SOLVER_H 27 #define NUM_CONTACTS_AT_END 2 33 : m_position(position),
35 m_edgeStart(edgeStart),
39 m_normalForce(normalForce),
41 m_frictionCoeff(frictionCoeff)
43 m_edge = m_edgeEnd-m_edgeStart;
68 m_position = m_position + m_edge*velocity*timestep;
73 m_velocity = m_velocity + m_externalForce*timestep*m_invMass;
78 m_externalForce = externalForce*m_edge;
101 Real m_externalForce;
102 Real m_frictionCoeff;
113 :m_youngsModulus(youngsModulus),m_compliance(compliance),m_restlength(restlength),m_density(density),m_radius(radius),m_tension(tension)
128 Real m_youngsModulus;
149 virtual void calculateJacobian() = 0;
151 virtual void calculateViolation() = 0;
155 m_lambda = timestep*m_violation/m_compliance;
160 if ( m_particles.empty() )
161 m_firstParticleGlobalIndex = contactIndex;
163 m_particles.push_back( wp );
164 m_jacobianVector.push_back(
agx::Real(0));
170 if ( m_jacobianVector.empty() )
173 if ( particleIndex < m_firstParticleGlobalIndex || m_jacobianVector.size() <= particleIndex - m_firstParticleGlobalIndex )
176 G = m_jacobianVector[particleIndex-m_firstParticleGlobalIndex];
183 if ( m_particles.empty() )
186 if ( particleIndex < m_firstParticleGlobalIndex || m_particles.size() <= particleIndex - m_firstParticleGlobalIndex )
189 return m_particles[particleIndex-m_firstParticleGlobalIndex]->getInvMass();
194 if ( m_particles.empty() )
197 if ( particleIndex < m_firstParticleGlobalIndex || m_particles.size() <= particleIndex - m_firstParticleGlobalIndex )
200 return m_particles[particleIndex-m_firstParticleGlobalIndex]->getMass();
208 Real gamma = 1/(1+4*m_damping*invTimestep);
211 for (
size_t i = 0; i < m_particles.size(); ++i )
213 Real G = m_jacobianVector[i];
214 GV += G*m_particles[i]->getVelocity();
217 m_rhs = -4*gamma*violation*invTimestep + gamma*GV;
230 size_t indexOffset = getFirstParticleGlobalIndex();
232 calculateEpsilon(timestep);
236 for (
size_t i = 0; i < m_jacobianVector.size(); ++i )
238 size_t particleIndex = i + indexOffset;
240 bool success = getJacobian(particleIndex,g);
255 m_epsilon =
Real(4.0) / ( timestep * timestep * (
Real(1.0) +
Real(4.0) * m_damping / timestep ) ) * m_compliance;
260 if ( globalIndex < m_firstParticleGlobalIndex || globalIndex - m_firstParticleGlobalIndex >= m_jacobianVector.size() )
263 return m_lambda*m_jacobianVector[ globalIndex - m_firstParticleGlobalIndex ]/timestep;
269 m_lowerBounds = bounds.
lower();
270 m_upperBounds = bounds.
upper();
305 bool m_reachedBounds;
318 m_beginParticle(nullptr),
319 m_endParticle(nullptr),
320 m_beginParticleVelocity( beginVelocity ),
321 m_endParticleVelocity( endVelocity ),
322 m_restlength(restlength)
324 m_compliance = compliance;
329 m_beginParticle->setPosition( m_beginParticle->getPosition() + m_beginParticleVelocity*timestep );
330 m_endParticle->setPosition( m_endParticle->getPosition() + m_endParticleVelocity*timestep );
332 virtual void calculateJacobian()
override;
333 virtual void calculateViolation()
override;
339 WireParticleRef m_beginParticle;
340 WireParticleRef m_endParticle;
341 Vec3 m_beginParticleVelocity;
342 Vec3 m_endParticleVelocity;
353 m_beginParticle(bwp),
354 m_middleParticle(mwp),
360 addWireParticle(m_beginParticle,beginIndex);
361 addWireParticle(m_middleParticle,beginIndex+1);
362 addWireParticle(m_endParticle,beginIndex+2);
363 m_damping =
Real(0.5);
364 m_firstParticleGlobalIndex = beginIndex;
369 m_compliance =
std::max(
Real(400) *( l1 + l2 ) / ( A * radius * radius * youngsModulus ),
Real(1E-4));
372 virtual void calculateJacobian()
override;
373 virtual void calculateViolation()
override;
379 WireParticleRef m_beginParticle;
380 WireParticleRef m_middleParticle;
381 WireParticleRef m_endParticle;
395 m_particle(particle),
398 m_restLength = edge.
length();
399 m_compliance = compliance;
400 m_firstParticleGlobalIndex = beginIndex;
402 addWireParticle(particle,beginIndex);
407 if ( m_jacobianVector.empty() )
410 m_jacobianVector[0] = 1;
414 m_violation = m_particle->getPosition().distance( m_fixPoint ) - m_restLength;
434 m_particle = particle;
436 m_restLength = edge.
length();
437 m_compliance = compliance;
438 m_firstParticleGlobalIndex = beginIndex;
440 addWireParticle(particle,beginIndex);
468 m_createSpringConstraints(false),
470 m_outsideTimestep(outsideTimestep),
472 m_beginMass(beginMass),
480 void createWire(
const Real radius,
const Real density,
const Real restlength,
const Real youngsModulus,
const Real compliance,
const Real tension,
bool useBend);
482 void createConstraints(
bool distanceBounds =
false );
484 bool iterateConstraints(
bool onlyOneStep =
false,
bool updatePositionsAndVelocities =
true );
486 void updateParticleForces(
Real timestep );
488 const WireParticleRefVector&
getParticles()
const {
return m_particles; }
507 m_constraints.clear();
520 void setTimestep(
Real timestep ) { m_timestep = timestep; }
525 WireContactConstraintRefVector m_constraints;
527 ParticleContactWireRef m_wire;
528 WireParticleRefVector m_particles;
529 bool m_createSpringConstraints;
531 Real m_outsideTimestep;
ref_ptr< WireParticle > WireParticleRef
void setPosition(Vec3 pos)
ref_ptr< WireContactSpringConstraint > WireContactSpringConstraintRef
Real getCompliance() const
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
ref_ptr< WireContactFrictionConstraint > WireContactFrictionConstraintRef
void addToTotalForce(Real constraintForce)
ref_ptr< WireContactSolver > WireContactSolverRef
void setExternalForce(Vec3 externalForce)
#define AGXPHYSICS_EXPORT
Base class providing referencing counted objects.
WireParticle(Vec3 position, Vec3 edgeStart, Vec3 edgeEnd, Real mass, Real velocity=Real(0), Real normalForce=0, Real frictionCoeff=0)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void setNormalForce(Real normalForce)
Real getYoungsModulus() const
void updatePosition(Real timestep, Real maxVelocity=agx::Infinity)
agx::Vector< WireParticleRef > WireParticleRefVector
ref_ptr< WireContactDistanceConstraint > WireContactDistanceConstraintRef
Real getNormalForce() const
void applyVelocityDamping()
AGXCORE_EXPORT const Real Infinity
ref_ptr< WireContactConstraint > WireContactConstraintRef
virtual ~ParticleContactWire()
Real getFrictionCoefficient()
void setVelocity(Real velocity)
void setFrictionCoefficient(Real frictionCoeff)
Real normalize()
Normalize the vector so that it has length unity.
Real length() const
Length of the vector = sqrt( vec .
agx::Vector< WireContactConstraintRef > WireContactConstraintRefVector
T1 clamp(T1 v, T2 minimum, T3 maximum)
Real getRestlength() const
ref_ptr< ParticleContactWire > ParticleContactWireRef
Real getExternalForce() const
ref_ptr< WireContactBendConstraint > WireContactBendConstraintRef
ParticleContactWire(Real restlength, Real density, Real youngsModulus, Real compliance, Real radius, Real tension, bool)
void integrateExternalForce(Real timestep)