Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
agentfem
finite-element-method
scientific-machine-learning
physics-ai
simulation
heat-transfer
License:
Add runnable heat-source and temperature-field plotting recipe
Browse files- README.md +15 -0
- heat-input-output.png +3 -0
- plot_heat.py +99 -0
README.md
CHANGED
|
@@ -40,6 +40,21 @@ Predict peak temperature rise from the source and material parameters, then comp
|
|
| 40 |
|
| 41 |
[Load the test split](load_example.py) · [Inspect baseline results](baselines.json) · [Practice heat conduction with AgentFEM](https://lab.haoming-luo.com/learn/)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
## Physical problem
|
| 44 |
|
| 45 |
Steady isotropic conduction: -div(k grad(T)) = q. All four edges are held at 300 K. The two Gaussian sources are uniform through the unit out-of-plane thickness. No air flow, contact resistance, radiation, or convection is solved.
|
|
|
|
| 40 |
|
| 41 |
[Load the test split](load_example.py) · [Inspect baseline results](baselines.json) · [Practice heat conduction with AgentFEM](https://lab.haoming-luo.com/learn/)
|
| 42 |
|
| 43 |
+
### See the source and temperature together
|
| 44 |
+
|
| 45 |
+
Run [plot_heat.py](plot_heat.py) to draw one recorded sample: heat generation on the left, temperature rise on the right. It downloads only the pinned test split (about 1.9 MB), uses the actual triangular mesh, and prints the peak temperature and its coordinates. No FEM installation or GPU is needed.
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
pip install numpy h5py matplotlib huggingface_hub
|
| 49 |
+
python plot_heat.py
|
| 50 |
+
# Or use a file you already downloaded:
|
| 51 |
+
python plot_heat.py --data test.h5 --sample 00016 --output heat.png
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+

|
| 55 |
+
|
| 56 |
+
The circle marks the hottest mesh node. Compare the two source locations with that point: source strength alone does not determine the temperature, because heat spreads through the plate and escapes at the cooled edges. This figure reads a stored solution; changing a source parameter requires a new solve, not recolouring this image.
|
| 57 |
+
|
| 58 |
## Physical problem
|
| 59 |
|
| 60 |
Steady isotropic conduction: -div(k grad(T)) = q. All four edges are held at 300 K. The two Gaussian sources are uniform through the unit out-of-plane thickness. No air flow, contact resistance, radiation, or convection is solved.
|
heat-input-output.png
ADDED
|
Git LFS Details
|
plot_heat.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Plot heat inputs and recorded FEM temperatures. SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
|
| 3 |
+
pip install numpy h5py matplotlib huggingface_hub
|
| 4 |
+
python plot_heat.py
|
| 5 |
+
python plot_heat.py --data test.h5 --sample 00016 --output heat.png
|
| 6 |
+
|
| 7 |
+
This reads an existing FEM result, not a new simulation or neural prediction.
|
| 8 |
+
Data: CC BY 4.0, Haoming Luo / AgentFEM-MultiSource-Heat-2D (2026).
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
import h5py
|
| 16 |
+
import matplotlib
|
| 17 |
+
matplotlib.use("Agg")
|
| 18 |
+
import matplotlib.pyplot as plt
|
| 19 |
+
import matplotlib.tri as mtri
|
| 20 |
+
import numpy as np
|
| 21 |
+
|
| 22 |
+
REPO = "HaomingLuo/AgentFEM-MultiSource-Heat-2D"
|
| 23 |
+
REVISION = "7d19e509b4fdc33c767cbc469c9a669d817b11e4"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def read_sample(path, sample_id=None):
|
| 27 |
+
with h5py.File(path, "r") as handle:
|
| 28 |
+
key = sample_id or sorted(handle)[0]
|
| 29 |
+
if key not in handle:
|
| 30 |
+
raise ValueError(f"Sample {key!r} not found. Available: {', '.join(sorted(handle))}")
|
| 31 |
+
group = handle[key]
|
| 32 |
+
parameters = json.loads(group.attrs["parameters_json"])
|
| 33 |
+
xy = group["coordinates"][:, :2]
|
| 34 |
+
triangles = group["connectivity"][:]
|
| 35 |
+
source = group["inputs/source_w_m3"][:]
|
| 36 |
+
temperature = group["point/Temperature"][:]
|
| 37 |
+
boundary = group["inputs/cooled_boundary"][:].astype(bool)
|
| 38 |
+
if triangles.shape[1] != 3:
|
| 39 |
+
raise ValueError("This recipe expects linear triangular elements.")
|
| 40 |
+
if not all(np.isfinite(a).all() for a in (xy, source, temperature)):
|
| 41 |
+
raise ValueError("Non-finite field values.")
|
| 42 |
+
if not boundary.any():
|
| 43 |
+
raise ValueError("Missing cooled boundary nodes.")
|
| 44 |
+
if not np.allclose(temperature[boundary], 300.0, atol=1e-7, rtol=0):
|
| 45 |
+
raise ValueError("Boundary temperature differs from the documented 300 K.")
|
| 46 |
+
return key, parameters, xy, triangles, source, temperature
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def main():
|
| 50 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 51 |
+
parser.add_argument("--data", type=Path, help="Existing split HDF5 file; otherwise download pinned test split")
|
| 52 |
+
parser.add_argument("--sample", help="Sample ID, for example 00016")
|
| 53 |
+
parser.add_argument("--output", type=Path, default=Path("heat-input-output.png"))
|
| 54 |
+
args = parser.parse_args()
|
| 55 |
+
path = args.data
|
| 56 |
+
if path is None:
|
| 57 |
+
from huggingface_hub import hf_hub_download
|
| 58 |
+
path = hf_hub_download(REPO, "test.h5", repo_type="dataset", revision=REVISION)
|
| 59 |
+
key, p, xy, triangles, source, temperature = read_sample(path, args.sample)
|
| 60 |
+
peak = int(np.argmax(temperature))
|
| 61 |
+
report = {
|
| 62 |
+
"sample": key,
|
| 63 |
+
"conductivity_W_m_K": p["conductivity_w_m_k"],
|
| 64 |
+
"peak_temperature_K": float(temperature[peak]),
|
| 65 |
+
"peak_rise_K": float(temperature[peak] - 300),
|
| 66 |
+
"peak_node_xy_mm": (xy[peak] * 1000).tolist(),
|
| 67 |
+
"source": "Recorded finite-element result; not a new solve",
|
| 68 |
+
}
|
| 69 |
+
print(json.dumps(report, indent=2))
|
| 70 |
+
mesh = mtri.Triangulation(xy[:, 0] * 1000, xy[:, 1] * 1000, triangles)
|
| 71 |
+
plt.rcParams.update({"font.family": "DejaVu Sans", "font.size": 10,
|
| 72 |
+
"axes.spines.top": False, "axes.spines.right": False})
|
| 73 |
+
fig, axes = plt.subplots(1, 2, figsize=(11, 4.4))
|
| 74 |
+
fig.subplots_adjust(left=.065, right=.95, bottom=.21, top=.76, wspace=.34)
|
| 75 |
+
fig.suptitle("Two heat sources. One temperature field.", x=.065, ha="left", y=.96,
|
| 76 |
+
fontsize=19, fontweight="bold", color="#173a42")
|
| 77 |
+
fig.text(.065, .855, f"AgentFEM / sample {key} / k = {p['conductivity_w_m_k']:.2f} W/(m K)"
|
| 78 |
+
" / all edges at 300 K", color="#536a70")
|
| 79 |
+
for ax, values, title, label, cmap in zip(
|
| 80 |
+
axes, (source / 1e6, temperature - 300),
|
| 81 |
+
("Input: distributed heat generation", "Output: temperature rise"),
|
| 82 |
+
("q / MW m$^{-3}$", "T - 300 K / K"), ("magma", "inferno")):
|
| 83 |
+
artist = ax.tripcolor(mesh, values, shading="gouraud", cmap=cmap, vmin=0)
|
| 84 |
+
fig.colorbar(artist, ax=ax, fraction=.045, pad=.035, label=label)
|
| 85 |
+
ax.set(title=title, xlabel="x / mm", ylabel="y / mm", aspect="equal")
|
| 86 |
+
ax.set_xlim(0, p["length_m"] * 1000)
|
| 87 |
+
ax.set_ylim(0, p["height_m"] * 1000)
|
| 88 |
+
axes[1].plot(*(xy[peak] * 1000), "o", ms=5, mfc="none", mec="#66e4dc", mew=1.4)
|
| 89 |
+
fig.text(.065, .08, f"Peak nodal rise: {temperature[peak] - 300:.3f} K. "
|
| 90 |
+
"The hottest point need not coincide with the strongest source.", color="#173a42")
|
| 91 |
+
fig.text(.065, .025, "Recorded FEM fields • source shown by nodal interpolation • data CC BY 4.0 • Haoming Luo / AgentFEM",
|
| 92 |
+
fontsize=8, color="#536a70")
|
| 93 |
+
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 94 |
+
fig.savefig(args.output, dpi=180, facecolor="white")
|
| 95 |
+
plt.close(fig)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
main()
|