ede2dee772
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.
69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "Organ.h"
|
|
#include <string>
|
|
|
|
/**
|
|
* @brief Represents the state of the bladder muscles and sphincters.
|
|
*/
|
|
enum class MicturitionState {
|
|
FILLING,
|
|
FULL,
|
|
VOIDING
|
|
};
|
|
|
|
/**
|
|
* @brief Represents the Bladder, which stores urine.
|
|
*/
|
|
class MEDICAL_LIB_API Bladder : public Organ {
|
|
public:
|
|
/**
|
|
* @brief Constructor for the Bladder class.
|
|
* @param id The ID of the organ.
|
|
*/
|
|
Bladder(int id);
|
|
|
|
/**
|
|
* @brief Updates the bladder's state over a time interval.
|
|
* @param patient A reference to the patient object.
|
|
* @param deltaTime_s The time elapsed in seconds.
|
|
*/
|
|
void update(Patient& patient, double deltaTime_s) override;
|
|
|
|
/**
|
|
* @brief Gets a string summary of the bladder's state.
|
|
* @return A string containing the bladder's state.
|
|
*/
|
|
std::string getSummary() const override;
|
|
|
|
/**
|
|
* @brief Adds urine from the kidneys.
|
|
* @param amount_ml The volume of urine to add.
|
|
*/
|
|
void addUrine(double amount_ml);
|
|
|
|
// --- Getters for Bladder State ---
|
|
|
|
/** @brief Gets the current volume of urine in the bladder in mL. */
|
|
double getVolume() const;
|
|
|
|
/** @brief Gets the current pressure inside the bladder in cmH2O. */
|
|
double getPressure() const;
|
|
|
|
/** @brief Gets the current state of the micturition cycle. */
|
|
MicturitionState getCurrentState() const;
|
|
|
|
private:
|
|
// --- Helper to convert enum to string ---
|
|
std::string stateToString(MicturitionState state) const;
|
|
|
|
// --- Physiological Parameters ---
|
|
MicturitionState currentState;
|
|
double currentVolume_mL;
|
|
double pressure_cmH2O;
|
|
bool internalSphincterClosed;
|
|
|
|
const double capacity_mL = 500.0;
|
|
const double pressureThreshold_cmH2O = 40.0; // Pressure at which voiding reflex is strong
|
|
};
|