SimpleBathProblemSetup.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef SIMPLEBATHPROBLEMSETUP_HPP_
00029 #define SIMPLEBATHPROBLEMSETUP_HPP_
00030
00037 #include "AbstractCardiacCellFactory.hpp"
00038 #include "SimpleStimulus.hpp"
00039 #include "LuoRudyIModel1991OdeSystem.hpp"
00040 #include "HeartRegionCodes.hpp"
00041
00046 template<unsigned DIM>
00047 class BathCellFactory : public AbstractCardiacCellFactory<DIM>
00048 {
00049 private:
00051 boost::shared_ptr<SimpleStimulus> mpStimulus;
00053 c_vector<double,DIM> mStimulatedPoint;
00054
00055 public:
00062 BathCellFactory(double stimulusMagnitude, c_vector<double,DIM> stimulatedPoint)
00063 : AbstractCardiacCellFactory<DIM>(),
00064 mpStimulus(new SimpleStimulus(stimulusMagnitude, 0.5)),
00065 mStimulatedPoint(stimulatedPoint)
00066 {
00067 }
00068
00073 AbstractCardiacCell* CreateCardiacCellForTissueNode(unsigned node)
00074 {
00075
00076 assert(this->GetMesh()->GetNode(node)->GetRegion() == HeartRegionCode::TISSUE);
00077
00078
00079 bool is_centre;
00080
00081 if (DIM==1)
00082 {
00083 is_centre = (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6);
00084 }
00085 else if (DIM==2)
00086 {
00087 is_centre = ( (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
00088 && (fabs(this->GetMesh()->GetNode(node)->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) );
00089 }
00090 else
00091 {
00092 is_centre = ( (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
00093 && (fabs(this->GetMesh()->GetNode(node)->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6)
00094 && (fabs(this->GetMesh()->GetNode(node)->GetPoint()[2]-mStimulatedPoint(2)) < 1e-6) );
00095 }
00096
00097 if (is_centre)
00098 {
00099 return new LuoRudyIModel1991OdeSystem(this->mpSolver, mpStimulus);
00100 }
00101 else
00102 {
00103 return new LuoRudyIModel1991OdeSystem(this->mpSolver, this->mpZeroStimulus);
00104 }
00105 }
00106 };
00107
00116 template<class MeshType>
00117 void SetCircularTissueIn2dMesh(MeshType* pMesh,
00118 double centreX, double centreY, double radius)
00119 {
00120 for (typename MeshType::ElementIterator it = pMesh->GetElementIteratorBegin();
00121 it != pMesh->GetElementIteratorEnd();
00122 ++it)
00123 {
00124 double x = it->CalculateCentroid()[0];
00125 double y = it->CalculateCentroid()[1];
00126 if ( (x-centreX)*(x-centreX) + (y-centreY)*(y-centreY) > radius*radius )
00127 {
00128 it->SetRegion(HeartRegionCode::BATH);
00129 }
00130 }
00131 pMesh->SetMeshHasChangedSinceLoading();
00132 }
00133
00142 template<class MeshType>
00143 MeshType* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
00144 double centreX, double centreY, double radius)
00145 {
00146 TrianglesMeshReader<2,2> reader(rMeshPath);
00147 MeshType* p_mesh = new MeshType;
00148 p_mesh->ConstructFromMeshReader(reader);
00149
00150 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
00151
00152 return p_mesh;
00153 }
00154
00163 template<>
00164 DistributedTetrahedralMesh<2,2>* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
00165 double centreX, double centreY, double radius)
00166 {
00167 TrianglesMeshReader<2,2> reader(rMeshPath);
00168
00169 DistributedTetrahedralMesh<2,2>* p_mesh = new DistributedTetrahedralMesh<2,2>(DistributedTetrahedralMesh<2,2>::DUMB);
00170 p_mesh->ConstructFromMeshReader(reader);
00171
00172 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
00173
00174 return p_mesh;
00175 }
00176
00177 #endif