Skip to content

Commit 5632a3b

Browse files
committed
Cleaning up attackers: introduce a vector of attackers for a cell not to have to look at all cells
1 parent cbf625e commit 5632a3b

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

core/PhysiCell_cell.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,9 @@ void delete_cell( int index )
12071207
// released internalized substrates (as of 1.5.x releases)
12081208
pDeleteMe->release_internalized_substrates();
12091209

1210+
// new Dec 2, 2025
1211+
pDeleteMe->remove_self_from_attackers();
1212+
12101213
// performance goal: don't delete in the middle -- very expensive reallocation
12111214
// alternative: copy last element to index position, then shrink vector by 1 at the end O(constant)
12121215

@@ -3433,6 +3436,15 @@ void Cell::remove_all_spring_attachments( void )
34333436
return;
34343437
}
34353438

3439+
void Cell::remove_self_from_attackers( void )
3440+
{
3441+
for (Cell* pCell : phenotype.cell_interactions.attacked_by)
3442+
{
3443+
pCell->phenotype.cell_interactions.pAttackTarget = NULL;
3444+
}
3445+
phenotype.cell_interactions.attacked_by.clear();
3446+
return;
3447+
}
34363448

34373449
void attach_cells( Cell* pCell_1, Cell* pCell_2 )
34383450
{

core/PhysiCell_cell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class Cell : public Basic_Agent
238238
void attach_cell_as_spring( Cell* pAddMe ); // done
239239
void detach_cell_as_spring( Cell* pRemoveMe ); // done
240240
void remove_all_spring_attachments( void ); // done
241+
void remove_self_from_attackers( void );
241242

242243
// I want to eventually deprecate this, by ensuring that
243244
// critical BioFVM and PhysiCell data elements are synced when they are needed

core/PhysiCell_phenotype.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ Cell_Interactions::Cell_Interactions()
12771277
immunogenicities = {1};
12781278

12791279
pAttackTarget = NULL;
1280+
attacked_by = std::vector<Cell*>{};
12801281
total_damage_delivered = 0.0;
12811282

12821283
attack_duration = 30.0; // a typical attack duration for a T cell using perforin/granzyme is ~30 minutes

core/PhysiCell_phenotype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ class Cell_Interactions
698698
double attack_damage_rate;
699699

700700
Cell* pAttackTarget;
701+
std::vector<Cell*> attacked_by;
701702
double total_damage_delivered;
702703

703704
double attack_duration;

core/PhysiCell_standard_models.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "PhysiCell_standard_models.h"
6969
#include "PhysiCell_cell.h"
7070
#include "../modules/PhysiCell_pathology.h"
71+
#include <algorithm>
7172

7273
namespace PhysiCell{
7374

@@ -1267,6 +1268,7 @@ void standard_cell_cell_interactions( Cell* pCell, Phenotype& phenotype, double
12671268
if( UniformRandom() < probability )
12681269
{
12691270
pCell->phenotype.cell_interactions.pAttackTarget = pTarget;
1271+
pTarget->phenotype.cell_interactions.attacked_by.push_back(pCell);
12701272
attacked = true;
12711273
/*
12721274
std::cout << "********* ********* ******** start atack **** " << PhysiCell_globals.current_time << std::endl;
@@ -1345,6 +1347,14 @@ void standard_cell_cell_interactions( Cell* pCell, Phenotype& phenotype, double
13451347
detach_cells_as_spring(pCell,pTarget);
13461348

13471349
pCell->phenotype.cell_interactions.pAttackTarget = NULL;
1350+
pTarget->phenotype.cell_interactions.attacked_by.erase(
1351+
std::remove(
1352+
pTarget->phenotype.cell_interactions.attacked_by.begin(),
1353+
pTarget->phenotype.cell_interactions.attacked_by.end(),
1354+
pCell),
1355+
pTarget->phenotype.cell_interactions.attacked_by.end()
1356+
);
1357+
13481358
}
13491359
}
13501360

0 commit comments

Comments
 (0)