BidomainTissue.cpp
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
00036 #include "BidomainTissue.hpp"
00037
00038 #include "DistributedVector.hpp"
00039 #include "AxisymmetricConductivityTensors.hpp"
00040 #include "OrthotropicConductivityTensors.hpp"
00041 #include "ChastePoint.hpp"
00042 #include "AbstractChasteRegion.hpp"
00043
00044 template <unsigned SPACE_DIM>
00045 BidomainTissue<SPACE_DIM>::BidomainTissue(
00046 AbstractCardiacCellFactory<SPACE_DIM>* pCellFactory,
00047 bool exchangeHalos)
00048 : AbstractCardiacTissue<SPACE_DIM>(pCellFactory, exchangeHalos)
00049 {
00050 CreateExtracellularConductivityTensors();
00051 }
00052
00053 template <unsigned SPACE_DIM>
00054 BidomainTissue<SPACE_DIM>::BidomainTissue(AbstractTetrahedralMesh<SPACE_DIM,SPACE_DIM>* pMesh)
00055 : AbstractCardiacTissue<SPACE_DIM>(pMesh)
00056 {
00057 CreateExtracellularConductivityTensors();
00058 }
00059
00060 template <unsigned SPACE_DIM>
00061 void BidomainTissue<SPACE_DIM>::CreateExtracellularConductivityTensors()
00062 {
00063 if (this->mpConfig->IsMeshProvided() && this->mpConfig->GetLoadMesh())
00064 {
00065 assert(this->mFibreFilePathNoExtension != "");
00066
00067 switch (this->mpConfig->GetConductivityMedia())
00068 {
00069 case cp::media_type::Orthotropic:
00070 {
00071 mpExtracellularConductivityTensors = new OrthotropicConductivityTensors<SPACE_DIM,SPACE_DIM>;
00072 FileFinder ortho_file(this->mFibreFilePathNoExtension + ".ortho", RelativeTo::AbsoluteOrCwd);
00073 assert(ortho_file.Exists());
00074 mpExtracellularConductivityTensors->SetFibreOrientationFile(ortho_file);
00075 break;
00076 }
00077
00078 case cp::media_type::Axisymmetric:
00079 {
00080 mpExtracellularConductivityTensors = new AxisymmetricConductivityTensors<SPACE_DIM,SPACE_DIM>;
00081 FileFinder axi_file(this->mFibreFilePathNoExtension + ".axi", RelativeTo::AbsoluteOrCwd);
00082 assert(axi_file.Exists());
00083 mpExtracellularConductivityTensors->SetFibreOrientationFile(axi_file);
00084 break;
00085 }
00086
00087 case cp::media_type::NoFibreOrientation:
00088 mpExtracellularConductivityTensors = new OrthotropicConductivityTensors<SPACE_DIM,SPACE_DIM>;
00089 break;
00090
00091 default :
00092 NEVER_REACHED;
00093 }
00094 }
00095 else
00096 {
00097 mpExtracellularConductivityTensors = new OrthotropicConductivityTensors<SPACE_DIM,SPACE_DIM>;
00098 }
00099
00100 c_vector<double, SPACE_DIM> extra_conductivities;
00101 this->mpConfig->GetExtracellularConductivities(extra_conductivities);
00102
00103
00104
00105 unsigned num_local_elements = this->mpMesh->GetNumLocalElements();
00106 std::vector<c_vector<double, SPACE_DIM> > hetero_extra_conductivities;
00107
00108 if (this->mpConfig->GetConductivityHeterogeneitiesProvided())
00109 {
00110 try
00111 {
00112 assert(hetero_extra_conductivities.size()==0);
00113
00114 hetero_extra_conductivities.resize(num_local_elements, extra_conductivities);
00115 }
00116 catch(std::bad_alloc &r_bad_alloc)
00117 {
00118 #define COVERAGE_IGNORE
00119 std::cout << "Failed to allocate std::vector of size " << num_local_elements << std::endl;
00120 PetscTools::ReplicateException(true);
00121 throw r_bad_alloc;
00122 #undef COVERAGE_IGNORE
00123 }
00124 PetscTools::ReplicateException(false);
00125
00126 std::vector<boost::shared_ptr<AbstractChasteRegion<SPACE_DIM> > > conductivities_heterogeneity_areas;
00127 std::vector< c_vector<double,3> > intra_h_conductivities;
00128 std::vector< c_vector<double,3> > extra_h_conductivities;
00129 HeartConfig::Instance()->GetConductivityHeterogeneities(conductivities_heterogeneity_areas,
00130 intra_h_conductivities,
00131 extra_h_conductivities);
00132
00133 unsigned local_element_index = 0;
00134
00135 for (typename AbstractTetrahedralMesh<SPACE_DIM,SPACE_DIM>::ElementIterator iter = (this->mpMesh)->GetElementIteratorBegin();
00136 iter != (this->mpMesh)->GetElementIteratorEnd();
00137 ++iter)
00138 {
00139
00140 ChastePoint<SPACE_DIM> element_centroid(iter->CalculateCentroid());
00141 for (unsigned region_index=0; region_index< conductivities_heterogeneity_areas.size(); region_index++)
00142 {
00143
00144 if ( conductivities_heterogeneity_areas[region_index]->DoesContain( element_centroid ) )
00145 {
00146
00147 for (unsigned i=0; i<SPACE_DIM; i++)
00148 {
00149 hetero_extra_conductivities[local_element_index][i] = extra_h_conductivities[region_index][i];
00150 }
00151 }
00152 }
00153 local_element_index++;
00154 }
00155 mpExtracellularConductivityTensors->SetNonConstantConductivities(&hetero_extra_conductivities);
00156 }
00157 else
00158 {
00159 mpExtracellularConductivityTensors->SetConstantConductivities(extra_conductivities);
00160 }
00161
00162 mpExtracellularConductivityTensors->Init(this->mpMesh);
00163 }
00164
00165 template <unsigned SPACE_DIM>
00166 BidomainTissue<SPACE_DIM>::~BidomainTissue()
00167 {
00168 if (mpExtracellularConductivityTensors)
00169 {
00170 delete mpExtracellularConductivityTensors;
00171 }
00172 }
00173
00174
00175 template <unsigned SPACE_DIM>
00176 const c_matrix<double, SPACE_DIM, SPACE_DIM>& BidomainTissue<SPACE_DIM>::rGetExtracellularConductivityTensor(unsigned elementIndex)
00177 {
00178 assert(mpExtracellularConductivityTensors);
00179 if(this->mpConductivityModifier==NULL)
00180 {
00181 return (*mpExtracellularConductivityTensors)[elementIndex];
00182 }
00183 else
00184 {
00185 return this->mpConductivityModifier->rGetModifiedConductivityTensor(elementIndex, (*mpExtracellularConductivityTensors)[elementIndex], 1u);
00186 }
00187 }
00188
00189
00191
00193
00194 template class BidomainTissue<1>;
00195 template class BidomainTissue<2>;
00196 template class BidomainTissue<3>;
00197
00198
00199
00200 #include "SerializationExportWrapperForCpp.hpp"
00201 EXPORT_TEMPLATE_CLASS_SAME_DIMS(BidomainTissue)