§
    ‡Ûgˆ3  ã                   óh   — d Z ddlZddlmZ ddlmZ ddlZ G d„ d¦  «        Z G d„ de¦  «        Z	dS )	z'
Mesh refinement for triangular grids.
é    N)Ú_api)ÚTriangulationc                   ó   — e Zd ZdZd„ ZdS )Ú
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   — t          j        t          |¬¦  «         || _        d S )N)Útriangulation)r   Úcheck_isinstancer   Ú_triangulation)Úselfr   s     úO/granary/edev/quantum/lib/python3.11/site-packages/matplotlib/tri/_trirefine.pyÚ__init__zTriRefiner.__init__*   s&   € ÝÔ�m¸=ÐIÑIÔIÐIØ+ˆÔÐÐó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r   r      s-   € € € € € ðð ð:,ð ,ð ,ð ,ð ,r   r   c                   óJ   ‡ — e Zd ZdZˆ fd„Zd	d„Zd
d„Zedd„¦   «         Zˆ xZ	S )ÚUniformTriRefinerzÆ
    Uniform mesh refinement by recursive subdivisions.

    Parameters
    ----------
    triangulation : `~matplotlib.tri.Triangulation`
        The encapsulated triangulation (to be refined)
    c                 óJ   •— t          ¦   «                              |¦  «         d S ©N)Úsuperr   )r   r   Ú	__class__s     €r   r   zUniformTriRefiner.__init__=   s!   ø€ Ý‰Œ×Ò˜Ñ'Ô'Ð'Ð'Ð'r   Fé   c                 óÈ  — | j         }|j        j        d         }t          j        |t          j        ¬¦  «        }t          |¦  «        D ]}|                      ||¦  «        \  }}Œ|j        j        d         }|j        }|rât          j	        |dt          j        ¬¦  «        }	| j         j
        }
|
€-t          j        |d¦  «                             dd¦  «        |	|<   n‚|
|         }t          j        ||         d¦  «                             dd¦  «        |	||dd…f         <   t          j        ||          d¦  «                             dd¦  «        |	|| dd…f         <   ||	fS |S )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.
        r   ©ÚdtypeéÿÿÿÿNr   )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_triangulationz&UniformTriRefiner.refine_triangulation@   sŒ  € ð< "Ô0ÐØ!Ô+Ô1°!Ô4ˆõ ”I˜d­"¬(Ð3Ñ3Ô3ˆ	Ý�v‘”ð 	/ð 	/ˆAØ,0×,KÒ,KØ" Iñ-/ô -/Ñ)Ð 	 	à&Ô(Ô.¨qÔ1ˆ	Ø+Ô5ˆð ð 	&õ œ' )¨Rµr´xÐ@Ñ@Ô@ˆKØÔ*Ô/ˆHØÐÝ.0¬i¸	Ø89ñ/;ô /;ß;Bº7À2Àq¹>¼>ð ˜NÑ+Ð+ð !)¨Ô 3�å "¤	¨)°MÔ*BØ*+ñ!-ô !-ß-4ªW°R¸©^¬^ð ˜N¨=¸!¸!¸!Ð+;Ô<ñ õ !#¤	¨)°]°NÔ*CØ*+ñ!-ô !-ß-4ªW°R¸©^¬^ð ˜N¨M¨>¸1¸1¸1Ð+<Ô=ñ ð & {Ð2Ð2à%Ð%r   Nc                 ó,  — |€&t           j                             | j        |¦  «        }n't	          j        t           j        j        |¬¦  «         |}|                      |d¬¦  «        \  }}|                     |j	        |j
        |¬¦  «        d         }||fS )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).
        N)ÚtriinterpolatorT)r,   r+   )Ú	tri_indexr   )Ú
matplotlibÚtriÚCubicTriInterpolatorr
   r   r	   ÚTriInterpolatorr6   Ú_interpolate_multikeysr&   Úy)r   Úzr8   r,   ÚinterpÚrefi_trir3   Úrefi_zs           r   Úrefine_fieldzUniformTriRefiner.refine_field…   s¶   € ð0 Ð"Ý”^×8Ò8ØÔ# Qñ(ô (ˆFˆFõ Ô!¥*¤.Ô"@Ø2AðCñ Cô Cð Cà$ˆFà $× 9Ò 9Ø¨Dð !:ñ !2ô !2Ñˆ�+à×.Ò.ØŒJ˜œ
¨kð /ñ ;ô ;Ø;<ô>ˆà˜ÐÐr   c           
      ó¨	  — | j         }| j        }| j        }| j        }t	          j        |¦  «        d         }t	          j        |¦  «        d         }|�tt	          j        |¦  «        }t	          j        |¦  «        |fk    rGt          d                     t	          j        |¦  «        t	          j        |¦  «        ¦  «        ¦  «        ‚t	          j	        |dk    ¦  «        }d|z  |z   dz  }	||	z   }
t	          j
        |
¦  «        }t	          j
        |
¦  «        }||d|…<   ||d|…<   t	          j        t	          j        |t          j        ¬¦  «        d¦  «        }t	          j        t	          j        dt          j        ¬¦  «        |¦  «        }|||f         }||k    }||         }||         }||||f                  ||||dz   dz  f                  z   d	z  }||||f                  ||||dz   dz  f                  z   d	z  }|||d…<   |||d…<   |}t	          j        |dgt          j        ¬¦  «        }|}t!          d¦  «        D ]Y}||k    }t	          j	        |¦  «        }||         }t	          j        |t          j        ¬¦  «        |z   |dd…|f         |<   ||z  }ŒZt	          j        |¦  «        }||         }||         }t	          j        ||dd…f         t	          j        |t	          j        dt          j        ¬¦  «        ¦  «        z
  ¦  «        }t	          j        |d¬
¦  «        } ||         }!||| f         |||!f<   t	          j        |dz  dgt          j        ¬¦  «        }"t	          j        |dd…df         |dd…df         |dd…df         g¦  «        j        |"ddd…dd…f<   t	          j        |dd…df         |dd…df         |dd…df         g¦  «        j        |"ddd…dd…f<   t	          j        |dd…df         |dd…df         |dd…df         g¦  «        j        |"ddd…dd…f<   t	          j        |dd…df         |dd…df         |dd…df         g¦  «        j        |"ddd…dd…f<   t1          |||"¦  «        }#| j        �-|#                     t	          j        | j        d¦  «        ¦  «         |€|#S |#t	          j        |d¦  «        fS )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,).
        r   NzYIncompatible shapes provide for triangulation.masked_triangles and ancestors: {0} and {1}r   r   é   r   é   g      à?)Úaxisé   )r&   r?   Ú	neighborsr   r!   r    ÚasarrayÚ
ValueErrorÚformatÚsumÚzerosÚtiler"   r#   r)   Úemptyr$   Úlogical_notÚabsÚouterÚonesÚargminÚvstackÚTr   r(   Úset_mask)$r   r/   r&   r?   rJ   r   Únptsr.   ÚbordersÚ	added_ptsr1   Ú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%   z,UniformTriRefiner._refine_triangulation_once«   sƒ  € ð( ŒOˆØŒOˆð "Ô+ˆ	Ø!Ô+ˆ	ÝŒx˜‰{Œ{˜1Œ~ˆÝŒx˜	Ñ"Ô" 1Ô%ˆØÐ Ýœ
 9Ñ-Ô-ˆIÝŒx˜	Ñ"Ô" t gÒ-Ð-Ý ðCßCIÂ6Ýœ Ñ+Ô+­R¬X°iÑ-@Ô-@ñDBô DBñCô Cð Cõ ”&˜ bšÑ)Ô)ˆØ�t‘V˜gÑ%¨!Ñ+ˆ	Ø˜9Ñ$ˆ	Ý”˜)Ñ$Ô$ˆÝ”˜)Ñ$Ô$ˆð ˆˆu�ˆu‰Øˆˆu�ˆu‰õ ”W�RœY tµ2´8Ð<Ñ<Ô<¸aÑ@Ô@ˆ
Ý”i¥¤	¨!µ2´8Ð <Ñ <Ô <¸dÑCÔCˆØ" :¨{Ð#:Ô;ˆØ" ^Ò3ˆð ˜\Ô*ˆØ" <Ô0ˆØ�9˜W lÐ2Ô3Ô4Ø�9˜W |°A¡~¸Ñ&:Ð:Ô;Ô<ñ=Ø@CñDˆà�9˜W lÐ2Ô3Ô4Ø�9˜W |°A¡~¸Ñ&:Ð:Ô;Ô<ñ=Ø@CñDˆàˆˆtˆuˆu‰Øˆˆtˆuˆu‰ð "ˆõ œ 4¨ )µ2´8Ð<Ñ<Ô<ˆØˆÝ˜!‘H”Hð 	%ð 	%ˆDØ <Ò/ˆKÝœF ;Ñ/Ô/ˆMØ& {Ô3ÐÝ8:¼	Ø¥R¤Xð9/ñ 9/ô 9/Ø18ñ99ˆN˜1˜1˜1˜d˜7Ô#Ð$4Ñ5à�}Ñ$ˆGˆGõ ”n \Ñ2Ô2ˆØ˜KÔ(ˆØ'¨Ô4ˆÝ”V˜I n°a°a°aÐ&7Ô8ÝœH V­R¬W°Q½b¼hÐ-GÑ-GÔ-GÑHÔHñIñ Jô Jˆ
åœY z¸Ð:Ñ:Ô:ÐØ! +Ô.ˆØ.<ØÐ.Ð.ô/0ˆ�v˜{Ð*Ñ+õ œ( D¨¡F¨A ;µb´hÐ?Ñ?Ô?ˆÝ#%¤9Ø˜!˜!˜!˜Q˜$Ô °°°°1°Ô!5Ø˜1˜1˜1˜a˜4Ô ð."ñ $#ô $#ä#$ð 	˜˜˜1˜˜a˜a˜a˜Ñ õ $&¤9Ø˜!˜!˜!˜Q˜$Ô °°°°1°Ô!5Ø˜1˜1˜1˜a˜4Ô ð."ñ $#ô $#ä#$ð 	˜˜˜1˜˜a˜a˜a˜Ñ õ $&¤9Ø˜!˜!˜!˜Q˜$Ô °°°°1°Ô!5Ø˜1˜1˜1˜a˜4Ô ð."ñ $#ô $#ä#$ð 	˜˜˜1˜˜a˜a˜a˜Ñ õ $&¤9Ø˜1˜1˜1˜a˜4Ô  .°°°°A°Ô"6Ø˜1˜1˜1˜a˜4Ô ð."ñ $#ô $#ä#$ð 	˜˜˜1˜˜a˜a˜a˜Ñ õ ,¨F°F¸OÑLÔLÐð ÔÐ)Ø×(Ò(­¬°=Ô3EÀqÑ)IÔ)IÑJÔJÐJàÐØ&Ð&à&­¬	°)¸QÑ(?Ô(?Ð?Ð?r   )Fr   )Nr   r   )
r   r   r   r   r   r6   rD   Ústaticmethodr%   Ú__classcell__)r   s   @r   r   r   /   s    ø€ € € € € ðð ð(ð (ð (ð (ð (ðC&ð C&ð C&ð C&ðJ$ ð $ ð $ ð $ ðL ðG@ð G@ð G@ñ „\ðG@ð G@ð G@ð G@ð G@r   r   )
r   Únumpyr!   r:   r   Úmatplotlib.tri._triangulationr   Úmatplotlib.tri._triinterpolater   r   r   r   r   ú<module>r{      s¾   ððð ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø %Ð %Ð %Ð %ð ,ð  ,ð  ,ð  ,ð  ,ñ  ,ô  ,ð  ,ðFD@ð D@ð D@ð D@ð D@˜
ñ D@ô D@ð D@ð D@ð D@r   