Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geselowitz ECG + Poisson reconstruction #85

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

AbdAlazezAhmed
Copy link
Collaborator

For #71 and #72

This was linked to issues Feb 11, 2024
Project.toml Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
src/solver/ecg.jl Outdated Show resolved Hide resolved
src/solver/ecg.jl Outdated Show resolved Hide resolved
src/solver/ecg.jl Outdated Show resolved Hide resolved
src/solver/ecg.jl Outdated Show resolved Hide resolved
@AbdAlazezAhmed AbdAlazezAhmed changed the title [Almost there wip] Geselowitz ECG + Poisson reconstruction Geselowitz ECG + Poisson reconstruction Mar 6, 2024
@AbdAlazezAhmed AbdAlazezAhmed marked this pull request as ready for review March 6, 2024 18:41
Copy link
Owner

@termi-official termi-official left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume further progress is blocked until we have subdomains or intergrid transfer operators merged?

Comment on lines +94 to +99

ecg_reconst_cache = Thunderbolt.Potse2006ECGPoissonReconstructionCache(problem, κ, κ)

u = zeros(Thunderbolt.solution_size(problem.A))

κ = ConstantCoefficient(SymmetricTensor{2,3,Float64}((1.0, 0, 0, 1.0, 0, 1.0)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ecg_reconst_cache = Thunderbolt.Potse2006ECGPoissonReconstructionCache(problem, κ, κ)
u = zeros(Thunderbolt.solution_size(problem.A))
κ = ConstantCoefficient(SymmetricTensor{2,3,Float64}((1.0, 0, 0, 1.0, 0, 1.0)))
ecg_reconst_cache = Thunderbolt.Potse2006ECGPoissonReconstructionCache(problem, κ, κ)
u = zeros(Thunderbolt.solution_size(problem.A))
κ = ConstantCoefficient(SymmetricTensor{2,3,Float64}((1.0, 0, 0, 1.0, 0, 1.0)))

Comment on lines +239 to +251
author="Ogiermann, Dennis
and Balzani, Daniel
and Perotti, Luigi E.",
editor="Ennis, Daniel B.
and Perotti, Luigi E.
and Wang, Vicky Y.",
title="The Effect of Modeling Assumptions on the ECG in Monodomain and Bidomain Simulations",
booktitle="Functional Imaging and Modeling of the Heart",
year="2021",
publisher="Springer International Publishing",
address="Cham",
pages="503--514",
isbn="978-3-030-78710-3"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

(0.0, 50.0),
steady_state_initializer,
iocb_
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
)

@@ -54,6 +54,7 @@ struct ConstantCoefficient{T}
val::T
end

Base.:(-)(cc::ConstantCoefficient) = ConstantCoefficient(-cc.val)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I am not sure if we should do this, because this might be error prone for users (and internals).

@@ -137,6 +138,8 @@ end
@inline _eval_sdt_coefficient(M::SVector{MS}, λ::SVector{λS}) where {MS, λS} = error("Incompatible dimensions! dim(M)=$MS dim(λ)=$λS")
@inline _eval_sdt_coefficient(M::SVector{rdim,<:Vec{sdim}}, λ::SVector{rdim}) where {rdim,sdim} = sum(i->λ[i] * M[i] ⊗ M[i], 1:rdim; init=zero(Tensor{2,sdim}))

Base.:(-)(cc::SpectralTensorCoefficient) = SpectralTensorCoefficient(-cc.eigenvalues, cc.eigenvectors)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.


The important simplifications taken are:
1. Surrounding volume is an infinite, homogeneous sphere with isotropic conductivity
2. The extracellular space and surrounding volume share the same isotropic, homogeneous conductivity tensor
"""
struct Plonsey1964ECGGaussCache{BUF, CV, G}
struct Plonsey1964ECGGaussCache{BUF, CV, DH <: DofHandler, κT}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct Plonsey1964ECGGaussCache{BUF, CV, DH <: DofHandler, κT}
struct Plonsey1964ECGGaussCache{BUF, CV, DH <: AbstractDofHandler, κT}

Maybe?

f = zeros(ndofs(dh_Z))
v = zeros(size(Z,1))

integrator = BilinearDiffusionIntegrator(-κ)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can alternatively change the sign of the right hand side.

Comment on lines +127 to +129
function _compute_lead_field(f, ∇Z, Z, op, p, electrodes::AbstractArray{Vec{3, T}}) where T
_add_electrode(f, op.dh, electrodes[1], true)
_add_electrode(f, op.dh, electrodes[2], false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add the electrodes every time?

Also, since we need 2 electrodes at a time why not simply a static array?

function _compute_lead_field(f, ∇Z, Z, op, p, electrodes::AbstractArray{Vec{3, T}}) where T
_add_electrode(f, op.dh, electrodes[1], true)
_add_electrode(f, op.dh, electrodes[2], false)
(temp, _) = Krylov.cg(op.A,f, M=p, ldiv = true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for convergence failure here. Also, you can solve inplcae with Krylov.jl https://jso.dev/Krylov.jl/dev/solvers/spd/#Krylov.cg! .

as proposed in [PotDubRicVinGul:2006:cmb](@cite) and mentioned in [OgiBalPer:2021:ema](@cite). Where κ is the bulk conductivity tensor, and κᵢ is the intracellular conductivity tensor. The cache includes the assembled
stiffness matrix with applied homogeneous Dirichlet boundary condition at the first vertex of the mesh. As the problem is solved for each timestep with only the right hand side changing.

TODO: Implement [BisPla:2011:bes](@cite) to improve the precision.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some specific blocker for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Poisson ECG reconstruction Geselowitz' lead field ECG
2 participants