How to import VMAP meshes#

This notebook demonstrates how to import finite element meshes in VMAP format in pylife, e.g., to be used for a FKM nonlinear assessment.

[1]:
import pyvista as pv

import pylife.vmap
import pylife.mesh
import pylife.stress.equistress

First we read the file into a VMAPImport.

[2]:
filename = 'data/kt1.vmap'
vmap_mesh = pylife.vmap.VMAPImport(filename)

Now we can check for geometries and states that we found inside the VMAP file.

[3]:
list(vmap_mesh.geometries()), list(vmap_mesh.states())
[3]:
(['KT1-1'], ['Step-1'])

Now we select the forst geometry and the first state and check which field variables are available.

[4]:
geometry = 'KT1-1'
state = 'Step-1'
vmap_mesh.variables(geometry, state)
[4]:
['E', 'STRESS_CAUCHY']

For our purpose we are only interested in the stress tensor, so we create our mesh out of the vmap mesh, join coordinates and the STRESS_CAUCHY variable. Finally we get everything as a pd.DataFrame

[5]:
pylife_mesh = (
    vmap_mesh.make_mesh(geometry, state)
    .join_coordinates()
    .join_variable('STRESS_CAUCHY')
    .to_frame()
)
pylife_mesh
[5]:
x y z S11 S22 S33 S12 S13 S23
element_id node_id
1 68 -0.058024 0.005909 0.001042 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926
95 -0.058024 0.004247 0.000926 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926
96 -0.058024 0.003611 0.002350 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926
58 -0.058024 0.005196 0.003000 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926
14 -0.060000 0.005909 0.001042 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926
... ... ... ... ... ... ... ... ... ... ...
2684 3315 0.060000 -0.000494 0.002577 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831
3290 0.058024 -0.001621 0.002328 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831
3287 0.058024 -0.002545 0.003241 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831
3288 0.058024 -0.001180 0.003989 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831
3261 0.058024 -0.000494 0.002577 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831

21472 rows × 9 columns

With the mesh we can perform calculations like for example calculate the Mises stress and add it back to the mesh.

[6]:
pylife_mesh['mises'] = pylife_mesh.equistress.mises()
pylife_mesh
[6]:
x y z S11 S22 S33 S12 S13 S23 mises
element_id node_id
1 68 -0.058024 0.005909 0.001042 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926 91.658809
95 -0.058024 0.004247 0.000926 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926 91.658809
96 -0.058024 0.003611 0.002350 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926 91.658809
58 -0.058024 0.005196 0.003000 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926 91.658809
14 -0.060000 0.005909 0.001042 107.280235 15.659771 23.321180 -13.440862 -5.005887 -3.322926 91.658809
... ... ... ... ... ... ... ... ... ... ... ...
2684 3315 0.060000 -0.000494 0.002577 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831 100.006590
3290 0.058024 -0.001621 0.002328 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831 100.006590
3287 0.058024 -0.002545 0.003241 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831 100.006590
3288 0.058024 -0.001180 0.003989 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831 100.006590
3261 0.058024 -0.000494 0.002577 100.007462 0.000952 0.000791 0.000580 -0.000230 -0.000831 100.006590

21472 rows × 10 columns

Next, we visualize the absolute stress gradient G using the pyvista package.

[7]:
grid = pv.UnstructuredGrid(*pylife_mesh.mesh.vtk_data())
plotter = pv.Plotter()
plotter.add_mesh(
    grid,
    scalars=pylife_mesh.groupby('element_id')['mises'].mean().to_numpy(),
    show_edges=True,
    cmap='jet'
)
plotter.add_scalar_bar()
plotter.show()