The question. Mangrove forests lock carbon in wood and, much more, in the mud under them. A stand keeps its place only while its mud surface rises as fast as the sea. This lab links stem growth, self-thinning, tides, sediment and sea-level rise in one hectare of forest and shows when the carbon store survives and when it is squeezed out.
Trees. Mean stem diameter D grows logistically, dD/dt = g f(H) D (1 - D/Dmax), where f(H) = exp(-((H-0.40)/0.30)^2) is a growth multiplier peaking at a flooding fraction H = 0.40. Dry mass per tree uses the general mangrove allometry of Komiyama and co-workers (2005): AGB = 0.251 rho D^2.46 and BGB = 0.199 rho^0.899 D^2.22 (kg, D in cm, rho in g/cm3). Carbon is 47 % of dry mass. Stems thin towards a ceiling that follows the -3/2 self-thinning law, Nmax = 6000 (D/5)^-1.5 per hectare (the constant is illustrative).
Tides and flooding. A sinusoidal tide of amplitude A floods a surface at elevation z above mean sea level for the fraction H = arccos(z/A)/pi of each cycle. Real tides are mixed and have a spring-neap cycle; this is the simplest honest version.
Sediment and the squeeze. The surface changes at dz/dt = (a_eff - s)/1000 (m/yr) where s is sea-level rise and a_eff = a (0.5 + H)/0.9: more flooding brings more sediment (illustrative law, scaled so a_eff = a at H = 0.40). Because lower ground floods more and so gains faster, there is a stable equilibrium elevation z* = A cos(pi H*) with H* = (s/a)(0.9) - 0.5. If H* exceeds 0.9 (s above 1.56 a) the equilibrium is too wet for trees and the stand dies; above 1.67 a the surface cannot keep up at all. A stand with no room to move landward is "squeezed". Soil carbon accumulates at a_eff x 10 x BD x fOC Mg C per hectare per year (1 mm over 1 ha is 10 m3). Soil carbon decomposition and lateral export are ignored.
Checks on the page. (1) RK4 diameter against the logistic closed form; (2) allometry recomputed through logarithms; (3) the surface elevation after 400 years against the analytic equilibrium; (4) buried carbon against a x 10 x BD x fOC x t; (5) the hydroperiod formula against numerical time-sampling of a tide. They run when the page loads.
Honest simplifications. One mean tree per hectare, not individuals; the growth, thinning and sediment feedback laws are chosen for clarity and are illustrative, not fitted to a site; the allometric coefficients are typical published values and should be spot-checked before any use outside teaching. The 3D forest is a visual cast: trees shrink or vanish with the model state, stem positions are random, the tide cycle in the picture is much faster than the real one. This is an educational model, not a carbon-credit calculator.