new file: doc/manual.html
This commit is contained in:
+556
@@ -0,0 +1,556 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Dynamics — 物理模拟实验手册</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #f0f4ff; --card: #fff;
|
||||||
|
--text: #1a1a2e; --sub: #555;
|
||||||
|
--primary: #4361ee; --secondary: #7209b7;
|
||||||
|
--fun: #f72585; --green: #06d6a0; --orange: #ff9e00;
|
||||||
|
--code-bg: #1e1e2e; --code-text: #cdd6f4;
|
||||||
|
}
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, "Noto Sans SC", "Microsoft YaHei", sans-serif;
|
||||||
|
background: var(--bg); color: var(--text); line-height: 1.8;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 封面 ── */
|
||||||
|
.cover {
|
||||||
|
background: linear-gradient(135deg, var(--secondary), var(--primary), var(--fun));
|
||||||
|
color: #fff; padding: 60px 20px 50px; text-align: center;
|
||||||
|
position: relative; overflow: hidden;
|
||||||
|
}
|
||||||
|
.cover::after {
|
||||||
|
content: "⚛︎ ⋆ 。°✩"; font-size: 60px; opacity: .08;
|
||||||
|
position: absolute; bottom: 10px; right: 20px;
|
||||||
|
}
|
||||||
|
.cover h1 { font-size: 2.6em; margin-bottom: 10px; letter-spacing: 2px; }
|
||||||
|
.cover .subtitle { font-size: 1.1em; opacity: .88; margin-bottom: 8px; }
|
||||||
|
.cover .audience {
|
||||||
|
display: inline-block; margin-top: 12px;
|
||||||
|
background: rgba(255,255,255,.15); padding: 6px 20px;
|
||||||
|
border-radius: 20px; font-size: .85em;
|
||||||
|
}
|
||||||
|
.cover .particles { font-size: 40px; margin-bottom: 12px; }
|
||||||
|
|
||||||
|
/* ── 导航 ── */
|
||||||
|
nav {
|
||||||
|
background: var(--card); border-bottom: 1px solid #ddd;
|
||||||
|
padding: 10px 20px; position: sticky; top: 0; z-index: 100;
|
||||||
|
display: flex; flex-wrap: wrap; gap: 6px;
|
||||||
|
}
|
||||||
|
nav a {
|
||||||
|
color: var(--primary); text-decoration: none; font-size: .85em;
|
||||||
|
padding: 4px 14px; border-radius: 14px;
|
||||||
|
border: 1px solid #ddd; transition: .2s;
|
||||||
|
}
|
||||||
|
nav a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
|
||||||
|
|
||||||
|
/* ── 内容 ── */
|
||||||
|
.container { max-width: 820px; margin: 0 auto; padding: 24px 20px; }
|
||||||
|
section {
|
||||||
|
background: var(--card); border-radius: 16px; padding: 28px;
|
||||||
|
margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.5em; margin-bottom: 16px; color: var(--primary);
|
||||||
|
display: flex; align-items: center; gap: 10px;
|
||||||
|
}
|
||||||
|
h2 .emoji { font-size: 1.2em; }
|
||||||
|
h3 { font-size: 1.15em; margin: 20px 0 8px; color: var(--secondary); }
|
||||||
|
|
||||||
|
/* ── 小彩条 ── */
|
||||||
|
.tip {
|
||||||
|
background: #e8faf1; border-left: 4px solid var(--green);
|
||||||
|
padding: 12px 16px; margin: 12px 0; border-radius: 0 8px 8px 0;
|
||||||
|
}
|
||||||
|
.tip strong { color: #0a7a50; }
|
||||||
|
.warn-box {
|
||||||
|
background: #fff8e1; border-left: 4px solid var(--orange);
|
||||||
|
padding: 12px 16px; margin: 12px 0; border-radius: 0 8px 8px 0;
|
||||||
|
}
|
||||||
|
.fun-box {
|
||||||
|
background: #fce4ec; border-left: 4px solid var(--fun);
|
||||||
|
padding: 12px 16px; margin: 12px 0; border-radius: 0 8px 8px 0;
|
||||||
|
}
|
||||||
|
.fun-box strong { color: #c51162; }
|
||||||
|
|
||||||
|
p, li { margin-bottom: 10px; }
|
||||||
|
ul, ol { padding-left: 22px; margin: 8px 0 12px; }
|
||||||
|
|
||||||
|
/* ── 代码与路径 ── */
|
||||||
|
.file-path {
|
||||||
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
|
font-size: .82em; background: #eef; padding: 2px 8px;
|
||||||
|
border-radius: 4px; color: var(--secondary);
|
||||||
|
}
|
||||||
|
code {
|
||||||
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
|
background: #eef; padding: 1px 5px; border-radius: 3px;
|
||||||
|
font-size: .88em; color: var(--fun);
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
background: var(--code-bg); color: var(--code-text);
|
||||||
|
padding: 16px; border-radius: 8px; overflow-x: auto;
|
||||||
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
|
font-size: .82em; line-height: 1.6; margin: 10px 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
pre .tag {
|
||||||
|
position: absolute; top: 6px; right: 10px;
|
||||||
|
font-size: .7em; background: #333; color: #aaa;
|
||||||
|
padding: 2px 8px; border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 表格 ── */
|
||||||
|
table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .93em; }
|
||||||
|
th, td { border: 1px solid #ddd; padding: 10px 12px; text-align: left; }
|
||||||
|
th { background: #eef; font-weight: 600; }
|
||||||
|
tr:nth-child(even) { background: #f8f9fa; }
|
||||||
|
|
||||||
|
/* ── 图片占位 ── */
|
||||||
|
.demo-pic {
|
||||||
|
background: linear-gradient(135deg, #e0e7ff, #f0e6ff);
|
||||||
|
border-radius: 12px; padding: 30px; text-align: center;
|
||||||
|
margin: 14px 0; font-size: .9em; color: #666;
|
||||||
|
border: 2px dashed #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-box {
|
||||||
|
background: #f0f4ff; border-radius: 12px; padding: 16px 20px;
|
||||||
|
margin: 12px 0; border: 1px solid #d0d8f0;
|
||||||
|
}
|
||||||
|
.step-box .num {
|
||||||
|
display: inline-block; width: 28px; height: 28px;
|
||||||
|
background: var(--primary); color: #fff;
|
||||||
|
border-radius: 50%; text-align: center; line-height: 28px;
|
||||||
|
font-weight: 700; font-size: .85em; margin-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
text-align: center; padding: 24px; color: #999;
|
||||||
|
font-size: .85em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- ═══════════════════ 封面 ═══════════════════ -->
|
||||||
|
<div class="cover">
|
||||||
|
<div class="particles">⚛︎ ⋆。°✩ ⭐ ⋆。°✩</div>
|
||||||
|
<h1>Dynamics 物理模拟实验室</h1>
|
||||||
|
<div class="subtitle">用代码让小球动起来!从牛顿力学到分子模拟</div>
|
||||||
|
<div class="audience">🎯 适合高一同学 · 零基础也能上手</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<a href="#intro">这是什么?</a>
|
||||||
|
<a href="#setup">安装</a>
|
||||||
|
<a href="#physics">物理课</a>
|
||||||
|
<a href="#firstrun">第一次运行</a>
|
||||||
|
<a href="#config">调参数</a>
|
||||||
|
<a href="#exp">实验</a>
|
||||||
|
<a href="#advanced">高手进阶</a>
|
||||||
|
<a href="#faq">常见问题</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="intro">
|
||||||
|
<h2><span class="emoji">🤔</span> 这是什么?</h2>
|
||||||
|
|
||||||
|
<p>想象一下:你把一个弹珠从桌子上推下去——它会怎么运动?如果同时扔两个弹珠,它们会互相碰撞吗?如果弹珠之间用弹簧连着呢?</p>
|
||||||
|
|
||||||
|
<p><strong>Dynamics</strong> 就是一个在电脑上做这些"弹珠实验"的程序。你只需要告诉电脑:</p>
|
||||||
|
<ul>
|
||||||
|
<li>小球在哪里、多重、多快</li>
|
||||||
|
<li>有没有重力、有没有弹簧</li>
|
||||||
|
<li>跑多少步、画什么图</li>
|
||||||
|
</ul>
|
||||||
|
<p>然后电脑就会帮你算出每个小球每一瞬间的位置和速度,最后画出一张漂亮的轨迹图!</p>
|
||||||
|
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🎮 把它想象成一个超级物理沙盒游戏</strong><br>
|
||||||
|
你设置物理规则,电脑负责计算,然后你看到结果。和 Minecraft 有点像,但这里的「物理引擎」是真的物理公式!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>它能做什么?</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>模拟自由落体</strong> —— 苹果为什么会往下掉?</li>
|
||||||
|
<li><strong>模拟弹簧振动</strong> —— 弹弹球为什么上下跳?</li>
|
||||||
|
<li><strong>模拟双星绕转</strong> —— 两颗星星为什么互相转?</li>
|
||||||
|
<li><strong>画轨迹图</strong> —— 把运动过程变成曲线图</li>
|
||||||
|
<li><strong>3D 动画</strong> —— 在 3D 空间里看小球飞</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="setup">
|
||||||
|
<h2><span class="emoji">🛠️</span> 安装</h2>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<span class="num">1</span>
|
||||||
|
<strong>安装 Python</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;font-size:.92em;">
|
||||||
|
从 <a href="https://www.python.org/downloads/" target="_blank">python.org</a> 下载安装包,
|
||||||
|
安装时<strong>一定记得勾选</strong> "Add Python to PATH"。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<span class="num">2</span>
|
||||||
|
<strong>安装依赖包</strong>
|
||||||
|
<pre style="margin:8px 0 0 0;"><span class="tag">终端</span>pip install numpy pyyaml tqdm matplotlib</pre>
|
||||||
|
<p style="margin:4px 0 0 20px;font-size:.92em;color:var(--sub);">
|
||||||
|
如果下载慢,试试国内镜像:<code>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ...</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<span class="num">3</span>
|
||||||
|
<strong>下载程序</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;font-size:.92em;">
|
||||||
|
把整个项目文件夹放到电脑上。打开终端,<code>cd</code> 到项目目录。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<span class="num">4</span>
|
||||||
|
<strong>验证安装</strong>
|
||||||
|
<pre style="margin:8px 0 0 0;"><span class="tag">终端</span>py -3 examples/case01/run_dynamics.py --no-plot</pre>
|
||||||
|
<p style="margin:4px 0 0 20px;font-size:.92em;color:var(--sub);">
|
||||||
|
看到 <code>[run] 完成!</code> 就说明成功了!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tip">
|
||||||
|
<strong>💡 小提示:</strong>如果你只想看看效果,装好 <code>numpy</code> 和 <code>pyyaml</code> 就能跑了。<code>matplotlib</code> 是用来画图的,建议也装上。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="physics">
|
||||||
|
<h2><span class="emoji">📖</span> 快速物理课</h2>
|
||||||
|
|
||||||
|
<p>别怕,你学过的物理知识在这里全用得上!</p>
|
||||||
|
|
||||||
|
<h3>🌍 力(Force)</h3>
|
||||||
|
<p>力是让物体运动状态改变的东西。程序里支持四种力:</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><th>力</th><th>生活中的例子</th><th>程序里的开关</th></tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>均匀重力</strong></td>
|
||||||
|
<td>苹果从树上往下掉,方向朝地面</td>
|
||||||
|
<td><code>gravity_field</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>万有引力</strong></td>
|
||||||
|
<td>太阳和地球互相吸引,质量越大越明显</td>
|
||||||
|
<td><code>gravity_interaction</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>弹簧力</strong></td>
|
||||||
|
<td>蹦极的绳子把你拉回来</td>
|
||||||
|
<td><code>elastic_force</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>阻尼(阻力)</strong></td>
|
||||||
|
<td>在水里挥手比在空气里费劲得多</td>
|
||||||
|
<td><code>damping_force</code></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h3>🏃 运动</h3>
|
||||||
|
<p>程序用 <strong>蛙跳法(Leapfrog)</strong> 来模拟运动。名字很形象:</p>
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🐸 蛙跳的步骤:</strong><br>
|
||||||
|
<ol>
|
||||||
|
<li><strong>前半步</strong>:根据当前受力,把速度往前推一小半步</li>
|
||||||
|
<li><strong>跳</strong>:用新的速度把位置往前推一步</li>
|
||||||
|
<li><strong>后半步</strong>:到新位置后重新算受力,再推另一半速度</li>
|
||||||
|
</ol>
|
||||||
|
<p>就像青蛙跳一样——先蹲下蓄力(半步速度),跳出去(位置更新),再调整(后半步速度)!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>⚡ 能量(Energy)</h3>
|
||||||
|
<p>程序还会帮你计算各种能量,画出漂亮的能量图:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>动能</strong>(蓝色)—— 运动的能量,速度越快越大</li>
|
||||||
|
<li><strong>重力势能</strong>(绿色)—— 位置越高越大</li>
|
||||||
|
<li><strong>弹性势能</strong>(橙色)—— 弹簧拉得越长越大</li>
|
||||||
|
<li><strong>万有引力势能</strong>(紫色)—— 星星之间的引力势能</li>
|
||||||
|
<li>总能量(红色虚线)—— 所有能量加起来,理论上应该是不变的</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tip">
|
||||||
|
<strong>💡 核心思想:能量守恒!</strong> 如果没有外力干扰,总能量应该保持不变。
|
||||||
|
动能和势能之间互相转换——像荡秋千一样,荡到最高点速度最慢(动能最小、势能最大),
|
||||||
|
荡到最低点速度最快(动能最大、势能最小)。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="firstrun">
|
||||||
|
<h2><span class="emoji">🚀</span> 第一次运行</h2>
|
||||||
|
|
||||||
|
<p>让我们来运行第一个模拟——两个小球用弹簧连着,在重力场中下落。</p>
|
||||||
|
|
||||||
|
<h3>运行命令</h3>
|
||||||
|
<pre><span class="tag">终端</span>py -3 examples/case01/run_dynamics.py</pre>
|
||||||
|
|
||||||
|
<p>你会看到:</p>
|
||||||
|
<ol>
|
||||||
|
<li>终端里跳出进度条 <code>|[compute] 计算中: 100%|</code> —— 电脑正在算</li>
|
||||||
|
<li>然后弹出一个窗口,里面有 <strong>9 张图</strong>(位置、速度、能量)</li>
|
||||||
|
<li>最后会生成动画文件</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="demo-pic">
|
||||||
|
📈 这里会显示轨迹图:x-t, y-t, z-t, vx-t, vy-t, vz-t 和能量图<br>
|
||||||
|
<span style="font-size:.8em;">(运行程序后就能看到啦!)</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>只看不画图</h3>
|
||||||
|
<p>如果不想看图片(比如在服务器上跑),加个 <code>--no-plot</code> 就行:</p>
|
||||||
|
<pre><span class="tag">终端</span>py -3 examples/case01/run_dynamics.py --no-plot</pre>
|
||||||
|
|
||||||
|
<h3>输出文件</h3>
|
||||||
|
<p>运行完后在 <span class="file-path">examples/case01/output/</span> 里会生成:</p>
|
||||||
|
<table>
|
||||||
|
<tr><th>文件名</th><th>内容</th></tr>
|
||||||
|
<tr><td><span class="file-path">trajectory.txt</span></td><td>所有小球的全部轨迹数据(很大的文件)</td></tr>
|
||||||
|
<tr><td><span class="file-path">display.txt</span></td><td>抽帧后的显示数据(动画用)</td></tr>
|
||||||
|
<tr><td><span class="file-path">trajectory_plots.png</span></td><td>轨迹和能量图</td></tr>
|
||||||
|
<tr><td><span class="file-path">dynamics.log</span></td><td>运行日志(看看电脑算了多长时间)</td></tr>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="config">
|
||||||
|
<h2><span class="emoji">⚙️</span> 调参数</h2>
|
||||||
|
|
||||||
|
<p>所有参数都在 <span class="file-path">input.txt</span> 里(注意:虽然是 .txt 后缀,但内容是 YAML 格式)。</p>
|
||||||
|
|
||||||
|
<h3>最简单的改动</h3>
|
||||||
|
<p>试试改这几个参数,看看效果有什么不同:</p>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>改变重力大小</strong>
|
||||||
|
<pre style="margin:8px 0 4px;"><span class="tag">input.txt</span>G: [0.0, 0.0, -9.8] # 改成更大的数字,比如 -20</pre>
|
||||||
|
<p style="margin:0 0 4px 0;font-size:.9em;">G 的 3 个数字分别对应 x、y、z 方向的重力分量。</p>
|
||||||
|
<p style="margin:0;font-size:.9em;">把 z 方向改成 -50,小球"叮"一下就掉下去了!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>改变弹簧硬度</strong>
|
||||||
|
<pre style="margin:8px 0 4px;"><span class="tag">bond.txt</span>k1 100.0 2.0</pre>
|
||||||
|
<p style="margin:0;font-size:.9em;">中间那个数字是弹簧的劲度系数(k),越大弹簧越硬。改成 1000 试试?</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>改变步长</strong>
|
||||||
|
<pre style="margin:8px 0 4px;"><span class="tag">input.txt</span>DT: 0.001 # 时间步长(秒)</pre>
|
||||||
|
<p style="margin:0;font-size:.9em;">DT 越小计算越精确,但跑得越慢。试试 0.0001 看看效果?</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>各种力开关</h3>
|
||||||
|
<p>程序里每种力都可以独立开关:</p>
|
||||||
|
<pre><span class="tag">input.txt</span># ── 力开关(0=关闭, 1=开启)──────────────────
|
||||||
|
gravity_field: 1 # 均匀重力场
|
||||||
|
gravity_interaction: 0 # 原子间万有引力
|
||||||
|
elastic_force: 1 # 弹簧键力
|
||||||
|
damping_force: 0 # 阻尼(阻力)</pre>
|
||||||
|
|
||||||
|
<div class="tip">
|
||||||
|
<strong>💡 玩一玩:</strong><br>
|
||||||
|
- 关掉重力 <code>gravity_field: 0</code> → 小球就飘在空中了<br>
|
||||||
|
- 打开万有引力 <code>gravity_interaction: 1</code> → 两个小球会互相吸引<br>
|
||||||
|
- 打开阻尼 <code>damping_force: 1</code> → 小球会慢慢停下来
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>坐标文件</h3>
|
||||||
|
<p><span class="file-path">coord.txt</span> 存放每个小球(原子)的初始位置和速度:</p>
|
||||||
|
<pre><span class="tag">coord.txt</span>n mass radius x y z vx vy vz fix_x fix_y fix_z
|
||||||
|
1 1 0.28 -1 0 0 0 0 0 0 0 0 0
|
||||||
|
2 1 0.28 1 0 1 0 0 0 0 0 0 0</pre>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><th>列名</th><th>含义</th></tr>
|
||||||
|
<tr><td><code>n</code></td><td>小球编号</td></tr>
|
||||||
|
<tr><td><code>mass</code></td><td>质量(越大越「重」,越不容易被推动)</td></tr>
|
||||||
|
<tr><td><code>radius</code></td><td>半径(画出来的大小)</td></tr>
|
||||||
|
<tr><td><code>x y z</code></td><td>初始位置坐标</td></tr>
|
||||||
|
<tr><td><code>vx vy vz</code></td><td>初始速度</td></tr>
|
||||||
|
<tr><td><code>fix_x fix_y fix_z</code></td><td>固定约束(1=锁定该方向不动,0=自由运动)</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="warn-box">
|
||||||
|
<strong>⚠️ 注意:</strong><code>mass</code> 和 <code>radius</code> 必须 > 0。
|
||||||
|
如果设置了 <code>fix_x: 1</code>,那这个小球在 x 方向上就「钉死」了,拉不动。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="exp">
|
||||||
|
<h2><span class="emoji">🧪</span> 动手实验</h2>
|
||||||
|
|
||||||
|
<p>以下实验可以帮你理解不同的物理概念。每个实验都告诉你怎么改参数。</p>
|
||||||
|
|
||||||
|
<h3>实验 1:自由落体</h3>
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🎯 目标:</strong>观察小球在重力场中下落的过程,验证自由落体公式。<br>
|
||||||
|
<strong>操作:</strong>
|
||||||
|
</div>
|
||||||
|
<ol>
|
||||||
|
<li>把 <span class="file-path">coord.txt</span> 改成只有 1 个原子,位置 <code>0 0 10</code>,速度全 0</li>
|
||||||
|
<li>设 <code>gravity_field: 1</code>,关闭其他所有力</li>
|
||||||
|
<li>运行 <code>py -3 examples/case01/run_dynamics.py</code></li>
|
||||||
|
<li>观察 z-t 图(z 坐标随时间变化)—— 应该是一条抛物线!</li>
|
||||||
|
</ol>
|
||||||
|
<div class="tip">
|
||||||
|
<strong>🤔 想一想:</strong>根据物理公式 <em>z</em> = ½<em>gt</em>²,你能从图中算出重力加速度 g 吗?
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>实验 2:弹簧振子</h3>
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🎯 目标:</strong>观察弹簧振子的简谐振动。<br>
|
||||||
|
<strong>操作:</strong>
|
||||||
|
</div>
|
||||||
|
<ol>
|
||||||
|
<li>放两个原子,用弹簧连起来</li>
|
||||||
|
<li>关掉重力 <code>gravity_field: 0</code>,打开 <code>elastic_force: 1</code></li>
|
||||||
|
<li>把其中一个原子拉远一点(改 coord.txt 的初始位置)</li>
|
||||||
|
<li>观察两个小球来回振动</li>
|
||||||
|
</ol>
|
||||||
|
<div class="tip">
|
||||||
|
<strong>🤔 想一想:</strong>弹性势能和动能是怎么互相转换的?看看能量图,橙色线和蓝色线的变化规律。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>实验 3:双星绕转</h3>
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🎯 目标:</strong>模拟两颗星球在万有引力下互相绕转。<br>
|
||||||
|
<strong>操作:</strong>
|
||||||
|
</div>
|
||||||
|
<ol>
|
||||||
|
<li>放两个原子,给它们不同的质量(比如 10 和 1)</li>
|
||||||
|
<li>关掉所有其他力,只打开 <code>gravity_interaction: 1</code></li>
|
||||||
|
<li>给轻的原子一个切向初速度(比如 <code>vx: 0 vy: 1.5 vz: 0</code>)</li>
|
||||||
|
<li>观察轻的原子绕着重的原子转!</li>
|
||||||
|
</ol>
|
||||||
|
<div class="tip">
|
||||||
|
<strong>🤔 想一想:</strong>这和太阳系中行星绕太阳转的原理是一样的吗?哪个原子是「太阳」?
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>实验 4:单摆</h3>
|
||||||
|
<div class="fun-box">
|
||||||
|
<strong>🎯 目标:</strong>用固定约束做一个单摆。<br>
|
||||||
|
<strong>操作:</strong>
|
||||||
|
</div>
|
||||||
|
<ol>
|
||||||
|
<li>放两个原子:原子 1 在 <code>(0, 0, 5)</code>,原子 2 在 <code>(0, 0, 0)</code></li>
|
||||||
|
<li>原子 1 设 <code>fix_x: 1 fix_y: 1 fix_z: 1</code>(钉在天花板上)</li>
|
||||||
|
<li>用弹簧连接两个原子</li>
|
||||||
|
<li>打开重力,运行看效果 — 下面的原子会像摆锤一样摆动!</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="advanced">
|
||||||
|
<h2><span class="emoji">🔬</span> 高手进阶</h2>
|
||||||
|
|
||||||
|
<h3>改变积分方法</h3>
|
||||||
|
<p>程序支持 4 种计算方法,精度和速度不一样:</p>
|
||||||
|
<pre><span class="tag">input.txt</span>method: leapfrog # 可选: explicit_euler | implicit_euler | midpoint | leapfrog</pre>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><th>方法</th><th>精度</th><th>特点</th></tr>
|
||||||
|
<tr><td><code>explicit_euler</code></td><td>⭐</td><td>最简单的方法,不精确但快</td></tr>
|
||||||
|
<tr><td><code>implicit_euler</code></td><td>⭐⭐</td><td>比显式欧拉稳定一些</td></tr>
|
||||||
|
<tr><td><code>midpoint</code></td><td>⭐⭐⭐</td><td>中点法,精度不错</td></tr>
|
||||||
|
<tr><td><code>leapfrog</code></td><td>⭐⭐⭐⭐</td><td>默认方法,精度最高,还能很好地保持能量守恒</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="tip">
|
||||||
|
<strong>💡 试试:</strong>把 <code>method</code> 改成 <code>explicit_euler</code>,关掉所有阻尼,看能量图——
|
||||||
|
你会发现总能量(红色虚线)慢慢增加,因为显式欧拉法不守恒能量!
|
||||||
|
再换回 <code>leapfrog</code>,总能量几乎是一条水平线!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>换成 C 语言引擎</h3>
|
||||||
|
<p>Python 版本跑大模拟可能会慢。程序还支持用 C 语言引擎来加速:</p>
|
||||||
|
<pre><span class="tag">input.txt</span>engine: c # 改成 c 就用 C 引擎,比 Python 快 26 倍!</pre>
|
||||||
|
|
||||||
|
<div class="warn-box">
|
||||||
|
<strong>⚠️ 前提:</strong>需要先安装 C 编译器(gcc)。Windows 上推荐用 MSYS2 + MinGW64,
|
||||||
|
具体步骤见 <span class="file-path">INSTALL.md</span>。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>调整模拟规模</h3>
|
||||||
|
<pre><span class="tag">input.txt</span>NT: 100000 # 总步数(越大模拟时间越长)
|
||||||
|
DT: 0.001 # 每步的时间(秒)
|
||||||
|
NSTEP: 100 # 抽帧间隔(每 NSTEP 步记录一帧)
|
||||||
|
T_total: 100.0 # 总模拟时间(秒),程序会自动计算 NT = T_total / DT</pre>
|
||||||
|
|
||||||
|
<h3>3D 动画</h3>
|
||||||
|
<p>装好 VisPy 和 PyQt5 还能看 3D 动画:</p>
|
||||||
|
<pre><span class="tag">终端</span>pip install vispy PyQt5
|
||||||
|
py -3 draw.py examples/case01/output</pre>
|
||||||
|
<p>出现 3D 窗口后,可以用鼠标拖拽旋转视角!</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ════════════════════════════════════════════ -->
|
||||||
|
<section id="faq">
|
||||||
|
<h2><span class="emoji">❓</span> 常见问题</h2>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 报错 "pip 不是内部或外部命令"?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">试试 <code>py -3 -m pip install ...</code>。Windows 上有时需要这样用。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 为什么我改了参数但结果没变?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">检查一下 <code>force_calc: 1</code> 有没有设置。如果 <code>force_calc: 0</code>,程序会使用缓存的结果。
|
||||||
|
或者把 <code>force_calc</code> 改成 1 强制重新计算。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 总能量曲线为什么不是完全水平的?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">因为程序用了硬壁边界(小球碰到盒子壁会弹回来),这种"碰撞"会导致微小的能量损失。
|
||||||
|
这是正常的物理现象,不是 Bug。如果用软壁边界会好很多。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 为什么我的动画闪一下就没了?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">先确认装好了 <code>vispy</code> 和 <code>PyQt5</code>:<code>pip install vispy PyQt5</code>。如果还是不行,
|
||||||
|
直接在终端运行 <code>py -3 draw.py examples/case01/output</code> 看错误信息。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 为什么 C/C++/Fortran 引擎有"两个进度条"?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">之前确实有两个,但现在已经修好了!外部引擎只会显示一个 <code>tqdm</code> 进度条,
|
||||||
|
引擎自己的输出被静默收集到日志文件里了。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="step-box">
|
||||||
|
<strong>Q: 我想模拟更多的原子,怎么加?</strong>
|
||||||
|
<p style="margin:4px 0 0 20px;">在 <span class="file-path">coord.txt</span> 里增加行就可以。每行一个原子。
|
||||||
|
如果原子之间有弹簧连接,还要在 <span class="file-path">connection.txt</span> 和 <span class="file-path">bond.txt</span> 里添加对应的键。</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
Dynamics 物理模拟实验室 • 项目文档 • 适合高一同学阅读
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user