Chaste  Release::2017.1
AbstractCardiacCellFactory.cpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 "AbstractCardiacCellFactory.hpp"
37 #include "FakeBathCell.hpp"
38 #include "AbstractCvodeCell.hpp"
39 #include "HeartConfig.hpp"
40 
41 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
43  Node<SPACE_DIM>* pNode)
44 {
46  {
47  return new FakeBathCell(this->mpSolver, this->mpZeroStimulus);
48  }
49  else
50  {
51  AbstractCardiacCellInterface* p_cell = CreateCardiacCellForTissueNode(pNode);
52 #ifdef CHASTE_CVODE
53  if (dynamic_cast<AbstractCvodeCell*>(p_cell))
54  {
55 #if CHASTE_SUNDIALS_VERSION >= 20400
56  // Tell the single cell model solver not to re-initialise on subsequent Solve calls.
57  // Unfortunately the oldest CVODE we currently support (2.5.0 in Sundials 2.3.0) doesn't
58  // work very well this this enabled, so we will go without and take a performance hit.
59  static_cast<AbstractCvodeCell*>(p_cell)->SetMinimalReset(true);
60 #endif // SUNDIALS_VERSION
61  // Use the PDE timestep as the [maximum] CVODE timestep.
62  static_cast<AbstractCvodeCell*>(p_cell)->SetTimestep(HeartConfig::Instance()->GetPdeTimeStep());
63  }
64 #endif // CHASTE_CVODE
65  return p_cell;
66  }
67 }
68 
69 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
71  std::vector< AbstractCardiacCellInterface* >* pCellsDistributed,
72  unsigned lo,
73  unsigned hi)
74 {
75 }
76 
77 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
79 {
80  EXCEPTION("To get here you have probably asked for Epi/Mid/Endo CellularHeterogeneities in your HeartConfig "
81  "options or configuration .xml file, to use this you will need to provide a method"
82  " `FillInCellularTransmuralAreas()` in your cell factory to override this one.");
83 }
84 
85 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
87 {
88  assert(mpMesh != NULL);
89  return mpMesh->GetNumNodes();
90 }
91 
92 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
94  boost::shared_ptr<AbstractIvpOdeSolver> pSolver)
95  : mpMesh(NULL),
96  mpHeartGeometryInformation(NULL),
97  mpZeroStimulus(new ZeroStimulus),
98  mpSolver(pSolver)
99 {
100 }
101 
102 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
104 {
105 }
106 
107 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
109 {
110  mpMesh = pMesh;
111 }
112 
113 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
115 {
116  if (mpMesh == NULL)
117  {
118  EXCEPTION("The mesh object has not been set in the cell factory");
119  }
120  return mpMesh;
121 }
122 
123 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
125 {
126  mpHeartGeometryInformation = pHeartGeometryInformation;
127 }
128 
129 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
131 {
132  if (mpHeartGeometryInformation == NULL)
133  {
134  EXCEPTION("HeartGeometryInformation object has not been set in the cell factory");
135  }
137 }
138 
139 // Explicit instantiation
140 template class AbstractCardiacCellFactory<1,1>;
141 template class AbstractCardiacCellFactory<1,2>;
142 template class AbstractCardiacCellFactory<1,3>;
143 template class AbstractCardiacCellFactory<2,2>;
144 template class AbstractCardiacCellFactory<3,3>;
virtual void FinaliseCellCreation(std::vector< AbstractCardiacCellInterface * > *pCellsDistributed, unsigned lo, unsigned hi)
virtual AbstractCardiacCellInterface * CreateCardiacCellForNode(Node< SPACE_DIM > *pNode)
AbstractCardiacCellFactory(boost::shared_ptr< AbstractIvpOdeSolver > pSolver=boost::shared_ptr< AbstractIvpOdeSolver >(new EulerIvpOdeSolver))
static bool IsRegionBath(HeartRegionType regionId)
Definition: Node.hpp:58
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetMesh()
#define EXCEPTION(message)
Definition: Exception.hpp:143
HeartGeometryInformation< SPACE_DIM > * GetHeartGeometryInformation()
double GetPdeTimeStep() const
unsigned GetRegion() const
Definition: Node.cpp:437
HeartGeometryInformation< SPACE_DIM > * mpHeartGeometryInformation
virtual void SetMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
void SetHeartGeometryInformation(HeartGeometryInformation< SPACE_DIM > *pHeartGeometryInformation)
static HeartConfig * Instance()