Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
CellPopulationAreaWriter.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 "CellPopulationAreaWriter.hpp"
37
38#include "AbstractCellPopulation.hpp"
39#include "MeshBasedCellPopulation.hpp"
40#include "CaBasedCellPopulation.hpp"
41#include "NodeBasedCellPopulation.hpp"
42#include "PottsBasedCellPopulation.hpp"
43#include "VertexBasedCellPopulation.hpp"
44#include "ImmersedBoundaryCellPopulation.hpp"
45
46#include "ApoptoticCellProperty.hpp"
47
48template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53
54template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
56 [[maybe_unused]] MeshBasedCellPopulation<ELEMENT_DIM, SPACE_DIM>* pCellPopulation) // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9
57{
58 if constexpr ((SPACE_DIM == 2) || (SPACE_DIM == 3))
59 {
60 VertexMesh<ELEMENT_DIM, SPACE_DIM>* voronoi_tessellation = pCellPopulation->GetVoronoiTessellation();
61
62 assert(voronoi_tessellation != nullptr);
63
64 // Don't use the Voronoi tessellation to calculate the total area of the mesh because it gives huge areas for boundary cells
65 double total_area = static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((pCellPopulation->rGetMesh())).GetVolume();
66 double apoptotic_area = 0.0;
67
68 // Loop over elements of mpVoronoiTessellation
69 for (typename VertexMesh<ELEMENT_DIM,SPACE_DIM>::VertexElementIterator elem_iter = voronoi_tessellation->GetElementIteratorBegin();
70 elem_iter != voronoi_tessellation->GetElementIteratorEnd();
71 ++elem_iter)
72 {
73 // Get index of this element in mpVoronoiTessellation
74 unsigned elem_index = elem_iter->GetIndex();
75
76 // Get the index of the corresponding node in mrMesh
77 unsigned node_index = voronoi_tessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
78
79 // Discount ghost nodes
80 if (!pCellPopulation->IsGhostNode(node_index))
81 {
82 // Get the cell corresponding to this node
83 CellPtr p_cell = pCellPopulation->GetCellUsingLocationIndex(node_index);
84
85 // Only bother calculating the area/volume of apoptotic cells
86 bool cell_is_apoptotic = p_cell->HasCellProperty<ApoptoticCellProperty>();
87 if (cell_is_apoptotic)
88 {
89 double cell_volume = voronoi_tessellation->GetVolumeOfElement(elem_index);
90 apoptotic_area += cell_volume;
91 }
92 }
93 }
94 *this->mpOutStream << total_area << " " << apoptotic_area;
95 }
96 else
97 {
99 }
100}
101
102template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
104{
105 EXCEPTION("CellPopulationAreaWriter cannot be used with a CaBasedCellPopulation");
106}
107
108template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
110{
111 EXCEPTION("CellPopulationAreaWriter cannot be used with a NodeBasedCellPopulation");
112}
113
114template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
116{
117 EXCEPTION("CellPopulationAreaWriter cannot be used with a PottsBasedCellPopulation");
118}
119
120template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
122{
123 EXCEPTION("CellPopulationAreaWriter cannot be used with a VertexBasedCellPopulation");
124}
125
126template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
128{
129 EXCEPTION("CellPopulationAreaWriter cannot be used with a ImmersedBoundaryCellPopulation");
130}
131
132// Explicit instantiation
133template class CellPopulationAreaWriter<1,1>;
134template class CellPopulationAreaWriter<1,2>;
135template class CellPopulationAreaWriter<2,2>;
136template class CellPopulationAreaWriter<1,3>;
137template class CellPopulationAreaWriter<2,3>;
138template class CellPopulationAreaWriter<3,3>;
139
141// Declare identifier for the serializer
#define EXCEPTION(message)
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual void Visit(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation)
VertexElementIterator GetElementIteratorEnd()
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
unsigned GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(unsigned elementIndex)
virtual double GetVolumeOfElement(unsigned index)