Chaste  Build::
CellStateDependentDiscreteSource.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 "CellStateDependentDiscreteSource.hpp"
37 #include "AbstractCellPopulation.hpp"
38 #include "VesselNetwork.hpp"
39 
40 template<unsigned DIM>
42  : DiscreteSource<DIM>(),
43  mStateRateMap(),
44  mStateRateThresholdMap(),
45  mConsumptionRatePerUnitConcentration(1.0*unit::metre_cubed_per_second)
46 {
47 
48 }
49 
50 template<unsigned DIM>
52 {
53 
54 }
55 
56 template<unsigned DIM>
57 boost::shared_ptr<CellStateDependentDiscreteSource<DIM> > CellStateDependentDiscreteSource<DIM>::Create()
58 {
60  return pSelf;
61 }
62 
63 template<unsigned DIM>
64 std::vector<units::quantity<unit::concentration_flow_rate> > CellStateDependentDiscreteSource<DIM>::GetConstantInUMeshValues()
65 {
66  EXCEPTION("This source does not yet support meshes.");
67 }
68 
69 template<unsigned DIM>
70 std::vector<units::quantity<unit::rate> > CellStateDependentDiscreteSource<DIM>::GetLinearInUMeshValues()
71 {
72  EXCEPTION("This source does not yet support meshes.");
73 }
74 
75 template<unsigned DIM>
76 std::vector<units::quantity<unit::concentration_flow_rate> > CellStateDependentDiscreteSource<DIM>::GetConstantInURegularGridValues()
77 {
78  if(!this->mpRegularGrid)
79  {
80  EXCEPTION("A regular grid is required for this type of source");
81  }
82 
83 // units::quantity<unit::length> grid_spacing = this->mpRegularGrid->GetSpacing();
84 // units::quantity<unit::volume> grid_volume = units::pow<3>(grid_spacing);
85  std::vector<units::quantity<unit::concentration_flow_rate> > values(this->mpRegularGrid->GetNumberOfPoints(), 0.0*unit::mole_per_metre_cubed_per_second);
86 
87  boost::shared_ptr<ApoptoticCellProperty> apoptotic_property(new ApoptoticCellProperty);
88  unsigned apoptotic_label = apoptotic_property->GetColour();
89 
90  // Loop through all points
91  std::vector<std::vector<CellPtr> > point_cell_map = this->mpRegularGrid->GetPointCellMap();
92  for(unsigned idx=0; idx<point_cell_map.size(); idx++)
93  {
94  for(unsigned jdx=0; jdx<point_cell_map[idx].size(); jdx++)
95  {
96  // If a mutation specific consumption rate has been specified
97  if(mStateRateMap.size()>0)
98  {
99  std::map<unsigned, units::quantity<unit::concentration_flow_rate> >::iterator it;
100  // If the cell is apoptotic
101  if (point_cell_map[idx][jdx]->template HasCellProperty<ApoptoticCellProperty>())
102  {
103  it = mStateRateMap.find(apoptotic_label);
104  if (it != mStateRateMap.end())
105  {
106  values[idx] += it->second;
107  }
108  }
109  else
110  {
111  it = mStateRateMap.find(point_cell_map[idx][jdx]->GetMutationState()->GetColour());
112  if (it != mStateRateMap.end())
113  {
114  if(!this->mLabel.empty())
115  {
116  // Get a threshold value if it has been set, use the label to determine the field from which the label
117  // value is obtained.
118  units::quantity<unit::concentration> threshold = 0.0 * unit::mole_per_metre_cubed;
119  if(mStateRateThresholdMap.size()>0)
120  {
121  std::map<unsigned, units::quantity<unit::concentration> >::iterator it_threshold;
122  it_threshold = mStateRateThresholdMap.find(point_cell_map[idx][jdx]->GetMutationState()->GetColour());
123  if (it_threshold != mStateRateThresholdMap.end())
124  {
125  threshold = it_threshold->second;
126  }
127  }
128 // units::quantity<unit::concentration_flow_rate> conversion_factor = mConsumptionRatePerUnitConcentration*unit::mole_per_metre_cubed/grid_volume;
129 
130  if(threshold>0.0* unit::mole_per_metre_cubed)
131  {
132  if(point_cell_map[idx][jdx]->GetCellData()->GetItem(this->mLabel)>threshold.value())
133  {
134  values[idx] += it->second;
135  }
136  }
137  else
138  {
139  values[idx] += it->second;
140  }
141  }
142  else
143  {
144  values[idx] += it->second;
145  }
146  }
147  }
148  }
149  else
150  {
151  values[idx] += this->mConstantInUValue;
152  }
153  }
154  }
155  return values;
156 }
157 
158 template<unsigned DIM>
160 {
161  // This map is only for constant values
162  return std::vector<units::quantity<unit::rate> >(this->mpRegularGrid->GetNumberOfPoints(), 0.0*unit::per_second);
163 }
164 
165 template<unsigned DIM>
166 void CellStateDependentDiscreteSource<DIM>::SetStateRateMap(std::map<unsigned, units::quantity<unit::concentration_flow_rate> > stateRateMap)
167 {
168  mStateRateMap = stateRateMap;
169 }
170 
171 template<unsigned DIM>
172 void CellStateDependentDiscreteSource<DIM>::SetStateRateThresholdMap(std::map<unsigned, units::quantity<unit::concentration> > stateThresholdMap)
173 {
174  mStateRateThresholdMap = stateThresholdMap;
175 }
176 
177 // Explicit instantiation
std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInUMeshValues()
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
std::map< unsigned, units::quantity< unit::concentration > > mStateRateThresholdMap
void SetStateRateMap(std::map< unsigned, units::quantity< unit::concentration_flow_rate > > stateRateMap)
std::string mLabel
std::map< unsigned, units::quantity< unit::concentration_flow_rate > > mStateRateMap
std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInURegularGridValues()
static boost::shared_ptr< CellStateDependentDiscreteSource< DIM > > Create()
std::vector< units::quantity< unit::rate > > GetLinearInUMeshValues()
units::quantity< unit::concentration_flow_rate > mConstantInUValue
void SetStateRateThresholdMap(std::map< unsigned, units::quantity< unit::concentration > > stateThresholdMap)
std::vector< units::quantity< unit::rate > > GetLinearInURegularGridValues()