Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
RadialCellDataDistributionWriter.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 "RadialCellDataDistributionWriter.hpp"
37#include "MeshBasedCellPopulation.hpp"
38#include "CaBasedCellPopulation.hpp"
39#include "NodeBasedCellPopulation.hpp"
40#include "PottsBasedCellPopulation.hpp"
41#include "VertexBasedCellPopulation.hpp"
42#include "ImmersedBoundaryCellPopulation.hpp"
43
44template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
46 : AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM>("radial_dist.dat"),
47 mVariableName(""),
48 mNumRadialBins(UNSIGNED_UNSET)
49{
50}
51
52template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
54{
55 // Calculate the centre of the cell population
56 c_vector<double, SPACE_DIM> centre = pCellPopulation->GetCentroidOfCellPopulation();
57
58 // Calculate the distance between each node and the centre of the cell population, as well as the maximum of these
59 std::map<double, CellPtr> radius_cell_map;
60 double max_distance_from_centre = 0.0;
61 for (typename AbstractCellPopulation<SPACE_DIM, SPACE_DIM>::Iterator cell_iter = pCellPopulation->Begin();
62 cell_iter != pCellPopulation->End();
63 ++cell_iter)
64 {
65 double distance = norm_2(pCellPopulation->GetLocationOfCellCentre(*cell_iter) - centre);
66 radius_cell_map[distance] = *cell_iter;
67
68 if (distance > max_distance_from_centre)
69 {
70 max_distance_from_centre = distance;
71 }
72 }
73
74 // Create vector of radius intervals
75 std::vector<double> radius_intervals;
76 for (unsigned i=0; i<mNumRadialBins; i++)
77 {
78 double upper_radius = max_distance_from_centre*((double) i+1)/((double) mNumRadialBins);
79 radius_intervals.push_back(upper_radius);
80 }
81
82 // Calculate PDE solution in each radial interval
83 double lower_radius = 0.0;
84 for (unsigned i=0; i<mNumRadialBins; i++)
85 {
86 unsigned counter = 0;
87 double average_solution = 0.0;
88
89 for (std::map<double, CellPtr>::iterator iter = radius_cell_map.begin(); iter != radius_cell_map.end(); ++iter)
90 {
91 if (iter->first > lower_radius && iter->first <= radius_intervals[i])
92 {
93 average_solution += (iter->second)->GetCellData()->GetItem(mVariableName);
94 counter++;
95 }
96 }
97 if (counter != 0)
98 {
99 average_solution /= (double) counter;
100 }
101
102 // Write results to file
103 *this->mpOutStream << radius_intervals[i] << " " << average_solution << " ";
104 lower_radius = radius_intervals[i];
105 }
106}
107
108template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
110{
111 // Calculate the centre of the cell population
112 c_vector<double, SPACE_DIM> centre = pCellPopulation->GetCentroidOfCellPopulation();
113
114 // Calculate the distance between each node and the centre of the cell population, as well as the maximum of these
115 std::map<double, CellPtr> radius_cell_map;
116 double max_distance_from_centre = 0.0;
117 for (typename AbstractCellPopulation<ELEMENT_DIM, SPACE_DIM>::Iterator cell_iter = pCellPopulation->Begin();
118 cell_iter != pCellPopulation->End();
119 ++cell_iter)
120 {
121 double distance = norm_2(pCellPopulation->GetLocationOfCellCentre(*cell_iter) - centre);
122 radius_cell_map[distance] = *cell_iter;
123
124 if (distance > max_distance_from_centre)
125 {
126 max_distance_from_centre = distance;
127 }
128 }
129
130 // Create vector of radius intervals
131 std::vector<double> radius_intervals;
132 for (unsigned i=0; i<mNumRadialBins; i++)
133 {
134 double upper_radius = max_distance_from_centre*((double) i+1)/((double) mNumRadialBins);
135 radius_intervals.push_back(upper_radius);
136 }
137
138 // Calculate PDE solution in each radial interval
139 double lower_radius = 0.0;
140 for (unsigned i=0; i<mNumRadialBins; i++)
141 {
142 unsigned counter = 0;
143 double average_solution = 0.0;
144
145 for (std::map<double, CellPtr>::iterator iter = radius_cell_map.begin(); iter != radius_cell_map.end(); ++iter)
146 {
147 if (iter->first > lower_radius && iter->first <= radius_intervals[i])
148 {
149 average_solution += (iter->second)->GetCellData()->GetItem(mVariableName);
150 counter++;
151 }
152 }
153 if (counter != 0)
154 {
155 average_solution /= (double) counter;
156 }
157
158 // Write results to file
159 *this->mpOutStream << radius_intervals[i] << " " << average_solution << " ";
160 lower_radius = radius_intervals[i];
161 }
162}
163
164template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
166{
167 VisitAnyPopulation(pCellPopulation);
168}
169
170template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
172{
173 VisitAnyPopulation(pCellPopulation);
174}
175
176template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
178{
179 VisitAnyPopulation(pCellPopulation);
180}
181
182template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
184{
185 VisitAnyPopulation(pCellPopulation);
186}
187
188template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
190{
191 VisitAnyPopulation(pCellPopulation);
192}
193
194
195template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
197{
198 mVariableName = variableName;
199}
200
201template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
203{
204 return mVariableName;
205}
206
207template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
209{
210 mNumRadialBins = numRadialBins;
211}
212
213template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
215{
216 return mNumRadialBins;
217}
218
219// Explicit instantiation
226
228// Declare identifier for the serializer
230
const unsigned UNSIGNED_UNSET
Definition Exception.hpp:53
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)=0
c_vector< double, SPACE_DIM > GetCentroidOfCellPopulation()
c_vector< double, SPACE_DIM > GetLocationOfCellCentre(CellPtr pCell)
void VisitAnyPopulation(AbstractCellPopulation< SPACE_DIM, SPACE_DIM > *pCellPopulation)
virtual void Visit(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation)