Chaste  Release::3.4
MonodomainProblem.cpp
1 /*
2 
3 Copyright (c) 2005-2016, 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 "MonodomainProblem.hpp"
37 
38 #include "Exception.hpp"
39 #include "ReplicatableVector.hpp"
40 #include "MonodomainSolver.hpp"
41 #include "OperatorSplittingMonodomainSolver.hpp"
42 
43 
44 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
46 {
48  return mpMonodomainTissue;
49 }
50 
51 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53 {
54  assert(mpMonodomainTissue);
55  /*
56  * NOTE: The this->mpBoundaryConditionsContainer.get() lines below convert a
57  * boost::shared_ptr to a normal pointer, as this is what the solvers are
58  * expecting. We have to be a bit careful though as boost could decide to delete
59  * them whenever it feels like as it won't count the assembers as using them.
60  *
61  * As long as they are kept as member variables here for as long as they are
62  * required in the solvers it should all work OK.
63  */
64 
65  if (HeartConfig::Instance()->GetUseReactionDiffusionOperatorSplitting())
66  {
68  mpMonodomainTissue,
69  this->mpBoundaryConditionsContainer.get());
70  }
71  else
72  {
73  return new MonodomainSolver<ELEMENT_DIM,SPACE_DIM>(this->mpMesh,
74  mpMonodomainTissue,
75  this->mpBoundaryConditionsContainer.get());
76  }
77 }
78 
79 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
81  : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 1>(pCellFactory),
82  mpMonodomainTissue(NULL)
83 {
84 }
85 
86 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
88  : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 1>(),
89  mpMonodomainTissue(NULL)
90 {
91 }
92 
93 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
95 {
96 }
97 
98 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
100 {
101  assert(mpMonodomainTissue != NULL);
102  return mpMonodomainTissue;
103 }
104 
105 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
107 {
108  if (PetscTools::AmMaster())
109  {
110  std::cout << "Solved to time " << time << "\n" << std::flush;
111  }
112 
113  double v_max, v_min;
114 
115  VecMax( this->mSolution, PETSC_NULL, &v_max );
116  VecMin( this->mSolution, PETSC_NULL, &v_min );
117 
118  if (PetscTools::AmMaster())
119  {
120  std::cout << " V = " << "[" <<v_min << ", " << v_max << "]" << "\n" << std::flush;
121  }
122 }
123 
124 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
126 {
129 }
130 
131 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
133 {
134  this->mpWriter->PutUnlimitedVariable(time);
135  this->mpWriter->PutVector(this->mVoltageColumnId, voltageVec);
137 }
138 
139 
141 // Explicit instantiation
143 
144 template class MonodomainProblem<1,1>;
145 template class MonodomainProblem<1,2>;
146 template class MonodomainProblem<1,3>;
147 template class MonodomainProblem<2,2>;
148 template class MonodomainProblem<3,3>;
149 
150 
151 
152 // Serialization for Boost >= 1.36
156 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 1, 3)
157 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 2, 2)
158 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 3, 3)
MonodomainTissue< ELEMENT_DIM, SPACE_DIM > * GetMonodomainTissue()
void WriteInfo(double time)
virtual void WriteOneStep(double time, Vec voltageVec)
static bool AmMaster()
Definition: PetscTools.cpp:120
bool GetUseStateVariableInterpolation() const
virtual void DefineWriterColumns(bool extending)
#define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
virtual void DefineWriterColumns(bool extending)
AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM > * CreateCardiacTissue()
AbstractDynamicLinearPdeSolver< ELEMENT_DIM, SPACE_DIM, 1 > * CreateSolver()
static HeartConfig * Instance()
void DefineExtraVariablesWriterColumns(bool extending)