Skip to content

Commit 20f3f40

Browse files
authored
Merge pull request #364 from drbergman/fix-update-intracellular-first-step
update intracellular in first time step
2 parents 08b8d60 + 27f6924 commit 20f3f40

2 files changed

Lines changed: 24 additions & 44 deletions

File tree

‎core/PhysiCell_cell_container.cpp‎

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
124124
{
125125
// secretions and uptakes. Syncing with BioFVM is automated.
126126

127+
static double time_since_last_phenotype = phenotype_dt_;
128+
static double time_since_last_mechanics = mechanics_dt_;
129+
static double phenotype_threshold = phenotype_dt_ - 0.5 * diffusion_dt_;
130+
static double mechanics_threshold = mechanics_dt_ - 0.5 * diffusion_dt_;
131+
132+
bool time_for_phenotype = time_since_last_phenotype > phenotype_threshold;
133+
bool time_for_mechanics = time_since_last_mechanics > mechanics_threshold;
134+
127135
#pragma omp parallel for
128136
for( int i=0; i < (*all_cells).size(); i++ )
129137
{
@@ -132,36 +140,20 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
132140
(*all_cells)[i]->phenotype.secretion.advance( (*all_cells)[i], (*all_cells)[i]->phenotype , diffusion_dt_ );
133141
}
134142
}
135-
136-
//if it is the time for running cell cycle, do it!
137-
double time_since_last_cycle= t- last_cell_cycle_time;
138-
139-
static double phenotype_dt_tolerance = 0.001 * phenotype_dt_;
140-
static double mechanics_dt_tolerance = 0.001 * mechanics_dt_;
141143

142144
// intracellular update. called for every diffusion_dt, but actually depends on the intracellular_dt of each cell (as it can be noisy)
143-
if (initialzed)
144-
{ update_all_cells_intracellular(); }
145+
update_all_cells_intracellular();
145146

146-
if( time_since_last_cycle > phenotype_dt_ - 0.5 * diffusion_dt_ || !initialzed )
147+
if( time_for_phenotype )
147148
{
148-
// Reset the max_radius in each voxel. It will be filled in set_total_volume
149-
// It might be better if we calculate it before mechanics each time
150-
// std::fill(max_cell_interactive_distance_in_voxel.begin(), max_cell_interactive_distance_in_voxel.end(), 0.0);
151-
152-
if(!initialzed)
153-
{
154-
time_since_last_cycle = phenotype_dt_;
155-
}
156-
157149
// new as of 1.2.1 -- bundles cell phenotype parameter update, volume update, geometry update,
158150
// checking for death, and advancing the cell cycle. Not motility, though. (that's in mechanics)
159151
#pragma omp parallel for
160152
for( int i=0; i < (*all_cells).size(); i++ )
161153
{
162154
if( (*all_cells)[i]->is_out_of_domain == false )
163155
{
164-
(*all_cells)[i]->advance_bundled_phenotype_functions( time_since_last_cycle );
156+
(*all_cells)[i]->advance_bundled_phenotype_functions( time_since_last_phenotype );
165157
}
166158
}
167159

@@ -179,19 +171,13 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
179171

180172
cells_ready_to_die.clear();
181173
cells_ready_to_divide.clear();
182-
last_cell_cycle_time= t;
174+
time_since_last_phenotype = 0.0; // reset and then increment below for next cycle
183175
}
176+
177+
time_since_last_phenotype += diffusion_dt_;
184178

185-
double time_since_last_mechanics= t- last_mechanics_time;
186-
187-
// if( time_since_last_mechanics>= mechanics_dt || !initialzed)
188-
if( time_since_last_mechanics > mechanics_dt_ - 0.5 * diffusion_dt_ || !initialzed )
179+
if( time_for_mechanics )
189180
{
190-
if(!initialzed)
191-
{
192-
time_since_last_mechanics = mechanics_dt_;
193-
}
194-
195181
// new February 2018
196182
// if we need gradients, compute them
197183
if( default_microenvironment_options.calculate_gradients )
@@ -248,7 +234,6 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
248234
for( int j=0; j < pC->state.spring_attachments.size(); j++ )
249235
{
250236
Cell* pC1 = pC->state.spring_attachments[j];
251-
// standard_elastic_contact_function_confluent_rest_length(pC,pC->phenotype,pC1,pC1->phenotype,time_since_last_mechanics);
252237
standard_elastic_contact_function(pC,pC->phenotype,pC1,pC1->phenotype,time_since_last_mechanics);
253238
}
254239
}
@@ -264,15 +249,9 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
264249
standard_cell_cell_interactions(pC,pC->phenotype,time_since_last_mechanics);
265250
}
266251
// super-critical to performance! clear the "dummy" cells from phagocytosis / fusion
267-
// otherwise, comptuational cost increases at polynomial rate VERY fast, as O(10,000)
268252
// dummy cells of size zero are left ot interact mechanically, etc.
269253
if( cells_ready_to_die.size() > 0 )
270254
{
271-
/*
272-
std::cout << "\tClearing dummy cells from phagocytosis and fusion events ... " << std::endl;
273-
std::cout << "\t\tClearing " << cells_ready_to_die.size() << " cells ... " << std::endl;
274-
// there might be a lot of "dummy" cells ready for removal. Let's do it.
275-
*/
276255
for( int i=0; i < cells_ready_to_die.size(); i++ )
277256
{ cells_ready_to_die[i]->die(); }
278257
cells_ready_to_die.clear();
@@ -289,16 +268,18 @@ void Cell_Container::update_all_cells(double t, double phenotype_dt_ , double me
289268
{ pC->update_position(time_since_last_mechanics); }
290269
}
291270

292-
// When somebody reviews this code, let's add proper braces for clarity!!!
293-
294271
// Update cell indices in the container
295272
for( int i=0; i < (*all_cells).size(); i++ )
296-
if(!(*all_cells)[i]->is_out_of_domain && (*all_cells)[i]->is_movable)
297-
(*all_cells)[i]->update_voxel_in_container();
298-
last_mechanics_time=t;
273+
{
274+
if (!(*all_cells)[i]->is_out_of_domain && (*all_cells)[i]->is_movable)
275+
{ (*all_cells)[i]->update_voxel_in_container(); }
276+
}
277+
time_since_last_mechanics = 0.0; // reset and then increment below for next cycle
299278
}
300-
301-
initialzed=true;
279+
280+
time_since_last_mechanics += diffusion_dt_;
281+
282+
302283
return;
303284
}
304285

‎core/PhysiCell_cell_container.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class Cell_Container : public BioFVM::Agent_Container
8484
std::vector<Cell*> cells_ready_to_divide; // the index of agents ready to divide
8585
std::vector<Cell*> cells_ready_to_die;
8686
int boundary_condition_for_pushed_out_agents; // what to do with pushed out cells
87-
bool initialzed = false;
8887

8988
public:
9089
BioFVM::Cartesian_Mesh underlying_mesh;

0 commit comments

Comments
 (0)