
    _-Ph}                     X   d Z ddlmZ ddlZddlmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZmZ dd
lmZmZmZ ddlmZmZ ddlm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 d%dZ1d Z2dddddddddddddifdi fddd d!difd fd"Z3	 d&d#Z4d$ Z5dS )'zAdaptive Smoothed Aggregation.    )warnN)
csr_matrix
bsr_matrixisspmatrix_csrisspmatrix_cscisspmatrix_bsreyeSparseEfficiencyWarning   )MultilevelSolver) symmetric_strength_of_connection classical_strength_of_connection evolution_strength_of_connection)gmres)normapproximate_spectral_radius)
amalgamate levelize_strength_or_aggregation%levelize_smooth_or_improve_candidates)change_smoothersrho_D_inv_A)gauss_seidelgauss_seidel_nrgauss_seidel_negauss_seidel_indexedjacobi
polynomial   )smoothed_aggregation_solver)standard_aggregationlloyd_aggregation)jacobi_prolongation_smootherenergy_prolongation_smoother richardson_prolongation_smoother)fit_candidates      ?c                 h   t          |          st          |          st          d          |r	 |                                }t	          | j                  }t          ||j        d         z            }d }d }	| |	||| ||          z  }
 || |||          |
k    }| ||j        | z  z  z
  } |||||          |
k    }t          j	        ||z             
                                d         }|j        d         dk    r.||dd|f         j        z  }t          |          D ]}d| ||z   <   dS dS )a  Eliminate candidates locally.

    Helper function that determines where to eliminate candidates locally
    on a per aggregate basis.

    Parameters
    ----------
    x : array
        n x 1 vector of new candidate
    AggOp : CSR or CSC sparse matrix
        Aggregation operator for the level that x was generated for
    A : sparse matrix
        Operator for the level that x was generated for
    T : sparse matrix
        Tentative prolongation operator for the level that x was generated for
    thresh : scalar
        Constant threshold parameter to decide when to drop candidates

    Returns
    -------
    Nothing, x is modified in place

    z!AggOp must be a CSR or CSC matrixr   c                 V   t          j        |           t          j        |           z  } t          j        d|j        d         f| j                  }t          |          D ]3}|| t          |||                                       dd          |z  z  }4|                    dd          S )zInner products per aggregate.

        Helper function that calculates <z, z>_i, i.e., the
        inner product of z only over aggregate i
        Returns a vector of length num_aggregates where entry i is <z, z>_i

        r   dtype)npravelzerosshaper*   rangeslicereshape)zAggOpnpdendofinnerpjs         Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyamg/aggregation/adaptive.pyaggregate_wise_inner_productz@eliminate_local_candidates.<locals>.aggregate_wise_inner_product;   s     HQKK#1ek!n-QW===t 	E 	EAaat,,-55a<<uDDFF~~b!$$$    c                 d   |}t          |          }t          j        |                    dd          ||                    dd          z            }|| j        dd         | j        dd         z
  z  }t          j        |          |z  |j        d         |z  z  }	|	                    dd          S )zWeights per aggregate.

        Calculate local aggregate quantities
        Return a vector of length num_aggregates where entry i is
        (card(agg_i)/A.shape[0]) ( <Az, z>/rho(A) )

        r   r+   Nr   )r   r,   dotr2   indptrr-   r/   )
r4   Ar3   r5   r6   _rhozAzcardweightss
             r9   get_aggregate_weightsz9eliminate_local_candidates.<locals>.get_aggregate_weightsJ   s     )!,,fQYYq"%%q2q)9)9'9::u|ABB'SbS(99:8D>>#%
37r1%%%r;   Ng        )r   r   	TypeErrortocscmaxr/   intTr,   r-   nonzeroindicesr0   )xr4   r?   rJ   threshkwargsr6   r5   r:   rE   rD   mask1projected_xmask2maskr8   s                   r9   eliminate_local_candidatesrT      s   0 5!! =^E%:%: =;<<< KKMMEqw<<DtEKN"##D% % %& & &  ,,UAq$EEEG((E4>>'IE aQi-K(().d< <?FGE 8EEM""**,,Q/Dz!}qeAAAtGn,,t 	 	AAd1fII 	 	r;   c                 T    t          | t                    r| d         | d         fS | i fS )zUse for local methods.r   r   )
isinstancetuple)vs    r9   
unpack_argrY   k   s/    !U tQqTzb5Lr;   	hermitianT   g?
   standardr   sweep	symmetricr   pinvFrN   c                 
   t          |           sWt          |           sH	 t          |           } t          dt                     n"# t
          $ r}t          d          |d}~ww xY w|                                 } | j        d         | j        d         k    rt          d          t          j        d          }t          |||	          \  }}	}t          |
||	          \  }}	}
t          ||          }|:t          | ||||||	|
||||          \  }}
}dt          |d	          z  |z  }|dz  }n|}||j        d         z  }t!          | f||||||||	|
|dd
d|t#          j                  dk    r`fdt'          t#          j                  dz
            D             }
fdt'          t#          j                  dz
            D             }t'          |          D ]}t)          t!          | f|||||||
|dd
d
||||||||          }|t          |d	          z  }t          j        |d                   st          j        |d                   rt          d| d          t          j        ||                    dd          f          }|j        d         dk    r|dk    rt          j        | j        d         df| j                  }t'          |          D ]}t'          |j        d                   D ]n}|dddf         }|ddddf         }t!          | f|||||||
|dd
d
|}|                    ||d|d          }|ddxx         d|                                z  |j        d         j        j        z  |z  z  cc<   t=          |          \  }}|d
u rC|t          |d	          z  }t?          ||j        d         j         | |j        d         j!        fi | |t          |d	          z  }t          j        |d                   st          j        |d                   rt          d| d          t          j        ||                    dd          f          }pnb|dk    r\t#          |
          dz   }d}	t'          |          D ]8}t          | ||||||	|
|||||          \  }}
}dt          |d	          z  |z  }9t!          | f|||||||
|d|d
||d         | j        z  gS )a  Create a multilevel solver using Adaptive Smoothed Aggregation (aSA).

    Parameters
    ----------
    A : csr_matrix, bsr_matrix
        Square matrix in CSR or BSR format
    initial_candidates : None, n x m dense matrix
        If a matrix, then this forms the basis for the first m candidates.
        Also in this case, the initial setup stage is skipped, because this
        provides the first candidate(s).  If None, then a random initial guess
        and relaxation are used to inform the initial candidate.
    symmetry : string
        'symmetric' refers to both real and complex symmetric
        'hermitian' refers to both complex Hermitian and real Hermitian
        Note that for the strictly real case, these two options are the same
        Note that this flag does not denote definiteness of the operator
    pdef : bool
        True or False, whether A is known to be positive definite.
    num_candidates : integer
        Number of near-nullspace candidates to generate
    candidate_iters : integer
        Number of smoothing passes/multigrid cycles used at each level of
        the adaptive setup phase
    improvement_iters : integer
        Number of times each candidate is improved
    epsilon : float
        Target convergence factor
    max_levels : integer
        Maximum number of levels to be used in the multilevel solver.
    max_coarse : integer
        Maximum number of variables permitted on the coarse grid.
    prepostsmoother : string or dict
        Pre- and post-smoother used in the adaptive method
    strength : ['symmetric', 'classical', 'evolution', None]
        Method used to determine the strength of connection between unknowns of
        the linear system.  See smoothed_aggregation_solver(...) documentation.
        Predefined strength may be used with ('predefined', {'C': csr_matrix}).
    aggregate : ['standard', 'lloyd', 'naive', ('predefined', {'AggOp': csr_matrix})]
        Method used to aggregate nodes.  See smoothed_aggregation_solver(...)
        documentation.
    smooth : ['jacobi', 'richardson', 'energy', None]
        Method used used to smooth the tentative prolongator.  See
        smoothed_aggregation_solver(...) documentation
    coarse_solver : ['splu', 'lu', 'cholesky, 'pinv', 'gauss_seidel', ... ]
        Solver used at the coarsest level of the MG hierarchy.
        Optionally, may be a tuple (fn, args), where fn is a string such as
        ['splu', 'lu', ...] or a callable function, and args is a dictionary of
        arguments to be passed to fn.
    eliminate_local : tuple
        Length 2 tuple.  If the first entry is True, then eliminate candidates
        where they aren't needed locally, using the second entry of the tuple
        to contain arguments to local elimination routine.  Given the rigid
        sparse data structures, this doesn't help much, if at all, with
        complexity.  Its more of a diagnostic utility.
    keep : bool
        Flag to indicate keeping extra operators in the hierarchy for
        diagnostics.  For example, if True, then strength of connection (C),
        tentative prolongation (T), and aggregation (AggOp) are kept.

    Returns
    -------
    MultilevelSolver : MultilevelSolver
        Smoothed aggregation solver with adaptively generated candidates

    Notes
    -----
    - Floating point value representing the 'work' required to generate
      the solver.  This value is the total cost of just relaxation, relative
      to the fine grid.  The relaxation method used is assumed to symmetric
      Gauss-Seidel.

    - Unlike the standard Smoothed Aggregation (SA) method, adaptive SA does
      not require knowledge of near-nullspace candidate vectors.  Instead, an
      adaptive procedure computes one or more candidates 'from scratch'.  This
      approach is useful when no candidates are known or the candidates have
      been invalidated due to changes to matrix A.

    Examples
    --------
    >>> from pyamg.gallery import stencil_grid
    >>> from pyamg.aggregation import adaptive_sa_solver
    >>> import numpy as np
    >>> A=stencil_grid([[-1,-1,-1],[-1,8.0,-1],[-1,-1,-1]], (31,31),format='csr')
    >>> [asa,work] = adaptive_sa_solver(A,num_candidates=1)
    >>> res=[]
    >>> x=asa.solve(b=np.ones((A.shape[0],)), x0=np.ones((A.shape[0],)), residuals=res)

    References
    ----------
    .. [1] Brezina, Falgout, MacLachlan, Manteuffel, McCormick, and Ruge
       "Adaptive Smoothed Aggregation (alpha SA) Multigrid"
       SIAM Review Volume 47,  Issue 2  (2005)

    zImplicit conversion of A to CSRzSArgument A must have type csr_matrix or bsr_matrix, or be convertible to csr_matrixNr   r   zexpected square matrix)r   r&   infT)Bsymmetrypresmootherpostsmoothersmoothstrength
max_levels
max_coarse	aggregatecoarse_solverimprove_candidateskeepc                 `    g | ]*}d dj         |         j                                        if+S 
predefinedr4   )levelsr4   tocsr.0isas     r9   
<listcomp>z&adaptive_sa_solver.<locals>.<listcomp>  sH     = = = '")A,2D2J2J2L2L(MN = = =r;   c                 `    g | ]*}d dj         |         j                                        if+S rq   C)rr   r{   rs   rt   s     r9   rx   z&adaptive_sa_solver.<locals>.<listcomp>  sG     < < < &RYq\^-A-A-C-C'DE < < <r;   )
rc   rd   re   rf   rg   rl   rk   rh   rm   rn   zThe zth adaptive candidate is all 0.r+   r)   #B;V)x0tolmaxitercycler   z(th improved adaptive candidate is all 0.)initial_candidate)"r   r   r   r   r
   	ExceptionrF   asfptyper/   
ValueErrorr,   r.   r   r   initial_setup_stager   r   lenrr   r0   general_setup_stageisinfisnanhstackr2   r*   solveoperator_complexityr?   nnzrY   rT   r4   rJ   )r?   initial_candidatesrd   pdefnum_candidatescandidate_itersimprovement_itersepsilonri   rj   rk   prepostsmootherrg   rh   rl   eliminate_localrn   rO   eworkrc   rv   rM   b_ir8   r~   sa_tempelimelim_kwargsrw   s                                 @r9   adaptive_sa_solverr   r   s   P 1 R!2!2 R	R1A24KLLLL 	R 	R 	R J K KPQR	R 	


AwqzQWQZ1222 8D>>D
 	):zJJ %J
H 	)J
KK &J
I26:FFF !8T?G *J	 /4I I 	9h
 a1$! !'!*$( 	3a(5D6E064>4>3<7D<@t	3 	3 ,2	3 	3 ry>>A= = = ="'BI(:";";= = =I< < < <!&s29~~'9!:!:< < <H >"" - -' =Q4C5D/56C2;19;?-1= = 6<= = o]D2 2 d1enn8AaD>> 	HRXad^^ 	HFAFFFGGGIq!))B**+,, 	wqzA~~+a//Hagaj!_AG444)** "	5 "	5B171:&& !5 !5 qqq!tWaaaeH/ EQ<K=L7=>K:C9ACG59E E >DE E  MM!&+*9 " F F QQQ1w::<<<N1%'+,.=> > %/$?$?!k4<<$q%..(A.q'.2C2I1/6~a/@/B> >1<> > >
 d1enn$8AaD>> YRXad^^ Y$%WA%W%W%WXXXIq!))B"2"2344C!5"	5H 
Q		^^a'

)** 	' 	'B#Ax$+Z$-$,daI I I #Ay( T!U^^#Q&AA' 2Q4C5D/56C2;h;?d2 2 +12 2 GAEM s   $A 
A%A  A%c           	        !" fd}d}| }|t           j                            |j        d         d                              |j                  }|j        j                            d          r1|dt           j                            |j        d         d          z  z   }nt          j        ||j                  } |||           |ddxx         |j	        z  d	z  z  cc<   | g}|g}g }g !g "| j        d         |k    rs|dk    rlt          |
t          |          dz
                     \  }}|d
k    r9t          |fi |}|t          |j        d         |j        d         d          z   }n|dk    rct          |fi |}|t          |j        d         |j        d         d          z   }t          |          rt!          ||j        d                   }n|dv r5t%          |t          j        |j        d         df| j                  fi |}nW|dk    r|d                                         }n6||                                }nt+          dt-          |                     |j        j                            d          rt          j        |j                  |_        |dv rd|j        z  |_        t          |t          |          dz
                     \  }}|dk    rt3          |fi |d         }nZ|dk    rt5          |fi |d         }n@|dk    r|d                                         }nt+          dt-          |                     t7          ||          \  }}t          |	t          |          dz
                     \  }}|dk    rt9          ||||fi |}nT|dk    rt;          ||fi |}n?|dk    rt=          ||||ddi ffi |}n$||}nt+          dt-          |                     |d
k    r&|j                             |j!                  |z  |z  }nQ|dk    r8|j        "                                                     |j!                  |z  |z  }nt+          d| d          "#                    |           !#                    |           |#                    |           |#                    |           |j        d         |k    st          !          dz   |k    rn|s'|$                                } |||           |ddxx         |j	        z  d	z  z  cc<   |du rjt          j%        t          j"        |          j        ||z            }t          j%        t          j"        |          j        ||z            }||z  dz  z  }nk||z  }t          j%        t          j"        |          j        |          }t          j%        t          j"        |          j        ||z            }||z  dz  z  }||k     r
d}|dk    r|}n) |||           |ddxx         d	|j	        z  z  z  cc<   |#                    |           | j        d         |k    r|dk    l|d          }tM          t          |          d	z
  d d           D ]@}||         } ||         } | |z  } || |           |ddxx         | j	        z  d	z  z  cc<   At          !          dk    rP!fd!tM          t          !                    D             }"fd"tM          t          "                    D             }
|||
fS )#a0  Compute aggregation and the first near-nullspace candidate.

    Parameters
    ----------
    candidate_iters
        number of test relaxation iterations
    epsilon
        minimum acceptable relaxation convergence factor

    Notes
    -----
    This follows Algorithm 3 in Brezina et al.

    References
    ----------
    .. [1] Brezina, Falgout, MacLachlan, Manteuffel, McCormick, and Ruge
       "Adaptive Smoothed Aggregation (aSA) Multigrid"
       SIAM Review Volume 47,  Issue 2  (2005)
       http://www.cs.umn.edu/~maclach/research/aSA2.pdf

    c           
         t                    \  }}|dk    r(t          | |t          j        |          d           d S |dk    r(t	          | |t          j        |          d           d S |dk    r(t          | |t          j        |          d           d S |dk    r8t          | |t          j        |          ddt          |           z  	           d S |d
k    r9t          | |t          j        |          ddt          |           z  g           d S |dk    rJt          | t          j        |          |          d                             |j                  |d d <   d S t          d          )Nr   r_   
iterationsr^   r   r   r   r   r&   r   omega
richardsonr   coefficientsr   r~   r   r   Unrecognized smoother)rY   r   r,   
zeros_liker   r   r   r   r   r   r   r2   r/   rF   )r?   rM   fnr@   r   r   s       r9   relaxz"initial_setup_stage.<locals>.relax~  s   ?++AAr}Q//$3;H H H H H H$$$Aq"-"2"2'6kK K K K K K$$$Aq"-"2"2'6kK K K K K K8^^1aq))a{1~~-/ / / / / /<q!R]1--!%()DQ)G)G%G$HJ J J J J J7]]!R]1--!"13 3 33467>wqw7G7G aaaDDD 3444r;   TNr   r   complex              ?r)   r   r_   csr)format	classical)ode	evolutionrq   r{   z,Unrecognized strength of connection method: )r   r   energy_basedr&   r]   lloydr4   z Unrecognized aggregation method r   r   energyF+Unrecognized prolongation smoother method: rZ   z!aSA not implemented for symmetry=.r+   c                 (    g | ]}d d|         ifS rp    )ru   rv   AggOpss     r9   rx   z'initial_setup_stage.<locals>.<listcomp>3  s7     2 2 2 #WfQi$89 2 2 2r;   c                 (    g | ]}d d|         ifS rz   r   )ru   rv   StrengthOpss     r9   rx   z'initial_setup_stage.<locals>.<listcomp>5  s7     6 6 6 "CQ#89 6 6 6r;   )'r,   randomrandr/   astyper*   name
startswitharrayr   rY   r   r   r	   r   r   r   	blocksizer   onesrs   r   strabsdatar    r!   r%   r"   r$   r#   rJ   asformatr   	conjugateappendcopyr=   r0   )#r?   rd   r   r   r   ri   rj   rk   r   rg   rh   r   r   r   skip_f_to_iA_lrM   AsxsPsr   rO   C_lr4   T_lP_lx_hatx_A_xxhat_A_xhat	err_ratioAxlevPr   r   s#      `    `                        @@r9   r   r   e  s   25 5 5 5 5 50 K C INN39Q<++2239== 9>$$Y// 	9D	!a8888AH&ci888 
E#qMMMGGGsw(**GGG B
B	BFK
'!*z
!
!j1nn  R 344
F23AA&AACCIaL#)A,uEEEECC;23AA&AACCIaL#)A,uEEEECc"" 8 cmA&677'''233578;	!a7H=>W4F 4F 4F= = 6<	= =CC
 <+##%%CCZ))++CCUCPRGGUUVVV 9>$$Y// 	(vch''CH 555SX~CH  	#b''A+ 677
F(7777:EE7]]%c44V44Q7EE<7O))++EEIBIIJJJq))Qs2wwqy 122
F>>.sCaJJ6JJCC<23FFvFFCC8^^.sCa05r{F F>DF FCCZCCT3r77TTUUU {""%..,,s2S8CC$$%//##,,SZ883>DCCLLLLMMM3e
		#
		# IaLJ&&CKK!Oz,I,I 	5FFHHEE#qMMMGGGsw.q00GGGt||r|A0#a%88 fR\%%8%8%:CIFF";.#o2EF		 1Wr|B//1266 fR\%%8%8%:CIFF";.#o2EF	7"""A::A E#qMMMGGGq37{_44GGG 			!Y '!*z
!
!j1nnb 	2ASWWQYB'' + +sGsGEaQQQ15(** 6{{Q2 2 2 2#CKK002 2 2	6 6 6 6"3{#3#3446 6 6 i!!r;   c                    d }d }	| j         }
t          j                            |
d         j        j        d         d          }|
d         j        j        j                            d          r<|dt          j                            |
d         j        j        d         d          z  z   }t          j	        |          }| 
                    ||d|          }|d	d	xx         |                                 | j         d         j        j        z  |z  d
z  z  cc<   |
d         j                                        }t          t!          | j                   d
z
            D ]}t          j        |
|         j        |                    dd          f          }t)          |
|         j        |          \  }}||
|         _        |d	d	df                             dd          }t-          ||                   \  }}|dk    r2t/          |
|         j        ||
|         j        |fi ||
|         _        n|dk    r%t5          |
|         j        |fi ||
|         _        n|dk    rVt7          |
|         j        ||
|         j        |d	di ffi ||
|         _        |d	d	df                             dd          }n/|||
|         _        nt9          dt;          |                     |dk    rA|
|         j        j                            |
|         j        j                  |
|         _         nX|dk    rR|
|         j        j        !                                                    |
|         j        j                  |
|         _         |
|         j         |
|         j        z  |
|         j        z  |
|dz            _         ||
|dz            j                  }|
|d
z            j        }t-          ||dz                      \  }}|dk    r;t/          |
|dz            j        ||
|dz            j        |fi ||
|dz            _        n|dk    r+t5          |
|dz            j        |fi ||
|dz            _        nw|dk    r?t7          |
|dz            j        ||
|dz            j        |d	di ffi ||
|dz            _        n2|||
|dz            _        nt9          dt;          |                     |dk    rJ|
|dz            j        j                            |
|dz            j        j                  |
|dz            _         na|dk    r[|
|dz            j        j        !                                                    |
|dz            j        j                  |
|dz            _         tE          |
|dz   d	         |          }tG          |||           |
                    t          j	        |          |d|          }|d	d	xx         d
|                                z  |j         d         j        j        z  |z  d
z  z  cc<   |d	d	d	df                                         |
|dz            _        ||
|dz            _        t-          |          \  }}tI          |
d	d                   D ]}|j        |z  }|d	d	xx         |j        j        |z  d
z  z  cc<   |dk    rYt          j%        |          &                                d         }tO          |j        |t          j	        |          ||d           |dk    r,tQ          |j        |t          j	        |          |d           |dk    r,tS          |j        |t          j	        |          |d           |dk    rBtU          |j        |t          j	        |          ddtW          |j                  z             :|dk    rCtY          |j        |t          j	        |          ddt[          |j                  z  g           |dk    rOt]          |j        t          j	        |          ||          d                             |j                  |d	d	<   t_          d           t-          |          \  }}|d!u r9|ta          |d"          z  }tc          ||
d         j        |
d         j        |fi | |                    dd          S )#a#  Compute additional candidates and improvements.

    Parameters
    ----------
    candidate_iters
        number of test relaxation iterations
    epsilon
        minimum acceptable relaxation convergence factor

    Notes
    -----
    Follows Algorithm 4 in Brezina et al.

    References
    ----------
    .. [1] Brezina, Falgout, MacLachlan, Manteuffel, McCormick, and Ruge
       "Adaptive Smoothed Aggregation (alphaSA) Multigrid"
       SIAM Review Volume 47,  Issue 2  (2005)
       http://www.cs.umn.edu/~maclach/research/aSA2.pdf

    c                    | j         \  }}| j        d         }| j        d         }t          j        ||dz   |f| j                  }| j        |d d d dd d f<   t          || j        | j        f|dz   t          ||z            z  |f          S )Nr   r+   r   r)   )r/   )
r/   r   r>   r,   r.   r*   r   r   rL   rI   )rJ   MNKbnnzr   s         r9   make_bridgez(general_setup_stage.<locals>.make_bridgeR  s    w1KNx| xqsAag666&QQQQQQY4AH5"#a%3q1u::!5q 9; ; ; 	;r;   c                 
   | j         d         }t          | j         d         |z            }t          j        ||dz   |f| j                  }|                     |||          |d d d dd d f<   |                    d|          S )Nr   r   r)   r+   )r/   rI   r,   r.   r*   r2   )B_oldnodesizeNullDimnnodesBnews        r9   expand_candidatesz.general_setup_stage.<locals>.expand_candidates]  s     +a.U[^h.//x!W5U[III--'BBQQQQQQY||B(((r;   r   r   r   r   r|   )r~   r   r   Nr   r+   r   r   r   Fr   r_   rZ   z*Unrecognized prolongation smoother method )rl   )re   rf   r   r   r   r   r&   r   r   r   r   r   Trb   )2rr   r,   r   r   r?   r/   r*   r   r   r   r   r   r   rJ   r   r0   r   r   rc   r2   r%   r4   rY   r"   r{   r   r$   r#   r   r   r   r   Rr   r   r   reversedr-   rK   r   r   r   r   r   r   r   r   rF   r   rT   )mlrd   r   r   rg   r   rl   r   r   r   rr   rM   r   T0rv   rc   rJ   r   r   rO   T_bridgeR_bridgesolverlvlrL   r   r   s                              r9   r   r   ;  s	   .	; 	; 	;) ) ) YF
	vay{(+Q//Aay{((33 =RY^^F1IK$5a$8!<<<<
aA
qe( 	 	* 	*AGGGr%%''	!(::?J1LLGGG					B 3ry>>A%&& Y! Y! Ivay{AIIb!$4$4566 fQioq111q	aaaeHR##  q	**
F>>6vay{A7=ay{AA A9?A AF1IKK <:6!9; E E=CE EF1IKK8^^6vay{A7=ay{At8=r{N NFLN NF1IK !!!R%  Q''AAZF1IKKT3r77TTUUU {"" )+-001CDDF1IKK$$ )+-1133<<VAY[=OPPF1IK q	fQik1F1IK?qs ;vac{}--!A#;=  qs,,
F>>8!9A9?!9AM M FLM MF1Q3KMM <<VAaC[]=EG G?EG GF1Q3KMM 8^^8!9A9?!9A4:?	P P IO	P PF1Q3KMM
 Z$F1Q3KMMS#b''SSTTT {"""1Q3KMO44VAaC[]5IJJF1Q3KMM$$"1Q3KMO5577@@!AUVVF1Q3KM "&1,mLLL_&5	7 	7 	7 	7LLq))a"!0  2 2 	QQQ1v11333fmA6F6H6LL 	 !!!SbS&	((qs qs O,,JBss$$ 5 5EAIQQQ359_,Q.. hqkk))++A.G 2=+;+;W,;;P P P P P $$$CE1bmA&6&6'6kK K K K K $$$CE1bmA&6&6'6kK K K K K 8^^35!R]1--!{351113 3 3 3 3 <suaq!1!1a%()DSU)K)K%K$LN N N N N 7]]#%q!1!1a"13 3 33467>wqw7G7G aaaDD 3444 #?33D+t||d1enn"1fQiovay{B 	2 	2%0	2 	2 	2 99Rr;   )r&   )N)6__doc__warningsr   numpyr,   scipy.sparser   r   r   r   r   r	   r
   
multilevelr   rh   r   r   r   krylovr   util.linalgr   r   
util.utilsr   r   r   relaxation.smoothingr   r   relaxation.relaxationr   r   r   r   r   r   aggregationr   rk   r    r!   rg   r"   r#   r$   	tentativer%   rT   rY   r   r   r   r   r;   r9   <module>r      s   $ $          A A A A A A A A A A A A A A A A A A * ) ) ) ) )G G G G G G G G G G       ; ; ; ; ; ; ; ;* * * * * * * * * * @ @ @ @ @ @ @ @> > > > > > > > > > > > > > > > 4 4 4 4 4 4 > > > > > > > >C C C C C C C C C C % % % % % %O O O Od   .2K A)*C"$z(6)0+(>(@'n{%+(-#'?ep p p pj CGS" S" S" S"l    r;   