Commit b8e5f5c8 authored by Rachel Clipp's avatar Rachel Clipp Committed by Aaron Bray
Browse files

Correct usage of absolute value method

(cherry picked from commit 0ebeb6a5)
parent 3c1acba0
......@@ -36,6 +36,7 @@
#include <fstream>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#ifdef _MSC_VER
#include <direct.h>
......
......@@ -21,7 +21,6 @@
#include "properties/SEScalarMassPerVolume.h"
#include "properties/SEScalarAmountPerVolume.h"
#include <cmath>
#include <iterator>
DataTrack::DataTrack() : DataTrack(nullptr)
......
......@@ -2133,7 +2133,7 @@ void Cardiovascular::CalculatePleuralCavityVenousEffects()
{
//The left and right pleural pressures are likely to have large differences only due to a pneumothorax
//Pressure difference causes a mediastinum shift
double pleuralCavityPressureDiff_cmH2O = abs(m_leftPleuralCavity->GetPressure(PressureUnit::cmH2O) - m_rightPleuralCavity->GetPressure(PressureUnit::cmH2O));
double pleuralCavityPressureDiff_cmH2O = std::abs(m_leftPleuralCavity->GetPressure(PressureUnit::cmH2O) - m_rightPleuralCavity->GetPressure(PressureUnit::cmH2O));
double maxPressureDiff_cmH2O = 40.0;
double maxResistanceMultiplier = 10.0;
......
......@@ -73,7 +73,6 @@ void Nervous::Initialize()
m_ArterialOxygenBaseline_mmHg = 0;
m_ArterialCarbonDioxideBaseline_mmHg = 0;
m_BaroreceptorActivityTime_s = 0.0;
m_sedationDampeningEffect = 0;
}
//--------------------------------------------------------------------------------------------------
......@@ -174,13 +173,16 @@ void Nervous::BaroreceptorFeedback()
double meanArterialPressure_mmHg = m_data.GetCardiovascular().GetMeanArterialPressure(PressureUnit::mmHg);
UpdateBaroreceptorThresholds();
//Dampen response due to sedation
double sedationDampeningEffect = m_data.GetDrugs().GetSedationLevel().GetValue() * 0.35; //maximum slope reduction of 35% - making that up right now
//update nu - the slope response of the firing rate
//nu *= (1 - m_sedationDampeningEffect); TODO: Add this back when I have data for validation
//nu *= (1 - sedationDampeningEffect); TODO: Add this back when I have data for validation
//Adjusting the mean arterial pressure set-point to account for cardiovascular drug effects
m_meanArterialPressureBaseline_mmHg = m_meanArtrialPressurePatientBaseline_mmHg //m_MeanArterialPressureNoFeedbackBaseline_mmHg
+ m_data.GetDrugs().GetMeanBloodPressureChange(PressureUnit::mmHg)
+ m_data.GetEnergy().GetExerciseMeanArterialPressureDelta(PressureUnit::mmHg);
+ m_data.GetEnergy().GetExerciseMeanArterialPressureDelta(PressureUnit::mmHg);
double sympatheticFraction = 1.0 / (1.0 + pow(meanArterialPressure_mmHg / m_meanArterialPressureBaseline_mmHg, nu));
double parasympatheticFraction = 1.0 / (1.0 + pow(meanArterialPressure_mmHg / m_meanArterialPressureBaseline_mmHg, -nu));
......@@ -231,31 +233,19 @@ void Nervous::BaroreceptorFeedback()
//--------------------------------------------------------------------------------------------------
void Nervous::UpdateBaroreceptorThresholds()
{
UpdateBaroreceptorActivityStatus();
//Need to change the threshold every 7 minutes based on over activation
double thresholdChangeTime_s = 420.0;
if (m_BaroreceptorFeedbackStatus && m_BaroreceptorActivityTime_s > thresholdChangeTime_s)
{
//Adjust the threshold by up to 30%
double meanArterialPressure_mmHg = m_data.GetCardiovascular().GetMeanArterialPressure(PressureUnit::mmHg);
double pressureDeviation = meanArterialPressure_mmHg - m_meanArterialPressureBaseline_mmHg;
m_meanArtrialPressurePatientBaseline_mmHg += 0.35*pressureDeviation;
m_ss << "Baroreceptor threshold updated to " << m_meanArtrialPressurePatientBaseline_mmHg << " mmHg";
Warning(m_ss);
//Reset the time
m_BaroreceptorActivityTime_s = 0.0;
}
//Dampen response due to sedation
double sedationLevel = m_data.GetDrugs().GetSedationLevel().GetValue();
//maximum slope reduction of 25% - making that up right now
double maxSedationEffect = 0.35;
m_sedationDampeningEffect = maxSedationEffect * sedationLevel;
UpdateBaroreceptorActivityStatus();
//Need to change the threshold every 7 minutes based on over activation
double thresholdChangeTime_s = 420.0;
if (m_BaroreceptorFeedbackStatus && m_BaroreceptorActivityTime_s > thresholdChangeTime_s)
{
//Adjust the threshold by up to 30%
double meanArterialPressure_mmHg = m_data.GetCardiovascular().GetMeanArterialPressure(PressureUnit::mmHg);
double pressureDeviation = meanArterialPressure_mmHg - m_meanArterialPressureBaseline_mmHg;
m_meanArtrialPressurePatientBaseline_mmHg += 0.35*pressureDeviation;
//Reset the time
m_BaroreceptorActivityTime_s = 0.0;
}
}
//--------------------------------------------------------------------------------------------------
......@@ -268,26 +258,28 @@ void Nervous::UpdateBaroreceptorThresholds()
//--------------------------------------------------------------------------------------------------
void Nervous::UpdateBaroreceptorActivityStatus()
{
//Determine if barorectors are active and for how long
double meanArterialPressure_mmHg = m_data.GetCardiovascular().GetMeanArterialPressure(PressureUnit::mmHg);
double pressureDeviationFraction = abs(meanArterialPressure_mmHg - m_meanArterialPressureBaseline_mmHg) / m_meanArterialPressureBaseline_mmHg;
if (pressureDeviationFraction > 0.05)
{
if (!m_BaroreceptorFeedbackStatus)
{
m_BaroreceptorActivityTime_s = 0.0;
m_BaroreceptorFeedbackStatus = true;
}
else
{
m_BaroreceptorActivityTime_s += m_dt_s;
}
}
else
{
if (m_BaroreceptorFeedbackStatus)
m_BaroreceptorFeedbackStatus = false;
}
//Determine if barorectors are active and for how long
double meanArterialPressure_mmHg = m_data.GetCardiovascular().GetMeanArterialPressure(PressureUnit::mmHg);
double pressureDeviationFraction = std::abs(meanArterialPressure_mmHg - m_meanArterialPressureBaseline_mmHg) / m_meanArterialPressureBaseline_mmHg;
if (pressureDeviationFraction > 0.05)
{
if (!m_BaroreceptorFeedbackStatus)
{
m_BaroreceptorActivityTime_s = 0.0;
m_BaroreceptorFeedbackStatus = true;
}
else
{
m_BaroreceptorActivityTime_s += m_dt_s;
}
}
else
{
if (m_BaroreceptorFeedbackStatus)
{
m_BaroreceptorFeedbackStatus = false;
}
}
}
//--------------------------------------------------------------------------------------------------
......
......@@ -52,7 +52,6 @@ protected:
//Baroreceptor threshold parameters
double m_BaroreceptorActivityTime_s;
double m_meanArterialPressureBaseline_mmHg;
double m_sedationDampeningEffect;
double m_meanArtrialPressurePatientBaseline_mmHg;
// Configuration fractions representing the amount by which each quantity can change due to baroreceptors;
......
......@@ -16,8 +16,6 @@
#include "properties/SEScalarInversePressure.h"
#include "unsupported/Eigen/NonLinearOptimization"
#include <cmath>
#include <algorithm>
//#define VERBOSE
......@@ -315,7 +313,7 @@ void SaturationCalculator::CalculateCarbonMonoxideSpeciesDistribution(SELiquidCo
}
// Check to make sure hemoglobin was conserved
newTotalHb_mM = HbUnbound_mM + HbO2_mM + HbO2CO2_mM + HbCO2_mM + targetBoundCO_mM;
if (abs(newTotalHb_mM - totalHb_mM) > tolerance)
if (std::abs(newTotalHb_mM - totalHb_mM) > tolerance)
Warning("Hemoglobin not conserved during carbon monoxide species distribution calculation.");
// We can now set and balance for CO.
......@@ -430,12 +428,12 @@ void SaturationCalculator::CalculateBloodGasDistribution(SELiquidCompartment& cm
double newHb_mM = m_subHbQ->GetMolarity(AmountPerVolumeUnit::mmol_Per_L);
double newTotalHb_mM = newHbO2_mM + newHbCO2_mM + newHbO2CO2_mM + newHb_mM + newHbCO_mM;
double diffTotal = newTotalHb_mM - oldTotalHb_mM;
if (abs(diffTotal) > 1.0e-8)
if (std::abs(diffTotal) > 1.0e-8)
{
std::stringstream debugSS;
debugSS << "CalculateCarbonMonoxideSpeciesDistribution failed to conserve hemoglobin. Difference = ";
debugSS << diffTotal;
if (abs(diffTotal) > 1.0e-8)
if (std::abs(diffTotal) > 1.0e-8)
Warning(debugSS.str());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment