Пример #1
0
def scenario3pts():
    l = 1.e-5
    U = np.array([6.e-5, 4.5e-5, 5.e-5])
    mu = 1.e-3
    eps = [l / 2., 3 * l / 2.]
    v = -1 * np.array([[
        np.cos(np.pi / 6), np.sin(np.pi / 6), 0
    ], [np.cos(5 * np.pi / 6), np.sin(5 * np.pi / 6), 0
        ], [np.cos(-np.pi / 2), np.sin(-np.pi / 2), 0]])
    xh = -4.e-6 * v
    x = np.arange(-1.e-3, 1.01e-3, 1.e-5)
    X, Y = np.meshgrid(x, x)
    xu = np.column_stack([
        np.column_stack([X.flatten(), Y.flatten()]),
        np.zeros(X.flatten().shape)
    ])
    u, xt = calcFlow(xu, xh, v, U, l, eps, mu)
    yu = xu[:, 1].reshape((len(x), len(x)))
    xu = xu[:, 0].reshape((len(x), len(x)))
    v = u[:, 1].reshape((len(x), len(x)))
    u = u[:, 0].reshape((len(x), len(x)))
    # plotVels(xu,yu,u,v,xh,xt)
    mat2py.write('/Users/bcummins/colonyvel.mat', {
        'xu': xu,
        'yu': yu,
        'xh': xh,
        'xt': xt,
        'u': u,
        'v': v,
        'eps': eps
    })
    return xu, yu, u, v, xh, xt
Пример #2
0
    def write(self, d, stream, filetype, **kw):
        '''
        d is a dictionary of gicdat.doc.Node instances, of the sort returned by
        gicdat.Doc.allNodes(). Stream is a file-like object open in write mode.
        filetype is a mime-type-like string. kw args are implementation
        specific

        Write should return None
        '''
        mat2py.write(stream, d)
Пример #3
0
def mySwimmer():
    #get ready to save files
    import mat2py
    import os

    #dictionary of variables for both Stokes flow and viscoelastic flow
    pdict = dict(N=40, M=16, gridspc=1.5 / 40, origin=[0, 0], mu=1, Wi=0.2)
    pdict['beta'] = 1. / (2 * pdict['Wi'])

    #set time parameters, save data every numskip time steps
    t0 = 0
    totalTime = 1
    dt = 1.e-4
    numskip = 500

    #save file name
    fname = os.path.expanduser('~/scratch/swimmer')

    #make swimmer
    #first assign params
    a = 0.1
    w = 2 * np.pi
    lam = 8.4  #2*np.pi/0.75
    Np = 20
    L = 0.78
    h = L / (Np - 1)
    pdict['K'] = 100
    pdict['xr'] = np.array([h])
    pdict['forcedict'] = {'a': a, 'w': w, 't': 0, 'Kcurv': 0.25, 'lam': lam}
    pdict['eps'] = 0.75 * h
    #Now setup initial conditions
    y0 = 0.3 * np.ones((2 * Np, ))
    v = np.arange(0.5, 0.5 + L + h / 2, h)
    y0[:-1:2] = v  #initial conds [x0,y0,x1,y1,...,xn,yn]

    #add unsaveable entries
    pdict1 = pdict.copy()
    pdict1['myForces'] = calcForcesSwimmer
    pdict1['blob'] = RS2D.CubicRegStokeslet(pdict['eps'], pdict['mu'])
    pdict1['blobderiv'] = RS2D.CubicRegStokesletDeriv(pdict['eps'],
                                                      pdict['mu'])

    #run the ode solver
    print('Stokes flow...')
    fpts, t, l, S, Strace = mySolver(stokesFlowUpdater, y0, t0, dt, totalTime,
                                     'bdf', pdict1, numskip)
    mat2py.write(fname + '_stokes_RicardoParams_08162011.mat', {
        't': t,
        'fpts': fpts,
        'pdict': pdict,
        'dt': dt
    })
Пример #4
0
        if quadtype == 't':
            quad = qm.CompTrapRule(circ.quadspacing)
            print('Trapezoid Rule')
        elif quadtype == 's':
            quad = qm.CompSimpRule(circ.quadspacing)
            print("Simpson's Rule")
        elif quadtype == 'r':
            quad = qm.RiemannSum(circ.quadspacing)
            print('Riemann Sum')
        if basistype == 'c':
            basfun = CstBasisFunc(M, quadtype)
            print(basfun.phi)
        elif basistype == 'h':
            basfun = HatBasisFunc(M, quadtype)
            print(basfun.phi)
        P = basfun.phi.shape[0]
        coeffs = quad.makeCoeffs(P)
        subintegral = nm.sum(coeffs * basfun.phi)
        wholeintegral = nm.sum(f * subintegral)
        print(wholeintegral)
        data.append(wholeintegral)
    data = nm.asarray(data)
    exactans = (4 * nm.pi**3) / 3.
    import mat2py as mf
    mf.write('/Users/bcummins/basistest.mat', {
        'N': numchords,
        'intvals': data,
        'exactans': exactans
    })
    print('Exact answer is ' + str(exactans))
			origforcemat = origblob.makeMatrix2DOriginal(nodes,nodes)
			origforces = useGMRES(origforcemat,BCs)
			origvelmat = blob.makeMatrix2DOriginal(obspts,nodes)
			origvel = nm.dot(origvelmat,origforces)
			if len(u) == 0:
				u = vel[0::2]                   	
				v = vel[1::2]                    	
				origu = origvel[0::2]                   	
				origv = origvel[1::2]                    	
			else:                                                     	
				u = nm.append(u,vel[0::2])	
				v = nm.append(v,vel[1::2])	
				origu = nm.append(origu,origvel[0::2])	
				origv = nm.append(origv,origvel[1::2])	
		fname = 'StokesCylTest_exactintegralsANDorig_points_singleblobfortable_N'+ (4-len(str(N)))*'0' + str(N) + '.mat'                	
		mf.write(fname,{'u':u,'v':v,'origu':origu,'origv':origv,'exactu':exactu,'exactv':exactv,'obspts':obspts,'origbps':origblobparams,'eintbps':eintblobparams})
	
	
	
	# #single blob for table, patches
	# mu = 1.0
	# rad = 0.25
	# obspts = constructpatches()
	# exactu, exactv = exactSoln(obspts,rad,mu)
	# numchords = [2**k for k in range(3,9)]
	# for N in numchords:
	# 	nodes = discretizeCircle(N,rad)
	# 	BCs = nm.asarray(N*[1,0])
	# 	origblobparams = [2*nm.pi/(5*N)]
	# 	eintblobparams = [(2*nm.pi/(5*N))**2]
	# 	u = nm.empty((0,))
Пример #6
0
def mySprings():
    #get ready to save files
    import mat2py
    #dictionary of variables for both Stokes flow and viscoelastic flow
    pdictsave = dict(N=20,
                     M=20,
                     gridspc=1. / 20,
                     origin=[0.0, 0.0],
                     mu=1.0,
                     K=5.0,
                     xr=np.array([0.1]))
    pdictsave['eps'] = 4 * pdictsave['gridspc']
    pdict = pdictsave.copy()
    pdict['myForces'] = calcForcesTwoHeadSpring
    #set time parameters, save data every numskip time steps
    t0 = 0
    totalTime = 4
    dt = 1.e-3
    numskip = 50
    #save file name
    fname = os.path.expanduser('~/scratch/springtestC')
    #Stokes flow test, works
    print('Stokes flow...')
    #set up initial conditions
    y0 = np.array([0.3, 0.5, 0.7, 0.5])
    #run the ode solver
    fpts, t, l, S, Strace, alldets = mySolver(stokesFlowUpdater, y0, t0, dt,
                                              totalTime, pdict, 'bdf', numskip)
    #save the output
    mat2py.write(fname + '_stokes.mat', {
        't': t,
        'fpts': fpts,
        'pdict': pdictsave,
        'dt': dt
    })
    #use same initial conditions for spring as in Stokes flow, but add on Lagrangian points and stress
    N = pdict['N']
    M = pdict['M']
    gridspc = pdict['gridspc']
    l0 = mygrids.makeGridCenter(N, M, gridspc, pdict['origin'])
    P0 = np.zeros((N, M, 2, 2))
    P0[:, :, 0, 0] = 1
    P0[:, :, 1, 1] = 1
    y0 = np.append(np.append(y0, l0.flatten()), P0.flatten())
    for Wi in [0.2, 0.4, 0.8, 1.6, 3.2, 6.4, 12.8]:
        print('Wi = %f' % Wi)
        pdictsave['Wi'] = Wi
        pdictsave['beta'] = 1. / (2 * Wi)
        pdict['Wi'] = Wi
        pdict['beta'] = 1. / (2 * Wi)
        totalTime = 8 * np.ceil(Wi)

        #Viscoelastic run
        print('VE flow...')
        #run the ode solver
        fpts, t, l, S, Strace, alldets = mySolver(
            viscoElasticUpdaterKernelDeriv, y0, t0, dt, totalTime, pdict,
            'bdf', numskip)
        #save the output
        mat2py.write(
            fname + '_visco%03d.mat' % int(Wi * 10), {
                't': np.asarray(t),
                'fpts': np.asarray(fpts),
                'l': np.asarray(l),
                'S': np.asarray(S),
                'Strace': np.asarray(Strace),
                'pdict': pdictsave,
                'dt': dt
            })
Пример #7
0
def mySpot():
    #get ready to save files
    import mat2py
    import os
    #dictionary of variables for both Stokes flow and viscoelastic flow
    for N in [20, 40, 80, 160]:
        pdict = dict(N=N,
                     M=(16 * N) / 40,
                     gridspc=1.5 / N,
                     origin=[0.0, 0.0],
                     mu=1.0,
                     Wi=0.2)
        pdict['beta'] = 1. / (2 * pdict['Wi'])

        #set time parameters, save data every time step
        #note that I do not control the time step in the solver!!
        # my time step only tells me where I will save data
        t0 = 0
        totalTime = 1.0
        dt = 5.e-2
        #save file name
        fname = os.path.expanduser('~/scratch/spotC')

        #make swimmer
        #first assign params
        Np = 20
        L = 0.78
        h = L / (Np - 1)
        pdict['K'] = 10.0
        pdict['xr'] = np.array([[1.173, 1.173]])
        pdict['eps'] = 2 * (0.75 * h)
        #Now setup initial conditions
        y0 = np.array([0.8 - h / 2., 0.3 + h / 4.])

        #add unsaveable entries
        pdict1 = pdict.copy()
        pdict1['myForces'] = calcForcesConstant
        #    #run the ode solver
        #    print('Stokes flow...')
        #    fpts, t, l, S, Strace = mySolver(stokesFlowUpdater,y0,t0,dt,totalTime,pdict1)
        #    mat2py.write(fname+'_stokesonly.mat', {'t':t,'fpts':fpts,'pdict':pdict,'dt':dt})

        initTime = 0.0  #remove this when initialization in Stokes flow is desired

        #make the grid
        N = pdict['N']
        M = pdict['M']
        gridspc = pdict['gridspc']
        l0 = mygrids.makeGridCenter(N, M, gridspc, pdict['origin'])
        P0 = np.zeros((N, M, 2, 2))
        #    P0[:,:,0,0] = 1.0
        #    P0[:,:,1,1] = 1.0
        y0 = np.append(np.append(y0, l0.flatten()), P0.flatten())

        #Viscoelastic run
        print('VE flow...')
        fpts, t, l, S, Strace, alldets = mySolver(
            viscoElasticUpdaterKernelDeriv, y0, initTime, dt,
            totalTime + initTime, pdict1)
        #save the output
        mat2py.write(
            fname + '_visco_nove%03d_centergrid.mat' % N, {
                't': np.asarray(t),
                'fpts': np.asarray(fpts),
                'l': np.asarray(l),
                'S': np.asarray(S),
                'Strace': np.asarray(Strace),
                'pdict': pdict,
                'dt': dt,
                'alldets': np.asarray(alldets)
            })
Пример #8
0
def fallingStar():
    ########################################################
    #falling star for art show
    ########################################################
    #get ready to save files
    import mat2py
    #dictionary of variables
    pdictsave = dict(N=80,
                     M=80,
                     gridspc=1. / 100,
                     origin=[0, 0],
                     mu=1.0,
                     K=0.05,
                     xr=[],
                     Wi=1.0)
    pdictsave['beta'] = 1. / (2 * pdictsave['Wi'])
    pdictsave['eps'] = 4 * pdictsave['gridspc']
    pdict = pdictsave.copy()
    pdict['myForces'] = calcForcesGravity
    N = pdict['N']
    M = pdict['M']
    gridspc = pdict['gridspc']

    #set time parameters
    t0 = 0
    totalTime = 0.45
    dt = 1.e-2
    numskip = 1

    #save file name
    fname = 'scratch/star_tree2C'

    #make the star
    R = 0.05
    d = 0.05
    r = 0.03
    spc = 2 * np.pi / 16
    theta = np.arange(0, 6 * np.pi + spc, spc)
    x = (R - r) * np.cos(theta) + d * np.cos(theta * (R - r) / r) + 0.35
    y = (R - r) * np.sin(theta) - d * np.sin(theta * (R - r) / r) + 0.45
    fpts = np.column_stack([x, y])
    pdictsave['n'] = fpts.shape[0]
    pdict['n'] = fpts.shape[0]

    #make tree marker points
    lx = np.arange(0, 0.8 + gridspc / 2, gridspc)
    llinex = 0.4 - lx * np.cos(np.pi / 3)
    lliney = 0.8 - lx * np.sin(np.pi / 3)
    bllinex = np.arange(0, 0.35 + gridspc / 2, gridspc)
    blliney = 0.1 * np.ones(bllinex.shape)
    mx = np.append(llinex, bllinex)
    my = np.append(lliney, blliney)
    ltrunky = np.arange(0.1, -gridspc / 2, -gridspc)
    ltrunkx = 0.35 * np.ones(ltrunky.shape)
    mx = np.append(mx, ltrunkx)
    my = np.append(my, ltrunky)
    btrunkx = np.arange(0.35, 0.45 + gridspc / 2, gridspc)
    btrunky = np.zeros(btrunkx.shape)
    mx = np.append(mx, btrunkx)
    my = np.append(my, btrunky)
    rtrunky = np.arange(0, 0.1 + gridspc / 2, gridspc)
    rtrunkx = 0.45 * np.ones(rtrunky.shape)
    mx = np.append(mx, rtrunkx)
    my = np.append(my, rtrunky)
    brlinex = np.arange(0.45, 0.8 + gridspc / 2, gridspc)
    brliney = blliney
    mx = np.append(mx, brlinex)
    my = np.append(my, brliney)
    rx = lx[range(len(lx) - 1, -1, -1)]
    rlinex = 0.4 + rx * np.cos(np.pi / 3)
    rliney = 0.8 - rx * np.sin(np.pi / 3)
    mx = np.append(mx, rlinex)
    my = np.append(my, rliney)
    mpts = np.column_stack([mx, my])

    #make the grid and stress ICs
    l0 = mygrids.makeGridCenter(N, M, gridspc, pdict['origin'])
    P0 = np.zeros((N, M, 2, 2))
    P0[:, :, 0, 0] = 1
    P0[:, :, 1, 1] = 1
    y0 = np.append(
        np.append(np.append(fpts.flatten(), mpts.flatten()), l0.flatten()),
        P0.flatten())
    #run the ode solver
    fpts, t, l, S, Strace = mySolver(viscoElasticUpdaterKernelDeriv, y0, t0,
                                     dt, totalTime, 'bdf', pdict, numskip)
    #save the output
    mat2py.write(
        fname + '_visco.mat', {
            't': np.asarray(t),
            'fpts': np.asarray(fpts),
            'l': np.asarray(l),
            'S': np.asarray(S),
            'Strace': np.asarray(Strace),
            'pdict': pdictsave,
            'dt': dt
        })
Пример #9
0
	# sys.exit()
	
	N=10
	print('N = 10')
	nodes = nm.column_stack([nm.linspace(-N*0.05,N*0.05,N), nm.zeros(N)])
	dt=nodes.dtype
	df = nm.column_stack([nm.zeros(N),nm.ones(N)])
	RHS = df.flatten()
	eps = 0.005
	blob = CubicRegStokeslet(eps,1,nodes,nodes,'open') #to solve matrix equation, use nodes as both sets of points 
	Ao = blob.makeMatrixOriginal('trap')
	fo = useGMRES(Ao,RHS)
	blobeval = CubicRegStokeslet(eps,1,obspts,nodes,'open')
	Ao2 = blobeval.makeMatrixOriginal('trap')
	uo = nm.dot(Ao2,fo)
	uo = nm.reshape(uo,(uo.shape[0]/2,2))
	Aes = blob.makeMatrixExactIntegralsSlow()
	fes = useGMRES(Aes,RHS)
	Aes2 = blobeval.makeMatrixExactIntegralsSlow()
	ues = nm.dot(Aes2,fes)
	ue = nm.reshape(ues,(ues.shape[0]/2,2))
	# print(Ao)
	# print(fo)
	# print(Aes)
	# print(fes)
	print( nm.max( nm.sum((uo - ue)**2,1) / nm.sum(ue**2,1)) )
	print( nm.sum( nm.sum((uo - ue)**2,1) / nm.sum(ue**2,1)) )
	import mat2py
	mat2py.write('testopencurve.mat',{'obspts':obspts,'uo':uo,'ue':ue})
	
Пример #10
0
    #save file name
    fname = 'scratch/oldversion_twohead'

    #Stokes flow test, works
    print('Stokes flow...')
    #set up initial conditions
    margin = (N * gridspc - 0.2) / 2
    y0 = nm.array(
        [margin, M * gridspc / 2, N * gridspc - margin, M * gridspc / 2])
    #run the ode solver
    fpts, t, l, P, Ptrace = mySolver(stokesFlowUpdater, y0, t0, dt, totalTime,
                                     'adams', pdict)
    #save the output
    mat2py.write(fname + '_stokes.mat', {
        't': t,
        'fpts': fpts,
        'pdict': pdictsave,
        'dt': dt
    })

    #Viscoelastic run
    print('VE flow...')
    #use same initial conditions for spring as in Stokes flow, but add on Lagrangian points and stress
    l0 = makeGrid(N, M, gridspc)
    P0 = nm.zeros((N, M, 2, 2))
    P0[:, :, 0, 0] = 1
    P0[:, :, 1, 1] = 1
    y0 = nm.append(nm.append(y0, l0.flatten()), P0.flatten())
    #run the ode solver
    fpts, t, l, P, Ptrace = mySolver(viscoElasticUpdater, y0, t0, dt,
                                     totalTime, 'bdf', pdict)
    #save the output
Пример #11
0
import numpy as nm
from scipy.integrate import ode
import mat2py


def f(t, y):
    return nm.array([y[1], -y[0]])


if __name__ == '__main__':
    y0, t0 = nm.array([0.25, 0.75]), 0
    r = ode(f).set_integrator('dopri5')
    r.set_initial_value(y0, t0)
    t1 = 4 * nm.pi
    dt = 4 * nm.pi / 1000
    approx = nm.empty(0, )
    while r.successful() and r.t < t1 + dt / 2.:
        r.integrate(r.t + dt)
        approx = nm.append(approx, r.y[0])
    t = nm.arange(0, t1 + dt / 2., dt)
    realsoln = 0.25 * nm.cos(t) + 0.75 * nm.sin(t)
    mat2py.write('testsimpleode.mat', {
        't': t,
        'approx': approx,
        'realsoln': realsoln
    })
Пример #12
0
def mySprings():
    #get ready to save files
    import mat2py, os

    #dictionary of variables for both Stokes flow and viscoelastic flow
    pdictsave = dict(N=20,
                     M=20,
                     gridspc=1. / 20,
                     origin=[0, 0],
                     mu=1,
                     K=5,
                     xr=np.array([0.1]),
                     Wi=0.2)
    pdictsave['beta'] = 1. / (2 * pdictsave['Wi'])
    pdictsave['eps'] = 4 * pdictsave['gridspc']
    pdict = pdictsave.copy()
    pdict['myForces'] = calcForcesQuadraticSpring
    pdict['blob'] = RS2D.CubicRegStokeslet(pdict['eps'], pdict['mu'])
    pdict['blobderiv'] = RS2D.CubicRegStokesletDeriv(pdict['eps'], pdict['mu'])
    gridspc = pdict['gridspc']

    #set time parameters, save data every numskip time steps
    t0 = 0
    totalTime = 1
    dt = 1.e-3
    numskip = 100

    #save file name
    fname = os.path.expanduser('~/scratch/springtest')

    #Stokes flow test, works
    print('Stokes flow...')
    #set up initial conditions
    # margin = (N*gridspc-0.2)/2
    # y0 = np.array([margin,M*gridspc/2,N*gridspc - margin,M*gridspc/2])
    y0 = np.array([0.4, 0.5, 0.6, 0.5])
    #run the ode solver
    fpts, t, l, S, Strace = mySolver(stokesFlowUpdater, y0, t0, dt, totalTime,
                                     'bdf', pdict, numskip)
    #save the output
    mat2py.write(fname + '_stokes_noC.mat', {
        't': t,
        'fpts': fpts,
        'pdict': pdictsave,
        'dt': dt
    })

    #Viscoelastic run
    print('VE flow...')
    #use same initial conditions for spring as in Stokes flow, but add on Lagrangian points and stress
    N = pdict['N']
    M = pdict['M']
    l0 = makeGrid(N, M, gridspc, pdict['origin'])
    P0 = np.zeros((N, M, 2, 2))
    P0[:, :, 0, 0] = 1
    P0[:, :, 1, 1] = 1
    y0 = np.append(np.append(y0, l0.flatten()), P0.flatten())
    #run the ode solver
    fpts, t, l, S, Strace = mySolver(viscoElasticUpdaterKernelDeriv, y0, t0,
                                     dt, totalTime, 'bdf', pdict, numskip)
    #save the output
    mat2py.write(
        fname + '_visco_noC.mat', {
            't': np.asarray(t),
            'fpts': np.asarray(fpts),
            'l': np.asarray(l),
            'S': np.asarray(S),
            'Strace': np.asarray(Strace),
            'pdict': pdictsave,
            'dt': dt
        })
                u_blob2 = vel2[0::2]
                v_blob2 = vel2[1::2]
            else:
                u_blob1 = nm.append(u_blob1, vel1[0::2])
                v_blob1 = nm.append(v_blob1, vel1[1::2])
                u_blob2 = nm.append(u_blob2, vel2[0::2])
                v_blob2 = nm.append(v_blob2, vel2[1::2])
        fname = 'StokesCylTest_hattrapBEM_bothblobs' + (
            4 - len(str(N))) * '0' + str(N) + '.mat'
        mf.write(
            fname, {
                'u_blob1': u_blob1,
                'v_blob1': v_blob1,
                'u_blob2': u_blob2,
                'v_blob2': v_blob2,
                'exactu': exactu,
                'exactv': exactv,
                'obspts': obspts,
                'blobparams': blobparams,
                'numchords': numchords,
                'M': M
            })
        print('Results in ' + fname)

        #original method, both blobs, varying N
        mu = 1.0
        rad = 0.25
        obspts = constructpatches()
        exactu, exactv = exactSoln(obspts, rad, mu)
        numchords = [2**k for k in range(3, 9)]
        for N in numchords: