Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
MonodomainPurkinjeProblem.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "MonodomainPurkinjeProblem.hpp"
37#include "MonodomainPurkinjeSolver.hpp"
38#include "Exception.hpp"
39#include "ReplicatableVector.hpp"
40
41
42template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
47
48
49template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
51{
52 assert(!HeartConfig::Instance()->GetUseReactionDiffusionOperatorSplitting());
54 EXCEPT_IF_NOT(p_mesh);
55 MonodomainTissue<ELEMENT_DIM,SPACE_DIM>* p_tissue = dynamic_cast<MonodomainTissue<ELEMENT_DIM,SPACE_DIM>*>(this->GetTissue());
56 assert(p_tissue);
58 p_tissue,
59 this->mpBoundaryConditionsContainer.get());
60}
61
62template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
67
68
69template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
71{
73
74 // Get the Purkinje voltage stripe
75 DistributedVector ic = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(init_cond);
76 DistributedVector::Stripe purkinje_voltage_stripe = DistributedVector::Stripe(ic, 1);
77
78 for (DistributedVector::Iterator index = ic.Begin();
79 index != ic.End();
80 ++index)
81 {
82 purkinje_voltage_stripe[index] = this->GetTissue()->GetPurkinjeCell(index.Global)->GetVoltage();
83 // Note that it doesn't matter if the cell is fake, as this will give a zero voltage for nodes not in the
84 // Purkinje network.
85 }
86 ic.Restore();
87
88 return init_cond;
89}
90
91
92template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
98
99
100// LCOV_EXCL_START
101template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
103 : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 2>(),
104 mPurkinjeVoltageColumnId(UNSIGNED_UNSET)
105{
106}
107// LCOV_EXCL_STOP
108
109template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
113
114
115template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
117{
119 {
120 std::cout << "Solved to time " << time << "\n" << std::flush;
121 }
122
123 double v_max, v_min, v_purk_max, v_purk_min;
124
125 VecStrideMax( this->mSolution, 0, CHASTE_PETSC_NULLPTR, &v_max );
126 VecStrideMin( this->mSolution, 0, CHASTE_PETSC_NULLPTR, &v_min );
127
128 VecStrideMax( this->mSolution, 1, CHASTE_PETSC_NULLPTR, &v_purk_max );
129 VecStrideMin( this->mSolution, 1, CHASTE_PETSC_NULLPTR, &v_purk_min );
130
131 // avoid printing 1e-320 etc
132 if(fabs(v_purk_min)<1e-20)
133 {
134 // It's very hard to hit this, as you'd need the whole Purkinje system to be activated
135 v_purk_min = 0.0; // LCOV_EXCL_LINE
136 }
137
138 if(fabs(v_purk_max)<1e-20)
139 {
140 v_purk_max = 0.0;
141 }
142
144 {
145 std::cout << " V_myo; V_purk = " << "[" <<v_min << ", " << v_max << "]" << ";\t"
146 << "[" << v_purk_min << ", " << v_purk_max << "]" << "\n"
147 << std::flush;
148 }
149}
150
151
152template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
154{
156 if (extending)
157 {
158 mPurkinjeVoltageColumnId = this->mpWriter->GetVariableByName("V_purk");
159 }
160 else
161 {
162 mPurkinjeVoltageColumnId = this->mpWriter->DefineVariable("V_purk","mV");
163 }
165}
166
167
168template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
170{
171 this->mpWriter->PutUnlimitedVariable(time);
172 std::vector<int> variable_ids;
173 variable_ids.push_back(this->mVoltageColumnId);
174 variable_ids.push_back(mPurkinjeVoltageColumnId);
175 this->mpWriter->PutStripedVector(variable_ids, voltageVec);
177}
178
179
181// Explicit instantiation
183
184template class MonodomainPurkinjeProblem<2,2>;
185template class MonodomainPurkinjeProblem<3,3>;
186
187
188
189// Serialization for Boost >= 1.36
#define EXCEPT_IF_NOT(test)
const unsigned UNSIGNED_UNSET
Definition Exception.hpp:53
#define CHASTE_PETSC_NULLPTR
A macro to define PETSc null pointer based on the PETSc version.
#define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
void DefineExtraVariablesWriterColumns(bool extending)
virtual void DefineWriterColumns(bool extending)
static HeartConfig * Instance()
AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, 2 > * CreateSolver()
virtual void WriteOneStep(double time, Vec voltageVec)
AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * CreateCardiacTissue()
virtual void DefineWriterColumns(bool extending)
static bool AmMaster()