Search in sources :

Example 51 with VectorNd

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

the class MFreeMeshComp method updateVertexColors.

protected void updateVertexColors() {
    if (mySurfaceRendering != SurfaceRender.Stress && mySurfaceRendering != SurfaceRender.Strain) {
        return;
    }
    if (myStressPlotRanging == Ranging.Auto) {
        myStressPlotRange.merge(myModel.getNodalPlotRange(mySurfaceRendering));
    }
    RenderProps rprops = getRenderProps();
    float alpha = (float) rprops.getAlpha();
    MeshBase mesh = getMesh();
    double sval = 0;
    for (int i = 0; i < myVertexAttachments.size(); i++) {
        PointAttachment attacher = myVertexAttachments.get(i);
        sval = 0;
        if (attacher instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
            FemNode[] nodes = pfa.getNodes();
            VectorNd weights = pfa.getCoordinates();
            for (int j = 0; j < nodes.length; j++) {
                if (nodes[j] instanceof MFreeNode3d) {
                    // paranoid!
                    MFreeNode3d node = (MFreeNode3d) nodes[j];
                    double w = weights.get(j);
                    if (mySurfaceRendering == SurfaceRender.Strain) {
                        sval += w * node.getVonMisesStrain();
                    } else if (mySurfaceRendering == SurfaceRender.Stress) {
                        sval += w * node.getVonMisesStress();
                    }
                }
            }
        } else if (attacher instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) attacher;
            MFreeNode3d node = (MFreeNode3d) ppa.getParticle();
            if (mySurfaceRendering == SurfaceRender.Strain) {
                sval = node.getVonMisesStrain();
            } else if (mySurfaceRendering == SurfaceRender.Stress) {
                sval = node.getVonMisesStress();
            }
        }
        double smin = myStressPlotRange.getLowerBound();
        double srng = myStressPlotRange.getRange();
        double c = (sval - smin) / srng;
        c = Math.max(0, Math.min(c, 1.0));
        myColorMap.getRGB(c, colorArray);
        mesh.setColor(i, colorArray[0], colorArray[1], colorArray[2], alpha);
    }
}
Also used : FemNode(artisynth.core.femmodels.FemNode) RenderProps(maspack.render.RenderProps) MeshBase(maspack.geometry.MeshBase) FemMeshBase(artisynth.core.femmodels.FemMeshBase) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 52 with VectorNd

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

the class MFreeModel3d method updateNodeMasses.

public void updateNodeMasses(double totalMass, VectorNd massMatrixDiag) {
    if (totalMass <= 0) {
        totalMass = integrateMass();
    }
    if (massMatrixDiag == null) {
        SparseMatrixNd massMatrix = computeConsistentMassMatrix();
        massMatrixDiag = new VectorNd(massMatrix.rowSize());
        for (int i = 0; i < massMatrix.rowSize(); i++) {
            double rowSum = 0;
            for (int j = 0; j < massMatrix.colSize(); j++) {
                rowSum += massMatrix.get(i, j);
            }
            // rowSum += massMatrix.get(i, i);
            massMatrixDiag.set(i, rowSum);
        }
    }
    double mTrace = massMatrixDiag.sum();
    for (FemNode3d node : myNodes) {
        int i = node.getNumber();
        double m = totalMass / mTrace * massMatrixDiag.get(i);
        node.setMass(m);
        node.setMassExplicit(true);
    }
}
Also used : SparseMatrixNd(maspack.matrix.SparseMatrixNd) VectorNd(maspack.matrix.VectorNd) FemNode3d(artisynth.core.femmodels.FemNode3d) Point(artisynth.core.mechmodels.Point)

Example 53 with VectorNd

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

the class MFreeModel3d method integrate.

public double integrate(Function3x1 fun) {
    double out = 0;
    if (!myStiffnessesValidP) {
        updateJacobians();
    }
    for (FemElement3d elem : myElements) {
        IntegrationPoint3d[] ipnts = elem.getIntegrationPoints();
        IntegrationData3d[] idata = elem.getIntegrationData();
        for (int i = 0; i < elem.numIntegrationPoints(); i++) {
            IntegrationPoint3d ipnt = ipnts[i];
            IntegrationData3d idat = idata[i];
            VectorNd shapeFunc = ipnt.getShapeWeights();
            for (int j = 0; j < elem.numNodes(); j++) {
                // if (elem.isTermActive(j, j)) {
                double f = fun.eval(((MFreePoint3d) ipnt).getPosition()) * ipnt.getWeight() * shapeFunc.get(j);
                f = f * ipnt.getDetF() * idat.getDetJ0();
                out += f;
            // }
            }
        }
    }
    return out;
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) VectorNd(maspack.matrix.VectorNd) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d) Point(artisynth.core.mechmodels.Point)

Example 54 with VectorNd

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

the class ParticleConstraintNdBase method updateEngagement.

protected double updateEngagement(ParticleInfo pi, double maxpen) {
    boolean oldEngaged = pi.myEngagedP;
    boolean engaged = false;
    VectorNd vr = new VectorNd(pi.myDist.length);
    VectorNd v = new VectorNd(pi.myPart.getVelocity());
    pi.myBlk.mul(vr, v);
    for (int j = 0; j < pi.myDist.length; ++j) {
        if (pi.myDist[j] < 0) {
            engaged = true;
            if (-pi.myDist[j] > maxpen) {
                maxpen = -pi.myDist[j];
            }
        }
    }
    // check if sufficient velocity to break
    if (oldEngaged && !engaged) {
        boolean breakEngagement = false;
        for (int j = 0; j < pi.myDist.length; ++j) {
            if (vr.get(j) > myBreakSpeed) {
                breakEngagement = true;
            }
        }
        if (breakEngagement) {
            pi.myEngagedP = false;
        }
    } else if (engaged) {
        pi.myEngagedP = true;
    }
    return maxpen;
}
Also used : VectorNd(maspack.matrix.VectorNd)

Example 55 with VectorNd

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

the class GMLSShapeFunction method eval.

@Override
public double eval(MFreeNode3d node, MFreeNode3d[] nodes, Point3d pnt, MatrixNd MInv) {
    VectorNd _p = new VectorNd(nBasis);
    VectorNd pi = new VectorNd(nBasis);
    computePtMInv(_p, MInv, pnt, nodes);
    Point3d xi = node.getRestPosition();
    computeDP(pi, xi.x, xi.y, xi.z, myDerivativeIdxs[0], myDerivativeIdxs[1], myDerivativeIdxs[2]);
    _p.scale(node.getWeight(pnt));
    return _p.dot(pi);
}
Also used : Point3d(maspack.matrix.Point3d) 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