Exemple #1
0
def run2():

    print(os.getcwd())
    os.chdir('data')
    print(os.getcwd())
    print(dir(md))

    dt = 0.002
    ucells = 2
    sigma = 1
    N = ucells * ucells
    dens = 0.1
    nu = 0.5
    L = math.sqrt(N / dens)
    print(L)
    T = 2.0
    v0 = math.sqrt(2.0 * T)
    eps = np.array([1.0])
    rc = sigma * math.pow(2, 1.0 / 6.0)
    rcut = np.array([rc])
    shift = np.array([1.0])
    E = 200
    k = 50

    pdb.set_trace()
    box = np.array([L, L])
    md.system_init(box)
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_circle(.3)
    L, R = fm.add_clusters(md, nodes, cells, 1.0, ucells, nu, 'sc')
    box = md.system_get_box()
    print("box", box)
    md.system_set_boundary_conditions(0)
    md.system_set_velocities(v0)
    md.system_set_zero_center_of_mass_vel()
    md.system_set_dt(dt)
    md.system_set_avg_steps(100)
    md.system_set_potential(eps, rcut, shift)
    md.system_set_youngs_modulus(E)
    #md.system_set_swelling_energy_constants(100,50,0)
    #md.system_set_friction(.1)
    #md.system_set_bond_spring_constant(k)
    md.system_init_neighbor_list()
    pos = md.system_get_positions()
    vel = md.system_get_velocities()
    upos = md.system_get_unfolded_positions()
    tet = md.system_get_tetras()
    bonds = md.system_get_bonds()
    #plt.scatter(pos[:,0],pos[:,1])
    #plt.show()
    #plt.triplot(pos[:,0], pos[:,1], tet, 'go-', lw=1.0)
    bonds = md.system_get_bonds()
    refVol, currVol = md.system_get_elements_volumes()
    I1, I2 = md.system_get_elements_invariants()
    print("Volume check: ", refVol.shape[0], currVol.shape[0], np.sum(refVol),
          np.sum(currVol))
    pdb.set_trace()

    sigmas = md.system_get_particle_sizes()
    sigmas *= sigma
    R = R - 0.5 + sigma / 2

    #xyzfile = fm.Saver(0,"test_test",pos)
    #vtkfile = fm.Saver(1,"test_test",upos,vel=vel,cells=tet)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[box[0],box[1]])
    #vtffile.append(0);
    plot = Plotter.Plotter(pos, vel, tet, box[0], box[1], 'tri', I1,
                           sigma)  # 2 is the radius
    plot.update(0)
    #plt.show()

    for i in range(1000):
        md.system_run(100)
        avgs = md.system_get_avgs()
        print(avgs)
        #xyzfile.append(avgs[0])
        #vtkfile.append(avgs[0])
        #vtffile.append(avgs[0])
        #md.system_unfold_positions()
        if i % 1 == 0: plot.update(avgs[0])

    print("finished")
    plt.show()
Exemple #2
0
def run0():

    # Switch to data directory
    print(os.getcwd())
    data_dir = 'data'
    if not os.path.exists(data_dir):
        os.makedirs(data_dir)
    os.chdir(data_dir)
    print(os.getcwd())
    print(dir(md))

    # set delta t for time evolution
    dt = 0.002
    # number of cell
    ucells = 2
    # size of particles
    sigma = 1
    # total number of elastormes 4, in this case
    N = ucells*ucells
    # set the density and packing fraction, will be modified later
    # density
    dens = 0.1
    # packing fraction
    nu = 0.5
    # size of the box
    L = math.sqrt(N / dens) 
    print(L)
    # temperature and initial average velocity
    T = 2.0
    v0 = math.sqrt(2.0 * T )
    # potetial parameters
    eps=np.array([1.0])
    rc = sigma*math.pow(2,1.0/6.0)
    rcut=np.array([rc])
    shift=np.array([1.0])

    # young's modulus
    E=200

    # set the box size and initialize the system
    box = np.array([L,L])
    md.system_init(box)

    # The elastomers and structure as a mesh with nodes and cells (triangle)
    # you can read the nodes and triangles from a file or you can 
    # use the function mdmesh to produce the shape, in this example we 
    # use mdmesh, it returs the nodes and cells as an array of vector positions and
    # another array of index of vertices for triangles, the .3 controls how 
    # fine we want the mesh, lower numbers will give you more triangles
    # in this case the mesh is a disk of diameter 1
    
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_circle(.3)

    # Now that we have the basic mesh for one elastomer we will replicate it 4 times
    # in the box, we will also rescale the size of of the box and meshes so that ieach 
    # vertices contains a particle of diameter 1. Refore to function in  add cluster
    # to see how it is done
    L,R = fm.add_clusters(md,nodes,cells,1.0,ucells,nu,'sc')

    # get the new size of the box
    box = md.system_get_box()
    print("box",box)

    # set boundary conditions, 0 for hard walls in all directions
    md.system_set_boundary_conditions(0)
    # set initial velocities
    md.system_set_velocities(v0)
    # substract center of mass
    md.system_set_zero_center_of_mass_vel()
    # set delta t for the sytem
    md.system_set_dt(dt)
    # set average steps
    md.system_set_avg_steps(100)
    # set the potential, interaction between particles
    md.system_set_potential(eps,rcut,shift)
    # set the youngs modulus for elactic interaction
    md.system_set_youngs_modulus(E)

    # if we wnat to initially swell the particles , uncomment this line
    #md.system_set_swelling_energy_constants(100,50,0)
    # if we want to get rid of thermal fluctiation, uncomment this line
    #md.system_set_friction(.1)
    #if we want to simulate a system with spring interactions instead, we use
    # the line below, but we would need to set k, and set E = 0
    #md.system_set_bond_spring_constant(k)

    # initialize neighbor list
    md.system_init_neighbor_list()
    # get pointers to positions, velocities and unfolded positions
    # also get a pointer ot the array of triangles
    pos = md.system_get_positions()
    vel = md.system_get_velocities()
    upos = md.system_get_unfolded_positions()
    tet = md.system_get_tetras()
    
    # get pointers to arrays fo initial area (refVol), and 
    # current area, (currVol) of triangles
    # also, array with the invariants of the triangles

    refVol, currVol = md.system_get_elements_volumes()
    I1,I2 = md.system_get_elements_invariants()
    print("Volume check: ",refVol.shape[0], currVol.shape[0], np.sum(refVol), np.sum(currVol))
    #pdb.set_trace()

    # we rescale the particles at the vertices 
    sigmas = md.system_get_particle_sizes()
    sigmas *= sigma
    R = R - 0.5 + sigma/2

    #if we want to save the configuration, we can use the formats below
    #xyzfile = fm.Saver(0,"test_test",pos)
    #vtkfile = fm.Saver(1,"test_test",upos,vel=vel,cells=tet)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[box[0],box[1]])
    #vtffile.append(0)
    
    # lets create a plot for animation
    plot = Plotter.Plotter(pos,vel,tet,box[0],box[1],'tri',I1,sigma) # 2 is the radius
    plot.update(0)
    
    # run the simulation
    for i in range(1000):
        md.system_run(100);
        avgs = md.system_get_avgs()
        print(avgs)
        #xyzfile.append(avgs[0])
        #vtkfile.append(avgs[0])
        #vtffile.append(avgs[0])
        #md.system_unfold_positions()
        if i % 1 == 0: plot.update(avgs[0])

    print("finished")
    plt.show()
Exemple #3
0
def run2():

    print(os.getcwd())
    os.chdir('c:\\tmp\\test1')
    print(os.getcwd())
    print(dir(md))
    #md.system_c_main()

    dt = 0.005
    ucells = 2
    sigma = 1
    N = ucells * ucells
    dens = 0.1
    nu = 0.2
    L = math.sqrt(N / dens)
    print(L)
    T = 2.0
    v0 = math.sqrt(2.0 * T)
    eps = np.array([1.0])
    rc = sigma * math.pow(2, 1.0 / 6.0)
    rcut = np.array([rc])
    shift = np.array([1.0])
    E = 200
    k = 50

    md.system_init(L, L)
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_circle(.2)
    L, R = fm.add_clusters(md, nodes, cells, 1.0, ucells, nu, 'sc')
    #fm.init_particles_simple_cubic(md,ucells,L)
    Lx, Ly = md.system_get_box()
    md.system_set_boundary_conditions(0)
    md.system_set_velocities(v0)
    md.system_set_zero_center_of_mass_vel()
    md.system_set_dt(dt)
    md.system_set_avg_steps(100)
    md.system_set_potential(eps, rcut, shift)
    md.system_set_youngs_modulus(E)
    #md.system_set_swelling_energy_constants(100,50,0)
    md.system_set_friction(.1)
    #md.system_set_bond_spring_constant(k)
    md.system_init_neighbor_list()
    pos = md.system_get_positions()
    vel = md.system_get_velocities()
    #vel += 1
    upos = md.system_get_unfolded_positions()
    tet = md.system_get_tetras()
    bonds = md.system_get_bonds()

    sigmas = md.system_get_particle_sizes()
    sigmas *= sigma
    R = R - 0.5 + sigma / 2

    xyzfile = fm.Saver(0, "test_test", pos)
    vtkfile = fm.Saver(1, "test_test", upos, vel=vel, cells=tet)
    vtffile = fm.Saver(2, "test_test", upos, bonds=bonds, box=[Lx, Lx])
    vtffile.append(0)
    plot = Plotter.Plotter(pos, vel, tet, Lx, Lx, 'tripts1',
                           sigma)  # 2 is the radius
    plot.update(0)
    r = 0.01
    md.system_set_walls_moving_rate(r, r)
    #pdb.set_trace()
    for i in range(1000):
        md.system_run(100)
        avgs = md.system_get_avgs()
        print(avgs)
        xyzfile.append(avgs[0])
        vtkfile.append(avgs[0])
        vtffile.append(avgs[0])
        md.system_unfold_positions()
        if i % 10 == 0: plot.update(avgs[0])

    print("finished")
    plt.show()
Exemple #4
0
def run1():

    print(os.getcwd())
    os.chdir('c:\\tmp\\test1')
    print(os.getcwd())
    print(dir(md))

    dt = 0.002
    ucells = 2
    sigma = 2
    N = ucells * ucells
    dens = 0.2
    #nu = 0.5
    nu = 0.3
    dens = nu / np.pi
    L = math.sqrt(N / dens)
    print(L)
    T = 1
    #v0 = math.sqrt(2.0 * T * (1.0-1.0/N))
    v0 = math.sqrt(2.0 * T)
    eps = np.array([1.0])
    rc = sigma * math.pow(2, 1.0 / 6.0)
    rcut = np.array([rc])
    shift = np.array([1.0])
    E = 200
    k = 200

    pdb.set_trace()
    box = np.array([L, L])
    md.system_init(box)
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_circle(.15)
    #L,R = fm.add_clusters(md,nodes,cells,1.0,ucells,nu,'sc1')
    L, R = fm.add_binary_clusters(md, nodes, cells, 1.0, 1.0, .15, ucells, nu,
                                  'sc')
    box = md.system_get_box()
    md.system_set_boundary_conditions(0)
    md.system_set_moving_walls(0)
    md.system_set_velocities(v0)
    md.system_set_zero_center_of_mass_vel()
    md.system_set_dt(dt)
    md.system_set_avg_steps(100)
    md.system_set_potential(eps, rcut, shift)
    md.system_set_youngs_modulus(E)
    #md.system_set_swelling_energy_constants(100,250,0.0)
    md.system_set_friction(.1)
    #md.system_set_bond_spring_constant(k)
    md.system_init_neighbor_list()
    pos = md.system_get_positions()
    vel = md.system_get_velocities()
    upos = md.system_get_unfolded_positions()
    tet = md.system_get_tetras()

    #plt.scatter(pos[:,0],pos[:,1])
    #plt.show()
    #plt.triplot(pos[:,0], pos[:,1], tet, 'go-', lw=1.0)
    bonds = md.system_get_bonds()
    refVol, currVol = md.system_get_elements_volumes()
    I1, I2 = md.system_get_elements_invariants()
    print("Volume check: ", refVol.shape[0], currVol.shape[0], np.sum(refVol),
          np.sum(currVol))

    sigmas = md.system_get_particle_sizes()
    sigmas *= sigma
    R = R - 0.5 + sigma / 2
    n1 = 0.79
    L1 = np.sqrt(ucells**2 * np.pi * R**2 / n1)
    nf = 0.95
    Lf = np.sqrt(ucells**2 * np.pi * R**2 / nf)
    print(L, Lf, R)

    pdb.set_trace()
    #xyzfile = fm.Saver(0,"test_test",pos)
    vtkfile = fm.Saver(1, "test_test", pos, vel=vel, cells=tet, I2=I2)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[Lx,Lx])
    vtkfile.append(0)
    walls = md.system_get_walls_pos()
    print("walls", walls)
    walls = [walls[0][0], walls[1][0], walls[0][1], walls[1][1]]
    print("walls", walls)
    plot = Plotter.Plotter(pos, vel, tet, box[0], box[1], 'tripts1', I1,
                           sigma)  # 2 is the radius
    plot.update(0, walls, "")
    #plt.show()
    r = Lf / 800
    r00 = np.array([1.01 * r, r])
    r10 = np.array([-1.01 * r, r])
    r0 = np.array([r, r])
    r1 = np.array([-r, -r])
    r02 = np.array([-r, r])
    r12 = np.array([r, -r])
    r_stop = np.array([0, 0])
    data = []
    totRefVol = np.sum(refVol)
    totCurrVol = np.sum(currVol)
    md.system_set_moving_walls(0)
    md.system_set_walls_moving_rate(r0, r1)
    pdb.set_trace()
    shear = 0

    Ws = 0
    for Ws in np.arange(0, 0, 100):
        md.system_run(100)
        avgs = md.system_get_avgs()
        print("\nstep %d" % avgs[0])
        print(avgs)
        title = "steps = %d" % (avgs[0])
        #if Ws % 10 == 0:
        #Ws += 10
        md.system_set_swelling_energy_constants(100, Ws, 0.0)
        plot.update(avgs[0], walls, title)
        #vtkfile.append(avgs[0])

    md.system_set_friction(1)
    md.system_set_moving_walls(1)
    md.system_set_walls_moving_rate(r0, r1)
    for i in range(10000):
        md.system_run(100)
        avgs = md.system_get_avgs()
        walls = md.system_get_walls_pos()
        walls = [walls[0][0], walls[1][0], walls[0][1], walls[1][1]]
        print("\nstep %d" % avgs[0])
        print("walls", walls)
        Lx = walls[1] - walls[0]
        Ly = walls[3] - walls[2]
        print("Box Vol = ", Lx * Ly)

        if i == 20:
            md.system_set_walls_moving_rate(r00, r10)
        if Ly / Lx > 1.1 and shear == 0:
            md.system_set_walls_moving_rate(r0, r1)
        if totCurrVol / totRefVol < 1.5 and i > 20:
            shear = 1
        if shear == 1:
            c = Lx / Ly
            r02 = np.array([-c * r, r])
            r12 = np.array([c * r, -r])
            md.system_set_walls_moving_rate(r02, r12)
            #md.system_set_walls_shear(1)
        if Lx > L:
            md.system_set_walls_moving_rate(r_stop, r_stop)

        md.system_unfold_positions()
        #xyzfile.append(avgs[0])
        vtkfile.append(avgs[0])
        #vtffile.append(avgs[0])
        #if i % 1 == 0:
        print(avgs)
        wf = md.system_get_walls_forces()
        #return Py_BuildValue("((dd)(dd))", f[0][0], f[0][1], f[1][0], f[1][1]);
        wf = [wf[0][0], wf[0][1], wf[1][0], wf[1][1]]
        print("force on walls :", wf)
        totCurrVol = np.sum(currVol)
        data.append([
            dt * avgs[0], wf[0], wf[1], wf[2], wf[3], totCurrVol / totRefVol,
            avgs[5]
        ])
        print("Volumes: ", totRefVol, totCurrVol, totCurrVol / totRefVol * 100)
        print("I1 max", I1.max())

        title = "steps = %d Lini = %f Lx = %f Ly = %f nu = %f V/Vref= %f" % (
            avgs[0], L, Lx, Ly, ucells**2 * np.pi * R**2 /
            (Lx * Ly), totCurrVol / totRefVol)
        if i % 10 == 0:
            plot.update(avgs[0], walls, title)
            wf = np.array(data)
            np.savetxt("data.dat", wf)
            vtkfile.append(avgs[0])

    wf = np.array(data)
    np.savetxt("data.dat", wf)
    print("finished")
    plt.show()
Exemple #5
0
def run1():

    print(os.getcwd())
    os.chdir('c:\\tmp\\test1')
    print(os.getcwd())
    print(dir(md))
    #md.system_c_main()

    dt = 0.005
    ucells = 2
    sigma = 2
    N = ucells * ucells
    dens = 0.1
    nu = 0.2
    dens = nu / np.pi
    L = math.sqrt(N / dens)
    print(L)
    T = 1.1
    #v0 = math.sqrt(2.0 * T * (1.0-1.0/N))
    v0 = math.sqrt(2.0 * T)
    eps = np.array([1.0])
    rc = sigma * math.pow(2, 1.0 / 6.0)
    rcut = np.array([rc])
    shift = np.array([1.0])
    E = 200
    k = 200

    md.system_init(L, L)
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_circle(.1)
    L, R = fm.add_clusters(md, nodes, cells, 1.0, ucells, nu, 'sc1')
    #init_particles_simple_cubic(ucells,L)
    Lx, Ly = md.system_get_box()
    md.system_set_boundary_conditions(0)
    md.system_set_velocities(v0)
    md.system_set_zero_center_of_mass_vel()
    md.system_set_dt(dt)
    md.system_set_avg_steps(100)
    md.system_set_potential(eps, rcut, shift)
    md.system_set_youngs_modulus(E)
    md.system_set_swelling_energy_constants(100, 50, 0)
    md.system_set_friction(1)
    #md.system_set_bond_spring_constant(k)
    md.system_init_neighbor_list()
    pos = md.system_get_positions()
    vel = md.system_get_velocities()
    #vel += 1
    upos = md.system_get_unfolded_positions()
    tet = md.system_get_tetras()
    bonds = md.system_get_bonds()
    refVol, currVol = md.system_get_elements_volumes()

    sigmas = md.system_get_particle_sizes()
    sigmas *= sigma
    R = R - 0.5 + sigma / 2
    n1 = 0.79
    L1 = np.sqrt(ucells**2 * np.pi * R**2 / n1)
    nf = 0.95
    Lf = np.sqrt(ucells**2 * np.pi * R**2 / nf)
    print(L, Lf, R)

    #xyzfile = fm.Saver(0,"test_test",pos)
    vtkfile = fm.Saver(1, "test_test", upos, vel=vel, cells=tet)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[Lx,Lx])
    #vtffile.append(0);
    plot = Plotter.Plotter(pos, vel, tet, Lx, Lx, 'tripts1',
                           sigma)  # 2 is the radius
    plot.update(0)
    r = Lf / 800
    md.system_set_walls_moving_rate(0, 0)
    data = []
    totRefVol = np.sum(refVol)
    md.system_set_walls_moving_rate(r, r)
    for i in range(10):
        md.system_run(100)
        avgs = md.system_get_avgs()
        walls = md.system_get_walls_pos()
        #print(walls)
        Lx = walls[1] - walls[0]
        Ly = walls[3] - walls[2]
        #if i == 20:
        #    md.system_set_walls_moving_rate(r,r)
        if Ly < L1 and Ly > Lf:
            md.system_set_walls_moving_rate(-r, r)
        if Lx > L:
            md.system_set_walls_moving_rate(0.0, 0.0)
        md.system_unfold_positions()
        #xyzfile.append(avgs[0])
        #vtkfile.append(avgs[0])
        #vtffile.append(avgs[0])
        #if i % 1 == 0:
        print(avgs)
        wf = md.system_get_walls_forces()
        print("force on walls :", wf)
        data.append([dt * avgs[0], wf[0], wf[1], wf[2], wf[3]])
        totCurrVol = np.sum(currVol)
        print("Volumes: ", totRefVol, totCurrVol, totCurrVol / totRefVol * 100)

        title = "steps = %d Lini = %f Lx = %f Ly = %f nu = %f" % (
            avgs[0], L, Lx, Ly, ucells**2 * np.pi * R**2 / (Lx * Ly))
        if i % 1 == 0: plot.update(avgs[0], walls, title)

    wf = np.array(data)
    np.savetxt("data.dat", wf)
    print("finished")