Feat: Implement interconnected organ simulation
This commit refactors the organ simulation to enable dynamic interactions between organs, replacing the previous "faked" or hardcoded connections.
Key changes include:
- Major Refactoring: Changed the `Organ::update` method signature to `update(Patient& patient, double deltaTime_s)`, allowing organs to access the shared patient state and other organs. This was propagated to all organ classes.
- Blood Chemistry Model: Introduced a central `Blood` struct in the `Patient` model to track shared resources like oxygen, CO2, glucose, and toxins.
- Organ System Interconnections:
- Lungs & Brain: Lungs now perform gas exchange affecting the blood. The brain consumes O2, produces CO2, and its GCS is affected by hypoxia/hypercapnia.
- Liver-Gallbladder: Gallbladder now receives bile directly from the liver's production rate.
- Digestive System: Stomach passes chyme to the intestines, which absorb glucose into the blood. The pancreas responds to blood glucose changes.
- Renal System: Kidneys' GFR is now influenced by the heart's aortic pressure, and they produce urine that fills the bladder directly.
- Cardiovascular & Neurological: The heart rate responds to hypoxia, and the brain uses live aortic pressure from the heart.
- Comprehensive Test Scenario: Updated the main example to include a 60-second simulation with a meal and a lung injury event to verify the new interconnected system.
This creates a more realistic and scalable physiological simulation framework where organ behaviors are emergent from their interactions.
This commit is contained in:
+25
-12
@@ -1,4 +1,5 @@
|
||||
#include "MedicalLib/Pancreas.h"
|
||||
#include "MedicalLib/Patient.h"
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
@@ -19,22 +20,34 @@ Pancreas::Pancreas(int id)
|
||||
amylaseSecretion_U_per_L(80.0),
|
||||
lipaseSecretion_U_per_L(40.0) {}
|
||||
|
||||
void Pancreas::update(double deltaTime_s) {
|
||||
// In a real model, hormone secretion would be driven by blood glucose.
|
||||
// Enzyme secretion would be driven by food in the duodenum.
|
||||
void Pancreas::update(Patient& patient, double deltaTime_s) {
|
||||
// Hormone secretion is driven by blood glucose.
|
||||
const double glucose = patient.blood.glucose_mg_per_dL;
|
||||
const double highGlucoseThreshold = 120.0;
|
||||
const double lowGlucoseThreshold = 80.0;
|
||||
|
||||
// Insulin response
|
||||
if (glucose > highGlucoseThreshold) {
|
||||
insulinSecretion_units_per_hr += (glucose - highGlucoseThreshold) * 0.1 * deltaTime_s;
|
||||
} else {
|
||||
insulinSecretion_units_per_hr -= 0.5 * deltaTime_s;
|
||||
}
|
||||
|
||||
// Glucagon response
|
||||
if (glucose < lowGlucoseThreshold) {
|
||||
glucagonSecretion_ng_per_hr += (lowGlucoseThreshold - glucose) * 0.2 * deltaTime_s;
|
||||
} else {
|
||||
glucagonSecretion_ng_per_hr -= 1.0 * deltaTime_s;
|
||||
}
|
||||
|
||||
// Enzyme secretion would be driven by food in the duodenum (not yet modeled).
|
||||
// For now, we just simulate minor fluctuations around a baseline.
|
||||
|
||||
// Endocrine fluctuations
|
||||
insulinSecretion_units_per_hr += getFluctuation(0.05);
|
||||
glucagonSecretion_ng_per_hr += getFluctuation(0.5);
|
||||
|
||||
// Exocrine fluctuations
|
||||
amylaseSecretion_U_per_L += getFluctuation(0.2);
|
||||
lipaseSecretion_U_per_L += getFluctuation(0.2);
|
||||
|
||||
// Clamp to healthy ranges
|
||||
insulinSecretion_units_per_hr = std::clamp(insulinSecretion_units_per_hr, 0.5, 2.0);
|
||||
glucagonSecretion_ng_per_hr = std::clamp(glucagonSecretion_ng_per_hr, 40.0, 60.0);
|
||||
// Clamp to healthy/possible ranges
|
||||
insulinSecretion_units_per_hr = std::clamp(insulinSecretion_units_per_hr, 0.5, 10.0);
|
||||
glucagonSecretion_ng_per_hr = std::clamp(glucagonSecretion_ng_per_hr, 20.0, 100.0);
|
||||
amylaseSecretion_U_per_L = std::clamp(amylaseSecretion_U_per_L, 60.0, 100.0);
|
||||
lipaseSecretion_U_per_L = std::clamp(lipaseSecretion_U_per_L, 20.0, 60.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user