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

Throw error if duplicate substrate or parameter #250

Merged
merged 2 commits into from
Aug 16, 2024
Merged
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
136 changes: 7 additions & 129 deletions BioFVM/BioFVM_microenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,146 +475,24 @@ void Microenvironment::add_density( void )
{
// fix in PhysiCell preview November 2017
// default_microenvironment_options.use_oxygen_as_first_field = false;

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

// update units
density_names.push_back( "unnamed" );
density_units.push_back( "none" );

// update coefficients
diffusion_coefficients.push_back( 0.0 );
decay_rates.push_back( 0.0 );

// 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 );
}

// resize the gradient data structures
for( unsigned int k=0 ; k < mesh.voxels.size() ; k++ )
{
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 );

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( true );
dirichlet_activation_vectors.assign( mesh.voxels.size(), dirichlet_activation_vector );

// Fixes 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 );

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;
return add_density( "unnamed" , "none" );
}

void Microenvironment::add_density( std::string name , std::string units )
{
// fix in PhysiCell preview November 2017
// default_microenvironment_options.use_oxygen_as_first_field = false;

// 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 );

// update coefficients
diffusion_coefficients.push_back( 0.0 );
decay_rates.push_back( 0.0 );

// 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 );
}

// resize the gradient data structures,
for( unsigned int k=0 ; k < mesh.voxels.size() ; k++ )
{
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 );

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.Dirichlet_all.push_back( false );
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 );

default_microenvironment_options.initial_condition_vector.push_back( 1.0 );

return;
return add_density( name , units , 0.0 , 0.0 );
}

void Microenvironment::add_density( std::string name , std::string units, double diffusion_constant, double decay_rate )
{
// fix in PhysiCell preview November 2017
// default_microenvironment_options.use_oxygen_as_first_field = false;
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);
}

// update 1, 0
zero.push_back( 0.0 );
Expand Down
120 changes: 36 additions & 84 deletions modules/PhysiCell_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,72 +449,24 @@ Parameters<T>::Parameters()
template <class T>
void Parameters<T>::add_parameter( std::string my_name )
{
Parameter<T>* pNew;
pNew = new Parameter<T> ;
pNew->name = my_name ;

int n = parameters.size();

parameters.push_back( *pNew );

name_to_index_map[ my_name ] = n;
return;
// this function is not currently (2024-06-03) called in the code, so these defaults largely do not matter; very unlikely others are directly calling this function, let alone this implementation
T my_value = T(); // for {int, double, bool, string} this will be {0, 0.0, false, ""} (this would technically change the behavior for strings since it is hardcoded above to default to "none", but nobody should rely on the default value of a string being "none")
return add_parameter( my_name , my_value );
}

template <class T>
void Parameters<T>::add_parameter( std::string my_name , T my_value )
{
Parameter<T>* pNew;
pNew = new Parameter<T> ;
pNew->name = my_name ;
pNew->value = my_value;

int n = parameters.size();

parameters.push_back( *pNew );

name_to_index_map[ my_name ] = n;
return;
}
/*
template <class T>
void Parameters<T>::add_parameter( std::string my_name , T my_value )
{
Parameter<T>* pNew;
pNew = new Parameter<T> ;
pNew->name = my_name ;
pNew->value = my_value;

int n = parameters.size();

parameters.push_back( *pNew );

name_to_index_map[ my_name ] = n;
return;
// this function is not currently (2024-06-03) called in the code, so these defaults largely do not matter; very unlikely others are directly calling this function, let alone this implementation
std::string my_units = "dimensionless"; // technically this would change the behavior for strings since it is hardcoded above to default to "none", but nobody should be using units on strings; also, if the xml does not have units, then "dimensionless" is used even for strings
return add_parameter( my_name , my_value , my_units );
}
*/

template <class T>
void Parameters<T>::add_parameter( std::string my_name , T my_value , std::string my_units )
{
Parameter<T>* pNew;
pNew = new Parameter<T> ;
pNew->name = my_name ;
pNew->value = my_value;
pNew->units = my_units;

int n = parameters.size();

parameters.push_back( *pNew );

name_to_index_map[ my_name ] = n;
return;
}
assert_not_exists(my_name);

/*
template <class T>
void Parameters<T>::add_parameter( std::string my_name , T my_value , std::string my_units )
{
Parameter<T>* pNew;
pNew = new Parameter<T> ;
pNew->name = my_name ;
Expand All @@ -528,17 +480,28 @@ void Parameters<T>::add_parameter( std::string my_name , T my_value , std::strin
name_to_index_map[ my_name ] = n;
return;
}
*/

template <class T>
void Parameters<T>::add_parameter( Parameter<T> param )
{
assert_not_exists(param.name);

int n = parameters.size();
parameters.push_back( param);
name_to_index_map[ param.name ] = n;
return;
}

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

std::cout << "ERROR: Parameter " << search_name << " already exists. Make sure all parameters (of a given type) have unique names." << std::endl;
exit(-1);
}

std::ostream& operator<<( std::ostream& os , const User_Parameters up )
{
os << "Bool parameters:: " << std::endl << up.bools << std::endl;
Expand All @@ -562,44 +525,33 @@ void User_Parameters::read_from_pugixml( pugi::xml_node parent_node )
{ units = "dimensionless"; }

std::string type = node1.attribute( "type" ).value();

bool done = false ;
if( type == "bool" && done == false )

if (type == "bool")
{
bool value = xml_get_my_bool_value( node1 );
bools.add_parameter( name , value, units );
done = true;
bool value = xml_get_my_bool_value(node1);
bools.add_parameter(name, value, units);
}

if( type == "int" && done == false )
else if (type == "int")
{
int value = xml_get_my_int_value( node1 );
ints.add_parameter( name , value, units );
done = true;
int value = xml_get_my_int_value(node1);
ints.add_parameter(name, value, units);
}

if( type == "double" && done == false )
else if (type == "double")
{
double value = xml_get_my_double_value( node1 );
doubles.add_parameter( name , value, units );
done = true;
double value = xml_get_my_double_value(node1);
doubles.add_parameter(name, value, units);
}

if( done == false && type == "string" )
else if (type == "string")
{
std::string value = xml_get_my_string_value( node1 );
strings.add_parameter( name, value , units );
done = true;
std::string value = xml_get_my_string_value(node1);
strings.add_parameter(name, value, units);
}

/* default if no type specified: */
if( done == false )
else // default if no type specified
{
double value = xml_get_my_double_value( node1 );
doubles.add_parameter( name , value, units );
done = true;
double value = xml_get_my_double_value(node1);
doubles.add_parameter(name, value, units);
}

node1 = node1.next_sibling();
i++;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/PhysiCell_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ class Parameters

void add_parameter( std::string my_name );
void add_parameter( std::string my_name , T my_value );
// void add_parameter( std::string my_name , T my_value );
void add_parameter( std::string my_name , T my_value , std::string my_units );
// void add_parameter( std::string my_name , T my_value , std::string my_units );

void add_parameter( Parameter<T> param );

Expand All @@ -202,7 +200,9 @@ class Parameters
Parameter<T>& operator[]( int i );
Parameter<T>& operator[]( std::string str );

int size( void ) const;
int size( void ) const;

void assert_not_exists(std::string search_name);
};

class User_Parameters
Expand Down
Loading