A bidomain simulation with spatially varying conductivities.#
Tissue conductivity can be altered in simple (cuboid and ellipsoid) regions using
the HeartConfigSetConductivityHeterogeneities methods. This tutorial describes a
much more powerful way which lets us change the conductivity of any element arbitrarily
by exploiting the machinery in AbstractConductivityModifier (which is normally
used in mechanics simulations for stretch-dependence).
In this example we have cooked up a modifier that:
for most elements returns the original conductivity tensor (from HeartConfig)
scaled by some factor, which is different for intracellular or extracellular
conductivities,
but for one particular element returns some constant matrix.
The first thing to do is include the usual headers, plus ones for the conductivity
modifier and an example cell factory (not needed if you’re using a custom one).
Here we define our conductivity modifier. It inherits from the abstract class.
Make sure to use the right element/space dims.
We’ll use a c_matrix called mTensor as “working memory” to hold the returned
modified tensor. This is needed because we return by reference to the problem class,
so we need to make sure the memory isn’t overwritten before it’s done with.
mSpecialMatrix will be some constant one.
The constructor.
In Chaste, all conductivity tensors are diagonal, so if we initialise our “constant
matrix” to zero then we only need to set the diagonal entries in the constructor.
Strange things will happen if the off-diagonal entries aren’t zeroed!
rCalculateModifiedConductivityTensor returns a reference to the “processed” conductivity tensor.
Now the usual test structure.
Generate a mesh.
Here we’re using a trivial cell factory for simplicity, but usually you’ll provide your own one.
Set up the problem with the factory as usual.
We need to apply the modifier directly to the tissue, which comes from the problem, but is only
accessible after Initialise(), so let’s do that now.
Get the original conductivity tensor values. We haven’t set them using
HeartConfig->SetIntra/ExtracellularConductivities so they’ll just be the defaults.
The first argument below is the element ID (we just check the first element we own here). The second accesses
the diagonal elements. We just do (0,0), as (1,1) should be the same (no fibre orientation).
Off-diagonal elements will be 0.
As we don’t have many elements, when we run on more than two processors some processors
will not own any elements. We only try to access the conductivity tensors if the process
owns at least one element.
We then check that we have the correct (default) conductivity values.
Now we can make the modifier and apply it to the tissue using SetConductivityModifier.
To confirm that the conductivities have changed, let’s iterate over all elements owned by this process
and check their conductivity against what we expect.