Beispiel #1
0
def get_interaction_end_points(int_snapshot,
                               par_snapshot,
                               int_cols,
                               par_cols):
    """
        For each interaction in f, get the position of the particles involved.
        Positions of every particle given in p. Return is NOT periodized.

        Returns an array containing x1,y1,z1,x2,y2,z2 for each interaction.
    """
    p1_idx = du.matching_uniq(int_cols, ['label', '1'])[1]
    p2_idx = du.matching_uniq(int_cols, ['label', '2'])[1]
    try:
        pos_idx = du.matching_uniq(par_cols, 'position')[1]
    except Exception:
        pos_idx = slice(du.matching_uniq(par_cols, ['position', 'x'])[1],
                        du.matching_uniq(par_cols, ['position', 'z'])[1]+1)
    # for each interaction: the particle indices
    part1 = int_snapshot[:, p1_idx].astype(np.int)
    part2 = int_snapshot[:, p2_idx].astype(np.int)

    # for each interaction: the particle positions
    r1 = par_snapshot[part1, pos_idx].astype(np.float)
    r2 = par_snapshot[part2, pos_idx].astype(np.float)

    return np.hstack((r1, r2))
Beispiel #2
0
def get_interaction_end_points(int_snapshot, par_snapshot, int_cols, par_cols):
    """
        For each interaction in f, get the position of the particles involved.
        Positions of every particle given in p. Return is NOT periodized.

        Returns an array containing x1,y1,z1,x2,y2,z2 for each interaction.
    """
    p1_idx = du.matching_uniq(int_cols, ['label', '1'])[1]
    p2_idx = du.matching_uniq(int_cols, ['label', '2'])[1]
    try:
        pos_idx = du.matching_uniq(par_cols, 'position')[1]
    except Exception:
        pos_idx = slice(
            du.matching_uniq(par_cols, ['position', 'x'])[1],
            du.matching_uniq(par_cols, ['position', 'z'])[1] + 1)
    # for each interaction: the particle indices
    part1 = int_snapshot[:, p1_idx].astype(np.int)
    part2 = int_snapshot[:, p2_idx].astype(np.int)

    # for each interaction: the particle positions
    r1 = par_snapshot[part1, pos_idx].astype(np.float)
    r2 = par_snapshot[part2, pos_idx].astype(np.float)

    return np.hstack((r1, r2))
Beispiel #3
0
def interactions_bonds_yaparray(int_snapshot,
                                par_snapshot,
                                icols,
                                pcols,
                                f_factor=None,
                                f_chain_thresh=None,
                                layer_contacts=1,
                                layer_noncontacts=2,
                                color_contacts=1,
                                color_noncontacts=2):
    if f_chain_thresh is None:
        f_chain_thresh = 0

    r1r2 = lfu.get_interaction_end_points(int_snapshot, par_snapshot,
                                          icols, pcols)
    f, r1r2 = filter_interactions_crossing_PBC(int_snapshot, r1r2)

    # display a line joining the center of interacting particles
    # with a thickness proportional to the normal force
    normal_forces = get_normal_force(f, icols)
    #  convert the force to a thickness. case-by-case.
    if f_factor is None:
        f_factor = 0.5/np.max(np.abs(normal_forces))
    normal_forces = f_factor*np.abs(normal_forces)
    avg_force = np.mean(np.abs(normal_forces))
    large_forces = normal_forces > f_chain_thresh * avg_force

    contact_state = f[:, du.matching_uniq(icols, 'contact state')[1]]

    # contacts
    keep = np.logical_and(contact_state > 0, large_forces)
    yap_out = pyp.layer_switch(layer_contacts)
    yap_out = pyp.add_color_switch(yap_out, color_contacts)
    contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep])
    yap_out = np.row_stack((yap_out, contact_bonds))

    # non contacts
    keep = np.logical_and(contact_state == 0, large_forces)
    yap_out = pyp.add_layer_switch(yap_out, layer_noncontacts)
    yap_out = pyp.add_color_switch(yap_out, color_noncontacts)
    non_contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep])
    yap_out = np.row_stack((yap_out, non_contact_bonds))

    return yap_out, f_factor
Beispiel #4
0
def interactions_bonds_yaparray(int_snapshot,
                                par_snapshot,
                                icols,
                                pcols,
                                f_factor=None,
                                f_chain_thresh=None,
                                layer_contacts=1,
                                layer_noncontacts=2,
                                color_contacts=1,
                                color_noncontacts=2):
    if f_chain_thresh is None:
        f_chain_thresh = 0

    r1r2 = lfu.get_interaction_end_points(int_snapshot, par_snapshot, icols,
                                          pcols)
    f, r1r2 = filter_interactions_crossing_PBC(int_snapshot, r1r2)

    # display a line joining the center of interacting particles
    # with a thickness proportional to the normal force
    normal_forces = get_normal_force(f, icols)
    #  convert the force to a thickness. case-by-case.
    if f_factor is None:
        f_factor = 0.5 / np.max(np.abs(normal_forces))
    normal_forces = f_factor * np.abs(normal_forces)
    avg_force = np.mean(np.abs(normal_forces))
    large_forces = normal_forces > f_chain_thresh * avg_force

    contact_state = f[:, du.matching_uniq(icols, 'contact state')[1]]

    # contacts
    keep = np.logical_and(contact_state > 0, large_forces)
    yap_out = pyp.layer_switch(layer_contacts)
    yap_out = pyp.add_color_switch(yap_out, color_contacts)
    contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep])
    yap_out = np.row_stack((yap_out, contact_bonds))

    # non contacts
    keep = np.logical_and(contact_state == 0, large_forces)
    yap_out = pyp.add_layer_switch(yap_out, layer_noncontacts)
    yap_out = pyp.add_color_switch(yap_out, color_noncontacts)
    non_contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep])
    yap_out = np.row_stack((yap_out, non_contact_bonds))

    return yap_out, f_factor
Beispiel #5
0
def snaps2yap(pos_fname,
              yap_file,
              f_factor=None,
              f_chain_thresh=None):

    forces_fname = pos_fname.replace("par_", "int_")
    par_f = clff.snapshot_file(pos_fname)
    int_f = clff.snapshot_file(forces_fname)


    pcols = par_f.column_def()
    icols = int_f.column_def()

    is2d = float(par_f.meta_data()['Ly']) == 0
    i = 0
    for frame_par, frame_int in zip(par_f, int_f):
        yap_out, f_factor =\
            interactions_bonds_yaparray(frame_int[1], frame_par[1],
                                        icols, pcols,
                                        f_factor=f_factor,
                                        f_chain_thresh=f_chain_thresh,
                                        layer_contacts=1,
                                        layer_noncontacts=2,
                                        color_contacts=4,
                                        color_noncontacts=5)

        # display a circle for every particle
        yap_out = pyp.add_layer_switch(yap_out, 3)
        yap_out = pyp.add_color_switch(yap_out, 3)

        if 'position (x, y, z)' in pcols:
            pos_slice = pcols['position (x, y, z)']
        else:
            pos_slice = slice(pcols['position x'], pcols['position z']+1)
        pos = frame_par[1][:, pos_slice].astype(np.float)
        rad = frame_par[1][:, pcols['radius']].astype(np.float)
        if is2d:
            angle = frame_par[1][:, pcols['angle']].astype(np.float)
            particles, crosses = particles_yaparray(pos, rad, angles=angle)
            yap_out = np.row_stack((yap_out, particles))
            yap_out = pyp.add_color_switch(yap_out, 1)
            yap_out = np.row_stack((yap_out, crosses))
        else:
            yap_out = np.row_stack((yap_out, particles_yaparray(pos, rad)))

        # display bounding box
        yap_out = pyp.add_layer_switch(yap_out, 4)
        yap_out = pyp.add_color_switch(yap_out, 0)
        lx2 = float(par_f.meta_data()['Lx'])/2
        ly2 = float(par_f.meta_data()['Ly'])/2
        lz2 = float(par_f.meta_data()['Lz'])/2
        if not is2d:
            yap_out = pyp.add_cmd(yap_out, 'l', cuboid(lx2, ly2, lz2))
        else:
            yap_out = pyp.add_cmd(yap_out, 'l', rectangle(lx2, lz2))

        # display strain
        yap_out = pyp.add_layer_switch(yap_out, 5)
        yap_out = pyp.add_color_switch(yap_out, 1)
        # *cu*rvilinear or *cu*mulated strain depending on LF_DEM version
        strain = du.matching_uniq(frame_par[0], ["cu".encode('utf8'), "strain".encode('utf8')])
        yap_out = np.row_stack((yap_out,
                                ['t', str(10.), str(0.), str(10.),
                                    'strain='+str(strain), '', '']))

        # output
        np.savetxt(yap_file, yap_out, fmt="%s "*7)
        yap_file.write("\n".encode('utf-8'))
        i += 1
        out_str = "\r frame " + str(i) +\
                  " - " + yap_filename + \
                  "   [force factor " + str(f_factor) + "]"
        try:
            print(out_str, end="", flush=True)
        except TypeError:
            # to work with Python 2.7.* importing print_function without flush
            print(out_str, end="")
    print("")
Beispiel #6
0
def snaps2yap(pos_fname, yap_file, f_factor=None, f_chain_thresh=None):

    forces_fname = pos_fname.replace("par_", "int_")
    par_f = clff.snapshot_file(pos_fname)
    int_f = clff.snapshot_file(forces_fname)

    pcols = par_f.column_def()
    icols = int_f.column_def()

    is2d = float(par_f.meta_data()['Ly']) == 0
    i = 0
    for frame_par, frame_int in zip(par_f, int_f):
        yap_out, f_factor =\
            interactions_bonds_yaparray(frame_int[1], frame_par[1],
                                        icols, pcols,
                                        f_factor=f_factor,
                                        f_chain_thresh=f_chain_thresh,
                                        layer_contacts=1,
                                        layer_noncontacts=2,
                                        color_contacts=4,
                                        color_noncontacts=5)

        # display a circle for every particle
        yap_out = pyp.add_layer_switch(yap_out, 3)
        yap_out = pyp.add_color_switch(yap_out, 3)

        if 'position (x, y, z)' in pcols:
            pos_slice = pcols['position (x, y, z)']
        else:
            pos_slice = slice(pcols['position x'], pcols['position z'] + 1)
        pos = frame_par[1][:, pos_slice].astype(np.float)
        rad = frame_par[1][:, pcols['radius']].astype(np.float)
        if is2d:
            angle = frame_par[1][:, pcols['angle']].astype(np.float)
            particles, crosses = particles_yaparray(pos, rad, angles=angle)
            yap_out = np.row_stack((yap_out, particles))
            yap_out = pyp.add_color_switch(yap_out, 1)
            yap_out = np.row_stack((yap_out, crosses))
        else:
            yap_out = np.row_stack((yap_out, particles_yaparray(pos, rad)))

        # display bounding box
        yap_out = pyp.add_layer_switch(yap_out, 4)
        yap_out = pyp.add_color_switch(yap_out, 0)
        lx2 = float(par_f.meta_data()['Lx']) / 2
        ly2 = float(par_f.meta_data()['Ly']) / 2
        lz2 = float(par_f.meta_data()['Lz']) / 2
        if not is2d:
            yap_out = pyp.add_cmd(yap_out, 'l', cuboid(lx2, ly2, lz2))
        else:
            yap_out = pyp.add_cmd(yap_out, 'l', rectangle(lx2, lz2))

        # display strain
        yap_out = pyp.add_layer_switch(yap_out, 5)
        yap_out = pyp.add_color_switch(yap_out, 1)
        # *cu*rvilinear or *cu*mulated strain depending on LF_DEM version
        strain = du.matching_uniq(
            frame_par[0], ["cu".encode('utf8'), "strain".encode('utf8')])
        yap_out = np.row_stack((yap_out, [
            't',
            str(10.),
            str(0.),
            str(10.), 'strain=' + str(strain), '', ''
        ]))

        # output
        np.savetxt(yap_file, yap_out, fmt="%s " * 7)
        yap_file.write("\n".encode('utf-8'))
        i += 1
        out_str = "\r frame " + str(i) +\
                  " - " + yap_filename + \
                  "   [force factor " + str(f_factor) + "]"
        try:
            print(out_str, end="", flush=True)
        except TypeError:
            # to work with Python 2.7.* importing print_function without flush
            print(out_str, end="")
    print("")