An example showing how to run a bidomain simulation for tissue contained in a perfusing bath#
In this tutorial we show how the changes the need to be made when running a simulation of
cardiac tissue contained in a bath.
The usual headers are included
Cell models can be solved using a specialised (for cardiac cell models) Backward Euler
implementation, with again the code being automatically generated from the cellml files.
Backward Euler allows greater ODE timesteps to be used. For cellml models provided with Chaste,
using Backward Euler is trivial: just change the .hpp included as follows, and the class name as below.
This test will show how to load a mesh in the test and pass it into the problem,
for which the following includes are needed
This header is needed for the sqrt function.
Define the test
First, set the end time and output info. In this simulation
we’ll explicitly read the mesh, alter it, then pass it
to the problem class, so we don’t set the mesh file name.
Bath problems seem to require decreased ODE timesteps.
Use the PlaneStimulusCellFactory to define a set
of Luo-Rudy cells. We pass the stimulus magnitude as 0.0
as we don’t want any stimulated cells.
Now, we load up a rectangular mesh (in triangle/tetgen format), done as follows,
using TrianglesMeshReader. Note that we use a distributed mesh, so the data
is shared among processes if run in parallel.
In most simulations there is one valid tissue identifier and one valid bath identifier
(for elements).
One of these can be assigned to an element with
If we want heterogeneous conductivities outside the heart (for example for torso and blood)
then we will need different identifiers:
In bath problems, each element has an attribute which must be set
to 0 (cardiac tissue) or 1 (bath). This can be done by having an
extra column in the element file (see the file formats documentation,
or for example
mesh/test/data/1D_0_to_1_10_elements_with_two_attributes.ele,
and note that the header in this file has 1 at the end to indicate that
the file defines an attribute for each element). We have read in a mesh
without this type of information set up, so we set it up manually,
by looping over elements and setting those more than 2mm from the centre
as bath elements (by default, the others are cardiac elements).
Since we have modified the mesh by setting element attributes, we need to inform Chaste of this fact.
If we do not, problems will arise when checkpointing,
since the code that saves the simulation state will assume that it can just reuse the original mesh files,
and thus won’t save the new element attributes.
(Some mesh modifications, that use methods on the mesh class directly, will automatically record that
the mesh has been modified. Since we’re just modifying elements, this information isn’t propagated at
present.)
The external conductivity can set two ways:
the default conductivity in the bath is set with SetBathConductivity(double)
heterogeneous overides can be set with SetBathMultipleConductivities(std::map<unsigned, double> )
Now we define the electrodes. First define the magnitude of the electrodes
(ie the magnitude of the boundary extracellular stimulus), and the duration
it lasts for. Currently, electrodes switch on at time 0 and have constant magnitude
until they are switched off. (Note that this test has a small range of
magnitudes that will work, perhaps because the electrodes are close to the tissue).
Electrodes work in two ways: the first electrode applies an input flux, and
the opposite electrode can either be grounded or apply an equal and opposite
flux (ie an output flux). The false here indicates the second electrode
is not grounded, ie has an equal and opposite flux. The “0” indicates
that the electrodes should be applied to the bounding surfaces in the x-direction
(1 would be $y$-direction, 2 the $z$-direction), which are $X=0.0$ and $X=0.1$ in the given mesh.
(This explains why the full mesh ought to be rectangular/cuboid - the nodes on
$x=xmin$ and $x=xmax$ ought to be form two surfaces of equal area.
Now create the problem class, using the cell factory and passing
in true as the second argument to indicate we are solving a bath
problem..
..set the mesh and electrodes..
..and solve as before.
The results can be visualised as before. Note: The voltage is only
defined at cardiac nodes (a node contained in ‘‘any’’ cardiac element), but
for visualisation and computation a ‘fake’ value of ZERO is given for the
voltage at bath nodes.
Finally, we can check that an AP was induced in any of the cardiac
cells. We use a ReplicatableVector as before, and make sure we
only check the voltage at cardiac cells.