In this tutorial we show how to create a new cell population boundary condition
class to specify a fixed domain within which cells are constrained to lie, and
how to use this in a cell-based simulation.
As in previous cell-based Chaste tutorials, we begin by including the necessary header files.
The next header defines a base class for cell population boundary conditions,
from which the new class will inherit.
The remaining header files define classes that will be used in the cell-based
simulation test. You will have encountered some these files already in previous
cell-based Chaste tutorials.
Defining the cell population boundary condition class#
As an example, let us consider a boundary condition for a two-dimensional cell-based
simulation, in which all cells are constrained to lie within the domain given in
Cartesian coordinates by $0 \leqslant y \leqslant 5$. To implement this we define a cell population
boundary condition class, MyBoundaryCondition, which inherits from
AbstractCellPopulationBoundaryCondition and overrides the methods
ImposeBoundaryCondition(), VerifyBoundaryCondition() and
OutputCellPopulationBoundaryConditionParameters().
The first public method is a default constructor, which calls the base
constructor. There is a single input argument, a pointer to a cell population.
The second public method overrides ImposeBoundaryCondition().
This method is called during the Solve() method in OffLatticeSimulation
at the end of each timestep, just after the position of each node
in the cell population has been updated according to its equation of motion.
The method iterates over all cells in the population, and moves any cell whose
centre has y coordinate less than 0 or greater than 5 back into the domain.
Implicit in this method is the assumption that, when a node hits the
boundary of the domain, it does so inelastically. This means, for example,
that a node hitting the boundary at $y=0$ has its location moved to $y=0$. A
more physically realistic modelling assumption might be to assume that
momentum is conserved in the collision.
Also implicit in this method is the assumption that we are using a cell-centre
based population. If we were using a vertex-based population then each node
would correspond not to a cell centre but to a vertex.
The third public method overrides VerifyBoundaryCondition().
This method is called during the Solve() method in OffLatticeSimulation
at the end of each timestep, just after ImposeBoundaryCondition(), and checks
that each cell in the population now satisfies MyBoundaryCondition.
Just as we encountered in the tutorial Creating And Using A New Cell Killer, here we must override
a method that outputs any member variables to a specified results file rParamsFile.
In our case, there are no parameters, so we simply call the method on the base class.
Nonetheless, we still need to override the method, since it is pure virtual in the base
class.
As mentioned in previous cell-based Chaste tutorials, we need to include the next block
of code to be able to archive the cell population boundary condition object in a cell-based
simulation, and to obtain a unique identifier for our new boundary condition for writing
results to file.
This completes the code for MyBoundaryCondition. Note that usually this code
would be separated out into a separate declaration in a .hpp file and definition
in a .cpp file.
We now test that our new cell population boundary condition is implemented correctly.
We first create a MeshBasedCellPopulation using the helper
classes HoneycombMeshGenerator and CellsGenerator,
as in previous cell-based Chaste tutorials.
We now use the cell population to construct a cell population boundary condition object.
We start by verifying that some cells do not satisfy the boundary condition:
To test that we have implemented the cell population boundary condition correctly,
we call the overridden method ImposeBoundaryCondition()…
… and check that the cell population does indeed now satisfy the boundary condition:
The last block of code provides an archiving test for the cell population boundary
condition, in a similar way to previous cell-based Chaste tutorials:
Using the boundary condition in a cell-based simulation#
We now provide a test demonstrating how MyBoundaryCondition can be used
in a cell-based simulation.
Once again we create a MeshBasedCellPopulation.
We use the cell population to construct a cell population boundary condition object.
We then pass in the cell population into an OffLatticeSimulation,
and set the output directory, output multiple, and end time.
We create a force law and pass it to the OffLatticeSimulation.
We now pass the cell population boundary condition into the cell-based simulation.