VMAP IO Demo

This demo shows the stress gradient calculation module. A gradient is calculated by fitting a plane into a node and its neighbor nodes of an FEM mesh.

See documentation for details on the module.

[1]:
import numpy as np
import pandas as pd
import pylife.vmap
import pylife.stress.equistress
import pyvista as pv

pv.set_plot_theme('document')
pv.set_jupyter_backend('ipygany')

Read in demo data and add the stress tensor dimensions for the third dimension.

[2]:
vm_mesh = pylife.vmap.VMAPImport("plate_with_hole.vmap")
[ ]:

[3]:
pyLife_mesh = (vm_mesh.make_mesh('1', 'STATE-2')
               .join_coordinates()
               .join_variable('STRESS_CAUCHY')
               .join_variable('DISPLACEMENT')
               .to_frame())
pyLife_mesh.sample(10)
[3]:
x y z S11 S22 S33 S12 S13 S23 dx dy dz
element_id node_id
3267 3621 8.121114 -4.490608 0.0 21.867970 -13.747931 0.0 7.758520 0.0 0.0 0.004623 7.864420e-04 0.0
3892 9034 -18.185001 0.000000 0.0 27.840216 15.018993 0.0 0.127443 0.0 0.0 -0.006497 1.918017e-37 0.0
4406 4412 -15.012715 -6.964381 0.0 39.262238 1.683851 0.0 -9.404963 0.0 0.0 -0.005405 4.239249e-05 0.0
4635 3833 -10.675753 -6.568871 0.0 48.634052 -0.761658 0.0 -13.739356 0.0 0.0 -0.004580 2.774546e-04 0.0
1872 2024 -14.391812 0.366991 0.0 15.852651 8.562475 0.0 1.622891 0.0 0.0 -0.006149 6.672515e-06 0.0
584 859 8.913480 2.461464 0.0 -2.514901 -25.786119 0.0 -3.572769 0.0 0.0 0.005472 -3.870771e-04 0.0
3245 3557 14.467859 -2.698292 0.0 21.078175 7.216562 0.0 9.874338 0.0 0.0 0.005719 -3.641288e-05 0.0
3156 3637 4.411795 -7.908645 0.0 76.299004 -0.893150 0.0 -8.012115 0.0 0.0 0.001600 3.362931e-03 0.0
4179 4206 -16.389534 -8.284608 0.0 37.194118 0.293217 0.0 -3.158941 0.0 0.0 -0.005526 8.016582e-05 0.0
1241 7567 14.355186 5.398512 0.0 34.705429 4.150722 0.0 -14.676251 0.0 0.0 0.005245 -8.010234e-07 0.0
[4]:
pyLife_mesh['mises'] = pyLife_mesh.equistress.mises()

We will use Pyvista for plotting FEM in the future

still work in progress, sorry dudes

[5]:

pyLife_nodes = pyLife_mesh[['x', 'y', 'z', 'mises']].groupby('node_id').mean() mesh = pv.PolyData(pyLife_nodes[['x', 'y', 'z']].values) mesh.point_arrays["mises"] = pyLife_nodes["mises"].values mesh.plot(scalars="mises")

if you are using jupyter-lab you can use some lines, too:

for more information see here: https://pyvista-doc.readthedocs.io/en/latest/plotting/itk_plotting.html

[6]:
pl = pv.PlotterITK()
pl.add_mesh(mesh, scalars="mises", smooth_shading=True)
pl.show(True)
[ ]: