首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >周期分子动力学模拟中实现Velocity Verlet算法时的失控速度

周期分子动力学模拟中实现Velocity Verlet算法时的失控速度
EN

Stack Overflow用户
提问于 2012-04-24 18:14:19
回答 1查看 955关注 0票数 2

我正在尝试写一个分子动力学模拟的lennard-jones流体在二维箱中,无论是周期边界条件还是反射边界条件。模拟似乎在反射边界下运行得很好,但由于某些原因,周期框中的粒子在几百个积分步骤后开始获得额外的速度,最终没有粒子留在框中。

我知道速度失控可能是由于设置的时间步长太小造成的。然而,当我使用相同的速度-verlet算法运行模拟时,我看不出这可能是速度失控的原因,特别是在反射边界工作得如此好的情况下。我认为在两种情况下,用来评估粒子上的力或粒子分离的方法可能是错误的,但我自己找不到。

我用来计算力的代码如下所示:

代码语言:javascript
复制
public static Vector3d LJForce(Particle3d a, Particle3d b,
        Vector3d particleSep) {

    //Define R (for simplicity)
    Vector3d R = particleSep; //(b-a)

    return new Vector3d(Vector3d.multVector3d(
            -24*EPSILON*(2*power12(SIGMA/R.getMag())/R.getMag()
                    -power6(SIGMA/R.getMag())/R.getMag()), R));
}

这应该给出作用在每个粒子上的lennard-jones力。颗粒的分离取决于边界条件。对于反射,它是:

代码语言:javascript
复制
@Override
public Vector3d getParticleSeparation(Particle3d a, Particle3d b) {
    return Particle3d.sepParticle3d(a, b);
}

它与一起使用

代码语言:javascript
复制
@Override
public void checkBoundaries(Particle3d a)   {
    Vector3d position = a.getPosition();
    Vector3d velocity = a.getVelocity();

    /*
     * We want to check the x,y and z coordinates. If
     * they break the boundaries we need to reflect 
     * the position in that coordinate and invert the
     * velocity in that axis.
     */
    //X coordinate
    if(position.getX()<0.0) {
        position.setX(Math.abs(position.getX()));
        velocity.setX(-velocity.getX());    
    }
    else if(position.getX()>getWidth()) {
        double howFar = position.getX()-getWidth();
        position.setX(getWidth()-howFar);
        velocity.setX(-velocity.getX());
    }   
    else    {}
    //Y coordinate
    if(position.getY()<0.0) {
        position.setY(Math.abs(position.getY()));
        velocity.setY(-velocity.getY());    
    }
    else if(position.getY()>getWidth()) {
        double howFar = position.getY()-getWidth();
        position.setY(getWidth()-howFar);
        velocity.setY(-velocity.getY());
    }   
    else    {}
    //Z coordinate
    if(position.getZ()<0.0) {
        position.setZ(Math.abs(position.getZ()));
        velocity.setZ(-velocity.getZ());    
    }
    else if(position.getZ()>getWidth()) {
        double howFar = position.getZ()-getWidth();
        position.setZ(getWidth()-howFar);
        velocity.setZ(-velocity.getZ());
    }   
    else    {}

    a.setPosition(position);
    a.setVelocity(velocity);
}//End checkBoundaries(i)

将粒子保留在盒子中。另一方面,对于周期性的.

代码语言:javascript
复制
@Override
public Vector3d getParticleSeparation(Particle3d a,Particle3d b) {
    Vector3d sep = Particle3d.sepParticle3d(a, b);
    if(sep.getX()>=(double)getWidth()/2)    {
        sep.setX(sep.getX()-getWidth());
    }   else{}
    if(sep.getY()>=(double)getWidth()/2)    {
        sep.setY(sep.getY()-getWidth());
    }   else{}
    if(sep.getZ()>=(double)getWidth()/2)    {
        sep.setZ(sep.getZ()-getWidth());
    }   else{}

    return sep;
}

给出了粒子分离和

代码语言:javascript
复制
@Override
public void checkBoundaries(Particle3d a) {
    Vector3d position = new Vector3d();

    position.setX((getWidth()+a.getPosition().getX())%getWidth());
    position.setY((getWidth()+a.getPosition().getY())%getWidth());
    position.setZ((getWidth()+a.getPosition().getZ())%getWidth());

    a.setPosition(position);
}

检查边界。这两个分离方法都调用

代码语言:javascript
复制
//Relative seperation
public static Vector3d sepParticle3d( Particle3d a, Particle3d b) {
    return new Vector3d(Vector3d.subVector3d(b.getPosition(),a.getPosition()));
}

这就是两个粒子在笛卡尔空间中的矢量分离。我的代码中是否有错误,或者是其他一些原因导致我的模拟在周期性边界条件下崩溃了?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-06 21:47:10

也许你已经弄明白了,但我认为错误存在于周期边界的checkBoundaries代码中。我可能错了,但我认为你不能在浮点数/双精度数上使用%运算符。我认为代码应该是(参见https://en.wikipedia.org/wiki/Periodic_boundary_conditions )

代码语言:javascript
复制
Vector3d op = a.getPosition(); //old position
double w = getWidth();
position.setX( op.getX() - w*((int)(2*op.getX()-1)) );
position.setX( op.getY() - w*((int)(2*op.getY()-1)) );
position.setX( op.getZ() - w*((int)(2*op.getZ()-1)) );
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10295913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档