Skip to content

Commit 508181b

Browse files
authored
Gh152 blood capacity calculation fix (#153)
Everyone turning 20 now has the same blood capacity whether they are sick or not when they turn 20, the capacity is capped at adult blood capacity (max kid capacity was slightly higher than adult capacity).
1 parent f1fd19e commit 508181b

File tree

164 files changed

+287709
-176174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+287709
-176174
lines changed

Eradication/SusceptibilityMalaria.cpp

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -228,28 +228,9 @@ namespace Kernel
228228
void SusceptibilityMalaria::Initialize(float _age, float immmod, float riskmod)
229229
{
230230
SusceptibilityVector::Initialize(_age, immmod, riskmod);
231-
232-
// how many RBC's a person should have determined by age
233-
if (_age > (20 * DAYSPERYEAR))
234-
{
235-
// This initializes the daily production of red blood cells for adults to maintain standard equilibrium RBC concentrations given RBC lifetime
236-
// N.B. Heavily caveated, because not all adults are same size. However, this keeps consistent equilibrium RBC densities, allowing study of anemia, etc...
237-
m_RBCproduction = ADULT_RBC_PRODUCTION;// 2.0*10^11 (RBCs/day)*(120 days) = 2.4x10^13 RBCs ~= 5 liters * 5x10^6 RBCs/microliter
238-
239-
// This equation tracks the blood volume separately from the equilibrium number of RBCs, allowing for non-constant RBC concentration.
240-
// m_inv_microliters_blood is 1/(microliters of blood in body)--this allows easy calculation of pathogen densities from pathogen numbers
241-
m_inv_microliters_blood = float(1 / ( (0.225 * (7300/DAYSPERYEAR) + 0.5) * 1e6 )); // 5 liters
242-
}
243-
else
244-
{
245-
// Initializes daily production of red blood cells for children to grow linearly from INFANT_RBC_PRODUCTION to ADULT_RBC_PRODUCTION by age 20
246-
// Only approximate due to linear increase in blood volume from 0.5 to 5 liters from birth to age 20 years. Non-linear growth model might be better...
247-
m_RBCproduction = int64_t(INFANT_RBC_PRODUCTION + (_age * 0.000137) * (ADULT_RBC_PRODUCTION - INFANT_RBC_PRODUCTION)); //*.000137==/7300 (linear growth to age 20)
248-
m_inv_microliters_blood = float(1 / ( (0.225 * (_age/DAYSPERYEAR) + 0.5 ) * 1e6)); // linear growth from 0.5 liters at birth to 5 liters at age 20
249-
}
250-
251-
m_RBCcapacity = m_RBCproduction * AVERAGE_RBC_LIFESPAN; // Health equilibrium of RBC is production*lifetime. This is the total number of RBC per human
252-
m_RBC = m_RBCcapacity;
231+
232+
recalculateBloodCapacity( _age );
233+
m_RBC = m_RBCcapacity; // initial m_RBC is at capacity
253234

254235
// Set up variable pyrogenic thresholds + fever killing rates
255236
m_ind_pyrogenic_threshold = SusceptibilityMalariaConfig::pyrogenic_threshold;
@@ -330,11 +311,15 @@ namespace Kernel
330311

331312
void SusceptibilityMalaria::Update(float dt)
332313
{
333-
release_assert( params() );
314+
// dt = 0.125 when infected, 1.0 otherwise
315+
release_assert(params());
334316

335317
age += dt; // age in days
336318
m_age_dependent_biting_risk = BitingRiskAgeFactor(age);
337-
recalculateBloodCapacity(age);
319+
if(age < (20 * DAYSPERYEAR + dt)) // recalculate < 20 every time step and then once when they turn 20
320+
{
321+
recalculateBloodCapacity(age);
322+
}
338323

339324
// Red blood cell dynamics
340325
if (SusceptibilityMalariaConfig::erythropoiesis_anemia_effect > 0)
@@ -569,28 +554,27 @@ namespace Kernel
569554
void SusceptibilityMalaria::recalculateBloodCapacity( float _age )
570555
{
571556
// How many RBCs a person should have determined by age.
572-
// This sets the daily production of red blood cells for adults to maintain
573-
// standard equilibrium RBC concentrations given RBC lifetime
574-
if ( _age > (20 * DAYSPERYEAR) )
557+
// Sets daily production of red blood cells for people to set their equilibrium RBC concentrations and blood volume given an RBC lifetime
558+
// Only approximate due to linear increase in blood volume from 0.5 to 5 liters with age, a better growth model would be nonlinear
559+
if (_age >= 20 * DAYSPERYEAR) // 20 years = 7300 days
575560
{
576-
// Update adults every year. TODO: this presumes DAYSPERYEAR is a multiple of dt
577-
if ( int(_age) % DAYSPERYEAR == 0 )
578-
{
579-
// 2.0*10^11 (RBCs/day)*(120 days)=2.4x10^13 RBCs ~= 5 liters * 5x10^6 RBCs/microliter
580-
m_RBCproduction = ADULT_RBC_PRODUCTION;
581-
m_inv_microliters_blood = float(1 / ( (0.225 * (7300/DAYSPERYEAR) + 0.5) * 1e6 ));
582-
m_RBCcapacity = m_RBCproduction * AVERAGE_RBC_LIFESPAN; // Health equilibrium of RBC is production*lifetime
583-
}
561+
// This initializes the daily production of red blood cells for adults to maintain standard equilibrium RBC concentrations given RBC lifetime
562+
// N.B. Heavily caveated, because not all adults are same size. However, this keeps consistent equilibrium RBC densities, allowing study of anemia, etc...
563+
m_RBCproduction = ADULT_RBC_PRODUCTION;
564+
m_inv_microliters_blood = float( 1 / ( ( 0.225 * ( 7300 / DAYSPERYEAR ) + 0.5 ) * 1e6 ) );// adult blood volume 5 liters
584565
}
585566
else
586-
{
587-
// Update children every day.
588-
// Sets daily production of red blood cells for children to set their equilibrium RBC concentrations and blood volume given an RBC lifetime
589-
// Only approximate due to linear increase in blood volume from 0.5 to 5 liters with age, a better growth model would be nonlinear
590-
m_RBCproduction = int64_t(INFANT_RBC_PRODUCTION + (_age * .000137) * (ADULT_RBC_PRODUCTION - INFANT_RBC_PRODUCTION)); //*.000137==/(20*DAYSPERYEAR)
591-
m_inv_microliters_blood = float(1 / ( (0.225 * (_age/DAYSPERYEAR) + 0.5 ) * 1e6 ));
592-
m_RBCcapacity = m_RBCproduction * AVERAGE_RBC_LIFESPAN; // Health equilibrium of RBC is production*lifetime
567+
{
568+
// linear growth from 0.5L to 5L over 0-20 years, not ideal but works for now
569+
// 0.000137 = 1/(20*DAYSPERYEAR)
570+
m_RBCproduction = int64_t( INFANT_RBC_PRODUCTION + ( _age * 0.000137) * ( ADULT_RBC_PRODUCTION - INFANT_RBC_PRODUCTION ) );
571+
if(m_RBCproduction > ADULT_RBC_PRODUCTION)
572+
{
573+
m_RBCproduction = ADULT_RBC_PRODUCTION; // cap at adult production, overrun happens to infected people at age 7299.375-7300 days
574+
}
575+
m_inv_microliters_blood = float( 1 / ( ( 0.225 * ( _age / DAYSPERYEAR ) + 0.5 ) * 1e6 ) );
593576
}
577+
m_RBCcapacity = m_RBCproduction * AVERAGE_RBC_LIFESPAN; // Health equilibrium of RBC is production*lifetime
594578
}
595579

596580
void SusceptibilityMalaria::countAntibodyVariations()

Regression/Malaria/101_Malaria_ReportInterventionData/output/InsetChart.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/101_Malaria_ReportInterventionData/output/InsetChart.linux.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/102_Malaria_MalariaChallenge/output/InsetChart.linux.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/104_Malaria_Household_5x5_Serialization/output/InsetChart.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8735,7 +8735,7 @@
87358735
0.007477736100554,
87368736
0.008269515819848,
87378737
0.008843364194036,
8738-
0.007301237434149,
8738+
0.007301236968488,
87398739
0.007040482480079,
87408740
0.006629044190049,
87418741
0.00649824924767,
@@ -22053,8 +22053,8 @@
2205322053
},
2205422054
"Header": {
2205522055
"Channels": 30,
22056-
"DTK_Version": "2.29.6 antibody_decay_improvements(7f57409a) Nov 4 2025 11:39:54",
22057-
"DateTime": "Tue Nov 4 13:39:33 2025",
22056+
"DTK_Version": "2.30.0 gh152_BloodCapacity_Calculation_Fix(050fe88582) Jan 7 2026 09:48:56",
22057+
"DateTime": "Wed Jan 7 11:06:41 2026",
2205822058
"Report_Type": "InsetChart",
2205922059
"Report_Version": "3.2",
2206022060
"Simulation_Timestep": 1,

Regression/Malaria/105_Malaria_Innate_Immune_Variation/output/InsetChart.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/105_Malaria_Innate_Immune_Variation/output/InsetChart.linux.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/106_Malaria_ReportInterventionData_GH4629/output/InsetChart.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/106_Malaria_ReportInterventionData_GH4629/output/InsetChart.linux.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Regression/Malaria/107_Malaria_Serialization_DelayedIntervention/output/InsetChart.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5902,9 +5902,9 @@
59025902
0.0003566804807633,
59035903
0.000390064669773,
59045904
0.0004215698863845,
5905-
0.0004461080825422,
5906-
0.0004527047276497,
5907-
0.0004664439184126,
5905+
0.0004461080534384,
5906+
0.0004527046985459,
5907+
0.0004664438893087,
59085908
0.000462149415398,
59095909
0.0004665091109928,
59105910
0.0004663094587158,
@@ -5920,8 +5920,8 @@
59205920
0.0004726638144348,
59215921
0.0004671269853134,
59225922
0.0004466707468964,
5923-
0.0004189886385575,
5924-
0.0003876005939674,
5923+
0.0004189886676613,
5924+
0.0003876006230712,
59255925
0.0003202469379175,
59265926
0.0002837656065822,
59275927
0.0002754237793852,
@@ -15153,8 +15153,8 @@
1515315153
},
1515415154
"Header": {
1515515155
"Channels": 30,
15156-
"DTK_Version": "2.29.6 antibody_decay_improvements(7f57409a) Nov 4 2025 11:39:54",
15157-
"DateTime": "Tue Nov 4 13:39:25 2025",
15156+
"DTK_Version": "2.30.0 gh152_BloodCapacity_Calculation_Fix(050fe88582) Jan 7 2026 09:48:56",
15157+
"DateTime": "Wed Jan 7 11:06:33 2026",
1515815158
"Report_Type": "InsetChart",
1515915159
"Report_Version": "3.2",
1516015160
"Simulation_Timestep": 1,

0 commit comments

Comments
 (0)