Chaste  Release::3.4
CellPopulationAreaWriter.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 "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 
44 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
46  : AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM>("cellpopulationareas.dat")
47 {
48 }
49 
50 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
52 {
53  assert(SPACE_DIM==2 || SPACE_DIM==3);
54 
55  VertexMesh<ELEMENT_DIM, SPACE_DIM>* voronoi_tessellation = pCellPopulation->GetVoronoiTessellation();
56 
57  assert (voronoi_tessellation != NULL);
58 
59  // Don't use the Voronoi tessellation to calculate the total area of the mesh because it gives huge areas for boundary cells
60  double total_area = static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((pCellPopulation->rGetMesh())).GetVolume();
61  double apoptotic_area = 0.0;
62 
63  // Loop over elements of mpVoronoiTessellation
64  for (typename VertexMesh<ELEMENT_DIM,SPACE_DIM>::VertexElementIterator elem_iter = voronoi_tessellation->GetElementIteratorBegin();
65  elem_iter != voronoi_tessellation->GetElementIteratorEnd();
66  ++elem_iter)
67  {
68  // Get index of this element in mpVoronoiTessellation
69  unsigned elem_index = elem_iter->GetIndex();
70 
71  // Get the index of the corresponding node in mrMesh
72  unsigned node_index = voronoi_tessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
73 
74  // Discount ghost nodes
75  if (!pCellPopulation->IsGhostNode(node_index))
76  {
77  // Get the cell corresponding to this node
78  CellPtr p_cell = pCellPopulation->GetCellUsingLocationIndex(node_index);
79 
80  // Only bother calculating the area/volume of apoptotic cells
81  bool cell_is_apoptotic = p_cell->HasCellProperty<ApoptoticCellProperty>();
82  if (cell_is_apoptotic)
83  {
84  double cell_volume = voronoi_tessellation->GetVolumeOfElement(elem_index);
85  apoptotic_area += cell_volume;
86  }
87  }
88  }
89  *this->mpOutStream << total_area << " " << apoptotic_area;
90 }
91 
92 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
94 {
95 }
96 
97 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
99 {
100 }
101 
102 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
104 {
105 }
106 
107 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
109 {
110 }
111 
112 // Explicit instantiation
113 template class CellPopulationAreaWriter<1,1>;
114 template class CellPopulationAreaWriter<1,2>;
115 template class CellPopulationAreaWriter<2,2>;
116 template class CellPopulationAreaWriter<1,3>;
117 template class CellPopulationAreaWriter<2,3>;
118 template class CellPopulationAreaWriter<3,3>;
119 
121 // Declare identifier for the serializer
unsigned GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(unsigned elementIndex)
Definition: VertexMesh.cpp:506
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
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)