AveragedSourcePde.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 "AveragedSourcePde.hpp"
00037 #include "ApoptoticCellProperty.hpp"
00038 #include "PetscTools.hpp"
00039
00040 template<unsigned DIM>
00041 AveragedSourcePde<DIM>::AveragedSourcePde(AbstractCellPopulation<DIM>& rCellPopulation, double coefficient)
00042 : mrCellPopulation(rCellPopulation),
00043 mCoefficient(coefficient)
00044 {
00045 }
00046
00047 template<unsigned DIM>
00048 const AbstractCellPopulation<DIM>& AveragedSourcePde<DIM>::rGetCellPopulation() const
00049 {
00050 return mrCellPopulation;
00051 }
00052
00053 template<unsigned DIM>
00054 double AveragedSourcePde<DIM>::GetCoefficient() const
00055 {
00056 return mCoefficient;
00057 }
00058
00059 template<unsigned DIM>
00060 void AveragedSourcePde<DIM>::SetupSourceTerms(TetrahedralMesh<DIM,DIM>& rCoarseMesh, std::map< CellPtr, unsigned >* pCellPdeElementMap)
00061 {
00062
00063 mCellDensityOnCoarseElements.resize(rCoarseMesh.GetNumElements());
00064 for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
00065 {
00066 mCellDensityOnCoarseElements[elem_index] = 0.0;
00067 }
00068
00069
00070 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = mrCellPopulation.Begin();
00071 cell_iter != mrCellPopulation.End();
00072 ++cell_iter)
00073 {
00074 unsigned elem_index = 0;
00075 const ChastePoint<DIM>& r_position_of_cell = mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
00076
00077 if (pCellPdeElementMap != NULL)
00078 {
00079 elem_index = (*pCellPdeElementMap)[*cell_iter];
00080 }
00081 else
00082 {
00083 elem_index = rCoarseMesh.GetContainingElementIndex(r_position_of_cell);
00084 }
00085
00086
00087 bool cell_is_apoptotic = cell_iter->template HasCellProperty<ApoptoticCellProperty>();
00088
00089 if (!cell_is_apoptotic)
00090 {
00091 mCellDensityOnCoarseElements[elem_index] += 1.0;
00092 }
00093 }
00094
00095
00096 c_matrix<double, DIM, DIM> jacobian;
00097 double det;
00098 for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
00099 {
00100 rCoarseMesh.GetElement(elem_index)->CalculateJacobian(jacobian, det);
00101 mCellDensityOnCoarseElements[elem_index] /= rCoarseMesh.GetElement(elem_index)->GetVolume(det);
00102 }
00103 }
00104
00105 template<unsigned DIM>
00106 double AveragedSourcePde<DIM>::ComputeConstantInUSourceTerm(const ChastePoint<DIM>& rX, Element<DIM,DIM>* pElement)
00107 {
00108 return 0.0;
00109 }
00110
00111 template<unsigned DIM>
00112 double AveragedSourcePde<DIM>::ComputeLinearInUCoeffInSourceTerm(const ChastePoint<DIM>& rX, Element<DIM,DIM>* pElement)
00113 {
00114 assert(!mCellDensityOnCoarseElements.empty());
00115 return mCoefficient * mCellDensityOnCoarseElements[pElement->GetIndex()];
00116 }
00117
00118 template<unsigned DIM>
00119 c_matrix<double,DIM,DIM> AveragedSourcePde<DIM>::ComputeDiffusionTerm(const ChastePoint<DIM>& rX)
00120 {
00121 return identity_matrix<double>(DIM);
00122 }
00123
00124 template<unsigned DIM>
00125 double AveragedSourcePde<DIM>::GetUptakeRateForElement(unsigned elementIndex)
00126 {
00127 return this->mCellDensityOnCoarseElements[elementIndex];
00128 }
00129
00131
00133
00134 template class AveragedSourcePde<1>;
00135 template class AveragedSourcePde<2>;
00136 template class AveragedSourcePde<3>;
00137
00138
00139 #include "SerializationExportWrapperForCpp.hpp"
00140 EXPORT_TEMPLATE_CLASS_SAME_DIMS(AveragedSourcePde)