Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
DivisionBiasTrackingModifier.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 "DivisionBiasTrackingModifier.hpp"
37#include "MeshBasedCellPopulation.hpp"
38
39template<unsigned DIM>
42 mDivisionBiasVector(divisionBiasVector)
43{
44 // mDivisionBiasVector must be a unit vector
45 assert(fabs(norm_2(mDivisionBiasVector) - 1.0) < 1e-6);
46}
47
48template<unsigned DIM>
52
53template<unsigned DIM>
55{
56 return mDivisionBiasVector;
57}
58
59template<unsigned DIM>
61{
62 UpdateCellData(rCellPopulation);
63}
64
65template<unsigned DIM>
66void DivisionBiasTrackingModifier<DIM>::SetupSolve(AbstractCellPopulation<DIM,DIM>& rCellPopulation, std::string outputDirectory)
67{
68 /*
69 * We must update CellData in SetupSolve(), otherwise it will not have been
70 * fully initialised by the time we enter the main time loop.
71 */
72 UpdateCellData(rCellPopulation);
73}
74
75template<unsigned DIM>
77{
78 // Make sure the cell population is updated
79 rCellPopulation.Update();
80
90 if (bool(dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation)))
91 {
92 static_cast<MeshBasedCellPopulation<DIM>*>(&(rCellPopulation))->CreateVoronoiTessellation();
93 }
94
95 // Find centroid of cell population
96 c_vector<double, DIM> centroid = rCellPopulation.GetCentroidOfCellPopulation();
97
103 std::vector<double> biases;
104 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();
105 cell_iter != rCellPopulation.End();
106 ++cell_iter)
107 {
108 double distance = inner_prod(rCellPopulation.GetLocationOfCellCentre(*cell_iter) - centroid, mDivisionBiasVector);
109 biases.push_back(distance);
110 }
111
112 // Map signed distances into [0,1]
113 double min_distance = *std::min_element(biases.begin(), biases.end());
114 double max_distance = *std::max_element(biases.begin(), biases.end());
115 for (unsigned i = 0; i < biases.size(); i++)
116 {
117 biases[i] = (biases[i] - min_distance) / (max_distance - min_distance);
118 }
119
120 // Iterate over cell population
121 unsigned i = 0;
122 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();
123 cell_iter != rCellPopulation.End();
124 ++cell_iter)
125 {
126 // Store the cell's volume in CellData
127 cell_iter->GetCellData()->SetItem("bias", biases[i]);
128 i++;
129 }
130}
131
132template<unsigned DIM>
134{
135 *rParamsFile << "\t\t\t<DivisionBiasVector>";
136 for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
137 {
138 *rParamsFile << mDivisionBiasVector[index] << ",";
139 }
140 *rParamsFile << mDivisionBiasVector[DIM-1] << "</DivisionBiasVector>\n";
141
142 // Call method on direct parent class
144}
145
146// Explicit instantiation
150
151// Serialization for Boost >= 1.36
154
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputSimulationModifierParameters(out_stream &rParamsFile)=0
virtual c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)=0
virtual void Update(bool hasHadBirthsOrDeaths=true)=0
c_vector< double, SPACE_DIM > GetCentroidOfCellPopulation()
DivisionBiasTrackingModifier(c_vector< double, DIM > divisionBiasVector)
virtual void UpdateAtEndOfTimeStep(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
void UpdateCellData(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
const c_vector< double, DIM > & rGetDivisionBiasVector() const
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)