跳到正文
DEV Community· sishiya (しし屋)·· 2 小時前AI 評分48

計算各房間空氣的「年齡」:通風網絡與二維氣流

Computing how 'old' the air in each room is (ventilation network + 2D flow + age of air)

AI 導讀

作者製作網頁,計算兩居室公寓各處空氣的「年齡」,並模擬通風網絡與室內二維氣流。以 10 cm 網格計算後,出口平均空氣年齡達名義時間常數 τ 的 0.999–1.000。每幀計算時間低於 15 ms;快速模式會固定氣流模式,只推進空氣年齡與煙霧。

正文

How much faster does air get replaced with two windows open instead of one? With only the exhaust fan running, where does air stagnate?

I made a page that computes this for a two-bedroom apartment and colors how old the air is in each spot (the age of air). No libraries.

https://sishiya.github.io/manabi-lab/air-flow/?lang=en

The calculation has three stages:

  1. How much air the whole home exchanges (ventilation network)
  2. How air moves through the home (2D flow)
  3. How long ago the air at each spot came in from outside (age of air)

This post covers the equations for each and where I got stuck in stage 3.

1. How much air: find the indoor pressure by bisection

Windows, the front door, vents and leaks use the orifice equation:

Q = αA · sign(Δp) · √(2|Δp| / ρ)      Δp = wind pressure on the outer wall − indoor pressure p

Exhaust fans use a straight-line approximation of "less flow the harder they pull" (Q = q·(1 − Δp/p_max)). Wind pressure comes from a wind-pressure-coefficient formula for low-rise buildings (Swami and Chandra), using the angle between the wall and the wind.

Once indoor pressure p is known, every opening's flow is known. So bisection finds the p where inflow equals outflow. Closed doors still connect through the gap underneath, so normally the whole home is treated as one space.

2. Flow in the home: a 2D MAC grid

A horizontal plane about 1 m above the floor is split into 10 cm cells (96×60), on a MAC grid with a 0.05-second step.

Order of one step:

  1. Forcing from jets (circulator fan, air conditioner, wind coming in through open windows)
  2. Advection (semi-Lagrangian)
  3. Viscosity and drag
  4. Projection (pressure equation, 40 SOR iterations, starting from the previous solution)

Flows from stage 1 enter as sources in cells just inside openings and sinks in fan cells.

One trick: 2D flow = "real flow ÷ ceiling height 2.4 m". That keeps the volume equal to the real one, so the exchange time V/Q comes out right.

Closed doors stay fluid cells, but the face permeability is set to 0.05. What is pushed by pressure difference (through the gap under the door) gets through; stirring flow mostly does not.

3. Age of air: "air ages one second per second"

The age of air is how long it has been since that air came in from outside. Thinking of it like this, it can be solved with an ordinary advection–diffusion equation:

  • air coming in from outside is 0 seconds old
  • in every cell, air ages one second per second (source S = 1)

Each cell gets a finite-volume, upwind, implicit (backward Euler) equation:

(DX/Δt)(a − a_old) + Σout u·a − Σin u·a_n + q_out·a + (D/DX) Σ(a − a_n) = DX · S

Smoke concentration uses the same equation with S = 0.

Stuck 1: time would not advance

At first I solved this system with a few Gauss–Seidel sweeps. With a large Δt per frame, the age of air barely moved.

Adding diffusion makes the problem elliptic, and a few sweeps do not converge. Switching to BiCGSTAB (with diagonal preconditioning) made it advance properly.

Stuck 2: subtracting twice at inflow cells

In cells where air enters through a window, I had added a term "as much air leaves this cell as enters". But entering air leaves through the faces to the neighbors, so that subtracted it twice. Now the outflow term is only for exit cells and for exchange at a single open window.

The check: the age at the exit equals V/Q

Both mistakes were found with one check.

The mean age of the air leaving (weighted by flow) equals the nominal time constant τ = V/Q, regardless of the flow pattern (Sandberg). However much stagnation there is inside, this holds at the exit.

At first it came out at 1/10 of τ, which is how I noticed. After the fixes, every scene gives 0.999–1.000 of τ.

The same ratio gives the air exchange efficiency:

air exchange efficiency = τ / (2 × mean age of air in the home)

Speed tricks

  • Flow is computed at most 3 × 0.05 seconds per frame (about 9× speed)
  • At faster settings (1 hour per second, etc.), the flow pattern is frozen and only the age of air and smoke advance
  • When one frame's Δt exceeds τ/6, it is split in two

A frame's computation stays under 15 ms.

Main sources

  • M. Sandberg (1981) "What is ventilation efficiency?", Building and Environment 16
  • D. Etheridge, M. Sandberg (1996) Building Ventilation: Theory and Measurement, Wiley
  • M. V. Swami, S. Chandra (1988) ASHRAE Transactions 94 (wind pressure coefficients for low-rise buildings)
  • P. R. Warren, L. M. Parkins (1985) "Single-sided ventilation through open windows"

Fan flows, leak sizes and so on are typical values for products and homes.


This page is part of Manabi Lab, a series of small learning apps that run in the browser (English and Japanese). The code and this post were written together with AI (Claude).

https://sishiya.github.io/manabi-lab/?lang=en

來源:DEV Community · dev.to