Beispiel #1
0
def test():
    print(os.getcwd())
    os.chdir('c:\\tmp\\test1')
    print(os.getcwd())
    print(dir(md))
    L = np.array([1.0, 2.0])
    md.system_init(L)
    p = md.system_get_walls_pos()
    print(p[0][0], p[1][1])
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
0
def run0():

    #Create a data directory for all data produced by the program
    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))

    # define some variables
    # delta time, time increment
    dt = 0.005
    # number of cells, will be used to assign the initial position  of
    # particles and for size of system
    ucells = 10
    # diameter of particles
    sigma = 1
    # Number of particles, we have one particle per cell
    N = ucells * ucells
    # Density, N/V, V volume
    dens = 0.1
    # packing fraction N*sigme*3/V
    nu = 0.3
    # size of of square
    L = math.sqrt(N / dens)
    print(L)
    # Initial temperature
    T = 2.0
    # Initial average velocity of particles
    v0 = math.sqrt(2.0 * T)
    # lennard jones potential epsilon, strenght of potential
    # it has to be declared using a list in case we have more type of particles
    eps = np.array([1.0])
    # Cut for the potetial,
    rc = sigma * math.pow(2, 1.0 / 6.0)
    rc = 2.5
    rcut = np.array([rc])
    # potential zero reference
    shift = np.array([0.0])

    #Now we create the simulation system

    # initialize the system with a box size of [L,L]
    md.system_init(np.array([L, L]))
    # set the particles on a square lattice
    fm.init_particles_simple_cubic(md, ucells, L)
    lbox = md.system_get_box()
    print("box", lbox)
    #set boundary condiations
    # we use the following construct in C++ enum PBCTYPE {NOPBC, XPBC, XYPBC, XYZPBC};
    # 0, is no periadic boundary conditions, all hard walls
    # 1 is boundary conditions in the x direction
    # 2 is boundary conditions in both x and y direction
    md.system_set_boundary_conditions(2)
    #set the initial veloctities random with average v0
    md.system_set_velocities(v0)
    #substract the center of mass velocity
    md.system_set_zero_center_of_mass_vel()
    # set delta_t for the system
    md.system_set_dt(dt)
    # number of steps to average
    md.system_set_avg_steps(100)
    # set the potential using the varialbles eps, rcut and shift defined before
    md.system_set_potential(eps, rcut, shift)
    # initialize verlet list
    md.system_init_neighbor_list()
    # Get a pointer to array with position and velocities for later work
    pos = md.system_get_positions1()
    vel = md.system_get_velocities()

    # we can save the position using any of these formats, uncomment the wa
    #xyzfile = fm.Saver(0,"test_test",pos)
    #vtkfile = fm.Saver(1,"test_test",pos,vel=vel,cells=tet)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[lbox[0],lbox[1]])
    #vtffile.append(0);

    # If you want to plot the particles along with the simulation,
    #uncomment these lines
    #plot = Plotter.Plotter(pos,vel,None,lbox[0],lbox[1],'pts',sigma) # 2 is the radius
    #plot.update(0)

    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()
        #plot.update(avgs[0])

    print("finished")
Beispiel #5
0
def run0():

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

    dt = 0.005
    ucells = 10
    sigma = 1
    N = ucells * ucells
    dens = 0.1
    nu = 0.3
    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)
    rc = 2.5
    rcut = np.array([rc])
    shift = np.array([0.0])
    E = 200
    k = 50

    pdb.set_trace()

    md.system_init(np.array([L, L]))
    fm.init_particles_simple_cubic(md, ucells, L)
    lbox = md.system_get_box()
    print("box", lbox)
    md.system_set_boundary_conditions(2)
    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_init_neighbor_list()
    pos = md.system_get_positions1()
    vel = md.system_get_velocities()

    #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",pos,vel=vel,cells=tet)
    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[lbox[0],lbox[1]])
    #vtffile.append(0);

    plot = Plotter.Plotter(pos, vel, None, lbox[0], lbox[1], 'pts',
                           sigma)  # 2 is the radius
    plot.update(0)
    #r = 0.0
    #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()
        plot.update(avgs[0])

    print("finished")
Beispiel #6
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()
Beispiel #7
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()
Beispiel #8
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")
Beispiel #9
0
def run3D():

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

    dt = 0.005
    ucells = 1
    sigma = 1
    N = ucells**3
    dens = 0.1
    nu = 0.1
    L = math.pow(N / dens,1/3.0) 
    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)
    #rc = 2.5
    rcut=np.array([rc])
    shift=np.array([1.0])
    E=200
    k=50

    pdb.set_trace()

    md.system_init(np.array([L,L,L]))
    #nodes = np.loadtxt("diskR1Vertices1.txt");
    #cells = np.loadtxt("diskR1Triangles1.txt") - 1;
    nodes, cells = mdmesh.uniform_mesh_on_unit_ball(.2)
    L,R = fm.add_3D_clusters(md,nodes,cells,1.0,ucells,nu,'sc1')
    #fm.init_particles_simple_cubic3D(md,ucells,L)
    lbox = 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,10,0)
    md.system_set_friction(1)
    #md.system_set_bond_spring_constant(k)
    md.system_init_neighbor_list()
    pos = md.system_get_positions()
    print(pos)
    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,dims=3)
    vtkfile = fm.Saver(1,"test_test",pos,dims=3,vel=vel,cells=tet)
    vtkfile.append(0)
    '''
    lx = lbox[0]
    fig = plt.figure()
    ax = a3.Axes3D(fig)
    ax.set_aspect('equal')
    ax.set_xlim(0,lx)
    ax.set_ylim(0,lx)
    ax.set_zlim(0,lx)
    fig.set_size_inches(15, 15)
    ax.scatter(pos[:,0],pos[:,1],pos[:,2])
    ax.add_collection3d(tri)
    plt.show()
    '''

    #vtffile = fm.Saver(2,"test_test",upos,bonds=bonds,box=[lbox[0],lbox[1]])
    #vtffile.append(0);
    #plot = Plotter.Plotter(pos,vel,tet,lbox[0],lbox[1],'pts',sigma) # 2 is the radius
    #plot.update(0)
    #r = 0.0
    #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()
        #plot.update(avgs[0])

    print("finished")
    plt.show()