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