pyfieldml Quickstart¶
Five-minute demo: install, load a dataset, inspect, evaluate, and export.
In [ ]:
Copied!
from pyfieldml import datasets
doc = datasets.load_unit_cube()
print("Version :", doc.source_version)
print("Region :", doc.region.name)
from pyfieldml import datasets
doc = datasets.load_unit_cube()
print("Version :", doc.source_version)
print("Region :", doc.region.name)
Inspect the evaluator graph¶
In [ ]:
Copied!
for name, ev in doc.evaluators.items():
print(f"{name:30s} {type(ev).__name__}")
for name, ev in doc.evaluators.items():
print(f"{name:30s} {type(ev).__name__}")
Extract coordinates as NumPy¶
In [ ]:
Copied!
coords_ev = doc.evaluators["coordinates"]
xyz = coords_ev.as_ndarray()
print("coords shape:", xyz.shape)
print("coords:")
print(xyz)
coords_ev = doc.evaluators["coordinates"]
xyz = coords_ev.as_ndarray()
print("coords shape:", xyz.shape)
print("coords:")
print(xyz)
Evaluate the coordinate field at the element centroid¶
In [ ]:
Copied!
coords = doc.field("coordinates")
centroid = coords.evaluate(element=1, xi=(0.5, 0.5, 0.5))
print("centroid:", centroid)
coords = doc.field("coordinates")
centroid = coords.evaluate(element=1, xi=(0.5, 0.5, 0.5))
print("centroid:", centroid)
Export to meshio (requires [meshio] extra)¶
In [ ]:
Copied!
try:
m = doc.to_meshio()
print("meshio cell type:", m.cells[0].type, "count:", len(m.cells[0].data))
except ImportError as exc:
print("meshio not installed; install with: pip install pyfieldml[meshio]")
print(exc)
try:
m = doc.to_meshio()
print("meshio cell type:", m.cells[0].type, "count:", len(m.cells[0].data))
except ImportError as exc:
print("meshio not installed; install with: pip install pyfieldml[meshio]")
print(exc)
Next steps¶
- See
02_evaluator_graph.ipynbfor a tour of the evaluator hierarchy. - See
04_muscle_fibers.ipynbfor a fiber-field workflow.