Chaste  Release::2017.1
CellPopulationAreaWriter.cpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 "CellPopulationAreaWriter.hpp"
37 #include "AbstractCellPopulation.hpp"
38 #include "MeshBasedCellPopulation.hpp"
39 #include "CaBasedCellPopulation.hpp"
40 #include "NodeBasedCellPopulation.hpp"
41 #include "PottsBasedCellPopulation.hpp"
42 #include "VertexBasedCellPopulation.hpp"
43 #include "ApoptoticCellProperty.hpp"
44 
45 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
47  : AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM>("cellpopulationareas.dat")
48 {
49 }
50 
51 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53 {
54  assert(SPACE_DIM==2 || SPACE_DIM==3); // LCOV_EXCL_LINE
55 
56  VertexMesh<ELEMENT_DIM, SPACE_DIM>* voronoi_tessellation = pCellPopulation->GetVoronoiTessellation();
57 
58  assert (voronoi_tessellation != nullptr);
59 
60  // Don't use the Voronoi tessellation to calculate the total area of the mesh because it gives huge areas for boundary cells
61  double total_area = static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((pCellPopulation->rGetMesh())).GetVolume();
62  double apoptotic_area = 0.0;
63 
64  // Loop over elements of mpVoronoiTessellation
65  for (typename VertexMesh<ELEMENT_DIM,SPACE_DIM>::VertexElementIterator elem_iter = voronoi_tessellation->GetElementIteratorBegin();
66  elem_iter != voronoi_tessellation->GetElementIteratorEnd();
67  ++elem_iter)
68  {
69  // Get index of this element in mpVoronoiTessellation
70  unsigned elem_index = elem_iter->GetIndex();
71 
72  // Get the index of the corresponding node in mrMesh
73  unsigned node_index = voronoi_tessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
74 
75  // Discount ghost nodes
76  if (!pCellPopulation->IsGhostNode(node_index))
77  {
78  // Get the cell corresponding to this node
79  CellPtr p_cell = pCellPopulation->GetCellUsingLocationIndex(node_index);
80 
81  // Only bother calculating the area/volume of apoptotic cells
82  bool cell_is_apoptotic = p_cell->HasCellProperty<ApoptoticCellProperty>();
83  if (cell_is_apoptotic)
84  {
85  double cell_volume = voronoi_tessellation->GetVolumeOfElement(elem_index);
86  apoptotic_area += cell_volume;
87  }
88  }
89  }
90  *this->mpOutStream << total_area << " " << apoptotic_area;
91 }
92 
93 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
95 {
96  EXCEPTION("CellPopulationAreaWriter cannot be used with a CaBasedCellPopulation");
97 }
98 
99 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
101 {
102  EXCEPTION("CellPopulationAreaWriter cannot be used with a NodeBasedCellPopulation");
103 }
104 
105 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
107 {
108  EXCEPTION("CellPopulationAreaWriter cannot be used with a PottsBasedCellPopulation");
109 }
110 
111 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
113 {
114  EXCEPTION("CellPopulationAreaWriter cannot be used with a VertexBasedCellPopulation");
115 }
116 
117 // Explicit instantiation
118 template class CellPopulationAreaWriter<1,1>;
119 template class CellPopulationAreaWriter<1,2>;
120 template class CellPopulationAreaWriter<2,2>;
121 template class CellPopulationAreaWriter<1,3>;
122 template class CellPopulationAreaWriter<2,3>;
123 template class CellPopulationAreaWriter<3,3>;
124 
126 // Declare identifier for the serializer
unsigned GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(unsigned elementIndex)
Definition: VertexMesh.cpp:497
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
#define EXCEPTION(message)
Definition: Exception.hpp:143
MutableMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
Definition: VertexMesh.hpp:668
virtual double GetVolumeOfElement(unsigned index)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
VertexMesh< ELEMENT_DIM, SPACE_DIM > * GetVoronoiTessellation()
VertexElementIterator GetElementIteratorEnd()
Definition: VertexMesh.hpp:675
virtual void Visit(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation)