Chaste  Build::
VesselFlowProperties.cpp
1 /*
2 
3  Copyright (c) 2005-2015, 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 "VesselFlowProperties.hpp"
37 
38 template<unsigned DIM>
40  mSegments(),
41  mUndergoingRegression(false),
42  mRemoveViaRegression(false),
43  mRegressionTime(DBL_MAX*unit::seconds)
44 {
45 }
46 
47 template<unsigned DIM>
49 {
50 }
51 
52 template<unsigned DIM>
54 {
55  if(mSegments.size() == 0)
56  {
57  EXCEPTION("No vessel segments have been set for vessel flow property calculation.");
58  }
59 }
60 
61 template<unsigned DIM>
62 units::quantity<unit::dimensionless> VesselFlowProperties<DIM>::GetHaematocrit() const
63 {
64  this->CheckSegments();
65 
66  units::quantity<unit::dimensionless> value = 0.0;
67  for (unsigned i = 0; i < mSegments.size(); i++)
68  {
69  value += mSegments[i]->GetFlowProperties()->GetHaematocrit() / double(mSegments.size());
70  }
71  return value;
72 }
73 
74 template<unsigned DIM>
75 units::quantity<unit::flow_rate> VesselFlowProperties<DIM>::GetFlowRate() const
76 {
77  this->CheckSegments();
78 
79  units::quantity<unit::flow_rate> value = 0.0 * unit::metre_cubed_per_second;
80  for (unsigned i = 0; i < mSegments.size(); i++)
81  {
82  value += mSegments[i]->GetFlowProperties()->GetFlowRate() / double(mSegments.size());
83  }
84  return value;
85 }
86 
87 template<unsigned DIM>
88 units::quantity<unit::flow_impedance> VesselFlowProperties<DIM>::GetImpedance() const
89 {
90  this->CheckSegments();
91 
92  units::quantity<unit::flow_impedance> value = 0.0 * unit::pascal_second_per_metre_cubed;
93  for (unsigned i = 0; i < mSegments.size(); i++)
94  {
95  value += mSegments[i]->GetFlowProperties()->GetImpedance();
96  }
97  return value;
98 }
99 
100 template<unsigned DIM>
101 units::quantity<unit::dynamic_viscosity> VesselFlowProperties<DIM>::GetViscosity() const
102 {
103  this->CheckSegments();
104 
105  units::quantity<unit::dynamic_viscosity> value = 0.0 * unit::poiseuille;
106  for (unsigned i = 0; i < mSegments.size(); i++)
107  {
108  value += mSegments[i]->GetFlowProperties()->GetViscosity()/ double(mSegments.size());
109  }
110  return value;
111 }
112 
113 template<unsigned DIM>
114 units::quantity<unit::pressure> VesselFlowProperties<DIM>::GetWallShearStress() const
115 {
116  this->CheckSegments();
117 
118  units::quantity<unit::pressure> value = 0.0 * unit::pascals;
119  for (unsigned i = 0; i < mSegments.size(); i++)
120  {
121  value += mSegments[i]->GetFlowProperties()->GetWallShearStress()/ double(mSegments.size());
122  }
123  return value;
124 }
125 
126 template<unsigned DIM>
127 units::quantity<unit::rate> VesselFlowProperties<DIM>::GetGrowthStimulus() const
128 {
129  this->CheckSegments();
130 
131  units::quantity<unit::rate> value = 0.0 * unit::per_second;
132  for (unsigned i = 0; i < mSegments.size(); i++)
133  {
134  value += mSegments[i]->GetFlowProperties()->GetGrowthStimulus()/ double(mSegments.size());
135  }
136  return value;
137 }
138 
139 template<unsigned DIM>
140 std::map<std::string, double> VesselFlowProperties<DIM>::GetOutputData() const
141 {
142  std::map<std::string, double> output_data;
143  output_data["Vessel Impedance kg/m^4/s"] = this->GetImpedance() / unit::pascal_second_per_metre_cubed;
144  output_data["Vessel Haematocrit"] = this->GetHaematocrit();
145  output_data["Vessel Flow Rate m^3/s"] = this->GetFlowRate() / unit::metre_cubed_per_second;
146  output_data["Absolute Vessel Flow Rate m^3/s"] = fabs(this->GetFlowRate()) / unit::metre_cubed_per_second;
147  output_data["Vessel Viscosity Pa.s"] = this->GetViscosity() / unit::poiseuille;
148  output_data["Vessel Wall Shear Stress Pa"] = this->GetWallShearStress() / unit::pascals;
149  output_data["Vessel Growth Stimulus s^-1"] = this->GetGrowthStimulus() / unit::per_second;
150  output_data["Vessel Time Until Regression s"] = this->mRegressionTime / unit::seconds;
151  return output_data;
152 }
153 
154 template<unsigned DIM>
155 units::quantity<unit::time> VesselFlowProperties<DIM>::GetRegressionTime() const
156 {
157  return mRegressionTime;
158 }
159 
160 template<unsigned DIM>
161 bool VesselFlowProperties<DIM>::HasVesselRegressed(units::quantity<unit::time> simulationReferenceTime)
162 {
163  if (SimulationTime::Instance()->GetTime()*simulationReferenceTime >= this->mRegressionTime)
164  {
165  assert(mUndergoingRegression);
166  mRemoveViaRegression = true;
167  return mRemoveViaRegression;
168  }
169  else
170  {
171  mRemoveViaRegression = false;
172  return mRemoveViaRegression;
173  }
174 }
175 
176 template<unsigned DIM>
177 void VesselFlowProperties<DIM>::SetHaematocrit(units::quantity<unit::dimensionless> haematocrit)
178 {
179  this->CheckSegments();
180 
181  for (unsigned i = 0; i < mSegments.size(); i++)
182  {
183  mSegments[i]->GetFlowProperties()->SetHaematocrit(haematocrit);
184  }
185 }
186 
187 template<unsigned DIM>
188 void VesselFlowProperties<DIM>::SetFlowRate(units::quantity<unit::flow_rate> haematocrit)
189 {
190  this->CheckSegments();
191 
192  for (unsigned i = 0; i < mSegments.size(); i++)
193  {
194  mSegments[i]->GetFlowProperties()->SetFlowRate(haematocrit);
195  }
196 }
197 
198 
199 template<unsigned DIM>
200 void VesselFlowProperties<DIM>::SetImpedance(units::quantity<unit::flow_impedance> value)
201 {
202  this->CheckSegments();
203 
204  for (unsigned i = 0; i < mSegments.size(); i++)
205  {
206  mSegments[i]->GetFlowProperties()->SetImpedance(value/double(mSegments.size()));
207  }
208 }
209 
210 template<unsigned DIM>
211 void VesselFlowProperties<DIM>::SetViscosity(units::quantity<unit::dynamic_viscosity> value)
212 {
213  this->CheckSegments();
214 
215  for (unsigned i = 0; i < mSegments.size(); i++)
216  {
217  mSegments[i]->GetFlowProperties()->SetViscosity(value);
218  }
219 }
220 
221 template<unsigned DIM>
222 void VesselFlowProperties<DIM>::SetWallShearStress(units::quantity<unit::pressure> value)
223 {
224  this->CheckSegments();
225 
226  for (unsigned i = 0; i < mSegments.size(); i++)
227  {
228  mSegments[i]->GetFlowProperties()->SetWallShearStress(value);
229  }
230 }
231 
232 template<unsigned DIM>
233 void VesselFlowProperties<DIM>::SetGrowthStimulus(units::quantity<unit::rate> value)
234 {
235  this->CheckSegments();
236 
237  for (unsigned i = 0; i < mSegments.size(); i++)
238  {
239  mSegments[i]->GetFlowProperties()->SetGrowthStimulus(value);
240  }
241 }
242 
243 template<unsigned DIM>
244 void VesselFlowProperties<DIM>::SetTimeUntilRegression(units::quantity<unit::time> time, units::quantity<unit::time> simulationReferenceTime)
245 {
246  assert(!mRemoveViaRegression);
247 
249  {
250  EXCEPTION("SetTimeUntilRegression(time) called when already undergoing regression");
251  }
252 
253  mUndergoingRegression = true;
254  this->mRegressionTime = SimulationTime::Instance()->GetTime()*simulationReferenceTime + time;
255 }
256 
257 template<unsigned DIM>
258 void VesselFlowProperties<DIM>::SetRegressionTime(units::quantity<unit::time> time)
259 {
260  this->mRegressionTime = time;
261  if(time<DBL_MAX*unit::seconds)
262  {
263  mUndergoingRegression = true;
264  }
265 }
266 
267 template<unsigned DIM>
269 {
270  return mUndergoingRegression;
271 }
272 
273 template<unsigned DIM>
275 {
276  this->mRegressionTime = DBL_MAX*unit::seconds;
277  mUndergoingRegression = false;
278  mRemoveViaRegression = false;
279 }
280 
281 template<unsigned DIM>
282 void VesselFlowProperties<DIM>::UpdateSegments(std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments)
283 {
284  mSegments = segments;
285 }
286 
287 // Explicit instantiation
288 template class VesselFlowProperties<2> ;
289 template class VesselFlowProperties<3> ;
std::map< std::string, double > GetOutputData() const
void UpdateSegments(std::vector< boost::shared_ptr< VesselSegment< DIM > > > segments)
void SetWallShearStress(units::quantity< unit::pressure > wallShear)
void SetHaematocrit(units::quantity< unit::dimensionless > haematocrit)
units::quantity< unit::flow_impedance > GetImpedance() const
units::quantity< unit::pressure > GetWallShearStress() const
bool HasVesselRegressed(units::quantity< unit::time > simulationReferenceTime)
void SetGrowthStimulus(units::quantity< unit::rate > stimulus)
void SetTimeUntilRegression(units::quantity< unit::time > time, units::quantity< unit::time > simulationReferenceTime)
void SetViscosity(units::quantity< unit::dynamic_viscosity > viscosity)
void SetRegressionTime(units::quantity< unit::time > time)
units::quantity< unit::time > GetRegressionTime() const
units::quantity< unit::dimensionless > GetHaematocrit() const
std::vector< boost::shared_ptr< VesselSegment< DIM > > > mSegments
units::quantity< unit::time > mRegressionTime
units::quantity< unit::dynamic_viscosity > GetViscosity() const
units::quantity< unit::rate > GetGrowthStimulus() const
units::quantity< unit::flow_rate > GetFlowRate() const
void SetImpedance(units::quantity< unit::flow_impedance > impedance)
void SetFlowRate(units::quantity< unit::flow_rate > flowRate)