Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
agentfem
finite-element-method
scientific-machine-learning
physics-ai
simulation
stress-concentration
License:
Download plot_notch.py from HaomingLuo/AgentFEM-DoubleNotch-Elasticity-2D: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-DoubleNotch-Elasticity-2D/resolve/main/plot_notch.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-DoubleNotch-Elasticity-2D/plot_notch.py
-
curl -L -o plot_notch.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-DoubleNotch-Elasticity-2D/resolve/main/plot_notch.py
3.2 kB
| """Plot published double-notch FEM fields without a solver. Apache-2.0.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| from matplotlib.tri import Triangulation | |
| from huggingface_hub import hf_hub_download | |
| REPO = "HaomingLuo/AgentFEM-DoubleNotch-Elasticity-2D" | |
| REVISION = "2d315d7dc6b9d41badceb02ac8fbb475e3413ec2" | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--data", type=Path, help="Existing test.h5; otherwise download pinned test split (~49 MB)") | |
| parser.add_argument("--sample", default="00016", help="HDF5 sample ID") | |
| parser.add_argument("--output", type=Path, default=Path("notch-fields.png")) | |
| args = parser.parse_args() | |
| path = args.data or hf_hub_download(REPO, "test.h5", repo_type="dataset", revision=REVISION) | |
| with h5py.File(path) as f: | |
| g = f[args.sample] | |
| p = json.loads(g.attrs["parameters_json"]) | |
| xy = g["coordinates"][:, :2] | |
| triangles = g["connectivity"][:, :3] # XDMF Triangle_6 corner nodes | |
| mises = g["cell/MISES"][:] | |
| displacement = g["point/UMAG"][:] | |
| assert np.isfinite(xy).all() and np.isfinite(mises).all() and np.isfinite(displacement).all() | |
| assert triangles.min() >= 0 and triangles.max() < len(xy) | |
| centers = xy[triangles].mean(axis=1) | |
| central = (centers[:, 0] > .3*p["length_m"]) & (centers[:, 0] < .7*p["length_m"]) | |
| central_max = float(mises[central].max()) | |
| mesh = Triangulation(*(xy * 1000).T, triangles=triangles) | |
| plt.rcParams.update({"font.family": "DejaVu Sans", "font.size": 10}) | |
| fig, axes = plt.subplots(2, 1, figsize=(10, 6.5), constrained_layout=True) | |
| values = (displacement * 1e6, mises / 1e6) | |
| for ax, value, title, unit, cmap in zip(axes, values, | |
| ("Displacement magnitude", "Von Mises stress · original cell values"), | |
| ("Displacement / µm", "Stress / MPa"), ("viridis", "magma")): | |
| if ax is axes[0]: | |
| # Linear display on corner nodes, not a new FEM reconstruction. | |
| artist = ax.tripcolor(mesh, value, shading="gouraud", cmap=cmap) | |
| else: | |
| artist = ax.tripcolor(mesh, facecolors=value, shading="flat", cmap=cmap) | |
| for fraction in (.3, .7): | |
| ax.axvline(fraction*p["length_m"]*1000, color="#158b83", ls="--", lw=1) | |
| ax.set(title=title, xlabel="x / mm", ylabel="y / mm", aspect="equal") | |
| ax.spines[["top", "right"]].set_visible(False) | |
| fig.colorbar(artist, ax=ax, label=unit, shrink=.85, pad=.02) | |
| fig.suptitle(f"AgentFEM · Double-notch plate | sample {args.sample}\n" | |
| f"Applied traction {p['traction_pa']/1e6:.2f} MPa · Central-region cell maximum {central_max/1e6:.2f} MPa", | |
| fontsize=13) | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| fig.savefig(args.output, dpi=180) | |
| plt.close(fig) | |
| print(json.dumps({"sample": args.sample, "central_cell_mises_max_pa": central_max, | |
| "maximum_displacement_um": float(displacement.max()*1e6), "output": str(args.output)})) | |
| if __name__ == "__main__": | |
| main() | |