VolumeDependentAveragedSourcePde.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "VolumeDependentAveragedSourcePde.hpp"
00030 #include "ApoptoticCellProperty.hpp"
00031 
00032 template<unsigned DIM>
00033 VolumeDependentAveragedSourcePde<DIM>::VolumeDependentAveragedSourcePde(AbstractCellPopulation<DIM>& rCellPopulation, double coefficient)
00034     : AveragedSourcePde<DIM>(rCellPopulation, coefficient)
00035 {
00036     assert(dynamic_cast<NodeBasedCellPopulation<DIM>*>(&(this->mrCellPopulation)));
00037     mpStaticCastCellPopulation = static_cast<NodeBasedCellPopulation<DIM>*>(&(this->mrCellPopulation));
00038 }
00039 
00040 template<unsigned DIM>
00041 void VolumeDependentAveragedSourcePde<DIM>::SetupSourceTerms(TetrahedralMesh<DIM,DIM>& rCoarseMesh,  std::map< CellPtr, unsigned >* pCellPdeElementMap) // must be called before solve
00042 {
00043     // Allocate memory
00044     this->mCellDensityOnCoarseElements.resize(rCoarseMesh.GetNumElements());
00045     for (unsigned elem_index=0; elem_index<this->mCellDensityOnCoarseElements.size(); elem_index++)
00046     {
00047         this->mCellDensityOnCoarseElements[elem_index] = 0.0;
00048     }
00049 
00050     // Loop over cells, find which coarse element it is in, and add volume to the mSourceTermOnCoarseElements[elem_index];
00051     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mrCellPopulation.Begin();
00052          cell_iter != this->mrCellPopulation.End();
00053          ++cell_iter)
00054     {
00055         unsigned elem_index = 0;
00056         const ChastePoint<DIM>& r_position_of_cell = this->mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
00057 
00058         if (pCellPdeElementMap != NULL)
00059         {
00060             elem_index = (*pCellPdeElementMap)[*cell_iter];
00061         }
00062         else
00063         {
00064             elem_index = rCoarseMesh.GetContainingElementIndex(r_position_of_cell);
00065         }
00066 
00067         unsigned node_index = this->mrCellPopulation.GetLocationIndexUsingCell(*cell_iter);
00068 
00069         // Uptake normalised to 1 for unit cell
00070         double radius = mpStaticCastCellPopulation->rGetMesh().GetCellRadius(node_index);
00071         double cell_weight = radius*radius;
00072 
00073         bool cell_is_apoptotic = cell_iter->template HasCellProperty<ApoptoticCellProperty>();
00074         if (!cell_is_apoptotic)
00075         {
00076             this->mCellDensityOnCoarseElements[elem_index] += cell_weight;
00077         }
00078     }
00079 
00080     // Then divide each entry of mSourceTermOnCoarseElements by the element's area
00081     c_matrix<double, DIM, DIM> jacobian;
00082     double det;
00083     for (unsigned elem_index=0; elem_index<this->mCellDensityOnCoarseElements.size(); elem_index++)
00084     {
00085         rCoarseMesh.GetElement(elem_index)->CalculateJacobian(jacobian, det);
00086         this->mCellDensityOnCoarseElements[elem_index] /= rCoarseMesh.GetElement(elem_index)->GetVolume(det);
00087     }
00088 }
00089 
00091 // Explicit instantiation
00093 
00094 template class VolumeDependentAveragedSourcePde<1>;
00095 template class VolumeDependentAveragedSourcePde<2>;
00096 template class VolumeDependentAveragedSourcePde<3>;
00097 
00098 // Serialization for Boost >= 1.36
00099 #include "SerializationExportWrapperForCpp.hpp"
00100 EXPORT_TEMPLATE_CLASS_SAME_DIMS(VolumeDependentAveragedSourcePde)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3