Skip to content

Commit

Permalink
write update_density and update_parameter in a concise and speedy way.
Browse files Browse the repository at this point in the history
  • Loading branch information
elmbeech committed Oct 3, 2024
1 parent 58cd783 commit df4e374
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
18 changes: 10 additions & 8 deletions BioFVM/BioFVM_microenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,27 +562,29 @@ void Microenvironment::add_density( std::string name , std::string units, double
return;
}

void Microenvironment::assert_exists( std::string search_name )
int Microenvironment::assert_density_exists( std::string search_name )
{
if( find_density_index( search_name ) != -1 )
{ return; }
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 )
{
assert_exists( name );
density_units[ find_density_index( name ) ] = 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 )
{
update_density( name, units );
diffusion_coefficients[ find_density_index( name ) ] = diffusion_constant;
decay_rates[ find_density_index( name ) ] = decay_rate;
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;
}

Expand Down
3 changes: 1 addition & 2 deletions BioFVM/BioFVM_microenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,14 @@ class Microenvironment
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 assert_exists( std::string search_name );

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 voxel_index( int i, int j, int k );
std::vector<unsigned int> cartesian_indices( int n );
Expand Down
28 changes: 16 additions & 12 deletions modules/PhysiCell_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void Parameters<T>::add_parameter( std::string my_name , T my_value )
template <class T>
void Parameters<T>::add_parameter( std::string my_name , T my_value , std::string my_units )
{
assert_not_exists(my_name);
assert_parameter_not_exists(my_name);

Parameter<T>* pNew;
pNew = new Parameter<T> ;
Expand All @@ -505,7 +505,7 @@ void Parameters<T>::add_parameter( std::string my_name , T my_value , std::strin
template <class T>
void Parameters<T>::add_parameter( Parameter<T> param )
{
assert_not_exists(param.name);
assert_parameter_not_exists(param.name);

int n = parameters.size();
parameters.push_back( param);
Expand All @@ -514,7 +514,7 @@ void Parameters<T>::add_parameter( Parameter<T> param )
}

template <class T>
void Parameters<T>::assert_not_exists( std::string search_name )
void Parameters<T>::assert_parameter_not_exists( std::string search_name )
{
if( find_index( search_name ) == -1 )
{ return; }
Expand All @@ -524,10 +524,12 @@ void Parameters<T>::assert_not_exists( std::string search_name )
}

template <class T>
void Parameters<T>::assert_exists( std::string search_name )
int Parameters<T>::assert_parameter_exists( std::string search_name )
{
if( find_index( search_name ) != -1 )
{ return; }

int parameter_index = find_index( search_name );
if( parameter_index != -1 )
{ return parameter_index; }

std::cout << "Error: parameter named " << search_name << " does not exist. Cannot update the parameter!" << std::endl;
exit(-1);
Expand All @@ -536,24 +538,26 @@ void Parameters<T>::assert_exists( std::string search_name )
template <class T>
void Parameters<T>::update_parameter( std::string my_name , T my_value )
{
assert_exists( my_name );
parameters[ find_index( my_name ) ].value = my_value;
int parameter_index = assert_parameter_exists( my_name );
parameters[ parameter_index ].value = my_value;
return;
}

template <class T>
void Parameters<T>::update_parameter( std::string my_name , T my_value , std::string my_units )
{
update_parameter( my_name, my_value );
parameters[ find_index( my_name ) ].units = my_units;
int parameter_index = assert_parameter_exists( my_name );
parameters[ parameter_index ].value = my_value;
parameters[ parameter_index ].units = my_units;
return;
}

template <class T>
void Parameters<T>::update_parameter( Parameter<T> param )
{
update_parameter( param.name, param.value );
parameters[ find_index( param.name ) ].units = param.units;
int parameter_index = assert_parameter_exists( param.name );
parameters[ parameter_index ].value = param.value;
parameters[ parameter_index ].units = param.units;
return;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/PhysiCell_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class Parameters

int size( void ) const;

void assert_not_exists(std::string search_name);
void assert_exists(std::string search_name);
void assert_parameter_not_exists(std::string search_name);
int assert_parameter_exists(std::string search_name);
};

class User_Parameters
Expand Down

0 comments on commit df4e374

Please sign in to comment.