Search in sources :

Example 31 with FemNode3d

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

the class TransverseIsotropy method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    MechModel mech = new MechModel("mech");
    addModel(mech);
    double h = 0.1;
    double r = 0.005;
    RigidBody rb = RigidBody.createBox("box", 2 * r, 2 * r, 2 * r, 100, true);
    mech.addRigidBody(rb);
    rb.transformGeometry(new RigidTransform3d(new Vector3d(0, 0, -h / 2 - r), AxisAngle.IDENTITY));
    FemModel3d fem = FemFactory.createCylinder(null, h, r, 24, 40, 4);
    fem.setDensity(1000);
    mech.addModel(fem);
    TransverseLinearMaterial mat = new TransverseLinearMaterial();
    mat.setYoungsModulus(50000, 50000);
    mat.setPoissonsRatio(0.45, 0.45);
    double G = 50000 / (2 * (1 + 0.45));
    mat.setShearModulus(G);
    fem.setMaterial(mat);
    fem.setName("fem");
    fem.setSurfaceRendering(SurfaceRender.Shaded);
    RenderProps.setFaceColor(fem, Color.ORANGE);
    RenderProps.setVisible(fem.getElements(), false);
    double eps = 1e-10;
    for (FemNode3d node : fem.getNodes()) {
        if (node.getPosition().z > h / 2 - eps) {
            node.setDynamic(false);
        } else if (node.getPosition().z < -h / 2 + eps) {
            PointAttachment pa = rb.createPointAttachment(node);
            mech.addAttachment(pa);
        }
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) Vector3d(maspack.matrix.Vector3d) FemNode3d(artisynth.core.femmodels.FemNode3d) RigidBody(artisynth.core.mechmodels.RigidBody) PointAttachment(artisynth.core.mechmodels.PointAttachment) TransverseLinearMaterial(artisynth.core.materials.TransverseLinearMaterial)

Example 32 with FemNode3d

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

the class Fem3dBlock method build.

public void build(String type, int nz, int nxy, int options) {
    FemModel3d femMod = new FemModel3d("fem");
    femMod.setDensity(myDensity);
    if (type.equals("tet")) {
        FemFactory.createTetGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
    } else if (type.equals("hex")) {
        FemFactory.createHexGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
    } else if (type.equals("quadtet")) {
        FemFactory.createQuadtetGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
    } else if (type.equals("quadhex")) {
        FemFactory.createQuadhexGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
    } else {
        throw new UnsupportedOperationException("Unsupported element type " + type);
    }
    femMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
    femMod.setLinearMaterial(200000, 0.4, true);
    femMod.setStiffnessDamping(0.002);
    Renderable elements = femMod.getElements();
    RenderProps.setLineWidth(elements, 2);
    RenderProps.setLineColor(elements, Color.BLUE);
    Renderable nodes = femMod.getNodes();
    RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(nodes, 0.01);
    RenderProps.setPointColor(nodes, new Color(153, 0, 204));
    // fix the leftmost nodes
    LinkedList<FemNode3d> leftNodes = getLeftNodes(femMod);
    LinkedList<FemNode3d> rightNodes = getRightNodes(femMod);
    myAttachNodes = rightNodes.toArray(new FemNode3d[0]);
    double wx, wy, wz;
    double mass;
    RigidTransform3d X = new RigidTransform3d();
    PolygonalMesh mesh;
    MechModel mechMod = new MechModel("mech");
    // mechMod.setPrintState ("%10.5f");
    wx = 0.1;
    wy = 0.3;
    wz = 0.3;
    RigidBody leftBody = new RigidBody("leftBody");
    mass = wx * wy * wz * myDensity;
    leftBody.setInertia(SpatialInertia.createBoxInertia(mass, wx, wy, wz));
    mesh = MeshFactory.createBox(wx, wy, wz);
    // mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
    leftBody.setMesh(mesh, /* fileName= */
    null);
    X.R.setIdentity();
    X.p.set(-0.35, 0, 0);
    leftBody.setPose(X);
    leftBody.setDynamic(true);
    mechMod.addRigidBody(leftBody);
    RenderProps.setPointStyle(mechMod, Renderer.PointStyle.SPHERE);
    RigidTransform3d TCW = new RigidTransform3d();
    RigidTransform3d TCA = new RigidTransform3d();
    TCA.p.set(0, 0, wz / 2);
    TCA.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
    TCW.mul(X, TCA);
    RevoluteJoint joint = new RevoluteJoint(leftBody, TCA, TCW);
    RenderProps.setCylindricalLines(joint, 0.01, Color.BLUE);
    joint.setAxisLength(0.5);
    mechMod.addBodyConnector(joint);
    // right box
    RigidBody rightBody = new RigidBody("rightBody");
    rightBody.setInertia(SpatialInertia.createBoxInertia(mass, wx, wy, wz));
    mesh = MeshFactory.createBox(wx, wy, wz);
    // mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
    rightBody.setMesh(mesh, /* fileName= */
    null);
    X.p.set(0.35, 0, 0);
    rightBody.setPose(X);
    rightBody.setDynamic(true);
    mechMod.addRigidBody(rightBody);
    mechMod.addModel(femMod);
    for (FemNode3d n : leftNodes) {
        mechMod.attachPoint(n, leftBody);
    }
    // femMod.setProfile (true);
    mechMod.setIntegrator(Integrator.BackwardEuler);
    setConnected(true);
    addModel(mechMod);
    // mechMod.setProfiling (true);
    // int numWays = 10;
    // double res = 0.1;
    // for (int i = 0; i < numWays; i++) {
    // addWayPoint (new WayPoint (TimeBase.secondsToTicks ((i + 1) * res)));
    // }
    // addWayPoint (new WayPoint (TimeBase.secondsToTicks (5)));
    // addBreakPoint(5);
    // setupOutputProbes();
    addControlPanel(mechMod, femMod);
}
Also used : FemModel3d(artisynth.core.femmodels.FemModel3d) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) MechModel(artisynth.core.mechmodels.MechModel) FemNode3d(artisynth.core.femmodels.FemNode3d) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 33 with FemNode3d

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

the class FemMuscleArm method addFemMuscle.

public void addFemMuscle(Point3d upper, Point3d lower) throws IOException {
    upperArm = model.rigidBodies().get("upper");
    RigidBody lowerArm = model.rigidBodies().get("lower");
    if (upperArm == null || lowerArm == null) {
        return;
    }
    muscle = new PointToPointMuscle("muscle", 1.0, 0.85, "muscle", true);
    model.addModel(muscle);
    RigidTransform3d X = new RigidTransform3d();
    // Point3d upper = new Point3d(2.4, 0, 20), lower = new Point3d(3, 0, -7);
    FemNode3d first = muscle.getFirstNode(), last = muscle.getLastNode();
    double scale = (upper.distance(lower) / first.getPosition().distance(last.getPosition()));
    System.out.println(scale);
    AffineTransform3d scaling = new AffineTransform3d();
    scaling.setIdentity();
    scaling.applyScaling(scale, scale, scale);
    // muscle.transformGeometry(scaling);
    Vector3d translate = new Vector3d();
    translate.sub(upper, first.getPosition());
    muscle.transformGeometry(new RigidTransform3d(translate, new AxisAngle()));
    Vector3d offfem = new Vector3d(), offtarget = new Vector3d();
    offfem.sub(last.getPosition(), first.getPosition());
    offtarget.sub(lower, upper);
    double angle = offfem.angle(offtarget);
    offfem.cross(offtarget);
    muscle.transformGeometry(new RigidTransform3d(new Vector3d(-upper.x, -upper.y, -upper.z), new AxisAngle()));
    muscle.transformGeometry(new RigidTransform3d(upper, new AxisAngle(offfem, angle)));
    muscle.getFirstNode().setDynamic(false);
    // ant.getFirstNode().setPosition(new Point3d(2.381, 0.000, 20));
    // model.AttachPoint(ant.getFirstNode(),upperArm,new Point3d(-size.x,0,-(size.z/2.0)/1.2));
    model.attachPoint(muscle.getLastNode(), lowerArm);
    muscle.setMaxForce(300000);
    muscle.setExcitation(0.0);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setFaceColor(Color.RED);
    rp.setLineStyle(Renderer.LineStyle.LINE);
    rp.setPointStyle(Renderer.PointStyle.POINT);
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setLineColor(Color.WHITE);
    muscle.setRenderProps(rp);
    muscle.setSurfaceRendering(SurfaceRender.Shaded);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) FemNode3d(artisynth.core.femmodels.FemNode3d) RenderProps(maspack.render.RenderProps) PointToPointMuscle(artisynth.core.femmodels.PointToPointMuscle) RigidBody(artisynth.core.mechmodels.RigidBody) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 34 with FemNode3d

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

the class FemMuscleDemo method findNearestNode.

FemNode3d findNearestNode(Point3d pnt) {
    FemNode3d node = null;
    double mind = Double.MAX_VALUE;
    for (FemNode3d n : tissue.getNodes()) {
        double d = n.distance(pnt);
        if (d < mind) {
            mind = d;
            node = n;
        }
    }
    return node;
}
Also used : FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 35 with FemNode3d

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

the class FemSkinDemo method getLeftNodes.

LinkedList<FemNode3d> getLeftNodes(FemModel3d femMod) {
    LinkedList<FemNode3d> nodes = new LinkedList<FemNode3d>();
    double minx = Double.POSITIVE_INFINITY;
    for (FemNode3d n : femMod.getNodes()) {
        if (n.getPosition().x < minx) {
            minx = n.getPosition().x;
        }
    }
    for (FemNode3d n : femMod.getNodes()) {
        if (n.getPosition().x < minx + EPS) {
            nodes.add(n);
        }
    }
    return nodes;
}
Also used : FemNode3d(artisynth.core.femmodels.FemNode3d)

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