-
Notifications
You must be signed in to change notification settings - Fork 48
Tutorial: How to Create a Simulation
In this tutorial you will learn the basics on how to use BioDynaMo to create biological simulations. We shall guide you through an example (cell proliferation), explaining step-by-step what is being done. We expect you to have installed the prerequisites and have the latest released source code.
Define how you want your cells to grow, and what the criterion is for cell division. Encapsulate this in a struct
, like the following:
struct GrowthModule {
template <typename T>
void Run(T* cell) {
if (cell->GetDiameter() <= 40) {
cell->ChangeVolume(300);
} else {
Divide(*cell);
}
}
bool IsCopied(Event event) const { return true; }
ClassDefNV(GrowthModule, 1);
};
This growth behavior increases each cell's volume by 300. If a cells' diameter reaches 40, the cell divides into two.
Set the properties of the simulation objects in the simulation, and pass them to the ModelInitializer
. In this example we shall create a 3D grid of cells (4x4x4 cells), with a spacing between them of 20. We also set some other properties of each cell, including it's biological behavior, which is the previously defined growth module.
auto construct = [](const std::array<double, 3>& position) {
Cell cell(position);
cell.SetDiameter(30);
cell.SetAdherence(0.4);
cell.SetMass(1.0);
cell.AddBiologyModule(GrowthModule());
return cell;
};
ModelInitializer::Grid3D(4, 20, construct);
What is left to do is start the simulation and optionally enable live visualization with ParaView. You can define the number of simulation steps in the Simulate
function.
Param::use_paraview_ = true; // optional
Scheduler<> scheduler;
scheduler.Simulate(100);
Build the executable according to [need reference here!]. To display the live visualization, you simply open ParaView and select Catalyst --> Connect
. It is recommended that you pause the simulation before running it to avoid the simulation being completed too early (Catalyst --> Pause Simulation
).
Find the complete code for this example in demo/cell_division_module.h