A mesh field specifies scalar or vector values for the features of an FEM mesh. These can be either the vertices (vertex fields) or faces (face fields). Mesh fields have been introduced in particular to allow properties of contact force behaviors (Section 8.7.2), such as LinearElasticContact, to vary over the contact mesh. Mesh fields can currently be defined only for triangular polyhedral meshes.
To evaluate getValue(p) at an arbitrary point , the field finds the mesh face nearest to , and then either interpolates the value from the surrounding vertices (vertex fields) or uses the face value directly (face fields).
Mesh fields make use of the classes PolygonalMesh, Vertex3d, and Face, defined in the package maspack.geometry. They maintain a default value which describes the value at features for which values are not explicitly set. If unspecified, the default value itself is zero.
In the remainder of this section, it is assumed that vector fields are constructed using fixed-size vectors or matrices, such as Vector3d or Matrix3d. However, it is also possible to construct fields using VectorNd or MatrixNd, with the aid of special wrapper classes, as described in Section 7.4. That section also details a convenience wrapper class for Vector3d.
The two field types are now described in detail.
Implemented by ScalarVertexField, VectorVertexField<T>, or subclasses of the latter, vertex fields specify their values at the vertices of a mesh. They can be created with constructors such as
where mcomp is a mesh component containing the mesh, defaultValue is the default value, and name is a component name. For vector fields, the maspack.matrix.VectorObject type is parameterized by T, and type gives its actual class type (e.g., Vector3d.class).
Once the field has been created, values can be queried and set at the vertices using methods such as
Scalar fields: | |
---|---|
void setValue(Vertex3d vtx, double value) |
Set value for vertex vtx. |
double getValue(Vertex3d vtx) |
Get value for vertex vtx. |
double getValue(int vidx) |
Get value for vertex at index vidx. |
Vector fields with parameterized type T: | |
void setValue(Vertex3d vtx, T value) |
Set value for vertex vtx. |
T getValue(Vertex3d vtx) |
Get value for vertex vtx. |
T getValue(int vidx) |
Get value for vertex at index vidx. |
All fields: | |
boolean isValueSet(Vertex3d vtx) |
Query if value set for vertex vtx. |
void clearValue(Vertex3d vtx) |
Unset value for vertex vtx. |
void clearAllValues() |
Unset values for all vertices. |
Note that values don’t need to be set at all vertices, and set values can be unset using the clear methods. For vertices with no value set, getValue() will return the default value.
As a simple example, the following code fragment constructs a ScalarVertexField for a mesh contained in the MeshComponent mcomp that describes contact stiffness values at every vertex:
As noted earlier, mesh fields are usually stored in the fields list of a MechModel.
Another example shows the creation of a field of 3D direction vectors:
When creating a vector field, the constructor needs the class type of the field’s VectorObject. However, for the special case of Vector3d, one may also use the convenience wrapper class Vector3dVertexField, described in Section 7.4.
Implemented by ScalarFaceField, VectorFaceField<T>, or subclasses of the latter, face fields specify their values at the faces of a polygonal mesh, and these values are assumed to be constant within the face. To evaluate getValue(p), the field finds the containing (or nearest) face for , and then returns the value for that face.
Because values are assume to be constant within each face, face fields are inherently discontinuous across face boundaries.
The constructors for face fields are analogous to those for vertex fields:
and the methods for setting values at faces are similar as well, where fidx refers to the face index:
The following code fragment constructs a VectorFaceField based on Vector2d that stores a 2D coordinate value at all faces of a mesh: