Files
medicallib/examples/main.cpp
T
google-labs-jules[bot] dbe8490cb1 feat: Implement detailed mechanical heart simulation
This commit introduces a major enhancement to the heart simulation, adding a detailed mechanical model of the cardiac cycle that is synchronized with the existing EKG waveform.

Key features:
- The Heart class is refactored to include data structures for the four chambers (atria and ventricles) and four valves (mitral, tricuspid, aortic, pulmonary).
- The `update` method now simulates the phases of the cardiac cycle, including atrial and ventricular systole and diastole.
- Chamber pressures and volumes are dynamically updated based on the phase of the cycle.
- Valve statuses (open/closed) are determined by pressure gradients between chambers.
- Ejection Fraction is now calculated based on the simulated end-diastolic and end-systolic volumes of the left ventricle.
- The example program has been updated to display a live, detailed summary of the heart's mechanical status, showing pressures, volumes, and valve states as they change over time.
2025-08-20 06:22:24 +00:00

43 lines
1.4 KiB
C++

#include <iostream>
#include <memory>
#include <thread>
#include <chrono>
#include <vector>
#include <string>
#include "MedicalLib/MedicalLib.h"
#include "MedicalLib/Patient.h"
#include "MedicalLib/Organ.h"
#include "MedicalLib/Heart.h"
int main() {
// Initialize a new patient with a 12-lead heart
Patient patient = initializePatient(1, 12);
std::cout << "Patient created with ID: " << patient.patientId << std::endl;
// Simulate time passing and print a live summary
const double simulationTime_s = 10.0;
const double deltaTime_s = 0.05; // 20 Hz update rate for display
const int numSteps = static_cast<int>(simulationTime_s / deltaTime_s);
std::cout << "\n--- Simulating " << simulationTime_s << " seconds of heart activity... ---" << std::endl;
for (int i = 0; i < numSteps; ++i) {
// Clear console on systems that support ANSI escape codes
#if defined(__linux__) || defined(__APPLE__)
std::cout << "\033[2J\033[1;1H";
#endif
updatePatient(patient, deltaTime_s);
std::cout << "Time: " << i * deltaTime_s << "s / " << simulationTime_s << "s\n" << std::endl;
std::cout << getOrganSummary(patient, "Heart") << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
std::cout << "\n--- Simulation Complete. Final State: ---\n" << std::endl;
std::cout << getPatientSummary(patient) << std::endl;
return 0;
}