Beispiel #1
0
    def __init__(self, A, **kwargs):
        PysparseDirectSolver.__init__(self, A, **kwargs)

        if 'strategy' in kwargs.keys():
            strategy = upper(kwargs.get('strategy'))
            if strategy not in ['AUTO', 'UNSYMMETRIC', 'SYMMETRIC', '2BY2']:
                strategy = 'AUTO'
            kwargs['strategy'] = 'UMFPACK_STRATEGY_' + strategy

        if 'scale' in kwargs.keys():
            scale = upper(kwargs.get('scale'))
            if scale not in ['NONE', 'SUM', 'MAX']: scale = 'SUM'
            kwargs['scale'] = 'UMFPACK_SCALE_' + scale
        
        self.type = numpy.float
        self.nrow, self.ncol = A.getShape()
        t = cputime()
        self.LU = umfpack.factorize(A.matrix, **kwargs)
        self.factorizationTime = cputime() - t
        self.solutionTime = 0.0
        self.sol = None
        self.L = self.U = None
        self.P = self.Q = self.R = None
        self.do_recip = False
        self.lnz = self.unz = self.nz_udiag = None
        return
Beispiel #2
0
    def SolveNextTime(self):
        r"""
        Calculate the next time (factorization)
        and update the time stack grids
        """

        try:
            self.tstep += 1
        except:
            self.tstep = 0
            self.LinearSystem()
            self.mUtLU = umfpack.factorize(
                self.mUt, strategy="UMFPACK_STRATEGY_SYMMETRIC")
            # gets the m factor from the solved system

        # As t is in [0, 1, 2] (2nd order)
        # time t in this case is Utime[2]
        # the independent term of the matrix, due the pressure field
        v = self.Independent()
        result = np.empty(self.Nx * self.Nz)
        self.mUtLU.solve(v, result)
        # reshape the vector to become a matrix again
        self.Ufuture = np.reshape(result, (self.Nz, self.Nx))

        # make the update in the time stack
        # before [t-2, t-1,  t]
        # after  [t-1, t,  t+1]
        # so t-2 receive t-1 and etc.
        # make the update in the time stack
        self.Uprevious[:][:] = self.Ucurrent[:][:]
        self.Ucurrent[:][:] = self.Ufuture[:][:]

        return self.Ufuture
Beispiel #3
0
    def __init__(self, A, **kwargs):
        PysparseDirectSolver.__init__(self, A, **kwargs)

        if 'strategy' in kwargs.keys():
            strategy = upper(kwargs.get('strategy'))
            if strategy not in ['AUTO', 'UNSYMMETRIC', 'SYMMETRIC', '2BY2']:
                strategy = 'AUTO'
            kwargs['strategy'] = 'UMFPACK_STRATEGY_' + strategy

        if 'scale' in kwargs.keys():
            scale = upper(kwargs.get('scale'))
            if scale not in ['NONE', 'SUM', 'MAX']: scale = 'SUM'
            kwargs['scale'] = 'UMFPACK_SCALE_' + scale

        self.type = numpy.float
        self.nrow, self.ncol = A.getShape()
        t = cputime()
        self.LU = umfpack.factorize(A.matrix, **kwargs)
        self.factorizationTime = cputime() - t
        self.solutionTime = 0.0
        self.sol = None
        self.L = self.U = None
        self.P = self.Q = self.R = None
        self.do_recip = False
        self.lnz = self.unz = self.nz_udiag = None
        return
    def SolveNextTime(self):
        r"""
        Calculate the next time (factorization)
        and update the time stack grids
        """

        try:
            self.tstep += 1
        except :
            self.tstep = 0
            self.LinearSystem()
            self.mUtLU = umfpack.factorize(self.mUt, strategy="UMFPACK_STRATEGY_SYMMETRIC")
            # gets the m factor from the solved system

        # As t is in [0, 1, 2] (2nd order)
        # time t in this case is Utime[2]
        # the independent term of the matrix, due the pressure field
        v = self.Independent()
        result = np.empty(self.Nx*self.Nz)
        self.mUtLU.solve(v, result)
        # reshape the vector to become a matrix again
        self.Ufuture = np.reshape(result, (self.Nz, self.Nx))        

        # make the update in the time stack
        # before [t-2, t-1,  t]
        # after  [t-1, t,  t+1]
        # so t-2 receive t-1 and etc.
        # make the update in the time stack
        self.Uprevious[:][:] = self.Ucurrent[:][:]
        self.Ucurrent[:][:] = self.Ufuture[:][:]        
        
        return self.Ufuture
Beispiel #5
0
l[0,0] = 2.0
l[0,1] = 3.0
l[1,4] = 6.0
l[1,0] = 3.0
l[1,2] = 4.0
l[2,1] = -1.0
l[2,2] = -3.0
l[2,3] = 2.0
l[3,2] = 1.0
l[4,1] = 4.0
l[4,2] = 2.0
l[4,4] = 1.0

b = np.array([8.0, 45.0, -3.0, 3.0, 19.0], "d")
x = np.zeros(5, "d")
umf = umfpack.factorize(l)
umf.solve(b, x, 'UMFPACK_A')
print umf.getlists()
print x

print "------------------------------"

n = 50
L = poisson2d_vec_sym_blk(n)
b = np.ones(n * n, 'd')
x = np.empty(n * n, 'd')
umf = umfpack.factorize(L)
umf.solve(b, x, 'UMFPACK_A')

r = np.empty(n * n, 'd')
L.matvec(x, r)
from pysparse.sparse import spmatrix
from pysparse.direct import umfpack
import numpy
n = 100
A = poisson2d_sym_blk(n)
b = numpy.ones(n*n)
x = numpy.empty(n*n)
LU = umfpack.factorize(A, strategy="UMFPACK_STRATEGY_SYMMETRIC")
LU.solve(b, x)
Beispiel #7
0
l[0, 0] = 2.0
l[0, 1] = 3.0
l[1, 4] = 6.0
l[1, 0] = 3.0
l[1, 2] = 4.0
l[2, 1] = -1.0
l[2, 2] = -3.0
l[2, 3] = 2.0
l[3, 2] = 1.0
l[4, 1] = 4.0
l[4, 2] = 2.0
l[4, 4] = 1.0

b = np.array([8.0, 45.0, -3.0, 3.0, 19.0], "d")
x = np.zeros(5, "d")
umf = umfpack.factorize(l)
umf.solve(b, x, 'UMFPACK_A')
print umf.getlists()
print x

print "------------------------------"

n = 50
L = poisson2d_vec_sym_blk(n)
b = np.ones(n * n, 'd')
x = np.empty(n * n, 'd')
umf = umfpack.factorize(L)
umf.solve(b, x, 'UMFPACK_A')

r = np.empty(n * n, 'd')
L.matvec(x, r)
Beispiel #8
0
from pysparse.sparse import spmatrix
from pysparse.direct import umfpack
import numpy
n = 100
A = poisson2d_sym_blk(n)
b = numpy.ones(n * n)
x = numpy.empty(n * n)
LU = umfpack.factorize(A, strategy="UMFPACK_STRATEGY_SYMMETRIC")
LU.solve(b, x)