+
     ]iz3  c                   s\    R t ^ RIt^ RIHt ^ RIHt ^ RIt ! R R4      t ! R R]4      t	R# )z'
Mesh refinement for triangular grids.
N)_api)Triangulationc                   s*   a  ] tR t^t o RtR tRtV tR# )
TriRefinera+  
Abstract base class for classes implementing mesh refinement.

A TriRefiner encapsulates a Triangulation object and provides tools for
mesh refinement and interpolation.

Derived classes must implement:

- ``refine_triangulation(return_tri_index=False, **kwargs)`` , where
  the optional keyword arguments *kwargs* are defined in each
  TriRefiner concrete implementation, and which returns:

  - a refined triangulation,
  - optionally (depending on *return_tri_index*), for each
    point of the refined triangulation: the index of
    the initial triangulation triangle to which it belongs.

- ``refine_field(z, triinterpolator=None, **kwargs)``, where:

  - *z* array of field values (to refine) defined at the base
    triangulation nodes,
  - *triinterpolator* is an optional `~matplotlib.tri.TriInterpolator`,
  - the other optional keyword arguments *kwargs* are defined in
    each TriRefiner concrete implementation;

  and which returns (as a tuple) a refined triangular mesh and the
  interpolated values of the field at the refined triangulation nodes.
c                sJ    \         P                  ! \        VR 7       Wn        R# ))triangulationN)r    check_isinstancer   _triangulation)selfr   s   &&@/usr/lib64/python3.14/site-packages/matplotlib/tri/_trirefine.py__init__ZTriRefiner.__init__*   s    m=I+    )r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s     :, ,r	   r   c                   s^   a a ] tR t^/t oRtV 3R ltRR ltRR lt]R	R l4       t	Rt
VtV ;t# )
UniformTriRefinerz
Uniform mesh refinement by recursive subdivisions.

Parameters
----------
triangulation : `~matplotlib.tri.Triangulation`
    The encapsulated triangulation (to be refined)
c                s&   < \         SV `  V4       R # N)Zsuperr   )r   r   	__class__s   &&r   r   ZUniformTriRefiner.__init__=   s    'r	   c                s$   V P                   pVP                  P                  ^ ,          p\        P                  ! V\        P
                  R7      p\        V4       F  pV P                  W54      w  r5K  	  VP                  P                  ^ ,          pVP                  pV'       d   \        P                  ! VR\        P
                  R7      p	V P                   P                  p
V
f-   \        P                  ! V^4      P                  R^4      W&   W93# W,          p\        P                  ! W[,          ^4      P                  R^4      WVR3,          &   \        P                  ! W[( ,          ^4      P                  R^4      WV( R3,          &   W93# V# )a  
Compute a uniformly refined triangulation *refi_triangulation* of
the encapsulated :attr:`triangulation`.

This function refines the encapsulated triangulation by splitting each
father triangle into 4 child sub-triangles built on the edges midside
nodes, recursing *subdiv* times.  In the end, each triangle is hence
divided into ``4**subdiv`` child triangles.

Parameters
----------
return_tri_index : bool, default: False
    Whether an index table indicating the father triangle index of each
    point is returned.
subdiv : int, default: 3
    Recursion level for the subdivision.
    Each triangle is divided into ``4**subdiv`` child triangles;
    hence, the default results in 64 refined subtriangles for each
    triangle of the initial triangulation.

Returns
-------
refi_triangulation : `~matplotlib.tri.Triangulation`
    The refined triangulation.
found_index : int array
    Index of the initial triangulation containing triangle, for each
    point of *refi_triangulation*.
    Returned only if *return_tri_index* is set to True.
ZdtypeNNN)r   	trianglesshapenparangeint32range_refine_triangulation_oncexZfullmaskrepeatZreshape)r   return_tri_indexsubdivZrefi_triangulationntri	ancestorsZ_	refi_nptsZrefi_trianglesfound_indexZtri_maskZancestor_masks   &&&         r   refine_triangulationZ&UniformTriRefiner.refine_triangulation@   sp   < "00!++11!4 IId"((3	vA,0,K,K"-/)	  '((..q1	+55  '')Rrxx@K**//H.0ii	89/;;B72q> + &22 !) 3 "		)*B*+!--4WR^ =!+;<  !#		)N*C*+!--4WR^ M>1+<=  &22%%r	   c                sR   Vf,   \         P                  P                  V P                  V4      pM2\        P
                  ! \         P                  P                  VR7       TpV P                  VRR7      w  rVVP                  VP                  VP                  VR7      ^ ,          pWW3# )a%  
Refine a field defined on the encapsulated triangulation.

Parameters
----------
z : (npoints,) array-like
    Values of the field to refine, defined at the nodes of the
    encapsulated triangulation. (``n_points`` is the number of points
    in the initial triangulation)
triinterpolator : `~matplotlib.tri.TriInterpolator`, optional
    Interpolator used for field interpolation. If not specified,
    a `~matplotlib.tri.CubicTriInterpolator` will be used.
subdiv : int, default: 3
    Recursion level for the subdivision.
    Each triangle is divided into ``4**subdiv`` child triangles.

Returns
-------
refi_tri : `~matplotlib.tri.Triangulation`
     The returned refined triangulation.
refi_z : 1D array of length: *refi_tri* node count.
     The returned interpolated field (at *refi_tri* nodes).
)triinterpolatorT)r#   r"   )Z	tri_index)
matplotlibZtriZCubicTriInterpolatorr   r    r   ZTriInterpolatorr(   Z_interpolate_multikeysr   y)r   Zzr)   r#   ZinterpZrefi_trir'   Zrefi_zs   &&&&    r   refine_fieldZUniformTriRefiner.refine_field   s    0 "^^88##Q(F !!*.."@"@2AC$F $ 9 9D !: !2..JJ

k / ;;<>r	   c                sx
   V P                   pV P                  pV P                  pV P                  p\        P
                  ! V4      ^ ,          p\        P
                  ! V4      ^ ,          pVel   \        P                  ! V4      p\        P
                  ! V4      V38w  d:   \        R\        P
                  ! V4       R\        P
                  ! V4       24      h\        P                  ! VR8H  4      p^V,          V,           ^,          p	Wi,           p
\        P                  ! V
4      p\        P                  ! V
4      pW+RV% W<RV% \        P                  ! \        P                  ! V\        P                  R7      ^4      p\        P                  ! \        P                  ! ^\        P                  R7      V4      pWMV3,          pW8  pVV,          pVV,          pW%VV3,          ,          W%VV^,           ^,          3,          ,          ,           R,          pW5VV3,          ,          W5VV^,           ^,          3,          ,          ,           R,          pVWR% VWR% Tp\        P                  ! V^.\        P                  R7      pTp\        ^4       Fi  pVV8H  p\        P                  ! V4      pVV,          p\        P                  ! V\        P                  R7      V,           VRV3,          V&   VV,          pKk  	  \        P                   ! V4      pVV,          pVV,          p\        P"                  ! VVR3,          \        P$                  ! V\        P&                  ! ^\        P                  R7      4      ,
          4      p\        P(                  ! V^R7      p VV,          p!VVV 3,          VVV!3&   \        P                  ! V^,          ^.\        P                  R7      p"\        P*                  ! VR	,          VR	,          VR
,          .4      P,                  V"R&   \        P*                  ! VR,          VR,          VR	,          .4      P,                  V"R&   \        P*                  ! VR
,          VR
,          VR,          .4      P,                  V"R&   \        P*                  ! VR	,          VR,          VR
,          .4      P,                  V"R&   \/        WV"4      p#V P0                  e1   V#P3                  \        P                  ! V P0                  ^4      4       Vf   V## V#\        P                  ! V^4      3# )a  
Refine a `.Triangulation` by splitting each triangle into 4
child-masked_triangles built on the edges midside nodes.

Masked triangles, if present, are also split, but their children
returned masked.

If *ancestors* is not provided, returns only a new triangulation:
child_triangulation.

If the array-like key table *ancestor* is given, it shall be of shape
(ntri,) where ntri is the number of *triangulation* masked_triangles.
In this case, the function returns
(child_triangulation, child_ancestors)
child_ancestors is defined so that the 4 child masked_triangles share
the same index as their father: child_ancestors.shape = (4 * ntri,).
NzNIncompatible shapes provide for triangulation.masked_triangles and ancestors: z and r   g      ?r   )Zaxisr   )r       )r      ):r-   N   r   )r      ):r0   Nr/   r   ):r.   Nr/   r   ):   Nr/   r   )r   r+   	neighborsr   r   r   ZasarrayZ
ValueErrorZsumZzerosZtiler   r   r!   Zemptyr   Zlogical_notZabsZouterZonesZargminZvstackZTr   r    Zset_mask)$r   r%   r   r+   r2   r   Znptsr$   ZbordersZ	added_ptsr&   Zrefi_xZrefi_yZ
edge_elemsZedge_apexesZedge_neighborsZmask_mastersZmastersZapex_mastersZx_addZy_addZnew_pt_cornerZnew_pt_midsideZcum_sumZimidZmask_st_locZn_masters_locZelem_masters_locZmask_slavesZslavesZslaves_mastersZ
diff_tableZslave_masters_apexZslaves_apexZchild_trianglesZchild_triangulations$   &&                                  r   r   Z,UniformTriRefiner._refine_triangulation_once   s   ( OOOO "++	!++	xx{1~xx	"1% 

9-Ixx	"tg- Exx	*+5)1D0EGH H &&b)tVg%!+	$	)$)$ uu WWRYYt288<a@
ii		!288 <dC"{#:;"3 \*"<0Wl234W|A~&::;<=@CDWl234W|A~&::;<=@CDuu " 4)288<!HD</KFF;/M&{38:		RXX9/1899N1d7#$45}$G  nn\2K('4VVIna&78HHVRWWQbhh-GHI J
YYz:!+..<../0v{*+ ((DFA;bhh?#%99$!54 ." $##$1 	  $&99$!54 ." $##$1 	  $&99$!54 ." $##$1 	  $&994 ."64 ." $##$1 	  ,FOL )((=3E3Eq)IJ&&&		)Q(???r	    )Fr1   )Nr1   r   )r
   r   r   r   r   r   r(   r,   Zstaticmethodr   r   r   Z__classcell__)r   r   s   @@r   r   r   /   s;     (C&J$ L G@ G@ G@r	   r   )
r   Znumpyr   r*   r    Zmatplotlib.tri._triangulationr   Zmatplotlib.tri._triinterpolater   r   r3   r	   r   <module>r4      s3      7 % ,  ,FD@
 D@r	   