Chaste Commit::30a3e656d4b131f8c595cc6eb2becd297337570f
CellwiseSourceEllipticPde.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 "CellwiseSourceEllipticPde.hpp"
37
38template<unsigned DIM>
40 const double constantSourceCoefficient,
41 const double linearSourceCoefficient,
42 const double diffusionCoefficient,
43 const bool scaleByCellVolume)
44 : mrCellPopulation(rCellPopulation),
45 mConstantSourceCoefficient(constantSourceCoefficient),
46 mLinearSourceCoefficient(linearSourceCoefficient),
47 mDiffusionCoefficient(diffusionCoefficient),
48 mScaleByCellVolume(scaleByCellVolume)
49{
50}
51
52template<unsigned DIM>
57
58template<unsigned DIM>
60{
61 return mConstantSourceCoefficient;
62}
63
64template<unsigned DIM>
66{
67 return mLinearSourceCoefficient;
68}
69
70template<unsigned DIM>
72{
73 return mDiffusionCoefficient;
74}
75
76template<unsigned DIM>
78{
79 return mScaleByCellVolume;
80}
81
82// LCOV_EXCL_START
83template<unsigned DIM>
88
89template<unsigned DIM>
94// LCOV_EXCL_STOP
95
96template<unsigned DIM>
98{
99 double linear_source_coefficient = 0.0;
100
101 if (mLinearSourceCoefficient != 0.0)
102 {
103 if (mrCellPopulation.IsPdeNodeAssociatedWithNonApoptoticCell(rNode.GetIndex()))
104 {
105 double cell_volume = 1.0;
106
107 // Scale by volume if wanted
108 if (mScaleByCellVolume)
109 {
110 CellPtr p_cell = mrCellPopulation.GetCellUsingLocationIndex(rNode.GetIndex());
111 cell_volume = mrCellPopulation.GetVolumeOfCell(p_cell);
112
113 if (cell_volume <1e-6)
114 {
115 EXCEPTION("The volume of one of the cells is " << cell_volume <<
116 " and you are scaling by cell volume. Either turn scaling off or use"
117 " a cell model with non zero areas (i.e. a Bounded Voronoi Tesselation model).");
118 }
119 }
120 linear_source_coefficient = mLinearSourceCoefficient/cell_volume;
121 }
122 }
123
124 return linear_source_coefficient;
125}
126
127template<unsigned DIM>
129{
130 double constant_source_coefficient = 0.0;
131
132 if (mConstantSourceCoefficient != 0.0)
133 {
134 if (mrCellPopulation.IsPdeNodeAssociatedWithNonApoptoticCell(rNode.GetIndex()))
135 {
136 double cell_volume = 1.0;
137
138 // Scale by volume if wanted
139 if (mScaleByCellVolume)
140 {
141 CellPtr p_cell = mrCellPopulation.GetCellUsingLocationIndex(rNode.GetIndex());
142 cell_volume = mrCellPopulation.GetVolumeOfCell(p_cell);
143 if (cell_volume <1e-6)
144 {
145 EXCEPTION("The volume of one of the cells is " << cell_volume <<
146 " and you are scaling by cell volume. Either turn scaling off or use"
147 " a cell model with non zero areas (i.e. a Bounded Voronoi Tesselation model).");
148 }
149 }
150 constant_source_coefficient = mConstantSourceCoefficient/cell_volume;
151 }
152 }
153
154 return constant_source_coefficient;
155}
156
157template<unsigned DIM>
159{
160 return mDiffusionCoefficient*identity_matrix<double>(DIM);
161}
162
163// Explicit instantiation
164template class CellwiseSourceEllipticPde<1>;
165template class CellwiseSourceEllipticPde<2>;
166template class CellwiseSourceEllipticPde<3>;
167
168// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
const AbstractCellPopulation< DIM > & rGetCellPopulation() const
double ComputeConstantInUSourceTermAtNode(const Node< DIM > &rNode) override
double ComputeConstantInUSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement) override
double ComputeLinearInUCoeffInSourceTerm(const ChastePoint< DIM > &rX, Element< DIM, DIM > *pElement) override
c_matrix< double, DIM, DIM > ComputeDiffusionTerm(const ChastePoint< DIM > &rX) override
double ComputeLinearInUCoeffInSourceTermAtNode(const Node< DIM > &rNode) override
CellwiseSourceEllipticPde(AbstractCellPopulation< DIM, DIM > &rCellPopulation, double constantSourceCoefficient=0.0, double linearSourceCoefficient=0.0, double diffusionCoefficient=1.0, bool scaleByCellVolume=false)
Definition Node.hpp:59
unsigned GetIndex() const
Definition Node.cpp:158