分子MC模拟不平衡
假设聚合物在其链中具有 n 单体。我想使用 Bead-Spring 模型来模拟其运动。但是,没有应用周期性的边界条件。 COZ,生成点,使它们永远不会越过边界。
因此,我写了以下程序。
我正在使用100万步。能量不会像预期的那样波动。几千步后,曲线完全平坦。
Y轴是总能量。
谁能检查源代码并告诉我我应该更改什么?
NB我特别关注计算聚合物总能量的功能。
大概,该算法不正确。
public double GetTotalPotential()
{
double totalBeadPotential = 0.0;
double totalSpringPotential = 0.0;
// calculate total bead-energy
for (int i = 0; i < beadsList.Count; i++)
{
Bead item_i = beadsList[i];
Bead item_i_plus_1 = null;
try
{
item_i_plus_1 = beadsList[i + 1];
if (i != beadsList.Count - 1)
{
// calculate total spring energy.
totalSpringPotential += item_i.GetHarmonicPotential(item_i_plus_1);
}
}
catch { }
for (int j = 0; j < beadsList.Count; j++)
{
if (i != j)
{
Bead item_j = beadsList[j];
totalBeadPotential += item_i.GetPairPotential(item_j);
//Console.Write(totalBeadPotential + "\n");
//Thread.Sleep(100);
}
}
}
return totalBeadPotential + totalSpringPotential;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此应用程序的问题是,模拟(
simulation.simulatemotion
)在单独的线程中与draw Timer并行运行(simulationguiform.timer.timer1_tick
),并共享相同的状态(polymerchain
)无需任何同步/信号,因此polymerchain
的某些突变被完全跳过(未绘制),并且仿真完成(远前绘制绘制之前)timer1_tick
将重新绘制相同的Polymerchain
。您可以通过对simulation
添加计数器并在simulateMotion
中增加情况来轻松地检查,并在
timer1_tick
中进行检查:您需要重写应用程序
,就像我在 pull request 或仅执行动作的操作当渲染当前状态时。
simulateMotion
在某些集合中存储迭代,该集合被timer1_tick
消费(例如,基本上实现生产者 - 消费者模式,例如,您可以尝试使用blockingcollection
Problem of this application is that simulations (
Simulation.SimulateMotion
) are run in separate thread in parallel to the draw timer (SimulationGuiForm.timer1_Tick
) and share the same state (polymerChain
) without any sync/signaling, so some mutations ofpolymerChain
are skipped completely (not drawn) and when the simulation is finished (far before the finish of the drawing) thetimer1_Tick
will redraw the samepolymerChain
. You can easily check that by adding counter toSimulation
and increasing it in theSimulateMotion
:And checking it in
timer1_Tick
:You need to rewrite your application in such way that
SimulateMotion
either stores iterations in some collection which is consumed bytimer1_Tick
(basically implementing producer-consumer pattern, for example you can try usingBlockingCollection
, like I do in the pull request) or performs it's actions only when the current state is rendered.