Chaste Commit::30a3e656d4b131f8c595cc6eb2becd297337570f
CellwiseSourceParabolicPde.cpp
1/*
2
3Copyright (c) 2005-2025, 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 "CellwiseSourceParabolicPde.hpp"
37
38template<unsigned DIM>
40 const double constantSourceCoefficient,
41 const double linearSourceCoefficient,
42 const double diffusionCoefficient,
43 const double duDtCoefficient,
44 const bool scaleByCellVolume)
45 : mrCellPopulation(rCellPopulation),
46 mConstantSourceCoefficient(constantSourceCoefficient),
47 mLinearSourceCoefficient(linearSourceCoefficient),
48 mDiffusionCoefficient(diffusionCoefficient),
49 mDuDtCoefficient(duDtCoefficient),
50 mScaleByCellVolume(scaleByCellVolume)
51{
52}
53
54template<unsigned DIM>
59
60template<unsigned DIM>
62{
63 return mConstantSourceCoefficient;
64}
65
66template<unsigned DIM>
68{
69 return mLinearSourceCoefficient;
70}
71
72template<unsigned DIM>
74{
75 return mDiffusionCoefficient;
76}
77
78template<unsigned DIM>
80{
81 return mDuDtCoefficient;
82}
83
84template<unsigned DIM>
86{
87 return mScaleByCellVolume;
88}
89
90template<unsigned DIM>
95
96// LCOV_EXCL_START
97template<unsigned DIM>
102// LCOV_EXCL_STOP
103
104template<unsigned DIM>
106{
107 double source_term = 0.0;
108
109 if (mConstantSourceCoefficient != 0.0 || mLinearSourceCoefficient != 0.0)
110 {
111 if (mrCellPopulation.IsPdeNodeAssociatedWithNonApoptoticCell(rNode.GetIndex()))
112 {
113
114 double cell_volume = 1.0;
115
116 // Scale by volume if wanted
117 if (mScaleByCellVolume)
118 {
119 CellPtr p_cell = mrCellPopulation.GetCellUsingLocationIndex(rNode.GetIndex());
120 cell_volume = mrCellPopulation.GetVolumeOfCell(p_cell);
121
122 if (cell_volume <1e-6)
123 {
124 EXCEPTION("The volume of one of the cells is " << cell_volume <<
125 " and you are scaling by cell volume. Either turn scaling off or use"
126 " a cell model with non zero areas (i.e. a Bounded Voronoi Tesselation model).");
127 }
128 }
129
130 // At cells the source term is a*u + b
131 source_term = (mLinearSourceCoefficient * u + mConstantSourceCoefficient)/cell_volume;
132 }
133 }
134
135
136 return source_term;
137}
138
139template<unsigned DIM>
141{
142 return mDiffusionCoefficient*identity_matrix<double>(DIM);
143}
144
145// Explicit instantiation
146template class CellwiseSourceParabolicPde<1>;
147template class CellwiseSourceParabolicPde<2>;
148template class CellwiseSourceParabolicPde<3>;
149
150// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
CellwiseSourceParabolicPde(AbstractCellPopulation< DIM, DIM > &rCellPopulation, double constantSourceCoefficient=0.0, double linearSourceCoefficient=0.0, double diffusionCoefficient=1.0, double duDtCoefficient=1.0, bool scaleByCellVolume=false)
double ComputeDuDtCoefficientFunction(const ChastePoint< DIM > &rX) override
const AbstractCellPopulation< DIM > & rGetCellPopulation() const
double ComputeSourceTerm(const ChastePoint< DIM > &rX, double u, Element< DIM, DIM > *pElement) override
c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement=nullptr) override
double ComputeSourceTermAtNode(const Node< DIM > &rNode, double u) override
Definition Node.hpp:59
unsigned GetIndex() const
Definition Node.cpp:158