Search in sources :

Example 6 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment 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 7 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method postscanItem.

protected boolean postscanItem(Deque<ScanToken> tokens, CompositeComponent ancestor) throws IOException {
    if (postscanAttributeName(tokens, "fem")) {
        myModel = postscanReference(tokens, MFreeModel3d.class, ancestor);
        return true;
    } else if (postscanAttributeName(tokens, "attachments")) {
        for (int i = 0; i < myVertexAttachments.size(); i++) {
            PointAttachment va = myVertexAttachments.get(i);
            FemNode[] nodes = ScanWriteUtils.postscanReferences(tokens, FemNode.class, ancestor);
            if (va instanceof PointParticleAttachment) {
                PointParticleAttachment ppa = (PointParticleAttachment) va;
                ppa.setParticle(nodes[0]);
            } else if (va instanceof PointFem3dAttachment) {
                PointFem3dAttachment pfa = (PointFem3dAttachment) va;
                double[] coords = (double[]) tokens.poll().value();
                pfa.setFromNodes(nodes, coords);
            }
        }
        buildNodeVertexMap();
        return true;
    }
    return super.postscanItem(tokens, ancestor);
}
Also used : FemNode(artisynth.core.femmodels.FemNode) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 8 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method getVertexMasters.

public void getVertexMasters(List<ContactMaster> mlist, 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++) {
            mlist.add(new ContactMaster(masters[j], pfa.getCoordinate(j)));
        }
    } else {
        PointParticleAttachment ppa = (PointParticleAttachment) pa;
        mlist.add(new ContactMaster((MFreeNode3d) ppa.getParticle(), 1));
    }
}
Also used : FemNode(artisynth.core.femmodels.FemNode) ContactMaster(artisynth.core.mechmodels.ContactMaster) 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 9 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method writeAttachment.

protected void writeAttachment(PointAttachment attacher, PrintWriter pw, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
    pw.print("[ ");
    if (attacher instanceof PointParticleAttachment) {
        PointParticleAttachment ppa = (PointParticleAttachment) attacher;
        FemNode node = (FemNode) ppa.getParticle();
        pw.print(ComponentUtils.getWritePathName(ancestor, node) + " 1 ");
    } else if (attacher instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
        FemNode[] nodes = pfa.getNodes();
        VectorNd weights = pfa.getCoordinates();
        for (int i = 0; i < nodes.length; i++) {
            pw.print(ComponentUtils.getWritePathName(ancestor, nodes[i]) + " " + fmt.format(weights.get(i)) + " ");
        }
    }
    pw.println("]");
}
Also used : FemNode(artisynth.core.femmodels.FemNode) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 10 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp 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) FemNode(artisynth.core.femmodels.FemNode) 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) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Aggregations

PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)13 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)13 FemNode (artisynth.core.femmodels.FemNode)10 PointAttachment (artisynth.core.mechmodels.PointAttachment)9 ContactPoint (artisynth.core.mechmodels.ContactPoint)8 Point (artisynth.core.mechmodels.Point)8 VectorNd (maspack.matrix.VectorNd)6 Vertex3d (maspack.geometry.Vertex3d)5 ArrayList (java.util.ArrayList)4 PolygonalMesh (maspack.geometry.PolygonalMesh)3 Point3d (maspack.matrix.Point3d)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 FemMeshBase (artisynth.core.femmodels.FemMeshBase)1 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)1 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)1 ContactMaster (artisynth.core.mechmodels.ContactMaster)1