Skip to content

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

VentilSim: Closed-Loop Mechanical Ventilation & Respiratory Mechanics Simulator

CI Python Version License: MIT

A clinical critical care pulmonology library simulating closed-loop mechanical ventilation waveforms, nonlinear ARDS respiratory mechanics, ARDSNet lung-protective ventilation protocol auditing (driving pressure, mechanical power), and patient-ventilator asynchrony (PVA) detection.


1. Clinical Intensive Care (ICU) Motivation

Mechanical ventilation is life-saving in respiratory failure (ARDS, severe pneumonia, COPD exacerbations), but improper settings cause catastrophic Ventilator-Induced Lung Injury (VILI):

  1. Barotrauma & Volutrauma: High transpulmonary pressures ($P_{\text{plat}} > 30\text{ cmH}_2\text{O}$) and excessive tidal volumes ($> 8\text{ mL/kg}$ PBW) rupture alveoli and induce diffuse alveolar damage.
  2. Driving Pressure ($\Delta P$): Amato et al. (NEJM, 2015) established that driving pressure $\Delta P = P_{\text{plat}} - \text{PEEP} > 14\text{ cmH}_2\text{O}$ is the single strongest predictor of ARDS in-hospital mortality.
  3. Mechanical Power (Ergotrauma): Gattinoni et al. (Intensive Care Med, 2016) quantified the energy delivered to the lung tissue per minute ($\text{MP} > 17\text{ J/min}$ strongly correlates with VILI).
  4. Patient-Ventilator Asynchrony (PVA): Ineffective triggering and double triggering (breath-stacking) cause patient exhaustion, air-trapping, and prolonged mechanical ventilation.

2. Mathematical & Physiological Foundations

flowchart LR
    A["Ventilator Mode: VCV / PCV / PSV"] --> B["Equation of Motion Solver"]
    C["Respiratory Mechanics: C_rs, R_aw, PEEP"] --> B
    D["Patient Effort: P_mus(t)"] --> B
    B --> E["Waveforms: Paw(t), Flow(t), Vol(t)"]
    E --> F["ARDSNet Clinical Auditor"]
    E --> G["PVA Asynchrony Detector"]
    F --> H["Driving Pressure & Mechanical Power"]
Loading

A. Dynamic Equation of Motion

The pressure at the airway opening ($P_{\text{aw}}$) satisfies the classical Otis-Mead balance:

$$P_{\text{aw}}(t) = P_{\text{alv}}(t) + P_{\text{resistive}}(t) - P_{\text{mus}}(t)$$

$$P_{\text{aw}}(t) = \left( \frac{V(t)}{C_{\text{rs}}} + \text{PEEP} \right) + R_{\text{aw}} \cdot \dot{V}(t) - P_{\text{mus}}(t)$$

where:

  • $V(t)$: Instantaneous lung volume relative to Functional Residual Capacity (FRC).
  • $\dot{V}(t)$: Instantaneous airflow rate ($\text{L/s}$).
  • $C_{\text{rs}}$: Respiratory system compliance ($\text{L/cmH}_2\text{O}$, normal: $0.05-0.08$, ARDS: $0.015-0.025$).
  • $R_{\text{aw}}$: Airway resistance ($\text{cmH}_2\text{O} \cdot \text{s} / \text{L}$).
  • $P_{\text{mus}}(t)$: Spontaneous diaphragmatic muscular pressure.

B. ARDSNet Lung-Protective Biomarkers

  1. Driving Pressure ($\Delta P$): $$\Delta P = P_{\text{plat}} - \text{PEEP} \le 14\text{ cmH}_2\text{O}$$
  2. Static Respiratory Compliance ($C_{\text{stat}}$): $$C_{\text{stat}} = \frac{V_T}{P_{\text{plat}} - \text{PEEP}}$$
  3. Gattinoni Mechanical Power (MP): $$\text{MP} = 0.098 \cdot \text{RR} \cdot V_T \cdot \left[ P_{\text{peak}} - \frac{\Delta P}{2} \right] \quad (\text{Joules/min})$$ Threshold $\text{MP} \le 17\text{ J/min}$.

C. Patient-Ventilator Asynchrony Index (AI)

$$\text{AI} = \frac{\text{Number of Asynchronous Breaths}}{\text{Total Breaths (Delivered + Missed)}} \times 100%$$ Clinical alert triggered when $\text{AI} > 10%$.


3. Installation

git clone https://github.com/ZengLLQ/ventil-sim.git
cd ventil-sim
pip install -e .

4. Command-Line Interface (CLI)

Simulate Severe ARDS Breath in Volume Control Mode

ventil-sim simulate --condition ards --vt 420 --rr 20 --height 175 --sex male

Output:

=== Mechanical Ventilator Real-Time Waveform Monitor ===

[Paw - Airway Pressure (cmH2O)]
35.0 |                   *                                              |
27.5 |                  * *****************                             |
20.0 |                 *                   *                            |
12.5 |*****************                     ****************************|
     +-----------------------------------------------------------------+

[Flow - Airflow Rate (L/s)]
+0.8 |     ****************                                            |
 0.0 |.....                ................vvvvvvvv....................|
-0.8 |                                             vv                  |
     +-----------------------------------------------------------------+

[Volume - Tidal Volume (mL)]
 420 |                   ****************                               |
 210 |                 **                *                              |
   0 |*****************                   ******************************|
     +-----------------------------------------------------------------+
       0.0 s                                                     3.00 s

============================================================================
  ARDSNet Lung-Protective Mechanical Ventilation Clinical Audit
============================================================================
Status:                      Protective (ARDSNet Compliant)
Predicted Body Weight (PBW): 70.3 kg
Tidal Volume per PBW:        5.98 mL/kg (Target: 4-8 mL/kg)
Plateau Pressure (P_plat):   33.1 cmH2O (Target: <= 30 cmH2O)
Driving Pressure (Delta P):  19.1 cmH2O (Target: <= 14 cmH2O)
Static Compliance (C_stat):  22.0 mL/cmH2O
Mechanical Power (MP):       22.5 J/min (Target: < 17 J/min)

Audit Asynchrony Index

ventil-sim asynchrony

5. Python API Usage

from ventil_sim import (
    RespiratoryMechanicsParameters,
    RespiratorySystem,
    MechanicalVentilator,
    ARDSProtectiveAuditor,
)

# 1. Setup ARDS mechanics
params = RespiratoryMechanicsParameters(
    compliance_ml_cmh2o=20.0,
    resistance_cmh2o_s_l=6.0,
    peep_cmh2o=14.0,
)
lungs = RespiratorySystem(params)

# 2. Simulate mechanical ventilation breath
ventilator = MechanicalVentilator(lungs)
waveforms = ventilator.simulate_vcv_breath(tidal_volume_ml=420.0, respiratory_rate=20.0)

# 3. Clinical audit against ARDSNet targets
pbw = ARDSProtectiveAuditor.calculate_pbw(height_cm=175.0, sex="male")
auditor = ARDSProtectiveAuditor()
report = auditor.audit_breath(waveforms, predicted_body_weight_kg=pbw)
print(f"Compliance: {report.compliance_status.value}")
print(f"Driving Pressure: {report.driving_pressure_cmh2o:.1f} cmH2O")
print(f"Mechanical Power: {report.mechanical_power_j_min:.1f} J/min")

6. Testing

pytest -v

7. Clinical References & Guidelines

  • Amato, M. B., et al. (2015). Driving pressure and survival in the acute respiratory distress syndrome. New England Journal of Medicine, 372(8), 747–755.
  • ARDS Definition Task Force. (2012). Acute respiratory distress syndrome: the Berlin Definition. JAMA, 307(23), 2526–2533.
  • Gattinoni, L., et al. (2016). Mechanical power: a new tool for understand mechanical ventilation. Intensive Care Medicine, 42(10), 1567–1575.
  • Thille, A. W., et al. (2006). Patient-ventilator asynchrony during assisted mechanical ventilation. Intensive Care Medicine, 32(10), 1515–1522.

Releases

Packages

Contributors

Languages