Search in sources :

Example 26 with MatrixNd

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

the class Test method TestMatrix.

static void TestMatrix(int n) {
    int reps = 1;
    MatrixNd m1 = new MatrixNd(n, n), m2 = new MatrixNd(n, n), m3 = new MatrixNd(n, n);
    Random r = new Random(1234);
    for (int i = 0; i < n; i++) {
        for (int j = 0; i < n; i++) {
            m1.set(i, j, r.nextDouble());
            m2.set(i, j, r.nextDouble());
        }
    }
    long t = System.nanoTime();
    for (int i = 0; i < reps; i++) {
        m3.mul(m1, m2);
    }
    t = System.nanoTime() - t;
    System.out.println(n + "x" + n + ", " + reps + ": " + (float) t / 1e9 + " sec");
}
Also used : Random(java.util.Random) MatrixNd(maspack.matrix.MatrixNd)

Example 27 with MatrixNd

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

the class AffineNumericInputProbe method initTransform.

// initializes the identity transformation
public void initTransform(int size) {
    R = new MatrixNd(size, size);
    t = new VectorNd(size);
    R.setIdentity();
    t.setZero();
}
Also used : MatrixNd(maspack.matrix.MatrixNd) VectorNd(maspack.matrix.VectorNd)

Example 28 with MatrixNd

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

the class MLSShapeFunction method computeM.

public void computeM(MatrixNd M, Point3d pnt, MFreeNode3d[] nodeList) {
    MatrixNd cc = new MatrixNd(nBasis, nBasis);
    M.setSize(nBasis, nBasis);
    M.setZero();
    for (MFreeNode3d node : nodeList) {
        Point3d pos = node.getRestPosition();
        computePCorrelation(cc, pos.x, pos.y, pos.z);
        M.scaledAdd(node.getWeight(pnt), cc);
    }
}
Also used : MatrixNd(maspack.matrix.MatrixNd) Point3d(maspack.matrix.Point3d)

Example 29 with MatrixNd

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

the class MLSShapeFunction method computeDM.

public void computeDM(MatrixNd DM, int dIdx, Point3d pnt, MFreeNode3d[] nodeList) {
    MatrixNd cc = new MatrixNd(nBasis, nBasis);
    DM.setSize(nBasis, nBasis);
    DM.setZero();
    int[] derivatives = new int[3];
    derivatives[dIdx] = 1;
    for (MFreeNode3d node : nodeList) {
        Point3d pos = node.getRestPosition();
        computePCorrelation(cc, pos.x, pos.y, pos.z);
        DM.scaledAdd(node.getWeightFunction().evalDerivative(pnt, derivatives), cc);
    }
}
Also used : MatrixNd(maspack.matrix.MatrixNd) Point3d(maspack.matrix.Point3d)

Example 30 with MatrixNd

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

the class MLSShapeFunction method evalDerivative.

protected double evalDerivative(MFreeNode3d node, MFreeNode3d[] nodes, Point3d in, VectorNd pXi, double wx, int[] derivatives, MatrixNd MInv) {
    int dx = derivatives[0];
    int dy = derivatives[1];
    int dz = derivatives[2];
    double out = 0;
    VectorNd pTmp = new VectorNd(nBasis);
    MFreeWeightFunction fun = node.getWeightFunction();
    VectorNd p = new VectorNd(nBasis);
    computeP(p, in.x, in.y, in.z);
    if (dx + dy + dz == 1) {
        MatrixNd DMInv = new MatrixNd(nBasis, nBasis);
        VectorNd pk = new VectorNd(nBasis);
        double wk;
        if (dz == 1) {
            computeDMInv(DMInv, 2, MInv, in, nodes);
            computeDP(pk, in.x, in.y, in.z, 0, 0, 1);
            wk = fun.evalDerivative(in.x, in.y, in.z, 0, 0, 1);
        } else if (dy == 1) {
            computeDMInv(DMInv, 1, MInv, in, nodes);
            computeDP(pk, in.x, in.y, in.z, 0, 1, 0);
            wk = fun.evalDerivative(in.x, in.y, in.z, 0, 1, 0);
        } else {
            computeDMInv(DMInv, 0, MInv, in, nodes);
            computeDP(pk, in.x, in.y, in.z, 1, 0, 0);
            wk = fun.evalDerivative(in.x, in.y, in.z, 1, 0, 0);
        }
        pTmp.mulTranspose(MInv, pk);
        out = wx * pTmp.dot(pXi);
        pTmp.mulTranspose(DMInv, p);
        out += wx * pTmp.dot(pXi);
        pTmp.mulTranspose(MInv, p);
        out += wk * pTmp.dot(pXi);
        return out;
    } else if (dx + dy + dz == 2) {
        MatrixNd MklInv = new MatrixNd(nBasis, nBasis);
        MatrixNd MkInv = new MatrixNd(nBasis, nBasis);
        MatrixNd MlInv;
        VectorNd pkl = new VectorNd(nBasis);
        VectorNd pk = new VectorNd(nBasis);
        VectorNd pl;
        double wkl;
        double wk;
        double wl;
        if (dx == 1 && dy == 1) {
            computeDDMInv(MklInv, 0, 1, MInv, in, nodes);
            computeDMInv(MkInv, 0, MInv, in, nodes);
            MlInv = new MatrixNd(nBasis, nBasis);
            computeDM(MlInv, 1, in, nodes);
            computeDP(pkl, in.x, in.y, in.z, 1, 1, 0);
            computeDP(pk, in.x, in.y, in.z, 1, 0, 0);
            pl = new VectorNd(nBasis);
            computeDP(pl, in.x, in.y, in.z, 0, 1, 0);
            wkl = fun.evalDerivative(in.x, in.y, in.z, 1, 1, 0);
            wk = fun.evalDerivative(in.x, in.y, in.z, 1, 0, 0);
            wl = fun.evalDerivative(in.x, in.y, in.z, 0, 1, 0);
        } else if (dx == 1 && dz == 1) {
            computeDDMInv(MklInv, 0, 2, MInv, in, nodes);
            computeDMInv(MkInv, 0, MInv, in, nodes);
            MlInv = new MatrixNd(nBasis, nBasis);
            computeDM(MlInv, 2, in, nodes);
            computeDP(pkl, in.x, in.y, in.z, 1, 0, 1);
            computeDP(pk, in.x, in.y, in.z, 1, 0, 0);
            pl = new VectorNd(nBasis);
            computeDP(pl, in.x, in.y, in.z, 0, 0, 1);
            wkl = fun.evalDerivative(in.x, in.y, in.z, 1, 0, 1);
            wk = fun.evalDerivative(in.x, in.y, in.z, 1, 0, 0);
            wl = fun.evalDerivative(in.x, in.y, in.z, 0, 0, 1);
        } else if (dy == 1 && dz == 1) {
            computeDDMInv(MklInv, 1, 2, MInv, in, nodes);
            computeDMInv(MkInv, 1, MInv, in, nodes);
            MlInv = new MatrixNd(nBasis, nBasis);
            computeDM(MlInv, 2, in, nodes);
            computeDP(pkl, in.x, in.y, in.z, 0, 1, 1);
            computeDP(pk, in.x, in.y, in.z, 0, 1, 0);
            pl = new VectorNd(nBasis);
            computeDP(pl, in.x, in.y, in.z, 0, 0, 1);
            wkl = fun.evalDerivative(in.x, in.y, in.z, 0, 1, 1);
            wk = fun.evalDerivative(in.x, in.y, in.z, 0, 1, 0);
            wl = fun.evalDerivative(in.x, in.y, in.z, 0, 0, 1);
        } else if (dx == 2) {
            computeDDMInv(MklInv, 0, 0, MInv, in, nodes);
            computeDMInv(MkInv, 0, MInv, in, nodes);
            MlInv = MkInv;
            computeDP(pkl, in.x, in.y, in.z, 2, 0, 0);
            computeDP(pk, in.x, in.y, in.z, 1, 0, 0);
            pl = pk;
            wkl = fun.evalDerivative(in.x, in.y, in.z, 2, 0, 0);
            wk = fun.evalDerivative(in.x, in.y, in.z, 1, 0, 0);
            wl = wk;
        } else if (dy == 2) {
            computeDDMInv(MklInv, 1, 1, MInv, in, nodes);
            computeDMInv(MkInv, 1, MInv, in, nodes);
            MlInv = MkInv;
            computeDP(pkl, in.x, in.y, in.z, 0, 2, 0);
            computeDP(pk, in.x, in.y, in.z, 0, 1, 0);
            pl = pk;
            wkl = fun.evalDerivative(in.x, in.y, in.z, 0, 2, 0);
            wk = fun.evalDerivative(in.x, in.y, in.z, 0, 1, 0);
            wl = wk;
        } else {
            computeDDMInv(MklInv, 2, 2, MInv, in, nodes);
            computeDMInv(MkInv, 2, MInv, in, nodes);
            MlInv = MkInv;
            computeDP(pkl, in.x, in.y, in.z, 0, 0, 2);
            computeDP(pk, in.x, in.y, in.z, 0, 0, 1);
            pl = pk;
            wkl = fun.evalDerivative(in.x, in.y, in.z, 0, 0, 2);
            wk = fun.evalDerivative(in.x, in.y, in.z, 0, 0, 1);
            wl = wk;
        }
        pTmp.mulTranspose(MInv, pkl);
        out = wx * pTmp.dot(pXi);
        pTmp.mulTranspose(MlInv, pk);
        out += wx * pTmp.dot(pXi);
        pTmp.mulTranspose(MInv, pk);
        out += wl * pTmp.dot(pXi);
        pTmp.mulTranspose(MkInv, pl);
        out += wx * pTmp.dot(pXi);
        pTmp.mulTranspose(MklInv, p);
        out += wx * pTmp.dot(pXi);
        pTmp.mulTranspose(MkInv, p);
        out += wl * pTmp.dot(pXi);
        pTmp.mulTranspose(MInv, pl);
        out += wk * pTmp.dot(pXi);
        pTmp.mulTranspose(MlInv, p);
        out += wk * pTmp.dot(pXi);
        pTmp.mulTranspose(MInv, p);
        out += wkl * pTmp.dot(pXi);
        return out;
    }
    throw new IllegalArgumentException("Derivatives only defined up to second-order");
}
Also used : MatrixNd(maspack.matrix.MatrixNd) VectorNd(maspack.matrix.VectorNd)

Aggregations

MatrixNd (maspack.matrix.MatrixNd)37 Point3d (maspack.matrix.Point3d)9 VectorNd (maspack.matrix.VectorNd)9 SparseMatrixNd (maspack.matrix.SparseMatrixNd)4 Vector3d (maspack.matrix.Vector3d)4 LUDecomposition (maspack.matrix.LUDecomposition)3 RigidTransform3d (maspack.matrix.RigidTransform3d)2 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)2 Point (artisynth.core.mechmodels.Point)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 StringReader (java.io.StringReader)1 Random (java.util.Random)1 CholeskyDecomposition (maspack.matrix.CholeskyDecomposition)1 DenseMatrix (maspack.matrix.DenseMatrix)1 Matrix (maspack.matrix.Matrix)1 Matrix3d (maspack.matrix.Matrix3d)1 Matrix6d (maspack.matrix.Matrix6d)1 Matrix6dBase (maspack.matrix.Matrix6dBase)1