Chaste  Release::2017.1
SimpleBathProblemSetup.hpp
Go to the documentation of this file.
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 #ifndef SIMPLEBATHPROBLEMSETUP_HPP_
36 #define SIMPLEBATHPROBLEMSETUP_HPP_
37 
44 #include "AbstractCardiacCellFactory.hpp"
45 #include "SimpleStimulus.hpp"
46 #include "LuoRudy1991.hpp"
47 #include "HeartRegionCodes.hpp"
48 
53 template<unsigned DIM, class CELLTYPE=CellLuoRudy1991FromCellML>
55 {
56 private:
58  boost::shared_ptr<SimpleStimulus> mpStimulus;
60  c_vector<double,DIM> mStimulatedPoint;
61 
62 public:
69  BathCellFactory(double stimulusMagnitude, c_vector<double,DIM> stimulatedPoint)
71  mpStimulus(new SimpleStimulus(stimulusMagnitude, 0.5)),
72  mStimulatedPoint(stimulatedPoint)
73  {
74  }
75 
81  {
82  // paranoia - check this is really a tissue node
83  assert(HeartRegionCode::IsRegionTissue( pNode->GetRegion() ));
84 
85  // stimulate centre node normally..
86  bool is_centre;
87 
88  if (DIM==1)
89  {
90  is_centre = (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6);
91  }
92  else if (DIM==2)
93  {
94  is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
95  && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) );
96  }
97  else
98  {
99  is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
100  && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6)
101  && (fabs(pNode->GetPoint()[2]-mStimulatedPoint(2)) < 1e-6) );
102  }
103 
104  if (is_centre)
105  {
106  return new CELLTYPE(this->mpSolver, mpStimulus);
107  }
108  else
109  {
110  return new CELLTYPE(this->mpSolver, this->mpZeroStimulus);
111  }
112  }
113 };
114 
123 template<class MeshType>
124 void SetCircularTissueIn2dMesh(MeshType* pMesh,
125  double centreX, double centreY, double radius)
126 {
127  for (typename MeshType::ElementIterator it = pMesh->GetElementIteratorBegin();
128  it != pMesh->GetElementIteratorEnd();
129  ++it)
130  {
131  double x = it->CalculateCentroid()[0];
132  double y = it->CalculateCentroid()[1];
133  if ((x-centreX)*(x-centreX) + (y-centreY)*(y-centreY) > radius*radius)
134  {
135  it->SetAttribute(HeartRegionCode::GetValidBathId());
136  }
137  }
138  pMesh->SetMeshHasChangedSinceLoading();
139 }
140 
150 template<class MeshType>
151 MeshType* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
152  double centreX, double centreY, double radius)
153 {
154  TrianglesMeshReader<2,2> reader(rMeshPath);
155  MeshType* p_mesh = new MeshType;
156  p_mesh->ConstructFromMeshReader(reader);
157 
158  SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
159 
160  return p_mesh;
161 }
162 
172 template<>
174  double centreX, double centreY, double radius)
175 {
176  TrianglesMeshReader<2,2> reader(rMeshPath);
177  // Force dumb partitioning so migration tests pass!
178  DistributedTetrahedralMesh<2,2>* p_mesh = new DistributedTetrahedralMesh<2,2>(DistributedTetrahedralMeshPartitionType::DUMB);
179  p_mesh->ConstructFromMeshReader(reader);
180 
181  SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
182 
183  return p_mesh;
184 }
185 
186 #endif /*SIMPLEBATHPROBLEMSETUP_HPP_*/
AbstractCardiacCellInterface * CreateCardiacCellForTissueNode(Node< DIM > *pNode)
Definition: Node.hpp:58
MeshType * Load2dMeshAndSetCircularTissue(const std::string &rMeshPath, double centreX, double centreY, double radius)
boost::shared_ptr< ZeroStimulus > mpZeroStimulus
void SetCircularTissueIn2dMesh(MeshType *pMesh, double centreX, double centreY, double radius)
BathCellFactory(double stimulusMagnitude, c_vector< double, DIM > stimulatedPoint)
boost::shared_ptr< AbstractIvpOdeSolver > mpSolver
static HeartRegionType GetValidBathId()
virtual void ConstructFromMeshReader(AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > &rMeshReader)
unsigned GetRegion() const
Definition: Node.cpp:437
c_vector< double, DIM > mStimulatedPoint
boost::shared_ptr< SimpleStimulus > mpStimulus
ChastePoint< SPACE_DIM > GetPoint() const
Definition: Node.cpp:133
static bool IsRegionTissue(HeartRegionType regionId)