ExternalMesh
ExternalMesh
ExternalMesh(user_name: str, element: Element, region: Optional[RegionBase] = None, *, mesh: Optional[DataSet] = None, filepath: Optional[str] = None, scale: Optional[float] = None, rotate_x: Optional[float] = None, rotate_y: Optional[float] = None, rotate_z: Optional[float] = None, translate_x: float = 0.0, translate_y: float = 0.0, translate_z: float = 0.0)
Bases: MeshPart
PyVista-based custom volume mesh part imported from an external file or dataset.
This mesh part allows importing custom 3D volume meshes (such as VTK, VTU, or OBJ files) via PyVista. It supports scale, rotation, and translation transformations, casting the source mesh to a PyVista UnstructuredGrid for use with 3D brick or PML elements.
Note
- Provide either
mesh(a pre-loaded PyVista DataSet) orfilepath(path to a mesh file on disk), but not both. - The imported mesh is automatically cast to a PyVista UnstructuredGrid format required by Femora.
Example
from femora.core.model import Model
model = Model()
mat = model.material.nd.elastic_isotropic(user_name="soil", e_mod=30000.0, nu=0.3, rho=2.0)
ele = model.element.brick.std(ndof=3, material=mat)
# Create an external mesh part via filepath
mesh_part = model.meshpart.general.external_mesh(
user_name="ext_soil",
element=ele,
filepath="soil_mesh.vtk",
scale=1.0,
)
print(mesh_part.tag)
Create a custom external mesh part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_name
|
str
|
Unique user-defined name for this mesh part. |
required |
element
|
Element
|
Associated Element template used for discretization. |
required |
region
|
Optional[RegionBase]
|
Physical Region where this mesh part is added. |
None
|
mesh
|
Optional[DataSet]
|
Optional pre-existing PyVista DataSet object. |
None
|
filepath
|
Optional[str]
|
Optional path to a mesh file on disk (e.g. VTK, VTU, OBJ). |
None
|
scale
|
Optional[float]
|
Optional scale factor greater than 0 applied to the mesh coordinates. |
None
|
rotate_x
|
Optional[float]
|
Optional rotation angle in degrees around the X-axis. |
None
|
rotate_y
|
Optional[float]
|
Optional rotation angle in degrees around the Y-axis. |
None
|
rotate_z
|
Optional[float]
|
Optional rotation angle in degrees around the Z-axis. |
None
|
translate_x
|
float
|
Translation offset along the X-axis. |
0.0
|
translate_y
|
float
|
Translation offset along the Y-axis. |
0.0
|
translate_z
|
float
|
Translation offset along the Z-axis. |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both mesh and filepath are provided, if neither is provided, or if scale is less than or equal to 0. |
TypeError
|
If mesh is not a PyVista mesh or filepath is not a string. |
FileNotFoundError
|
If filepath is provided but the file does not exist. |
Methods:
generate_mesh
Apply specified geometric transformations and cast to an UnstructuredGrid.
Returns:
| Type | Description |
|---|---|
UnstructuredGrid
|
pv.UnstructuredGrid: The fully transformed PyVista UnstructuredGrid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If casting the transformed mesh to an unstructured grid fails. |