def viscoElasticUpdater_bgvel(t, y, wdict):
    #interior function for incompressible background flow only
    #split up long vector into individual sections (force pts, Lagrangian pts, stress components)
    pdict = wdict['pdict']
    N = pdict['N']
    M = pdict['M']
    l2 = np.reshape(y[range(2 * N * M)], (N * M, 2))
    l3 = np.reshape(l2, (N, M, 2))
    P2 = np.reshape(y[(2 * N * M):], (N * M, 2, 2))
    P3 = np.reshape(P2, (N, M, 2, 2))
    #calculate tensor derivative
    Pd = pdict['beta'] * SD2D.tensorDiv(P3, pdict['gridspc'], N, M)
    Pd = np.reshape(Pd, (N * M, 2))
    #calculate deformation matrix and its inverse
    F = SD2D.vectorGrad(l3, pdict['gridspc'], N, M)
    F = np.reshape(F, (N * M, 2, 2))
    #calculate new velocities at all points of interest
    ub, gradub = wdict['myVelocity'](pdict, l2)
    lt0 = pdict['gridspc']**2 * CM.matmult(pdict['eps_grid'], pdict['mu'], l2,
                                           l2, Pd)
    # reshape the velocities on the grid
    lt3 = np.reshape(lt0, (N, M, 2))
    lt = ub + lt0
    #    calculate new stress time derivatives
    gradlt = SD2D.vectorGrad(lt3, pdict['gridspc'], N, M)
    gradlt = np.reshape(gradlt, (N * M, 2, 2))
    Pt = CM.stressDeriv(pdict['Wi'], gradub, gradlt, F, P2)
    #    gradlt = pdict['gridspc']**2*CM.derivop(pdict['eps_grid'],pdict['mu'],l2,l2,Pd,F) #grad(Stokeslet) method
    #    Finv = CM.matinv2x2(F) #first grad(u) method
    #    Pt = np.zeros((N*M,2,2)) #first grad(u) method
    #    for j in range(N*M):
    #        Pt[j,:,:] = np.dot(gradub[j,:,:],P2[j,:,:]) + np.dot(np.dot(gradlt[j,:,:],Finv[j,:,:]),P2[j,:,:]) - (1./pdict['Wi'])*(P2[j,:,:] - Finv[j,:,:].transpose())
    return np.append(lt, Pt.flatten())
示例#2
0
def veExtensionUpdater(t, y, pdict):
    #interior function for incompressible background flow only
    #split up long vector into individual sections (force pts, Lagrangian pts, stress components)
    N = pdict['N']
    M = pdict['M']
    l = y[range(2 * N * M)]
    l2col = np.reshape(l, (N * M, 2))
    l3D = np.reshape(l, (N, M, 2))
    P = np.reshape(y[(2 * N * M):], (N, M, 2, 2))
    Ps = np.reshape(P, (N * M, 2, 2))
    #calculate tensor derivative
    Pd = pdict['beta'] * SD2D.tensorDiv(P, pdict['gridspc'], N, M)
    Pd = np.reshape(Pd, (N * M, 2))
    #calculate deformation matrix and its inverse
    F = SD2D.vectorGrad(l3D, pdict['gridspc'], N, M)
    F = np.reshape(F, (N * M, 2, 2))
    Finv = CM.matinv2x2(F)
    #calculate new velocities at all points of interest (Lagrangian points and force points)
    ub, gradub = pdict['myVelocity'](pdict, l, l2col)
    lt = ub + pdict['gridspc']**2 * CM.matmult(pdict['eps'], pdict['mu'],
                                               l2col, l2col, Pd)
    #calculate new stress time derivatives
    gradlt = pdict['gridspc']**2 * CM.derivop(pdict['eps'], pdict['mu'], l2col,
                                              l2col, Pd, F)
    Pt = np.zeros((N * M, 2, 2))
    for j in range(N * M):
        Pt[j, :, :] = np.dot(gradub[j, :, :], Ps[j, :, :]) + np.dot(
            np.dot(gradlt[j, :, :], Finv[j, :, :]), Ps[j, :, :]) - (
                1. / pdict['Wi']) * (Ps[j, :, :] - Finv[j, :, :].transpose())
    return np.append(lt, Pt.flatten())
def simresults(basename, basedir):
    '''Retrieve approximate solution from saved output'''
    mydict = fileops.loadPickle(basename=basename, basedir=basedir)
    l = mydict['l']
    S = mydict['S']
    F = []
    Finv = []
    P = []
    N = l[0].shape[0]
    M = l[0].shape[1]
    for k in range(len(mydict['t'])):
        Ft = SD2D.vectorGrad(l[k], mydict['pdict']['gridspc'], N, M)
        Ftemp = np.reshape(Ft, (N * M, 2, 2))
        Ftinv = CM.matinv2x2(Ftemp)
        Ftinv = np.reshape(Ftinv, (N, M, 2, 2))
        F.append(Ft.copy())
        Finv.append(Ftinv.copy())
        stress = np.zeros((N, M, 2, 2))
        for j in range(N):
            for m in range(M):
                stress[j,
                       m, :, :] = S[k][j,
                                       m, :, :] * Ftinv[j,
                                                        m, :, :].transpose()
        P.append(stress.copy())
    return l, P, S, F, Finv, mydict
示例#4
0
def viscoElasticUpdaterKernelDeriv(t, y, pdict):
    #interior function for force pts only
    #split up long vector into individual sections (force pts, Lagrangian pts, stress components)
    if 'forcedict' not in pdict.keys():
        pdict['forcedict'] = {}
    pdict['forcedict']['t'] = t
    N = pdict['N']
    M = pdict['M']
    Q = len(y) / 2 - N * M - 2 * N * M
    fpts = np.reshape(y[:2 * Q], (Q, 2))
    l = y[range(2 * Q, 2 * Q + 2 * N * M)]
    l2col = np.reshape(l, (N * M, 2))
    l3D = np.reshape(l, (N, M, 2))
    allpts = y[:2 * Q + 2 * N * M]  #both force points and Lagrangian points
    ap = np.reshape(allpts, (Q + N * M, 2))
    P = np.reshape(y[(2 * Q + 2 * N * M):], (N, M, 2, 2))
    Ps = np.reshape(P, (N * M, 2, 2))
    #calculate tensor derivative
    Pd = pdict['beta'] * SD2D.tensorDiv(P, pdict['gridspc'], N, M)
    Pd = np.reshape(Pd, (N * M, 2))
    #calculate spring forces
    f = pdict['myForces'](fpts, pdict['xr'], pdict['K'], **pdict['forcedict'])
    #calculate deformation matrix and its inverse
    gl = SD2D.vectorGrad(l3D, pdict['gridspc'], N, M)
    gls = np.reshape(gl, (N * M, 2, 2))
    igls = CM.matinv2x2(gls)
    #calculate new velocities at all points of interest (Lagrangian points and force points)
    lt = pdict['gridspc']**2 * CM.matmult(
        pdict['eps'], pdict['mu'], ap, l2col, Pd) + CM.matmult(
            pdict['eps'], pdict['mu'], ap, fpts, f)
    #calculate new stress time derivatives
    glst = pdict['gridspc']**2 * CM.derivop(
        pdict['eps'], pdict['mu'], l2col, l2col, Pd, gls) + CM.derivop(
            pdict['eps'], pdict['mu'], l2col, fpts, f, gls)
    Pt = np.zeros((N * M, 2, 2))
    for j in range(N * M):
        Pt[j, :, :] = np.dot(np.dot(glst[j, :, :], igls[j, :, :]),
                             Ps[j, :, :]) - (1. / pdict['Wi']) * (
                                 Ps[j, :, :] - igls[j, :, :].transpose())
    return np.append(lt, Pt.flatten())
def viscoElasticUpdater_force(t, y, wdict):
    #interior function for force pts only
    #split up long vector into individual sections (force pts, Lagrangian pts, stress components)
    pdict = wdict['pdict']
    pdict['forcedict']['t'] = t
    N = pdict['N']
    M = pdict['M']
    Q = len(y) / 2 - N * M - 2 * N * M
    fpts = np.reshape(y[:2 * Q], (Q, 2))
    l2 = np.reshape(y[range(2 * Q, 2 * Q + 2 * N * M)], (N * M, 2))
    l3 = np.reshape(l2, (N, M, 2))
    allpts = np.reshape(
        y[:2 * Q + 2 * N * M],
        (Q + N * M, 2))  # both force points and Lagrangian points
    P2 = np.reshape(y[(2 * Q + 2 * N * M):], (N * M, 2, 2))
    P3 = np.reshape(P2, (N, M, 2, 2))
    #calculate tensor derivative
    Pd = pdict['beta'] * SD2D.tensorDiv(P3, pdict['gridspc'], N, M)
    Pd = np.reshape(Pd, (N * M, 2))
    #calculate spring forces
    f = wdict['myForces'](fpts, **pdict['forcedict'])
    #calculate new velocities at all points of interest (Lagrangian points and force points)
    lt = pdict['gridspc']**2 * CM.matmult(
        pdict['eps_grid'], pdict['mu'], allpts, l2, Pd) + CM.matmult(
            pdict['eps_obj'], pdict['mu'], allpts, fpts, f)
    # reshape the velocities on the grid
    lt3 = np.reshape(lt[2 * Q:], (N, M, 2))
    #calculate deformation matrix and its inverse
    F = SD2D.vectorGrad(l3, pdict['gridspc'], N, M)
    F = np.reshape(F, (N * M, 2, 2))
    #calculate new stress time derivatives
    #    gradlt = pdict['gridspc']**2*CM.derivop(pdict['eps_grid'],pdict['mu'],l2,l2,Pd,F) + CM.derivop(pdict['eps_obj'],pdict['mu'],l2,fpts,f,F)   #grad(Stokeslet) method
    gradlt = SD2D.vectorGrad(lt3, pdict['gridspc'], N, M)
    gradlt = np.reshape(gradlt, (N * M, 2, 2))
    #    Finv = CM.matinv2x2(F)   # first grad(u) method
    #    Pt = np.zeros((N*M,2,2))
    #    for j in range(N*M):
    #        Pt[j,:,:] = np.dot(np.dot(gradlt[j,:,:],Finv[j,:,:]),P2[j,:,:]) - (1./pdict['Wi'])*(P2[j,:,:] - Finv[j,:,:].transpose())
    Pt = CM.stressDeriv(pdict['Wi'], gradlt, F, P2)
    return np.append(lt, Pt.flatten())
def stokesFlowUpdaterWithMarkers(t, y, wdict):
    pdict = wdict['pdict']
    pdict['forcedict']['t'] = t
    N = pdict['N']
    M = pdict['M']
    Q = len(y) / 2 - N * M
    fpts = np.reshape(y[:2 * Q], (Q, 2))
    ap = np.reshape(y, (Q + N * M, 2))
    #calculate spring forces
    f = pdict['myForces'](fpts, **pdict['forcedict'])
    #calculate new velocities at all points of interest (Lagrangian points and force points)
    lt = CM.matmult(pdict['eps_obj'], pdict['mu'], ap, fpts, f)
    return lt
def stokesFlowUpdater(t, y, wdict):
    '''
    t = current time, y = [fpts.flatten(), l.flatten(), P.flatten()], pdict 
    contains: K is spring constant, xr is resting position, blob is regularized 
    Stokeslet object, myForces is a function handle, forcedict is a dictionary
    containing optional parameters for calculating forces.
    
    '''
    pdict = wdict['pdict']
    pdict['forcedict']['t'] = t
    Q = len(y) / 2
    fpts = np.reshape(y, (Q, 2))
    f = wdict['myForces'](fpts, **pdict['forcedict'])
    yt = CM.matmult(pdict['eps_obj'], pdict['mu'], fpts, fpts, f)
    return yt
示例#8
0
def simresults(basename, basedir):
    '''Retrieve approximate solution from saved output'''
    mydict = loadPickle(basename, basedir)
    l = mydict['l']
    regridinds = findRegridTimes(l)
    S=mydict['S']
    P=[]
    for k in range(len(mydict['t'])):
        # N and M can change because of regridding
        N = l[k].shape[0]
        M = l[k].shape[1]
        Ft = SD2D.vectorGrad(l[k],mydict['pdict']['gridspc'],N,M)
        Ftemp = np.reshape(Ft,(N*M,2,2))
        Ftinv = CM.matinv2x2(Ftemp)
        Ftinv = np.reshape(Ftinv,(N,M,2,2))
        stressP = np.zeros((N,M,2,2))
        for j in range(N):
            for m in range(M):
                stressP[j,m,:,:] = S[k][j,m,:,:]*Ftinv[j,m,:,:].transpose()
        P.append(stressP.copy())
    return l, P, S, mydict, regridinds
def simresults(basename, basedir):
    '''Retrieve approximate solution from saved output'''
    mydict = fileops.loadPickle(basename=basename, basedir=basedir)
    l = mydict['l']
    S=mydict['S']
    F=[]
    Finv=[]
    P=[]
    N = l[0].shape[0]
    M = l[0].shape[1]
    for k in range(len(mydict['t'])):
        Ft = SD2D.vectorGrad(l[k],mydict['pdict']['gridspc'],N,M)
        Ftemp = np.reshape(Ft,(N*M,2,2))
        Ftinv = CM.matinv2x2(Ftemp)
        Ftinv = np.reshape(Ftinv,(N,M,2,2))
        F.append(Ft.copy())
        Finv.append(Ftinv.copy())
        stress = np.zeros((N,M,2,2))
        for j in range(N):
            for m in range(M):
                stress[j,m,:,:] = S[k][j,m,:,:]*Ftinv[j,m,:,:].transpose()
        P.append(stress.copy())
    return l, P, S, F, Finv, mydict