Files
AutoControlCourse/assets/knowledge_cards_html.py
T
2026-04-07 19:23:12 +08:00

2173 lines
154 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
知识卡片内容 - 包含时域、频域、根轨迹、控制器设计、模型蒸馏、能量管理分析的公式和方法
使用纯HTML格式,无需LaTeX渲染库
"""
# 时域分析知识卡片
TIME_DOMAIN_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #667eea; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>📚</span> 时域分析常用公式
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 二阶系统标准形式
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p style='margin: 10px 0;'><strong>标准传递函数:</strong></p>
<div style='text-align: center; background: white; padding: 20px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.3em; display: inline-block;'>
<i>G</i>(<i>s</i>) =
<div style='display: inline-block; vertical-align: middle; margin: 0 8px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 10px 5px;'>ω<sub>n</sub><sup>2</sup></div>
<div style='text-align: center; padding: 5px 10px 0;'><i>s</i><sup>2</sup> + 2ζω<sub>n</sub><i>s</i> + ω<sub>n</sub><sup>2</sup></div>
</div>
</div>
</div>
<h4 style='color: #667eea; margin-top: 20px; font-size: 1.1em;'>📊 关键参数</h4>
<table style='width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 0.95em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;'>
<th style='padding: 12px; text-align: left; font-weight: 700;'>参数</th>
<th style='padding: 12px; text-align: left; font-weight: 700;'>含义</th>
<th style='padding: 12px; text-align: left; font-weight: 700;'>影响</th>
</tr>
<tr style='background: white;'>
<td style='padding: 10px; border: 1px solid #e0e7ff;'><strong>ζ (zeta)</strong></td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>阻尼比</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>控制超调量和振荡</td>
</tr>
<tr style='background: #f8f9ff;'>
<td style='padding: 10px; border: 1px solid #e0e7ff;'><strong>ω<sub>n</sub></strong></td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>无阻尼自然频率 (rad/s)</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>决定响应速度</td>
</tr>
</table>
<h4 style='color: #764ba2; margin-top: 20px; font-size: 1.1em;'>🎯 阻尼比分类</h4>
<ul style='line-height: 2; margin-left: 20px;'>
<li><strong style='color: #f5576c;'>ζ &lt; 0:</strong> 不稳定系统</li>
<li><strong style='color: #ffa726;'>ζ = 0:</strong> 无阻尼振荡</li>
<li><strong style='color: #4caf50;'>0 &lt; ζ &lt; 1:</strong> 欠阻尼(有振荡)⭐ 最常见</li>
<li><strong style='color: #2196f3;'>ζ = 1:</strong> 临界阻尼(无超调)</li>
<li><strong style='color: #9c27b0;'>ζ &gt; 1:</strong> 过阻尼(响应慢)</li>
</ul>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #fff0f8 0%, #fce4ec 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📊 时域性能指标(欠阻尼系统)
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #667eea;'>
<strong style='color: #667eea; font-size: 1.1em;'>1️⃣ 上升时间 (Rise Time, t<sub>r</sub>)</strong>
<p style='margin: 8px 0;'>响应从 10% 上升到 90% 终值所需时间</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0;'>
<div style='font-size: 1.2em; display: inline-block;'>
<i>t</i><sub>r</sub> ≈
<div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>1.8</div>
<div style='text-align: center; padding: 3px 8px 0;'>ω<sub>n</sub></div>
</div>
</div>
</div>
</div>
<div style='background: linear-gradient(135deg, #fff4f0 0%, #ffe0b2 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #ff9800;'>
<strong style='color: #f57c00; font-size: 1.1em;'>2️⃣ 峰值时间 (Peak Time, t<sub>p</sub>)</strong>
<p style='margin: 8px 0;'>响应达到第一个峰值的时间</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0;'>
<div style='font-size: 1.2em; display: inline-block;'>
<i>t</i><sub>p</sub> =
<div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>π</div>
<div style='text-align: center; padding: 3px 8px 0;'>ω<sub>n</sub>√(1−ζ²)</div>
</div>
=
<div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>π</div>
<div style='text-align: center; padding: 3px 8px 0;'>ω<sub>d</sub></div>
</div>
</div>
</div>
<p style='margin: 8px 0; color: #666; font-size: 0.95em;'>其中 ω<sub>d</sub> = ω<sub>n</sub>√(1−ζ²) 为阻尼振荡频率</p>
</div>
<div style='background: linear-gradient(135deg, #f0fff4 0%, #c8e6c9 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #4caf50;'>
<strong style='color: #388e3c; font-size: 1.1em;'>3️⃣ 超调量 (Overshoot, σ%)</strong>
<p style='margin: 8px 0;'>响应超过稳态值的最大百分比</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0; font-size: 1.2em;'>
σ% = <i>e</i><sup>−πζ/√(1−ζ²)</sup> × 100%
</div>
<p style='margin: 8px 0; color: #388e3c; font-weight: 600;'>💡 仅与 ζ 有关!</p>
<table style='width: 100%; margin: 10px 0; font-size: 0.9em;'>
<tr style='background: #e8f5e9;'>
<td style='padding: 6px; border: 1px solid #c8e6c9;'><strong>ζ = 0.5</strong></td>
<td style='padding: 6px; border: 1px solid #c8e6c9;'>σ% ≈ 16%</td>
</tr>
<tr style='background: white;'>
<td style='padding: 6px; border: 1px solid #c8e6c9;'><strong>ζ = 0.707</strong></td>
<td style='padding: 6px; border: 1px solid #c8e6c9;'>σ% ≈ 4.3% ⭐ 最佳</td>
</tr>
</table>
</div>
<div style='background: linear-gradient(135deg, #fff0f8 0%, #f3e5f5 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #9c27b0;'>
<strong style='color: #7b1fa2; font-size: 1.1em;'>4️⃣ 调节时间 (Settling Time, t<sub>s</sub>)</strong>
<p style='margin: 8px 0;'>响应达到并保持在稳态值 ±2%(或±5%)范围内的时间</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0;'>
<div style='font-size: 1.2em;'>
<i>t</i><sub>s</sub> ≈
<div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>4</div>
<div style='text-align: center; padding: 3px 8px 0;'>ζω<sub>n</sub></div>
</div>
&nbsp; (2% 误差带)
</div>
<div style='font-size: 1.2em; margin-top: 10px;'>
<i>t</i><sub>s</sub> ≈
<div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>3</div>
<div style='text-align: center; padding: 3px 8px 0;'>ζω<sub>n</sub></div>
</div>
&nbsp; (5% 误差带)
</div>
</div>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎯 一阶系统特性
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p><strong>标准传递函数:</strong></p>
<div style='text-align: center; background: white; padding: 20px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.3em; display: inline-block;'>
<i>G</i>(<i>s</i>) =
<div style='display: inline-block; vertical-align: middle; margin: 0 8px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 10px 5px;'><i>K</i></div>
<div style='text-align: center; padding: 5px 10px 0;'>τ<i>s</i> + 1</div>
</div>
</div>
</div>
<p><strong>阶跃响应:</strong></p>
<div style='text-align: center; background: white; padding: 20px; border-radius: 8px; margin: 10px 0; font-size: 1.2em;'>
<i>y</i>(<i>t</i>) = <i>K</i>(1 <i>e</i><sup><i>t</i>/τ</sup>)
</div>
<div style='background: #e3f2fd; padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 关键时间点:</strong></p>
<ul style='line-height: 1.8;'>
<li><strong><i>t</i> = τ:</strong> 达到稳态值的 63.2%</li>
<li><strong><i>t</i> = 3τ:</strong> 达到稳态值的 95%</li>
<li><strong><i>t</i> = 4τ:</strong> 达到稳态值的 98.2%</li>
<li><strong><i>t</i> = 5τ:</strong> 达到稳态值的 99.3%</li>
</ul>
</div>
</div>
</details>
</div>
"""
# 频域分析知识卡片
FREQUENCY_DOMAIN_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #667eea; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>📚</span> 频域分析常用方法
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎯 增益裕度 (Gain Margin, GM)
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p><strong>定义:</strong>在相角为 -180° 时,系统增益可增加的最大倍数</p>
<div style='text-align: center; background: white; padding: 20px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.3em;'>
GM<sub>dB</sub> = 20log<sub>10</sub>|<i>G</i>(<i>j</i>ω<sub>pc</sub>)|
</div>
</div>
<p style='margin: 8px 0;'><strong>ω<sub>pc</sub></strong> - 相角交越频率(相角 = -180°)</p>
<h4 style='color: #667eea; margin-top: 15px;'>判断准则</h4>
<table style='width: 100%; border-collapse: collapse; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: #e8f5e9;'>
<td style='padding: 10px; border: 1px solid #c8e6c9; font-weight: 600;'>GM &gt; 0 dB</td>
<td style='padding: 10px; border: 1px solid #c8e6c9;'>✅ 系统稳定</td>
</tr>
<tr style='background: #fff3e0;'>
<td style='padding: 10px; border: 1px solid #ffe0b2; font-weight: 600;'>GM = 0 dB</td>
<td style='padding: 10px; border: 1px solid #ffe0b2;'>⚠️ 临界稳定</td>
</tr>
<tr style='background: #ffebee;'>
<td style='padding: 10px; border: 1px solid #ffcdd2; font-weight: 600;'>GM &lt; 0 dB</td>
<td style='padding: 10px; border: 1px solid #ffcdd2;'>❌ 系统不稳定</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 工程要求:</strong>通常要求 <strong>GM ≥ 6 dB</strong>(约2倍增益余量)</p>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎯 相角裕度 (Phase Margin, PM)
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p><strong>定义:</strong>在增益为 1 (0dB) 时,系统相角与 -180° 的差值</p>
<div style='text-align: center; background: white; padding: 20px; border-radius: 8px; margin: 10px 0; font-size: 1.3em;'>
PM = 180° + ∠<i>G</i>(<i>j</i>ω<sub>gc</sub>)
</div>
<p style='margin: 8px 0;'><strong>ω<sub>gc</sub></strong> - 增益交越频率(幅值 = 1 或 0dB</p>
<h4 style='color: #764ba2; margin-top: 15px;'>判断准则</h4>
<table style='width: 100%; border-collapse: collapse; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: #e8f5e9;'>
<td style='padding: 10px; border: 1px solid #c8e6c9; font-weight: 600;'>PM &gt; 0°</td>
<td style='padding: 10px; border: 1px solid #c8e6c9;'>✅ 系统稳定</td>
</tr>
<tr style='background: #fff3e0;'>
<td style='padding: 10px; border: 1px solid #ffe0b2; font-weight: 600;'>PM = 0°</td>
<td style='padding: 10px; border: 1px solid #ffe0b2;'>⚠️ 临界稳定</td>
</tr>
<tr style='background: #ffebee;'>
<td style='padding: 10px; border: 1px solid #ffcdd2; font-weight: 600;'>PM &lt; 0°</td>
<td style='padding: 10px; border: 1px solid #ffcdd2;'>❌ 系统不稳定</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 工程要求:</strong>通常要求 <strong>PM ∈ [30°, 60°]</strong></p>
<p style='margin: 8px 0;'>• PM ≈ 45° ~ 60°: 良好阻尼特性</p>
<p style='margin: 8px 0;'>• PM 越大,超调量越小</p>
</div>
<h4 style='color: #f57c00; margin-top: 15px;'>与时域性能的关系</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0; font-size: 1.2em;'>
ζ ≈ <div style='display: inline-block; vertical-align: middle; margin: 0 5px;'>
<div style='text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>PM</div>
<div style='text-align: center; padding: 3px 8px 0;'>100</div>
</div> &nbsp; (PM 以度为单位)
</div>
<table style='width: 100%; margin: 10px 0; font-size: 0.9em; box-shadow: 0 2px 6px rgba(0,0,0,0.06); border-radius: 6px; overflow: hidden;'>
<tr style='background: #f5f5f5; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #ddd;'>PM</td>
<td style='padding: 8px; border: 1px solid #ddd;'>ζ</td>
<td style='padding: 8px; border: 1px solid #ddd;'>超调量</td>
</tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'>30°</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 0.3</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 37%</td></tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'>45°</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 0.45</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 20%</td></tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'>60°</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 0.6</td><td style='padding: 8px; border: 1px solid #ddd;'>≈ 10% ⭐</td></tr>
</table>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fff0f8 0%, #fce4ec 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📊 Bode 图与 Nyquist 图
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<h4 style='color: #667eea;'>Bode 图(伯德图)</h4>
<p><strong>组成:</strong>幅频特性图 + 相频特性图</p>
<ul style='line-height: 1.8;'>
<li><strong>横轴:</strong>频率 ω (对数刻度)</li>
<li><strong>纵轴(幅频):</strong>20log|<i>G</i>(<i>j</i>ω)| (dB)</li>
<li><strong>纵轴(相频):</strong>∠<i>G</i>(<i>j</i>ω) (度)</li>
</ul>
<div style='background: #e3f2fd; padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 优点:</strong></p>
<ul style='line-height: 1.6;'>
<li>便于绘制(渐近线近似)</li>
<li>直观读取稳定裕度</li>
<li>串联系统可图形叠加</li>
</ul>
</div>
<h4 style='color: #764ba2; margin-top: 20px;'>Nyquist 图(奈奎斯特图)</h4>
<p><strong>定义:</strong>开环频率特性在复平面上的轨迹</p>
<div style='background: #fff3e0; padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>🎯 奈奎斯特稳定判据:</strong></p>
<p style='text-align: center; font-weight: 600; margin: 10px 0; font-size: 1.2em;'><i>Z</i> = <i>P</i> <i>N</i></p>
<p style='font-size: 0.95em;'>• <i>Z</i>: 闭环右半平面极点数<br>
• <i>P</i>: 开环右半平面极点数<br>
• <i>N</i>: 曲线逆时针包围 (1, <i>j</i>0) 的圈数</p>
<p style='margin-top: 10px; color: #f57c00; font-weight: 600;'>稳定条件:<i>Z</i> = 0</p>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔧 典型环节频率特性
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<div style='margin-bottom: 15px; padding: 12px; background: white; border-radius: 8px; border-left: 4px solid #667eea;'>
<h4 style='margin-top: 0; color: #667eea;'>1️⃣ 比例环节 <i>K</i></h4>
<p>• 幅频:20log<i>K</i> (dB) - 水平线<br>• 相频:0° - 水平线</p>
</div>
<div style='margin-bottom: 15px; padding: 12px; background: white; border-radius: 8px; border-left: 4px solid #f57c00;'>
<h4 style='margin-top: 0; color: #f57c00;'>2️⃣ 积分环节 1/<i>s</i></h4>
<p>• 幅频:-20dB/dec 斜率<br>• 相频:-90° - 水平线</p>
</div>
<div style='margin-bottom: 15px; padding: 12px; background: white; border-radius: 8px; border-left: 4px solid #4caf50;'>
<h4 style='margin-top: 0; color: #4caf50;'>3️⃣ 惯性环节 1/(<i>Ts</i>+1)</h4>
<p>• 转折频率:ω = 1/<i>T</i><br>• 幅频:低频 0dB,高频 -20dB/dec<br>• 相频:0° → -90°</p>
</div>
</div>
</details>
</div>
"""
# 根轨迹分析知识卡片
ROOT_LOCUS_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #667eea; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>📚</span> 根轨迹分析要点
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎯 根轨迹基本概念
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p><strong>定义:</strong>当开环增益 <i>K</i> 从 0 → ∞ 变化时,闭环特征方程根(极点)在 <i>s</i> 平面上的运动轨迹</p>
<h4 style='color: #667eea; margin-top: 15px;'>特征方程</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0; font-size: 1.3em;'>
1 + <i>KG</i>(<i>s</i>)<i>H</i>(<i>s</i>) = 0
</div>
<h4 style='color: #764ba2; margin-top: 15px;'>主要作用</h4>
<ul style='line-height: 1.8;'>
<li>✅ 直观显示增益对极点位置的影响</li>
<li>✅ 判断系统稳定性</li>
<li>✅ 选择合适的增益值</li>
<li>✅ 设计控制器参数</li>
</ul>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 根轨迹绘制基本条件
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #4caf50;'>
<h4 style='margin-top: 0; color: #388e3c;'>1️⃣ 幅值条件(充要条件)</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0; font-size: 1.2em;'>
|<i>KG</i>(<i>s</i><sub>0</sub>)<i>H</i>(<i>s</i><sub>0</sub>)| = 1
</div>
<p style='margin: 8px 0;'><strong>💡 用途:</strong>确定增益 <i>K</i> 的值</p>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #ff9800;'>
<h4 style='margin-top: 0; color: #f57c00;'>2️⃣ 相角条件(充要条件)</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 6px; margin: 8px 0; font-size: 1.2em;'>
∠<i>G</i>(<i>s</i><sub>0</sub>)<i>H</i>(<i>s</i><sub>0</sub>) = (2<i>k</i>+1) × 180°
</div>
<p style='margin: 8px 0; font-size: 0.95em;'>其中 <i>k</i> = 0, ±1, ±2, ...</p>
<p style='margin: 8px 0;'><strong>💡 用途:</strong>判断 <i>s</i> 平面某点是否在根轨迹上</p>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #fff0f8 0%, #fce4ec 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🌟 根轨迹基本性质
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<table style='width: 100%; border-collapse: collapse; margin: 15px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;'>
<th style='padding: 12px; text-align: left; font-weight: 700;'>规则</th>
<th style='padding: 12px; text-align: left; font-weight: 700;'>内容</th>
</tr>
<tr style='background: white;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>起点</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'><i>K</i>=0,位于<strong>开环极点</strong></td>
</tr>
<tr style='background: #f8f9ff;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>终点</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'><i>K</i>→∞,位于<strong>开环零点</strong>或无穷远</td>
</tr>
<tr style='background: white;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>分支数</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>max(<i>n</i>, <i>m</i>)<i>n</i>=极点数,<i>m</i>=零点数</td>
</tr>
<tr style='background: #f8f9ff;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>实轴段</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>右侧零极点总数为<strong>奇数</strong>的区段</td>
</tr>
<tr style='background: white;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>渐近线数</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'><strong><i>n</i> <i>m</i></strong> 条</td>
</tr>
<tr style='background: #f8f9ff;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>渐近线角度</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>φ<sub>a</sub> = (2<i>k</i>+1)×180°/(<i>n</i><i>m</i>)</td>
</tr>
<tr style='background: white;'>
<td style='padding: 10px; border: 1px solid #e0e7ff; font-weight: 600;'>渐近线交点</td>
<td style='padding: 10px; border: 1px solid #e0e7ff;'>σ<sub>a</sub> = (Σ<i>p</i> Σ<i>z</i>)/(<i>n</i><i>m</i>)</td>
</tr>
</table>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🛡️ <i>s</i> 平面稳定性区域
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<table style='width: 100%; border-collapse: collapse; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: #f5f5f5; font-weight: 600;'>
<th style='padding: 10px; border: 1px solid #ddd;'>区域</th>
<th style='padding: 10px; border: 1px solid #ddd;'>条件</th>
<th style='padding: 10px; border: 1px solid #ddd;'>稳定性</th>
</tr>
<tr>
<td style='padding: 10px; border: 1px solid #ddd;'>左半平面</td>
<td style='padding: 10px; border: 1px solid #ddd;'>Re(<i>s</i>) &lt; 0</td>
<td style='padding: 10px; border: 1px solid #ddd; background: #c8e6c9;'><strong>✅ 稳定</strong></td>
</tr>
<tr>
<td style='padding: 10px; border: 1px solid #ddd;'>虚轴</td>
<td style='padding: 10px; border: 1px solid #ddd;'>Re(<i>s</i>) = 0</td>
<td style='padding: 10px; border: 1px solid #ddd; background: #fff9c4;'><strong>⚠️ 临界稳定</strong></td>
</tr>
<tr>
<td style='padding: 10px; border: 1px solid #ddd;'>右半平面</td>
<td style='padding: 10px; border: 1px solid #ddd;'>Re(<i>s</i>) &gt; 0</td>
<td style='padding: 10px; border: 1px solid #ddd; background: #ffcdd2;'><strong>❌ 不稳定</strong></td>
</tr>
</table>
<div style='background: #e3f2fd; padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 虚轴(<i>x</i>=0</strong>即为<strong>稳定性边界</strong></p>
<p style='margin: 8px 0;'>根轨迹穿越虚轴点对应<strong>临界增益 <i>K</i><sub>c</sub></strong></p>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📏 阻尼比等值线
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e0e7ff;'>
<p>从原点出发的射线代表恒定阻尼比 ζ 的轨迹:</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0; font-size: 1.2em;'>
θ = arccos(ζ)
</div>
<table style='width: 100%; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-radius: 6px; overflow: hidden;'>
<tr style='background: #f5f5f5; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #ddd;'>阻尼比 ζ</td>
<td style='padding: 8px; border: 1px solid #ddd;'>角度 θ</td>
<td style='padding: 8px; border: 1px solid #ddd;'>系统特性</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #ddd;'>0.5</td>
<td style='padding: 8px; border: 1px solid #ddd;'>60°</td>
<td style='padding: 8px; border: 1px solid #ddd;'>欠阻尼,较大超调</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #ddd;'><strong>0.707</strong></td>
<td style='padding: 8px; border: 1px solid #ddd;'><strong>45°</strong></td>
<td style='padding: 8px; border: 1px solid #ddd;'><strong>⭐ 最佳阻尼</strong></td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 工程应用:</strong>通过根轨迹与阻尼比等值线的交点,选择满足性能要求的增益 <i>K</i></p>
</div>
</div>
</details>
</div>
"""
# ============================================================
# 发动机控制器设计知识卡片 (PID + MPC) — 中文
# ============================================================
ENGINE_CONTROL_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #e65100; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>🔧</span> 发动机控制器设计理论
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎛️ PID 控制器 — 增量式形式
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #ffe0b2;'>
<p style='margin: 10px 0;'><strong>标准PID传递函数:</strong></p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.2em;'>
<i>u</i>(<i>t</i>) = <i>K</i><sub>p</sub> <i>e</i>(<i>t</i>)
+ <i>K</i><sub>i</sub> ∫<i>e</i>(τ)dτ
+ <i>K</i><sub>d</sub>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>d<i>e</i>(<i>t</i>)</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>d<i>t</i></span>
</span>
</div>
</div>
<p style='margin: 10px 0;'><strong>增量式(速度型)PID</strong></p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.1em;'>
Δ<i>u</i>(<i>k</i>) = <i>K</i><sub>p</sub>[<i>e</i>(<i>k</i>) <i>e</i>(<i>k</i>1)]
+ <i>K</i><sub>i</sub> <i>e</i>(<i>k</i>)
+ <i>K</i><sub>d</sub>[<i>e</i>(<i>k</i>) 2<i>e</i>(<i>k</i>1) + <i>e</i>(<i>k</i>2)]
</div>
</div>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 增量式优势:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>输出为控制量的增量 Δu,而非绝对值,避免积分饱和(Windup</li>
<li>手动/自动切换时输出无跳变,适合工程实际</li>
<li>计算量恒定,不随运行时间增加</li>
<li>即使计算失误,影响仅限于当前步的增量</li>
</ul>
</div>
<h4 style='color: #e65100; margin-top: 18px;'>📊 各参数作用与调节规律</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #e65100 0%, #bf360c 100%); color: white;'>
<th style='padding: 10px; text-align: left;'>参数</th>
<th style='padding: 10px; text-align: left;'>增大效果</th>
<th style='padding: 10px; text-align: left;'>过大时</th>
<th style='padding: 10px; text-align: left;'>调节建议</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>K<sub>p</sub></strong> (比例)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>加快响应速度,减小稳态误差</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>产生振荡甚至不稳定</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>先调大至出现振荡,再回退70%</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>K<sub>i</sub></strong> (积分)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>彻底消除稳态误差</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>超调加重,积分饱和</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>从小值开始缓慢增大</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>K<sub>d</sub></strong> (微分)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>抑制超调和振荡,改善动态品质</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>放大噪声,响应迟钝</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>通常取较小值,有噪声时可设为0</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>🎯 经典调参步骤(Ziegler-Nichols 启发式):</strong></p>
<ol style='line-height: 2; margin-left: 15px;'>
<li>设 K<sub>i</sub>=0, K<sub>d</sub>=0,逐渐增大 K<sub>p</sub> 直到系统出现等幅振荡</li>
<li>记录此时的临界增益 K<sub>u</sub> 和振荡周期 T<sub>u</sub></li>
<li>按经验公式设定:K<sub>p</sub>=0.6K<sub>u</sub>, K<sub>i</sub>=2K<sub>p</sub>/T<sub>u</sub>, K<sub>d</sub>=K<sub>p</sub>T<sub>u</sub>/8</li>
<li>根据实际响应微调各参数</li>
</ol>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🧠 MPC — 模型预测控制
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #bbdefb;'>
<p style='margin: 10px 0;'>MPCModel Predictive Control)利用系统的<strong>内部动态模型</strong>预测未来行为,
在<strong>滚动时域</strong>上优化控制序列,仅执行第一步,然后重新优化——这就是"滚动优化"原理。</p>
<h4 style='color: #1565c0; margin-top: 12px;'>🔑 优化目标函数</h4>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.1em;'>
min<sub><i>U</i></sub> &nbsp; <i>J</i> = Σ<sub>k=1</sub><sup>H</sup>
[ <i>W</i><sub>p</sub> (<i>P</i><sub>k</sub> <i>P</i><sub>ref</sub>)²
+ <i>W</i><sub>Δu</sub> (Δ<i>u</i><sub>k</sub>)² ]
</div>
</div>
<p style='margin: 8px 0; color: #555; font-size: 0.93em;'>
其中 H 为预测时域长度,W<sub>p</sub> 为功率跟踪权重,W<sub>Δu</sub> 为控制增量惩罚权重。
</p>
<h4 style='color: #1565c0; margin-top: 18px;'>🔑 MPC 核心概念</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%); color: white;'>
<th style='padding: 10px; text-align: left;'>概念</th>
<th style='padding: 10px; text-align: left;'>说明</th>
<th style='padding: 10px; text-align: left;'>调节效果</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>预测时域 (H)</strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>优化器向前看的步数</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>H越大前瞻性越强,但计算量增加</td>
</tr>
<tr style='background: #f0f7ff;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>W<sub>power</sub></strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>功率跟踪权重</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>越大跟踪越紧密,但控制信号波动可能增大</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>W<sub>Δcost</sub></strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>控制平滑度权重</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>越大控制越平滑,减少执行器磨损</td>
</tr>
<tr style='background: #f0f7ff;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>超调限制</strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>输出偏差的硬约束(如 ≤5%</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>越小越安全但可能减缓响应速度</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #ede7f6 0%, #d1c4e9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>🔬 内部线性化模型:</strong>本仿真中,涡轴发动机被线性化为以下离散状态方程:</p>
<div style='text-align: center; background: white; padding: 12px; border-radius: 6px; margin: 8px 0;'>
<i>N</i><sub>k+1</sub> = <i>N</i><sub>k</sub> + Δt · <i>K</i><sub>inertia</sub> · (<i>W</i><sub>f,act</sub> <i>W</i><sub>f,req</sub>)<br>
<i>W</i><sub>f,act,k+1</sub> = (1 Δt/τ) · <i>W</i><sub>f,act,k</sub> + (Δt/τ) · <i>u</i><sub>k</sub>
</div>
<p style='margin: 8px 0; font-size: 0.93em; color: #555;'>
τ 为燃油执行机构时间常数,K<sub>inertia</sub> 为转子惯性增益。W<sub>f,req</sub> 和功率 P 由 NN 代理模型实时提供。
</p>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>⚖️ PID vs MPC 对比:</strong></p>
<table style='width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.91em;'>
<tr style='background: #f5f5f5; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>特性</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>PID</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>MPC</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>原理</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>基于误差的反馈校正(事后调节)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>基于模型的前馈预测(提前规划)</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>约束处理</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>需额外加限幅/抗饱和机制</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>在优化中自然处理约束</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>计算量</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>极低,微秒级</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>较高,需在线优化</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>模型依赖</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>无需模型</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>需要准确的系统模型</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>适用场景</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>稳定对象,简单跟踪</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>多变量、有约束的复杂系统</td>
</tr>
</table>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fff0f8 0%, #fce4ec 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
✈️ 涡轴发动机模型
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #fce4ec;'>
<p>涡轴发动机由三个耦合子系统建模:</p>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #ad1457 0%, #880e4f 100%); color: white;'>
<th style='padding: 10px;'>子系统</th>
<th style='padding: 10px;'>动态特性</th>
<th style='padding: 10px;'>关键参数</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #fce4ec;'><strong>NN 代理模型</strong></td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>映射 (高度, 马赫数, 转速) → (燃油流量, 功率);基于 GPR/数据训练</td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>输入3维, 输出2维</td>
</tr>
<tr style='background: #fff5f8;'>
<td style='padding: 8px; border: 1px solid #fce4ec;'><strong>燃油执行机构</strong></td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>一阶惯性环节: dW<sub>f</sub>/dt = (u W<sub>f</sub>) / τ<sub>fuel</sub></td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>τ 越大响应越慢</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #fce4ec;'><strong>转子动力学</strong></td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>dN/dt = K<sub>inertia</sub> · (W<sub>f,actual</sub> W<sub>f,required</sub>)</td>
<td style='padding: 8px; border: 1px solid #fce4ec;'>K 越大加速越快</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 仿真流程:</strong></p>
<ol style='line-height: 2; margin-left: 15px;'>
<li>给定当前转速 NNN模型预测所需燃油流量 W<sub>f,req</sub> 和当前功率 P</li>
<li>控制器(PID或MPC)根据功率误差计算燃油命令 W<sub>f,cmd</sub></li>
<li>执行机构将命令滤波为实际燃油流量 W<sub>f,act</sub></li>
<li>W<sub>f,act</sub> W<sub>f,req</sub> 产生净力矩驱动转子加速或减速</li>
<li>转速变化又改变NN模型的输入,形成闭环</li>
</ol>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>📏 性能评价指标:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>稳态误差:</strong>功率达到稳态后与目标的平均偏差</li>
<li><strong>超调量 (σ%)</strong>输出超过目标值的最大百分比</li>
<li><strong>上升时间 (t<sub>r</sub>)</strong>功率从10%变化到90%所需时间</li>
<li><strong>调节时间 (t<sub>s</sub>)</strong>功率进入并持续保持在 ±2% 误差带内的时间</li>
</ul>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e0f7fa 0%, #b2ebf2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 PID 控制器 — Laplace 域传递函数
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #b2ebf2;'>
<p><strong>连续域 PID 传递函数:</strong></p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
<i>C</i>(<i>s</i>) = <i>K</i><sub>p</sub>
<span style='font-size: 1.2em;'>(</span>
1 +
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>1</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>T<sub>i</sub> s</span>
</span>
+ T<sub>d</sub> s
<span style='font-size: 1.2em;'>)</span>
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>其中 T<sub>i</sub> = K<sub>p</sub>/K<sub>i</sub> 为积分时间常数,
T<sub>d</sub> = K<sub>d</sub>/K<sub>p</sub> 为微分时间常数。</p>
<h4 style='color: #00838f; margin-top: 15px;'>Ziegler-Nichols 整定公式表</h4>
<p>基于极限灵敏度(临界增益)法——设 K<sub>u</sub> 为临界增益,T<sub>u</sub> 为临界周期:</p>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #00838f 0%, #006064 100%); color: white;'>
<th style='padding: 10px;'>控制器类型</th>
<th style='padding: 10px;'>K<sub>p</sub></th>
<th style='padding: 10px;'>T<sub>i</sub></th>
<th style='padding: 10px;'>T<sub>d</sub></th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #b2ebf2;'><strong>P</strong></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>0.5 K<sub>u</sub></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>—</td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>—</td>
</tr>
<tr style='background: #f0fafa;'>
<td style='padding: 8px; border: 1px solid #b2ebf2;'><strong>PI</strong></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>0.45 K<sub>u</sub></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>T<sub>u</sub> / 1.2</td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>—</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #b2ebf2;'><strong>PID</strong></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>0.6 K<sub>u</sub></td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>T<sub>u</sub> / 2</td>
<td style='padding: 8px; border: 1px solid #b2ebf2;'>T<sub>u</sub> / 8</td>
</tr>
</table>
<p style='color: #555; font-size: 0.93em;'>
等价转换:K<sub>i</sub> = K<sub>p</sub>/T<sub>i</sub>K<sub>d</sub> = K<sub>p</sub>·T<sub>d</sub>。
Z-N 公式通常产生约 25% 超调,实际应用中需进一步微调。
</p>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #f1f8e9 0%, #dcedc8 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🧮 MPC 矩阵化优化问题
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #dcedc8;'>
<p>MPC 将有限时域优化问题转化为<strong>二次规划 (QP)</strong> 或非线性规划问题:</p>
<h4 style='color: #558b2f;'>离散状态空间模型</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
<b>x</b><sub>k+1</sub> = A<b>x</b><sub>k</sub> + B<b>u</b><sub>k</sub><br>
<b>y</b><sub>k</sub> = C<b>x</b><sub>k</sub>
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>
本系统中:<b>x</b> = [N, W<sub>f,act</sub>]<sup>T</sup>(转速和实际燃油流量),
<b>u</b> = W<sub>f,cmd</sub>(燃油命令),<b>y</b> = P(功率输出)。
</p>
<h4 style='color: #558b2f;'>预测矩阵展开</h4>
<p>利用递推关系,将 H 步预测写成矩阵形式:</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.05em;'>
<b>Y</b> = Ψ<b>x</b><sub>0</sub> + Θ<b>U</b>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px; font-size: 0.95em;'>
<li><b>Y</b> = [y<sub>1</sub>, ..., y<sub>H</sub>]<sup>T</sup>:预测输出序列</li>
<li><b>U</b> = [u<sub>0</sub>, ..., u<sub>H1</sub>]<sup>T</sup>:控制输入序列</li>
<li>Ψ = [CA, CA², ..., CA<sup>H</sup>]<sup>T</sup>:自由响应矩阵</li>
<li>Θ:Toeplitz 控制响应矩阵</li>
</ul>
<h4 style='color: #558b2f;'>带约束 QP 问题</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.05em;'>
min<sub><b>U</b></sub> (<b>Y</b> <b>R</b>)<sup>T</sup> Q (<b>Y</b> <b>R</b>) + Δ<b>U</b><sup>T</sup> R<sub>Δ</sub> Δ<b>U</b><br><br>
s.t. &nbsp; u<sub>min</sub> ≤ u<sub>k</sub> ≤ u<sub>max</sub>, &nbsp;
|y<sub>k</sub> r<sub>k</sub>| ≤ ε<sub>overshoot</sub>
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>
Q 和 R<sub>Δ</sub> 分别对应界面中的 W<sub>power</sub> 和 W<sub>Δcost</sub> 权重滑块。
本系统使用 SciPy SLSQP 求解器进行约束非线性优化。
</p>
</div>
</details>
</div>
"""
MOTOR_CONTROL_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #1565c0; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>⚡</span> 电机控制器设计理论
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
⚙️ PMSM 永磁同步电机模型
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #bbdefb;'>
<p><strong>永磁同步电机 (PMSM)</strong> 是电动推进系统的核心驱动组件,具有功率密度高、效率高、控制精度好等优点。</p>
<h4 style='color: #1565c0;'>机械动力学方程</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.15em;'>
<i>J</i>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>dω</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>dt</span>
</span>
= (<i>T</i><sub>motor</sub> + <i>T</i><sub>load</sub> + <i>T</i><sub>ext</sub> + <i>B</i>ω)
</div>
</div>
<p style='margin: 8px 0; color: #555; font-size: 0.93em;'>
其中 T<sub>motor</sub> 为电磁转矩(电机产生),T<sub>load</sub> 为负载转矩,
T<sub>ext</sub> 为外部扰动,Bω 为粘性摩擦力矩。
</p>
<h4 style='color: #1565c0;'>电磁转矩表达式</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.15em;'>
<i>T</i><sub>e</sub> = 1.5 · <i>n</i><sub>p</sub> · ψ<sub>f</sub> · <i>i</i><sub>q</sub>
</div>
</div>
<p style='margin: 8px 0; color: #555; font-size: 0.93em;'>
对表贴式PMSM (L<sub>d</sub> = L<sub>q</sub>),转矩仅与q轴电流 i<sub>q</sub> 成正比。
</p>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%); color: white;'>
<th style='padding: 10px;'>符号</th>
<th style='padding: 10px;'>含义</th>
<th style='padding: 10px;'>典型值</th>
<th style='padding: 10px;'>对系统的影响</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>J</strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>转动惯量 (kg·m²)</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>0.5 5.0</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>越大响应越慢但越平稳</td>
</tr>
<tr style='background: #f0f7ff;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>B</strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>粘性摩擦系数 (N·m·s)</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>3×10⁻⁴</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>提供自然阻尼</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>n<sub>p</sub></strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>极对数</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>3</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>影响电气频率和转矩常数</td>
</tr>
<tr style='background: #f0f7ff;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>ψ<sub>f</sub></strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>永磁体磁链 (Wb)</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>0.15</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>决定转矩能力和反电动势</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #bbdefb;'><strong>P<sub>rate</sub></strong></td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>额定功率 (kW)</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>300</td>
<td style='padding: 8px; border: 1px solid #bbdefb;'>确定最大可用转矩</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 电压约束与弱磁:</strong>
当转速升高时,反电动势 e = n<sub>p</sub>·ψ<sub>f</sub>·ω 增大。
当反电动势接近母线电压 V<sub>dc</sub> 时,电机进入弱磁区,
需注入负的 i<sub>d</sub> 电流来削弱磁链,此时可用转矩下降。
</p>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🎯 转速控制环路
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #c8e6c9;'>
<p>典型电机控制采用<strong>双环级联</strong>结构:外环为转速环,内环为电流环。</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<span style='font-size: 1em; color: #555;'>
ω<sub>ref</sub> → [转速控制器] → <i>T</i><sub>cmd</sub> → [电流环 + SVPWM] → PMSM → ω<sub>actual</sub>
</span>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>PID 模式:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>根据转速误差 e = ω<sub>ref</sub> ω 计算转矩命令 T = K<sub>p</sub>·e + K<sub>i</sub>·∫e + K<sub>d</sub>·ė</li>
<li>转矩命令转换为功率请求 P = T·ω 送入逆变器</li>
<li>简单可靠,但无法提前预知负载变化</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>MPC 模式:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>利用电机离散动力学模型预测 H 步后的转速轨迹</li>
<li>优化 H 步的转矩序列,使转速跟踪误差和控制增量同时最小化</li>
<li>支持超调硬约束:转速偏差不得超过设定百分比</li>
</ul>
<div style='text-align: center; background: white; padding: 10px; border-radius: 6px; margin: 8px 0;'>
min<sub>T<sub>0..H</sub></sub> Σ [ W<sub>ω</sub>(ω<sub>k</sub> ω<sub>ref</sub>)² + W<sub>Δ</sub>(T<sub>k</sub> T<sub>k1</sub>)² ]
</div>
<p style='margin: 8px 0; font-size: 0.93em; color: #555;'>
离散状态方程:ω<sub>k+1</sub> = (1dt·B/J)·ω<sub>k</sub> (dt/J)·T<sub>cmd</sub> (dt/J)·(T<sub>ext</sub>+T<sub>load</sub>)
</p>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔍 负载扰动测试设计
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #f8bbd0;'>
<p style='margin: 10px 0;'>本仿真在运行至 <strong>60% 时刻</strong>时自动施加 <strong>50% 负载阶跃扰动</strong>
用于检验控制器的抗扰性能。</p>
<h4 style='color: #c62828; margin-top: 12px;'>📊 抗扰性能指标</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); color: white;'>
<th style='padding: 10px;'>指标</th>
<th style='padding: 10px;'>定义</th>
<th style='padding: 10px;'>理想范围</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffcdd2;'><strong>转速跌落 (Speed Dip)</strong></td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>扰动后转速最大瞬时下降量</td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>< 5% 额定转速</td>
</tr>
<tr style='background: #fff5f5;'>
<td style='padding: 8px; border: 1px solid #ffcdd2;'><strong>恢复时间</strong></td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>转速回到 ±2% 设定值的时间</td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>< 3 秒</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffcdd2;'><strong>稳态误差</strong></td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>扰动后新稳态与目标的偏差</td>
<td style='padding: 8px; border: 1px solid #ffcdd2;'>< 1% 或指定精度</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>⚙️ 转动惯量 J 的影响:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>J 较大:</strong>响应较慢但转速跌落小,系统惯性大不易被扰动"推走"</li>
<li><strong>J 较小:</strong>响应快但对扰动更敏感,转速波动大</li>
<li>实际工程中,可通过飞轮或增大转子质量来调整等效惯量</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 MPC 调参建议:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>如果扰动后转速恢复慢→增大 W<sub>speed</sub> 或减小 W<sub>Δcost</sub></li>
<li>如果转速振荡→增大 W<sub>Δcost</sub> 或减小 W<sub>speed</sub></li>
<li>如果超调过大→降低超调限制百分比</li>
<li>负载很大时,确认电机额定功率是否足以提供所需转矩</li>
</ul>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 PMSM dq 坐标系电压方程
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e1bee7;'>
<p>通过 Park 变换将三相 ABC 坐标系转换为旋转 dq 坐标系,PMSM 的电压方程简化为:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em; line-height: 2.0;'>
u<sub>d</sub> = R<sub>s</sub> i<sub>d</sub> + L<sub>d</sub>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>di<sub>d</sub></span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>dt</span>
</span>
ω<sub>e</sub> L<sub>q</sub> i<sub>q</sub><br>
u<sub>q</sub> = R<sub>s</sub> i<sub>q</sub> + L<sub>q</sub>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>di<sub>q</sub></span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>dt</span>
</span>
+ ω<sub>e</sub> (L<sub>d</sub> i<sub>d</sub> + ψ<sub>f</sub>)
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>ω<sub>e</sub></strong> = n<sub>p</sub> · ω<sub>m</sub>:电气角速度</li>
<li><strong>−ω<sub>e</sub>L<sub>q</sub>i<sub>q</sub></strong>d 轴耦合项(q 轴电流产生的交叉耦合)</li>
<li><strong>+ω<sub>e</sub>ψ<sub>f</sub></strong>:永磁体反电动势(ωψ<sub>f</sub> = E<sub>back-EMF</sub></li>
<li>表贴式 PMSM 中 L<sub>d</sub> = L<sub>q</sub>,无磁阻转矩分量</li>
</ul>
<h4 style='color: #7b1fa2; margin-top: 15px;'>磁场定向控制 (FOC) 原理</h4>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>FOC 核心思想:</strong>通过控制 i<sub>d</sub> = 0(表贴式),使电磁转矩与 i<sub>q</sub> 线性正比:</p>
<div style='text-align: center; background: white; padding: 12px; border-radius: 6px; margin: 8px 0;'>
T<sub>e</sub> = 1.5 · n<sub>p</sub> · ψ<sub>f</sub> · i<sub>q</sub>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>外环(转速环)→ 给出转矩参考 → 换算为 i<sub>q</sub> 参考</li>
<li>内环(电流环)→ PI 控制 i<sub>d</sub>=0, i<sub>q</sub>=目标值</li>
<li>逆 Park 变换 → SVPWM 产生三相驱动电压</li>
</ul>
</div>
<h4 style='color: #7b1fa2; margin-top: 15px;'>坐标变换</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em;'>
<tr style='background: #f3e5f5; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'>变换</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>作用</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>公式要点</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #e1bee7;'><strong>Clarke (ABC→αβ)</strong></td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>三相→两相静止坐标</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>i<sub>α</sub> = i<sub>a</sub>i<sub>β</sub> = (i<sub>a</sub> + 2i<sub>b</sub>)/√3</td>
</tr>
<tr style='background: #faf5ff;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'><strong>Park (αβ→dq)</strong></td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>静止→旋转坐标</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>i<sub>d</sub> = i<sub>α</sub>cosθ + i<sub>β</sub>sinθ</td>
</tr>
</table>
</div>
</details>
</div>
"""
GPR_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #4a148c; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>📈</span> GPR 高斯过程回归 — 理论与公式详解
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📖 什么是高斯过程回归 (Gaussian Process Regression)?
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e1bee7;'>
<p style='margin: 10px 0;'><strong>高斯过程 (Gaussian Process, GP)</strong> 是一种定义在函数空间上的随机过程。
直觉上,GP 将"先验分布"从有限维的参数空间推广到无穷维的函数空间——它不是对参数建模,
而是直接对函数本身施加概率分布。</p>
<div style='background: linear-gradient(135deg, #ede7f6 0%, #d1c4e9 100%); padding: 15px; border-radius: 8px; margin: 12px 0; border-left: 4px solid #7c4dff;'>
<p style='margin: 0; font-weight: 700; color: #4a148c;'>📌 核心定义</p>
<p style='margin: 8px 0;'>一个高斯过程是指:对于任意有限输入点集合 {<b>x</b><sub>1</sub>, ..., <b>x</b><sub>n</sub>}
其对应的函数值 [f(<b>x</b><sub>1</sub>), ..., f(<b>x</b><sub>n</sub>)] 服从联合多元高斯分布。</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
<i>f</i>(<b>x</b>) ~ GP( <i>m</i>(<b>x</b>),&nbsp; <i>k</i>(<b>x</b>, <b>x</b>') )
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>均值函数</strong> <i>m</i>(<b>x</b>) = E[<i>f</i>(<b>x</b>)]:描述函数的先验趋势</li>
<li><strong>协方差函数(核函数)</strong> <i>k</i>(<b>x</b>, <b>x</b>') = Cov[<i>f</i>(<b>x</b>), <i>f</i>(<b>x</b>')]
刻画不同输入点处函数值之间的相关性</li>
</ul>
</div>
<p><strong>与参数化回归的本质区别:</strong></p>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #6a1b9a 0%, #4a148c 100%); color: white;'>
<th style='padding: 10px;'>方面</th>
<th style='padding: 10px;'>参数化方法(如线性回归)</th>
<th style='padding: 10px;'>GPR(非参数贝叶斯)</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'>模型形式</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>f(x) = w<sup>T</sup>φ(x),参数 w 有限</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>直接在函数空间上建模</td>
</tr>
<tr style='background: #faf5ff;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'>复杂度</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>由模型结构(特征维度)固定</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>随数据量自适应增长</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'>不确定性</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>通常只提供点估计</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>天然提供预测方差(置信区间)</td>
</tr>
<tr style='background: #faf5ff;'>
<td style='padding: 8px; border: 1px solid #e1bee7;'>小样本</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>容易过拟合或欠拟合</td>
<td style='padding: 8px; border: 1px solid #e1bee7;'>先验正则化,小样本表现好</td>
</tr>
</table>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔬 核函数 (Kernel / Covariance Function) 详解
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #c5cae9;'>
<p>核函数是 GPR 的"灵魂"——它完全决定了 GP 的先验性质(平滑度、周期性、长程相关性等)。
核函数 <i>k</i>(<b>x</b>, <b>x</b>') 衡量两个输入点对应函数值的相关程度。</p>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #1565c0;'>
<strong style='color: #1565c0; font-size: 1.05em;'>1️⃣ RBF 核 (径向基函数核 / 平方指数核)</strong>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
<i>k</i><sub>RBF</sub>(<b>x</b>, <b>x</b>') = σ<sub>f</sub><sup>2</sup> · exp
<span style='font-size: 1.2em;'>(</span>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>‖<b>x</b> <b>x</b>'‖²</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>2ℓ²</span>
</span>
<span style='font-size: 1.2em;'>)</span>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>σ<sub>f</sub><sup>2</sup></strong> (输出尺度):控制函数值的整体变化幅度</li>
<li><strong></strong> (长度尺度):控制平滑度——ℓ 越大,函数变化越缓慢;ℓ 越小,函数变化越剧烈</li>
<li>RBF 核假设函数<b>无限可微</b>,适合建模光滑连续的物理过程</li>
<li>当 ‖<b>x</b> <b>x</b>'‖ ≫ 时,<i>k</i> → 0(远距离点不相关)</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #fff4f0 0%, #ffe0b2 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #ff9800;'>
<strong style='color: #e65100; font-size: 1.05em;'>2️⃣ Matérn 核(本项目使用 Matérn-5/2</strong>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
<i>k</i><sub>5/2</sub>(<i>r</i>) = σ<sub>f</sub><sup>2</sup>
<span style='font-size: 1.1em;'>(</span>1 + √5 ·
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'><i>r</i></span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'></span>
</span>
+ <span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>5<i>r</i>²</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>3ℓ²</span>
</span>
<span style='font-size: 1.1em;'>)</span>
exp<span style='font-size: 1.1em;'>(</span>−√5 ·
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'><i>r</i></span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'></span>
</span>
<span style='font-size: 1.1em;'>)</span>
</div>
</div>
<p style='margin: 8px 0; color: #555;'>其中 <i>r</i> = ‖<b>x</b> <b>x</b>'‖ 为欧氏距离</p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>Matérn 核是 RBF 的推广,通过参数 ν 控制可微性:ν=1/2 → 不可微; ν=∞ → RBF</li>
<li><strong>ν=5/2</strong>:函数<b>两次可微</b>,比 RBF 更灵活,是工程建模的常用选择</li>
<li>相比 RBF 能更好地捕捉工程数据中的局部不规则性</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #f0fff4 0%, #c8e6c9 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #4caf50;'>
<strong style='color: #2e7d32; font-size: 1.05em;'>3️⃣ ARD (自动相关性判定) 机制</strong>
<p style='margin: 8px 0;'>对于多维输入 <b>x</b> = [x<sub>1</sub>, ..., x<sub>d</sub>]ARD 核为每个输入维度分配独立的长度尺度:</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
<i>r</i><sub>ARD</sub><sup>2</sup> = Σ<sub>j=1</sub><sup>d</sup>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>(x<sub>j</sub> x'<sub>j</sub>)²</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'><sub>j</sub>²</span>
</span>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>若 <sub>j</sub> 很大 → 函数对第 j 维输入不敏感(自动"忽略"该维度)</li>
<li>若 <sub>j</sub> 很小 → 函数在第 j 维变化剧烈(高度相关)</li>
<li>ARD 通过数据自动学习每维的重要性,实现<b>隐式特征选择</b></li>
<li>本项目:3 个输入 [高度, 马赫数, RPM] → 3 个独立的 <sub>j</sub></li>
</ul>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 GPR 后验推断公式(预测均值与方差)
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #b2dfdb;'>
<p><strong>训练数据:</strong>给定 N 个观测 D = {(<b>x</b><sub>i</sub>, y<sub>i</sub>)}<sub>i=1</sub><sup>N</sup>
假设 y = f(<b>x</b>) + ε,其中 ε ~ N(0, σ<sub>n</sub>²) 为观测噪声。</p>
<p><strong>联合先验分布:</strong></p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
<span style='font-size: 1.3em;'>[</span>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; padding: 2px;'><b>y</b></span>
<span style='display: block; padding: 2px;'><b>f</b><sub>*</sub></span>
</span>
<span style='font-size: 1.3em;'>]</span>
~ N
<span style='font-size: 1.3em;'>(</span>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; padding: 2px;'><b>m</b></span>
<span style='display: block; padding: 2px;'><b>m</b><sub>*</sub></span>
</span>
,
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; padding: 2px;'>[K + σ<sub>n</sub>²I &nbsp; K<sub>*</sub>]</span>
<span style='display: block; padding: 2px;'>[K<sub>*</sub><sup>T</sup> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K<sub>**</sub>]</span>
</span>
<span style='font-size: 1.3em;'>)</span>
</div>
</div>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 15px; border-radius: 8px; margin: 12px 0; border-left: 4px solid #4caf50;'>
<p style='font-weight: 700; color: #2e7d32;'>🎯 后验预测分布(关键公式)</p>
<p>对新输入 <b>x</b><sub>*</sub>,后验 f<sub>*</sub> | D, <b>x</b><sub>*</sub> 仍为高斯分布:</p>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em; margin: 8px 0;'>
<strong>预测均值:</strong>&nbsp;
μ<sub>*</sub> = m(<b>x</b><sub>*</sub>) + <b>k</b><sub>*</sub><sup>T</sup> (K + σ<sub>n</sub>²I)<sup>1</sup> (<b>y</b> <b>m</b>)
</div>
<div style='font-size: 1.1em; margin: 8px 0;'>
<strong>预测方差:</strong>&nbsp;
σ<sub>*</sub>² = k<sub>**</sub> <b>k</b><sub>*</sub><sup>T</sup> (K + σ<sub>n</sub>²I)<sup>1</sup> <b>k</b><sub>*</sub>
</div>
</div>
<p style='margin: 8px 0; color: #333; font-size: 0.95em;'>其中:</p>
<ul style='line-height: 1.8; margin-left: 15px; font-size: 0.95em;'>
<li><strong>K</strong> ∈ <sup>N×N</sup>:训练数据之间的核矩阵,K<sub>ij</sub> = k(<b>x</b><sub>i</sub>, <b>x</b><sub>j</sub>)</li>
<li><strong>k<sub>*</sub></strong> ∈ <sup>N</sup>:测试点与所有训练点之间的核向量</li>
<li><strong>k<sub>**</sub></strong>:测试点自身的先验方差 k(<b>x</b><sub>*</sub>, <b>x</b><sub>*</sub>)</li>
<li><strong>(K + σ<sub>n</sub>²I)<sup>1</sup></strong>:核心计算瓶颈,复杂度 O(N³)</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>📊 方差的物理含义:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>σ<sub>*</sub>² <strong>小</strong>(接近训练数据区域)→ 预测可信度高,GPR "有信心"</li>
<li>σ<sub>*</sub>² <strong>大</strong>(远离训练数据区域)→ 预测不确定性高,是外推区域</li>
<li>方差热力图可以直观展示模型"知道什么"和"不知道什么"</li>
<li>这是 GPR 优于 NN 的核心优势——自动量化认知不确定性</li>
</ul>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
⚙️ 超参数优化 — 最大化边际似然
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #f8bbd0;'>
<p>GPR 的超参数 θ = {σ<sub>f</sub>, <sub>1</sub>, ..., <sub>d</sub>, σ<sub>n</sub>} 通过
<strong>最大化对数边际似然 (Log Marginal Likelihood)</strong> 自动确定:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.1em;'>
log <i>p</i>(<b>y</b>|X, θ) =
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>1</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>2</span>
</span>
<b>y</b><sup>T</sup>K<sub>y</sub><sup>1</sup><b>y</b>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>1</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>2</span>
</span>
log|K<sub>y</sub>|
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>N</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>2</span>
</span>
log(2π)
</div>
</div>
<p style='margin: 8px 0; color: #555;'>其中 K<sub>y</sub> = K + σ<sub>n</sub>²I</p>
<div style='background: linear-gradient(135deg, #ede7f6 0%, #d1c4e9 100%); padding: 12px; border-radius: 8px; margin: 12px 0;'>
<p><strong>📐 三项分解的物理意义:</strong></p>
<table style='width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.93em;'>
<tr style='background: #f5f5f5; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>项</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>数学形式</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>含义</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>数据拟合项</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>−½ <b>y</b><sup>T</sup>K<sub>y</sub><sup>1</sup><b>y</b></td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>模型对数据的拟合程度(越大越好拟合)</td>
</tr>
<tr style='background: #faf5ff;'>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>复杂度惩罚项</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>−½ log|K<sub>y</sub>|</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>Occam 剃刀:自动惩罚过于复杂的模型</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>归一化常数</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>(N/2) log(2π)</td>
<td style='padding: 8px; border: 1px solid #d1c4e9;'>与超参数无关,优化时可忽略</td>
</tr>
</table>
<p style='margin: 8px 0; color: #555; font-size: 0.93em;'>
优化过程在"拟合数据"和"模型简单性"之间自动取得平衡,天然防止过拟合。
本项目使用 BoTorch/GPyTorch 框架,通过 L-BFGS 优化器求解。
</p>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔄 数据预处理流水线
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #bbdefb;'>
<p>发动机数据(燃油流量、功率)的数值范围跨越多个数量级,直接建模会导致核函数
无法有效捕捉小值区域的变化。采用两步预处理:</p>
<div style='background: white; padding: 18px; border-radius: 8px; margin: 12px 0; border: 1px dashed #90caf9;'>
<ol style='line-height: 2.5; margin-left: 15px;'>
<li>
<strong>Log1p 变换:</strong> y<sub>log</sub> = log(1 + y)<br>
<span style='color: #555; font-size: 0.93em;'>→ 压缩大值,拉伸小值,使数据分布更均匀。log1p(0)=0,避免 log(0) 的数值问题。</span>
</li>
<li>
<strong>Z-Score 标准化:</strong> ŷ = (y<sub>log</sub> μ) / σ<br>
<span style='color: #555; font-size: 0.93em;'>→ 标准化为均值 0、标准差 1,使核函数的超参数在同一尺度上可比。</span>
</li>
<li>
<strong>反变换(预测时):</strong><br>
y<sub>log</sub> = ŷ · σ + μ &nbsp;&nbsp;→&nbsp;&nbsp; y = expm1(y<sub>log</sub>) = e<sup>y<sub>log</sub></sup> 1<br>
<span style='color: #555; font-size: 0.93em;'>→ 从标准化空间恢复到物理空间</span>
</li>
</ol>
</div>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 相同的预处理同时应用于 GPR 和 NN</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>GPR 在 Z-Score 空间中训练和预测</li>
<li>NN(蒸馏学生模型)使用 GPR 相同的 scaler 参数</li>
<li>这确保了两个模型的输入输出在相同数值空间中进行比较</li>
</ul>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📊 模型评价指标与计算复杂度
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #ffe0b2;'>
<h4 style='color: #e65100;'>评价指标公式</h4>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0;'>
<p><strong>MAPE (Mean Absolute Percentage Error)</strong></p>
<div style='text-align: center; padding: 8px; font-size: 1.1em;'>
MAPE =
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>1</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>N</span>
</span>
Σ<sub>i=1</sub><sup>N</sup>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>|y<sub>i</sub> ŷ<sub>i</sub>|</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>y<sub>i</sub></span>
</span>
× 100%
</div>
<p style='color: #555; font-size: 0.93em;'>注意:MAPE 计算排除 y ≈ 0 的数据点(避免除零导致的虚高误差)</p>
</div>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0;'>
<p><strong>R² (决定系数)</strong></p>
<div style='text-align: center; padding: 8px; font-size: 1.1em;'>
R² = 1
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>Σ(y<sub>i</sub> ŷ<sub>i</sub>)²</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>Σ(y<sub>i</sub> ȳ)²</span>
</span>
</div>
<p style='color: #555; font-size: 0.93em;'>R² = 1 → 完美预测; R² = 0 → 与均值预测一样差; R² &lt; 0 → 更差</p>
</div>
<h4 style='color: #e65100; margin-top: 15px;'>计算复杂度分析</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #e65100 0%, #bf360c 100%); color: white;'>
<th style='padding: 10px;'>操作</th>
<th style='padding: 10px;'>时间复杂度</th>
<th style='padding: 10px;'>空间复杂度</th>
<th style='padding: 10px;'>瓶颈</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>训练(Cholesky 分解)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N³)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N²)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>核矩阵 K 的 Cholesky 分解</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>单点预测</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>需与所有训练点计算核值</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>批量预测 (M 点)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(MN + N²)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(MN)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>大 M 时成为瓶颈</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>超参数优化</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N³) × 迭代次数</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>O(N²)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>每次迭代都需 Cholesky</td>
</tr>
</table>
<p style='margin: 8px 0; color: #c62828; font-weight: 600;'>
⚠️ 正是 O(N³) 的训练复杂度和 O(N) 的单点预测成本,使得 GPR 不适合 MPC 实时控制
(每个控制步需评估模型数十次),因此需要将 GPR 的知识蒸馏到 O(1) 推理的 NN 中。
</p>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
✈️ GPR 在发动机代理建模中的应用
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #c8e6c9;'>
<p>在本项目中,GPR 被用作涡轴发动机的<strong>高精度代理模型 (Surrogate Model)</strong>
替代复杂的热力学仿真代码。</p>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0; border: 1px solid #c8e6c9;'>
<p><strong>建模映射关系:</strong></p>
<div style='text-align: center; padding: 10px; font-size: 1.05em;'>
[高度(m), 马赫数, RPM] &nbsp;→&nbsp; GPR &nbsp;→&nbsp; [燃油流量(kg/h), 功率(kW)]
</div>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em;'>
<tr style='background: #e8f5e9; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>变量</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>含义</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>典型范围</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>Altitude_m</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>飞行高度</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>0 ~ 10000 m</td>
</tr>
<tr style='background: #f8fdf8;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>Mach</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>飞行马赫数</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>0 ~ 0.8</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>RPM</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>燃气涡轮转速</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>1000 ~ 30000+</td>
</tr>
</table>
</div>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 为什么选择 GPR 作为代理模型?</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>发动机热力学仿真每次调用耗时秒级,而 GPR 训练后毫秒级预测</li>
<li>发动机测试数据成本高昂,GPR 在小样本下表现优异</li>
<li>GPR 的方差输出可识别数据稀疏区域,指导后续试验设计</li>
<li>多输出 GPR (Multi-output GP) 可同时建模燃油流量和功率</li>
</ul>
</div>
</div>
</details>
</div>
"""
# ============================================================
# NN 神经网络知识蒸馏知识卡片 — 中文
# ============================================================
NN_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #00695c; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>🧠</span> NN 神经网络 — 知识蒸馏与 MLP 详解
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📖 知识蒸馏 (Knowledge Distillation) 原理
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #b2dfdb;'>
<p style='margin: 10px 0;'><strong>知识蒸馏</strong>是一种模型压缩技术,
将大型"教师"模型(如 GPR)的知识迁移到轻量级"学生"模型(如 MLP 神经网络)中,
在几乎不损失精度的前提下大幅提升推理速度。</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.05em; color: #333;'>
<span style='background: #f3e5f5; padding: 6px 12px; border-radius: 6px;'>[GPR 教师模型]</span>
&nbsp;→ 密集网格预测 →&nbsp;
<span style='background: #e0f2f1; padding: 6px 12px; border-radius: 6px;'>[NN 学生模型]</span>
</div>
</div>
<h4 style='color: #00695c; margin-top: 15px;'>蒸馏流程</h4>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 10px 0; border: 1px dashed #80cbc4;'>
<ol style='line-height: 2.2; margin-left: 15px;'>
<li><strong>训练 GPR 教师:</strong>用少量真实发动机数据训练 GPR 模型</li>
<li><strong>生成伪数据:</strong>在输入空间的密集网格上用 GPR 预测,生成大量"虚拟标签"</li>
<li><strong>训练 NN 学生:</strong>用 GPR 的预测结果作为训练标签,训练 MLP 网络</li>
<li><strong>部署学生网络:</strong>在 MPC 控制器中使用轻量 NN 替代 GPR</li>
</ol>
</div>
<h4 style='color: #00695c; margin-top: 15px;'>教师 vs 学生对比</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #00695c 0%, #004d40 100%); color: white;'>
<th style='padding: 10px;'>指标</th>
<th style='padding: 10px;'>GPR (教师)</th>
<th style='padding: 10px;'>NN (学生)</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #b2dfdb;'><strong>推理速度</strong></td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>~10 ms(核矩阵运算)</td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>~0.1 ms(矩阵乘法)</td>
</tr>
<tr style='background: #f0faf8;'>
<td style='padding: 8px; border: 1px solid #b2dfdb;'><strong>内存占用</strong></td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>O(N²) — 存储全部训练数据</td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>O(W) — 约 4.5K 参数</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #b2dfdb;'><strong>不确定性</strong></td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>预测均值 + 后验方差</td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>仅点估计</td>
</tr>
<tr style='background: #f0faf8;'>
<td style='padding: 8px; border: 1px solid #b2dfdb;'><strong>MPC 适用性</strong></td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>推理太慢,不适合实时</td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>✅ 满足实时控制需求</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #b2dfdb;'><strong>批量预测</strong></td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>大批量很慢</td>
<td style='padding: 8px; border: 1px solid #b2dfdb;'>天然并行,GPU 加速</td>
</tr>
</table>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🏗️ MLP 多层感知机架构详解
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #c5cae9;'>
<p>学生网络采用 <strong>3 层全连接 MLP (Multi-Layer Perceptron)</strong> 架构:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.05em; color: #333;'>
<span style='background: #e3f2fd; padding: 5px 10px; border-radius: 6px;'>输入 (3)</span>
→ <span style='background: #f3e5f5; padding: 5px 10px; border-radius: 6px;'>Linear(64) + Tanh</span>
→ <span style='background: #f3e5f5; padding: 5px 10px; border-radius: 6px;'>Linear(64) + Tanh</span>
→ <span style='background: #e8f5e9; padding: 5px 10px; border-radius: 6px;'>Linear(2)</span>
→ <span style='background: #fff3e0; padding: 5px 10px; border-radius: 6px;'>输出 (2)</span>
</div>
</div>
<h4 style='color: #303f9f; margin-top: 18px;'>前向传播数学公式</h4>
<p>每一层的计算可以表示为仿射变换 + 非线性激活:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em; margin: 6px 0;'>
<strong>第 l 层:</strong>&nbsp;
<b>z</b><sup>(l)</sup> = W<sup>(l)</sup> <b>a</b><sup>(l1)</sup> + <b>b</b><sup>(l)</sup>
</div>
<div style='font-size: 1.1em; margin: 6px 0;'>
<strong>激活后:</strong>&nbsp;
<b>a</b><sup>(l)</sup> = σ(<b>z</b><sup>(l)</sup>)
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px; font-size: 0.95em;'>
<li><strong>W<sup>(l)</sup></strong> ∈ <sup>d<sub>l</sub>×d<sub>l1</sub></sup>:第 l 层的权重矩阵</li>
<li><strong>b<sup>(l)</sup></strong> ∈ <sup>d<sub>l</sub></sup>:第 l 层的偏置向量</li>
<li><strong>σ(·)</strong>:激活函数(本项目使用 Tanh</li>
<li><strong>a<sup>(0)</sup></strong> = <b>x</b>(输入向量)</li>
</ul>
<h4 style='color: #303f9f; margin-top: 18px;'>本网络的完整前向计算</h4>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0; border: 1px solid #c5cae9;'>
<div style='font-size: 1.05em; line-height: 2.5;'>
<b>h</b><sub>1</sub> = tanh(W<sub>1</sub> · <b>x̂</b> + <b>b</b><sub>1</sub>) &nbsp;&nbsp;&nbsp; <span style='color: #888;'>// 隐藏层 1: ℝ³ → ℝ⁶⁴</span><br>
<b>h</b><sub>2</sub> = tanh(W<sub>2</sub> · <b>h</b><sub>1</sub> + <b>b</b><sub>2</sub>) &nbsp;&nbsp;&nbsp; <span style='color: #888;'>// 隐藏层 2: ℝ⁶⁴ → ℝ⁶⁴</span><br>
<b>ŷ</b> = W<sub>3</sub> · <b>h</b><sub>2</sub> + <b>b</b><sub>3</sub> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style='color: #888;'>// 输出层: ℝ⁶⁴ → ℝ² (无激活)</span>
</div>
</div>
<h4 style='color: #303f9f; margin-top: 18px;'>参数量计算</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em;'>
<tr style='background: #e8eaf6; font-weight: 600;'>
<td style='padding: 8px; border: 1px solid #c5cae9;'>层</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>形状</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>权重数</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>偏置数</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>合计</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #c5cae9;'>Linear-1</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>3 → 64</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>192</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>64</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>256</td>
</tr>
<tr style='background: #f5f5ff;'>
<td style='padding: 8px; border: 1px solid #c5cae9;'>Linear-2</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>64 → 64</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>4096</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>64</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>4160</td>
</tr>
<tr>
<td style='padding: 8px; border: 1px solid #c5cae9;'>Linear-3</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>64 → 2</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>128</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>2</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>130</td>
</tr>
<tr style='background: #e8eaf6; font-weight: 700;'>
<td style='padding: 8px; border: 1px solid #c5cae9;' colspan='4'>总参数量</td>
<td style='padding: 8px; border: 1px solid #c5cae9;'>4,546</td>
</tr>
</table>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📐 激活函数详解
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #ffe0b2;'>
<p>激活函数为神经网络引入<strong>非线性</strong>——没有激活函数,无论多少层的网络都等价于单层线性变换。</p>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 15px; border-radius: 10px; margin: 12px 0; border-left: 4px solid #43a047;'>
<strong style='color: #2e7d32; font-size: 1.05em;'>Tanh (双曲正切) — 本项目所用</strong>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
tanh(x) =
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>e<sup>x</sup> e<sup>x</sup></span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>e<sup>x</sup> + e<sup>x</sup></span>
</span>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>输出范围:</strong>(1, +1),以零为中心</li>
<li><strong>导数:</strong>tanh'(x) = 1 tanh²(x),最大值为 1x=0 处)</li>
<li><strong>优点:</strong>输出零中心,有助于加速收敛</li>
<li><strong>缺点:</strong>|x| 较大时梯度接近 0(梯度饱和),deep网络可能出现梯度消失</li>
</ul>
</div>
<h4 style='color: #e65100; margin-top: 15px;'>常用激活函数对比</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #e65100 0%, #bf360c 100%); color: white;'>
<th style='padding: 10px;'>函数</th>
<th style='padding: 10px;'>公式</th>
<th style='padding: 10px;'>范围</th>
<th style='padding: 10px;'>特点</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>Sigmoid</strong></td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>1 / (1 + e<sup>x</sup>)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>(0, 1)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>输出非零中心,双端饱和</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>Tanh</strong></td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>(e<sup>x</sup>e<sup>x</sup>)/(e<sup>x</sup>+e<sup>x</sup>)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>(1, 1)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>零中心,双端饱和</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>ReLU</strong></td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>max(0, x)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>[0, ∞)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>计算高效,但有"死神经元"问题</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'><strong>GELU</strong></td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>x · Φ(x)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>连续</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>Transformer 常用,性能好</td>
</tr>
</table>
<p style='color: #555; font-size: 0.93em;'>对于本项目的回归任务(光滑连续的发动机特性映射),Tanh 是良好的选择,
因为数据经过 Z-Score 标准化后值域在 [−3, 3] 左右,刚好在 Tanh 的线性区间内。</p>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📉 损失函数与反向传播
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #e1bee7;'>
<h4 style='color: #7b1fa2;'>损失函数 (Loss Function)</h4>
<p>本项目在<strong>标准化 log 空间</strong>中使用 MSE (Mean Squared Error) 损失:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
L =
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>1</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>N</span>
</span>
Σ<sub>i=1</sub><sup>N</sup> ‖ŷ<sub>i</sub> y<sub>i</sub>‖²
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>
其中 ŷ 和 y 均为标准化 log 空间中的值(先 log1p 变换,再 Z-Score)。
在标准化空间中训练使得燃油流量和功率两个输出的损失贡献相当。
</p>
<h4 style='color: #7b1fa2; margin-top: 18px;'>反向传播算法 (Backpropagation)</h4>
<p>反向传播基于<strong>链式法则 (Chain Rule)</strong>,从输出层到输入层逐层计算梯度:</p>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0; border: 1px solid #e1bee7;'>
<div style='font-size: 1.05em; line-height: 2.5;'>
<strong>输出层梯度:</strong>&nbsp;
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>∂L</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>∂W<sub>3</sub></span>
</span>
=
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>∂L</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>∂ŷ</span>
</span>
· <b>h</b><sub>2</sub><sup>T</sup>
<br>
<strong>隐藏层梯度:</strong>&nbsp;
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>∂L</span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>∂W<sub>l</sub></span>
</span>
= δ<sup>(l)</sup> · <b>a</b><sup>(l1)T</sup>
&nbsp;&nbsp;其中&nbsp; δ<sup>(l)</sup> = (W<sub>l+1</sub><sup>T</sup> δ<sup>(l+1)</sup>) ⊙ σ'(<b>z</b><sup>(l)</sup>)
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>⊙</strong> 表示逐元素乘法 (Hadamard product)</li>
<li><strong>σ'</strong> 为激活函数的导数:tanh'(x) = 1 tanh²(x)</li>
<li>反向传播的梯度从后向前"流动",自动计算所有参数的偏导数</li>
<li>PyTorch 的 <code>autograd</code> 引擎自动构建计算图并执行反向传播</li>
</ul>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔧 优化器与学习率调度
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #bbdefb;'>
<h4 style='color: #1565c0;'>Adam 优化器</h4>
<p>Adam (Adaptive Moment Estimation) 结合了动量 (Momentum) 和 RMSProp 的优点:</p>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0; border: 1px solid #bbdefb;'>
<div style='font-size: 1.05em; line-height: 2.5;'>
<b>m</b><sub>t</sub> = β<sub>1</sub> <b>m</b><sub>t1</sub> + (1−β<sub>1</sub>) <b>g</b><sub>t</sub>
&nbsp;&nbsp;<span style='color: #888;'>// 一阶矩(梯度均值)</span><br>
<b>v</b><sub>t</sub> = β<sub>2</sub> <b>v</b><sub>t1</sub> + (1−β<sub>2</sub>) <b>g</b><sub>t</sub>²
&nbsp;&nbsp;<span style='color: #888;'>// 二阶矩(梯度方差)</span><br>
<b>m̂</b><sub>t</sub> = <b>m</b><sub>t</sub> / (1−β<sub>1</sub><sup>t</sup>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style='color: #888;'>// 偏差修正</span><br>
<b>v̂</b><sub>t</sub> = <b>v</b><sub>t</sub> / (1−β<sub>2</sub><sup>t</sup>)<br>
θ<sub>t+1</sub> = θ<sub>t</sub> η · <b>m̂</b><sub>t</sub> / (√<b>v̂</b><sub>t</sub> + ε)
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>β<sub>1</sub>=0.9, β<sub>2</sub>=0.999</strong>:动量和二阶矩的衰减率(默认值)</li>
<li><strong>ε=10⁻⁸</strong>:防止除零的小常数</li>
<li><strong>η</strong>:初始学习率(本项目约 1e-3 ~ 5e-3</li>
<li>Adam 为每个参数维护独立的自适应学习率</li>
</ul>
<h4 style='color: #1565c0; margin-top: 18px;'>余弦退火学习率调度 (Cosine Annealing)</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
η<sub>t</sub> = η<sub>min</sub> +
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>η<sub>max</sub> η<sub>min</sub></span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>2</span>
</span>
<span style='font-size: 1.2em;'>(</span>
1 + cos
<span style='font-size: 1.2em;'>(</span>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>πt</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>T</span>
</span>
<span style='font-size: 1.2em;'>)</span>
<span style='font-size: 1.2em;'>)</span>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>学习率从 η<sub>max</sub> 平滑下降到 η<sub>min</sub>,呈余弦形状</li>
<li>训练初期学习率大 → 快速探索参数空间</li>
<li>训练后期学习率小 → 精细化调整,不会跳出最优解</li>
<li>比阶梯式衰减更平滑,收敛更稳定</li>
</ul>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔄 数据处理流水线与超参数建议
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #f8bbd0;'>
<h4 style='color: #c62828;'>完整数据流水线</h4>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 12px 0; border: 1px dashed #f48fb1;'>
<ol style='line-height: 2.3; margin-left: 15px;'>
<li><strong>原始输入:</strong>[高度(m), 马赫数, 转速(RPM)]</li>
<li><strong>输入 Z-Score</strong>x̂ = (x μ<sub>x</sub>) / σ<sub>x</sub></li>
<li><strong>NN 前向传播:</strong>ŷ<sub>norm</sub> = MLP(x̂)</li>
<li><strong>反 Z-Score</strong>ŷ<sub>log</sub> = ŷ<sub>norm</sub> · σ<sub>y</sub> + μ<sub>y</sub></li>
<li><strong>反 Log1p</strong>ŷ = expm1(ŷ<sub>log</sub>) = e<sup>ŷ<sub>log</sub></sup> 1</li>
<li><strong>物理输出:</strong>[燃油流量(kg/h), 功率(kW)]</li>
</ol>
</div>
<h4 style='color: #c62828; margin-top: 15px;'>超参数调优建议</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); color: white;'>
<th style='padding: 10px;'>超参数</th>
<th style='padding: 10px;'>推荐范围</th>
<th style='padding: 10px;'>增大效果</th>
<th style='padding: 10px;'>减小效果</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>隐藏层宽度</strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>32 ~ 128</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>拟合能力增强,速度稍降</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>推理更快,但可能欠拟合</td>
</tr>
<tr style='background: #fff5f8;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>训练轮数</strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>2000 ~ 5000</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>精度更高,但耗时增加</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>训练快,但可能未收敛</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>学习率</strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>1e-3 ~ 5e-3</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>收敛更快,但容易振荡</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>收敛更稳,但可能太慢</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>🎯 观察训练 Loss 曲线的注意事项:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>Loss 持续下降</strong>:正常训练中,一切良好</li>
<li><strong>Loss 振荡不降</strong>:学习率可能过大,尝试降低</li>
<li><strong>Loss 很快收敛到平台</strong>:模型容量不足(增大隐藏层宽度)或学习率太小</li>
<li><strong>Parity Plot 偏离对角线</strong>:模型预测有系统偏差,可能需要更多训练轮数</li>
<li>典型目标:MAPE &lt; 1%,即 NN 与 GPR 的预测差异小于 1%</li>
</ul>
</div>
</div>
</details>
</div>
"""
# ============================================================
# 能量管理策略知识卡片 — 中文
# ============================================================
EMS_KNOWLEDGE = """
<div class='knowledge-card'>
<h3 style='color: #2e7d32; margin-top: 0; display: flex; align-items: center; gap: 10px;'>
<span style='font-size: 1.3em;'>🔋</span> 串联混动能量管理策略 (EMS)
</h3>
<details open>
<summary style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📊 SOC 迟滞控制 (Hysteresis Control)
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #c8e6c9;'>
<p>EMS 采用<strong>迟滞(滞回)控制策略</strong>,在"充电模式"与"功率跟随模式"
之间引入死区,避免因 SOC 在阈值附近波动而导致频繁切换:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
<div style='font-size: 1.05em; color: #333;'>
SOC &lt; SOC<sub>low</sub> → <span style='color: #c62828; font-weight: bold;'>充电模式</span>(发动机以固定高功率运行)<br>
SOC &gt; SOC<sub>high</sub> → <span style='color: #2e7d32; font-weight: bold;'>功率跟随模式</span>(发动机跟踪需求功率)<br>
SOC<sub>low</sub> ≤ SOC ≤ SOC<sub>high</sub> → <span style='color: #1565c0; font-weight: bold;'>保持当前模式</span>(迟滞死区)
</div>
</div>
<h4 style='color: #2e7d32; margin-top: 18px;'>运行模式详解</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%); color: white;'>
<th style='padding: 10px;'>模式</th>
<th style='padding: 10px;'>发动机功率</th>
<th style='padding: 10px;'>触发条件</th>
<th style='padding: 10px;'>设计目的</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'><strong style='color:#c62828;'>紧急充电</strong></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>最大功率 P<sub>eng,max</sub></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>SOC &lt; 10%</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>防止电池深放电损坏</td>
</tr>
<tr style='background: #f0fff0;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'><strong style='color:#e65100;'>充电模式</strong></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>恒定充电功率 P<sub>charge</sub></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>SOC &lt; SOC<sub>low</sub>(进入)</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>高效率恒定工况点运行</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'><strong style='color:#2e7d32;'>功率跟随</strong></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>P<sub>demand</sub> + Reserve + K<sub>SOC</sub>·ΔSOC</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>SOC &gt; SOC<sub>high</sub>(退出充电)</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>实时匹配负载需求</td>
</tr>
<tr style='background: #f0fff0;'>
<td style='padding: 8px; border: 1px solid #c8e6c9;'><strong style='color:#1565c0;'>过充保护</strong></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>最低功率 P<sub>eng,min</sub></td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>SOC &gt; 95%</td>
<td style='padding: 8px; border: 1px solid #c8e6c9;'>防止电池过充损坏</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 迟滞控制原理:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>上阈值 SOC<sub>high</sub></strong>(如 0.7):SOC 超过此值时从充电切换到功率跟随</li>
<li><strong>下阈值 SOC<sub>low</sub></strong>(如 0.3):SOC 降到此值时从功率跟随切换到充电</li>
<li>死区宽度 = SOC<sub>high</sub> SOC<sub>low</sub>,越宽则切换频率越低,但 SOC 波动范围越大</li>
<li>死区内保持上一步的运行模式不变 → 有效抑制"抖动"(chattering)</li>
</ul>
</div>
</div>
</details>
<details open>
<summary style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔌 串联混合动力架构
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #ffe0b2;'>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<span style='font-size: 1em; color: #555;'>
[涡轴发动机] → 发电机 → 直流母线 ← → [锂电池组]<br>
直流母线 → 逆变器 → [PMSM 驱动电机] → 螺旋桨
</span>
</div>
<p>发动机与推进轴<strong>机械解耦</strong>:所有动力通过电气母线传输,
允许发动机始终运行在最优效率点,不受负载功率变化的直接影响。</p>
<h4 style='color: #e65100; margin-top: 15px;'>架构特点</h4>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #e65100 0%, #bf360c 100%); color: white;'>
<th style='padding: 10px;'>特性</th>
<th style='padding: 10px;'>串联构型</th>
<th style='padding: 10px;'>并联构型(对比)</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>发动机-负载耦合</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>完全解耦</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>机械直连</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>发动机工况</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>可固定在最优效率点</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>随负载波动</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>EMS 复杂度</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>较低(功率分配)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>较高(扭矩耦合)</td>
</tr>
<tr style='background: #fff8f0;'>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>能量传递效率</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>经两次电能转换(略低)</td>
<td style='padding: 8px; border: 1px solid #ffe0b2;'>机械直驱(略高)</td>
</tr>
</table>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
⚙️ 关键参数与调节指南
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #f8bbd0;'>
<table style='width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.93em; box-shadow: 0 2px 10px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden;'>
<tr style='background: linear-gradient(135deg, #880e4f 0%, #ad1457 100%); color: white;'>
<th style='padding: 10px;'>参数</th>
<th style='padding: 10px;'>作用</th>
<th style='padding: 10px;'>调大效果</th>
<th style='padding: 10px;'>调小效果</th>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>P<sub>charge</sub></strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>充电模式发动机功率</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>SOC 恢复更快</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>充电更温和,效率稍高</td>
</tr>
<tr style='background: #fff0f5;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>K<sub>SOC</sub></strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>功率跟随模式 SOC 反馈增益</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>SOC 偏差纠正更强</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>发动机功率更平稳</td>
</tr>
<tr style='background: white;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>功率裕度 %</strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>发动机额外功率余量</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>抗瞬态能力增强</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>油耗更低</td>
</tr>
<tr style='background: #fff0f5;'>
<td style='padding: 8px; border: 1px solid #f8bbd0;'><strong>电池容量</strong></td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>能量缓冲区大小</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>SOC 波动更小</td>
<td style='padding: 8px; border: 1px solid #f8bbd0;'>系统更轻、响应更快</td>
</tr>
</table>
<div style='background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>🎯 仿真观察要点:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>SOC 是否维持在安全范围(10% ~ 95%)内</li>
<li>充电-跟随模式切换是否过于频繁(理想为低频切换)</li>
<li>发动机功率曲线是否平稳(频繁剧烈波动 → 油耗升高、寿命下降)</li>
<li>最终 SOC 与初始 SOC 之差(SOC 平衡性)</li>
<li>电池充放电电流是否超过安全限值</li>
</ul>
</div>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 调参建议:</strong></p>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li>先用默认参数跑一次,观察 SOC 整体走势</li>
<li>若 SOC 持续下降 → 增大 P<sub>charge</sub> 或 K<sub>SOC</sub></li>
<li>若模式切换过于频繁 → 加大 SOC<sub>high</sub> SOC<sub>low</sub> 死区宽度</li>
<li>若发动机功率波动大 → 降低 K<sub>SOC</sub>,增大功率裕度</li>
</ul>
</div>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
🔋 电池 SOC 动态方程与功率平衡
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #bbdefb;'>
<h4 style='color: #1565c0;'>SOC 状态方程(库仑计数法)</h4>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.15em;'>
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 6px 3px;'>dSOC</span>
<span style='display: block; text-align: center; padding: 3px 6px 0;'>dt</span>
</span>
=
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>P<sub>bat</sub></span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>Q<sub>bat</sub></span>
</span>
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>
P<sub>bat</sub> 为电池充放电功率(放电为正),Q<sub>bat</sub> 为电池总容量 (kWh)。
离散化:SOC<sub>k+1</sub> = SOC<sub>k</sub> (P<sub>bat,k</sub> · Δt) / Q<sub>bat</sub>
</p>
<h4 style='color: #1565c0; margin-top: 15px;'>系统功率平衡方程</h4>
<div style='text-align: center; background: white; padding: 15px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
P<sub>demand</sub>(t) = P<sub>engine</sub>(t) + P<sub>battery</sub>(t)
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>P<sub>demand</sub> &gt; P<sub>engine</sub></strong>:电池补充差额(放电),SOC 下降</li>
<li><strong>P<sub>demand</sub> &lt; P<sub>engine</sub></strong>:多余功率给电池充电,SOC 上升</li>
<li>EMS 的核心任务就是合理分配 P<sub>engine</sub>,使 SOC 维持在安全范围</li>
</ul>
<h4 style='color: #1565c0; margin-top: 15px;'>功率跟随模式公式</h4>
<div style='background: white; padding: 15px; border-radius: 8px; margin: 10px 0; border: 1px solid #bbdefb;'>
<div style='font-size: 1.05em; line-height: 2.0;'>
P<sub>eng,cmd</sub> = P<sub>demand</sub> × (1 + Reserve%) + K<sub>SOC</sub> × (SOC<sub>target</sub> SOC)<br>
P<sub>eng,cmd</sub> = clamp(P<sub>eng,cmd</sub>, P<sub>eng,min</sub>, P<sub>eng,max</sub>)
</div>
</div>
<p style='color: #555; font-size: 0.93em;'>
第二项为 SOC 反馈补偿:当 SOC 低于目标时增加发动机功率以充电;
当 SOC 高于目标时减少发动机功率以节油。
</p>
</div>
</details>
<details>
<summary style='background: linear-gradient(135deg, #ede7f6 0%, #d1c4e9 100%); padding: 12px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; color: #333; font-size: 1.05em; margin: 10px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.08);'>
📚 进阶:ECMS 等效消耗最小化策略
</summary>
<div style='padding: 15px; background: #fafbff; margin-top: 5px; border-radius: 10px; border: 1px solid #d1c4e9;'>
<p>ECMS (Equivalent Consumption Minimization Strategy) 是一种更先进的实时优化 EMS。
它将电池充放电等效为燃油消耗,从而将双能源分配问题转化为单目标瞬时优化:</p>
<div style='text-align: center; background: white; padding: 18px; border-radius: 8px; margin: 10px 0;'>
<div style='font-size: 1.1em;'>
min<sub>P<sub>eng</sub></sub> &nbsp;
J = ṁ<sub>fuel</sub>(P<sub>eng</sub>) + s(t) ·
<span style='display: inline-block; vertical-align: middle;'>
<span style='display: block; text-align: center; border-bottom: 2px solid #333; padding: 0 8px 3px;'>P<sub>bat</sub></span>
<span style='display: block; text-align: center; padding: 3px 8px 0;'>η<sub>bat</sub> · Q<sub>LHV</sub></span>
</span>
</div>
</div>
<ul style='line-height: 1.8; margin-left: 15px;'>
<li><strong>s(t)</strong>:等效因子,将电能消耗折算为燃油消耗</li>
<li><strong>Q<sub>LHV</sub></strong>:燃料低热值 (MJ/kg)</li>
<li><strong>η<sub>bat</sub></strong>:电池充放电效率</li>
<li>当 s(t) 自适应调整以维持 SOC 时,ECMS 近似全局最优</li>
</ul>
<div style='background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%); padding: 12px; border-radius: 8px; margin: 10px 0;'>
<p><strong>💡 本平台使用的是基于规则的滞环策略(简单可靠),
ECMS 和 DP (动态规划) 等高级方法可作为后续扩展方向。</strong></p>
</div>
</div>
</details>
</div>
"""