Chaste  Release::3.4
AbstractCardiacCellFactory.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 "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  //implemented in subclasses
81 }
82 
83 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
85 {
86  assert(mpMesh != NULL);
87  return mpMesh->GetNumNodes();
88 }
89 
90 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
92  boost::shared_ptr<AbstractIvpOdeSolver> pSolver)
93  : mpMesh(NULL),
94  mpHeartGeometryInformation(NULL),
95  mpZeroStimulus(new ZeroStimulus),
96  mpSolver(pSolver)
97 {
98 }
99 
100 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
102 {
103 }
104 
105 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
107 {
108  mpMesh = pMesh;
109 }
110 
111 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
113 {
114  if (mpMesh == NULL)
115  {
116  EXCEPTION("The mesh object has not been set in the cell factory");
117  }
118  return mpMesh;
119 }
120 
121 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
123 {
124  mpHeartGeometryInformation = pHeartGeometryInformation;
125 }
126 
127 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
129 {
130  if (mpHeartGeometryInformation == NULL)
131  {
132  EXCEPTION("HeartGeometryInformation object has not been set in the cell factory");
133  }
134  return mpHeartGeometryInformation;
135 }
137 // Explicit instantiation
139 
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:378
virtual void SetMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)
void SetHeartGeometryInformation(HeartGeometryInformation< SPACE_DIM > *pHeartGeometryInformation)
static HeartConfig * Instance()