Chaste  Release::2018.1
MonodomainPurkinjeProblem.cpp
1 /*
2 
3 Copyright (c) 2005-2018, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF 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 
42 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
44 {
46 }
47 
48 
49 template<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 
62 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
64 {
66 }
67 
68 
69 template<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 
92 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
94  : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 2>(pCellFactory),
95  mPurkinjeVoltageColumnId(UNSIGNED_UNSET)
96 {
97 }
98 
99 
100 // LCOV_EXCL_START
101 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
103  : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 2>(),
104  mPurkinjeVoltageColumnId(UNSIGNED_UNSET)
105 {
106 }
107 // LCOV_EXCL_STOP
108 
109 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
111 {
112 }
113 
114 
115 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
117 {
118  if (PetscTools::AmMaster())
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, PETSC_NULL, &v_max );
126  VecStrideMin( this->mSolution, 0, PETSC_NULL, &v_min );
127 
128  VecStrideMax( this->mSolution, 1, PETSC_NULL, &v_purk_max );
129  VecStrideMin( this->mSolution, 1, PETSC_NULL, &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 
143  if (PetscTools::AmMaster())
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 
152 template<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 
168 template<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 
184 template class MonodomainPurkinjeProblem<2,2>;
185 template class MonodomainPurkinjeProblem<3,3>;
186 
187 
188 
189 // Serialization for Boost >= 1.36
static bool AmMaster()
Definition: PetscTools.cpp:120
DistributedTetrahedralMeshPartitionType::type GetMeshPartitioning() const
AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * CreateCardiacTissue()
virtual void DefineWriterColumns(bool extending)
bool GetUseStateVariableInterpolation() const
#define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
const unsigned UNSIGNED_UNSET
Definition: Exception.hpp:52
AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, 2 > * CreateSolver()
#define EXCEPT_IF_NOT(test)
Definition: Exception.hpp:158
virtual void DefineWriterColumns(bool extending)
virtual void WriteOneStep(double time, Vec voltageVec)
static HeartConfig * Instance()
void DefineExtraVariablesWriterColumns(bool extending)