Skip to content

Commit

Permalink
Update Cardiac.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mirams authored Jan 8, 2025
1 parent 2edc0a8 commit 4c360ce
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions day-02/Cardiac.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,56 @@ Second, read the [tutorial on solving bidomain problems](https://chaste.github.i

We'll use [Paraview](https://www.paraview.org/) for visualization (there is also the option to output to the [Meshalyzer](https://git.opencarp.org/openCARP/meshalyzer) or [Cmgui](https://github.com/cmiss/cmgui) formats), but since the cell-based workshop has been using Paraview we'll focus on that.

**Note** you need to run a little script on the Chaste VTK output to add time annotations to avoid the need to duplicate/alter the mesh at each time point. See [Using Paraview for Visualizing Cardiac Simulation Ouptut](https://chaste.github.io/docs/user-guides/visualisation-guides/paraview-for-cardiac/).


## Suggested exercises

* Run the tutorials and visualise the results [using Paraview](https://chaste.github.io/docs/user-guides/visualisation-guides/paraview-for-cardiac/).
* Run the tutorials and visualise the results [using Paraview](https://chaste.github.io/docs/user-guides/visualisation-guides/paraview-for-cardiac/). N.B. you can comment out the lines to output in the other visualizer formats to save a bit of unnecessary file I/O and results download to your local machine.
* Note that tests can be run from the `build` folder via `ctest` or just by running the executable, e.g. `./heart/test/TestRunningBidomainSimulationsTutorial`
* To run executables in parallel (on multiple processors) we use MPI, e.g. `mpirun -np 3 heart/test/TestRunningBidomainSimulationsTutorial` to run on 3 processors (note this might actually be slower than running on one process for very small meshes!)
* This command should work for VTK time annotations if you are in the `build` folder and using the codespace/docker setup: `python python/utils/AddVtuTimeAnnotations.py ~/output/BidomainTutorial/vtk_output/results.vtu ~/output/BidomainTutorial/vtk_output/annotated.vtu`
* Then download to your machine by right clicking the folder in VS Code, and open `annotated.vtu` with Paraview.
> [!IMPORTANT]
> you need to run a little `AddVtuTimeAnnotations.py` script on the Chaste VTK output to add time annotations to avoid the need to duplicate the mesh at each time point as you might do for mechanics simulations.
* Have a look at the auto-converted-at-compile-time CellML file which is in `build/heart/src/odes/cellml/LuoRudy1991.cpp`. Scroll down to the bottom method which sets the 'tagged' parameter names and values. These parameters can be altered using the public methods available on the cell model classes by calling (e.g.) `p_cell->SetParameter("membrane_fast_sodium_current_conductance", 0.0)`. Try altering the 'Cell Factory' at the top to use this method to set the sodium channel conductance to zero in one corner of the mesh (x >= 0.05 and y <= 0.02). Visualize the new spead of the activation wave (because a lot of the charge here moves by diffusion, this region still depolarises, but more slowly!).
* This command should work for VTK time annotations if you are in the `build` folder and using the codespace/docker setup: `python python/utils/AddVtuTimeAnnotations.py ~/output/BidomainTutorial/vtk_output/results.vtu ~/output/BidomainTutorial/vtk_output/annotated.vtu`
* Then download to your machine by right clicking the folder in VS Code, and open `annotated.vtu` with Paraview. See [Using Paraview for Visualizing Cardiac Simulation Ouptut](https://chaste.github.io/docs/user-guides/visualisation-guides/paraview-for-cardiac/).

* **Note:** in the cell factory, you can do something like
```cpp
if ( (x>0.4) && (x<0.6) )
{
LuoRudyIModel1991OdeSystem* p_luo_rudy_system = new LuoRudyIModel1991OdeSystem(mpSolver, mpZeroStimulus);
p_luo_rudy_system->SetParameter("membrane_fast_sodium_current_conductance",0.0);
return p_luo_rudy_system;
}
```
For more flexibility in tagging new parameters and adjusting what gets generated, see the
* Have a look at the auto-converted-at-compile-time CellML file which is in `build/heart/src/odes/cellml/LuoRudy1991.cpp`. Scroll down to the bottom method which sets the 'tagged' parameter names and values, and work out which parameters have been tagged in the CellML file. The 'tagging' means these parameters are treated differently to normal constants in the equations, and are given names so that they can be altered using public methods (e.g.)

```p_cell->SetParameter("membrane_fast_sodium_current_conductance", 0.0);```

* Try altering the 'Cell Factory' at the top to use this method to set the sodium channel conductance to zero in one corner of the mesh (x >= 0.05 and y <= 0.02). Visualize the new spead of the activation wave (because a lot of the charge here moves by diffusion, this region still depolarises, but more slowly!). For more flexibility in tagging new parameters and adjusting what gets generated, see the
[Code Generation From CellML Guide](https://chaste.github.io/docs/user-guides/code-generation-from-cellml/).

* Make a second test method within the tutorial .hpp file and convert it to the analogous monodomain problem - you only need to change 'Bi/bi' to 'Mono/mono'.
(If you were using the results vector within C++, note that it now has the form `V_0 ... V_n`, not `V_0 phi_0_ ... V_n phi_n`).
**Note** if you need to do anything to examine/print the solution in the C++ file, we suggest you just use the `ReplicatableVector` to deal with the solution (replicated across all processes, fine for these small problems), not `DistributedVector` just because the output from the latter can be confusing if you aren't used to dealing with parallel computing).
Compare with the bidomain simulation visually.
> [!TIP]
> in the cell factory, you can do something like
> ```cpp
> if ( (x>0.4) && (x<0.6) )
> {
> LuoRudyIModel1991OdeSystem* p_luo_rudy_system = new LuoRudyIModel1991OdeSystem(mpSolver, mpZeroStimulus);
> p_luo_rudy_system->SetParameter("membrane_fast_sodium_current_conductance",0.0);
> return p_luo_rudy_system;
>}
>```
* Make a second test method within the tutorial .hpp file and convert it to the analogous monodomain problem - you only need to change 'Bi/bi' to 'Mono/mono'. Note, you'll need to `#include MonodomainProblem.hpp` at the top of the file.
(If you were using the results vector within C++, be aware that indexing will be different for voltage as it now has the form `V_0 ... V_n`, not `V_0 phi_0_ ... V_n phi_n`).
> [!NOTE]
> if you need to do anything to examine/print the solution in the C++ file, we suggest you just use the `ReplicatableVector` to deal with the solution (replicated across all processes, fine for these small problems), not `DistributedVector` just because the output from the latter can be confusing if you aren't used to dealing with parallel computing).
* By calling
* Calling
```cpp
monodomain_problem.SetWriteInfo();
```
before
```cpp
monodomain_problem.Solve();
```
this method makes the program print out `[min(V), max(V)], [min(phi_e), max(phi_e)]` at each output time. It can be a simple way to see whether waves are propagating without even having to visualise the output. Determine, approximately, by trial and error/interval bisection, for this test, the threshold below which the stimulus magnitude is too small to create a propagating action potential.
makes the program print out `[min(V), max(V)]` at each output time. It can be a simple way to see whether waves are propagating without even having to visualise the output.
* Using `SetWriteInfo()` Determine, approximately, by trial and error, the threshold below which the stimulus magnitude is too small to create a propagating action potential.

0 comments on commit 4c360ce

Please sign in to comment.