Search in sources :

Example 1 with FemNode3d

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

the class TransverseIsotropyTest method createCylinder.

FemModel3d createCylinder(double h, double r) {
    FemModel3d fem = FemFactory.createCylinder(null, h, r, 24, 40, 4);
    fem.setDensity(1000);
    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);
        }
    }
    return fem;
}
Also used : FemModel3d(artisynth.core.femmodels.FemModel3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 2 with FemNode3d

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

the class FemBeam method build.

public void build(String[] args) throws IOException {
    // Create and add MechModel
    mech = new MechModel("mech");
    addModel(mech);
    // Create and add FemModel
    fem = new FemModel3d("fem");
    mech.add(fem);
    // Build hex beam using factory method
    FemFactory.createHexGrid(fem, length, width, width, /*nx=*/
    6, /*ny=*/
    3, /*nz=*/
    3);
    // Set FEM properties
    fem.setDensity(density);
    fem.setParticleDamping(0.1);
    fem.setMaterial(new LinearMaterial(4000, 0.33));
    // Fix left-hand nodes for boundary condition
    for (FemNode3d n : fem.getNodes()) {
        if (n.getPosition().x <= -length / 2 + EPS) {
            n.setDynamic(false);
        }
    }
    // Set rendering properties
    setRenderProps(fem);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) FemModel3d(artisynth.core.femmodels.FemModel3d) FemNode3d(artisynth.core.femmodels.FemNode3d) LinearMaterial(artisynth.core.materials.LinearMaterial)

Example 3 with FemNode3d

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

the class Cell method buildUnstructuredMesh_volume.

public static void buildUnstructuredMesh_volume(FemModel3d fem, VtkData vtkData) throws IOException {
    // BufferedReader input = new BufferedReader(new FileReader(filename));
    // String inLine = null;
    // String[] inSplit = null;
    // 
    // int nPoints = 0;
    // int nCells = 0;
    // ArrayList<Point3d> points = null;
    // ArrayList<Cell> cells = null;
    // 
    // inLine = input.readLine();          // 1st line: version info, etc...
    // String title = input.readLine();    // 2nd line: title
    // fem.setName(title);
    // inLine = input.readLine();          // 3rd line: ASCII or Binary --> better be ASCII!
    // inLine = input.readLine();          // 4th line: DATASET <type> --> this only reads unstructured grid
    // inSplit = inLine.split(" ");
    // if (inSplit[1].equalsIgnoreCase("UNSTRUCTURED_GRID") == false)
    // {
    // System.out.println("Unrecognized VTK dataset: " + inSplit[1]);
    // return null;
    // }
    // 
    // while (input.ready() == true)
    // {
    // inLine = input.readLine();
    // inLine = inLine.trim();
    // if (inLine.isEmpty () == true)
    // continue;   // blank lines can be ignored...
    // 
    // inSplit = inLine.split(" ");
    // 
    // if       (inSplit[0].equalsIgnoreCase("POINTS") == true)
    // {
    // nPoints = Integer.parseInt (inSplit[1]);
    // points = new ArrayList<Point3d>(nPoints);
    // 
    // double[] nums = new double[nPoints*3];
    // int nNum = 0;
    // while (nNum < nPoints*3)
    // {
    // inLine = input.readLine();
    // inSplit = inLine.split(" ");
    // for (int i=0; i<inSplit.length; i++)
    // {
    // nums[nNum] = Double.parseDouble( inSplit[i] );
    // nNum++;
    // }
    // }
    // 
    // for (int n=0; n<nPoints; n++)
    // {
    // points.add( new Point3d(nums[n*3+0],nums[n*3+1],nums[n*3+2]) );
    // //fem.addNode( new FemNode3d(nums[n*3+0],nums[n*3+1],nums[n*3+2]) );
    // }
    // }
    // else if (inSplit[0].equalsIgnoreCase("CELLS") == true)
    // {
    // nCells = Integer.parseInt (inSplit[1]);
    // cells = new ArrayList<Cell>(nCells);
    // 
    // for (int n=0; n<nCells; n++)
    // {
    // Cell cell = new Cell();
    // cells.add(cell);
    // 
    // inLine = input.readLine();
    // while (inLine.contains("  ") )
    // inLine = inLine.replaceAll("  ", " "); // some writers use multiple spaces...
    // inSplit = inLine.split(" ");
    // cell.nPoints = Integer.parseInt(inSplit[0]);
    // cell.indices = new int[cell.nPoints];
    // for (int i=0; i<cell.nPoints; i++)
    // cell.indices[i] = Integer.parseInt(inSplit[i+1]);
    // }
    // }
    // else if (inSplit[0].equalsIgnoreCase("CELL_TYPES") == true)
    // {
    // // I'm assuming "CELLS" comes before "CELL_TYPES"...
    // for (int n=0; n<nCells; n++)
    // {
    // inLine = input.readLine();
    // 
    // Cell cell = cells.get(n);
    // cell.vtkType = Integer.parseInt(inLine);
    // }
    // }
    // 
    // // I do not see much point in implementing cell,point,field data reading (we are just getting the geometry)
    // else if (inSplit[0].equalsIgnoreCase("CELL_DATA") == true)
    // {
    // }
    // else if (inSplit[0].equalsIgnoreCase("POINT_DATA") == true)
    // {
    // }
    // else if (inSplit[0].equalsIgnoreCase("FIELD_DATA") == true)
    // {
    // }
    // 
    // }
    // input.close();
    ArrayList<Point3d> points = vtkData.points;
    ArrayList<Cell> cells = vtkData.cells;
    fem.setName(vtkData.name);
    // now, compile the FEM
    for (Point3d p : points) fem.addNode(new FemNode3d(p));
    // for (Cell c : cells)
    for (int a = 0; a < cells.size(); a++) {
        Cell c = cells.get(a);
        if (// vertex
        c.vtkType == 1)
            ;
        else if (// line
        c.vtkType == 3)
            ;
        else if (// polyline
        c.vtkType == 4)
            ;
        else if (// triangle
        c.vtkType == 5)
            ;
        else if (// polygon
        c.vtkType == 7)
            ;
        else if (// quad
        c.vtkType == 9)
            ;
        else if (// tet (vtk and artisynth agree)
        c.vtkType == 10) {
            TetElement elem = new TetElement(fem.getNode(c.indices[0]), fem.getNode(c.indices[1]), fem.getNode(c.indices[2]), fem.getNode(c.indices[3]));
            fem.addElement(elem);
            elem.computeVolumes();
            if (elem.getVolume() < 0.0)
                System.out.println("Warning: inverted tet element");
        } else if (// hex  (vtk and artisynth disagree)
        c.vtkType == 12) {
            HexElement elem = new HexElement(fem.getNode(c.indices[0]), fem.getNode(c.indices[3]), fem.getNode(c.indices[2]), fem.getNode(c.indices[1]), fem.getNode(c.indices[4]), fem.getNode(c.indices[7]), fem.getNode(c.indices[6]), fem.getNode(c.indices[5]));
            fem.addElement(elem);
            elem.computeVolumes();
            if (elem.getVolume() < 0.0)
                System.out.println("Warning: inverted hex element");
        } else if (// wedge (vtk and artisynth disagree)
        c.vtkType == 13) {
            WedgeElement elem = new WedgeElement(fem.getNode(c.indices[0]), fem.getNode(c.indices[2]), fem.getNode(c.indices[1]), fem.getNode(c.indices[3]), fem.getNode(c.indices[5]), fem.getNode(c.indices[4]));
            fem.addElement(elem);
            elem.computeVolumes();
            if (elem.getVolume() < 0.0)
                System.out.println("Warning: inverted wedge element");
        } else if (// pyramid  (vtk and artisynth agree)
        c.vtkType == 14) {
            PyramidElement elem = new PyramidElement(fem.getNode(c.indices[0]), fem.getNode(c.indices[1]), fem.getNode(c.indices[2]), fem.getNode(c.indices[3]), fem.getNode(c.indices[4]));
            fem.addElement(elem);
            elem.computeVolumes();
            if (elem.getVolume() < 0.0)
                System.out.println("Warning: inverted pyramid element");
        }
    }
}
Also used : HexElement(artisynth.core.femmodels.HexElement) PyramidElement(artisynth.core.femmodels.PyramidElement) TetElement(artisynth.core.femmodels.TetElement) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) WedgeElement(artisynth.core.femmodels.WedgeElement)

Example 4 with FemNode3d

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

the class Cell method writeVTK.

public static void writeVTK(String filename, FemModel3d fem, ArrayList<String> pointData_scalar_names, ArrayList<double[]> pointData_scalar_data, ArrayList<String> pointData_vector_names, ArrayList<ArrayList<double[]>> pointData_vector_data, ArrayList<String> cellData_scalar_names, ArrayList<double[]> cellData_scalar_data, ArrayList<String> cellData_vector_names, ArrayList<ArrayList<double[]>> cellData_vector_data) {
    // this writes a surface geometry
    int nPoints = fem.getNodes().size();
    int nCells = fem.getElements().size();
    try {
        PrintWriter file = new PrintWriter(new BufferedWriter(new FileWriter(filename, false)));
        // header
        file.println("# vtk DataFile Version 3.0");
        // title
        file.println("VolumeMesh");
        // data type: ASCII or BINARY
        file.println("ASCII");
        // dataset type: STRUCTURED_POINTS, STRUCTURED_GRID, UNSTRUCTURED_GRID, POLYDATA, RECTILINEAR_GRID,  FIELD
        file.println("DATASET UNSTRUCTURED_GRID");
        // write points
        file.println();
        file.printf("POINTS %d float\n", nPoints);
        for (FemNode3d n : fem.getNodes()) {
            Point3d p = n.getPosition();
            file.printf("%f %f %f\n", p.x, p.y, p.z);
        }
        // write cells
        int nCellPoints = 0;
        int[] numNodes = new int[nCells];
        for (int a = 0; a < nCells; a++) {
            int nNodes = fem.getElement(a).getNodes().length;
            nCellPoints = nCellPoints + nNodes;
            numNodes[a] = nNodes;
        }
        // correction in case indices start at 1 rather than 0
        int iAdj = 0;
        if (fem.getNodes().getByNumber(0) == null) {
            iAdj = 1;
            System.out.println("VTK Writer warning: node indices start at 0 rather than 1");
        }
        file.println();
        file.printf("CELLS %d %d\n", nCells, nCellPoints + nCells);
        for (int a = 0; a < nCells; a++) {
            FemNode3d[] femNodes = fem.getElement(a).getNodes();
            if ((fem.getElement(a) instanceof TetElement) || (fem.getElement(a) instanceof QuadtetElement)) {
                // VTK and Artisynth agree in node order
                file.printf("%d %d %d %d %d\n", numNodes[a], fem.getNodes().indexOf(femNodes[0]), fem.getNodes().indexOf(femNodes[1]), fem.getNodes().indexOf(femNodes[2]), fem.getNodes().indexOf(femNodes[3]));
            // femNodes[0].myNumber-iAdj, femNodes[1].myNumber-iAdj, femNodes[2].myNumber-iAdj, femNodes[3].myNumber-iAdj);
            } else if ((fem.getElement(a) instanceof HexElement) || (fem.getElement(a) instanceof QuadhexElement)) {
                // VTK and Artisynth differ in node order
                file.printf("%d %d %d %d %d %d %d %d %d\n", numNodes[a], fem.getNodes().indexOf(femNodes[0]), fem.getNodes().indexOf(femNodes[3]), fem.getNodes().indexOf(femNodes[2]), fem.getNodes().indexOf(femNodes[1]), fem.getNodes().indexOf(femNodes[4]), fem.getNodes().indexOf(femNodes[7]), fem.getNodes().indexOf(femNodes[6]), fem.getNodes().indexOf(femNodes[5]));
            // femNodes[0].myNumber-iAdj, femNodes[3].myNumber-iAdj, femNodes[2].myNumber-iAdj, femNodes[1].myNumber-iAdj,
            // femNodes[4].myNumber-iAdj, femNodes[7].myNumber-iAdj, femNodes[6].myNumber-iAdj, femNodes[5].myNumber-iAdj);
            } else if ((fem.getElement(a) instanceof WedgeElement) || (fem.getElement(a) instanceof QuadwedgeElement)) {
                // VTK and Artisynth differ in node order
                file.printf("%d %d %d %d %d %d %d\n", numNodes[a], fem.getNodes().indexOf(femNodes[0]), fem.getNodes().indexOf(femNodes[2]), fem.getNodes().indexOf(femNodes[1]), fem.getNodes().indexOf(femNodes[3]), fem.getNodes().indexOf(femNodes[5]), fem.getNodes().indexOf(femNodes[4]));
            // femNodes[0].myNumber-iAdj, femNodes[2].myNumber-iAdj, femNodes[1].myNumber-iAdj,
            // femNodes[3].myNumber-iAdj, femNodes[5].myNumber-iAdj, femNodes[4].myNumber-iAdj);
            } else if ((fem.getElement(a) instanceof PyramidElement) || (fem.getElement(a) instanceof QuadpyramidElement)) {
                // VTK and Artisynth agree in node order
                file.printf("%d %d %d %d %d %d\n", numNodes[a], fem.getNodes().indexOf(femNodes[0]), fem.getNodes().indexOf(femNodes[1]), fem.getNodes().indexOf(femNodes[2]), fem.getNodes().indexOf(femNodes[3]), fem.getNodes().indexOf(femNodes[4]));
            // femNodes[0].myNumber-iAdj, femNodes[1].myNumber-iAdj, femNodes[2].myNumber-iAdj, femNodes[3].myNumber-iAdj,
            // femNodes[4].myNumber-iAdj);
            } else {
                file.printf("%d", numNodes[a]);
                for (int b = 0; b < numNodes[a]; b++) file.printf(" %d", femNodes[b].myNumber - iAdj);
                file.println();
            }
        }
        file.println();
        file.printf("CELL_TYPES %d\n", nCells);
        for (int a = 0; a < nCells; a++) {
            if (numNodes[a] == 4)
                // tetrahedron == 10
                file.printf("%d\n", 10);
            else if (numNodes[a] == 8)
                // hexahedron == 12
                file.printf("%d\n", 12);
            else if (numNodes[a] == 6)
                // wedge == 13
                file.printf("%d\n", 13);
            else if (numNodes[a] == 5)
                // pyramid == 14
                file.printf("%d\n", 14);
        }
        // write point data
        writePointData(file, nPoints, pointData_scalar_names, pointData_scalar_data, pointData_vector_names, pointData_vector_data);
        // write cell data
        writeCellData(file, nCells, cellData_scalar_names, cellData_scalar_data, cellData_vector_names, cellData_vector_data);
        // file.flush();
        file.close();
    } catch (Exception e) {
        System.out.println("Warning: exception caught in VTK writer.");
    }
}
Also used : PyramidElement(artisynth.core.femmodels.PyramidElement) TetElement(artisynth.core.femmodels.TetElement) WedgeElement(artisynth.core.femmodels.WedgeElement) HexElement(artisynth.core.femmodels.HexElement) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 5 with FemNode3d

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

the class MFreeElement3d method updateBounds.

public void updateBounds(Vector3d min, Vector3d max) {
    if (myBoundaryMesh != null) {
        myBoundaryMesh.updateBounds(min, max);
    } else {
        // XXX HACK, based on ipnts or nodes
        if (myIntegrationPoints.size() > 0) {
            for (MFreeIntegrationPoint3d ipnt : myIntegrationPoints) {
                Point3d pos = ipnt.getPosition();
                pos.updateBounds(min, max);
            }
        } else {
            for (FemNode3d node : myNodes) {
                node.updateBounds(min, max);
            }
        }
    }
}
Also used : Point3d(maspack.matrix.Point3d) IntegrationPoint3d(artisynth.core.femmodels.IntegrationPoint3d) 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