{
 "id": "lattice-boltzmann-fluids",
 "title": "Lattice Boltzmann fluids",
 "aliases": [
  "LBM"
 ],
 "domain": "simulation",
 "subdomain": "grid fluids",
 "stage": "simulation",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda",
  "cpu"
 ],
 "year_introduced": 1998,
 "inputs": [
  "voxels"
 ],
 "outputs": [
  "volume-density",
  "particles"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Simulates fluid with particle-distribution functions streaming and colliding on a lattice, with simple local updates that parallelise perfectly on GPUs.",
 "how_it_works": "Instead of velocity and pressure, each cell stores a small set of distribution values (D2Q9 in 2D, D3Q19 or D3Q27 in 3D), one per lattice direction. A step has two phases: collision relaxes each cell's distributions toward equilibrium (BGK, with relaxation time setting viscosity), and streaming copies each distribution to the neighbouring cell it points to. Density and velocity are recovered as sums of the distributions. Solid boundaries use bounce-back, which works for arbitrary voxelised shapes. There is no pressure Poisson solve, so each step is a purely local, memory-bound pass, ideal for fragment/compute shaders.",
 "when_to_use": "Choose it for wind tunnels, smoke around complex voxel obstacles, and GPU-friendly fluid that must run many steps per frame. Prefer `stable-fluids` for artist-friendly large time steps and stable smoke, `flip-pic-fluids` or `sph-fluids` for liquids with free surfaces, and `position-based-fluids` for game liquids.",
 "cost": {
  "class": "medium",
  "notes": "Memory-bandwidth bound: a lattice cell costs 9-27 reads and writes per step."
 },
 "failure_modes": [
  "Only stable for low Mach numbers; high speeds or low viscosity cause blow-ups",
  "Compressibility errors: density waves reflect around obstacles",
  "Fixed lattice step ties time step to grid resolution, so large domains need many steps",
  "Free surfaces and multiphase flow need extra models"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1146/annurev.fluid.30.1.329",
   "type": "paper",
   "title": "LATTICE BOLTZMANN METHOD FOR FLUID FLOWS",
   "authors": [
    "Shiyi Chen",
    "Gary D. Doolen"
   ],
   "year": 1998,
   "venue": "Annual Review of Fluid Mechanics",
   "url": "https://doi.org/10.1146/annurev.fluid.30.1.329",
   "ids": {
    "doi": "10.1146/annurev.fluid.30.1.329"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1146/annurev.fluid.30.1.329",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1146/annurev.fluid.30.1.329",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1146/annurev.fluid.30.1.329",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1146/annurev.fluid.30.1.329",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1146/annurev.fluid.30.1.329",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "chen1998lattice"
  },
  {
   "role": "primary",
   "key": "doi:10.1007/978-3-319-44649-3",
   "type": "book",
   "title": "The Lattice Boltzmann Method",
   "authors": [
    "Timm Krüger",
    "Halim Kusumaatmaja",
    "Alexandr Kuzmin",
    "Orest Shardt",
    "Goncalo Silva",
    "Erlend Magnus Viggen"
   ],
   "year": 2017,
   "venue": "Graduate Texts in Physics",
   "url": "https://doi.org/10.1007/978-3-319-44649-3",
   "ids": {
    "doi": "10.1007/978-3-319-44649-3"
   },
   "license": null,
   "extra": {
    "csl_type": "book"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-44649-3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-44649-3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-44649-3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-44649-3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-44649-3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "krger2017lattice"
  },
  {
   "role": "primary",
   "key": "doi:10.1109/tvcg.2004.1260768",
   "type": "paper",
   "title": "The lattice-boltzmann method for simulating gaseous phenomena",
   "authors": [
    "Xiaoming Wei",
    "Wei Li",
    "K. Mueller",
    "A.E. Kaufman"
   ],
   "year": 2004,
   "venue": "IEEE Transactions on Visualization and Computer Graphics",
   "url": "https://doi.org/10.1109/tvcg.2004.1260768",
   "ids": {
    "doi": "10.1109/tvcg.2004.1260768"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2004.1260768",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2004.1260768",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2004.1260768",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2004.1260768",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2004.1260768",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "wei2004lattice"
  }
 ],
 "presets": [
  {
   "id": "lattice-boltzmann-fluids-live",
   "title": "Lattice Boltzmann fluids — D2Q9 Kármán vortex street vorticity, equilibrium vectors & wake shedding",
   "runtime": "glsl-fragment",
   "params": {
    "P_REYNOLDS": 1.15,
    "P_VORTEX_SHED": 1,
    "P_LATTICE_GRID": 0.75,
    "P_FLOW_SPEED": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_REYNOLDS = 1.15; // P Vortex Strength [0.3, 2.2, 0.05]\nconst float P_VORTEX_SHED = 1.0; // P Strouhal Freq [0.4, 2.0, 0.05]\nconst float P_LATTICE_GRID = 0.75; // P D2Q9 Stencils [0.0, 1.5, 0.05]\nconst float P_FLOW_SPEED = 1.0; // P Inflow Speed [0.0, 2.5, 0.05]\n\n// Analytical D2Q9 Karman vortex street streamfunction behind cylinder at cylPos\nfloat streamPsi(vec2 p, vec2 cylPos, float cylR, float t, float reyn, float stFreq) {\n  vec2 q = p - cylPos;\n  float r2 = max(dot(q, q), 1e-4);\n  // Potential doublet flow around cylinder (strictly tangent at r = cylR)\n  float u0 = 0.75;\n  float psi = u0 * q.y * (1.0 - (cylR * cylR) / r2);\n\n  // Shedding alternating von Karman vortex street downstream (q.x > 0)\n  float wakeMask = smoothstep(cylR * 0.6, cylR * 2.2, q.x) * exp(-abs(q.y) * 2.2);\n  float kX = 5.4 * stFreq;\n  float spacing = 6.2831853 / kX;\n  float phase = t * 1.45 * stFreq;\n  for (int k = 0; k < 6; k++) {\n    float fk = float(k);\n    float sgn = (mod(fk, 2.0) < 0.5) ? 1.0 : -1.0;\n    float vx = mod(fk * spacing * 0.5 + phase * (spacing / 6.2831853), 1.65) + cylR * 1.15;\n    float vy = sgn * (0.072 + 0.032 * vx);\n    vec2 dv = q - vec2(vx, vy);\n    float d2 = dot(dv, dv);\n    float core = 0.0055 + 0.006 * vx;\n    float fade = exp(-vx * 0.82) * smoothstep(cylR * 0.9, cylR * 1.8, vx);\n    // Lamb-Oseen regularized point vortex contribution\n    psi += sgn * 0.058 * reyn * fade * wakeMask * log(d2 + core);\n  }\n  return psi;\n}\n\nvec2 evalVelocity(vec2 p, vec2 cylPos, float cylR, float t, float reyn, float stFreq) {\n  float e = 0.006;\n  float dPsiDy = (streamPsi(p + vec2(0.0, e), cylPos, cylR, t, reyn, stFreq) - streamPsi(p - vec2(0.0, e), cylPos, cylR, t, reyn, stFreq)) / (2.0 * e);\n  float dPsiDx = (streamPsi(p + vec2(e, 0.0), cylPos, cylR, t, reyn, stFreq) - streamPsi(p - vec2(e, 0.0), cylPos, cylR, t, reyn, stFreq)) / (2.0 * e);\n  return vec2(dPsiDy, -dPsiDx);\n}\n\n// Diverging scientific vorticity palette (blue = clockwise, dark slate = irrotational, orange/gold = CCW)\nvec3 vortPalette(float w) {\n  float a = clamp(abs(w), 0.0, 1.0);\n  vec3 neg = mix(vec3(0.04, 0.14, 0.34), vec3(0.14, 0.86, 1.00), pow(a, 0.72));\n  vec3 pos = mix(vec3(0.32, 0.08, 0.10), vec3(1.00, 0.72, 0.18), pow(a, 0.72));\n  return mix(vec3(0.035, 0.052, 0.082), (w >= 0.0 ? pos : neg), smoothstep(0.02, 0.85, a));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float px = 1.0 / max(iResolution.y, 1.0);\n  float tAnim = iTime * max(P_FLOW_SPEED, 0.0);\n  float reyn = clamp(P_REYNOLDS, 0.2, 2.5);\n  float stFreq = clamp(P_VORTEX_SHED, 0.35, 2.2);\n  float gridVis = clamp(P_LATTICE_GRID, 0.0, 1.6);\n\n  vec2 cylPos = vec2(-0.42, 0.0);\n  float cylR = 0.115;\n\n  // Evaluate macroscopic velocity u and vorticity curl(u) = dv/dx - du/dy\n  vec2 vel = evalVelocity(uv, cylPos, cylR, tAnim, reyn, stFreq);\n  float e = 0.01;\n  vec2 vxP = evalVelocity(uv + vec2(e, 0.0), cylPos, cylR, tAnim, reyn, stFreq);\n  vec2 vxM = evalVelocity(uv - vec2(e, 0.0), cylPos, cylR, tAnim, reyn, stFreq);\n  vec2 vyP = evalVelocity(uv + vec2(0.0, e), cylPos, cylR, tAnim, reyn, stFreq);\n  vec2 vyM = evalVelocity(uv - vec2(0.0, e), cylPos, cylR, tAnim, reyn, stFreq);\n  float omega = (vxP.y - vxM.y - (vyP.x - vyM.x)) / (2.0 * e);\n\n  // Advected streamline dye streaks to reveal flow topology\n  float psi = streamPsi(uv, cylPos, cylR, tAnim, reyn, stFreq);\n  float streak = smoothstep(0.06, 0.01, abs(fract(psi * 7.5 + 0.5) - 0.5));\n\n  vec3 col = vortPalette(omega * 0.22);\n  float speed = length(vel);\n  col += vec3(0.18, 0.32, 0.45) * streak * clamp(speed * 0.55, 0.15, 0.65);\n\n  // Microscopic D2Q9 lattice stencil overlay showing discrete velocity population arrows per cell\n  if (gridVis > 0.01) {\n    float cellScale = 14.0;\n    vec2 cellId = floor(uv * cellScale);\n    vec2 cellCenter = (cellId + 0.5) / cellScale;\n    vec2 lf = fract(uv * cellScale) - 0.5;\n    vec2 cVel = evalVelocity(cellCenter, cylPos, cylR, tAnim, reyn, stFreq);\n    float cSpd = length(cVel);\n    vec2 dir = cVel / max(cSpd, 1e-4);\n    // Project local offset onto cell velocity direction to draw a tiny directional D2Q9 flux vector\n    float proj = clamp(dot(lf, dir), 0.0, clamp(cSpd * 0.32, 0.08, 0.38));\n    float dVec = length(lf - dir * proj);\n    float dDot = length(lf);\n    float glyph = max(smoothstep(0.055, 0.018, dVec), smoothstep(0.075, 0.03, dDot) * 0.65);\n    col += vec3(0.75, 0.90, 1.0) * glyph * 0.26 * gridVis;\n  }\n\n  // Solid bounce-back cylindrical obstacle (no-slip LBM boundary condition)\n  float dCyl = length(uv - cylPos) - cylR;\n  if (dCyl < 0.0) {\n    vec2 rel = (uv - cylPos) / cylR;\n    float nz = sqrt(max(1.0 - dot(rel, rel), 0.0));\n    vec3 cn = normalize(vec3(rel, nz));\n    float diff = max(dot(cn, normalize(vec3(0.5, 0.7, 0.6))), 0.0);\n    col = vec3(0.14, 0.17, 0.23) * (0.35 + 0.85 * diff);\n  }\n  col = mix(col, vec3(0.86, 0.92, 1.0), smoothstep(px * 3.0, px * 0.6, abs(dCyl)) * 0.9);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "lattice-boltzmann-fluids",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:32.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4163,
      "std": 0.2209,
      "min": 0.2442,
      "max": 0.9072
     },
     "image": "/specimens/lattice-boltzmann-fluids-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "stable-fluids",
  "sph-fluids",
  "gray-scott-reaction-diffusion"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/simulation/lattice-boltzmann-fluids.json"
 },
 "solves": [
  "simulate wind flowing around complex obstacles",
  "need gpu-friendly fluid with many steps per frame",
  "smoke around voxelised geometry",
  "fluid solver with simple local parallel updates",
  "wind tunnel style airflow visualisation"
 ],
 "authority": "Chen & Doolen, 1998",
 "url": "https://texelatlas.vercel.app/t/lattice-boltzmann-fluids/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 28.31,
  "tier": "heavy",
  "p50_ms": 0.8889,
  "p95_ms": 0.9218,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "lattice-boltzmann-fluids-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 23.4,
   "tier": "heavy",
   "p50_ms": 0.3697,
   "p95_ms": 0.37,
   "speedup_x": 2.4,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 19.64,
   "tier": "moderate",
   "p50_ms": 0.5656,
   "p95_ms": 0.5658,
   "speedup_x": 1.57,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}