Chaste  Release::2017.1
AveragedSourceParabolicPde.cpp
1 /*
2 
3 Copyright (c) 2005-2017, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "AveragedSourceParabolicPde.hpp"
37 #include "ApoptoticCellProperty.hpp"
38 
39 template<unsigned DIM>
41  double duDtCoefficient,
42  double diffusionCoefficient,
43  double sourceCoefficient)
44  : mrCellPopulation(rCellPopulation),
45  mDuDtCoefficient(duDtCoefficient),
46  mDiffusionCoefficient(diffusionCoefficient),
47  mSourceCoefficient(sourceCoefficient)
48 {
49 }
50 
51 template<unsigned DIM>
53 {
54  return mrCellPopulation;
55 }
56 
57 template<unsigned DIM>
58 void AveragedSourceParabolicPde<DIM>::SetupSourceTerms(TetrahedralMesh<DIM,DIM>& rCoarseMesh, std::map<CellPtr, unsigned>* pCellPdeElementMap) // must be called before solve
59 {
60  // Allocate memory
61  mCellDensityOnCoarseElements.resize(rCoarseMesh.GetNumElements());
62  for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
63  {
64  mCellDensityOnCoarseElements[elem_index] = 0.0;
65  }
66 
67  // Loop over cells, find which coarse element it is in, and add 1 to mSourceTermOnCoarseElements[elem_index]
69  cell_iter != mrCellPopulation.End();
70  ++cell_iter)
71  {
72  unsigned elem_index = 0;
73  const ChastePoint<DIM>& r_position_of_cell = mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
74 
75  if (pCellPdeElementMap != nullptr)
76  {
77  elem_index = (*pCellPdeElementMap)[*cell_iter];
78  }
79  else
80  {
81  elem_index = rCoarseMesh.GetContainingElementIndex(r_position_of_cell);
82  }
83 
84  // Update element map if cell has moved
85  bool cell_is_apoptotic = cell_iter->template HasCellProperty<ApoptoticCellProperty>();
86 
87  if (!cell_is_apoptotic)
88  {
89  mCellDensityOnCoarseElements[elem_index] += 1.0;
90  }
91  }
92 
93  // Then divide each entry of mSourceTermOnCoarseElements by the element's area
94  c_matrix<double, DIM, DIM> jacobian;
95  double det;
96  for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
97  {
98  rCoarseMesh.GetElement(elem_index)->CalculateJacobian(jacobian, det);
99  mCellDensityOnCoarseElements[elem_index] /= rCoarseMesh.GetElement(elem_index)->GetVolume(det);
100  }
101 }
102 
103 template<unsigned DIM>
105 {
106  return mDuDtCoefficient;
107 }
108 
109 template<unsigned DIM>
111 {
112  assert(!mCellDensityOnCoarseElements.empty());
113  double coefficient = mSourceCoefficient * mCellDensityOnCoarseElements[pElement->GetIndex()];
114 
115  // The source term is C*u
116  return coefficient*u;
117 }
118 
119 // LCOV_EXCL_START
120 template<unsigned DIM>
122 {
124  return 0.0;
125 }
126 // LCOV_EXCL_STOP
127 
128 template<unsigned DIM>
130 {
131  return mDiffusionCoefficient*identity_matrix<double>(DIM);
132 }
133 
134 template<unsigned DIM>
136 {
137  return this->mCellDensityOnCoarseElements[elementIndex];
138 }
139 
140 // Explicit instantiation
141 template class AveragedSourceParabolicPde<1>;
142 template class AveragedSourceParabolicPde<2>;
143 template class AveragedSourceParabolicPde<3>;
144 
145 // Serialization for Boost >= 1.36
virtual double ComputeSourceTerm(const ChastePoint< DIM > &rX, double u, Element< DIM, DIM > *pElement=NULL)
Definition: Node.hpp:58
double GetUptakeRateForElement(unsigned elementIndex)
virtual unsigned GetNumElements() const
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
virtual c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement=NULL)
std::vector< double > mCellDensityOnCoarseElements
#define NEVER_REACHED
Definition: Exception.hpp:206
virtual void SetupSourceTerms(TetrahedralMesh< DIM, DIM > &rCoarseMesh, std::map< CellPtr, unsigned > *pCellPdeElementMap=nullptr)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
const AbstractCellPopulation< DIM > & rGetCellPopulation() const
virtual double ComputeSourceTermAtNode(const Node< DIM > &rNode, double u)
unsigned GetContainingElementIndex(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false, std::set< unsigned > testElements=std::set< unsigned >(), bool onlyTryWithTestElements=false)
virtual c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)=0
AveragedSourceParabolicPde(AbstractCellPopulation< DIM, DIM > &rCellPopulation, double duDtCoefficient=1.0, double diffusionCoefficient=1.0, double sourceCoefficient=0.0)
virtual double ComputeDuDtCoefficientFunction(const ChastePoint< DIM > &rX)
unsigned GetIndex() const
AbstractCellPopulation< DIM, DIM > & mrCellPopulation