# 材料性能数据库 · 机器可读接口文档

本文档面向大模型 / Agent / 脚本，介绍如何查询材料性能数据库。
所有端点均为 **GET**、**无需登录认证**，返回 UTF-8 JSON（`ensure_ascii=False`）。

文档本身通过 `GET /mech/material-properties/llms.md` 以 `text/markdown` 原文提供，可被抓取后直接阅读。

## 端点一览

以下均为相对路径，拼接部署域名即可使用（如 `http://127.0.0.1:8000` 或线上站点域名）。

| 用途 | 路径 | 返回 |
|---|---|---|
| ① 材料清单（**发现入口，先调这个**） | `/mech/material-properties/api/materials/` | JSON 数组 |
| ② 单材料全部当前性能（**推荐数据入口**） | `/mech/material-properties/api/<identifier>/` | JSON 对象 |
| ③ 单材料导出（浏览器下载） | `/mech/material-properties/export/material/<pk>/json/` | JSON 附件 |
| ④ 单性能导出 | `/mech/material-properties/export/property/<pk>/json/` 或 `.../csv/` | JSON / CSV 附件 |
| 本文档 | `/mech/material-properties/llms.md` | Markdown |

- `<identifier>` 可以是材料主键（数字，如 `3`）或材料名称 URL 编码（如 `Hastelloy%20N`）。
- ② 和 ③ 返回的数据内容一致；③ 带 `Content-Disposition: attachment`（浏览器触发下载，对程序无影响）。
- ② 与 ④ 只返回 `is_current=True` 的当前版本性能；历史版本请在网页端查看。

## 快速开始

```bash
# 第 1 步：获取材料清单，确定要查的材料 pk / 名称
curl -s http://127.0.0.1:8000/mech/material-properties/api/materials/

# 第 2 步：按 pk 或名称取该材料全部当前性能
curl -s http://127.0.0.1:8000/mech/material-properties/api/1/
curl -s "http://127.0.0.1:8000/mech/material-properties/api/IG-110%20%E6%A0%B8%E7%9F%B3%E5%A2%A8/"
```

当前库中的材料（示例，实际以 ① 的返回为准）：`1 Hastelloy N (N10003)`、`2 NG-CT-10 核石墨`、`3 IG-110 核石墨`、`4 SA SiC 单相碳化硅管`、`5 Silit SK SiSiC 高温管`。

## 材料清单结构（端点 ①）

```json
[
  {
    "pk": 1,
    "name": "Hastelloy N",
    "uns": "N10003",
    "description": "…",
    "current_property_count": 10,
    "api_path": "/mech/material-properties/api/1/"
  }
]
```

`api_path` 是该材料端点 ② 的路径，直接拼接域名调用即可。

## 单材料数据结构（端点 ②）

```json
{
  "material": {"name": "Hastelloy N", "uns": "N10003", "description": "…"},
  "properties": [ { … }, { … } ]
}
```

`properties` 中每条记录的字段：

| 字段 | 类型 | 说明 |
|---|---|---|
| `property` | string | 性能规范名（英文），如 `density`、`elastic_modulus`、`stress_rupture` |
| `display_name` | string | 中文显示名 |
| `symbol` | string | 工程符号（`E`、`ρ`、`Sr`…），可能为空 |
| `category` | string | 分类：`physical` / `thermal` / `mechanical` / `other` |
| `abaqus_keyword` | string | 对应 Abaqus 卡片关键字（`*Density`…），无对应时为空 |
| `unit` | string | `y` 值的单位（SI），如 `Pa`、`kg/m^3`、`MPa` |
| `variables` | array | 自变量定义，每项含 `name` / `label` / `unit`（可含 `role`：`x` 主绘图轴 / `condition` 试验条件） |
| `observation_variables` | array | 附加观测值列定义（同结构），无则为 `[]` |
| `chart` | object | 页面绘图配置（`x`、`x_scale`、`y_scale`、`series_by`），仅供绘图参考 |
| `is_temperature_dependent` | bool | 数据点多于 1 个时为 `true` |
| `data_points` | array | 见下文 |
| `source_status` | string | 数据等级，枚举见下表 |
| `source_title` / `source_url` | string | 数据来源，URL 可能为空 |
| `validity_note` | string | 有效范围说明（如 `20–1000 °C`） |
| `metadata` | object | 性能特有解释元数据，多数为 `{}`（见下文） |
| `note` | string | 适用性说明，可能为空 |

### data_points 与多维数据

每个数据点是 `{"inputs": {...}, "observations": {...}, "y": 值}`：

- `inputs` 的键名与 `variables` 的 `name` 一一对应；`variables` 的长度就是维度数。
- `y` 是性能主值，单位为该记录的 `unit`。
- `observations` 是附加观测值（如疲劳试验的应力幅），键名对应 `observation_variables` 的 `name`，无则为 `{}`。

一维示例（密度，温度相关）：

```json
{"inputs": {"temperature": 20.0}, "observations": {}, "y": 8860.0}
```

二维示例（应力断裂强度 Sr：温度 × 断裂时间 → 应力）：

```json
{"inputs": {"temperature": 600.0, "rupture_time": 1000.0}, "observations": {}, "y": 232.34}
```

## source_status 枚举

| 值 | 含义 |
|---|---|
| `design_report` | 设计方案报告给定参数 |
| `manufacturer_public_constant` | 制造商公开常数 |
| `manufacturer_public_table` | 制造商公开数据表 |
| `public_measured_table` | 公开测量数据表 |
| `public_derived_table` | 公开推导数据表（如 k = α·cp·ρ） |
| `public_constant_assumption` | 公开常数假设 |
| `public_correlation` | 公开拟合公式 |

## metadata 特殊键

多数性能 `metadata` 为 `{}`；遇到未知键请忽略。已知键：

| 键 | 适用性能 | 说明 |
|---|---|---|
| `correlation_expression` | 报告中仅给出关联式、无离散数据点的性能 | 原样公式文本，不由 API 执行 |
| `correlation_variable` | 同上 | 公式自变量名称，如 `temperature` |
| `correlation_temperature_unit` | 同上 | 公式中的温度单位，如 `K` 或 `°C` |
| `formula_execution` | 同上 | 当前固定为 `not_supported` |
| `expansion_definition` | `thermal_expansion_coefficient` | `"mean"`（平均热膨胀系数）或 `"instantaneous"`（瞬时） |
| `reference_temperature` | `thermal_expansion_coefficient` | 平均 CTE 的参考温度（°C） |
| `source_material` | `low_cycle_fatigue`、`ludwik_parameters` | 实际试验材料（见下方警示） |
| `model` / `temperature_labels` | `ludwik_parameters` | 本构模型公式、原始温度标签 |

## 使用注意

1. **单位均为 SI**（m-kg-s-J-K）。写入其他单位制的求解器（如 Abaqus mm-tonne-s）前必须自行换算，接口不做转换。
2. **来源材料警示**：`low_cycle_fatigue` 与 `ludwik_parameters` 来自 GH3535 试验数据，按归档要求挂在 Hastelloy N / UNS N10003 名下，`metadata.source_material` 有标注。引用时必须保留这一警告，不得当作 N10003 的直接性能。
3. `validity_note` 给出数据有效范围，范围外插值外推需向用户明确提示。
4. 若需把数据写成 Abaqus 材料卡片（`*Elastic` 分组、单位换算表、缺失数据清单等），参见仓库内 `mech_apps/material_properties/docs/abaqus-mcp-integration.md`。
