+
    iz3                     \    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                   *   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                J    \         P                  ! \        VR 7       Wn        R# ))triangulationN)r   check_isinstancer   _triangulation)selfr   s   &&y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/matplotlib/tri/_trirefine.py__init__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                   ^   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V `  V4       R # N)superr   )r
   r   	__class__s   &&r   r   UniformTriRefiner.__init__=   s    'r   c                $   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.
dtypeNNN)r	   	trianglesshapenparangeint32range_refine_triangulation_oncexfullmaskrepeatreshape)r
   return_tri_indexsubdivrefi_triangulationntri	ancestors_	refi_nptsrefi_trianglesfound_indextri_maskancestor_masks   &&&         r   refine_triangulation&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                R   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)r0   r/   )	tri_index)
matplotlibtriCubicTriInterpolatorr	   r   r   TriInterpolatorr:   _interpolate_multikeysr*   y)r
   zr=   r0   interprefi_trir7   refi_zs   &&&&    r   refine_fieldUniformTriRefiner.refine_field   s    0 "^^88##Q(F !!*.."@"@2AC$F $ 9 9D !: !2..JJ

k / ;;<>r   c                x
   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!   )axisr"   )r!       )r!      ):rM   N   r!   )r!      ):rP   NrO   r!   ):rN   NrO   r!   ):   NrO   r!   )r*   rD   	neighborsr#   r%   r$   asarray
ValueErrorsumzerostiler&   r'   r-   emptyr(   logical_notabsouteronesargminvstackTr   r,   set_mask)$r   r3   r*   rD   rR   r#   nptsr2   borders	added_ptsr5   refi_xrefi_y
edge_elemsedge_apexesedge_neighborsmask_mastersmastersapex_mastersx_addy_addnew_pt_cornernew_pt_midsidecum_sumimidmask_st_locn_masters_locelem_masters_locmask_slavesslavesslaves_masters
diff_tableslave_masters_apexslaves_apexchild_triangleschild_triangulations$   &&                                  r   r)   ,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    )FrQ   )NrQ   r   )r   r   r   r   r   r   r:   rI   staticmethodr)   r   r   __classcell__)r   r   s   @@r   r   r   /   s;     (C&J$ L G@ G@ G@r   r   )
r   numpyr%   r?   r   matplotlib.tri._triangulationr   matplotlib.tri._triinterpolater   r   r~   r   r   <module>r      s3      7 % ,  ,FD@
 D@r   