Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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(unsigned node) 00081 { 00082 // paranoia - check this is really a tissue node 00083 assert(HeartRegionCode::IsRegionTissue( this->GetMesh()->GetNode(node)->GetRegion() )); 00084 00085 // stimulate centre node normally.. 00086 bool is_centre; 00087 00088 if (DIM==1) 00089 { 00090 is_centre = (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6); 00091 } 00092 else if (DIM==2) 00093 { 00094 is_centre = ( (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6) 00095 && (fabs(this->GetMesh()->GetNode(node)->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) ); 00096 } 00097 else 00098 { 00099 is_centre = ( (fabs(this->GetMesh()->GetNode(node)->GetPoint()[0]-mStimulatedPoint(0)) < 1e-6) 00100 && (fabs(this->GetMesh()->GetNode(node)->GetPoint()[1]-mStimulatedPoint(1)) < 1e-6) 00101 && (fabs(this->GetMesh()->GetNode(node)->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 00149 template<class MeshType> 00150 MeshType* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath, 00151 double centreX, double centreY, double radius) 00152 { 00153 TrianglesMeshReader<2,2> reader(rMeshPath); 00154 MeshType* p_mesh = new MeshType; 00155 p_mesh->ConstructFromMeshReader(reader); 00156 00157 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius); 00158 00159 return p_mesh; 00160 } 00161 00170 template<> 00171 DistributedTetrahedralMesh<2,2>* Load2dMeshAndSetCircularTissue(const std::string& rMeshPath, 00172 double centreX, double centreY, double radius) 00173 { 00174 TrianglesMeshReader<2,2> reader(rMeshPath); 00175 // Force dumb partitioning so migration tests pass! 00176 DistributedTetrahedralMesh<2,2>* p_mesh = new DistributedTetrahedralMesh<2,2>(DistributedTetrahedralMeshPartitionType::DUMB); 00177 p_mesh->ConstructFromMeshReader(reader); 00178 00179 SetCircularTissueIn2dMesh(p_mesh, centreX, centreY, radius); 00180 00181 return p_mesh; 00182 } 00183 00184 #endif /*SIMPLEBATHPROBLEMSETUP_HPP_*/