37 #include "ExtendedBidomainSolver.hpp"
38 #include "ExtendedBidomainMassMatrixAssembler.hpp"
39 #include "ExtendedBidomainAssembler.hpp"
41 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
44 if (this->mpLinearSystem != NULL)
52 Vec& r_template = this->mpLinearSystem->rGetRhsVector();
53 VecDuplicate(r_template, &mVecForConstructingRhs);
56 VecGetOwnershipRange(r_template, &ownership_range_lo, &ownership_range_hi);
57 PetscInt local_size = ownership_range_hi - ownership_range_lo;
59 3*this->mpMesh->CalculateMaximumNodeConnectivityPerProcess(),
60 local_size, local_size);
64 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
69 assert(this->mpLinearSystem->rGetLhsMatrix() != NULL);
70 assert(this->mpLinearSystem->rGetRhsVector() != NULL);
71 assert(currentSolution != NULL);
79 mpExtendedBidomainAssembler->SetMatrixToAssemble(this->mpLinearSystem->rGetLhsMatrix());
80 mpExtendedBidomainAssembler->AssembleMatrix();
84 assert(SPACE_DIM==ELEMENT_DIM);
89 this->mpLinearSystem->SwitchWriteModeLhsMatrix();
102 double Am1 = this->mpExtendedBidomainTissue->GetAmFirstCell();
103 double Am2 = this->mpExtendedBidomainTissue->GetAmSecondCell();
104 double AmGap = this->mpExtendedBidomainTissue->GetAmGap();
105 double Cm1 = this->mpExtendedBidomainTissue->GetCmFirstCell();
106 double Cm2 = this->mpExtendedBidomainTissue->GetCmSecondCell();
121 index!= dist_vec_matrix_based.
End();
124 double V_first_cell = distributed_current_solution_v_first_cell[index];
125 double V_second_Cell = distributed_current_solution_v_second_cell[index];
127 double i_ionic_first_cell = this->mpExtendedBidomainTissue->rGetIionicCacheReplicated()[index.Global];
128 double i_ionic_second_cell = this->mpExtendedBidomainTissue->rGetIionicCacheReplicatedSecondCell()[index.Global];
129 double intracellular_stimulus_first_cell = this->mpExtendedBidomainTissue->rGetIntracellularStimulusCacheReplicated()[index.Global];
130 double intracellular_stimulus_second_cell = this->mpExtendedBidomainTissue->rGetIntracellularStimulusCacheReplicatedSecondCell()[index.Global];
131 double extracellular_stimulus = this->mpExtendedBidomainTissue->rGetExtracellularStimulusCacheReplicated()[index.Global];
132 double g_gap = this->mpExtendedBidomainTissue->rGetGgapCacheReplicated()[index.Global];
134 dist_vec_matrix_based_v_first_cell[index] = Am1*Cm1*V_first_cell/delta_t - Am1*i_ionic_first_cell + AmGap*g_gap*(V_second_Cell - V_first_cell) - intracellular_stimulus_first_cell;
135 dist_vec_matrix_based_v_second_cell[index] = Am2*Cm2*V_second_Cell/delta_t - Am2*i_ionic_second_cell + AmGap*g_gap*(V_first_cell - V_second_Cell) - intracellular_stimulus_second_cell;
137 if (this->mpExtendedBidomainTissue->HasTheUserSuppliedExtracellularStimulus() )
139 assert((fabs(intracellular_stimulus_first_cell) < 1e-12)
140 && (fabs(intracellular_stimulus_second_cell) < 1e-12));
146 dist_vec_matrix_based_phi_e[index] = -extracellular_stimulus;
150 dist_vec_matrix_based_phi_e[index] = 0.0;
155 dist_vec_matrix_based.
Restore();
161 MatMult(mMassMatrix, mVecForConstructingRhs, this->mpLinearSystem->rGetRhsVector());
170 mpExtendedBidomainNeumannSurfaceTermAssembler->ResetBoundaryConditionsContainer(this->mpBoundaryConditions);
171 mpExtendedBidomainNeumannSurfaceTermAssembler->SetVectorToAssemble(this->mpLinearSystem->rGetRhsVector(),
false);
172 mpExtendedBidomainNeumannSurfaceTermAssembler->AssembleVector();
174 this->mpLinearSystem->FinaliseRhsVector();
176 this->mpBoundaryConditions->ApplyDirichletToLinearProblem(*(this->mpLinearSystem), computeMatrix);
180 this->mpLinearSystem->FinaliseLhsMatrix();
182 this->mpLinearSystem->FinaliseRhsVector();
186 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
202 EXCEPTION(
"Bath simulations are not yet supported for extended bidomain problems");
213 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
216 delete mpExtendedBidomainAssembler;
217 delete mpExtendedBidomainNeumannSurfaceTermAssembler;
219 if(mVecForConstructingRhs)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
ExtendedBidomainNeumannSurfaceTermAssembler< ELEM_DIM, SPACE_DIM > * mpExtendedBidomainNeumannSurfaceTermAssembler
ExtendedBidomainSolver(bool bathSimulation, AbstractTetrahedralMesh< ELEM_DIM, SPACE_DIM > *pMesh, ExtendedBidomainTissue< SPACE_DIM > *pTissue, BoundaryConditionsContainer< ELEM_DIM, SPACE_DIM, 3 > *pBoundaryConditions)
ExtendedBidomainAssembler< ELEM_DIM, SPACE_DIM > * mpExtendedBidomainAssembler
DistributedVector CreateDistributedVector(Vec vec, bool readOnly=false)
#define EXCEPTION(message)
static void BeginEvent(unsigned event)
ExtendedBidomainTissue< SPACE_DIM > * mpExtendedBidomainTissue
void SetupLinearSystem(Vec currentSolution, bool computeMatrix)
Vec mVecForConstructingRhs
static double GetPdeTimeStep()
~ExtendedBidomainSolver()
void InitialiseForSolve(Vec initialSolution)
void SetCacheReplication(bool doCacheReplication)
static void EndEvent(unsigned event)
void SetMatrixToAssemble(Mat &rMatToAssemble, bool zeroMatrixBeforeAssembly=true)
void InitialiseForSolve(Vec initialSolution)