-
Notifications
You must be signed in to change notification settings - Fork 112
DC initialization from file #357
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
base: development
Are you sure you want to change the base?
Conversation
provide a CSV file with similar structure to the substrate ICs csv header row: x,y,z,<substrate_01>,<substrate_02>,... where the list of substrates need not be all the substrates, only those with DCs being set each subsequent row is: <x_coord>,<y_coord>,<z_coord>,<val_01>,<val_02>,... where the coords must be specified and the vals can either be empty (<val_01>,,<val_03>,...) or a number If empty, then nothing chagnes for the substrate in that column at that voxel If a number, then the DC activation for that voxel-substrate pairing is set to the number
0cec57e to
c7860b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 9 out of 16 changed files in this pull request and generated no comments.
Files not reviewed (7)
- Makefile: Language not supported
- sample_projects/Makefile-default: Language not supported
- sample_projects/dirichlet_from_file/Makefile: Language not supported
- sample_projects/dirichlet_from_file/config/PhysiCell_settings.xml: Language not supported
- sample_projects/dirichlet_from_file/config/cell_rules.csv: Language not supported
- sample_projects/dirichlet_from_file/config/cells.csv: Language not supported
- sample_projects/dirichlet_from_file/config/dcs.csv: Language not supported
Comments suppressed due to low confidence (1)
BioFVM/BioFVM_microenvironment.cpp:1735
- The function update_dirichlet_node is invoked here but it is not declared or defined in the provided diffs. Consider replacing this call with a defined function such as set_substrate_dirichlet_activation (or implementing update_dirichlet_node) to ensure the dirichlet condition is updated correctly.
microenvironment.update_dirichlet_node(voxel_ind, substrate_indices[ci], data[ci + 3]);
| return; | ||
| } | ||
|
|
||
| void load_initial_conditions_from_matlab(std::string filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unchanged except that the error at the bottom now goes to std::cerr rather than std::cout. It is green here only because the set_microenvironment_initial_condition function is refactored and that moved things around too much for git to track well.
| return; | ||
| } | ||
|
|
||
| void load_initial_conditions_from_csv(std::string filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unchanged except the comment // Do not include a header row. has been removed since you can (and probably should) included a header row. See comment on load_initial_conditions_from_matlab.
Note: you should include a header row to explicitly declare the substrates you are setting, rather than relying on their index in the substrate list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reviewing this PR, I found an error when loading DCs from a CSV without a header row. That mistake was traced back to the code for reading in substrates from a CSV (written by yours truly). So, that has been fixed here.
| return; | ||
| } | ||
|
|
||
| void get_row_from_substrate_initial_condition_csv(std::vector<int> &voxel_set, const std::string line, const std::vector<int> substrate_indices, const bool header_provided) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is entirely unchanged. See comment on load_initial_conditions_from_matlab.
| set_dirichlet_boundaries_from_file(); | ||
| } | ||
|
|
||
| void set_dirichlet_boundaries_from_XML( void ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new function is just the old end to set_microenvironment_initial_condition, refactored into its own function for simplicity and clarity of logic. This is especially useful as its caller (set_dirichlet_initial_condition) handles the loading of DC conditions from both XML and file.
| } | ||
|
|
||
| void load_initial_conditions_from_matlab(std::string filename) | ||
| void set_dirichlet_boundaries_from_file( void ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on load_initial_conditions_from_matlab. This is a new function, not a rework of load_initial_conditions_from_matlab. It just shares enough code that git thinks it is reworking this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces functionality for initializing Dirichlet conditions from a CSV file. Key changes include updates to the main simulation and configuration files, new parsing routines for CSV‐based Dirichlet conditions in the BioFVM module, and corresponding build system modifications.
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sample_projects/dirichlet_from_file/main.cpp | Updates to main simulation code to invoke DC initialization |
| sample_projects/dirichlet_from_file/custom_modules/.h,.cpp | Custom module updates with minimal changes |
| config/*.csv, config/PhysiCell_settings.xml | New configuration files (CSV and XML) supporting DC initialization |
| Makefile, Makefile-default | Build files updated to support the new project configuration |
| modules/PhysiCell_settings.cpp | Added XML parsing logic for Dirichlet condition file settings |
| BioFVM/BioFVM_vector.{h,cpp} | New function (dirichlet_csv_to_vector) to parse CSV rows for DC data |
| BioFVM/BioFVM_microenvironment.{h,cpp} | Updates and new functions for setting and loading Dirichlet conditions |
| while( i < strlen( buffer ) ) | ||
| { | ||
| if(buffer[i] == ',') | ||
| { |
Copilot
AI
May 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside 'dirichlet_csv_to_vector', the index 'ind' is incremented without checking whether it has reached the allocated size of the 'is_missing' and 'data' vectors, which could lead to an out-of-bounds access if the CSV row contains more fields than expected. Consider adding a bounds check before writing to these vectors.
| { | |
| { | |
| if (ind >= is_missing.size()) | |
| { | |
| std::cerr << "Error: Too many fields in the CSV row. Expected at most " << is_missing.size() << " fields." << std::endl; | |
| std::cerr << "\tRow: " << buffer << std::endl; | |
| exit(-1); | |
| } |
| << "\tExpected: " << microenvironment.number_of_voxels() << std::endl | ||
| << "\tFound: " << data.size() - 3 << std::endl |
Copilot
AI
May 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning message incorrectly prints the expected value using 'microenvironment.number_of_voxels()' even though the check compares against (number_of_densities() + 3). This could be confusing; revise the error message to correctly reference the expected number of density data columns.
| << "\tExpected: " << microenvironment.number_of_voxels() << std::endl | |
| << "\tFound: " << data.size() - 3 << std::endl | |
| << "\tExpected: " << (microenvironment.number_of_densities() + 3) << " columns (3 for position + " << microenvironment.number_of_densities() << " for substrates)" << std::endl | |
| << "\tFound: " << data.size() << " columns" << std::endl |
provide a CSV file with similar structure to the substrate ICs csv header row: x,y,z,<substrate_01>,<substrate_02>,... where the list of substrates need not be all the substrates, only those with DCs being set. Each subsequent row is:
where the coords must be specified and the vals can either be empty (<val_01>,,<val_03>,...) or a number
If the XML sets DCs, this will overwrite those values for which a number is supplied in the CSV. In other words, if a voxel on the boundary has a DC set to ON by the XML, parsing the CSV file can only change the value of the DC, not turn it OFF.
a sample project in
sample_projects/dirichlet_from_fileis provided. try it withmake dirichlet-from-file-sample