In the previous cell-based Chaste tutorials, we used existing cell-cycle and SRN models to define how cells
proliferate and update and subcellular model. In this tutorial, we show how to create a new SRN model class, and how this
can be used in a cell-based simulation.
The next header includes the Boost shared_ptr smart pointer, and defines some useful
macros to save typing when using it.
The next header includes the NEVER_REACHED macro, used in one of the methods below.
The next header defines a base class for ode-based SRN models.
Our new SRN model will inherit from this abstract class.
These headers specify the methods to solve the ODE system.
This header specifies the ODE solvers.
The following headers are needed for checkpointing.
The remaining header files define classes that will be used in the cell-based
simulation test. We have encountered each of these header files in previous cell-based Chaste
tutorials.
As an example, let us consider a SRN model in which we solve a simple ODE
dx/dt = -0.25*y,
dy/dt = x.
This has exact solution x = A cos 0.5t + B sin 0.5t.
where A and B are determined by the initial condions.
To implement this model we define a new SRN model, MySrnModel,
which inherits from AbstractOdeSrnModel and
contains a MyOdeSystem.
Note that usually this code would be separated out into a separate declaration in
a .hpp file and definition in a .cpp file.
We only need to include the next block of code if we wish to be able
to archive (save or load) the ODE system (and therefore the SRN model) object in a cell-based simulation.
The code consists of a serialize() method, in which we archive the ODE system
using the serialization code defined in the base class
AbstractOdeSystem.
As in the ODE tutorials we need to define the ODE system information.
We only need to include the next block of code if we wish to be able
to archive (save or load) the SRN model object in a cell-based simulation.
The code consists of a serialize method, in which we archive the SRN
model using the serialization code defined in the base class
AbstractOdeSrnModel.
These lines copy the ODE system.
The first public method is a constructor, which just calls the base
constructor. Note you can include an optional argument to specify the ODE solver.
The second public method overrides CreateSrnModel(). This is a
builder method to create new copies of the SRN model. We call
the (protected) copy constructor which creates a copy of the cell cycle model.
The third public method overrides Initialise().
The fourth public method runs the ODEs at each timestep and saves some results to CellData.
this line outputs the ODE system variable to CellData.
Finally we define a method to output any parameters in our model, this needs to be included in every SRN model.
We need to include the next block of code if you want to be able to archive (save or load)
the SRN model object in a cell-based simulation. It is also required for writing out
the parameters file describing the settings for a simulation - it provides the unique
identifier for our new SRN model. Thus every SRN model class must provide this,
or you’ll get errors when running simulations.
Since we’re defining the new SRN model and ODEs within the test file, we need to include the
following stanza as well, to make the code work with newer versions of the Boost libraries.
Normally the above export declaration would occur in the SRN model’s .hpp file, and
the following lines would appear in the .cpp file. See Boost Serialization Guide for
more information.
Need to re-include this after SerializationExportWrapperForCpp.hpp. This is to export the
components that would normally be in a seperate cpp file.
This completes the code for MySrnModel. Note that usually this code would
be separated out into a separate declaration in a .hpp file and definition in a .cpp file.
We begin by testing that our new cell-cycle model is implemented correctly.
Test that we can construct a MySrnModel object:
Now we construct and initialise a cell with a MySrnModel.
Now increment time and check the ODE in MySrnModel is solved correctly.
Check that the ODE system is solved correctly.
Lastly, we briefly test that archiving of MySrnModel has
been implemented correctly. Create an OutputFileHandler and use
this to define a filename for the archive.
Create an output archive.
Destroy the current instance of SimulationTime and create another instance.
Set the start time, end time and number of time steps.
Create a cell with associated srn and cell-cycle model.
Move forward two time steps.
Solve the SRN.
Now archive the cell-cycle model through its cell.
Now create an input archive. Begin by again destroying the current
instance of SimulationTime and creating another instance. Set
the start time, end time and number of time steps. note that this is
overwritten when you load the archive.
Create a pointer to a cell.
Create an input archive and restore the cell from the archive.
Test that the state of the ODEs has been restored correctly.
We conclude with a brief test demonstrating how MySrnModel can be used
in a cell-based simulation.
We use the honeycomb vertex mesh generator to create a vertex mesh.
Next, we create some cells. First, define the cells vector.
We must create a shared_ptr to a CellMutationState with which to bestow the cells.
We make use of the macro MAKE_PTR to do this: the first argument is the class and
the second argument is the name of the shared_ptr.
Then we loop over the nodes.
For each node we create a cell with our SRN model and simple stochastic uniformly distributed cell cycle model.
We choose to initialise the concentrations to random levels in each cell.
Now, we define a random birth time, chosen from [-T,0], where
T is the typical cell cycle duration
We then set the birth time and push the cell back into the vector of cells.
Now that we have defined the mesh and cells, we can define the cell population, forces, target area modifier, and simulation
in the same way as the other tutorials.
Finally to run the simulation, we call Solve().
To visualize the results, use Paraview. See the Visualizing With Paraview tutorial for more information.
Load the file /tmp/$USER/testoutput/TestOffLatticeSimulationWithMySrnModel/results_from_time_0/results.pvd,
and color by x.