Exemplo n.º 1
0
def test_build_3():
    """Verify VerletList.build_grid against VerletList.build_simple."""
    cutoff = 5.0
    max_neighbours = 100
    n_squares = 3
    box = et_ppmd.Box(0., 0., n_squares * 5. * et_ppmd.hcp.uc_centered_a,
                      n_squares * 3. * et_ppmd.hcp.uc_centered_b)
    x, y = box.generateAtoms(r=et_ppmd.hcp.radius)

    # compute grid
    the_grid = grid.Grid(cell_size=cutoff,
                         wx=box.xur - box.xll,
                         wy=box.yur - box.yll,
                         max_atoms_per_cell=100)
    the_grid.build(x, y)

    # build grid-based verlet list
    vl = verlet.VerletList(cutoff=cutoff, max_neighbours=max_neighbours)
    vl.build_grid(x, y, the_grid)
    print(vl)
    pairs = vl2set(vl)

    vlsimple = verlet.VerletList(cutoff=cutoff, max_neighbours=max_neighbours)
    vlsimple.build_simple(x, y)
    print(vlsimple)
    expected = vl2set(vlsimple)
    assert pairs == expected
Exemplo n.º 2
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))
Exemplo n.º 3
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()
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_build_2():
    """Verify VerletList.build against VerletList.build_simple."""
    cutoff = 5.0
    max_neighbours = 50
    n_squares = 3
    box = et_ppmd.Box(0., 0., n_squares * 5. * et_ppmd.hcp.uc_centered_a,
                      n_squares * 3. * et_ppmd.hcp.uc_centered_b)
    x, y = box.generateAtoms(r=et_ppmd.hcp.radius)
    vl = verlet.VerletList(cutoff=cutoff, max_neighbours=max_neighbours)
    vl.build(x, y)
    print(vl)
    pairs = vl2set(vl)

    vlsimple = verlet.VerletList(cutoff=cutoff, max_neighbours=max_neighbours)
    vlsimple.build_simple(x, y)
    print(vlsimple)
    expected = vl2set(vlsimple)
    assert pairs == expected
Exemplo n.º 6
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))
Exemplo n.º 7
0
from et_stopwatch import Stopwatch

import matplotlib.pyplot as plt

if __name__ == '__main__':
    cutoff = 5.0
    max_neighbours = 60

    # some lists to store our results
    n_at = []  # number of atoms
    t_bs = []  # timings for VerletList.build_simple
    t_b = []  # timings for VerletList.build
    t_bg = []  # timings for VerletList.build_grid
    for n_squares in range(1, 16):
        # a single square contains on average 30 atoms ( 6 rows of each 5 atoms)
        box = et_ppmd.Box(0., 0., n_squares * 5. * et_ppmd.hcp.uc_centered_a,
                          n_squares * 3. * et_ppmd.hcp.uc_centered_b)
        x, y = box.generateAtoms(r=et_ppmd.hcp.radius)
        n_atoms = len(x)
        # store n_atoms in the result array
        n_at.append(n_atoms)
        vl = verlet.VerletList(cutoff=cutoff, max_neighbours=max_neighbours)
        # time building the Verlet list
        with Stopwatch(message=f"VerletList.build_simple for {n_atoms} atoms"
                       ) as sw_build_simple:
            vl.build_simple(x, y)

        # store the timing in the result array
        t_bs.append(sw_build_simple.time)

        # time building the Verlet list
        with Stopwatch(