Skip to content

Eurocode fire analysis: 500 °C isotherm method — Part 2: Post-processing

This script loads the model produced by fire_isotherm_500.py and builds the reduced cross-section geometry per EN 1992-1-2 §B.2 (500 °C isotherm method):

  1. Load the serialized model from the pickle written by Part 1.
  2. Query results directly from the existing SQLite database (no solver run, no re-extraction — the DB connection is recreated lazily).
  3. Remove elements where T > 500 °C using filter_model.
  4. Visualise the reduced section and generate comparison plots.

Run fire_isotherm_500.py first to generate the analysis results.

The model before it is solved: parts, supports and loads

The model before it is solved: its parts, supports (red) and loads (blue).

The result: the model coloured by temperature (T [K])

The model, coloured by temperature (T [K]), in xfea’s 3D viewer.

Open in 3D turn it, cut it, pick any field: in xfea's viewer, in your browser

examples/scripts/02_core_concepts/thermal_analysis/fire_isotherm_500_postprocess.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/thermal_analysis/fire_isotherm_500_postprocess.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/thermal_analysis/fire_isotherm_500_postprocess.py.

import os
import matplotlib.pyplot as plt
import numpy as np
from xfea.model import Model
from xfea.results import TemperatureFieldResults
from xfea_examples import out_dir
from xfea_examples import show_viewer
from xfea_tools import filter_model
# Load model from Part 1
MODEL_NAME = "fire_isotherm_500"
FIRE_DURATION = 7200 # [s] fire exposure duration (must match Part 1)
model_pkl = os.path.join(out_dir(MODEL_NAME), "model.pkl")
print(f"Loading model from: {model_pkl}")
model = Model.from_pickle(model_pkl)
part = list(model.parts)[0]
print(f"Mesh: {len(list(part.nodes))} nodes, {len(list(part.elements))} elements")
# Recover the existing problem, step, and temperature field
# The pickle preserves the full object graph: Model → Problem → Step →
# FieldResults. Problem.__getstate__ nulls the _rdb (results database)
# before pickling; the lazy .rdb property recreates it on first access
# using the preserved _path, so results are available immediately.
problem = list(model.problems)[0]
step = problem.steps[0]
# Find the TemperatureFieldResults registered to the step
temp = None
for fo in step.field_outputs:
if isinstance(fo, TemperatureFieldResults):
temp = fo
break
if temp is None:
raise RuntimeError("No TemperatureFieldResults found in the deserialized model. "
"Run fire_isotherm_500.py first.")
print(f"Problem: {problem.name}")
print(f"Step: {step.name}")
print(f"DB: {problem.rdb.db_uri}")
min_T = temp.get_min_result("T", time=FIRE_DURATION)
max_T = temp.get_max_result("T", time=FIRE_DURATION)
print(f"Final temperatures: min = {float(min_T.T):.1f} K ({float(min_T.T) - 273.15:.1f} °C), "
f"max = {float(max_T.T):.1f} K ({float(max_T.T) - 273.15:.1f} °C)")
# 500 °C isotherm — remove elements where T > 773.15 K (500 °C)
T_ISOTHERM = 773.15 # [K] 500 °C isotherm threshold
print(f"\n{'=' * 60}")
print(f"500 °C isotherm: removing elements where T > {T_ISOTHERM} K")
print("=" * 60)
n_orig = len(list(part.elements))
reduced = filter_model(
model, temp, "T",
condition=lambda T: T > T_ISOTHERM,
mode="remove",
cleanup_orphans=True,
copy_fields=False,
smooth=3,
time=FIRE_DURATION,
)
reduced_part = list(reduced.parts)[0]
n_reduced = len(list(reduced_part.elements))
n_removed = n_orig - n_reduced
print(f"Original: {n_orig} elements")
print(f"Reduced: {n_reduced} elements ({n_removed} removed, {n_removed/n_orig:.1%})")
# Export reduced section geometry
print(f"\n{'=' * 60}")
print("Exporting reduced section")
print("=" * 60)
step_path = os.path.join(out_dir(MODEL_NAME), "reduced_section.step")
reduced_part.to_step(step_path)
print(f" STEP (solid): {step_path}")
stl_path = os.path.join(out_dir(MODEL_NAME), "reduced_section.stl")
reduced_part.to_stl(stl_path)
print(f" STL: {stl_path}")
obj_path = os.path.join(out_dir(MODEL_NAME), "reduced_section.obj")
reduced_part.to_obj(obj_path)
print(f" OBJ: {obj_path}")
try:
vtu_path = os.path.join(out_dir(MODEL_NAME), "reduced_section.vtu")
reduced_part.to_meshio(vtu_path)
print(f" VTU (tets): {vtu_path}")
except ImportError:
print(" VTU: skipped (meshio not installed)")
# Viewer — show reduced section
print(f"\n{'=' * 60}")
print("Showing reduced cross-section in viewer")
print("=" * 60)
show_viewer(reduced)
# Cross-section comparison plots
print(f"\n{'=' * 60}")
print("Generating cross-section comparison plots")
print("=" * 60)
# Geometry dimensions (read from bounding box)
bbox = part.bounding_box
bb_width = bbox.xmax - bbox.xmin
bb_depth = bbox.ymax - bbox.ymin
bb_height = bbox.zmax - bbox.zmin
fig, axes = plt.subplots(1, 3, figsize=(20, 6))
# Collect results from the final time step
final_results = temp.get_results(time=FIRE_DURATION)
xs = np.array([r.location._x for r in final_results])
ys = np.array([r.location._y for r in final_results])
zs = np.array([r.location._z for r in final_results])
ts = np.array([float(r.T) - 273.15 for r in final_results]) # °C
# --- Panel 1: Temperature field at mid-section (y = depth/2) ---
y_mid = bbox.ymin + bb_depth / 2
mask_y = np.abs(ys - y_mid) < 30
tri = axes[0].tricontourf(xs[mask_y], zs[mask_y], ts[mask_y], levels=32, cmap="hot_r")
fig.colorbar(tri, ax=axes[0], label="Temperature [°C]")
try:
axes[0].tricontour(xs[mask_y], zs[mask_y], ts[mask_y],
levels=[500], colors="cyan", linewidths=2)
except Exception:
pass
axes[0].set_xlabel("x [mm]")
axes[0].set_ylabel("z [mm] (distance from fire face)")
axes[0].set_title(f"Temperature at y = {y_mid:.0f} mm (t = {FIRE_DURATION/60:.0f} min)")
axes[0].set_aspect("equal")
# --- Panel 2: Temperature profile through depth ---
x_mid = bbox.xmin + bb_width / 2
centre_mask = (np.abs(xs - x_mid) < 20) & (np.abs(ys - y_mid) < 20)
z_line = zs[centre_mask]
t_line = ts[centre_mask]
sort_idx = np.argsort(z_line)
axes[1].plot(z_line[sort_idx], t_line[sort_idx], "r-o", markersize=3, label="FEA")
axes[1].axhline(y=500, color="cyan", linestyle="--", linewidth=2, label="500 °C isotherm")
axes[1].set_xlabel("z [mm] (distance from fire face)")
axes[1].set_ylabel("Temperature [°C]")
axes[1].set_title("Temperature Profile Through Depth")
axes[1].legend()
axes[1].grid(True, alpha=0.3)
# --- Panel 3: Reduced cross-section ---
r_red = list(reduced_part.nodes)
xs_r = np.array([n._x for n in r_red])
ys_r = np.array([n._y for n in r_red])
zs_r = np.array([n._z for n in r_red])
mask_r = np.abs(ys_r - y_mid) < 30
if np.any(mask_r):
axes[2].scatter(xs_r[mask_r], zs_r[mask_r], s=3, c="steelblue", alpha=0.6)
axes[2].set_xlim(axes[0].get_xlim())
axes[2].set_ylim(axes[0].get_ylim())
axes[2].set_xlabel("x [mm]")
axes[2].set_ylabel("z [mm]")
axes[2].set_title(f"Reduced Section (T < 500 °C): {n_reduced} elements")
axes[2].set_aspect("equal")
fig.suptitle(
f"EN 1992-1-2 — 500 °C Isotherm Method (ISO 834, R{FIRE_DURATION//60})",
fontsize=14, fontweight="bold",
)
fig.tight_layout()
plot_path = os.path.join(out_dir(MODEL_NAME), "fire_isotherm_500_postprocess.png")
fig.savefig(plot_path, dpi=150)
print(f"Plot saved to: {plot_path}")
plt.close(fig)
# Summary
print(f"\n{'=' * 60}")
print("EN 1992-1-2 — 500 °C Isotherm Method Summary")
print("=" * 60)
print(f" Fire curve: ISO 834")
print(f" Exposure: {FIRE_DURATION/60:.0f} min (R{FIRE_DURATION//60})")
print(f" Section: {bb_width:.0f} x {bb_depth:.0f} x {bb_height:.0f} mm")
print(f" Max temperature: {float(max_T.T) - 273.15:.0f} C")
print(f" Min temperature: {float(min_T.T) - 273.15:.0f} C")
print(f" Original elements: {n_orig}")
print(f" Reduced elements: {n_reduced} ({n_removed/n_orig:.1%} removed)")
print(f" -> Reduced section carries ambient-temperature capacity per EN 1992-1-2 B.2")

© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them