use of artisynth.core.materials.LinearAxialMaterial in project artisynth_core by artisynth.
the class AxialSpringTest method testForceAndJacobians.
private void testForceAndJacobians(AxialSpring spring) {
Vector3d u = new Vector3d();
Matrix3d uuT = new Matrix3d();
Matrix3d Iminus_uuT = new Matrix3d();
Vector3d delv = new Vector3d();
Matrix3d udelvT = new Matrix3d();
double l;
Vector3d f = new Vector3d();
Matrix3d Fxx = new Matrix3d();
Matrix3d Fvv = new Matrix3d();
Vector3d fcheck = new Vector3d();
LinearAxialMaterial mat = (LinearAxialMaterial) spring.getMaterial();
double k = mat.getStiffness();
double d = mat.getDamping();
double r = spring.getRestLength();
Point pnt0 = spring.getFirstPoint();
Point pnt1 = spring.getSecondPoint();
Point3d pos = new Point3d();
Vector3d vel = new Vector3d();
pos.setRandom();
vel.setRandom();
pnt0.setPosition(pos);
pnt1.setVelocity(vel);
pos.setRandom();
vel.setRandom();
pnt0.setPosition(pos);
pnt1.setVelocity(vel);
SparseNumberedBlockMatrix S = createJacobian(spring);
u.sub(pnt1.getPosition(), pnt0.getPosition());
l = u.norm();
u.scale(1 / l);
uuT.outerProduct(u, u);
Iminus_uuT.setIdentity();
Iminus_uuT.sub(uuT);
delv.sub(pnt1.getVelocity(), pnt0.getVelocity());
udelvT.outerProduct(u, delv);
double fmag = k * (l - r) + d * delv.dot(u);
fcheck.scale(fmag, u);
spring.computeForce(f);
if (!f.epsilonEquals(fcheck, 1e-10)) {
throw new TestException("\nforce is " + f.toString("%10.5f") + ", expected " + fcheck.toString("%10.5f"));
}
spring.computeForcePositionJacobian(Fxx);
Matrix3d FxxCheck = checkForcePositionJacobian(spring);
if (!Fxx.epsilonEquals(FxxCheck, 1e-10)) {
System.out.println("pos0=" + pnt0.getPosition());
System.out.println("vel0=" + pnt0.getVelocity());
System.out.println("pos1=" + pnt1.getPosition());
System.out.println("vel1=" + pnt1.getVelocity());
throw new TestException("\nFxx is\n" + Fxx.toString("%10.5f") + "expected\n" + FxxCheck.toString("%10.5f"));
}
// if (!(pnt0 instanceof PlanarComponent) &&
// !(pnt1 instanceof PlanarComponent))
// {
// Matrix3d FxxDiscrete = discreteForcePositionJacobian (spring);
// if (!Fxx.epsilonEquals (FxxDiscrete, 1e-4))
// { throw new TestException (
// "\nFxx is\n"+Fxx.toString("%10.5f")+
// "expected\n"+FxxDiscrete.toString("%10.5f"));
// }
// }
spring.computeForceVelocityJacobian(Fvv);
Matrix3d FvvCheck = checkForceVelocityJacobian(spring);
if (!Fvv.epsilonEquals(FvvCheck, 1e-10)) {
throw new TestException("\nFvv is\n" + Fvv.toString("%10.5f") + "expected\n" + FvvCheck.toString("%10.5f"));
}
// if (!(pnt0 instanceof PlanarComponent) &&
// !(pnt1 instanceof PlanarComponent))
// {
// Matrix3d FvvDiscrete = discreteForceVelocityJacobian (spring);
// if (!Fvv.epsilonEquals (FvvDiscrete, 1e-4))
// { throw new TestException (
// "\nFvv is\n"+Fvv.toString("%10.5f")+
// "expected\n"+FvvDiscrete.toString("%10.5f"));
// }
// }
// now test full Jacobian calculation
spring.addSolveBlocks(S);
spring.addPosJacobian(S, 1);
checkJacobian(S, spring, Fxx);
S.setZero();
spring.addVelJacobian(S, 1);
checkJacobian(S, spring, Fvv);
}
use of artisynth.core.materials.LinearAxialMaterial in project artisynth_core by artisynth.
the class PointSpringBase method setStiffness.
public static void setStiffness(PointSpringBase s, double k) {
if (s.getMaterial() instanceof LinearAxialMaterial) {
LinearAxialMaterial mat = (LinearAxialMaterial) s.getMaterial().clone();
mat.setStiffness(k);
s.setMaterial(mat);
} else {
System.out.println("Warning: setStiffness(): no stiffness in spring material");
}
}
use of artisynth.core.materials.LinearAxialMaterial in project artisynth_core by artisynth.
the class PointSpringBase method setDamping.
public static void setDamping(PointSpringBase s, double d) {
if (s.getMaterial() instanceof LinearAxialMaterial) {
LinearAxialMaterial mat = (LinearAxialMaterial) s.getMaterial().clone();
mat.setDamping(d);
s.setMaterial(mat);
} else if (s.getMaterial() instanceof AxialMuscleMaterial) {
AxialMuscleMaterial mat = (AxialMuscleMaterial) s.getMaterial().clone();
mat.setDamping(d);
s.setMaterial(mat);
} else {
System.out.println("Warning: setDamping(): no damping in spring material");
}
}
Aggregations