Export Data in separated variables (PXDMF Format)¶
Inports¶
[1]:
import numpy as np
import pyvista
pyvista.global_theme._jupyter_backend = 'panel' # remove this line to get interactive 3D plots
from Muscat.IO.XdmfWriter import XdmfWriter
from Muscat.Containers.MeshCreationTools import CreateUniformMeshOfBars, CreateConstantRectilinearMesh
from Muscat.Helpers.IO.TemporaryDirectory import TemporaryDirectory
Mesh and data Creation¶
[2]:
mesh1DTime = CreateUniformMeshOfBars(2,5,10)
mesh1DTime.props['ParafacDims'] = 1
mesh1DTime.props['ParafacDim0'] = "T"
mesh2DParameters = CreateConstantRectilinearMesh(dimensions=[4,4], origin=[0,0], spacing=[1,1])
mesh2DParameters.props['ParafacDims'] = 2
mesh2DParameters.props['ParafacDim0'] = "Px"
mesh2DParameters.props['ParafacDim1'] = "Py"
mesh3DSpace = CreateConstantRectilinearMesh(dimensions=[8,8,8], origin=[0,0,0], spacing=[1,1,1])
Plot meshes for each dimension¶
[3]:
import pyvista as pv
from Muscat.Bridges.PyVistaBridge import MeshToPyVista
def GetAxes(names):
axes = pv.Axes()
actor = axes.axes_actor
for name, coordName in zip(names, ("X","Y","Z")):
if len(name):
getattr(actor, "Set"+coordName+"AxisLabelText")(name)
else:
getattr(actor, "Set"+coordName+"AxisLabelText")("")
getattr(actor, "Get"+coordName+"AxisTipProperty")().SetOpacity(0)
getattr(actor, "Get"+coordName+"AxisShaftProperty")().SetOpacity(0)
return axes
plotter = pv.Plotter(shape=(1, 3))
plotter.subplot(0, 0)
plotter.add_text("1D Time Domain", font_size=10)
plotter.add_mesh(MeshToPyVista(mesh1DTime), show_edges=True, show_scalar_bar=False, edge_color="grey", cmap="rainbow_r")
plotter.add_actor(GetAxes(("T","","")).axes_actor)
plotter.subplot(0, 1)
plotter.add_text("2D Parametric Domain", font_size=10)
plotter.add_mesh(MeshToPyVista(mesh2DParameters), show_edges=True, show_scalar_bar=False, edge_color="grey", cmap="rainbow_r")
plotter.add_actor(GetAxes(("Px","Py","")).axes_actor)
plotter.subplot(0, 2)
plotter.add_text("3D Physical Domain", font_size=10)
plotter.add_mesh(MeshToPyVista(mesh3DSpace), show_edges=True, show_scalar_bar=False, edge_color="grey", cmap="rainbow_r")
plotter.add_actor(GetAxes(("x","y","z")).axes_actor)
plotter.show()
Export¶
[4]:
writer = XdmfWriter()
writer.SetBinary(True)
writer.SetHdf5(False)
writer.SetParafac(True)
writer.Open(filename=TemporaryDirectory.GetTempPath() + 'parafac.pxdmf')
writer.Write(mesh2DParameters, CellFields= [np.arange(mesh2DParameters.GetNumberOfElements())+0.1 ],CellFieldsNames=["Sigma_0"])
writer.Write(mesh1DTime, CellFields = [np.arange(mesh1DTime.GetNumberOfElements())+0.1 ], CellFieldsNames=["Sigma_0"])
writer.Write(mesh3DSpace, CellFields = [np.arange(mesh3DSpace.GetNumberOfElements())+0.1 ], CellFieldsNames=["Sigma_0"])
writer.Close()