@@ -154,10 +154,10 @@ stiffness matrix with applied homogeneous Dirichlet boundary condition at the fi
154154"""
155155struct PoissonECGReconstructionCache{DiffusionOperatorType1, DiffusionOperatorType2, TransferOperatorType, SolutionVectorType, SolverCacheType, PHType, CHType}
156156 torso_op:: DiffusionOperatorType1 # Operator on the torso mesh for ∇κ∇
157- heart_op :: DiffusionOperatorType2 # Operator on the heart mesh for ∇κᵢ∇
157+ source_op :: DiffusionOperatorType2 # Operator on the heart mesh for ∇κᵢ∇
158158 transfer_op:: TransferOperatorType # Transfer from heart to torso mesh
159159 ϕₑ:: SolutionVectorType # Solution vector buffer
160- κ∇φₘ_h :: SolutionVectorType # Source term buffer on heart
160+ φₘ_t :: SolutionVectorType # Solution vector buffer on torso
161161 κ∇φₘ_t:: SolutionVectorType # Source term buffer on torso
162162 inner_solver:: SolverCacheType # Linear solver
163163 ph:: PHType # PointEvalHandler on the torso
@@ -237,16 +237,16 @@ function PoissonECGReconstructionCache(
237237 subdomains_to = get_subdofhandler_indices_on_subdomains (torso_dh, torso_heart_domain)
238238 )
239239
240- heart_op = setup_assembled_operator (
240+ source_op = setup_assembled_operator (
241241 BilinearDiffusionIntegrator (
242242 heart_diffusion_tensor_field,
243243 qrc,
244244 extracellular_potential_symbol,
245245 ),
246246 system_matrix_type,
247- heart_dh ,
247+ torso_dh ,
248248 )
249- update_operator! (heart_op , 0. ) # Trigger assembly
249+ update_operator! (source_op , 0. ) # Trigger assembly
250250
251251 torso_op = setup_assembled_operator (
252252 BilinearDiffusionIntegrator (
@@ -268,7 +268,7 @@ function PoissonECGReconstructionCache(
268268 PoissonECGReconstructionCache (
269269 heart_fun,
270270 torso_fun,
271- heart_op ,
271+ source_op ,
272272 torso_op,
273273 transfer_op,
274274 ph;
280280function PoissonECGReconstructionCache (
281281 heart_fun:: AffineODEFunction ,
282282 torso_fun:: AffineSteadyStateFunction ,
283- heart_op :: AssembledBilinearOperator ,
283+ source_op :: AssembledBilinearOperator ,
284284 torso_op:: AssembledBilinearOperator ,
285285 transfer_op:: AbstractTransferOperator ,
286286 ph:: PointEvalHandler ;
@@ -292,7 +292,7 @@ function PoissonECGReconstructionCache(
292292 grid = get_grid (torso_dh)
293293 length (torso_dh. field_names) == 1 || @warn " Multiple fields detected. Setup might be broken..."
294294
295- κ∇φₘh = create_system_vector (solution_vector_type, heart_fun ) # RHS buffer before transfer
295+ φₘt = create_system_vector (solution_vector_type, torso_fun ) # RHS buffer for source term
296296 κ∇φₘt = create_system_vector (solution_vector_type, torso_fun) # RHS buffer after transfer
297297 κ∇φₘt .= 0.0
298298 ϕₑ = create_system_vector (solution_vector_type, torso_fun) # Solution vector
@@ -302,14 +302,14 @@ function PoissonECGReconstructionCache(
302302 )
303303 lincache = init (linprob, linear_solver)
304304
305- return PoissonECGReconstructionCache (torso_op, heart_op , transfer_op, ϕₑ, κ∇φₘh , κ∇φₘt, lincache, ph, torso_ch)
305+ return PoissonECGReconstructionCache (torso_op, source_op , transfer_op, ϕₑ, φₘt , κ∇φₘt, lincache, ph, torso_ch)
306306end
307307
308308function update_ecg! (cache:: PoissonECGReconstructionCache , φₘ:: AbstractVector )
309- # Compute κᵢ∇ φₘ on the heart
310- mul ! (cache. κ∇φₘ_h , cache. heart_op , φₘ)
311- # Transfer κᵢ∇φₘ to the torso
312- transfer ! (cache. κ∇φₘ_t, cache. transfer_op , cache. κ∇φₘ_h )
309+ # Transfer φₘ to the torso
310+ transfer ! (cache. φₘ_t , cache. transfer_op , φₘ)
311+ # Compute κᵢ∇φₘ on the torso
312+ mul ! (cache. κ∇φₘ_t, cache. source_op , cache. φₘ_t )
313313 cache. κ∇φₘ_t[isnan .(cache. κ∇φₘ_t)] .= 0.0 # FIXME
314314 # "Move to right hand side
315315 cache. κ∇φₘ_t .*= - 1.0
@@ -348,9 +348,9 @@ V(t)=\\int \\nabla Z(\\boldsymbol{x}) \\cdot \\boldsymbol{\\kappa}_\\mathrm{i} \
348348```
349349"""
350350struct Geselowitz1989ECGLeadCache{TZ <: AbstractMatrix , DiffusionOperatorType, TransferOperatorType, SolutionVectorType <: AbstractVector , ElectrodesVecType}
351- heart_op :: DiffusionOperatorType # Operator on the heart mesh for ∇κᵢ∇
351+ source_op :: DiffusionOperatorType # Operator on the heart mesh for ∇κᵢ∇
352352 transfer_op:: TransferOperatorType # Transfer from heart to torso mesh
353- κ∇φₘ_h :: SolutionVectorType # Source term buffer on heart
353+ φₘ_t :: SolutionVectorType # Potential field on torso
354354 κ∇φₘ_t:: SolutionVectorType # Source term buffer on torso
355355 Z:: TZ # Lead field
356356 electrode_positions:: ElectrodesVecType
419419function Geselowitz1989ECGLeadCache (
420420 heart_fun:: AffineODEFunction ,
421421 torso_grid:: AbstractGrid ,
422- heart_diffusion_tensor_field, # κᵢ - diffusion tensor description for heart on heart grid
422+ heart_diffusion_tensor_field, # κᵢ - diffusion tensor description for heart on heart grid alone
423423 full_diffusion_tensor_field, # κ - diffusion tensor description for heart and torso on torso grid
424424 electrode_positions:: AbstractVector{Vector{VertexIndex}} ;
425425 ipc = LagrangeCollection {1} (),
@@ -454,15 +454,14 @@ function Geselowitz1989ECGLeadCache(
454454 torso_grid
455455 )
456456
457- heart_grid = get_grid (heart_fun. dh)
458457 sourcefun = semidiscretize (
459458 source_model,
460459 FiniteElementDiscretization (
461460 Dict (tmpsym => ipc),
462461 Dirichlet[],
463- subdomain_names (heart_grid ),
462+ subdomain_names (torso_grid ),
464463 ),
465- heart_grid ,
464+ torso_grid ,
466465 )
467466
468467 ϕₘ_op = setup_assembled_operator (
@@ -472,7 +471,7 @@ function Geselowitz1989ECGLeadCache(
472471 tmpsym,
473472 ),
474473 system_matrix_type,
475- sourcefun . dh,
474+ lead_field_fun . dh,
476475 )
477476 update_operator! (ϕₘ_op, 0. ) # Trigger assembly
478477
@@ -525,14 +524,13 @@ function Geselowitz1989ECGLeadCache(
525524 lead_dh = lead_op. dh
526525 length (lead_dh. field_names) == 1 || @warn " Multiple fields detected. Setup might be broken..."
527526 nelectrodes = length (electrode_positions)
528- ∇Njκ∇φₘ_h = create_system_vector (solution_vector_type, heart_fun ) # Solution vector
529- ∇Njκ∇ φₘ_t = create_system_vector (solution_vector_type, lead_fun) # Solution vector
530- Z = zeros (eltype (∇Njκ∇ φₘ_t), nelectrodes, length (∇Njκ ∇φₘ_t))
527+ φₘ_t = create_system_vector (solution_vector_type, lead_fun ) # Solution vector
528+ ∇φₘ_t = create_system_vector (solution_vector_type, lead_fun) # Solution vector
529+ Z = zeros (eltype (∇φₘ_t), nelectrodes, length (∇φₘ_t))
531530 ϕₑ = zeros (nelectrodes)
532531
533- lead_rhs = zeros (eltype (∇Njκ∇ φₘ_t), nelectrodes, length (∇Njκ ∇φₘ_t))
532+ lead_rhs = zeros (eltype (∇φₘ_t), nelectrodes, length (∇φₘ_t))
534533
535- @info size (lead_op. A), size (lead_rhs[1 ,:])
536534 leadprob = LinearSolve. LinearProblem (
537535 lead_op. A, copy (lead_rhs[1 ,:])
538536 )
@@ -544,17 +542,12 @@ function Geselowitz1989ECGLeadCache(
544542 for j in 2 : length (electrode_set)
545543 _add_electrode! (current_rhs, lead_dh, electrode_set[j], - 1.0 / (length (electrode_set)- 1 ), lead_field_sym)
546544 end
547- # leadprob = LinearSolve.LinearProblem(
548- # lead_op.A, copy(current_rhs);# u0=Z[i,:]
549- # )
550- # lincache = init(leadprob, linear_solver)
551- # LinearSolve.solve!(lincache)
552- LinearSolve. set_b (lincache, copy (current_rhs))
545+ lincache. b .= current_rhs
553546 LinearSolve. solve! (lincache)
554547 Z[i,:] .= lincache. u
555548 end
556549
557- return Geselowitz1989ECGLeadCache (source_op, transfer_op, ∇Njκ∇φₘ_h, ∇Njκ ∇φₘ_t, Z, electrode_positions)
550+ return Geselowitz1989ECGLeadCache (source_op, transfer_op, φₘ_t, ∇φₘ_t, Z, electrode_positions)
558551end
559552
560553function _add_electrode! (f:: AbstractVector{T} , dh:: DofHandler , electrode:: VertexIndex , weight, lead_field_sym:: Symbol ) where {T<: Number }
@@ -565,10 +558,10 @@ function _add_electrode!(f::AbstractVector{T}, dh::DofHandler, electrode::Vertex
565558end
566559
567560function update_ecg! (cache:: Geselowitz1989ECGLeadCache , φₘ:: AbstractVector )
568- # Compute κᵢ∇φₘ on the heart
569- mul! (cache. κ∇φₘ_h, cache. heart_op, φₘ)
570561 # Transfer κᵢ∇φₘ to the torso
571- transfer! (cache. κ∇φₘ_t, cache. transfer_op, cache. κ∇φₘ_h)
562+ transfer! (cache. φₘ_t, cache. transfer_op, φₘ)
563+ # Compute κᵢ∇φₘ on the heart
564+ mul! (cache. κ∇φₘ_t, cache. source_op, cache. φₘ_t)
572565 cache. κ∇φₘ_t[isnan .(cache. κ∇φₘ_t)] .= 0.0 # FIXME
573566 return nothing
574567end
0 commit comments