Search in sources :

Example 26 with VectorNd

use of maspack.matrix.VectorNd in project artisynth_core by artisynth.

the class ForceTargetTerm method updateWeightsVector.

private void updateWeightsVector() {
    myTargetWgts = new VectorNd(myForceTargets.size());
    int idx = 0;
    for (int t = 0; t < myForceTargets.size(); t++) {
        double w = myTargetWeights.get(t);
        int targetSize = myForceTargets.get(t).getTargetLambda().size();
        for (int i = 0; i < targetSize; i++) {
            myTargetWgts.set(idx++, w);
        }
    }
}
Also used : VectorNd(maspack.matrix.VectorNd)

Example 27 with VectorNd

use of maspack.matrix.VectorNd in project artisynth_core by artisynth.

the class ForceTargetTerm method updateTargetForce.

public void updateTargetForce(double t0, double t1) {
    if (!isEnabled()) {
        return;
    }
    if (myTargetFor == null || myTargetFor.size() != myTargetForSize)
        myTargetFor = new VectorNd(myTargetForSize);
    double[] buf = myTargetFor.getBuffer();
    int idx = 0;
    for (int i = 0; i < myForceTargets.size(); i++) {
        ForceTarget target = myForceTargets.get(i);
        VectorNd lambda = target.getTargetLambda();
        idx = lambda.get(buf, idx);
    }
// System.out.println("targetForce = "+myTargetFor);
}
Also used : VectorNd(maspack.matrix.VectorNd)

Example 28 with VectorNd

use of maspack.matrix.VectorNd in project artisynth_core by artisynth.

the class ForceTargetTerm method getTerm.

/**
 * Fills <code>H</code> and <code>b</code> with this motion term
 * @param H LHS matrix to fill
 * @param b RHS vector to fill
 * @param rowoff row offset to start filling term
 * @param t0 starting time of time step
 * @param t1 ending time of time step
 * @return next row offset
 */
public int getTerm(MatrixNd H, VectorNd b, int rowoff, double t0, double t1) {
    double h = TimeBase.round(t1 - t0);
    // System.out.println("using pre-comp data");
    // set myTargetForce
    updateTargetForce(t0, t1);
    VectorNd cbar = new VectorNd(myTargetForSize);
    // XXX do useTimestepScaling, useNormalizeH on targetVel
    // cbar.sub (myTargetFor, myController.getData ().getC0 ());
    // scale cbar by h -- Benedikt
    cbar.set(myTargetFor);
    cbar.scale(h);
    // XXX do useTimestepScaling, useNormalizeH on targetVel
    cbar.sub(myController.getData().getC0());
    MatrixNd Hc = new MatrixNd(myTargetForSize, myController.numExcitations());
    Hc.set(myController.getData().getHc());
    if (myController.getData().normalizeH) {
        double fn = 1.0 / Hc.frobeniusNorm();
        Hc.scale(fn);
        cbar.scale(fn);
    }
    if (myController.getData().useTimestepScaling) {
        // makes it independent of the time step
        Hc.scale(1 / h);
        cbar.scale(1 / h);
    }
    // apply weights
    if (myTargetWgts != null) {
        MotionForceInverseData.diagMul(myTargetWgts, Hc, Hc);
        MotionForceInverseData.pointMul(myTargetWgts, cbar, cbar);
    }
    if (myWeight >= 0) {
        Hc.scale(myWeight);
        cbar.scale(myWeight);
    }
    H.setSubMatrix(rowoff, 0, Hc);
    b.setSubVector(rowoff, cbar);
    /* debug output */
    if (myController.getDebug()) {
    // System.out.println ("(ForceTargetTerm)");
    // System.out.println("\tTargetForce: " + myTargetFor);
    // System.out.println("\tJc:\n" + getForceJacobian ().toString ("%.3f"));
    // System.out.println("\tHc:\n" + Hc.toString ("%.3f"));
    // System.out.println("\tcbar: " + cbar.toString ("%.3f"));
    }
    return rowoff + Hc.rowSize();
}
Also used : MatrixNd(maspack.matrix.MatrixNd) VectorNd(maspack.matrix.VectorNd)

Example 29 with VectorNd

use of maspack.matrix.VectorNd in project artisynth_core by artisynth.

the class ForceTargetTerm method createForceJacobian.

private void createForceJacobian() {
    MechModel mechMod = (MechModel) myMech;
    SparseBlockMatrix GT = new SparseBlockMatrix();
    VectorNd dg = new VectorNd();
    mechMod.getBilateralConstraints(GT, dg);
    if (debug) {
        System.out.println("num con = " + mechMod.bodyConnectors().size());
        System.out.println(GT.colSize());
        System.out.println(GT.rowSize());
        System.out.println(GT.getSize());
        System.out.println(GT.numBlocks());
        System.out.println(GT.getBlock(0, 0));
        System.out.println(GT.getBlock(0, 1));
        System.out.println(GT.getBlock(0, 2));
        System.out.println(GT.getBlock(1, 0));
    }
    // find the number of bilateral constraints for each connector
    int[] connectorSizes = new int[mechMod.bodyConnectors().size()];
    int[] targetToConnectorMap = new int[myForceTargets.size()];
    int targetIdx = 0;
    for (ForceTarget ft : myForceTargets) {
        int connectorIdx = 0;
        for (BodyConnector connector : mechMod.bodyConnectors()) {
            if (debug) {
                System.out.println(connector.getName());
                System.out.println(ft.getName());
            }
            if (ft.getConnector() == connector) {
                targetToConnectorMap[targetIdx] = connectorIdx;
                targetIdx++;
            }
            if (connector.isEnabled() == true) {
                if (debug) {
                    System.out.println(connector.numBilateralConstraints());
                }
                connectorSizes[connectorIdx] = connector.numBilateralConstraints();
                connectorIdx++;
            }
        }
    }
    myForJacobian = new SparseBlockMatrix(new int[0], connectorSizes);
    for (int i = 0; i < myForceTargets.size(); i++) {
        ForceTarget target = myForceTargets.get(i);
        // TODO: non-enabled connectors should not add to Jacobian -- need to fix
        target.addForceJacobian(myForJacobian, i, targetToConnectorMap[i]);
    }
    if (debug) {
        System.out.println("Jc = " + myForJacobian);
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) SparseBlockMatrix(maspack.matrix.SparseBlockMatrix) VectorNd(maspack.matrix.VectorNd) BodyConnector(artisynth.core.mechmodels.BodyConnector)

Example 30 with VectorNd

use of maspack.matrix.VectorNd in project artisynth_core by artisynth.

the class LeastSquaresSolver method resetBounds.

private int resetBounds() {
    int size = 0;
    if (myLowerBound != null) {
        lb = new VectorNd(exSize);
        for (int i = 0; i < exSize; i++) {
            lb.set(i, myLowerBound);
        }
        size += exSize;
    } else {
        lb = null;
    }
    if (myUpperBound != null) {
        ub = new VectorNd(exSize);
        for (int i = 0; i < exSize; i++) {
            ub.set(i, myUpperBound);
        }
        size += exSize;
    } else {
        ub = null;
    }
    return size;
}
Also used : VectorNd(maspack.matrix.VectorNd)

Aggregations

VectorNd (maspack.matrix.VectorNd)136 Point (artisynth.core.mechmodels.Point)29 Point3d (maspack.matrix.Point3d)16 Vector3d (maspack.matrix.Vector3d)15 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)11 ArrayList (java.util.ArrayList)11 ContactPoint (artisynth.core.mechmodels.ContactPoint)9 MatrixNd (maspack.matrix.MatrixNd)9 Vertex3d (maspack.geometry.Vertex3d)8 SparseMatrixNd (maspack.matrix.SparseMatrixNd)8 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)7 PointAttachment (artisynth.core.mechmodels.PointAttachment)7 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)6 FemNode (artisynth.core.femmodels.FemNode)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 ReaderTokenizer (maspack.util.ReaderTokenizer)5 FemNode3d (artisynth.core.femmodels.FemNode3d)4 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)4 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)4