Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add update_density and update_parameter function #298

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 83 additions & 54 deletions BioFVM/BioFVM_microenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ bool Microenvironment::get_substrate_dirichlet_activation( int substrate_index )
// TODO? fix confusing swapped usage of args
double Microenvironment::get_substrate_dirichlet_value( int substrate_index, int index )
{
return dirichlet_value_vectors[index][substrate_index];
return dirichlet_value_vectors[index][substrate_index];
}

// new functions for finer-grained control of Dirichlet conditions -- 1.7.0
Expand Down Expand Up @@ -487,76 +487,105 @@ void Microenvironment::add_density( std::string name , std::string units )

void Microenvironment::add_density( std::string name , std::string units, double diffusion_constant, double decay_rate )
{
// fix in PhysiCell preview November 2017
if ( find_density_index( name ) != -1 )
// fix in PhysiCell preview November 2017
// default_microenvironment_options.use_oxygen_as_first_field = false;

// check if density exist
if (find_density_index( name ) != -1)
{
std::cout << "ERROR: density named " << name << " already exists. You probably want your substrates all have unique names!" << std::endl;
exit(-1);
std::cout << "Error: density named " << name << " already exists. You probably want your substrates all have unique names!" << std::endl;
exit(-1);
}
// update 1, 0
zero.push_back( 0.0 );

// update 1, 0
zero.push_back( 0.0 );
one.push_back( 1.0 );

// update units
density_names.push_back( name );
density_units.push_back( units );
density_names.push_back( name );
density_units.push_back( units );

// update coefficients
diffusion_coefficients.push_back( diffusion_constant );
decay_rates.push_back( decay_rate );
// update sources and such
// update coefficients
diffusion_coefficients.push_back( diffusion_constant );
decay_rates.push_back( decay_rate );

// update sources and such
for( unsigned int i=0; i < temporary_density_vectors1.size() ; i++ )
{
temporary_density_vectors1[i].push_back( 0.0 );
temporary_density_vectors2[i].push_back( 0.0 );
temporary_density_vectors1[i].push_back( 0.0 );
temporary_density_vectors2[i].push_back( 0.0 );
}

// resize the gradient data structures
// resize the gradient data structures
for( unsigned int k=0 ; k < mesh.voxels.size() ; k++ )
{
gradient_vectors[k].resize( number_of_densities() );
gradient_vectors[k].resize( number_of_densities() );
for( unsigned int i=0 ; i < number_of_densities() ; i++ )
{
(gradient_vectors[k])[i].resize( 3, 0.0 );
}
}
gradient_vector_computed.resize( mesh.voxels.size() , false );
gradient_vector_computed.resize( mesh.voxels.size() , false );

one_half = one;
one_half *= 0.5;

one_third = one;
one_third /= 3.0;

dirichlet_value_vectors.assign( mesh.voxels.size(), one );
dirichlet_activation_vector.push_back( false );
dirichlet_activation_vectors.assign( mesh.voxels.size(), dirichlet_activation_vector );

// fix in PhysiCell preview November 2017
default_microenvironment_options.Dirichlet_condition_vector.push_back( 1.0 ); // = one;
default_microenvironment_options.Dirichlet_activation_vector.push_back( false ); // assign( number_of_densities(), false );

default_microenvironment_options.initial_condition_vector.push_back( 1.0 );

default_microenvironment_options.Dirichlet_all.push_back( true );
// default_microenvironment_options.Dirichlet_interior.push_back( true );
default_microenvironment_options.Dirichlet_xmin.push_back( false );
default_microenvironment_options.Dirichlet_xmax.push_back( false );
default_microenvironment_options.Dirichlet_ymin.push_back( false );
default_microenvironment_options.Dirichlet_ymax.push_back( false );
default_microenvironment_options.Dirichlet_zmin.push_back( false );
default_microenvironment_options.Dirichlet_zmax.push_back( false );

default_microenvironment_options.Dirichlet_xmin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_xmax_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_ymin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_ymax_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_zmin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_zmax_values.push_back( 1.0 );
one_half = one;
one_half *= 0.5;

return;
one_third = one;
one_third /= 3.0;

dirichlet_value_vectors.assign( mesh.voxels.size(), one );
dirichlet_activation_vector.push_back( false );
dirichlet_activation_vectors.assign( mesh.voxels.size(), dirichlet_activation_vector );

// fix in PhysiCell preview November 2017
default_microenvironment_options.Dirichlet_condition_vector.push_back( 1.0 ); // = one;
default_microenvironment_options.Dirichlet_activation_vector.push_back( false ); // assign( number_of_densities(), false );

default_microenvironment_options.initial_condition_vector.push_back( 1.0 );

default_microenvironment_options.Dirichlet_all.push_back( true );
// default_microenvironment_options.Dirichlet_interior.push_back( true );
default_microenvironment_options.Dirichlet_xmin.push_back( false );
default_microenvironment_options.Dirichlet_xmax.push_back( false );
default_microenvironment_options.Dirichlet_ymin.push_back( false );
default_microenvironment_options.Dirichlet_ymax.push_back( false );
default_microenvironment_options.Dirichlet_zmin.push_back( false );
default_microenvironment_options.Dirichlet_zmax.push_back( false );

default_microenvironment_options.Dirichlet_xmin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_xmax_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_ymin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_ymax_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_zmin_values.push_back( 1.0 );
default_microenvironment_options.Dirichlet_zmax_values.push_back( 1.0 );

return;
}

int Microenvironment::assert_density_exists( std::string search_name )
{
int density_index = find_density_index( search_name );
if( density_index != -1 )
{ return density_index; }

std::cout << "Error: density named " << search_name << " does not exist. Cannot update density!" << std::endl;
exit(-1);
}

void Microenvironment::update_density( std::string name , std::string units )
{
int density_index = assert_density_exists( name );
density_units[ density_index ] = units;
return;
}

void Microenvironment::update_density( std::string name , std::string units, double diffusion_constant, double decay_rate )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the above implementation of update_density to simplify this function and the codebase?

Copy link
Contributor Author

@elmbeech elmbeech Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ok?

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still think it is odd to have to implement a slower version because of code maintenance.
before we had to call the find_index function 1 time, now 3 or 4 times.
just to avoid storing the value in a variable?

Copy link
Contributor Author

@elmbeech elmbeech Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the compromise i suggest between maintenance (as closed as it get to the existing add_parameter function) and speed.
i hope this is acceptable.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the same for the densities:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i pushed these changes and hope they are ok and get merged.

Copy link
Contributor Author

@elmbeech elmbeech Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drbergman could you please confirm that the conflict / conversation / change you requested has resolved (as i think so ).
or let me know if otherwise?

i don't think it is appropriate when i click the resolved button.

thank you, Elmar

{
int density_index = assert_density_exists( name );
density_units[ density_index ] = units;
diffusion_coefficients[ density_index ] = diffusion_constant;
decay_rates[ density_index ] = decay_rate;
return;
}

int Microenvironment::find_density_index( std::string name )
Expand Down Expand Up @@ -1427,7 +1456,7 @@ void initialize_microenvironment( void )
}
*/

// April 2023: no longer necessary after flipping our approach and doing an "additive" instead of "subtractive" DCs handling. I.e., we assume DC activation is false by default; make true on-demand.
// April 2023: no longer necessary after flipping our approach and doing an "additive" instead of "subtractive" DCs handling. I.e., we assume DC activation is false by default; make true on-demand.

// // set the Dirichlet condition activation vector to match the microenvironment options
// for( int i=0 ; i < default_microenvironment_options.Dirichlet_activation_vector.size(); i++ )
Expand Down
21 changes: 13 additions & 8 deletions BioFVM/BioFVM_microenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,21 @@ class Microenvironment
void resize_space( double x_start, double x_end, double y_start, double y_end, double z_start, double z_end , double dx_new , double dy_new , double dz_new );
void resize_space_uniform( double x_start, double x_end, double y_start, double y_end, double z_start, double z_end , double dx_new );

void resize_densities( int new_size );
void add_density( void );
void resize_densities( int new_size );

void add_density( void );
void add_density( std::string name , std::string units );
void add_density( std::string name , std::string units, double diffusion_constant, double decay_rate );
void add_density( std::string name , std::string units, double diffusion_constant, double decay_rate );

void set_density( int index , std::string name , std::string units );
void set_density( int index , std::string name , std::string units , double diffusion_constant , double decay_rate );
void update_density( std::string name , std::string units );
void update_density( std::string name , std::string units, double diffusion_constant, double decay_rate );

void set_density( int index , std::string name , std::string units );
void set_density( int index , std::string name , std::string units , double diffusion_constant , double decay_rate );

int find_density_index( std::string name );
int assert_density_exists( std::string search_name );

int find_density_index( std::string name );

int voxel_index( int i, int j, int k );
std::vector<unsigned int> cartesian_indices( int n );

Expand Down Expand Up @@ -254,7 +259,7 @@ class Microenvironment
void set_substrate_dirichlet_activation( int index, std::vector<bool>& new_value );
bool get_substrate_dirichlet_activation( int substrate_index, int index );

double get_substrate_dirichlet_value( int substrate_index, int index );
double get_substrate_dirichlet_value( int substrate_index, int index );

bool& is_dirichlet_node( int voxel_index );

Expand Down
Loading
Loading