This page was generated from docs\source\notebooks/io.ipynb.

Read and Write Mesh Data#

[1]:
from sigmaepsilon.mesh import PolyData, PointData, TriMesh, grid, triangulate
from sigmaepsilon.mesh.space import StandardFrame
from sigmaepsilon.mesh.cells import T3, Q4, H8
import numpy as np

A = StandardFrame(dim=3)

coords, topo, _ = triangulate(size=(100, 100), shape=(10, 10))
pd = PointData(coords=coords, frame=A)
cd = T3(topo=topo)
tri = TriMesh(pd, cd)

coords, topo = grid(size=(100, 100), shape=(10, 10), eshape="Q4")
pd = PointData(coords=coords, frame=A)
cd = Q4(topo=topo)
grid2d = PolyData(pd, cd)

coords, topo = grid(size=(100, 100, 100), shape=(8, 6, 2), eshape="H8")
pd = PointData(coords=coords, frame=A)
cd = H8(topo=topo)
grid3d = PolyData(pd, cd)

mesh = PolyData()
mesh["tri", "T3"] = tri.move(np.array([0.0, 0.0, -50]))
mesh["grids", "Q4"] = grid2d.move(np.array([0.0, 0.0, 150]))
mesh["grids", "H8"] = grid3d

mesh["tri", "T3"].pointdata["values"] = np.full(tri.coords().shape[0], 5.0)
mesh["grids", "Q4"].pointdata["values"] = np.full(grid2d.coords().shape[0], 10.0)
mesh["grids", "H8"].pointdata["values"] = np.full(grid3d.coords().shape[0], -5.0)

mesh.to_standard_form()
mesh.lock(create_mappers=True)

mesh.pvplot(
    notebook=True,
    window_size=(600, 400),
    jupyter_backend="static",
    scalars=mesh.pd["values"].to_numpy(),
    theme="document",
)
../_images/notebooks_io_1_0.png
[2]:
mesh.pd.to_parquet("pd.parquet")
mesh["tri", "T3"].cd.to_parquet("cdT3.parquet")
mesh["grids", "Q4"].cd.to_parquet("cdQ4.parquet")
mesh["grids", "H8"].cd.to_parquet("cdH8.parquet")
paths = ["pd.parquet", "cdT3.parquet", "cdQ4.parquet", "cdH8.parquet"]
[3]:
from sigmaepsilon.mesh.cells import T3, Q4, H8
from sigmaepsilon.mesh import PointData

frame = StandardFrame(dim=3)

pd = PointData.from_parquet("pd.parquet")
mesh = PolyData(pd, frame=frame)

cdT3 = T3.from_parquet("cdT3.parquet")
mesh["tri", "T3"] = PolyData(cdT3, frame=frame)

cdQ4 = Q4.from_parquet("cdQ4.parquet")
mesh["grids", "Q4"] = PolyData(cdQ4, frame=frame)

cdH8 = H8.from_parquet("cdH8.parquet")
mesh["grids", "H8"] = PolyData(cdH8, frame=frame)

mesh.to_standard_form()
mesh.lock(create_mappers=True)

mesh.pvplot(
    notebook=True,
    window_size=(600, 400),
    jupyter_backend="static",
    scalars=mesh.pd["values"].to_numpy(),
    theme="document",
)
../_images/notebooks_io_3_0.png
[4]:
mesh.to_parquet("mesh_pd.parquet", "mesh_cd.parquet")
paths.extend(["mesh_pd.parquet", "mesh_cd.parquet"])
[5]:
df_pd, df_cd = mesh.to_dataframe()
[6]:
import os

for path in paths:
    if os.path.exists(path):
        os.remove(path)