def SpilsPrecSolve(self, t, u, fu, r, z, gamma, delta, lr, tmp):
        """
        Preconditioner solve routine 
        """

        # Extract the P and pivot arrays from user_data.

        P = self.P
        pivot = self.pivot
        zdata = z.data

        r.Scale(ONE, z)

        # Solve the block-diagonal system Px = r using LU factors stored
        # in P and pivot data in pivot, and return the solution in z.

        for jy in range(MY):
            for jx in range(MX):
                #v =
                #print jx, jy, P[jx,jy,...], pivot[jx,jy,...], zdata[jx,jy,:]
                denseGETRS(P[jx, jy, ...], pivot[jx, jy, ...], zdata[jx,
                                                                     jy, :])
                #print jx, jy, P[jx,jy,...], pivot[jx,jy,...], zdata[jx,jy,:]

        return 0
    def SpilsPrecSolve(self, t, u, fu, r, z, gamma, delta, lr, tmp):
        """
        Preconditioner solve routine 
        """

        # Extract the P and pivot arrays from user_data. 

        P = self.P
        pivot = self.pivot
        zdata = z.data
        
        r.Scale(ONE, z)

        
  
        # Solve the block-diagonal system Px = r using LU factors stored
        # in P and pivot data in pivot, and return the solution in z. 
  
        for jy in range(MY):
            for jx in range(MX):
                #v = 
                #print jx, jy, P[jx,jy,...], pivot[jx,jy,...], zdata[jx,jy,:]
                denseGETRS(P[jx,jy,...], pivot[jx,jy,...], zdata[jx,jy,:])
                #print jx, jy, P[jx,jy,...], pivot[jx,jy,...], zdata[jx,jy,:]
                
        return 0
Example #3
0
def testDenseGET():
    """
    Simple test of denseGETRF and denseGETRS to solve a linear system
    """
    N = 2
    A = np.array([[4.0, 6.0], [3.0, 3.0]], dtype=np.float64, order='F')
    A_sp = np.ascontiguousarray(A)
    P = np.arange(N, dtype=np.int32)
    b = np.ones(N, dtype=np.float64)

    b_sp = linalg.lu_solve(linalg.lu_factor(A_sp), b)

    ret = denseGETRF(A, P)
    assert ret == 0

    denseGETRS(A, P, b)

    assert_allclose(b, b_sp)
    assert ret == 0
Example #4
0
def testDenseGET():
    """
    Simple test of denseGETRF and denseGETRS to solve a linear system
    """
    N = 2
    A = np.array( [[4.0,6.0],[3.0,3.0]], dtype=np.float64, order='F')
    A_sp = np.ascontiguousarray(A)
    P = np.arange( N, dtype=np.int32 )
    b = np.ones( N, dtype=np.float64 )

    b_sp = linalg.lu_solve(linalg.lu_factor(A_sp), b)
    
    ret = denseGETRF(A, P)
    assert ret == 0
    
    denseGETRS(A, P, b)
    
    assert_allclose(b, b_sp)
    assert ret == 0
Example #5
0
    def SpilsPrecSolve(self, tn, c, fc, r, z, gamma, delta, lr, vtemp):
        """
        This routine applies two inverse preconditioner matrices
        to the vector r, using the interaction-only block-diagonal Jacobian
        with block-grouping, denoted Jr, and Gauss-Seidel applied to the
        diffusion contribution to the Jacobian, denoted Jd.
        It first calls GSIter for a Gauss-Seidel approximation to
        ((I - gamma*Jd)-inverse)*r, and stores the result in z.
        Then it computes ((I - gamma*Jr)-inverse)*z, using LU factors of the
        blocks in P, and pivot information in pivot, and returns the result in z.
        """

        r.Scale(ONE, z)

        # call GSIter for Gauss-Seidel iterations

        self.GSIter(gamma, z, vtemp)

        # Do backsolves for inverse of block-diagonal preconditioner factor

        P = self.P
        pivot = self.pivot
        mx = self.mx
        my = self.my
        #ngx = self.ngx
        mp = self.mp
        jigx = self.jigx
        jigy = self.jigy

        iv = 0
        for jy in range(my):
            igy = jigy[jy]
            for jx in range(mx):
                igx = jigx[jx]
                #ig = igx + igy*ngx
                denseGETRS(P[igx, igy, ...], mp, pivot[igx, igy, :],
                           z.data[iv])
                iv += mp

        return 0