Search in sources :

Example 11 with Matrix3d

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

the class FemMuscleModel method computeAverageFiberDirection.

/**
 * Computes the average fiber direction in the vicinity of a point based on
 * the line segments contained in a PolylineMesh. Returns the number of
 * supporting line segments used for the calculation. If no segments were
 * found, the method returns 0 and the direction is undefined.
 *
 * @param dir returns the normalized direction
 * @param pos position at which direction should be computed
 * @param rad radius of influence within which polyline mesh segments are
 * considerd
 * @param mesh mesh containing line segments used to determine the direction
 * @return number of supporting line segment
 */
public static int computeAverageFiberDirection(Vector3d dir, Point3d pos, double rad, PolylineMesh mesh) {
    BVTree bvh = mesh.getBVTree();
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    Matrix3d cov = new Matrix3d();
    SVDecomposition3d svd = new SVDecomposition3d();
    Vector3d tmp = new Vector3d();
    Matrix3d tmp2 = new Matrix3d();
    bvh.intersectSphere(nodes, pos, rad);
    dir.setZero();
    int nsegs = 0;
    // for computing sign of direction vector
    Vector3d segmentSum = new Vector3d();
    // System.out.println("p=[");
    for (BVNode n : nodes) {
        Boundable[] elements = n.getElements();
        for (int i = 0; i < elements.length; i++) {
            LineSegment seg = (LineSegment) elements[i];
            seg = getSegmentInsideSphere(seg, pos, rad);
            if (seg != null) {
                tmp.sub(seg.myVtx1.pnt, seg.myVtx0.pnt);
                if (tmp.norm() >= 1e-8 * rad) {
                    // System.out.println(seg.myVtx0.getPosition() + " " +
                    // seg.myVtx1.getPosition());
                    nsegs++;
                    // prepare to average directions using SVD
                    computeCov(tmp2, tmp);
                    cov.add(tmp2);
                    segmentSum.add(tmp);
                }
            }
        }
    }
    if (nsegs > 0) {
        // we are technically including both +/- directions, so
        // we have twice the number of points
        cov.scale(2.0 / (2.0 * nsegs - 1));
        try {
            svd.factor(cov);
        } catch (Exception e) {
        // System.err.println(e.getMessage());
        }
        // principal components
        tmp2 = svd.getU();
        tmp2.getColumn(0, dir);
        dir.normalize();
        // most line segments
        if (dir.dot(segmentSum) < 0) {
            dir.scale(-1);
        }
        return nsegs;
    } else {
        return 0;
    }
}
Also used : BVTree(maspack.geometry.BVTree) Matrix3d(maspack.matrix.Matrix3d) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Vector3d(maspack.matrix.Vector3d) BVNode(maspack.geometry.BVNode) ArrayList(java.util.ArrayList) SVDecomposition3d(maspack.matrix.SVDecomposition3d) Boundable(maspack.geometry.Boundable) IOException(java.io.IOException) LineSegment(maspack.geometry.LineSegment)

Example 12 with Matrix3d

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

the class LinearMaterialCache method addInitialStiffness.

/**
 * Computes and stores the initial stiffness K0 and force f0 terms
 * @param e   element
 * @param mat linear material
 */
public void addInitialStiffness(FemElement3d e, FemMaterial mat) {
    SolidDeformation def = new SolidDeformation();
    def.setAveragePressure(0);
    def.setF(Matrix3d.IDENTITY);
    def.setR(Matrix3d.IDENTITY);
    // compute stiffness matrix
    Matrix6d D = new Matrix6d();
    IntegrationPoint3d[] ipnts = e.getIntegrationPoints();
    IntegrationData3d[] idata = e.getIntegrationData();
    for (int k = 0; k < ipnts.length; k++) {
        IntegrationPoint3d pt = ipnts[k];
        IntegrationData3d dt = idata[k];
        double dv0 = dt.myDetJ0 * pt.getWeight();
        if (dt.myScaling != 1) {
            dv0 *= dt.myScaling;
        }
        Matrix3d Q = dt.myFrame == null ? Matrix3d.IDENTITY : dt.myFrame;
        Vector3d[] GNx0 = pt.updateShapeGradient(dt.myInvJ0);
        // compute tangent matrix under zero stress
        mat.computeTangent(D, SymmetricMatrix3d.ZERO, def, Q, null);
        FemNode3d[] nodes = e.getNodes();
        for (int i = 0; i < nodes.length; i++) {
            for (int j = 0; j < nodes.length; j++) {
                FemUtilities.addMaterialStiffness(K0[i][j], GNx0[i], D, GNx0[j], dv0);
            }
        }
    }
    // initial RHS
    Vector3d tmp = new Vector3d();
    FemNode3d[] nodes = e.getNodes();
    for (int i = 0; i < nodes.length; i++) {
        tmp.setZero();
        for (int j = 0; j < nodes.length; j++) {
            K0[i][j].mulAdd(tmp, nodes[j].getRestPosition(), tmp);
        }
        f0[i].set(tmp);
    }
}
Also used : Matrix6d(maspack.matrix.Matrix6d) SolidDeformation(artisynth.core.materials.SolidDeformation) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix3d(maspack.matrix.Matrix3d) Vector3d(maspack.matrix.Vector3d)

Example 13 with Matrix3d

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

the class FemNodeNeighbor method addPressureStiffness.

public void addPressureStiffness(Vector3d gi, double p, Vector3d gj, double dv) {
    if (FemModel3d.noIncompressStiffnessDamping) {
        if (myKX == null) {
            myKX = new Matrix3d();
        }
        FemUtilities.addPressureStiffness(myKX, gi, p, gj, dv);
        FemUtilities.addPressureStiffness(myK, gi, -p, gj, dv);
    }
}
Also used : SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix3d(maspack.matrix.Matrix3d)

Example 14 with Matrix3d

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

the class NeoHookeanMaterial method main.

public static void main(String[] args) {
    NeoHookeanMaterial mat = new NeoHookeanMaterial();
    SolidDeformation def = new SolidDeformation();
    Matrix3d Q = new Matrix3d();
    def.setF(new Matrix3d(1, 3, 5, 2, 1, 4, 6, 1, 2));
    Matrix6d D = new Matrix6d();
    SymmetricMatrix3d sig = new SymmetricMatrix3d();
    mat.setYoungsModulus(10);
    mat.computeStress(sig, def, Q, null);
    mat.computeTangent(D, sig, def, Q, null);
    System.out.println("sig=\n" + sig.toString("%12.6f"));
    System.out.println("D=\n" + D.toString("%12.6f"));
}
Also used : SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix3d(maspack.matrix.Matrix3d) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix6d(maspack.matrix.Matrix6d)

Example 15 with Matrix3d

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

the class OgdenMaterial method main.

public static void main(String[] args) {
    OgdenMaterial mat = new OgdenMaterial();
    SolidDeformation def = new SolidDeformation();
    Matrix3d Q = new Matrix3d();
    def.setF(new Matrix3d(1.1, 0.1, 0.2, 0.3, 0.8, 0.23, 0.3, 0.1, 1.5));
    Matrix6d D = new Matrix6d();
    SymmetricMatrix3d sig = new SymmetricMatrix3d();
    // double[] alpha = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
    // double[] mu = {200.0, 0.0, 0.0, 0.0, 0.0, 0.0};
    mat.computeStress(sig, def, Q, null);
    System.out.println("sig=\n" + sig.toString("%12.6f"));
    mat.computeTangent(D, sig, def, Q, null);
    System.out.println("D=\n" + D.toString("%12.6f"));
}
Also used : SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix3d(maspack.matrix.Matrix3d) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix6d(maspack.matrix.Matrix6d)

Aggregations

Matrix3d (maspack.matrix.Matrix3d)64 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)42 Vector3d (maspack.matrix.Vector3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)22 Matrix6d (maspack.matrix.Matrix6d)15 Point3d (maspack.matrix.Point3d)9 RigidTransform3d (maspack.matrix.RigidTransform3d)7 SVDecomposition3d (maspack.matrix.SVDecomposition3d)7 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)6 AffineTransform3d (maspack.matrix.AffineTransform3d)4 VectorNd (maspack.matrix.VectorNd)4 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)3 SolidDeformation (artisynth.core.materials.SolidDeformation)3 FemMaterial (artisynth.core.materials.FemMaterial)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BVNode (maspack.geometry.BVNode)2 BVTree (maspack.geometry.BVTree)2 Boundable (maspack.geometry.Boundable)2 LineSegment (maspack.geometry.LineSegment)2