Algorithmadvanced
Dorfler marking
Also called bulk marking.
Marks a smallest set of elements whose squared indicators sum to at least a fraction theta of the total, the marking rule behind the convergence proofs of AFEM.
- Time
- Θ(M) average
- Space
- Θ(M) extra
- Where
- M = the number of elements
- Model
- Real RAM
- Properties
- randomizedexact with exact arithmeticminimal cardinality
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Willy Dorfler, 1996
Dorfler marking, also called bulk marking, is the MARK step of the adaptive finite element method. Given squared error indicators and a parameter , it marks a set of elements with , and among all such sets it takes one of the smallest size. So the marked elements carry a fixed share of the estimated error. This one inequality is what the convergence proofs need: with it, the error plus a multiple of the estimator contracts by a fixed factor in each step. With a small and a set of minimal size, the loop also reaches the optimal rate of the AFEM optimality theorem. The obvious implementation sorts the indicators. A partition around pivots, as in quickselect, finds a minimal set in expected linear time.
In plain words
Each element has a number that says how much error it holds. Put the elements in order from the largest number to the smallest. Take elements from the top of the list until the ones you took hold at least a fixed share of the total, for example half of it. Those are the elements to refine. If a few elements hold most of the error, as near a corner singularity, only a few are marked. If the error is spread evenly, many are marked, and the refinement is close to uniform. A faster method gets the same answer without sorting the whole list, by splitting it around one value at a time and keeping only the part that holds the cut.
The problem
Input. Numbers , one for each element, and .
Output. A set with (the bulk criterion, also called the Dorfler property) and with the smallest size among all nonempty sets with this property. The minimal size is unique. The set itself is unique only when there are no ties at the cut.
The algorithm
DORFLER-SORT is the direct method. DORFLER-SELECT keeps a candidate list and splits it around a random pivot value. The answer is a prefix of the sorted list, so the procedure only needs to find where the prefix ends.
DORFLER-SORT(eta2, theta)- 1
goal <- theta * sum(eta2) - 2
order <- the indices sorted by eta2, largest first - 3
M <- empty; acc <- 0 - 4
for each t in order, while acc < goal or M is empty do - 5
add t to M; acc <- acc + eta2[t] - 6
return M DORFLER-SELECT(eta2, theta)- 7
goal <- theta * sum(eta2); M <- empty - 8
cand <- all indices - 9
while cand is not empty do - 10
p <- eta2[t] for a random t in cand ▷ the pivot value - 11
split cand into high (> p), equal (= p) and low (< p) - 12
sh <- sum of eta2 over high - 13
if high is not empty and sh >= goal then cand <- high; continue ▷ the cut is inside high - 14
if sh + sum over equal >= goal then return M + high + enough of equal to reach goal - 15
M <- M + high + equal; goal <- goal - sh - sum over equal; cand <- low - 16
return M ▷ not reached
Line L14 may take the elements of equal in any order, because they all have the same value.
Example
Take seven elements with , numbered 0 to 6. The total is 30.
With , the goal is 15. DORFLER-SORT takes element 2 (value 9, sum 9) and element 4 (value 6, sum 15). The sum reaches 15, so . No single element has 15, so two is the minimal size.
DORFLER-SELECT with the pivots 4 and then 6 runs as follows.
| Pass | cand | Pivot | high | equal | low | Line | Action | |
|---|---|---|---|---|---|---|---|---|
| 1 | all 7 | 4 | {2, 4, 6} | {0} | {1, 3, 5} | 20 | L13 | , so cand {2, 4, 6} |
| 2 | {2, 4, 6} | 6 | {2} | {4} | {6} | 9 | L14 | , return {2, 4} |
With , the goal is 24. In pass 1 with pivot 4, and , so line L14 returns {2, 4, 6, 0}, the four largest. DORFLER-SORT gives the same set. The test file checks both procedures on these inputs and on 300 random inputs with Fraction values against a search over all subsets.
Effect in the loop. On the L-shaped domain with , the AFEM reference run marks mostly triangles near the reentrant corner, and its error falls like in the number of unknowns. With every triangle is marked, the loop is uniform refinement, and the error falls only like .
Correctness
The full proof is in the correctness proof. An exchange argument shows that among all sets of size , the largest indicators have the largest sum. So the minimal size is the length of the shortest prefix of the sorted list that reaches the goal, and DORFLER-SORT returns that prefix. For DORFLER-SELECT, the invariant is that marked is a prefix of some descending order, cand is the block right after it, goal is what marked still lacks, and the end of the shortest bulk prefix lies inside cand. Each of the three cases at lines L13 to L15 keeps the invariant and makes cand smaller, and line L14 returns exactly the shortest bulk prefix.
Proof: Both marking procedures return a bulk set of minimal sizefull
Setting. The input is a list of numbers with , and . Write and . A set is a bulk set if . Let be the smallest size of a nonempty bulk set. It exists, because the full set is a bulk set (). Fix a descending order of the indices, , and write for its prefixes. Arithmetic is exact (real-RAM, or Fraction in the code).
Lemma 1 (prefixes are best). For every , the prefix has the largest sum among all sets of size . So is the smallest such that is a bulk set, and every prefix of a descending order of length is a minimal bulk set.
Proof. Let . List the values of in descending order as . The -th largest value of is at most the -th largest value of all indicators, , because at least values of the whole list are at least . Sum over . If some of size is a bulk set, so is , and the converse is trivial.
Claim A (DORFLER-SORT, lines L1 to L6). The output has size and is a bulk set.
Proof. Line L2 gives a descending order. The loop at line L4 adds and stops before adding exactly when the sum of is at least and . So it returns for the smallest with a bulk set, which is by Lemma 1.
Claim B (DORFLER-SELECT, lines L7 to L16). The procedure stops, and its output has size and is a bulk set.
Proof. We prove the following invariant at the start of each pass of line L9. Write and . There is a descending order of all indices with
- marked and cand ;
- goal ;
- .
At the start , cand is everything, and , so the invariant holds.
In one pass, line L10 picks a value of cand, and line L11 splits cand into high (), equal () and low (), which are not empty in the case of equal. Choose so that it lists marked, then high, then equal, then low, each in descending order. It is still a descending order, and it keeps property 1 of the invariant. Let and be the sums of high and equal. By property 2, the prefix is a bulk set exactly when the sum of its first elements after marked is at least goal.
Case L13: high is not empty and goal. Then is a bulk set, so . The new cand is high, which is . Properties 1 and 2 still hold, and property 3 holds with the new . The new cand is smaller, because the pivot index is not in high.
Case L14: not case L13, and goal. If high is not empty, then goal, so is not a bulk set and . If high is empty, then by property 3. Also is a bulk set, so lies in the equal block. The code takes high and then the elements of equal one at a time, until the sum reaches goal and at least one element is marked. All elements of equal have the same value, so any order of them is a descending order, and the code returns the prefix of the smallest that is a bulk set (with ). This is by Lemma 1.
Case L15: goal. Then is not a bulk set, so . Line L15 moves high and equal into marked, lowers goal by and sets cand to low. All three properties hold for the new values. The new cand is smaller, because equal contains the pivot.
Each pass either returns or makes cand strictly smaller, so the loop ends after at most passes. It cannot end with cand empty: then , and property 3 would give . So it ends at line L14 with a bulk set of size .
Claim C (expected cost). With the pivot chosen uniformly at random from cand, the expected number of operations on indicators is at most , in the real-RAM model.
Proof. One pass costs at most operations (three filters and one sum over cand, plus a sum over equal). Let be the sizes of cand. If the pivot has rank in cand (in descending order, ties counted once), the next cand is high or low, of size at most . For uniform in , the mean of is at most , and ties only make the parts smaller. So , and . The expected total cost is at most .
Complexity
DORFLER-SORT costs comparisons in the worst case for the sort and for the scan. DORFLER-SELECT costs expected time in the real-RAM model: one pass is linear in the size of cand, and a random pivot makes the expected size of the next cand at most of the current one, so the expected total is at most operations. Its worst case is , with bad pivots every time. A median of medians pivot gives worst-case linear time, and Pfeiler and Praetorius proved that marking with minimal size is a linear time problem. Both procedures need extra memory.
In the adaptive loop the cost of marking is small next to the solve. The sort is often fast enough in practice. The linear methods matter when the theory counts every step, as in proofs that the whole loop has optimal cost.
Properties
- Minimal size. The output has the smallest size among all bulk sets. The optimality theorem allows a set up to a constant factor larger than the minimum.
- Largest values. Every marked indicator is at least as large as every unmarked one.
- Monotone in theta. A larger never gives a smaller set.
- Extremes. marks every element with a nonzero indicator (and at least one element), and a small marks the few largest.
- Contraction. With an exact solve, newest vertex bisection and the residual estimator, Dorfler marking gives with for every .
- Optimal marking lemma. The converse also holds. If a refinement reduces the total error by a fixed factor, then the refined elements satisfy the bulk criterion for every below a threshold that depends on the stability and discrete reliability constants. This is why the optimality theorem needs a small .
Variants and improvements
- Binning. Stevenson puts the indicators into bins by powers of 2 of their size relative to the largest one and takes whole bins from the top. This costs linear time and gives a bulk set at most twice the minimal size, which the optimality theorem allows.
- Maximum strategy. Mark every with . It needs no sort and often works well, but it does not satisfy the bulk criterion in general, and the classical rate proofs do not cover it.
- Marking for oscillation. Morin, Nochetto and Siebert (2000) also marked by the data oscillation with a second bulk criterion. Cascon, Kreuzer, Nochetto and Siebert showed this is not needed for the model problem.
- Separate marking for hp. For hp-FEM, the marked elements are then split between h and p refinement by a smoothness test.
- Goal-oriented marking. With a primal and a dual estimator, one marks a bulk set for each, or for their product, and takes the smaller set. The rates are then proved for the goal error.
When to use it
Use Dorfler marking in any adaptive loop where a convergence guarantee matters, and whenever the code should follow the theory of rates. It is also the safe default in practice: it adapts the number of marked elements to how concentrated the error is. When the indicators come from the Zienkiewicz-Zhu estimator or the dual weighted residual method, the same rule applies, but the convergence theory is less complete.
Pitfalls
- Squares, not norms. The criterion sums the squared indicators . Summing gives a different set and is not what the proofs use.
- Theta near 1. A large marks almost everything and loses the point of adaptivity. The optimality theorem needs , and is not known in practice. Values from 0.25 to 0.6 are common, and they are a rule of thumb.
- Floating point at the cut. In floating point, two procedures that add the values in different orders can disagree by one element when the sum is very close to the goal. Use exact arithmetic in tests, as the test file does with Fraction values.
- All zero indicators. If all indicators are 0, the goal is 0 and any single element satisfies the criterion. The loop should stop before this, because the estimator is already 0.
- Ties. With ties at the cut, the minimal set is not unique. Code that depends on a particular choice, for example in a parallel run, needs a fixed rule for ties.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dorfler-marking/. The authors are listed in prov/G0MEX4.jsonl.
"""Dorfler (bulk) marking with a marked set of minimal size.
Input: a list eta2 of squared error indicators eta_K^2 >= 0, one per
element, and a parameter theta in (0, 1]. Output: a list M of element
numbers with sum(eta2[K] for K in M) >= theta * sum(eta2) and with the
smallest possible size. The functions work on float or Fraction data; with
Fraction the comparisons are exact.
dorfler_sort sorts and takes the largest indicators: O(M log M) for M
elements. dorfler_select finds the same size by partitions around random
pivots, as in quickselect: O(M) expected time (real-RAM).
"""
import random
def dorfler_sort(eta2, theta):
"""Return a minimal bulk set by sorting the indicators in decreasing order."""
goal = theta * sum(eta2) # @line L1
order = sorted(range(len(eta2)), key=lambda t: -eta2[t]) # @line L2
marked, acc = [], 0 # @line L3
for t in order: # @line L4
if acc >= goal and marked:
break
marked.append(t) # @line L5
acc += eta2[t]
return marked # @line L6
def dorfler_select(eta2, theta, rng=None):
"""Return a minimal bulk set by partitions around random pivots (expected linear time)."""
rng = rng or random.Random(0)
goal = theta * sum(eta2) # @line L7
marked = []
cand = list(range(len(eta2))) # @line L8
while cand: # @line L9
p = eta2[cand[rng.randrange(len(cand))]] # @line L10
high = [t for t in cand if eta2[t] > p] # @line L11
equal = [t for t in cand if eta2[t] == p]
low = [t for t in cand if eta2[t] < p]
sh = sum(eta2[t] for t in high) # @line L12
if high and sh >= goal: # @line L13
cand = high # the answer ends inside high
continue
se = sum(eta2[t] for t in equal)
if sh + se >= goal: # @line L14
marked.extend(high)
acc = sh
for t in equal:
if acc >= goal and marked:
break
marked.append(t)
acc += eta2[t]
return marked
marked.extend(high + equal) # @line L15
goal -= sh + se
cand = low
return marked # @line L16
test_dorfler_marking.py 71 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dorfler-marking/. The authors are listed in prov/G0MEX4.jsonl.
import itertools
import random
from fractions import Fraction
from dorfler_marking import dorfler_select, dorfler_sort
def brute_force_size(eta2, theta):
goal = theta * sum(eta2)
n = len(eta2)
for k in range(1, n + 1):
for s in itertools.combinations(range(n), k):
if sum(eta2[t] for t in s) >= goal:
return k
return None
def check(eta2, theta, marked):
assert len(set(marked)) == len(marked)
assert all(0 <= t < len(eta2) for t in marked)
assert sum(eta2[t] for t in marked) >= theta * sum(eta2)
def test_hand_example():
eta2 = [4, 1, 9, 2, 6, 3, 5]
assert sorted(dorfler_sort(eta2, Fraction(1, 2))) == [2, 4]
assert sorted(dorfler_select(eta2, Fraction(1, 2))) == [2, 4]
assert sorted(dorfler_sort(eta2, Fraction(4, 5))) == [0, 2, 4, 6]
assert sorted(dorfler_select(eta2, Fraction(4, 5))) == [0, 2, 4, 6]
assert len(dorfler_sort(eta2, 1)) == 7
def test_minimal_against_brute_force_exact():
rng = random.Random(2024)
for _ in range(300):
n = rng.randint(1, 9)
eta2 = [Fraction(rng.randint(0, 12), rng.randint(1, 4)) for _ in range(n)]
if sum(eta2) == 0:
eta2[0] = Fraction(1)
theta = Fraction(rng.randint(1, 10), 10)
best = brute_force_size(eta2, theta)
a = dorfler_sort(eta2, theta)
b = dorfler_select(eta2, theta, random.Random(rng.randint(0, 10 ** 6)))
check(eta2, theta, a)
check(eta2, theta, b)
assert len(a) == best
assert len(b) == best
def test_same_size_on_large_float_input_with_ties():
rng = random.Random(9)
eta2 = [float(rng.randint(0, 50)) for _ in range(5000)] # integers: sums are exact
for theta in (0.1, 0.3, 0.5, 0.9, 1.0):
a = dorfler_sort(eta2, theta)
b = dorfler_select(eta2, theta, random.Random(1))
check(eta2, theta, a)
check(eta2, theta, b)
assert len(a) == len(b)
rest = set(range(len(eta2))) - set(b)
if rest:
assert min(eta2[t] for t in b) >= max(eta2[t] for t in rest) # b holds the largest values
def test_all_zero_and_single():
assert len(dorfler_sort([0.0, 0.0, 0.0], 0.5)) == 1
assert len(dorfler_select([0.0, 0.0, 0.0], 0.5)) == 1
assert dorfler_sort([2.0], 1.0) == [0]
assert dorfler_select([2.0], 1.0) == [0]
History
Willy Dorfler introduced the criterion in 1996, in the first proof that an adaptive finite element method for Poisson's equation in 2D reduces the error by a fixed factor in each step. His proof needed a fine enough initial mesh to resolve the data. Pedro Morin, Ricardo Nochetto and Kunibert Siebert removed this condition in 2000. Peter Binev, Wolfgang Dahmen and Ronald DeVore in 2004, and Rob Stevenson in 2007, used bulk marking in the first proofs of optimal rates, and Stevenson gave the binning method with linear cost. Manuel Cascon, Christian Kreuzer, Nochetto and Siebert proved the optimal marking lemma in 2008. Carl-Martin Pfeiler and Dirk Praetorius showed in 2020 that a set of exactly minimal size can be found in linear time.
References
- Willy Dorfler, A convergent adaptive algorithm for Poisson's equation, SIAM Journal on Numerical Analysis 33(3) (1996) 1106-1124, the marking criterion and the error reduction proof
- Carl-Martin Pfeiler and Dirk Praetorius, Dorfler marking with minimal cardinality is a linear complexity problem, Mathematics of Computation 89(326) (2020) 2735-2752, the linear time algorithm for a minimal Dorfler set and its cost analysis
- Rob Stevenson, Optimality of a standard adaptive finite element method, Foundations of Computational Mathematics 7(2) (2007) 245-269, the marking by binning, linear cost with a set at most twice the minimal size, and the optimality proof
- J. Manuel Cascon, Christian Kreuzer, Ricardo H. Nochetto and Kunibert G. Siebert, Quasi-optimal convergence rate for an adaptive finite element method, SIAM Journal on Numerical Analysis 46(5) (2008) 2524-2550, the contraction with Dorfler marking, and the optimal marking lemma with its threshold on theta
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag G0MEX4 Edit this page History Report an error Markdown