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