Chaste Release::3.1
AbstractPurkinjeCellFactory.cpp
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 
00036 
00037 #include "AbstractPurkinjeCellFactory.hpp"
00038 #include "PurkinjeVentricularJunctionStimulus.hpp"
00039 #include "MultiStimulus.hpp"
00040 #include "HeartConfig.hpp"
00041 
00042 
00043 
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 AbstractPurkinjeCellFactory<ELEMENT_DIM,SPACE_DIM>::AbstractPurkinjeCellFactory()
00046     : AbstractCardiacCellFactory<ELEMENT_DIM,SPACE_DIM>(),
00047       mpMixedDimensionMesh(NULL)
00048 {
00049 }
00050 
00051 
00052 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00053 void AbstractPurkinjeCellFactory<ELEMENT_DIM,SPACE_DIM>::CreateJunction(const Node<SPACE_DIM>* pNode,
00054                                                                         AbstractCardiacCellInterface* pPurkinjeCell,
00055                                                                         AbstractCardiacCellInterface* pCardiacCell,
00056                                                                         double resistance)
00057 {
00058     // Figure out the effective resistance for this mesh, in kOhm.cm^3
00059     if (pNode) // Should always be provided apart from low-level tests!
00060     {
00061         assert(mpMixedDimensionMesh);
00062         typedef typename MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>::CableRangeAtNode CableRangeAtNode;
00063         CableRangeAtNode cable_range = mpMixedDimensionMesh->GetCablesAtNode(pNode);
00064         double total_cross_sectional_area = 0.0;
00065         for (typename MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>::NodeCableIterator iter=cable_range.first;
00066              iter != cable_range.second;
00067              ++iter)
00068         {
00069             Element<1u,SPACE_DIM>* p_cable = iter->second;
00070             double cable_radius = p_cable->GetAttribute();
00071             total_cross_sectional_area += M_PI*cable_radius*cable_radius;
00072         }
00073         resistance *= total_cross_sectional_area / HeartConfig::Instance()->GetPurkinjeSurfaceAreaToVolumeRatio();
00074     }
00075     // Create the junction stimuli, and associate them with the cells
00076     boost::shared_ptr<PurkinjeVentricularJunctionStimulus> p_pvj_ventricular_stim(new PurkinjeVentricularJunctionStimulus(resistance));
00077     boost::shared_ptr<PurkinjeVentricularJunctionStimulus> p_pvj_purkinje_stim(new PurkinjeVentricularJunctionStimulus(resistance));
00078     p_pvj_purkinje_stim->SetAppliedToPurkinjeCellModel();
00079     p_pvj_ventricular_stim->SetVentricularCellModel(pCardiacCell);
00080     p_pvj_ventricular_stim->SetPurkinjeCellModel(pPurkinjeCell);
00081     p_pvj_purkinje_stim->SetVentricularCellModel(pCardiacCell);
00082     p_pvj_purkinje_stim->SetPurkinjeCellModel(pPurkinjeCell);
00083 
00084     // Create new combined stimuli which add the junction stimuli to those already in the cells
00085     boost::shared_ptr<MultiStimulus> p_multi_stim_ventricular(new MultiStimulus);
00086     p_multi_stim_ventricular->AddStimulus(p_pvj_ventricular_stim);
00087     p_multi_stim_ventricular->AddStimulus(pCardiacCell->GetStimulusFunction());
00088     pCardiacCell->SetStimulusFunction(p_multi_stim_ventricular);
00089 
00090     boost::shared_ptr<MultiStimulus> p_multi_stim_purkinje(new MultiStimulus);
00091     p_multi_stim_purkinje->AddStimulus(p_pvj_purkinje_stim);
00092     p_multi_stim_purkinje->AddStimulus(pPurkinjeCell->GetStimulusFunction());
00093     pPurkinjeCell->SetStimulusFunction(p_multi_stim_purkinje);
00094 }
00095 
00096 
00097 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00098 void AbstractPurkinjeCellFactory<ELEMENT_DIM,SPACE_DIM>::SetMesh(AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh)
00099 {
00100     mpMixedDimensionMesh = dynamic_cast<MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>*>(pMesh);
00101     if (mpMixedDimensionMesh ==NULL)
00102     {
00103         EXCEPTION("AbstractPurkinjeCellFactory must take a MixedDimensionMesh");
00104     }
00105     mLocalPurkinjeNodes.clear();
00106     for (typename MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>::CableElementIterator iter = mpMixedDimensionMesh->GetCableElementIteratorBegin();
00107           iter != mpMixedDimensionMesh->GetCableElementIteratorEnd();
00108           ++iter)
00109     {
00110         mLocalPurkinjeNodes.insert((*iter)->GetNodeGlobalIndex(0u));
00111         mLocalPurkinjeNodes.insert((*iter)->GetNodeGlobalIndex(1u));
00112     }
00113     AbstractCardiacCellFactory<ELEMENT_DIM,SPACE_DIM>::SetMesh(pMesh);
00114 }
00115 
00116 
00117 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00118 AbstractCardiacCellInterface*  AbstractPurkinjeCellFactory<ELEMENT_DIM,SPACE_DIM>::CreatePurkinjeCellForNode(
00119         unsigned nodeIndex,
00120         AbstractCardiacCellInterface* pCardiacCell)
00121 {
00122     if (mLocalPurkinjeNodes.count(nodeIndex)>0)
00123     {
00124         return CreatePurkinjeCellForTissueNode(nodeIndex, pCardiacCell);
00125     }
00126     else
00127     {
00128         return new FakeBathCell(this->mpSolver, this->mpZeroStimulus);
00129     }
00130 }
00131 
00132 
00133 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00134 MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>* AbstractPurkinjeCellFactory<ELEMENT_DIM,SPACE_DIM>::GetMixedDimensionMesh()
00135 {
00136     if (mpMixedDimensionMesh == NULL)
00137     {
00138         EXCEPTION("The mixed dimension mesh object has not been set in the cell factory");
00139     }
00140     return mpMixedDimensionMesh;
00141 }
00142 
00144 // Explicit instantiation
00146 
00147 template class AbstractPurkinjeCellFactory<1,1>;
00148 template class AbstractPurkinjeCellFactory<2,2>;
00149 template class AbstractPurkinjeCellFactory<3,3>;
00150 template class AbstractPurkinjeCellFactory<1,2>;
00151 template class AbstractPurkinjeCellFactory<1,3>;