Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
SimpleBathProblemSetup.hpp
Go to the documentation of this file.
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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 "DistributedTetrahedralMesh.hpp"
46#include "DistributedTetrahedralMeshPartitionType.hpp"
47#include "SimpleStimulus.hpp"
48#include "LuoRudy1991.hpp"
49#include "HeartRegionCodes.hpp"
50
55template<unsigned DIM, class CELLTYPE=CellLuoRudy1991FromCellML>
57{
58private:
60 boost::shared_ptr<SimpleStimulus> mpStimulus;
62 c_vector<double,DIM> mStimulatedPoint;
63
64public:
70 BathCellFactory(double stimulusMagnitude, c_vector<double,DIM> stimulatedPoint)
72 mpStimulus(new SimpleStimulus(stimulusMagnitude, 0.5)),
73 mStimulatedPoint(stimulatedPoint)
74 {
75 }
76
82 {
83 // paranoia - check this is really a tissue node
85
86 // stimulate centre node normally..
87 bool is_centre;
88
89 if (DIM==1)
90 {
91 is_centre = (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6);
92 }
93 else if (DIM==2)
94 {
95 is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
96 && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) );
97 }
98 else
99 {
100 is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
101 && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6)
102 && (fabs(pNode->GetPoint()[2]-mStimulatedPoint(2)) < 1e-6) );
103 }
104
105 if (is_centre)
106 {
107 return new CELLTYPE(this->mpSolver, mpStimulus);
108 }
109 else
110 {
111 return new CELLTYPE(this->mpSolver, this->mpZeroStimulus);
112 }
113 }
114};
115
124template<class MeshType>
125void SetCircularTissueIn2dMesh(MeshType* pMesh,
126 double centreX, double centreY, double radius)
127{
128 for (typename MeshType::ElementIterator it = pMesh->GetElementIteratorBegin();
129 it != pMesh->GetElementIteratorEnd();
130 ++it)
131 {
132 double x = it->CalculateCentroid()[0];
133 double y = it->CalculateCentroid()[1];
134 if ((x-centreX)*(x-centreX) + (y-centreY)*(y-centreY) > radius*radius)
135 {
136 it->SetAttribute(HeartRegionCode::GetValidBathId());
137 }
138 }
139 pMesh->SetMeshHasChangedSinceLoading();
140}
141
151template<class MeshType>
152MeshType* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
153 double centreX, double centreY, double radius)
154{
155 TrianglesMeshReader<2,2> reader(rMeshPath);
156 MeshType* p_mesh = new MeshType;
157 p_mesh->ConstructFromMeshReader(reader);
158
159 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
160
161 return p_mesh;
162}
163
173template<>
175 double centreX, double centreY, double radius)
176{
177 TrianglesMeshReader<2,2> reader(rMeshPath);
178 // Force dumb partitioning so migration tests pass!
179 DistributedTetrahedralMesh<2,2>* p_mesh = new DistributedTetrahedralMesh<2,2>(DistributedTetrahedralMeshPartitionType::DUMB);
180 p_mesh->ConstructFromMeshReader(reader);
181
182 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
183
184 return p_mesh;
185}
186
187#endif /*SIMPLEBATHPROBLEMSETUP_HPP_*/
void SetCircularTissueIn2dMesh(MeshType *pMesh, double centreX, double centreY, double radius)
MeshType * Load2dMeshAndSetCircularTissue(const std::string &rMeshPath, double centreX, double centreY, double radius)
boost::shared_ptr< AbstractIvpOdeSolver > mpSolver
boost::shared_ptr< ZeroStimulus > mpZeroStimulus
boost::shared_ptr< SimpleStimulus > mpStimulus
AbstractCardiacCellInterface * CreateCardiacCellForTissueNode(Node< DIM > *pNode)
BathCellFactory(double stimulusMagnitude, c_vector< double, DIM > stimulatedPoint)
c_vector< double, DIM > mStimulatedPoint
virtual void ConstructFromMeshReader(AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > &rMeshReader)
static bool IsRegionTissue(HeartRegionType regionId)
static HeartRegionType GetValidBathId()
Definition Node.hpp:59
ChastePoint< SPACE_DIM > GetPoint() const
Definition Node.cpp:133
unsigned GetRegion() const
Definition Node.cpp:437