Search in sources :

Example 21 with VectorNd

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

the class FemMeshComp method createVertex.

private Vertex3d createVertex(double s0, double s1, double s2, FemElement3d elem, FemNode3d n0, FemNode3d n1, FemNode3d n2) {
    Vector3d coords = new Vector3d();
    addNodeCoords(coords, s0, s1, s2, elem, n0, n1, n2);
    addNodeCoords(coords, s1, s0, s2, elem, n1, n0, n2);
    if (n2 != null) {
        addNodeCoords(coords, s2, s1, s0, elem, n2, n1, n0);
    }
    ArrayList<FemNode> nodes = new ArrayList<FemNode>();
    VectorNd weights = new VectorNd();
    Point3d pos = new Point3d();
    for (int i = 0; i < elem.numNodes(); i++) {
        double w = elem.getN(i, coords);
        if (Math.abs(w) > EPS) {
            FemNode3d n = elem.getNodes()[i];
            nodes.add(n);
            weights.append(w);
            pos.scaledAdd(w, n.getPosition());
        }
    }
    Vertex3d vtx = new Vertex3d(pos);
    PointFem3dAttachment attacher = new PointFem3dAttachment();
    attacher.setFromNodes(nodes, weights);
    myVertexAttachments.add(attacher);
    getMesh().addVertex(vtx);
    return vtx;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) VectorNd(maspack.matrix.VectorNd) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 22 with VectorNd

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

the class PointFem3dAttachment method dosetNodes.

private void dosetNodes(FemNode[] nodes, double[] weights) {
    if (nodes.length == 0) {
        throw new IllegalArgumentException("Must have at least one node");
    }
    if (nodes.length > weights.length) {
        throw new IllegalArgumentException("Number of weights is less than the number of nodes");
    }
    removeBackRefsIfConnected();
    myCoords = new VectorNd(nodes.length);
    myNodes = new FemNode[nodes.length];
    for (int i = 0; i < nodes.length; i++) {
        myNodes[i] = nodes[i];
        if (weights != null) {
            myCoords.set(i, weights[i]);
        }
    }
    invalidateMasters();
    addBackRefsIfConnected();
    notifyParentOfChange(DynamicActivityChangeEvent.defaultEvent);
}
Also used : VectorNd(maspack.matrix.VectorNd) Point(artisynth.core.mechmodels.Point)

Example 23 with VectorNd

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

the class PointFem3dAttachment method create.

/**
 * Create an attachment that connects a point to a FemElement
 * within a specified element.
 *
 * @param pnt Point to be attached
 * @param elem FemElement3d to attach the point to
 * @param loc point location with respect to the element. If <code>null</code>,
 * will be assumed to be pnt.getPosition().
 * @param reduceTol try to reduce the number of attached nodes by
 * removing those whose coordinate values are less then this number.
 * A value of zero ensures no reduction. If reduction is desired,
 * a value around 1e-5 is reasonable.
 * @return an attachment for
 */
public static PointFem3dAttachment create(Point pnt, FemElement3d elem, Point3d loc, double reduceTol) {
    PointFem3dAttachment ax = null;
    // Figure out the coordinates for the attachment point
    VectorNd coords = new VectorNd(elem.numNodes());
    elem.getMarkerCoordinates(coords, loc != null ? loc : pnt.getPosition(), false);
    // if (reduceTol > 0) {
    // FemNode3d[] nodes = elem.getNodes();
    // // Find number of coordinates which are close to zero
    // int numZero = 0;
    // for (int i=0; i<elem.numNodes(); i++) {
    // if (Math.abs(coords.get(i)) < reduceTol) {
    // numZero++;
    // }
    // }
    // // If we have coordinates close to zero, and the number of remaining
    // // coords is <= 4, then specify the nodes and coords explicitly
    // if (numZero > 0 && elem.numNodes()-numZero <= 4) {
    // int numc = elem.numNodes()-numZero;
    // double[] reducedCoords = new double[numc];
    // FemNode3d[] reducedNodes = new FemNode3d[numc];
    // int k = 0;
    // for (int i=0; i<elem.numNodes(); i++) {
    // if (Math.abs(coords.get(i)) >= reduceTol) {
    // reducedCoords[k] = coords.get(i);
    // reducedNodes[k] = nodes[i];
    // k++;
    // }
    // }
    // ax = new PointFem3dAttachment (pnt);
    // ax.setFromNodes (reducedNodes, reducedCoords);
    // return ax;
    // }
    // }
    ax = new PointFem3dAttachment(pnt);
    ax.setFromElement(pnt.getPosition(), elem, reduceTol);
    // ax.myCoords.set (coords);
    return ax;
}
Also used : VectorNd(maspack.matrix.VectorNd)

Example 24 with VectorNd

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

the class PointFem3dAttachment method setFromNodes.

public boolean setFromNodes(Point3d pos, FemNode[] nodes) {
    ArrayList<Vector3d> support = new ArrayList<Vector3d>(nodes.length);
    for (int i = 0; i < nodes.length; i++) {
        support.add(nodes[i].getPosition());
    }
    InverseDistanceWeights idweights = new InverseDistanceWeights(1, 1, /*normalize=*/
    true);
    VectorNd weights = new VectorNd();
    boolean status = idweights.compute(weights, pos, support);
    dosetNodes(nodes, weights.getBuffer());
    myElement = null;
    return status;
}
Also used : Vector3d(maspack.matrix.Vector3d) ArrayList(java.util.ArrayList) VectorNd(maspack.matrix.VectorNd) InverseDistanceWeights(maspack.geometry.InverseDistanceWeights) Point(artisynth.core.mechmodels.Point)

Example 25 with VectorNd

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

the class ForceTargetTerm method getTargetWeights.

public VectorNd getTargetWeights() {
    VectorNd out = new VectorNd(myForceTargets.size());
    getTargetWeights(out);
    return out;
}
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