Search in sources :

Example 21 with FemElement3d

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

the class SpongeModel method createGeometry.

public void createGeometry(String name, double widthX, double widthY, double widthZ, int numX, int numY, int numZ, double nodeMass) {
    if (numX < 1 || numY < 1 || numZ < 1) {
        throw new IllegalArgumentException("number of elements in each direction must be >= 1");
    }
    // create all the particles
    double dx = 1.0 / numX;
    double dy = 1.0 / numY;
    double dz = 1.0 / numZ;
    Point3d p = new Point3d();
    for (int k = 0; k <= numZ; k++) {
        for (int j = 0; j <= numY; j++) {
            for (int i = 0; i <= numX; i++) {
                p.x = widthX * (-0.5 + i * dx);
                p.y = widthY * (-0.5 + j * dy);
                p.z = widthZ * (-0.5 + k * dz);
                addNode(new FemNode3d(p));
            // getNode(numNodes()-1).setName(Integer.toString(numNodes()-1));
            }
        }
    }
    // PolygonalMesh mesh = new PolygonalMesh();
    // create all the elements
    int wk = (numX + 1) * (numY + 1);
    int wj = (numX + 1);
    FemNode3d n0, n1, n2, n3, n4, n5, n6, n7;
    for (int i = 0; i < numX; i++) {
        for (int j = 0; j < numY; j++) {
            for (int k = 0; k < numZ; k++) {
                n0 = getNodes().get((k + 1) * wk + j * wj + i);
                n1 = getNodes().get((k + 1) * wk + j * wj + i + 1);
                n2 = getNodes().get((k + 1) * wk + (j + 1) * wj + i + 1);
                n3 = getNodes().get((k + 1) * wk + (j + 1) * wj + i);
                n4 = getNodes().get(k * wk + j * wj + i);
                n5 = getNodes().get(k * wk + j * wj + i + 1);
                n6 = getNodes().get(k * wk + (j + 1) * wj + i + 1);
                n7 = getNodes().get(k * wk + (j + 1) * wj + i);
                TetElement[] elems = TetElement.createCubeTesselation(n0, n1, n2, n3, n4, n5, n6, n7, /* even= */
                (i + j + k) % 2 == 0);
                // HexElement he = new HexElement (n0, n1, n2, n3, n4, n5, n6, n7);
                for (FemElement3d e : elems) {
                    addElement(e);
                // he.addTetElement ((TetElement)e);
                }
            // add hex element
            // he.setTetElements(elems);
            // hexElements.add (he);
            }
        }
    }
    // TODO create outer Mesh here.
    // mesh.setFixed(false);
    // setSurfaceMesh(mesh);
    RenderProps.setShading(this, Renderer.Shading.SMOOTH);
    RenderProps.setFaceStyle(this, Renderer.FaceStyle.FRONT_AND_BACK);
    RenderProps.setFaceColor(this, Color.BLUE);
    RenderProps.setAlpha(this, 0.9);
    RenderProps.setVisible(this, true);
    invalidateStressAndStiffness();
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) TetElement(artisynth.core.femmodels.TetElement) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Aggregations

FemElement3d (artisynth.core.femmodels.FemElement3d)21 FemNode3d (artisynth.core.femmodels.FemNode3d)8 Point3d (maspack.matrix.Point3d)7 Vector3d (maspack.matrix.Vector3d)7 Point (artisynth.core.mechmodels.Point)6 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)4 MuscleBundle (artisynth.core.femmodels.MuscleBundle)4 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)3 VectorNd (maspack.matrix.VectorNd)3 FemMarker (artisynth.core.femmodels.FemMarker)2 FemMeshComp (artisynth.core.femmodels.FemMeshComp)2 FemMuscleModel (artisynth.core.femmodels.FemMuscleModel)2 LinearMaterial (artisynth.core.materials.LinearMaterial)2 SimpleForceMuscle (artisynth.core.materials.SimpleForceMuscle)2 MechModel (artisynth.core.mechmodels.MechModel)2 ArrayList (java.util.ArrayList)2 BVFeatureQuery (maspack.geometry.BVFeatureQuery)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 Vertex3d (maspack.geometry.Vertex3d)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2