示例#1
0
F = np.zeros(2, dtype=[('f1', float), ('f2', float), ('f3', float)])
F['f1'] = [1.0, -1.0]
F['f2'] = [0.0, 0.0]
F['f3'] = [0.5, -0.5]

#For more details about the input parameters see also the docstring in the
#module src.set_parameters.  Commenting out a line will use the default value.
#In particualar, set_parameters can be called without any input values.
par = set_parameters(
    domain=[0.0, 1.0, 0.0, 1.0, 0.0,
            1.0],  #compuational domain: [x_a,x_b,y_a,y_b,z_a,z_b]
    dx=1 / 64,
    dy=1 / 64,
    dz=1 / 64,  #grid spacing
    #    z_layers=None,#use for non-uniform grid in z
    images=True,  #turn image system on and off
    epsilon=1 / 64,  #regularization parameter
    method='Real',  #choices are 'Real', 'FFT', 'Ewald'
    #    xi=4/64,#splitting parameter
    #    r_cutoff=None,#cutoff radius for local piece in Ewald splitting
    ncopies_R=0  #number of terms in Stokeslet-double sum (per dimension)
)

U = run(X0, F, par, cores=1)  #set cores = 1 to run code in serial

fig = plt.figure()
ax = fig.add_subplot(111)
xx = par['grid']['x']
yy = par['grid']['y']
zz = par['grid']['z']
ax.quiver(
示例#2
0
nsteps = 13

cilia_config = {
    'T': 1.0,
    'npoints': 1000,
    'ncilia_x': 1,
    'ncilia_y': 1,
    'nsteps': nsteps,
    'dt': 1.0 / 13,
    'beat_pattern': 'SandersonSleigh',
    'L': 1.0,
    'ncilia': 1
}

par = set_parameters([-1.0, 1.0, -1.0, 1.0, 0.0, 1.0])

for i in range(nsteps)[::-1]:
    X0, U = parametrize(i / nsteps, cilia_config, par)
    if i < 5:
        plt.plot(X0['x'],
                 X0['z'],
                 linewidth=4,
                 color='red',
                 alpha=1 - (i + 2) / (nsteps + 2))
    else:
        plt.plot(X0['x'],
                 X0['z'],
                 linewidth=4,
                 color='blue',
                 alpha=1 - (i + 2) / (nsteps + 2))
示例#3
0
F['f1'][-1] = -sum(F['f1'][:-1])
F['f2'][-1] = -sum(F['f2'][:-1])
F['f3'][-1] = -sum(F['f3'][:-1])

dx = 1 / 64
eps = 4 * dx
xi = 6 * eps
diff_Ewald_Real = []
diff_Ewald_FFT = []

start = time.time()

par_Real = set_parameters(dx=dx,
                          dy=dx,
                          dz=1 / 65,
                          method='Real',
                          images=False,
                          epsilon=eps,
                          ncopies_R=40)
forces_Real = make_forces_struct(X0, F, par_Real)
sol_Real = velocity_from_forces(forces_Real, par_Real, cores)
max_Real = max(np.max(sol_Real['u']), np.max(sol_Real['v']),
               np.max(sol_Real['w']))

par_FFT = set_parameters(dx=dx,
                         dy=dx,
                         dz=1 / 65,
                         method='FFT',
                         images=False,
                         epsilon=eps)
forces_FFT = make_forces_struct(X0, F, par_FFT)
示例#4
0
for case in {'free_no-img','free_img','dp_no-img','dp_img'}:
    if case == 'free_no-img':
        method = 'Real'
        images = False
    elif case == 'free_img':
        method = 'Real'
        images = True
    elif case == 'dp_no-img':
        method = 'FFT'
        images = False
    elif case == 'dp_img':
        method = 'FFT'
        images = True

    par = set_parameters(domain=[-1.0,1.0,-1.0,1.0,0.0,2.0],dx=1/64,dy=1/64,dz=1/11,method=method,images=images,epsilon=0.2)

    X0 = np.zeros(1,dtype=[('x',float),('y',float),('z',float)])
    X0['x'] = 0.0
    X0['y'] = 0.0
    X0['z'] = 1.0

    F = np.zeros(1,dtype=[('f1',float),('f2',float),('f3',float)])
    F['f1'] = 1.0
    F['f2'] = 0.0
    F['f3'] = 1.0

    forces = make_forces_struct(X0,F,par)
    sol = velocity_from_forces(forces,par,cores)

    y = par['grid']['y_vec']
示例#5
0
F = np.zeros(nforces, dtype=[('f1', float), ('f2', float), ('f3', float)])
F['f1'] = rd.rand(nforces)
F['f2'] = rd.rand(nforces)
F['f3'] = rd.rand(nforces)

# make sure the netforce is equal to zero
F['f1'][-1] = -sum(F['f1'][:-1])
F['f2'][-1] = -sum(F['f2'][:-1])
F['f3'][-1] = -sum(F['f3'][:-1])

dx = 1 / 64
eps = 4 * dx

par_ref = set_parameters(dx=dx,
                         dy=dx,
                         dz=1 / 11,
                         method='FFT',
                         images=False,
                         epsilon=eps)
forces_ref = make_forces_struct(X0, F, par_ref)
sol_ref = velocity_from_forces(forces_ref, par_ref, cores)

vals = np.array([1, 2, 4, 7, 10, 20, 40, 80, 160, 320])
diff = np.zeros(vals.shape)
i = 0
for ncopies_R in vals:
    par = set_parameters(dx=dx,
                         dy=dx,
                         dz=1 / 11,
                         method='Real',
                         images=False,
                         epsilon=eps,
示例#6
0
# make sure the netforce is equal to zero
#F['f1'][-1] = -sum(F['f1'][:-1])
#F['f2'][-1] = -sum(F['f2'][:-1])
#F['f3'][-1] = -sum(F['f3'][:-1])

dx = 1 / 64

N = 16
epsilons = np.linspace(5 / N, 5, N, endpoint=True) * dx
diff = np.zeros(epsilons.shape)
i = 0
for eps in epsilons:
    par_Ewald = set_parameters(dx=dx,
                               dy=dx,
                               dz=1 / 65,
                               method='Ewald',
                               images=False,
                               epsilon=eps,
                               xi=4 * dx)
    forces_Ewald = make_forces_struct(X0, F, par_Ewald)
    sol_Ewald = velocity_from_forces(forces_Ewald, par_Ewald, cores)

    par_FFT = set_parameters(dx=dx,
                             dy=dx,
                             dz=1 / 65,
                             method='FFT',
                             images=False,
                             epsilon=eps)
    forces_FFT = make_forces_struct(X0, F, par_FFT)
    sol_FFT = velocity_from_forces(forces_FFT, par_FFT, cores)
示例#7
0
eps_vec = [10.0**-8, 0.0625, 0.3]

fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.grid(True)

for i in range(len(z0_vec)):
    z0 = z0_vec[i]
    X0['z'] = z0

    for j in range(len(eps_vec)):
        eps = eps_vec[j]
        par = set_parameters(domain=[0.0, 1.0, 0.0, 1.0, z0, 2.0],
                             dz=1 / 64,
                             method='FFT',
                             images=True,
                             epsilon=eps)
        forces = make_forces_struct(X0, F, par)
        sol = velocity_from_forces(forces, par, cores)
        z = par['grid']['z_vec']
        L_x = par['box']['L_x']
        L_y = par['box']['L_y']
        u_inf = z0 / (L_x * L_y) * F['f1']
        v_inf = z0 / (L_x * L_y) * F['f2']
        w_inf = 0.0
        err = np.sqrt((sol['u'] - u_inf)**2 + (sol['v'] - v_inf)**2 +
                      (sol['w'] - w_inf)**2)
        err_max = np.squeeze(np.apply_over_axes(np.amax, err, axes=[0, 1]))

        if i == 0:  # Add to legend only the first time
示例#8
0
    'ncilia_y': ncilia_y,
    'nsteps': nsteps,
    'dt': dt,
    'beat_pattern': beat_pattern,
    'L': L,
    #    'theta':theta*pi/180,
    #    'psi':psi*pi/180
}

output = []

for theta, psi in zip([20, 30], [20, 55]):
    for Length in [0.8, 0.9, 1.0, 1.2, 1.5, 2.0, 3.0, 4.0, 5.0]:
        par = set_parameters(domain=[0, Length, 0, Length, 0.0, 1.0],
                             dx=1 / 64,
                             dy=1 / 64,
                             dz=1 / 64,
                             epsilon=0.05,
                             images=True)

        L_x = par['box']['L_x']
        L_y = par['box']['L_y']

        cilia_config.update({'theta': theta * pi / 180, 'psi': psi * pi / 180})
        netflow = {'u': 0, 'v': 0}
        t = 0
        for i in range(nsteps):
            print('step %d' % i)
            (X0, U) = parametrize(t, cilia_config, par)[0:2]
            F = forces_from_velocity_exact(X0, U, par, cores)
            z0 = X0['z']
示例#9
0
# In order for this routine to work, in the module velocity_from_forces
# from src.velocity.velocity_from_forces replace the line
#u = u_erf + u_erfc
# with this
#u = par['erf']*u_erf + par['erfc']*u_erfc
# --------------------------------------

os.system("mkdir -p " + params.image_path)

cores = 4

for xi in {0.2, 0.3, 0.4}:
    par = set_parameters(domain=[-0.0, 1.0, -1.0, 1.0],
                         dx=1 / 256,
                         dy=1 / 64,
                         z_layers=np.array(1.0),
                         method='Ewald',
                         images=False,
                         epsilon=0.04,
                         xi=xi)

    X0 = np.zeros(1, dtype=[('x', float), ('y', float), ('z', float)])
    X0['x'] = 0.5
    X0['y'] = 0.0
    X0['z'] = 1.0

    F = np.zeros(1, dtype=[('f1', float), ('f2', float), ('f3', float)])
    F['f1'] = 1.0
    F['f2'] = 0.0
    F['f3'] = 0.0

    forces = make_forces_struct(X0, F, par)
示例#10
0
import params

cores = 4

nforces = 4

rd.seed(1)
X0 = np.zeros(nforces, dtype=[('x', float), ('y', float), ('z', float)])
X0['x'] = rd.rand(nforces)
X0['y'] = rd.rand(nforces)
z0_vec = [0.5, 0.1, 0.05]
eps_vec = [0.0625, 0.3]

F = np.zeros(nforces, dtype=[('f1', float), ('f2', float), ('f3', float)])
F['f1'] = rd.rand(nforces)
F['f2'] = rd.rand(nforces)
F['f3'] = rd.rand(nforces)

for z0 in z0_vec:
    X0['z'] = z0 * np.ones(nforces)
    for eps in eps_vec:
        par = set_parameters(z_layers=np.array([0]),
                             method='FFT',
                             images=True,
                             epsilon=eps)
        forces = make_forces_struct(X0, F, par)
        sol = velocity_from_forces(forces, par, cores)
        diff = np.max(np.sqrt(sol['u']**2 + sol['v']**2 + sol['w']**2))
        print 'z0 = %g, eps = %g, diff = %e' % (z0, eps, diff)