Skip to content

DC initialization from file - #357

Open
drbergman wants to merge 5 commits into
MathCancer:developmentfrom
drbergman:feature-dc-init-file
Open

DC initialization from file#357
drbergman wants to merge 5 commits into
MathCancer:developmentfrom
drbergman:feature-dc-init-file

Conversation

@drbergman

@drbergman drbergman commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator

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

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_file is provided. try it with make dirichlet-from-file-sample

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
@drbergman
drbergman force-pushed the feature-dc-init-file branch from 0cec57e to c7860b4 Compare February 2, 2025 11:31
@drbergman
drbergman requested a review from Copilot April 4, 2025 15:07

Copilot AI left a comment

Copy link
Copy Markdown

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

Comment thread BioFVM/BioFVM_microenvironment.cpp
Comment thread BioFVM/BioFVM_microenvironment.cpp
Comment thread BioFVM/BioFVM_microenvironment.cpp
Comment thread BioFVM/BioFVM_microenvironment.cpp
Comment thread BioFVM/BioFVM_microenvironment.cpp
@drbergman drbergman self-assigned this May 22, 2025
@drbergman
drbergman requested a review from Copilot May 22, 2025 13:07
@drbergman drbergman assigned drbergman and unassigned drbergman May 22, 2025

Copilot AI left a comment

Copy link
Copy Markdown

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

Comment thread BioFVM/BioFVM_vector.cpp
Comment thread BioFVM/BioFVM_microenvironment.cpp Outdated
drbergman and others added 2 commits August 21, 2026 09:15
#70)

Merging development into feature-dc-init-file dropped both trim_cr calls
from load_initial_conditions_from_csv. The two functions are near-identical
copies, so the resolution landed development's additions on the dirichlet
copy and kept the feature branch's untouched version of the substrate copy.
A CRLF substrates.csv with a header therefore fails again with "Substrate
<name> not found in the BioFVM microenvironment", since the final column
name carries the trailing carriage return.

Both csv row processors also indexed their parsed row without consulting
its length, which is out of bounds for a malformed row:

  - a blank or whitespace-only line leaves csv_to_vector's output empty, so
    data[0..2] reads past the end (and the churn loop itself walks past the
    terminator looking for a digit).
  - substrate_indices is sized from the header, so a short row runs
    data[ci + 3] off the end.
  - dirichlet_csv_to_vector writes is_missing[ind] and data[ind] once per
    comma with no bound, so a row with more fields than the header
    established writes past the end of both vectors.

Blank lines are now skipped in both, matching load_cells_csv_v1 and
process_csv_v2_line, and a row whose column count disagrees with the header
is a hard error rather than a silent partial write. Ordering the substrate
guard ahead of the existing warning also stops data.size() - 3 from
underflowing on a short row.

dirichlet_csv_to_vector additionally treats a whitespace-only field as
omitted rather than feeding it to std::stod, and reports a field that is not
a complete number instead of letting std::stod throw uncaught or silently
accepting "1.5abc" as 1.5.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Comment thread BioFVM/BioFVM_microenvironment.cpp Outdated
@drbergman

Copy link
Copy Markdown
Collaborator Author

After merging this and #386, there is some opportunity to reduce the codebase through DRY principles. Not worth stacking them here, so will just wait on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants