Search in sources :

Example 11 with FemNode3d

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

the class MFreeModel3d method updateSlavePos.

public void updateSlavePos() {
    super.updateSlavePos();
    // nodes
    for (FemNode3d node : myNodes) {
        ((MFreeNode3d) node).updateSlavePos();
    }
    // integration points
    for (FemElement3d elem : myElements) {
        for (IntegrationPoint3d mfip : elem.getIntegrationPoints()) {
            ((MFreeIntegrationPoint3d) mfip).updateSlavePos();
        }
        MFreePoint3d warp = (MFreePoint3d) elem.getWarpingPoint();
        if (warp != null) {
            warp.updateSlavePos();
        }
    }
    // meshes
    myMeshList.updateSlavePos();
    myBVTreeValid = false;
    if (myFrameConstraint != null && !myFrameRelativeP) {
        myFrameConstraint.updateFramePose(/*frameRelative=*/
        false);
    }
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 12 with FemNode3d

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

the class MFreeModel3d method findNearestNode.

/**
 * Finds the nearest node to a specified point that is within
 * a specified maximum distance. If no node is within the
 * specified maximum distance, <code>null</code> is returned.
 *
 * @param pnt Point for which the nearest node should be located
 * @param maxDist Maximum distance that the node must be from the
 * point. If <code>maxDist</code> &lt; 0, then <code>null</code>
 * will be returned.
 * @return Nearest point within the prescribed distance, or <code>null</code>
 * if there is no such point
 */
public FemNode3d findNearestNode(Point3d pnt, double maxDist) {
    if (maxDist < 0) {
        return null;
    }
    BVTree bvtree = getElementBVTree();
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    bvtree.intersectSphere(nodes, pnt, maxDist);
    FemNode3d nearest = null;
    double dist = 1 + 2 * maxDist;
    for (BVNode n : nodes) {
        Boundable[] elements = n.getElements();
        for (int i = 0; i < elements.length; i++) {
            FemElement3d e = (FemElement3d) elements[i];
            for (int k = 0; k < e.numNodes(); k++) {
                double d = e.getNodes()[k].getPosition().distance(pnt);
                if (d < dist && d <= maxDist) {
                    dist = d;
                    nearest = e.getNodes()[k];
                }
            }
        }
    }
    return nearest;
}
Also used : BVTree(maspack.geometry.BVTree) FemElement3d(artisynth.core.femmodels.FemElement3d) BVNode(maspack.geometry.BVNode) ArrayList(java.util.ArrayList) FemNode3d(artisynth.core.femmodels.FemNode3d) Boundable(maspack.geometry.Boundable) Point(artisynth.core.mechmodels.Point)

Example 13 with FemNode3d

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

the class FemDisplayProbe method getStressValue.

// computes stress value of a point inside the FemModel based on
// shape function interpolation
private static double getStressValue(Point3d pnt, FemModel3d model) {
    Point3d loc = new Point3d();
    FemElement3d elem = model.findContainingElement(pnt);
    if (elem == null) {
        elem = model.findNearestElement(loc, pnt);
    }
    Vector3d coords = new Vector3d();
    double stress = 0;
    if (elem != null) {
        elem.getNaturalCoordinates(coords, pnt);
        FemNode3d[] nodes = elem.getNodes();
        for (int i = 0; i < elem.numNodes(); i++) {
            stress += elem.getN(i, coords) * nodes[i].getVonMisesStress();
        }
    }
    return stress;
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 14 with FemNode3d

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

the class Fem3dBlock method setConnected.

public synchronized void setConnected(boolean connect) {
    MechModel mechMod = (MechModel) findComponent("models/mech");
    if (mechMod != null) {
        FemModel3d femMod = (FemModel3d) mechMod.findComponent("models/fem");
        LinkedList<FemNode3d> rightNodes = new LinkedList<FemNode3d>();
        for (int i = 0; i < myAttachNodes.length; i++) {
            rightNodes.add(myAttachNodes[i]);
        }
        if (connect && !rightNodes.get(0).isAttached()) {
            RigidBody rightBody = (RigidBody) mechMod.findComponent("rigidBodies/rightBody");
            // position the block so that it lies at the current
            // end of the beam
            Plane plane = new Plane();
            Point3d centroid = new Point3d();
            int numPnts = rightNodes.size();
            Point3d[] pnts = new Point3d[numPnts];
            for (int i = 0; i < numPnts; i++) {
                pnts[i] = rightNodes.get(i).getPosition();
                centroid.add(pnts[i]);
            }
            centroid.scale(1 / (double) numPnts);
            plane.fit(pnts, numPnts);
            Vector3d normal = new Vector3d(plane.getNormal());
            // to determine the appropriate sign of the normal
            for (FemNode3d node : femMod.getNodes()) {
                if (!rightNodes.contains(node)) {
                    Vector3d diff = new Vector3d();
                    diff.sub(node.getPosition(), rightNodes.get(0).getPosition());
                    if (diff.dot(normal) > 0) {
                        normal.negate();
                    }
                    break;
                }
            }
            RigidTransform3d X = new RigidTransform3d();
            X.R.setZDirection(normal);
            X.R.mulAxisAngle(0, 1, 0, -Math.PI / 2);
            X.p.set(centroid);
            X.mulXyz(0.05, 0, 0);
            rightBody.setPose(X);
            rightBody.setVelocity(new Twist());
            for (FemNode3d n : rightNodes) {
                mechMod.attachPoint(n, rightBody);
            }
        } else if (!connect && rightNodes.get(0).isAttached()) {
            for (FemNode3d n : rightNodes) {
                mechMod.detachPoint(n);
            }
        }
    }
    myConnectedP = connect;
}
Also used : FemModel3d(artisynth.core.femmodels.FemModel3d) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) MechModel(artisynth.core.mechmodels.MechModel) FemNode3d(artisynth.core.femmodels.FemNode3d) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 15 with FemNode3d

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

the class FemBeamMech method build.

public void build(String[] args) {
    femPath = "models/mech/models/fem/";
    modPath = "models/mech/";
    int nn = 2;
    myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
    myFemMod.setName("fem");
    myFemMod.setDensity(myDensity);
    myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
    myFemMod.setLinearMaterial(60000, 0.33, true);
    myFemMod.setStiffnessDamping(0.002);
    myFemMod.setImplicitIterations(100);
    myFemMod.setImplicitPrecision(0.001);
    myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
    Renderable elems = myFemMod.getElements();
    RenderProps.setLineWidth(elems, 2);
    RenderProps.setLineColor(elems, Color.BLUE);
    Renderable nodes = myFemMod.getNodes();
    RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(nodes, 0.005);
    RenderProps.setPointColor(nodes, Color.GREEN);
    // fix the leftmost nodes
    double EPS = 1e-9;
    for (FemNode3d n : myFemMod.getNodes()) {
        if (n.getPosition().x < -0.3 + EPS) {
            myLeftNodes.add(n);
        }
    }
    System.out.println("fixed nodes:");
    for (FemNode3d n : myLeftNodes) {
        n.setDynamic(false);
    }
    RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
    myFemMod.setProfiling(true);
    RigidBody anchorBox = new RigidBody("anchorBox");
    PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
    anchorBox.setMesh(mesh, /* fileName= */
    null);
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(-0.35, 0, 0);
    anchorBox.setPose(X);
    anchorBox.setDynamic(false);
    myMechMod = new MechModel("mech");
    myMechMod.addModel(myFemMod);
    myMechMod.addRigidBody(anchorBox);
    System.out.println("models: " + myMechMod.findComponent("models"));
    System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    myMechMod.setProfiling(true);
    // add marker to lower right corner element
    Point3d corner = new Point3d(0.3, -0.1, -0.1);
    FemElement cornerElem = null;
    for (FemElement e : myFemMod.getElements()) {
        FemNode[] nodeList = e.getNodes();
        for (int i = 0; i < nodeList.length; i++) {
            if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
                cornerElem = e;
                break;
            }
        }
    }
    if (cornerElem != null) {
        FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
        myFemMod.addMarker(mkr, cornerElem);
        RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(mkr, 0.01);
        RenderProps.setPointColor(mkr, Color.WHITE);
        Particle part = new Particle(1, 0.5, -0.07, -0.03);
        RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(part, 0.01);
        part.setDynamic(false);
        myMechMod.addParticle(part);
        AxialSpring spr = new AxialSpring(1000, 0, 0);
        myMechMod.attachAxialSpring(part, mkr, spr);
        RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
        RenderProps.setLineRadius(spr, 0.01);
        RenderProps.setLineColor(spr, Color.GREEN);
    }
    int numWays = 0;
    double res = 0.2;
    for (int i = 0; i < numWays; i++) {
        addWayPoint(new WayPoint((i + 1) * res, true));
    }
    addControlPanel(myMechMod, myFemMod);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemNode(artisynth.core.femmodels.FemNode) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh) FemMarker(artisynth.core.femmodels.FemMarker) WayPoint(artisynth.core.probes.WayPoint) AxialSpring(artisynth.core.mechmodels.AxialSpring) Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) Renderable(maspack.render.Renderable) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) WayPoint(artisynth.core.probes.WayPoint) RigidBody(artisynth.core.mechmodels.RigidBody) FemElement(artisynth.core.femmodels.FemElement)

Aggregations

FemNode3d (artisynth.core.femmodels.FemNode3d)38 FemModel3d (artisynth.core.femmodels.FemModel3d)12 Point3d (maspack.matrix.Point3d)12 RigidTransform3d (maspack.matrix.RigidTransform3d)9 FemElement3d (artisynth.core.femmodels.FemElement3d)8 MechModel (artisynth.core.mechmodels.MechModel)8 Point (artisynth.core.mechmodels.Point)7 RigidBody (artisynth.core.mechmodels.RigidBody)7 Vector3d (maspack.matrix.Vector3d)6 ArrayList (java.util.ArrayList)5 FemMarker (artisynth.core.femmodels.FemMarker)4 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)4 VectorNd (maspack.matrix.VectorNd)4 TetElement (artisynth.core.femmodels.TetElement)3 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)3 LinkedList (java.util.LinkedList)3 FemNode (artisynth.core.femmodels.FemNode)2 HexElement (artisynth.core.femmodels.HexElement)2 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)2 PyramidElement (artisynth.core.femmodels.PyramidElement)2