Example #1
0
    def findStencilSetsSlower(self, level, extraPts=[]):
        """Find the stencil sets [Macdonald & Ruuth 2008]"""
        from time import time
        global PAR_EXTSTENP

        print "finding stencil sets at level " + str(level)
        st = time()
        #F = self.Lists[level]
        G = self.Grids[level]
        # find the the CP, then find the points in the extsten
        # surrouding it, mark each of them
        relpt = self.basicPt
        # first, make them all false
        for n in G.values():
            n.isEvolvePt = False
            n.isExtendPt = False
        # now, follow the algorithm in [MR2008]
        for n in G.values():
            cp = n.cp
            basept = findGridInterpBasePt(cp,n.dx,relpt,PAR_EXTSTENP)
            n.cpbaseptI = basept
            for offset in self.InterpStencil:
                gridindex = basept + offset
                # for each extrapt, find pts in the extsten and mark them
                #try:
                G[tuple(gridindex)].isEvolvePt = True
                #except (KeyError):
                #    raise NameError('not enough points in grid')
                for off2 in self.DiffStencil:
                    gridind2 = basept + offset + off2
                    #    try:
                    G[tuple(gridind2)].isExtendPt = True
                    #    except (KeyError):
                    #        raise NameError('not enough points in grid')
        print "found stencil sets in time = " + str(time() - st)
Example #2
0
    def findStencilSetsSlower(self, level, extraPts=[]):
        """Find the stencil sets [Macdonald & Ruuth 2008]"""
        from time import time
        global PAR_EXTSTENP

        print "finding stencil sets at level " + str(level)
        st = time()
        #F = self.Lists[level]
        G = self.Grids[level]
        # find the the CP, then find the points in the extsten
        # surrouding it, mark each of them
        relpt = self.basicPt
        # first, make them all false
        for n in G.values():
            n.isEvolvePt = False
            n.isExtendPt = False
        # now, follow the algorithm in [MR2008]
        for n in G.values():
            cp = n.cp
            basept = findGridInterpBasePt(cp, n.dx, relpt, PAR_EXTSTENP)
            n.cpbaseptI = basept
            for offset in self.InterpStencil:
                gridindex = basept + offset
                # for each extrapt, find pts in the extsten and mark them
                #try:
                G[tuple(gridindex)].isEvolvePt = True
                #except (KeyError):
                #    raise NameError('not enough points in grid')
                for off2 in self.DiffStencil:
                    gridind2 = basept + offset + off2
                    #    try:
                    G[tuple(gridind2)].isExtendPt = True
                    #    except (KeyError):
                    #        raise NameError('not enough points in grid')
        print "found stencil sets in time = " + str(time() - st)
Example #3
0
    def findStencilSetsFaster(self, level, extraPts=[]):
        """
        Find the stencil sets [Macdonald & Ruuth 2008].  Here we use a
        faster version: mark the CP base points in the grid.  Then
        just iterate over those in a separate loop
        """
        from time import time
        global PAR_EXTSTENP

        print "Finding stencil sets at level " + str(level)
        st = time()
        #F = self.Lists[level]
        G = self.Grids[level]
        # find the the CP, then find the points in the extsten
        # surrouding it, mark each of them
        relpt = self.basicPt
        # first, make them all false
        for n in G.values():
            n.isEvolvePt = False
            n.isExtendPt = False
            n.isCPBasePt = False
        # essentially the algorithm in [MR2008], but here we mark each
        # CP Base Point and then iterate over those in a separate
        # loop.  I confirmed it gives the same thing as the slower
        # version and much faster
        for n in G.values():
            cp = n.cp
            basept = findGridInterpBasePt(cp,n.dx,relpt,PAR_EXTSTENP)
            n.cpbaseptI = basept
            try:
                G[tuple(basept)].isCPBasePt = True
            except KeyError:
                print basept,relpt,basept*n.dx+relpt
                print n.dx
                print n,n.cp
                G[tuple(basept)]
                pass  #?


        for n in G.values():
            if n.isCPBasePt == True:
                basept = n.gridIndex
                for offset in self.InterpStencil:
                    gridindex = basept + offset
                    try:
                        G[tuple(gridindex)].isEvolvePt = True
                    except (KeyError):
                        print basept,offset,gridindex
                        G[tuple(basept)]
                        pass  #?
                    for off2 in self.DiffStencil:
                        gridind2 = basept + offset + off2
                        G[tuple(gridind2)].isExtendPt = True
        print "Found stencil sets in time = " + str(time() - st)
Example #4
0
    def findStencilSetsFaster(self, level, extraPts=[]):
        """
        Find the stencil sets [Macdonald & Ruuth 2008].  Here we use a
        faster version: mark the CP base points in the grid.  Then
        just iterate over those in a separate loop
        """
        from time import time
        global PAR_EXTSTENP

        print "Finding stencil sets at level " + str(level)
        st = time()
        #F = self.Lists[level]
        G = self.Grids[level]
        # find the the CP, then find the points in the extsten
        # surrouding it, mark each of them
        relpt = self.basicPt
        # first, make them all false
        for n in G.values():
            n.isEvolvePt = False
            n.isExtendPt = False
            n.isCPBasePt = False
        # essentially the algorithm in [MR2008], but here we mark each
        # CP Base Point and then iterate over those in a separate
        # loop.  I confirmed it gives the same thing as the slower
        # version and much faster
        for n in G.values():
            cp = n.cp
            basept = findGridInterpBasePt(cp, n.dx, relpt, PAR_EXTSTENP)
            n.cpbaseptI = basept
            try:
                G[tuple(basept)].isCPBasePt = True
            except KeyError:
                print basept, relpt, basept * n.dx + relpt
                print n.dx
                print n, n.cp
                G[tuple(basept)]
                pass  #?

        for n in G.values():
            if n.isCPBasePt == True:
                basept = n.gridIndex
                for offset in self.InterpStencil:
                    gridindex = basept + offset
                    try:
                        G[tuple(gridindex)].isEvolvePt = True
                    except (KeyError):
                        print basept, offset, gridindex
                        G[tuple(basept)]
                        pass  #?
                    for off2 in self.DiffStencil:
                        gridind2 = basept + offset + off2
                        G[tuple(gridind2)].isExtendPt = True
        print "Found stencil sets in time = " + str(time() - st)
Example #5
0
def buildExtensionMatrix(g, xy, degreep=3):
    r"""
    Generate the matrix E

    Notes:
    In the diff op case, the weights are fixed, here they depend on
    which node we're at.
    """
    from math import ceil,log10
    from scipy.sparse import coo_matrix
    from time import time
    from numpy import zeros, isscalar

    # TODO: dim hardcoded to 2 in some places in this function
    dim = xy.shape[1]
    dx = g.dx
    if (isscalar(dx)):
        mytype = type(dx)
    else:
        mytype = type(dx[0])

    relpt = a((g.x1d[0], g.y1d[0]))
    #stencilsize = len(Levolve[0].interppts)
    stencilsize = (degreep+1)**dim
    progout = 10 ** (ceil(log10(len(g.band)))-1)
    print "building E"
    st=time()

    # make empty lists the sparse matrix
    # TODO: is it faster to use numpy arrays here?
    ii = [];  jj = [];  aij = []

    # how many points to interpolate
    N = xy.shape[0]

    # TODO: order here must match code elsewhere: this is a very bad idea
    stencil = zeros( (stencilsize,dim) , dtype=int)
    c = 0
    for j in range(0,degreep+1):
        for i in range(0,degreep+1):
            stencil[c][0] = i
            stencil[c][1] = j
            c = c+1

    # can do all of them at once
    #bpij = findGridInterpBasePt(xy, dx, relpt, degreep)
    for c in range(0, N):
        if c % progout == 0:  print "  E row " + str(c)
        x = xy[c]
        bpij = findGridInterpBasePt(x, dx, relpt, degreep)
        bpx = relpt + bpij * dx
        interpweights = buildInterpWeights(bpx, x, dx, degreep+1)
        interppts = g.sub2ind(bpij + stencil)

        ii.extend([c]*stencilsize)
        jj.extend(interppts)
        aij.extend(interpweights)
    #TODO: does this work with float96?
    E = coo_matrix( (aij,(ii,jj)), shape=(len(g.band),g.nx*g.ny), dtype=mytype )

    # TODO: return this info as well:
    from numpy import unique
    band2 = unique(jj)
    print (len(jj),len(band2),len(g.band))
    print "  E row " + str(len(g.band))
    print "elapsed time = " + str(time() - st)
    #return E.tocsr()
    #E2 = E.tocsr()
    #EE = E2[:,band2]
    return (E.tocsr(), band2)