
    _-Phd$                        d Z ddlmZ ddlZddlmZmZ ddlm	Z	 ddl
m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mZmZ ddlmZmZmZm Z m!Z! ddl"m#Z# ddddfdddifdddddfddddddddfddddf
dZ$d Z%dS ) z"Approximate idealkrestriction AMG.    )deepcopyN)isspmatrix_csrisspmatrix_bsr   )MultilevelSolver)change_smoothers) classical_strength_of_connection symmetric_strength_of_connection evolution_strength_of_connectiondistance_strength_of_connectionalgebraic_distanceaffinity_distance#energy_based_strength_of_connection)filter_matrix_rows)direct_interpolationclassical_interpolationinjection_interpolationone_point_interpolation	local_air   )RSPMISPMIScCLJPCLJPc)CR	classicalg333333?min)thetanormr   second_passT	one_pointairg?)r   degree	fc_jacobig      ?F)omega
iterationswithrhof_iterationsc_iterations   c           	      >   |                                  } | j        d         | j        d         k    rt          d          t          j        | j                  rt          d          t          j                    g}| |d         _        t          |          |k     rc|d         j        j        d         |	k    rGt          |||||||
          }|rn/t          |          |k     r|d         j        j        d         |	k    Gt          |fi |}t          |||           |S )uF  Create a multilevel solver using approximate ideal restriction (AIR) AMG.

    Parameters
    ----------
    A : csr_matrix
        Square (non)symmetric matrix in CSR format
    strength : ['symmetric', 'classical', 'evolution', 'distance',
                'algebraic_distance','affinity', 'energy_based', None]
        Method used to determine the strength of connection between unknowns
        of the linear system.  Method-specific parameters may be passed in
        using a tuple, e.g. strength=('symmetric',{'theta' : 0.25 }). If
        strength=None, all nonzero entries of the matrix are considered strong.
    CF : {string} : default 'RS' with second pass
        Method used for coarse grid selection (C/F splitting)
        Supported methods are RS, PMIS, PMISc, CLJP, CLJPc, and CR.
    interpolation : {string} : default 'one_point'
        Options include 'direct', 'classical', 'inject' and 'one-point'.
    restrict : {string} : default distance-2 AIR, with theta = 0.05.
        Option is 'air' for local approximate ideal restriction (lAIR),
        with inner options specifying degree, strength tolerance, etc.
    presmoother : {string or dict} : default None
        Method used for presmoothing at each level.  Method-specific parameters
        may be passed in using a tuple.
    postsmoother : {string or dict}
        Postsmoothing method with the same usage as presmoother.
        postsmoother=('fc_jacobi', ... ) with 2 F-sweeps, 1 C-sweep is default.
    filter_operator : (bool, tol) : default None
        Remove small entries in operators on each level if True. Entries are
        considered "small" if |a_ij| < tol |a_ii|.
    max_levels: {integer} : default 20
        Maximum number of levels to be used in the multilevel solver.
    max_coarse: {integer} : default 20
        Maximum number of variables permitted on the coarse grid.
    keep: {bool} : default False
        Flag to indicate keeping strength of connection matrix (C) in
        hierarchy.

    Returns
    -------
    ml : multilevel_solver
        Multigrid hierarchy of matrices and prolongation operators

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg import air_solver
    >>> A = poisson((10,),format='csr')
    >>> ml = air_solver(A,max_coarse=3)

    Notes
    -----
    "coarse_solver" is an optional argument and is the solver used at the
    coarsest grid.  The default is a pseudo-inverse.  Most simply,
    coarse_solver can be one of ['splu', 'lu', 'cholesky, 'pinv',
    'gauss_seidel', ... ].  Additionally, coarse_solver 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.
    See [2001TrOoSc]_ for additional details.


    References
    ----------
    [1] Manteuffel, T. A., Münzenmaier, S., Ruge, J., & Southworth, B. S.
    (2019). Nonsymmetric reduction-based algebraic multigrid. SIAM
    Journal on Scientific Computing, 41(5), S242-S268.

    [2] Manteuffel, T. A., Ruge, J., & Southworth, B. S. (2018).
    Nonsymmetric algebraic multigrid based on local approximate ideal
    restriction (lAIR). SIAM Journal on Scientific Computing, 40(6),
    A4105-A4130.

    See Also
    --------
    aggregation.smoothed_aggregation_solver, multilevel_solver,
    aggregation.rootnode_solver, ruge_stuben_solver

    r   r   zexpected square matrixz,AIR solver not verified for complex matrices)asfptypeshape
ValueErrornpiscomplexobjdatar   LevelAlenextend_hierarchyr   )r5   strengthCFinterpolationrestrictpresmootherpostsmootherfilter_operator
max_levels
max_coarsekeepkwargslevelsbottommls                  S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyamg/classical/air.py
air_solverrG      s#   t 	


AwqzQWQZ1222	qv IGHHH$&&'FF2JL
f++

"
"vbz|'9!'<z'I'I!&(Bx"149 9 		 f++

"
"vbz|'9!'<z'I'I 
&	+	+F	+	+BRl333I    c                 H   d }|g|d         dk    r[t          |           dk    rt          | d         j                  }n| d         j        }t          ||d         d|d                    n| d         j        }|j        |j        d         k    rdS  ||          \  }	}
|	dk    rt          |fi |
}n|	d	k    rt          |fi |
}ny|	d
k    rt          |fi |
}ne|	dv rt          |fi |
}nS|	dk    rt          |fi |
}n?|	dk    rt          |fi |
}n+|	dk    rt          |fi |
}n|	|}nt          d|	            ||          \  }	}
|	dk    rt          |fi |
}nv|	dk    rt          |fi |
}nb|	dk    rt!          |fi |
}nN|	dk    rt#          |fi |
}n:|	dk    rt%          |fi |
}n&|	dk    rt'          |fi |
}nt          d|           t)          j        |          }|t          |          k    s|dk    rdS  ||          \  }	}
|	d	k    rt-          |||fi |
}nS|	dk    rt/          |||fi |
}n=|	dk    rt1          |||fi |
}n'|	dk    rt3          ||fi |
}nt          d|	            ||          \  }	}
|	dk    rt5          ||fi |
}nt          d|	           |r|| d         _        |                    t:                    | d         _        || d         _        || d         _         ||z  |z  }tC          |          r$tC          |          s|"                                }n2tG          |          r#tG          |          s|$                                }| %                    tM          j'                               || d         _        dS )zExtend the multigrid hierarchy.c                 T    t          | t                    r| d         | d         fS | i fS )Nr   r   )
isinstancetuple)vs    rF   
unpack_argz$extend_hierarchy.<locals>.unpack_arg   s/    a 	Q41:"urH   Nr   r   r-   T)diagonallump	symmetricr   distance)ode	evolutionenergy_basedr   affinityz,Unrecognized strength of connection method: r   r   r   r   r   r   zUnknown C/F splitting method directr"   injectzUnknown interpolation method r#   zUnknown restriction method )(r6   r   r5   r   nnzr/   r
   r	   r   r   r   r   r   r0   r   r   r   r   r   r   r1   sumr   r   r   r   r   Castypebool	splittingPRr   tocsrr   tobsrappendr   r4   )rC   r8   r9   r:   r;   r>   rA   rN   r5   fnrB   r[   r^   num_fptsr_   r`   s                   rF   r7   r7      s      	#/!*<*A*Av;;!&&AAr
A1oa04oVWFXYYYYY2JL 	u
q H%%JB	[,Q99&99	{		,Q99&99	z		+A8888	#	#	#,Q99&99	~		/<<V<<	#	#	#q++F++	z		a**6**	LLLMMM BJB	TzzqOOFOO			v%%f%%			w!&&v&&			v%%f%%			w!&&v&&			tqOOFOO		===>>> vi  HC	NN""Aq M**JB	[#Aq)>>v>>	x Ay;;F;;	{		#Aq)>>v>>	x#Ay;;F;;===>>> H%%JB	U{{a--f--;r;;<<<  r
$++D11F2JF2JLF2JL 	
A	A 	q >!#4#4 GGII


 ^A%6%6 GGII
MM"(**+++F2JL1rH   )&__doc__copyr   numpyr1   scipy.sparser   r   
multilevelr   relaxation.smoothingr   r8   r	   r
   r   r   r   r   r   
util.utilsr   classical.interpolater   r   r   r   r   splitr   r   r   r   r   crr   rG   r7    rH   rF   <module>rq      s    ( (           7 7 7 7 7 7 7 7 ) ) ) ) ) ) 3 3 3 3 3 3P P P P P P P P P P P P P P P P P P , + + + + +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 / / / / / / / / / / / / /       %U&C&CD-./($! < <=(Cq6;Q;<+> +> ?  $k k k k\j j j j jrH   