假设一个polymer 链中有N个单体.我想用bead-spring模型来模拟它的运动.然而,没有应用周期性边界条件.因为,点的生成是这样的,它们永远不会越过边界.
所以,我写了下面的程序.
我用了100万步.能量并不像预期的那样波动.走了几千步后,曲线就完全变平了.
X轴为步数.Y轴是总能量.
有人能判断一下源代码,告诉我应该修改什么吗?
注:我特别关注计算polymer 总能量的函数.
算法可能不正确.
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;
}