AveragedSourcePde.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 "AveragedSourcePde.hpp"
00030 #include "ApoptoticCellProperty.hpp"
00031 
00032 template<unsigned DIM>
00033 AveragedSourcePde<DIM>::AveragedSourcePde(MeshBasedCellPopulation<DIM>& rCellPopulation, double coefficient)
00034     : mrCellPopulation(rCellPopulation),
00035       mCoefficient(coefficient)
00036 {
00037 }
00038 
00039 template<unsigned DIM>
00040 void AveragedSourcePde<DIM>::SetupSourceTerms(TetrahedralMesh<DIM,DIM>& rCoarseMesh) // must be called before solve
00041 {
00042     // Allocate memory
00043     mCellDensityOnCoarseElements.resize(rCoarseMesh.GetNumElements());
00044     for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
00045     {
00046         mCellDensityOnCoarseElements[elem_index] = 0.0;
00047     }
00048 
00049     // Loop over cells, find which coarse element it is in, and add 1 to the mSourceTermOnCoarseElements[elem_index];
00050     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = mrCellPopulation.Begin();
00051         cell_iter != mrCellPopulation.End();
00052         ++cell_iter)
00053     {
00054         const ChastePoint<DIM>& r_position_of_cell = mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
00055         unsigned elem_index = rCoarseMesh.GetContainingElementIndex(r_position_of_cell);
00056 
00057         bool cell_is_apoptotic = cell_iter->template HasCellProperty<ApoptoticCellProperty>();
00058 
00059         if (!cell_is_apoptotic)
00060         {
00061             mCellDensityOnCoarseElements[elem_index] += 1.0;
00062         }
00063     }
00064 
00065     // Then divide each entry of mSourceTermOnCoarseElements by the element's area
00066     c_matrix<double, DIM, DIM> jacobian;
00067     double det;
00068     for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
00069     {
00070         rCoarseMesh.GetElement(elem_index)->CalculateJacobian(jacobian, det);
00071         mCellDensityOnCoarseElements[elem_index] /= rCoarseMesh.GetElement(elem_index)->GetVolume(det);
00072     }
00073 }
00074 
00075 template<unsigned DIM>
00076 double AveragedSourcePde<DIM>::ComputeConstantInUSourceTerm(const ChastePoint<DIM>& rX)
00077 {
00078     return 0.0;
00079 }
00080 
00081 template<unsigned DIM>
00082 double AveragedSourcePde<DIM>::ComputeLinearInUCoeffInSourceTerm(const ChastePoint<DIM>& rX, Element<DIM,DIM>* pElement) // now takes in element
00083 {
00084     assert(!mCellDensityOnCoarseElements.empty());
00085     return mCoefficient*mCellDensityOnCoarseElements[pElement->GetIndex()];
00086 }
00087 
00088 template<unsigned DIM>
00089 c_matrix<double,DIM,DIM> AveragedSourcePde<DIM>::ComputeDiffusionTerm(const ChastePoint<DIM>& rX)
00090 {
00091     return identity_matrix<double>(DIM);
00092 }
00093 
00094 
00096 // Explicit instantiation
00098 
00099 template class AveragedSourcePde<1>;
00100 template class AveragedSourcePde<2>;
00101 template class AveragedSourcePde<3>;

Generated on Mon Apr 18 11:35:27 2011 for Chaste by  doxygen 1.5.5