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

Periodic boundaries #361

Merged
merged 18 commits into from
Feb 27, 2024
Merged

Periodic boundaries #361

merged 18 commits into from
Feb 27, 2024

Conversation

ryan-bournes
Copy link
Contributor

This is the pull request for adding periodic boundaries to the diffusion grid. This is simply an extra function on top of Neumann, Dirichlet, open and closed boundaries that the user can choose from. This also includes a unit test to confirm the boundary conditions work.

Periodic boundaries allows a diffusive substance to move from one boundary to another. This feature is the same as the taurus boundaries for agents, except it is for diffusion. An illustration can be seen below:

|                                                               |
| u0    u1    u2    ............     uN-2    uN-1 |
|                                                               |

When calculating diffusion in u0, it will look at the concentration in u1 and uN-1 to determine the change. If the concentration in uN-1 is lower/higher than u0 then concentration will be transferred from/to u0. Likewise when calculating diffusion in uN-1, it will look at uN-2 and u0, and determine the change in the same way. This transfer through the boundary does not modify the total concentration in the system: it only affects how the concentration can move through the simulation space. Many biological systems simulated with BioDynaMo represent small slices of the much larger system. Periodic boundaries promotes the idea of concentration coming from "other parts" of the biological system. There is a subtle but important difference between a diffusive substance colliding with a large concentration of substances vs colliding with a solid wall.

@TobiasDuswald and @nicogno since you two implemented the Neumann and Dirichlet boundaries, I figured you would be the right people to review this update. Feel free to take a look at this request and potentially do any stress testing when you have time.

@ryan-bournes ryan-bournes self-assigned this Feb 16, 2024
@ryan-bournes ryan-bournes added bdm-core Changes in BDM core diffusion Affects continuum / diffusion grid labels Feb 16, 2024
@ryan-bournes
Copy link
Contributor Author

I've updated the clamp function so it uses the standard version and removed the in-built clamp function. This clamp function was only used in the Neumann and Periodic boundary calculations. Seems like everything works fine. Is there any other changes which need to be made?

Copy link
Contributor

@TobiasDuswald TobiasDuswald left a comment

Choose a reason for hiding this comment

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

There are still a few changes missing (look for neumann or dirichlet in the specific files to see where descriptions of modifications are missing):

  • param.h - describe options
  • diffusion.md - documentation

// Clamp to avoid out of bounds access. Clamped values are initialized
// to a wrong value but will be overwritten by the boundary condition
// evaluation. All other values are correct.
real_t left{c1_[std::clamp(l, size_t{0}, num_boxes - 1)]};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? The indices should never be out of bounds. I think this piece of code makes it a bit harder to understand. can we drop all these real_t variables and simply use c1_[l] for instance?

Same comment goes for this piece of code above in Neumann, can we double check if we can get rid of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will be honest I am not sure the point of it as well. I copied the Neumann boundary code as a base for creating the Periodic boundaries and I figured it had a reason to be there so I kept it in. But we can try taking it out and seeing if any of the unit tests fail.

src/core/diffusion/euler_grid.cc Outdated Show resolved Hide resolved
@TobiasDuswald
Copy link
Contributor

⚠️ Merge PR after #362 .

@ryan-bournes
Copy link
Contributor Author

I've added the explantions for the param file and diffusion.md file. Removing the clamp functions seems to break the unit tests on macOS, so i've just reverted the changes and kept the clamp functions in.

Copy link
Contributor

@nicogno nicogno left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@TobiasDuswald
Copy link
Contributor

⚠️ I updated the branch via force pushing because of merge conflicts caused by the squash-merge earlier. Please update your local branch appropriately.

@ryan-bournes see bbe5789 regarding my comment earlier.

Copy link

@TobiasDuswald TobiasDuswald added the ready Ready for merge / review label Feb 26, 2024
@TobiasDuswald
Copy link
Contributor

Alright, from my side this is ready!

Thanks @ryan-bournes ! Green light from your side as well or are you still planning to push some changes?

@ryan-bournes
Copy link
Contributor Author

Thank you @TobiasDuswald and @nicogno ! In terms of the periodic boundaries, this functionality can be pushed to the main branch. I have mostly everything ready for the complex boundary implementation, but I would rather add these to the master branch one at a time, so I will open a new pull request for the complex boundaries. Do you think this is a good idea?

@TobiasDuswald TobiasDuswald merged commit 96ca70f into master Feb 27, 2024
21 of 22 checks passed
@TobiasDuswald TobiasDuswald deleted the periodic_boundaries branch February 27, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bdm-core Changes in BDM core diffusion Affects continuum / diffusion grid ready Ready for merge / review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants