Chaste  Build::
DiscreteSource.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 "DiscreteSource.hpp"
37 #include "AbstractCellPopulation.hpp"
38 #include "VesselNetwork.hpp"
39 #include "GeometryTools.hpp"
40 
41 template<unsigned DIM>
43  : mpRegularGrid(),
44  mpMesh(),
45  mPoints(),
46  mLabel("Default"),
47  mConstantInUValue(0.0*unit::mole_per_metre_cubed_per_second),
48  mLinearInUValue(0.0*unit::per_second)
49 {
50 
51 }
52 
53 template<unsigned DIM>
55 {
56 
57 }
58 
59 template<unsigned DIM>
60 boost::shared_ptr<DiscreteSource<DIM> > DiscreteSource<DIM>::Create()
61 {
62  MAKE_PTR(DiscreteSource<DIM>, pSelf);
63  return pSelf;
64 }
65 
66 template<unsigned DIM>
67 std::vector<units::quantity<unit::concentration_flow_rate> > DiscreteSource<DIM>::GetConstantInUMeshValues()
68 {
69  if(!mpMesh)
70  {
71  EXCEPTION("A mesh is required for this type of source");
72  }
73 
74  // Loop through all points
75  std::vector<units::quantity<unit::concentration_flow_rate> > values(mpMesh->GetNumElements(), 0.0*unit::mole_per_metre_cubed_per_second);
76  std::vector<std::vector<unsigned> > point_element_map = mpMesh->GetPointElementMap(mPoints);
77  for(unsigned idx=0; idx<point_element_map.size(); idx++)
78  {
79  values[idx] += mConstantInUValue * double(point_element_map[idx].size());
80  }
81  return values;
82 }
83 
84 template<unsigned DIM>
85 std::vector<units::quantity<unit::rate> > DiscreteSource<DIM>::GetLinearInUMeshValues()
86 {
87  if(!mpMesh)
88  {
89  EXCEPTION("A mesh is required for this type of source");
90  }
91 
92  // Loop through all points
93  std::vector<units::quantity<unit::rate> > values(mpMesh->GetNumElements(), 0.0*unit::per_second);
94  std::vector<std::vector<unsigned> > point_element_map = mpMesh->GetPointElementMap(mPoints);
95  for(unsigned idx=0; idx<point_element_map.size(); idx++)
96  {
97  values[idx] += mLinearInUValue * double(point_element_map[idx].size());
98  }
99  return values;
100 }
101 
102 template<unsigned DIM>
103 std::vector<units::quantity<unit::concentration_flow_rate> > DiscreteSource<DIM>::GetConstantInURegularGridValues()
104 {
105  if(!mpRegularGrid)
106  {
107  EXCEPTION("A regular grid is required for this type of source");
108  }
109 
110  if(mPoints.size()==0)
111  {
112  EXCEPTION("A point is required for this type of source");
113  }
114 
115  // Loop through all points
116  std::vector<units::quantity<unit::concentration_flow_rate> > values(mpRegularGrid->GetNumberOfPoints(), 0.0*unit::mole_per_metre_cubed_per_second);
117  std::vector<std::vector<unsigned> > point_point_map = mpRegularGrid->GetPointPointMap(mPoints);
118  for(unsigned idx=0; idx<point_point_map.size(); idx++)
119  {
120  values[idx] += mConstantInUValue * double(point_point_map[idx].size());
121  }
122  return values;
123 }
124 
125 template<unsigned DIM>
126 std::vector<units::quantity<unit::rate> > DiscreteSource<DIM>::GetLinearInURegularGridValues()
127 {
128  if(!mpRegularGrid)
129  {
130  EXCEPTION("A regular grid is required for this type of source");
131  }
132 
133  if(mPoints.size()==0)
134  {
135  EXCEPTION("A point is required for this type of source");
136  }
137 
138  // Loop through all points
139  std::vector<units::quantity<unit::rate> > values(mpRegularGrid->GetNumberOfPoints(), 0.0*unit::per_second);
140  std::vector<std::vector<unsigned> > point_point_map = mpRegularGrid->GetPointPointMap(mPoints);
141  for(unsigned idx=0; idx<point_point_map.size(); idx++)
142  {
143  values[idx] += mLinearInUValue * double(point_point_map[idx].size());
144  }
145  return values;
146 }
147 
148 template<unsigned DIM>
149 void DiscreteSource<DIM>::SetLabelName(const std::string& label)
150 {
151  mLabel = label;
152 }
153 
154 template<unsigned DIM>
156 {
157  mPoints = points;
158 }
159 
160 template<unsigned DIM>
162 {
163  mpMesh = pMesh;
164 }
165 
166 template<unsigned DIM>
167 void DiscreteSource<DIM>::SetRegularGrid(boost::shared_ptr<RegularGrid<DIM> > pRegularGrid)
168 {
169  mpRegularGrid = pRegularGrid;
170 }
171 
172 template<unsigned DIM>
173 void DiscreteSource<DIM>::SetConstantInUValue(units::quantity<unit::concentration_flow_rate> value)
174 {
175  mConstantInUValue = value;
176 }
177 
178 template<unsigned DIM>
179 void DiscreteSource<DIM>::SetLinearInUValue(units::quantity<unit::rate> value)
180 {
181  mLinearInUValue = value;
182 }
183 
184 // Explicit instantiation
185 template class DiscreteSource<2>;
186 template class DiscreteSource<3>;
void SetConstantInUValue(units::quantity< unit::concentration_flow_rate > value)
void SetLinearInUValue(units::quantity< unit::rate > value)
virtual ~DiscreteSource()
void SetPoints(std::vector< DimensionalChastePoint< DIM > > points)
void SetLabelName(const std::string &rLabel)
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
std::vector< DimensionalChastePoint< DIM > > mPoints
units::quantity< unit::rate > mLinearInUValue
virtual std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInURegularGridValues()
std::string mLabel
virtual std::vector< units::quantity< unit::rate > > GetLinearInURegularGridValues()
virtual std::vector< units::quantity< unit::concentration_flow_rate > > GetConstantInUMeshValues()
void SetMesh(boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > pMesh)
units::quantity< unit::concentration_flow_rate > mConstantInUValue
static boost::shared_ptr< DiscreteSource< DIM > > Create()
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > mpMesh
void SetRegularGrid(boost::shared_ptr< RegularGrid< DIM > > pRegularGrid)
virtual std::vector< units::quantity< unit::rate > > GetLinearInUMeshValues()