6 Finite Element Models

6.3 FEM Geometry

Associated with each FEM model is a list of geometry with the heading meshes. This geometry can be used for either display purposes, or for interactions such as collisions (Section 8.3.2). A geometry itself has no physical properties; its motion is entirely governed by the FEM model that contains it.

All FEM geometries are of type FemMeshComp, which stores a reference to a mesh object (Section 2.5), as well as attachment information that links vertices of the mesh to points within the FEM. The attachments enforce the shape function interpolation in Equation (6.1) to hold at each mesh vertex, with constant shape function coefficients.

6.3.1 Surface meshes

By default, every FemModel3d has an auto-generated geometry representing the “surface mesh”. The surface mesh consists of all un-shared element faces (i.e. the faces of individual elements that are exposed to the world), and its vertices correspond to the nodes that make up those faces. As the FEM nodes move, so do the mesh vertices due to the attachment framework.

The surface mesh can be obtained using one of the following functions in FemModel3d:

FemMeshComp getSurfaceMeshComp ();     // returns the FemMeshComp surface component
PolygonalMesh getSurfaceMesh ();  // returns the underlying polygonal surface mesh

The first returns the surface complete with attachment information. The latter method directly returns the PolygonalMesh that is controlled by the FEM.

It is possible to manually set the surface mesh:

setSurfaceMesh ( PolygonalMesh surface );  // manually set surface mesh

However, doing so is normally not necessary. It is always possible to add additional mesh geometries to a finite element model, and the visibility settings can be changed so that the default surface mesh is not rendered.

6.3.2 Embedding geometry within an FEM

Any geometry of type MeshBase can be added to a FemModel3d. To do so, first position the mesh so that its vertices are in the desired locations inside the FEM, then call one of the FemModel3d methods:

FemMeshComp addMesh ( MeshBase mesh );                // creates and returns FemMeshComp
FemMeshComp addMesh ( String name, MeshBase mesh );

The latter is a convenience routine that also gives the newly embedded FemMeshComp a name.

6.3.3 Example: a beam with an embedded sphere

Figure 6.5: FemEmbeddedSphere model loaded into ArtiSynth.

A complete model demonstrating embedding a mesh is given below.

1 package artisynth.demos.tutorial;
2
3 import java.awt.Color;
4 import java.io.IOException;
5
6 import maspack.geometry.*;
7 import maspack.render.RenderProps;
8 import artisynth.core.mechmodels.Collidable.Collidability;
9 import artisynth.core.femmodels.*;
10 import artisynth.core.femmodels.FemModel.SurfaceRender;
11 import artisynth.core.materials.LinearMaterial;
12 import artisynth.core.mechmodels.MechModel;
13 import artisynth.core.workspace.RootModel;
14
15 public class FemEmbeddedSphere extends RootModel {
16
17    // Internal components
18    protected MechModel mech;
19    protected FemModel3d fem;
20    protected FemMeshComp sphere;
21
22    @Override
23    public void build(String[] args) throws IOException {
24       super.build(args);
25
26       mech = new MechModel("mech");
27       addModel(mech);
28
29       fem = new FemModel3d("fem");
30       mech.addModel(fem);
31
32       // Build hex beam and set properties
33       double[] size = {0.4, 0.4, 0.4};
34       int[] res = {4, 4, 4};
35       FemFactory.createHexGrid (fem,
36          size[0], size[1], size[2], res[0], res[1], res[2]);
37       fem.setParticleDamping(2);
38       fem.setDensity(10);
39       fem.setMaterial(new LinearMaterial(4000, 0.33));
40
41       // Add an embedded sphere mesh
42       PolygonalMesh sphereSurface = MeshFactory.createOctahedralSphere(0.15, 3);
43       sphere = fem.addMesh("sphere", sphereSurface);
44       sphere.setCollidable (Collidability.EXTERNAL);
45
46       // Boundary condition: fixed LHS
47       for (FemNode3d node : fem.getNodes()) {
48          if (node.getPosition().x == -0.2) {
49             node.setDynamic(false);
50          }
51       }
52
53       // Set rendering properties
54       setFemRenderProps (fem);
55       setMeshRenderProps (sphere);
56    }
57
58    // FEM render properties
59    protected void setFemRenderProps ( FemModel3d fem ) {
60       fem.setSurfaceRendering (SurfaceRender.Shaded);
61       RenderProps.setLineColor (fem, Color.BLUE);
62       RenderProps.setFaceColor (fem, new Color (0.5f, 0.5f, 1f));
63       RenderProps.setAlpha(fem, 0.2);   // transparent
64    }
65
66    // FemMeshComp render properties
67    protected void setMeshRenderProps ( FemMeshComp mesh ) {
68       mesh.setSurfaceRendering( SurfaceRender.Shaded );
69       RenderProps.setFaceColor (mesh, new Color (1f, 0.5f, 0.5f));
70       RenderProps.setAlpha (mesh, 1.0);   // opaque
71    }
72
73 }

This example can be found in artisynth.demos.tutorial.FemEmbeddedSphere. The model is very similar to FemBeam. A MechModel and FemModel3d are created and added. At line 41, a PolygonalMesh of a sphere is created using a factory method. The sphere is already centered inside the beam, so it does not need to be repositioned. At Line 42, the sphere is embedded inside model fem, creating a FemMeshComp with the name “sphere”. The full model is shown in Figure 6.5.