Chaste  Release::2018.1
AveragedSourceEllipticPde.cpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 "AveragedSourceEllipticPde.hpp"
37 #include "ApoptoticCellProperty.hpp"
38 
39 template<unsigned DIM>
41  double sourceCoefficient,
42  double diffusionCoefficient)
43  : mrCellPopulation(rCellPopulation),
44  mSourceCoefficient(sourceCoefficient),
45  mDiffusionCoefficient(diffusionCoefficient)
46 {
47 }
48 
49 template<unsigned DIM>
51 {
52  return mrCellPopulation;
53 }
54 
55 template<unsigned DIM>
57 {
58  return mSourceCoefficient;
59 }
60 
61 template<unsigned DIM>
62 void AveragedSourceEllipticPde<DIM>::SetupSourceTerms(TetrahedralMesh<DIM,DIM>& rCoarseMesh, std::map< CellPtr, unsigned >* pCellPdeElementMap) // must be called before solve
63 {
64  // Allocate memory
65  mCellDensityOnCoarseElements.resize(rCoarseMesh.GetNumElements());
66  for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
67  {
68  mCellDensityOnCoarseElements[elem_index] = 0.0;
69  }
70 
71  // Loop over cells, find which coarse element it is in, and add 1 to mSourceTermOnCoarseElements[elem_index]
72  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = mrCellPopulation.Begin();
73  cell_iter != mrCellPopulation.End();
74  ++cell_iter)
75  {
76  unsigned elem_index = 0;
77  const ChastePoint<DIM>& r_position_of_cell = mrCellPopulation.GetLocationOfCellCentre(*cell_iter);
78 
79  if (pCellPdeElementMap != nullptr)
80  {
81  elem_index = (*pCellPdeElementMap)[*cell_iter];
82  }
83  else
84  {
85  elem_index = rCoarseMesh.GetContainingElementIndex(r_position_of_cell);
86  }
87 
88  // Update element map if cell has moved
89  bool cell_is_apoptotic = cell_iter->template HasCellProperty<ApoptoticCellProperty>();
90 
91  if (!cell_is_apoptotic)
92  {
93  mCellDensityOnCoarseElements[elem_index] += 1.0;
94  }
95  }
96 
97  // Then divide each entry of mSourceTermOnCoarseElements by the element's area
98  c_matrix<double, DIM, DIM> jacobian;
99  double det;
100  for (unsigned elem_index=0; elem_index<mCellDensityOnCoarseElements.size(); elem_index++)
101  {
102  rCoarseMesh.GetElement(elem_index)->CalculateJacobian(jacobian, det);
103  mCellDensityOnCoarseElements[elem_index] /= rCoarseMesh.GetElement(elem_index)->GetVolume(det);
104  }
105 }
106 
107 template<unsigned DIM>
109 {
110  return 0.0;
111 }
112 
113 template<unsigned DIM>
115 {
116  assert(!mCellDensityOnCoarseElements.empty());
117  return mSourceCoefficient * mCellDensityOnCoarseElements[pElement->GetIndex()];
118 }
119 
120 template<unsigned DIM>
122 {
123  return mDiffusionCoefficient*identity_matrix<double>(DIM);
124 }
125 
126 template<unsigned DIM>
128 {
129  return this->mCellDensityOnCoarseElements[elementIndex];
130 }
131 
132 // Explicit instantiation
133 template class AveragedSourceEllipticPde<1>;
134 template class AveragedSourceEllipticPde<2>;
135 template class AveragedSourceEllipticPde<3>;
136 
137 // Serialization for Boost >= 1.36
AveragedSourceEllipticPde(AbstractCellPopulation< DIM > &rCellPopulation, double sourceCoefficient=0.0, double diffusionCoefficient=1.0)
double GetUptakeRateForElement(unsigned elementIndex)
virtual unsigned GetNumElements() const
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
virtual void SetupSourceTerms(TetrahedralMesh< DIM, DIM > &rCoarseMesh, std::map< CellPtr, unsigned > *pCellPdeElementMap=nullptr)
c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
const AbstractCellPopulation< DIM > & rGetCellPopulation() const
unsigned GetContainingElementIndex(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false, std::set< unsigned > testElements=std::set< unsigned >(), bool onlyTryWithTestElements=false)
unsigned GetIndex() const
double ComputeLinearInUCoeffInSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement)
double ComputeConstantInUSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement)