Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
T2SwapCellKiller.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 "T2SwapCellKiller.hpp"
37#include "CellRemovalLocationsWriter.hpp"
38
39template<unsigned DIM>
41 : AbstractCellKiller<DIM>(pCellPopulation)
42{
43 // Throw an exception if the population is not a VertexBasedCellPopulation
44 if (dynamic_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation) == nullptr)
45 {
46 EXCEPTION("A T2SwapCellKiller should only be used together with a VertexBasedCellPopulation.");
47 }
48}
49
50template<unsigned DIM>
52{
53 /*
54 * This killer is different to other killers: it does not only check and label
55 * cells for apoptosis or death, it actually carries out vertex rearrangements
56 * and removes elements from the vertex mesh.
57 *
58 * We start with carrying out T2 swaps. Get the mesh and an element map.
59 * The static_cast will work since we already know it's a VertexBasedCellPopulation.
60 */
61 MutableVertexMesh<DIM,DIM>& mesh = static_cast<MutableVertexMesh<DIM,DIM>&>(this->mpCellPopulation->rGetMesh());
62 VertexBasedCellPopulation<DIM>* p_vertex_population = static_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation);
63 VertexElementMap element_map(mesh.GetNumAllElements());
64
65 bool recheck_mesh = true;
66 while (recheck_mesh == true)
67 {
68 // Note that whenever we call CheckForT2Swaps(), the element indices must run from zero up to mElements.size()-1
69 recheck_mesh = mesh.CheckForT2Swaps(element_map);
70 /*
71 * There might have maximally one T2 swap happened above, where a vertex element was removed from the
72 * mesh but the associated cell is still there. Here we check whether a new cell
73 * underwent a T2 swap and label it as dead as well as record its location and ID.
74 */
75 for (unsigned elem_index = 0; elem_index < element_map.Size(); elem_index++)
76 {
77 CellPtr p_cell = this->mpCellPopulation->GetCellUsingLocationIndex(elem_index);
78 if (element_map.IsDeleted(elem_index) && !(p_cell->IsDead()))
79 {
80 p_vertex_population->AddLocationOfT2Swap(mesh.GetLastT2SwapLocation());
81 p_vertex_population->AddCellIdOfT2Swap(p_cell->GetCellId());
82
83 /* Mark the cell as killed and store removal information if required.
84 * Note we can't use the KillCell() helper method here as it will fail as the
85 * element has already been deleted.
86 * this->mpCellPopulation->KillCell(p_cell, "T2SwapCellKiller");
87 */
88 if (p_vertex_population->template HasWriter<CellRemovalLocationsWriter>())
89 {
90 std::stringstream removal_info;
91 removal_info << SimulationTime::Instance()->GetTime() << "\t";
92 for (unsigned i = 0; i < DIM; i++)
93 {
94 removal_info << mesh.GetLastT2SwapLocation()[i] << "\t";
95 }
96 removal_info << "\t" << p_cell->GetAge() << "\t" << p_cell->GetCellId() << "\t"
97 << "T2SwapCellKiller"
98 << "\t";
99
100 p_vertex_population->AddRemovalInformation(removal_info.str());
101 }
102 p_cell->Kill();
103
104 // There can't have been more than one new cell death, so leave the for loop here.
105 break;
106 }
107 }
108 }
109
110}
111
112template<unsigned DIM>
114{
115 // No parameters to output, so just call method on direct parent class
117}
118
119// Explicit instantiation
120template class T2SwapCellKiller<1>;
121template class T2SwapCellKiller<2>;
122template class T2SwapCellKiller<3>;
123
124// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
AbstractCellPopulation< SPACE_DIM > * mpCellPopulation
virtual void OutputCellKillerParameters(out_stream &rParamsFile)=0
double GetTime() const
static SimulationTime * Instance()
T2SwapCellKiller(AbstractCellPopulation< DIM > *pCellPopulation)
void CheckAndLabelCellsForApoptosisOrDeath()
void OutputCellKillerParameters(out_stream &rParamsFile)