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
00029
00030
00031
00032
00033
00034
00035 #ifndef SIMPLEBATHPROBLEMSETUP_HPP_
00036 #define SIMPLEBATHPROBLEMSETUP_HPP_
00037
00044 #include "AbstractCardiacCellFactory.hpp"
00045 #include "SimpleStimulus.hpp"
00046 #include "LuoRudy1991.hpp"
00047 #include "HeartRegionCodes.hpp"
00048
00053 template<unsigned DIM, class CELLTYPE=CellLuoRudy1991FromCellML>
00054 class BathCellFactory : public AbstractCardiacCellFactory<DIM>
00055 {
00056 private:
00058 boost::shared_ptr<SimpleStimulus> mpStimulus;
00060 c_vector<double,DIM> mStimulatedPoint;
00061
00062 public:
00069 BathCellFactory(double stimulusMagnitude, c_vector<double,DIM> stimulatedPoint)
00070 : AbstractCardiacCellFactory<DIM>(),
00071 mpStimulus(new SimpleStimulus(stimulusMagnitude, 0.5)),
00072 mStimulatedPoint(stimulatedPoint)
00073 {
00074 }
00075
00080 AbstractCardiacCellInterface* CreateCardiacCellForTissueNode(Node<DIM>* pNode)
00081 {
00082
00083 assert(HeartRegionCode::IsRegionTissue( pNode->GetRegion() ));
00084
00085
00086 bool is_centre;
00087
00088 if (DIM==1)
00089 {
00090 is_centre = (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6);
00091 }
00092 else if (DIM==2)
00093 {
00094 is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
00095 && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) );
00096 }
00097 else
00098 {
00099 is_centre = ( (fabs(pNode->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6)
00100 && (fabs(pNode->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6)
00101 && (fabs(pNode->GetPoint()[2]-mStimulatedPoint(2)) < 1e-6) );
00102 }
00103
00104 if (is_centre)
00105 {
00106 return new CELLTYPE(this->mpSolver, mpStimulus);
00107 }
00108 else
00109 {
00110 return new CELLTYPE(this->mpSolver, this->mpZeroStimulus);
00111 }
00112 }
00113 };
00114
00123 template<class MeshType>
00124 void SetCircularTissueIn2dMesh(MeshType* pMesh,
00125 double centreX, double centreY, double radius)
00126 {
00127 for (typename MeshType::ElementIterator it = pMesh->GetElementIteratorBegin();
00128 it != pMesh->GetElementIteratorEnd();
00129 ++it)
00130 {
00131 double x = it->CalculateCentroid()[0];
00132 double y = it->CalculateCentroid()[1];
00133 if ( (x-centreX)*(x-centreX) + (y-centreY)*(y-centreY) > radius*radius )
00134 {
00135 it->SetAttribute(HeartRegionCode::GetValidBathId());
00136 }
00137 }
00138 pMesh->SetMeshHasChangedSinceLoading();
00139 }
00140
00150 template<class MeshType>
00151 MeshType* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
00152 double centreX, double centreY, double radius)
00153 {
00154 TrianglesMeshReader<2,2> reader(rMeshPath);
00155 MeshType* p_mesh = new MeshType;
00156 p_mesh->ConstructFromMeshReader(reader);
00157
00158 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
00159
00160 return p_mesh;
00161 }
00162
00172 template<>
00173 DistributedTetrahedralMesh<2,2>* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath,
00174 double centreX, double centreY, double radius)
00175 {
00176 TrianglesMeshReader<2,2> reader(rMeshPath);
00177
00178 DistributedTetrahedralMesh<2,2>* p_mesh = new DistributedTetrahedralMesh<2,2>(DistributedTetrahedralMeshPartitionType::DUMB);
00179 p_mesh->ConstructFromMeshReader(reader);
00180
00181 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius);
00182
00183 return p_mesh;
00184 }
00185
00186 #endif