File size: 953 Bytes
3e77c56 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | """Shared stress-field renderer (used by the Gate-0 sanity plot and the Gradio demo)."""
from __future__ import annotations
from typing import Optional
import numpy as np
def render_stress(
coords: np.ndarray,
sigma: np.ndarray,
title: str = "von Mises stress",
ax=None,
vmin: Optional[float] = None,
vmax: Optional[float] = None,
cmap: str = "coolwarm",
):
"""Scatter the per-node stress over the point cloud. Returns the matplotlib Figure.
coords: (N, 2) node coordinates; sigma: (N,) per-node stress.
"""
import matplotlib.pyplot as plt
if ax is None:
fig, ax = plt.subplots(figsize=(5, 5))
else:
fig = ax.figure
sc = ax.scatter(
coords[:, 0], coords[:, 1], c=sigma, s=18, cmap=cmap,
vmin=vmin, vmax=vmax, edgecolor="w", lw=0.1,
)
ax.set_aspect("equal")
ax.set_title(title)
fig.colorbar(sc, ax=ax, shrink=0.8, label="sigma")
return fig
|