Skip to content

Commit a5d4cd0

Browse files
authored
Merge pull request MathCancer#17 from MathCancer/development
Development
2 parents 261c5b9 + 9f39045 commit a5d4cd0

File tree

58 files changed

+5713
-1565
lines changed

Some content is hidden

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

58 files changed

+5713
-1565
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

BioFVM/BioFVM_basic_agent.cpp

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ Basic_Agent::Basic_Agent()
7474
saturation_densities= new std::vector<double>(0);
7575
// extern Microenvironment* default_microenvironment;
7676
// register_microenvironment( default_microenvironment );
77+
78+
internalized_substrates = new std::vector<double>(0); //
79+
fraction_released_at_death = new std::vector<double>(0);
80+
fraction_transferred_when_ingested = new std::vector<double>(0);
7781
register_microenvironment( get_default_microenvironment() );
82+
83+
// these are done in register_microenvironment
84+
// internalized_substrates.assign( get_default_microenvironment()->number_of_densities() , 0.0 );
85+
7886
return;
7987
}
8088

@@ -88,7 +96,6 @@ bool Basic_Agent::assign_position(std::vector<double> new_position)
8896

8997
bool Basic_Agent::assign_position(double x, double y, double z)
9098
{
91-
// std::cout << __FILE__ << " " << __LINE__ << std::endl;
9299
if( !get_microenvironment()->mesh.is_position_valid(x,y,z))
93100
{
94101
// std::cout<<"Error: the new position for agent "<< ID << " is invalid: "<<x<<","<<y<<","<<"z"<<std::endl;
@@ -122,20 +129,34 @@ void Basic_Agent::set_internal_uptake_constants( double dt )
122129
// p(n+1)*temp2 = p(n) + temp1
123130
// p(n+1) = ( p(n) + temp1 )/temp2
124131
//int nearest_voxel= current_voxel_index;
132+
133+
/*
134+
// new for tracking internal densities
135+
if( use_internal_densities_as_targets == true )
136+
{
137+
*saturation_densities = *internalized_substrates;
138+
*saturation_densities /= ( 1e-15 + volume );
139+
}
140+
*/
141+
125142
double internal_constant_to_discretize_the_delta_approximation = dt * volume / ( (microenvironment->voxels(current_voxel_index)).volume ) ; // needs a fix
126-
143+
127144
// temp1 = dt*(V_cell/V_voxel)*S*T
128145
cell_source_sink_solver_temp1.assign( (*secretion_rates).size() , 0.0 );
129146
cell_source_sink_solver_temp1 += *secretion_rates;
130147
cell_source_sink_solver_temp1 *= *saturation_densities;
131148
cell_source_sink_solver_temp1 *= internal_constant_to_discretize_the_delta_approximation;
149+
150+
// total_extracellular_substrate_change.assign( (*secretion_rates).size() , 1.0 );
132151

133152
// temp2 = 1 + dt*(V_cell/V_voxel)*( S + U )
134153
cell_source_sink_solver_temp2.assign( (*secretion_rates).size() , 1.0 );
135154
axpy( &(cell_source_sink_solver_temp2) , internal_constant_to_discretize_the_delta_approximation , *secretion_rates );
136155
axpy( &(cell_source_sink_solver_temp2) , internal_constant_to_discretize_the_delta_approximation , *uptake_rates );
137156

138157
volume_is_changed = false;
158+
159+
return;
139160
}
140161

141162
void Basic_Agent::register_microenvironment( Microenvironment* microenvironment_in )
@@ -148,6 +169,14 @@ void Basic_Agent::register_microenvironment( Microenvironment* microenvironment_
148169
// some solver temporary variables
149170
cell_source_sink_solver_temp1.resize( microenvironment->density_vector(0).size() , 0.0 );
150171
cell_source_sink_solver_temp2.resize( microenvironment->density_vector(0).size() , 1.0 );
172+
173+
// new for internalized substrate tracking
174+
internalized_substrates->resize( microenvironment->density_vector(0).size() , 0.0 );
175+
total_extracellular_substrate_change.resize( microenvironment->density_vector(0).size() , 1.0 );
176+
177+
fraction_released_at_death->resize( microenvironment->density_vector(0).size() , 0.0 );
178+
fraction_transferred_when_ingested->resize( microenvironment->density_vector(0).size() , 0.0 );
179+
151180
return;
152181
}
153182

@@ -156,7 +185,22 @@ Microenvironment* Basic_Agent::get_microenvironment( void )
156185

157186
Basic_Agent::~Basic_Agent()
158187
{
159-
return;
188+
Microenvironment* pS = get_default_microenvironment();
189+
190+
// change in total in voxel:
191+
// total_ext = total_ext + fraction*total_internal
192+
// total_ext / vol_voxel = total_ext / vol_voxel + fraction*total_internal / vol_voxel
193+
// density_ext += fraction * total_internal / vol_volume
194+
195+
// std::cout << "\t\t\t" << (*pS)(current_voxel_index) << "\t\t\t" << std::endl;
196+
*internalized_substrates /= pS->voxels(current_voxel_index).volume; // turn to density
197+
*internalized_substrates *= *fraction_released_at_death; // what fraction is released?
198+
199+
// release this amount into the environment
200+
201+
(*pS)(current_voxel_index) += *internalized_substrates;
202+
203+
return;
160204
}
161205

162206
Basic_Agent* create_basic_agent( void )
@@ -237,6 +281,7 @@ double Basic_Agent::get_total_volume()
237281
{
238282
return volume;
239283
}
284+
240285
void Basic_Agent::simulate_secretion_and_uptake( Microenvironment* pS, double dt )
241286
{
242287
if(!is_active)
@@ -247,6 +292,20 @@ void Basic_Agent::simulate_secretion_and_uptake( Microenvironment* pS, double dt
247292
set_internal_uptake_constants(dt);
248293
volume_is_changed = false;
249294
}
295+
296+
if( default_microenvironment_options.track_internalized_substrates_in_each_agent == true )
297+
{
298+
total_extracellular_substrate_change.assign( total_extracellular_substrate_change.size() , 1.0 ); // 1
299+
300+
total_extracellular_substrate_change -= cell_source_sink_solver_temp2; // 1-c2
301+
total_extracellular_substrate_change *= (*pS)(current_voxel_index); // (1-c2)*rho
302+
total_extracellular_substrate_change += cell_source_sink_solver_temp1; // (1-c2)*rho+c1
303+
total_extracellular_substrate_change /= cell_source_sink_solver_temp2; // ((1-c2)*rho+c1)/c2
304+
total_extracellular_substrate_change *= pS->voxels(current_voxel_index).volume; // W*((1-c2)*rho+c1)/c2
305+
306+
*internalized_substrates -= total_extracellular_substrate_change; // opposite of net extracellular change
307+
}
308+
250309
(*pS)(current_voxel_index) += cell_source_sink_solver_temp1;
251310
(*pS)(current_voxel_index) /= cell_source_sink_solver_temp2;
252311

BioFVM/BioFVM_basic_agent.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ class Basic_Agent
7474
std::vector<double> previous_velocity;
7575
bool is_active;
7676

77+
std::vector<double> total_extracellular_substrate_change;
78+
7779
public:
7880
std::vector<double> * secretion_rates;
7981
std::vector<double> * saturation_densities;
8082
std::vector<double> * uptake_rates;
8183
double get_total_volume();
8284
void set_total_volume(double);
8385
void update_voxel_index();
84-
86+
87+
/* new for internalized substrates in 1.5.0 */
88+
std::vector<double> * internalized_substrates;
89+
std::vector<double> * fraction_released_at_death;
90+
std::vector<double> * fraction_transferred_when_ingested;
91+
8592
void set_internal_uptake_constants( double dt ); // any time you update the cell volume or rates, should call this function.
8693

8794
void register_microenvironment( Microenvironment* );

BioFVM/BioFVM_microenvironment.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ void Microenvironment::update_dirichlet_node( int voxel_index , std::vector<doub
217217
return;
218218
}
219219

220+
void Microenvironment::update_dirichlet_node( int voxel_index , int substrate_index , double new_value )
221+
{
222+
mesh.voxels[voxel_index].is_Dirichlet = true;
223+
dirichlet_value_vectors[voxel_index][substrate_index] = new_value;
224+
return;
225+
}
226+
220227
void Microenvironment::remove_dirichlet_node( int voxel_index )
221228
{
222229
mesh.voxels[voxel_index].is_Dirichlet = false;
@@ -431,6 +438,8 @@ void Microenvironment::resize_densities( int new_size )
431438
default_microenvironment_options.Dirichlet_condition_vector.assign( new_size , 1.0 );
432439
default_microenvironment_options.Dirichlet_activation_vector.assign( new_size, true );
433440

441+
default_microenvironment_options.initial_condition_vector.assign( new_size , 1.0 );
442+
434443
return;
435444
}
436445

@@ -483,6 +492,8 @@ void Microenvironment::add_density( void )
483492
default_microenvironment_options.Dirichlet_condition_vector.push_back( 1.0 ); // = one;
484493
default_microenvironment_options.Dirichlet_activation_vector.push_back( true ); // assign( number_of_densities(), true );
485494

495+
default_microenvironment_options.initial_condition_vector.push_back( 1.0 );
496+
486497
return;
487498
}
488499

@@ -534,6 +545,8 @@ void Microenvironment::add_density( std::string name , std::string units )
534545
default_microenvironment_options.Dirichlet_condition_vector.push_back( 1.0 ); // = one;
535546
default_microenvironment_options.Dirichlet_activation_vector.push_back( true ); // assign( number_of_densities(), true );
536547

548+
default_microenvironment_options.initial_condition_vector.push_back( 1.0 );
549+
537550
return;
538551
}
539552

@@ -585,6 +598,8 @@ void Microenvironment::add_density( std::string name , std::string units, double
585598
default_microenvironment_options.Dirichlet_condition_vector.push_back( 1.0 ); // = one;
586599
default_microenvironment_options.Dirichlet_activation_vector.push_back( true ); // assign( number_of_densities(), true );
587600

601+
default_microenvironment_options.initial_condition_vector.push_back( 1.0 );
602+
588603
return;
589604
}
590605

@@ -1043,6 +1058,8 @@ Microenvironment_Options::Microenvironment_Options()
10431058
Dirichlet_condition_vector.assign( pMicroenvironment->number_of_densities() , 1.0 );
10441059
Dirichlet_activation_vector.assign( pMicroenvironment->number_of_densities() , true );
10451060

1061+
initial_condition_vector.resize(0); // = Dirichlet_condition_vector;
1062+
10461063
// set a far-field value for oxygen (assumed to be in the first field)
10471064
Dirichlet_condition_vector[0] = 38.0;
10481065

@@ -1059,20 +1076,15 @@ Microenvironment_Options::Microenvironment_Options()
10591076

10601077
calculate_gradients = false;
10611078

1079+
track_internalized_substrates_in_each_agent = false;
1080+
10621081
return;
10631082
}
10641083

10651084
Microenvironment_Options default_microenvironment_options;
10661085

10671086
void initialize_microenvironment( void )
10681087
{
1069-
/*
1070-
if( default_microenvironment_options.use_oxygen_as_first_field == false )
1071-
{
1072-
std::cout << "wha???" << std::endl;
1073-
}
1074-
*/
1075-
10761088
// create and name a microenvironment;
10771089
microenvironment.name = default_microenvironment_options.name;
10781090
// register the diffusion solver
@@ -1109,9 +1121,21 @@ void initialize_microenvironment( void )
11091121
microenvironment.time_units = default_microenvironment_options.time_units;
11101122
microenvironment.mesh.units = default_microenvironment_options.spatial_units;
11111123

1112-
// set the initial densities to the values set in the Dirichlet_condition_vector
1124+
// set the initial densities to the values set in the initial_condition_vector
1125+
1126+
// if the initial condition vector has not been set, use the Dirichlet condition vector
1127+
if( default_microenvironment_options.initial_condition_vector.size() !=
1128+
microenvironment.number_of_densities() )
1129+
{
1130+
std::cout << "BioFVM Warning: Initial conditions not set. " << std::endl
1131+
<< " Using Dirichlet condition vector to set initial substrate values!" << std::endl
1132+
<< " In the future, set default_microenvironment_options.initial_condition_vector."
1133+
<< std::endl << std::endl;
1134+
default_microenvironment_options.initial_condition_vector = default_microenvironment_options.Dirichlet_condition_vector;
1135+
}
1136+
11131137
for( unsigned int n=0; n < microenvironment.number_of_voxels() ; n++ )
1114-
{ microenvironment.density_vector(n) = default_microenvironment_options.Dirichlet_condition_vector; }
1138+
{ microenvironment.density_vector(n) = default_microenvironment_options.initial_condition_vector; }
11151139

11161140
if( default_microenvironment_options.outer_Dirichlet_conditions == true )
11171141
{

BioFVM/BioFVM_microenvironment.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Microenvironment
234234

235235
void add_dirichlet_node( int voxel_index, std::vector<double>& value );
236236
void update_dirichlet_node( int voxel_index , std::vector<double>& new_value );
237+
void update_dirichlet_node( int voxel_index , int substrate_index , double new_value );
237238
void remove_dirichlet_node( int voxel_index );
238239
void apply_dirichlet_conditions( void );
239240

@@ -300,6 +301,8 @@ class Microenvironment_Options
300301
std::vector<double> Dirichlet_condition_vector;
301302
std::vector<bool> Dirichlet_activation_vector;
302303

304+
std::vector<double> initial_condition_vector;
305+
303306
bool simulate_2D;
304307
std::vector<double> X_range;
305308
std::vector<double> Y_range;
@@ -310,6 +313,8 @@ class Microenvironment_Options
310313
bool calculate_gradients;
311314

312315
bool use_oxygen_as_first_field;
316+
317+
bool track_internalized_substrates_in_each_agent;
313318
};
314319

315320
extern Microenvironment_Options default_microenvironment_options;

BioFVM/BioFVM_vector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ void operator/=( std::vector<double>& v1, const double& a )
172172

173173
std::ostream& operator<<(std::ostream& os, const std::vector<double>& v )
174174
{
175+
/*
175176
if( v.size() == 3 )
176177
{
177178
os << "x=\"" << v[0] << "\" y=\"" << v[1] << "\" z=\"" << v[2] << "\"" ;
178179
return os;
179180
}
181+
*/
180182

181183
for( unsigned int i=0; i < v.size(); i++ )
182184
{ os << v[i] << " " ; }

CITATION.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
If you use PhysiCell in your project, please cite PhysiCell and the version
22
number, such as below:
33

4-
We implemented and solved the model using PhysiCell (Version 1.4.1) [1].
4+
We implemented and solved the model using PhysiCell (Version 1.5.0) [1].
55

66
[1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin,
77
PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu-
@@ -11,7 +11,7 @@ We implemented and solved the model using PhysiCell (Version 1.4.1) [1].
1111
Because PhysiCell extensively uses BioFVM, we suggest you also cite BioFVM
1212
as below:
1313

14-
We implemented and solved the model using PhysiCell (Version 1.4.1) [1],
14+
We implemented and solved the model using PhysiCell (Version 1.5.0) [1],
1515
with BioFVM [2] to solve the transport equations.
1616

1717
[1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin,

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ cancer-immune-sample:
118118
cp ./config/PhysiCell_settings.xml ./config/PhysiCell_settings-backup.xml
119119
cp ./sample_projects/cancer_immune/config/* ./config/
120120

121+
virus-macrophage-sample:
122+
cp ./sample_projects/virus_macrophage/custom_modules/* ./custom_modules/
123+
touch main.cpp && cp main.cpp main-backup.cpp
124+
cp ./sample_projects/virus_macrophage/main-virus_macrophage.cpp ./main.cpp
125+
cp Makefile Makefile-backup
126+
cp ./sample_projects/virus_macrophage/Makefile .
127+
cp ./config/PhysiCell_settings.xml ./config/PhysiCell_settings-backup.xml
128+
cp ./sample_projects/virus_macrophage/config/* ./config/
129+
121130
beta-testing:
122131
cp ./sample_projects/beta_testing/custom_modules/* ./custom_modules/
123132
touch main.cpp && cp main.cpp main-backup.cpp

0 commit comments

Comments
 (0)