Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
AveragedSourceEllipticPde.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
39template<unsigned DIM>
41 double sourceCoefficient,
42 double diffusionCoefficient)
43 : mrCellPopulation(rCellPopulation),
44 mSourceCoefficient(sourceCoefficient),
45 mDiffusionCoefficient(diffusionCoefficient)
46{
47}
48
49template<unsigned DIM>
54
55template<unsigned DIM>
57{
58 return mSourceCoefficient;
59}
60
61template<unsigned DIM>
62void 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
107template<unsigned DIM>
112
113template<unsigned DIM>
115{
116 assert(!mCellDensityOnCoarseElements.empty());
117 return mSourceCoefficient * mCellDensityOnCoarseElements[pElement->GetIndex()];
118}
119
120template<unsigned DIM>
122{
123 return mDiffusionCoefficient*identity_matrix<double>(DIM);
124}
125
126template<unsigned DIM>
128{
129 return this->mCellDensityOnCoarseElements[elementIndex];
130}
131
132// Explicit instantiation
133template class AveragedSourceEllipticPde<1>;
134template class AveragedSourceEllipticPde<2>;
135template class AveragedSourceEllipticPde<3>;
136
137// Serialization for Boost >= 1.36
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
unsigned GetIndex() const
unsigned GetContainingElementIndex(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false, std::set< unsigned > testElements=std::set< unsigned >(), bool onlyTryWithTestElements=false)
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
virtual unsigned GetNumElements() const
double GetUptakeRateForElement(unsigned elementIndex)
c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX)
double ComputeConstantInUSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement)
virtual void SetupSourceTerms(TetrahedralMesh< DIM, DIM > &rCoarseMesh, std::map< CellPtr, unsigned > *pCellPdeElementMap=nullptr)
double ComputeLinearInUCoeffInSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement)
AveragedSourceEllipticPde(AbstractCellPopulation< DIM > &rCellPopulation, double sourceCoefficient=0.0, double diffusionCoefficient=1.0)
const AbstractCellPopulation< DIM > & rGetCellPopulation() const