Chaste  Release::3.4
T2SwapCellKiller.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "T2SwapCellKiller.hpp"
37 
38 template<unsigned DIM>
40  : AbstractCellKiller<DIM>(pCellPopulation)
41 {
42  // Throw an exception if the population is not a VertexBasedCellPopulation
43  if (dynamic_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation) == NULL)
44  {
45  EXCEPTION("A T2SwapCellKiller should only be used together with a VertexBasedCellPopulation.");
46  }
47 }
48 
49 template<unsigned DIM>
51 {
52  /*
53  * This killer is different to other killers: it does not only check and label
54  * cells for apoptosis or death, it actually carries out vertex rearrangements
55  * and removes elements from the vertex mesh.
56  *
57  * We start with carrying out T2 swaps. Get the mesh and an element map.
58  * The static_cast will work since we already know it's a VertexBasedCellPopulation.
59  */
60  MutableVertexMesh<DIM,DIM>& mesh = static_cast<MutableVertexMesh<DIM,DIM>&>(this->mpCellPopulation->rGetMesh());
61  VertexBasedCellPopulation<DIM>* p_vertex_population = static_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation);
62  VertexElementMap element_map(mesh.GetNumAllElements());
63 
64  bool recheck_mesh = true;
65  while (recheck_mesh == true)
66  {
67  // Note that whenever we call CheckForT2Swaps(), the element indices must run from zero up to mElements.size()-1
68  recheck_mesh = mesh.CheckForT2Swaps(element_map);
69  /*
70  * There might have maximally one T2 swap happened above, where a vertex element was removed from the
71  * mesh but the associated cell is still there. Here we check whether a new cell
72  * underwent a T2 swap and label it as dead as well as record its location and ID.
73  */
74  for (unsigned elem_index = 0; elem_index < element_map.Size(); elem_index++)
75  {
76  CellPtr p_cell = this->mpCellPopulation->GetCellUsingLocationIndex(elem_index);
77  if (element_map.IsDeleted(elem_index) && !(p_cell->IsDead()))
78  {
79  p_vertex_population->AddLocationOfT2Swap(mesh.GetLastT2SwapLocation());
80  p_vertex_population->AddCellIdOfT2Swap(p_cell->GetCellId());
81  p_cell->Kill();
82 
83  // There can't have been more than one new cell death, so leave the for loop here.
84  break;
85  }
86  }
87  }
88 
89 }
90 
91 template<unsigned DIM>
93 {
94  // No parameters to output, so just call method on direct parent class
96 }
97 
98 // Explicit instantiation
99 template class T2SwapCellKiller<1>;
100 template class T2SwapCellKiller<2>;
101 template class T2SwapCellKiller<3>;
102 
103 // Serialization for Boost >= 1.36
T2SwapCellKiller(AbstractCellPopulation< DIM > *pCellPopulation)
void OutputCellKillerParameters(out_stream &rParamsFile)
void CheckAndLabelCellsForApoptosisOrDeath()
bool CheckForT2Swaps(VertexElementMap &rElementMap)
unsigned GetNumAllElements() const
Definition: VertexMesh.cpp:625
#define EXCEPTION(message)
Definition: Exception.hpp:143
AbstractCellPopulation< SPACE_DIM > * mpCellPopulation
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputCellKillerParameters(out_stream &rParamsFile)=0
c_vector< double, SPACE_DIM > GetLastT2SwapLocation()