Skip to content

expose and parse the mechanics grid size in XML#413

Open
rheiland wants to merge 13 commits intoMathCancer:developmentfrom
rheiland:mech_grid_xml
Open

expose and parse the mechanics grid size in XML#413
rheiland wants to merge 13 commits intoMathCancer:developmentfrom
rheiland:mech_grid_xml

Conversation

@rheiland
Copy link
Collaborator

@rheiland rheiland commented Feb 21, 2026

The mechanics voxel size has had a default of 30 and has been hard-coded in main.cpp since PhysiCell came out. This PR makes it possible to easily modify that value in the XML config file. A new tag <mechanics_voxel_size> now exists in the <options> block. And PhysiCell_settings.mechanics_voxel_size now exists and =30.

For all sample projects (and the ode intracellular project):

  • inserted <mechanics_voxel_size>30</mechanics_voxel_size> into the config files
  • modified main.cpp to no longer hard-code 30; rather, read it from PhysiCell_settings.mechanics_voxel_size

Added unit_tests/mech_voxel_size/ which contains a directory structure and files suitable for /user_projects:

  • includes three /config files for different sized mechanics voxel sizes: test_mech_grid_size_{20,25,30}.xml
  • the domain size [-300,300] was chosen to be the least common multiple of those 3 sizes (and the domain grid has the typical dx=dy=dz=20)
  • the main.cpp of this unit test has commented out microenvironment.simulate_diffusion_decay, primarily to see if it would affect the following issue (it didn't).

We may want to discuss some (perhaps) surprising results from just changing the mechanics voxel size, as the above unit test should demonstrate: we end up with a different number of agents. Aside from this, even if the number of agents had been the same, we may end up with different cell scalars, e.g., pressure, if those scalars depend on the neighbor cells which depends on the Moore neighborhood which depends on the mechanics voxel size.

Screenshot 2026-02-21 at 1 10 32 PM

Copy link
Collaborator

@drbergman drbergman left a comment

Choose a reason for hiding this comment

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

Love that this exposes this part of the model! Looks like a straightforward implementation of it, which will make it easy for users to pick up. I like the decision to have the stdout print if it's not in the XML as a way to inform users about this change. I also like that this message will only be read by those who look carefully through the initial model logs, since it is something that can be dangerous (see the comment Randy opened this PR with).

I raised two points here for discussion / to address. First, this PR has mechanics_voxel_size defined both in PhysiCell_constants and in PhysiCell_settings. My vote is for having it within PhysiCell_settings, and that is where the XML parser puts it now.

Second, I think we should completely remove mechanics_voxel_size from the main.cpp files. We should use the new PhysiCell_settings.mechanics_voxel_size within the called create_cell_container_for_microenvironment.

Looking forward to discussing and eventually merging! I heard that changes to Studio are already in dev (not sure branch or not), but happy to help any way I can there.


// set mechanics voxel size, and match the data structure to BioFVM
double mechanics_voxel_size = 30;
double mechanics_voxel_size = PhysiCell_settings.mechanics_voxel_size;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the main.cpp, mechanics_voxel_size is exclusively used to pass in to create_cell_container_for_microenvironment. Should we continue defining this variable scoped only to the main function for this? Or just rely on the PhysiCell constant we are defining?

double phenotype_dt = 6.0;
double intracellular_dt = 0.01;

double mechanics_voxel_size = 30.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As best I can tell, this mechanics_voxel_size is not being used anywhere else. Should we remove it from PhysiCell_constants and have it only exist within PhysiCell_settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had mistakely convinced myself that it need to be in both _constants and _settings, but I was apparently wrong. I removed it from _constants. Also, I agree that it's cleaner to just pass PhysiCell_settings.mechanics_voxel_size in all main.cpp create_cell_container_for_microenvironment and I pushed those changes.

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