Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
7173530
addded some classes from oldexplicit_stabilized branch. Mainly, the p…
grosilho May 12, 2023
8326cbe
added implicit,explicit,exponential integrator (in electrophysiology …
grosilho May 15, 2023
845ad1f
added exponential imex and mES, added parabolic_system in vec format
grosilho May 22, 2023
d8ea6d1
added new stabilized integrators using multirate, splitting and expon…
grosilho May 31, 2023
9ecc345
before adding exponential_runge_kutta as underlying method, instead o…
grosilho May 31, 2023
efcdfbf
added first order exponential runge kutta as underlying collocation m…
grosilho Jun 2, 2023
9b5c460
generalized exponential runge kutta to higher order. Added exponentia…
grosilho Jun 5, 2023
0da7d5d
fixed a few things
grosilho Sep 28, 2023
acaa70f
optimized a few things
grosilho Nov 10, 2023
3f19732
renamed project ExplicitStabilized to Monodomain
grosilho Nov 10, 2023
d4201a1
removed deprecated problems
grosilho Nov 10, 2023
c3bb09f
fixed some renaming issues
grosilho Nov 10, 2023
b3d253a
did refactoring of code and put in Monodomain_NEW
grosilho Dec 1, 2023
e500cff
removed old code and renamed new code
grosilho Dec 1, 2023
c29ce46
added finite difference discretization
grosilho Jan 3, 2024
7eb10ba
added many things, cant remember
grosilho Feb 13, 2024
5bbfc71
old convergence_controller
grosilho Feb 13, 2024
4686e59
addded some classes from oldexplicit_stabilized branch. Mainly, the p…
grosilho May 12, 2023
3ed021c
added implicit,explicit,exponential integrator (in electrophysiology …
grosilho May 15, 2023
71a2296
added exponential imex and mES, added parabolic_system in vec format
grosilho May 22, 2023
edf3193
added new stabilized integrators using multirate, splitting and expon…
grosilho May 31, 2023
7cd6b35
before adding exponential_runge_kutta as underlying method, instead o…
grosilho May 31, 2023
3c25e4a
added first order exponential runge kutta as underlying collocation m…
grosilho Jun 2, 2023
776822f
generalized exponential runge kutta to higher order. Added exponentia…
grosilho Jun 5, 2023
aed06ac
fixed a few things
grosilho Sep 28, 2023
7ee7278
optimized a few things
grosilho Nov 10, 2023
297b4d0
renamed project ExplicitStabilized to Monodomain
grosilho Nov 10, 2023
b8c3469
removed deprecated problems
grosilho Nov 10, 2023
77496ad
fixed some renaming issues
grosilho Nov 10, 2023
129d608
did refactoring of code and put in Monodomain_NEW
grosilho Dec 1, 2023
12d4aff
removed old code and renamed new code
grosilho Dec 1, 2023
1654ae0
added finite difference discretization
grosilho Jan 3, 2024
574289f
added many things, cant remember
grosilho Feb 13, 2024
a833924
added smooth TTP model for conv test, added DCT for 2D and 3D problems
grosilho Feb 15, 2024
3bcb16b
added plot stuff and run scripts
grosilho Mar 12, 2024
f05f749
fixed controller to original
grosilho Mar 12, 2024
c4673ed
removed explicit stabilized files
grosilho Mar 12, 2024
f532a90
fixed other files
grosilho Mar 12, 2024
57ae9c1
removed obsolete splittings from ionic models
grosilho Mar 12, 2024
a43d5d5
removed old sbatch scripts
grosilho Mar 12, 2024
f0a7ea6
removed mass transfer and sweeper
grosilho Mar 12, 2024
f879a16
fixed something
grosilho Mar 12, 2024
c03974f
removed my base transfer
grosilho Mar 12, 2024
ff00ac4
removed hook class pde
grosilho Mar 12, 2024
f55a3e2
removed FD files
grosilho Mar 12, 2024
6b0b61c
fixed some calls to FD stuff
grosilho Mar 12, 2024
79532b4
removed FEM FEniCSx files
grosilho Mar 12, 2024
ebd2189
renamed FD_Vector to DCT_Vector
grosilho Mar 12, 2024
ef30448
added hook for output and visualization script
grosilho Mar 12, 2024
017c78a
removed plot scripts
grosilho Mar 12, 2024
ae871de
removed run scripts, except convergence
grosilho Mar 12, 2024
abd9d37
removed convergence experiments script
grosilho Mar 12, 2024
2c9daff
fixed TestODE
grosilho Mar 12, 2024
252ba0b
added stability test in run_TestODE
grosilho Mar 12, 2024
8c55168
added stability test in run_TestODE
grosilho Mar 12, 2024
cc7465f
added stability test in run_TestODE
grosilho Mar 12, 2024
fc489ad
removed obsolete stuff in TestODE
grosilho Mar 12, 2024
4c9345e
removed unneeded stuff from run_MonodomainODE
grosilho Mar 12, 2024
08e3053
cleaned a bit run_MonodomainODE
grosilho Mar 12, 2024
08ee957
removed utils/
grosilho Mar 12, 2024
84820ec
added few comments, cleaned a bit
grosilho Mar 13, 2024
bbdfb81
removed schedule from workflow
grosilho Mar 13, 2024
75f9af0
restored tutorial step 7 A which I has modified time ago
grosilho Mar 13, 2024
1524531
run black on monodomain project
grosilho Mar 13, 2024
0607746
fixed a formatting thing
grosilho Mar 13, 2024
82c82e9
reformatted everything with black
grosilho Mar 13, 2024
93effd5
Revert "revert formatted with black"
grosilho Mar 13, 2024
1bfa064
added environment file for monodomain project, started to add stuff i…
grosilho Mar 13, 2024
1f343cd
added first test
grosilho Mar 13, 2024
e5a9f9f
added package tqdm to monodomain environment
grosilho Mar 13, 2024
e1a3367
added new TestODE using DCT_vectors instead of myfloat, moved phi_eva…
grosilho Mar 13, 2024
dab760b
deleted old TestODE and myfloat stuff
grosilho Mar 13, 2024
aa5d155
renamed TestODEnew to TestODE
grosilho Mar 13, 2024
605268e
cleaned a bit
grosilho Mar 13, 2024
ca90673
added stability, convergence and iterations tests. Changed a bit othe…
grosilho Mar 13, 2024
fe7724e
reactivated other tests in workflow
grosilho Mar 13, 2024
d3bf297
removed my tests temporarly
grosilho Mar 13, 2024
3484093
added monodomain marker to project pyproject.toml
grosilho Mar 13, 2024
ffc68ba
changed files and function names for tests
grosilho Mar 13, 2024
5b911be
fixed convergence test
grosilho Mar 13, 2024
d2624de
made one test a bit shorter
grosilho Mar 14, 2024
4705282
added test for SDC on HH and fixed missing feature in SDC imex sweepe…
grosilho Mar 14, 2024
c7e95c6
reformatted with correct black options
grosilho Mar 14, 2024
73ff9d3
fixed a lint error
grosilho Mar 14, 2024
7e96f5d
another lint error
grosilho Mar 14, 2024
7c8433f
adding tests with plot
grosilho Mar 14, 2024
7655d9e
modified convergence test
grosilho Mar 14, 2024
eb77d6f
added test iterations in parallel
grosilho Mar 14, 2024
e4a96c8
removed plot from tests
grosilho Mar 14, 2024
08884e7
added plots without writing to file
grosilho Mar 14, 2024
b4f9e5c
added write to file
grosilho Mar 14, 2024
3490af7
simplified plot
grosilho Mar 14, 2024
977c5a8
new plot
grosilho Mar 14, 2024
63b17a1
fixed plot in iterations parallel
grosilho Mar 14, 2024
29bc76f
added back all tests and plots
grosilho Mar 15, 2024
c5e2b87
cleaned a bit
grosilho Mar 18, 2024
863ff0b
added README
grosilho Mar 18, 2024
fe0e1d8
fixed readme
grosilho Mar 19, 2024
0d0dd23
modified comments in controllers
grosilho Mar 19, 2024
d38007f
try to compute phi every step
grosilho Mar 19, 2024
8ce1eba
removed my controllers, check u changed before comuting phis
grosilho Mar 19, 2024
c515809
enabled postprocessing in pipeline
grosilho Mar 19, 2024
c2c6f99
added comments to data_type classes, removed unnecessary methods
grosilho Mar 19, 2024
98100fb
added comments to hooks
grosilho Mar 20, 2024
5c7b027
added comments to the problem classes
grosilho Mar 20, 2024
2cc84f8
added comments to the run scripts
grosilho Mar 20, 2024
a530e3a
added comments to sweepers and transfer classes
grosilho Mar 20, 2024
86e6e27
fixed the readme
grosilho Mar 20, 2024
6f08ceb
decommented if in pipeline
grosilho Mar 20, 2024
358bd19
removed recv_mprobe option
grosilho Mar 20, 2024
cfbcf71
changed back some stuff outiside of monodomain project
grosilho Mar 20, 2024
f672095
same
grosilho Mar 20, 2024
07a7830
again
grosilho Mar 20, 2024
0367c9c
fixed Thomas hints
grosilho Mar 20, 2024
15b389f
removed old unneeded move coverage folders
grosilho Mar 20, 2024
0efbc90
fixed previously missed Thomas comments
grosilho Mar 20, 2024
acf0e06
begin change datatype
grosilho Mar 21, 2024
ae3620d
changed run_Monodomain
grosilho Mar 21, 2024
4f52f68
added prints
grosilho Mar 21, 2024
2e90dba
fixed prints
grosilho Mar 21, 2024
2ab15d4
mod print
grosilho Mar 21, 2024
14e9a3f
mod print
grosilho Mar 21, 2024
189eed4
mod print
grosilho Mar 21, 2024
6eec84c
mod print
grosilho Mar 21, 2024
d177cfd
rading init val
grosilho Mar 21, 2024
0bf0f31
rading init val
grosilho Mar 21, 2024
0033d24
removed prints
grosilho Mar 21, 2024
495a751
removed prints
grosilho Mar 21, 2024
7a66b86
checking longer time
grosilho Mar 21, 2024
d892284
checking longer time
grosilho Mar 21, 2024
81a0c62
fixed call phi eval
grosilho Mar 21, 2024
a667cd4
trying 2D
grosilho Mar 21, 2024
34923ab
trying 2D
grosilho Mar 21, 2024
5ce87c0
new_data type passing tests
grosilho Mar 21, 2024
b91a10b
removed coverage folders
grosilho Mar 21, 2024
369ba23
merged new_datatype
grosilho Mar 21, 2024
25af922
optmized phi eval lists
grosilho Mar 22, 2024
05cf6d5
before changing phi type
grosilho Mar 22, 2024
6ea1369
changed eval phi lists
grosilho Mar 22, 2024
a9037b5
polished a bit
grosilho Mar 22, 2024
ec0646c
before switch indeces
grosilho Mar 22, 2024
cb8820b
reformatted phi computaiton to its traspose
grosilho Mar 22, 2024
de5ba3f
before changing Q
grosilho Mar 22, 2024
73c622a
optimized integral of exp terms
grosilho Mar 22, 2024
c4bf545
changed interfate to c++ code
grosilho Mar 22, 2024
8a0fd8e
moved definition of dtype u f
grosilho Mar 22, 2024
6749e3d
tests passed after code refactoring
grosilho Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,53 @@ jobs:
path: |
data_libpressio
coverage_libpressio_3.10.dat


user_monodomain_tests_linux:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: "pySDC/projects/Monodomain/etc/environment-monodomain.yml"
create-args: >-
python=3.10

- name: Compile C++ ionic models
env:
IONIC_MODELS_PATH: "pySDC/projects/Monodomain/problem_classes/ionicmodels/cpp"
run: |
c++ -O3 -Wall -shared -std=c++11 -fPIC -fvisibility=hidden $(python3 -m pybind11 --includes) ${IONIC_MODELS_PATH}/bindings_definitions.cpp -o ${IONIC_MODELS_PATH}/ionicmodels$(python3-config --extension-suffix)

- name: Run pytest for CPU stuff
run: |
echo "print('Loading sitecustomize.py...')
import coverage
coverage.process_startup() " > sitecustomize.py
coverage run -m pytest --continue-on-collection-errors -v --durations=0 pySDC/tests -m monodomain

- name: Make coverage report
run: |
mv data data_monodomain
coverage combine
mv .coverage coverage_monodomain_3.10.dat

- name: Uploading artifacts
uses: actions/upload-artifact@v3
with:
name: cpu-test-artifacts
path: |
data_monodomain
coverage_monodomain_3.10.dat


# user_cpu_tests_macos:
# runs-on: macos-12
#
Expand Down Expand Up @@ -206,6 +252,7 @@ jobs:
- lint
- user_cpu_tests_linux
- user_libpressio_tests
- user_monodomain_tests_linux
# - wait_for_gitlab

defaults:
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Projects
projects/DAE.rst
projects/compression.rst
projects/second_order.rst
projects/monodomain.rst


API documentation
Expand Down
1 change: 1 addition & 0 deletions docs/source/projects/monodomain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: /../../pySDC/projects/Monodomain/README.rst
94 changes: 94 additions & 0 deletions pySDC/projects/Monodomain/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Exponential SDC for the Monodomain Equation in Cardiac Electrophysiology
==============================================================================
This project implements the exponential spectral deferred correction (ESDC) method for the monodomain equation in cardiac electrophysiology.
The method proposed here is an adaptation of the `ESDC method proposed by T. Buvoli <https://doi.org/10.1137/19M1256166>`_ to the monodomain equation.
In particular, the implicit-explicit Rush-Larsen method is used as correction scheme. Moreover, not all model components have exponential terms, therefore the resulting method is an hybrid between ESDC and the standard SDC method.

Monodomain equation
-------------------
The monodomain equation models the electrical activity in the heart. It is a reaction-diffusion equation coupled with an ordinary differential equation for the ionic model and is given by

.. math::
\begin{align}
\chi (C_m\frac{\partial V}{\partial t}+I_{ion}(V,z_E,z_e, t)) &= \nabla \cdot (D \nabla V) & \quad \text{in } &\Omega \times (0,T), \\
\frac{\partial z_E}{\partial t} &= g_E(V,z_E,z_e) & \quad \text{in } &\Omega \times (0,T), \\
\frac{\partial z_e}{\partial t} &= \Lambda_e(V)(z_e-z_{e,\infty}(V)) & \quad \text{in } &\Omega \times (0,T), \\
\end{align}

plus the boundary conditions, where :math:`V(t,x)\in\mathbb{R}` is the transmembrane potential and :math:`z_E(t,x)\in\mathbb{R}^n`, :math:`z_e(t,x)\in\mathbb{R}^m` are the ionic model state variables.
The ionic model right-hand side :math:`g_E` is a general nonlinear term, while :math:`\Lambda_e` is a diagonal matrix. The typical range for the number of unknowns :math:`N=1+n+m` is :math:`N\in [4,50]` and depends on the ionic model of choice.

Spatial discretization yields a system of ODEs which can be written in compact form as

.. math::
\mathbf y'=f_I(\mathbf y)+f_E(\mathbf y)+f_e(\mathbf y),

where :math:`\mathbf y(t)\in\mathbb{R}^{M N}` is the vector of unknowns and :math:`M` the number of mesh nodes.
Concerning the right-hand sides, :math:`f_I` is a linear term for the discrete diffusion, :math:`f_E` is a nonlinear but non-stiff term for :math:`I_{ion},g_E`, and :math:`f_e` is a severely stiff term for :math:`\Lambda_e(V)(z_e-z_{e,\infty}(V))`.

The standard (serial) way of integrating the monodomain equation is by using a splitting method, where :math:`f_I` is integrated implicitly, :math:`f_E` explicitly, and :math:`f_e` using the exponential Euler method (which is inexpensive due to the diagonal structure of :math:`\Lambda_e`). We denote this method as IMEXEXP.

The ESDC method for the monodomain equation
-------------------------------------------
A possible way to parallelize the integration of the monodomain equation is by employing the SDC method in combination with the IMEXEXP approach for the correction scheme (preconditioner).
However, this approach is unstable due to the severe stiffness of :math:`f_e`.
Therefore we propose a hybrid method, where we employ SDC for the :math:`f_I,f_E` terms and ESDC for the :math:`f_e` term. For the correcttion scheme we still use the IMEXEXP method.
The resulting method can be seen as a particular case of ESDC and will be denoted by ESDC in the next figures, for simplicity.

Running the code
----------------
Due to their complexity, ionic models are coded in C++ and wrapped to Python. Therefore, before running any example you need to compile the ionic models by running the following command in the root folder:

.. code-block::

export IONIC_MODELS_PATH=pySDC/projects/Monodomain/problem_classes/ionicmodels/cpp
c++ -O3 -Wall -shared -std=c++11 -fPIC -fvisibility=hidden $(python3 -m pybind11 --includes) ${IONIC_MODELS_PATH}/bindings_definitions.cpp -o ${IONIC_MODELS_PATH}/ionicmodels$(python3-config --extension-suffix)

Then an example can be run:

.. code-block::

cd pySDC/projects/Monodomain/run_scripts
mpirun -n 4 python run_MonodomainODE_cli.py --dt 0.05 --end_time 0.2 --num_nodes 6,3 --domain_name cube_1D --refinements 0 --ionic_model_name TTP --truly_time_parallel --n_time_ranks 4

Stability
---------
We display here the stability domain of the ESDC and SDC methods, both with IMEXEXP as correction scheme, applied to the test problem

.. math::
y'=\lambda_I y+\lambda_E y+\lambda_e y,

with :math:`\lambda_I,\lambda_E,\lambda_e` representing :math:`f_I,f_E,f_e`, respectively.
We fix :math:`\lambda_E=-1` and vary the stiff terms :math:`\lambda_I,\lambda_e` only. We see that the ESDC method is stable for all tested values of :math:`\lambda_I,\lambda_e`, while SDC is not.

.. image:: ../../../data/stability_domain_IMEXEXP_EXPRK.png
:scale: 60 %
.. image:: ../../../data/stability_domain_IMEXEXP.png
:scale: 60 %

Convergence
-----------
Here we verify convergence of the ESDC method for the monodomain equation.
We fix the number of collocation nodes to :math:`m=6` and perform a convergence experiment fixing the number of sweeps to either :math:`k=3` or :math:`k=6`.
We use the ten Tusscher-Panfilov ionic model, which is employed in practical applications.
We see that we gain one order of accuracy per sweep, as expected.

.. image:: ../../../data/convergence_ESDC_fixed_iter.png
:scale: 100 %


Iterations
----------
Here we consider three methods:

* ESDC: with :math:`m=6` collocation nodes.
* MLESDC: This is a multilevel version of ESDC with :math:`m=6` collocation nodes on the fine level and :math:`m=3` nodes on the coarse level.
* PFASST: Combination of the PFASST parallelization method with MLESDC, using 24 processors.

We display the number of iterations required by each method to reach a given tolerance and the residual at convergence. As ionic model we use again the ten Tusscher-Panfilov model.
We see that PFASST requires a reasonalbly small number of iterations, comparable to the serial counterparts ESDC and MLESDC.

.. image:: ../../../data/niter_VS_time.png
:scale: 100 %
.. image:: ../../../data/res_VS_time.png
:scale: 100 %
5 changes: 5 additions & 0 deletions pySDC/projects/Monodomain/datatype_classes/my_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pySDC.implementations.datatype_classes.mesh import MultiComponentMesh


class imexexp_mesh(MultiComponentMesh):
components = ['impl', 'expl', 'exp']
24 changes: 24 additions & 0 deletions pySDC/projects/Monodomain/etc/environment-monodomain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: pySDC_monodomain
channels:
- conda-forge
- defaults
dependencies:
- python
- numpy
- scipy>=0.17.1
- matplotlib>=3.0
- sympy>=1.0
- numba>=0.35
- dill>=0.2.6
- pytest
- pytest-benchmark
- pytest-timeout
- pytest-order
- coverage[toml]
- sphinx
- numdifftools
- pybind11
- mpi4py
- mpich
- tqdm
- pymp-pypi
34 changes: 34 additions & 0 deletions pySDC/projects/Monodomain/hooks/HookClass_pde.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pySDC.core.Hooks import hooks


class pde_hook(hooks):
"""
Hook class to write the solution to file.
"""

def __init__(self):
super(pde_hook, self).__init__()

def pre_run(self, step, level_number):
"""
Overwrite default routine called before time-loop starts
It calls the default routine and then writes the initial value to file.
"""
super(pde_hook, self).pre_run(step, level_number)

L = step.levels[level_number]
P = L.prob
if level_number == 0 and L.time == P.t0:
P.write_solution(L.u[0], P.t0)

def post_step(self, step, level_number):
"""
Overwrite default routine called after each step.
It calls the default routine and then writes the solution to file.
"""
super(pde_hook, self).post_step(step, level_number)

if level_number == 0:
L = step.levels[level_number]
P = L.prob
P.write_solution(L.uend, L.time + L.dt)
34 changes: 34 additions & 0 deletions pySDC/projects/Monodomain/hooks/HookClass_post_iter_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import time
from pySDC.core.Hooks import hooks


class post_iter_info_hook(hooks):
"""
Hook class to write additional iteration information to the command line.
It is used to print the final residual, after u[0] has been updated with the new value from the previous step.
This residual is the one used to check the convergence of the iteration and when running in parallel is different from
the one printed at IT_FINE.
"""

def __init__(self):
super(post_iter_info_hook, self).__init__()

def post_iteration(self, step, level_number):
"""
Overwrite default routine called after each iteration.
It calls the default routine and then writes the residual to the command line.
We call this the residual at IT_END.
"""
super().post_iteration(step, level_number)
self.__t1_iteration = time.perf_counter()

L = step.levels[level_number]

self.logger.info(
"Process %2i on time %8.6f at stage %15s: ----------- Iteration: %2i --------------- " "residual: %12.8e",
step.status.slot,
L.time,
"IT_END",
step.status.iter,
L.status.residual,
)
Loading