Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AveragedSourceParabolicPde.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 "AveragedSourceParabolicPde.hpp"
37#include "ApoptoticCellProperty.hpp"
38
39template<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
51template<unsigned DIM>
56
57template<unsigned DIM>
58void 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]
68 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = mrCellPopulation.Begin();
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
103template<unsigned DIM>
105{
106 return mDuDtCoefficient;
107}
108
109template<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
120template<unsigned DIM>
122{
124 return 0.0;
125}
126// LCOV_EXCL_STOP
127
128template<unsigned DIM>
130{
131 return mDiffusionCoefficient*identity_matrix<double>(DIM);
132}
133
134template<unsigned DIM>
136{
137 return this->mCellDensityOnCoarseElements[elementIndex];
138}
139
140// Explicit instantiation
141template class AveragedSourceParabolicPde<1>;
142template class AveragedSourceParabolicPde<2>;
143template class AveragedSourceParabolicPde<3>;
144
145// Serialization for Boost >= 1.36
#define NEVER_REACHED
#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
virtual double ComputeSourceTermAtNode(const Node< DIM > &rNode, double u)
AveragedSourceParabolicPde(AbstractCellPopulation< DIM, DIM > &rCellPopulation, double duDtCoefficient=1.0, double diffusionCoefficient=1.0, double sourceCoefficient=0.0)
virtual double ComputeDuDtCoefficientFunction(const ChastePoint< DIM > &rX)
virtual c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement=NULL)
double GetUptakeRateForElement(unsigned elementIndex)
const AbstractCellPopulation< DIM > & rGetCellPopulation() const
virtual void SetupSourceTerms(TetrahedralMesh< DIM, DIM > &rCoarseMesh, std::map< CellPtr, unsigned > *pCellPdeElementMap=nullptr)
virtual double ComputeSourceTerm(const ChastePoint< DIM > &rX, double u, Element< DIM, DIM > *pElement=NULL)
Definition Node.hpp:59