
    _-PhJ                     6    d Z ddlZddlmZmZ ddlmZ ddZdS )zTentative prolongator.    N)isspmatrix_csr
bsr_matrix)amg_core绽|=c                 @   t          |           st          d          t          j        |          }|j        dvrt          j        |d          }t          |j                  dk    rt          d          |j        d         | j        d         z  dk    r t          d| j         d	|j         d
          | j        \  }}t          |j        d         |z            }|j        d         }t          j	        |||f|j                  }t          j	        | j
        ||f|j                  }|                                 }	t          j        }
 |
|||||	j        |	j        |                                |                                |                                |
  
         t#          |                    dd                                          |	j        |	j        f||z  ||z  f          }|j                                        }|                    d|          }||fS )a  Fit near-nullspace candidates to form the tentative prolongator.

    Parameters
    ----------
    AggOp : csr_matrix
        Describes the sparsity pattern of the tentative prolongator.
        Has dimension (#blocks, #aggregates)
    B : array
        The near-nullspace candidates stored in column-wise fashion.
        Has dimension (#blocks * blocksize, #candidates)
    tol : scalar
        Threshold for eliminating local basis functions.
        If after orthogonalization a local basis function Q[:, j] is small,
        i.e. ||Q[:, j]|| < tol, then Q[:, j] is set to zero.

    Returns
    -------
    (Q, R) : (bsr_matrix, array)
        The tentative prolongator Q is a sparse block matrix with dimensions
        (#blocks * blocksize, #aggregates * #candidates) formed by dense blocks
        of size (blocksize, #candidates).  The coarse level candidates are
        stored in R which has dimensions (#aggregates * #candidates,
        #candidates).

    See Also
    --------
    amg_core.fit_candidates

    Notes
    -----
        Assuming that each row of AggOp contains exactly one non-zero entry,
        i.e. all unknowns belong to an aggregate, then Q and R satisfy the
        relationship B = Q*R.  In other words, the near-nullspace candidates
        are represented exactly by the tentative prolongator.

        If AggOp contains rows with no non-zero entries, then the range of the
        tentative prolongator will not include those degrees of freedom. This
        situation is illustrated in the examples below.

    References
    ----------
    .. [1] Vanek, P. and Mandel, J. and Brezina, M.,
       "Algebraic Multigrid by Smoothed Aggregation for
       Second and Fourth Order Elliptic Problems",
       Computing, vol. 56, no. 3, pp. 179--196, 1996.
       http://citeseer.ist.psu.edu/vanek96algebraic.html


    Examples
    --------
    >>> from scipy.sparse import csr_matrix
    >>> from pyamg.aggregation.tentative import fit_candidates
    >>> # four nodes divided into two aggregates
    ... AggOp = csr_matrix( [[1, 0],
    ...                      [1, 0],
    ...                      [0, 1],
    ...                      [0, 1]] )
    >>> # B contains one candidate, the constant vector
    ... B = [[1],
    ...      [1],
    ...      [1],
    ...      [1]]
    >>> Q, R = fit_candidates(AggOp, B)
    >>> Q.toarray()
    array([[0.70710678, 0.        ],
           [0.70710678, 0.        ],
           [0.        , 0.70710678],
           [0.        , 0.70710678]])
    >>> R
    array([[1.41421356],
           [1.41421356]])
    >>> # Two candidates, the constant vector and a linear function
    ... B = [[1, 0],
    ...      [1, 1],
    ...      [1, 2],
    ...      [1, 3]]
    >>> Q, R = fit_candidates(AggOp, B)
    >>> Q.toarray()
    array([[ 0.70710678, -0.70710678,  0.        ,  0.        ],
           [ 0.70710678,  0.70710678,  0.        ,  0.        ],
           [ 0.        ,  0.        ,  0.70710678, -0.70710678],
           [ 0.        ,  0.        ,  0.70710678,  0.70710678]])
    >>> R
    array([[1.41421356, 0.70710678],
           [0.        , 0.70710678],
           [1.41421356, 3.53553391],
           [0.        , 0.70710678]])
    >>> # aggregation excludes the third node
    ... AggOp = csr_matrix( [[1, 0],
    ...                      [1, 0],
    ...                      [0, 0],
    ...                      [0, 1]] )
    >>> B = [[1],
    ...      [1],
    ...      [1],
    ...      [1]]
    >>> Q, R = fit_candidates(AggOp, B)
    >>> Q.toarray()
    array([[0.70710678, 0.        ],
           [0.70710678, 0.        ],
           [0.        , 0.        ],
           [0.        , 1.        ]])
    >>> R
    array([[1.41421356],
           [1.        ]])

    z&expected csr_matrix for argument AggOp)float32float64	complex64
complex128r	   )dtype   z expected 2d array for argument Br   zDimensions of AggOp z and B z are incompatible   )shape)r   	TypeErrornpasarrayr   lenr   
ValueErrorintemptynnztocscr   fit_candidatesindptrindicesravelr   swapaxescopyTtobsrreshape)AggOpBtolN_fineN_coarseK1K2RQx	AggOp_cscfnQs               [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyamg/aggregation/tentative.pyr   r   	   s   X %   B@AAA

1AwGGGJq	***
17||q;<<<wqzEKN"a'' , , ,AG , , , - - 	- {FH	QWQZ& 	!	!B	
B 	(B#17333A	59b"%QW	5	5	5BI		 BBvxR*BHHJJwwyy!''))S" " " 	BKK1%%**,,i.?$&.0k2f9-E	G 	G 	GA			A			"bAa4K    )r   )	__doc__numpyr   scipy.sparser   r   pyamgr   r    r0   r/   <module>r6      sg          3 3 3 3 3 3 3 3      O O O O O Or0   