Skip to content
Projects

Regridding

The equations of patchwork.mesh.regrid, declared on the code that implements them and checked by the tests.

cluster

functionsource

Cover the tagged cells with boxes (the Berger-Rigoutsos algorithm).

efficiency
keep B  ⟺  #{tagged cells in B}∣B∣≥efficiency and B⊂A,chopped into ⌈n/max_size⌉ parts per axis\text{keep } B \iff \frac{\#\{\text{tagged cells in } B\}}{|B|} \ge \texttt{efficiency} \text{ and } B \subset \mathcal{A}, \quad \text{chopped into } \lceil n / \texttt{max\_size} \rceil \text{ parts per axis}
signature
Σk=#{tagged cells in row (or column) k}\Sigma_k = \#\{\text{tagged cells in row (or column) } k\}
inflection
Δk2=Σk+2−2Σk+1+Σk,cut at k+2 where ∣Δk+12−Δk2∣ is largest among sign changes\Delta^2_k = \Sigma_{k+2} - 2\Sigma_{k+1} + \Sigma_k, \qquad \text{cut at } k + 2 \text{ where } |\Delta^2_{k+1} - \Delta^2_k| \text{ is largest among sign changes}
Assumes
  • cut at an empty row or column nearest the middle, else at the strongest inflection (sides of at least 4 cells), else in the middle of the longest side
  • every part shrinks to its tagged cells; boxes shorter than min_size are widened into free allowed cells
  • the boxes are disjoint and cover every allowed tagged cell
References

curve_ranks

functionsource

The rank of each box: the boxes of all levels along a space-filling curve, cut into size runs.

morton
k(B)=∑b∑d=0D−1bitb(rL−ℓ id) 2bD+d(the lower corner i of B on level ℓ, in cells of the finest level L)k(B) = \sum_{b} \sum_{d=0}^{D-1} \mathrm{bit}_b\big(r^{L - \ell}\, i_d\big)\, 2^{bD + d} \quad \text{(the lower corner } \mathbf i \text{ of } B \text{ on level } \ell\text{, in cells of the finest level } L\text{)}
hilbert
k(B)=H(rL−ℓ i),H the Hilbert index (Skilling’s construction): consecutive keys are neighbouring cellsk(B) = H\big(r^{L - \ell}\, \mathbf i\big), \quad H \text{ the Hilbert index (Skilling's construction): consecutive keys are neighbouring cells}
ranks
along the curve, rank q takes boxes while wq+cB/2≤T,T=1R(∑qwq0+∑BcB)\text{along the curve, rank } q \text{ takes boxes while } w_q + c_B/2 \le T, \quad T = \frac{1}{R}\Big(\sum_q w_q^{0} + \sum_B c_B\Big)
Assumes
  • the patches of all refined levels on one curve, a coarse patch before the finer ones at the same corner, so that a patch and the patches over it tend to share a rank
  • the cost cBc_B of a box is its cells, or its weight (box_costs); the load a rank already has (the base level) counts
  • a patch stays on one rank
References

gradient_tags

functionsource

Tag the cells across which field name changes by more than threshold.

cells
tag i  ⟺  max⁡j∈N(i)∣ui−uj∣>τ(two neighbours in 1D, four in 2D)\text{tag } i \iff \max_{j \in N(i)} |u_i - u_j| > \tau \quad \text{(two neighbours in 1D, four in 2D)}
nodes
tag K  ⟺  max⁡p∈Kϕp−min⁡p∈Kϕp>τ\text{tag } K \iff \max_{p \in K} \phi_p - \min_{p \in K} \phi_p > \tau
Assumes
  • the change per cell of each level: tagging stops once the cells resolve the field
  • only points of one patch are compared; the tags are combined over the ranks by regrid

knapsack_ranks

functionsource

The rank of each box: the largest cost first, each to the rank with the least so far.

greedy
cB1≥cB2≥…,r(Bk)=arg⁡min⁡qwq (the lowest such rank),wr(Bk)+=cBkc_{B_1} \ge c_{B_2} \ge \dots, \qquad r(B_k) = \arg\min_q w_q \text{ (the lowest such rank)}, \quad w_{r(B_k)} \mathrel{+}= c_{B_k}
Assumes
  • the greedy (longest processing time first) solution of the knapsack-like partition: the largest cost at most 4/3 of the best possible
  • no locality: neighbouring patches may land on any ranks
References

quadtree_boxes

functionsource

The boxes of every refined level as the blocks of a quadtree (an octree in 3D).

blocks
Bmk=∏d[ mdb, (md+1)b ) (cells of level k),refined  ⟺  Bmk holds a tag of level k−1B^{k}_{\mathbf m} = \prod_{d} [\, m_d b,\ (m_d + 1) b \,) \text{ (cells of level } k\text{)}, \quad \text{refined} \iff B^{k}_{\mathbf m} \text{ holds a tag of level } k - 1
children
Bm′k+1⊂Bmk  ⟺  ⌊m′/r⌋=m(2d children for r=2)B^{k+1}_{\mathbf m'} \subset B^{k}_{\mathbf m} \iff \lfloor \mathbf m' / r \rfloor = \mathbf m \quad (2^d \text{ children for } r = 2)
Assumes
  • each patch is one block of block_size cells of its level, aligned to multiples of block_size; the last block of a level may be shorter, and a block that crosses the edge of the domain or a forbidden cell is cut into rectangles of its allowed cells
  • a level is refined, with a margin of nesting cells, wherever a finer block needs it, so the blocks are properly nested (a balanced tree)
References