Chaste  Build::
CellBasedDiscreteSource.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 "CellBasedDiscreteSource.hpp"
37 #include "AbstractCellPopulation.hpp"
38 #include "VesselNetwork.hpp"
39 #include "GeometryTools.hpp"
40 #include "Element.hpp"
41 
42 template<unsigned DIM>
44  : DiscreteSource<DIM>(),
45  mCellConstantInUValue(0.0*unit::mole_per_second),
46  mCellLinearInUValue(0.0*unit::per_second)
47 {
48 
49 }
50 
51 template<unsigned DIM>
53 {
54 
55 }
56 
57 template<unsigned DIM>
58 boost::shared_ptr<CellBasedDiscreteSource<DIM> > CellBasedDiscreteSource<DIM>::Create()
59 {
60  MAKE_PTR(CellBasedDiscreteSource<DIM>, pSelf);
61  return pSelf;
62 }
63 
64 template<unsigned DIM>
65 std::vector<units::quantity<unit::concentration_flow_rate> > CellBasedDiscreteSource<DIM>::GetConstantInUMeshValues()
66 {
67  if(!this->mpMesh)
68  {
69  EXCEPTION("A mesh is required for this type of source");
70  }
71 
72  std::vector<units::quantity<unit::concentration_flow_rate> > values(this->mpMesh->GetNumElements(), 0.0*unit::mole_per_metre_cubed_per_second);
73  std::vector<std::vector<CellPtr> > element_cell_map = this->mpMesh->GetElementCellMap();
74  for(unsigned idx=0; idx<element_cell_map.size(); idx++)
75  {
76  Element<DIM, DIM>* p_element = this->mpMesh->GetElement(idx);
77  double determinant = 0.0;
78  c_matrix<double, DIM, DIM> jacobian;
79  p_element->CalculateJacobian(jacobian, determinant);
80  units::quantity<unit::volume> element_volume = p_element->GetVolume(determinant) * units::pow<3>(this->mpMesh->GetReferenceLengthScale());
81  values[idx] += mCellConstantInUValue * double(element_cell_map[idx].size())/element_volume;
82  }
83  return values;
84 }
85 
86 template<unsigned DIM>
87 std::vector<units::quantity<unit::rate> > CellBasedDiscreteSource<DIM>::GetLinearInUMeshValues()
88 {
89  if(!this->mpMesh)
90  {
91  EXCEPTION("A mesh is required for this type of source");
92  }
93  std::vector<units::quantity<unit::rate> > values(this->mpMesh->GetNumElements(), 0.0*unit::per_second);
94  std::vector<std::vector<CellPtr> > element_cell_map = this->mpMesh->GetElementCellMap();
95 
96  for(unsigned idx=0; idx<element_cell_map.size(); idx++)
97  {
98  values[idx] += mCellLinearInUValue * double(element_cell_map[idx].size());
99  }
100  return values;
101 }
102 
103 template<unsigned DIM>
104 std::vector<units::quantity<unit::concentration_flow_rate> > CellBasedDiscreteSource<DIM>::GetConstantInURegularGridValues()
105 {
106  if(!this->mpRegularGrid)
107  {
108  EXCEPTION("A regular grid is required for this type of source");
109  }
110 
111  std::vector<units::quantity<unit::concentration_flow_rate> > values(this->mpRegularGrid->GetNumberOfPoints(), 0.0*unit::mole_per_metre_cubed_per_second);
112  units::quantity<unit::length> grid_spacing = this->mpRegularGrid->GetSpacing();
113  units::quantity<unit::volume> grid_volume = units::pow<3>(grid_spacing);
114 
115  std::vector<std::vector<CellPtr> > point_cell_map = this->mpRegularGrid->GetPointCellMap();
116  for(unsigned idx=0; idx<point_cell_map.size(); idx++)
117  {
118  values[idx] += mCellConstantInUValue * double(point_cell_map[idx].size())/grid_volume;
119  }
120  return values;
121 
122 }
123 
124 template<unsigned DIM>
125 std::vector<units::quantity<unit::rate> > CellBasedDiscreteSource<DIM>::GetLinearInURegularGridValues()
126 {
127  if(!this->mpRegularGrid)
128  {
129  EXCEPTION("A regular grid is required for this type of source");
130  }
131 
132  std::vector<units::quantity<unit::rate> > values(this->mpRegularGrid->GetNumberOfPoints(), 0.0*unit::per_second);
133  std::vector<std::vector<CellPtr> > point_cell_map = this->mpRegularGrid->GetPointCellMap();
134  for(unsigned idx=0; idx<point_cell_map.size(); idx++)
135  {
136  values[idx] += mCellLinearInUValue * double(point_cell_map[idx].size());
137  }
138  return values;
139 }
140 
141 template<unsigned DIM>
142 void CellBasedDiscreteSource<DIM>::SetConstantInUConsumptionRatePerCell(units::quantity<unit::molar_flow_rate> value)
143 {
144  mCellConstantInUValue = -value;
145 }
146 
147 template<unsigned DIM>
149 {
150  mCellLinearInUValue = -value;
151 }
152 
153 // Explicit instantiation
154 template class CellBasedDiscreteSource<2>;
155 template class CellBasedDiscreteSource<3>;
std::vector< units::quantity< unit::rate > > GetLinearInUMeshValues()
static boost::shared_ptr< CellBasedDiscreteSource< DIM > > Create()
units::quantity< unit::rate > mCellLinearInUValue
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
void SetConstantInUConsumptionRatePerCell(units::quantity< unit::molar_flow_rate > value)
std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInUMeshValues()
std::vector< units::quantity< unit::rate > > GetLinearInURegularGridValues()
units::quantity< unit::molar_flow_rate > mCellConstantInUValue
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > mpMesh
std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInURegularGridValues()
void SetLinearInUConsumptionRatePerCell(units::quantity< unit::rate > value)