rL iz3ZdZddlZddlmZddlmZddlZGddZGddeZ y) z' Mesh refinement for triangular grids. N)_api) TriangulationceZdZdZdZy) 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. cHtjt|||_y)N) triangulation)rcheck_isinstancer_triangulation)selfrs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/tri/_trirefine.py__init__zTriRefiner.__init__*s m=I+N)__name__ __module__ __qualname____doc__r rr rr s :,rrcDeZdZdZfdZddZddZeddZxZ S) UniformTriRefinerz Uniform mesh refinement by recursive subdivisions. Parameters ---------- triangulation : `~matplotlib.tri.Triangulation` The encapsulated triangulation (to be refined) c$t||yN)superr )r r __class__s r r zUniformTriRefiner.__init__=s 'rc|j}|jjd}tj|tj }t |D]}|j||\}}|jjd}|j}|rtj|dtj } |jj} | -tj|djdd| |<|| fS| |} tj|| djdd| || ddf<tj|| djdd| || ddf<|| fS|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. rdtypeN) r trianglesshapenparangeint32range_refine_triangulation_oncexfullmaskrepeatreshape) r return_tri_indexsubdivrefi_triangulationntri ancestors_ refi_nptsrefi_triangles found_indextri_mask ancestor_masks r refine_triangulationz&UniformTriRefiner.refine_triangulation@s<"00!++11!4IId"((3 v /A,0,K,K"I-/ )   /'((..q1 +55 '')Rrxx@K**//H.0ii 89/;;B72q>N+&{2 2!) 3 " )M*B*+!--4WR^N=!+;<!# )]N*C*+!--4WR^NM>1+<=&{2 2% %rcH|+tjj|j|}n1t j tjj ||}|j|d\}}|j|j|j|d}||fS)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+) tri_indexr) matplotlibtriCubicTriInterpolatorr rr TriInterpolatorr6_interpolate_multikeysr&y)r zr8r,interprefi_trir3refi_zs r refine_fieldzUniformTriRefiner.refine_fields0  "^^88##Q(F  ! !*.."@"@2A C$F $ 9 9D!:!2+.. JJ k/;;<>rc d |j}|j}|j}|j}t j |d}t j |d}|et j |}t j ||fk7r7tdt j |dt j |t j|dk(}d|z|zdz} || z} t j| } t j| } || d||| d|t jt j|tjd} t jt jdtj|}|| |f}| |kD}| |}||}||||f||||d zdzfzd z}||||f||||d zdzfzd z}|| |d|| |d|}t j|dgtj}|}tdD]X}||k(}t j|}||}t j|tj|z|dd|f|<||z }Zt j |}| |}||}t j"||ddft j$|t j&dtjz }t j(|d } ||}!||| f|||!f<t j|d zdgtj}"t j*|dddf|dddf|dddfgj,|"ddd ddf<t j*|ddd f|ddd f|dddfgj,|"d dd ddf<t j*|dddf|dddf|ddd fgj,|"ddd ddf<t j*|dddf|ddd f|dddfgj,|"ddd ddf<t/| | |"}#|j0/|#j3t j|j0d ||#S|#t j|d fS) 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,). rNzNIncompatible shapes provide for triangulation.masked_triangles and ancestors: z and rrrg?)axis)r&r? neighborsrr!r asarray ValueErrorsumzerostiler"r#r)emptyr$ logical_notabsouteronesargminvstackTrr(set_mask)$rr/r&r?rJrnptsr.borders added_ptsr1refi_xrefi_y edge_elems edge_apexesedge_neighbors mask_mastersmasters apex_mastersx_addy_add new_pt_cornernew_pt_midsidecum_sumimid mask_st_loc n_masters_locelem_masters_loc mask_slavesslavesslaves_masters diff_tableslave_masters_apex slaves_apexchild_triangleschild_triangulations$ r r%z,UniformTriRefiner._refine_triangulation_onces( OO OO "++ !++ xx{1~xx "1%   9-Ixx "tg- Exx *+5)1D0EGHH&&b)tVg%!+ 9$ )$)$u u WWRYYt288rzs37% , ,FD@ D@r