예제 #1
0
lx = 10.0
ly = 10.0
lz = 10.0
stokes.stokes_set_l(sys, lx, ly, lz)

ewald_tr = 60.25
xi = stokes.xi_by_tratio(sys, ewald_tr)
ewald_eps = 1.0e-12
stokes.stokes_set_xi(sys, xi, ewald_eps)

print 'xi =', xi

sys.lubmin2 = 4.0000000001
sys.lubmax = 4.0
stokes.stokes_set_iter(sys, "gmres", 2000, 20, 1.0e-6,
                       1, stokes.get_stdout())

pos = stokes.darray(np*3)
u   = stokes.darray(np*3)
f   = stokes.darray(np*3)

pos[ 0] = 0.0 # x component
pos[ 1] = 0.0 # y component
pos[ 2] = 0.0 # z component

pos[ 3] = 5.0
pos[ 4] = 0.0
pos[ 5] = 0.0

pos[ 6] = 0.0
pos[ 7] = 5.0
예제 #2
0
파일: stncdump.py 프로젝트: kichiki/stokes
def main():
    filename = ''
    flag_line = 0
    step = -1
    flag_com = 0
    x0 = 0.0
    y0 = 0.0
    z0 = 0.0
    i = 1
    while i < len(sys.argv):
        if sys.argv[i] == '-f' or sys.argv[i] == '--file':
            filename = sys.argv[i+1]
            i += 2
        elif sys.argv[i] == '-line':
            flag_line = 1
            i += 1
        elif sys.argv[i] == '-step':
            step = int(sys.argv[i+1])
            step -= 1
            i += 2
        elif sys.argv[i] == '-com':
            flag_com = 1
            x0 = float(sys.argv[i+1])
            y0 = float(sys.argv[i+2])
            z0 = float(sys.argv[i+3])
            i += 4
        else:
            usage()
    if filename == '': usage()

    nc = stokes.stokes_nc_open (filename)

    # pos[] : center of particles
    pos = stokes.darray(nc.np  * nc.nvec)

    # q[] : quaternion
    if nc.flag_q != 0:
        q  = stokes.darray(nc.np  * nc.nquat)
    else:
        q = []

    # lattice
    lattice = stokes.darray(3)
    stokes.stokes_nc_get_array1d (nc, 'l', lattice)

    # extract the config at the step
    if step >= 0:
        if step > nc.ntime:
            print 'out of the range %d <= %d'%(step, nc.ntime)
            sys.exit(1)

        # read the config at the step
        t = stokes.stokes_nc_get_time_step (nc, step)
        stokes.stokes_nc_get_data (nc, "x", step, pos)
        if nc.flag_q != 0:
            stokes.stokes_nc_get_data (nc, "q", step, q)

        comx = 0.0
        comy = 0.0
        comz = 0.0
        if flag_com != 0:
            for i in range(nc.np):
                comx += pos[i*3]
                comy += pos[i*3+1]
                comz += pos[i*3+2]
            comx /= float(nc.np)
            comy /= float(nc.np)
            comz /= float(nc.np)

        # print the config
        # print arguments as a comment
        print '; config at %d step of %s, generated by'%(step+1, filename)
        print ';  ',
        for i in range(len(sys.argv)):
            print '%s'%(sys.argv[i]),
        print ''
        print '; at time %f'%(t)
        print '(define x #('
        for i in range(nc.np):
            print '  %f %f %f ; %d'%(pos[i*3]   - comx + x0,
                                     pos[i*3+1] - comy + y0,
                                     pos[i*3+2] - comz + z0,
                                     i)
        print '))'

        if nc.flag_q != 0:
            stokes.stokes_nc_get_data (nc, "q", step, q)
            print '(define q #('
            for i in range(nc.np):
                print '  %f %f %f %f ; %d'\
                      %(q[i*4],q[i*4+1],q[i*4+2],q[i*4+3],i)
            print '))'
        sys.exit(1)
        # done!

    if flag_line == 0:
        # print some general informations
        stokes.stokes_nc_print_actives(nc, stokes.get_stdout())
        print ''
        print 'ntime = %d'%(nc.ntime)
        print ''

        # imposed flows
        if nc.flag_ui0 == 1:
            ui0 = stokes.darray(3)
            stokes.stokes_nc_get_array1d (nc, "Ui0", ui0)
            print 'ui0 = %f %f %f'%(ui0[0], ui0[1], ui0[2])
        if nc.flag_oi0 == 1:
            oi0 = stokes.darray(3)
            stokes.stokes_nc_get_array1d (nc, "Oi0", oi0)
            print 'oi0 = %f %f %f'%(oi0[0], oi0[1], oi0[2])
        if nc.flag_ei0 == 1:
            ei0 = stokes.darray(5)
            stokes.stokes_nc_get_array1d (nc, "Ei0", ei0)
            print 'ei0 = %f %f %f %f %f'\
                  %(ei0[0], ei0[1], ei0[2], ei0[3], ei0[4])
        print ''

        print 'lattice %f %f %f\n'%(lattice[0], lattice[1], lattice[2])

    # print the infos about the output format
    if flag_line == 0:
        if nc.flag_q != 0:
            print '# t, i, x, y, z, q1, q2, q3, q4'
        else:
            print '# t, i, x, y, z'
    else:
        if nc.flag_q != 0:
            print '# t, x, y, z, q1, q2, q3, q4 (for particle 0),'\
                  ' ... upto particle %d'%(nc.np)
        else:
            print '# t, x, y, z (for particle 0), x, y, z (for 1),'\
                  ' ... upto particle %d'%(nc.np)

    for i in range(nc.ntime):
        t = stokes.stokes_nc_get_time_step (nc, i)

        stokes.stokes_nc_get_data (nc, "x", i, pos)
        if nc.flag_q != 0:
            stokes.stokes_nc_get_data (nc, "q", i, q)

        if flag_line == 0:
            for j in range(nc.np):
                x = pos[j*3]
                y = pos[j*3+1]
                z = pos[j*3+2]
                if nc.flag_q != 0:
                    print '%f %d %f %f %f %f %f %f %f'\
                          %(t, j, x, y, z, q[0], q[1], q[2], q[3])
                else:
                    print '%f %d %f %f %f'%(t, j, x, y, z)
        else:
            print t,
            for j in range(nc.np):
                x = pos[j*3]
                y = pos[j*3+1]
                z = pos[j*3+2]
                print x, y, z,
                if nc.flag_q != 0:
                    print q[0], q[1], q[2], q[3],
            print ''