Search in sources :

Example 1 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method createPointAttachment.

public PointFem3dAttachment createPointAttachment(Point pnt) {
    if (!(getMesh() instanceof PolygonalMesh)) {
        return null;
    }
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    if (!mesh.isTriangular()) {
        return null;
    }
    // Find nearest face to the point. The vertices of this face will be used
    // to find the nodes and weight for the attachment.
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d near = new Point3d();
    Vector2d uv = new Vector2d();
    Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
    Vertex3d[] vtxs = face.getTriVertices();
    double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
    HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
    for (int i = 0; i < vtxs.length; i++) {
        PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
        if (va instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) va;
            FemNode node = (FemNode) ppa.getParticle();
            accumulateNodeWeights(node, wgts[i], nodeWeights);
        } else if (va instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) va;
            for (int k = 0; k < pfa.numMasters(); k++) {
                FemNode node = pfa.getNodes()[k];
                double w = pfa.getCoordinate(k);
                accumulateNodeWeights(node, w * wgts[i], nodeWeights);
            }
        }
    }
    // Create a new PointFem3dAttachment
    PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
    VectorNd weightVec = new VectorNd();
    for (Double d : nodeWeights.values()) {
        weightVec.append(d);
    }
    ax.setFromNodes(nodeWeights.keySet(), weightVec);
    return ax;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 2 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method addVertexNodes.

private void addVertexNodes(HashSet<FemNode3d> nodes, Vertex3d vtx) {
    PointAttachment pa = getAttachment(vtx.getIndex());
    if (pa instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
        FemNode[] masters = pfa.getNodes();
        for (int j = 0; j < masters.length; j++) {
            nodes.add((FemNode3d) masters[j]);
        }
    } else {
        PointParticleAttachment ppa = (PointParticleAttachment) pa;
        nodes.add((FemNode3d) ppa.getParticle());
    }
}
Also used : PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 3 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method copy.

@Override
public FemMeshComp copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
    FemMeshComp fm = (FemMeshComp) super.copy(flags, copyMap);
    FemModel3d newFem = (FemModel3d) copyMap.get(myFem);
    if (newFem != null) {
        fm.myFem = newFem;
    } else {
        fm.myFem = myFem;
    }
    HashMap<Vertex3d, Vertex3d> vertMap = null;
    if (getMesh() != fm.getMesh()) {
        vertMap = new HashMap<Vertex3d, Vertex3d>(myMeshInfo.numVertices());
        for (int i = 0; i < myMeshInfo.numVertices(); i++) {
            vertMap.put(getVertex(i), fm.getVertex(i));
        }
    }
    fm.myVertexAttachments = new ArrayList<PointAttachment>(myVertexAttachments.size());
    for (PointAttachment pa : myVertexAttachments) {
        PointAttachment newPa = pa.copy(flags, copyMap);
        fm.myVertexAttachments.add(newPa);
    }
    fm.buildNodeVertexMap();
    // fm.myEdgeVtxs = new HashMap<EdgeDesc,Vertex3d[]>(myEdgeVtxs.size());
    // for (Entry<EdgeDesc,Vertex3d[]> het : myEdgeVtxs.entrySet()) {
    // het.getKey();
    // Vertex3d[] oldVerts = het.getValue();
    // EdgeDesc newEdge = het.getKey().copy(vertMap);
    // Vertex3d[] newVerts = new Vertex3d[oldVerts.length];
    // 
    // if (vertMap != null) {
    // for (int i=0; i<newVerts.length; i++) {
    // newVerts[i] = vertMap.get(oldVerts[i]);
    // }
    // } else {
    // for (int i=0; i<newVerts.length; i++) {
    // newVerts[i] = oldVerts[i];
    // }
    // }
    // fm.myEdgeVtxs.put(newEdge, newVerts);
    // }
    fm.isSurfaceMesh = isSurfaceMesh();
    return fm;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) PointAttachment(artisynth.core.mechmodels.PointAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 4 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class MFreeFactory method cloneFem.

public static MFreeModel3d cloneFem(MFreeModel3d model, FemModel3d fem) {
    if (model == null) {
        model = new MFreeModel3d();
    }
    HashMap<FemNode3d, MFreeNode3d> nodeMap = new HashMap<FemNode3d, MFreeNode3d>();
    HashMap<MFreeNode3d, FemNode3d> nodeMapInv = new HashMap<MFreeNode3d, FemNode3d>();
    ArrayList<MFreeNode3d> nodeList = new ArrayList<MFreeNode3d>();
    // duplicate nodes
    for (FemNode3d node : fem.getNodes()) {
        MFreeNode3d mnode = new MFreeNode3d(node.getRestPosition());
        // explicit node masses
        mnode.setMassExplicit(true);
        mnode.setMass(node.getMass());
        MFreeNode3d[] deps = new MFreeNode3d[1];
        deps[0] = mnode;
        VectorNd coords = new VectorNd(new double[] { 1 });
        mnode.setDependentNodes(deps, coords);
        nodeMap.put(node, mnode);
        nodeMapInv.put(mnode, node);
        nodeList.add(mnode);
    }
    // convert surface mesh
    FemMeshComp surfaceFem = fem.getSurfaceMeshComp();
    PolygonalMesh mesh = (PolygonalMesh) surfaceFem.getMesh();
    // build mesh
    PolygonalMesh mesh2 = mesh.copy();
    // index vertices
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(idx++);
    }
    idx = 0;
    for (Vertex3d vtx : mesh2.getVertices()) {
        vtx.setIndex(idx++);
    }
    MFreeMeshComp surfaceMFree = new MFreeMeshComp(model, "surface");
    surfaceMFree.setMesh(mesh2);
    // manually build surface attachments
    for (Vertex3d vtx : mesh.getVertices()) {
        PointAttachment pa = surfaceFem.getAttachment(vtx.getIndex());
        if (pa instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
            FemNode[] masters = pfa.getNodes();
            MFreeNode3d[] deps = new MFreeNode3d[masters.length];
            VectorNd coords = new VectorNd(masters.length);
            for (int j = 0; j < masters.length; j++) {
                // mlist.add (new ContactMaster (masters[j], pfa.getCoordinate(j)));
                deps[j] = nodeMap.get(masters[j]);
                coords.set(j, pfa.getCoordinate(j));
            }
            surfaceMFree.setVertexAttachment(vtx.getIndex(), coords.getBuffer(), deps);
        } else {
            PointParticleAttachment ppa = (PointParticleAttachment) pa;
            DynamicComponent[] masters = ppa.getMasters();
            MFreeNode3d[] deps = new MFreeNode3d[1];
            deps[0] = nodeMap.get(masters[0]);
            VectorNd coords = new VectorNd(new double[] { 1 });
            surfaceMFree.setVertexAttachment(vtx.getIndex(), coords.getBuffer(), deps);
        }
    }
    // integration regions by copying elements
    ArrayList<MFreeElement3d> elemList = new ArrayList<MFreeElement3d>(fem.numElements());
    HashMap<FemElement3d, MFreeElement3d> elemMap = new HashMap<FemElement3d, MFreeElement3d>(fem.numElements());
    for (FemElement3d elem : fem.getElements()) {
        MFreeNode3d[] elemNodes = new MFreeNode3d[elem.numNodes()];
        FemNode3d[] fnodes = elem.getNodes();
        for (int i = 0; i < elem.numNodes(); i++) {
            elemNodes[i] = nodeMap.get(fnodes[i]);
        }
        MFreeElement3d region = new MFreeElement3d(null, elemNodes);
        // region.setAllTermsActive(true);
        MFreeIntegrationPoint3d[] mpnts = new MFreeIntegrationPoint3d[elem.numIntegrationPoints()];
        IntegrationData3d[] mdata = new IntegrationData3d[elem.numIntegrationPoints()];
        IntegrationPoint3d[] ipnts = elem.getIntegrationPoints();
        IntegrationData3d[] idata = elem.getIntegrationData();
        for (int i = 0; i < ipnts.length; i++) {
            Point3d pos = new Point3d();
            ipnts[i].computePosition(pos, elem.getNodes());
            Vector3d[] gradU = ipnts[i].getGNs();
            ArrayList<Vector3d> grads = new ArrayList<Vector3d>();
            for (Vector3d g : gradU) {
                grads.add(g);
            }
            MFreeIntegrationPoint3d mpnt = MFreeIntegrationPoint3d.create(elemNodes, ipnts[i].getShapeWeights(), grads, ipnts[i].getWeight());
            IntegrationData3d mdat = new IntegrationData3d();
            mdat.setRestInverseJacobian(idata[i].getInvJ0(), idata[i].getDetJ0());
            mpnts[i] = mpnt;
            mdata[i] = mdat;
        }
        // set warping point
        if (region.getWarpingPoint() == null) {
            IntegrationPoint3d wpnt = elem.getWarpingPoint();
            IntegrationData3d wdat = elem.getWarpingData();
            Point3d pos = new Point3d();
            wpnt.computePosition(pos, elem.getNodes());
            // Vector3d [] gradU = wpnt.updateShapeGradient(wdat.getInvJ0());
            Vector3d[] gradU = wpnt.getGNs();
            ArrayList<Vector3d> grads = new ArrayList<Vector3d>();
            for (Vector3d g : gradU) {
                grads.add(g);
            }
            // MFreeIntegrationPoint3d mpnt =
            // MFreeIntegrationPoint3d.create(pos, deps,
            // wpnt.getShapeWeights(), grads, wpnt.getWeight()*wdat.getDetJ0());
            MFreeIntegrationPoint3d mpnt = MFreeIntegrationPoint3d.create(elemNodes, wpnt.getShapeWeights(), grads, wpnt.getWeight());
            region.setWarpingPoint(mpnt);
            IntegrationData3d wdata = new IntegrationData3d();
            wdata.setRestInverseJacobian(wdat.getInvJ0(), wdat.getDetJ0());
            region.setWarpingPoint(mpnt, wdata);
        }
        region.setIntegrationPoints(mpnts, mdata);
        elemList.add(region);
        elemMap.put(elem, region);
    }
    // add everything to model
    model.addNodes(nodeList);
    model.addElements(elemList);
    model.setSurfaceMeshComp(surfaceMFree);
    // copy properties
    model.setDensity(fem.getDensity());
    model.setParticleDamping(fem.getParticleDamping());
    model.setStiffnessDamping(fem.getStiffnessDamping());
    // copy over all masses
    for (FemNode3d node : fem.getNodes()) {
        nodeMap.get(node).setMass(node.getMass());
    }
    for (FemElement3d elem : fem.getElements()) {
        elemMap.get(elem).setMass(elem.getMass());
    }
    model.setMaterial(fem.getMaterial());
    return model;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PointAttachment(artisynth.core.mechmodels.PointAttachment) IntegrationData3d(artisynth.core.femmodels.IntegrationData3d) PolygonalMesh(maspack.geometry.PolygonalMesh) Point3d(maspack.matrix.Point3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) FemNode3d(artisynth.core.femmodels.FemNode3d) DynamicComponent(artisynth.core.mechmodels.DynamicComponent) FemNode(artisynth.core.femmodels.FemNode) FemElement3d(artisynth.core.femmodels.FemElement3d) FemMeshComp(artisynth.core.femmodels.FemMeshComp) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) Vector3d(maspack.matrix.Vector3d) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 5 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method buildNodeVertexMap.

protected void buildNodeVertexMap() {
    myNodeVertexMap = new HashMap<MFreeNode3d, Vertex3d>();
    myNumSingleAttachments = 0;
    for (int i = 0; i < myVertexAttachments.size(); i++) {
        PointAttachment pa = myVertexAttachments.get(i);
        if (pa instanceof PointParticleAttachment) {
            MFreeNode3d node = (MFreeNode3d) ((PointParticleAttachment) pa).getParticle();
            myNodeVertexMap.put(node, getMesh().getVertex(i));
            myNumSingleAttachments++;
        } else if (pa instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
            for (FemNode node : pfa.getNodes()) {
                if (myNodeVertexMap.get(node) == null) {
                    myNodeVertexMap.put((MFreeNode3d) node, NO_SINGLE_VERTEX);
                }
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FemNode(artisynth.core.femmodels.FemNode) 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)

Aggregations

PointAttachment (artisynth.core.mechmodels.PointAttachment)21 ContactPoint (artisynth.core.mechmodels.ContactPoint)17 Point (artisynth.core.mechmodels.Point)17 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)16 Vertex3d (maspack.geometry.Vertex3d)10 FemNode (artisynth.core.femmodels.FemNode)9 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)9 VectorNd (maspack.matrix.VectorNd)7 PolygonalMesh (maspack.geometry.PolygonalMesh)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Face (maspack.geometry.Face)3 Point3d (maspack.matrix.Point3d)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 ContactMaster (artisynth.core.mechmodels.ContactMaster)2 DynamicComponent (artisynth.core.mechmodels.DynamicComponent)2 IOException (java.io.IOException)2 BVFeatureQuery (maspack.geometry.BVFeatureQuery)2 MeshBase (maspack.geometry.MeshBase)2 Vector2d (maspack.matrix.Vector2d)2