Пример #1
0
def test_computeForces():
    """"""
    box = md.Box(0., 0., 5. * md.hcp.uc_centered_a, 0.5 * md.hcp.uc_centered_b)
    atoms = md.MD(box, cutoff=2.5)
    if __plot:
        cmn.figure()
        cmn.plotBox(box)
        cmn.plotAtoms(atoms.x, atoms.y, radius=atoms.radius)
        cmn.plt.show()
    atoms.buildVerletLists()
    print(atoms.vl)
    cpp.computeForces(
        atoms.x,
        atoms.y  # atom positions
        ,
        atoms.vl.vl_size,
        atoms.vl.vl_list  # linearized verlet list data structure
        ,
        atoms.ax,
        atoms.ay  # atom forces
    )
    print(f'ax={atoms.ax}')
    print(f'ay={atoms.ay}')
    r = md.hcp.uc_centered_a
    r01sq = r**2
    r02sq = (2 * r)**2
    fx01 = lj.force_factor(r01sq) * r
    fx02 = lj.force_factor(r02sq) * 2 * r
    expected = np.array([fx01, fx01, fx01, fx01, 0.00]) \
             + np.array([fx02, fx02, fx02, 0.00, 0.00]) \
             - np.array([0.00, fx01, fx01, fx01, fx01]) \
             - np.array([0.00, 0.00, fx02, fx02, fx02])
    assert np.all(atoms.ax == expected)
    assert np.all(atoms.ay == np.zeros((atoms.n_atoms, ), dtype=float))
Пример #2
0
def test_MDCtor():
    box = md.Box(0., 0., 5. * md.hcp.uc_centered_a, 3. * md.hcp.uc_centered_b)
    atoms = md.MD(box)
    cmn.figure()
    cmn.plotBox(box)
    cmn.plotAtoms(atoms.x, atoms.y, radius=atoms.radius)
    if __plot:
        cmn.plt.show()
Пример #3
0
def test_computeEnergy():
    """"""
    box = md.Box(0., 0., 5. * md.hcp.uc_centered_a, 0.5 * md.hcp.uc_centered_b)
    atoms = md.MD(box, cutoff=2.5)
    if __plot:
        cmn.figure()
        cmn.plotBox(box)
        cmn.plotAtoms(atoms.x, atoms.y, radius=atoms.radius)
        cmn.plt.show()
    atoms.buildVerletLists()
    print(atoms.vl)
    energy = atoms.computeEnergy()
    r01sq = md.hcp.uc_centered_a**2
    r02sq = (2 * md.hcp.uc_centered_a)**2
    expected = 4 * lj.potential(r01sq) + 3 * lj.potential(r02sq)
    print(energy)
    print(expected)
    assert energy == expected
Пример #4
0
def test_computeForces():
    """"""
    box = md.Box(0., 0., 5. * md.hcp.uc_centered_a, 0.5 * md.hcp.uc_centered_b)
    atoms = md.MD(box, cutoff=2.5)
    if __plot:
        cmn.figure()
        cmn.plotBox(box)
        cmn.plotAtoms(atoms.x, atoms.y, radius=atoms.radius)
        cmn.plt.show()
    atoms.buildVerletLists()
    print(atoms.vl)
    energy = atoms.computeForces()
    r = md.hcp.uc_centered_a
    r01sq = r**2
    r02sq = (2 * r)**2
    fx01 = lj.force_factor(r01sq) * r
    fx02 = lj.force_factor(r02sq) * 2 * r
    expected = np.array([fx01, fx01, fx01, fx01, 0.00]) \
             + np.array([fx02, fx02, fx02, 0.00, 0.00]) \
             - np.array([0.00, fx01, fx01, fx01, fx01]) \
             - np.array([0.00, 0.00, fx02, fx02, fx02])
    assert np.all(atoms.ax == expected)
    print(atoms.ay)
    assert np.all(atoms.ay == np.zeros((atoms.n_atoms, ), dtype=float))