Chaste  Build::
VesselNode.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 <boost/weak_ptr.hpp>
37 #include "Exception.hpp"
38 #include "VesselNode.hpp"
39 
40 template<unsigned DIM>
41 VesselNode<DIM>::VesselNode(double v1, double v2, double v3, units::quantity<unit::length> referenceLength) : AbstractVesselNetworkComponent<DIM>(),
42  mLocation(DimensionalChastePoint<DIM>(v1 ,v2, v3, referenceLength)),
43  mSegments(std::vector<boost::weak_ptr<VesselSegment<DIM> > >()),
44  mIsMigrating(false),
45  mpFlowProperties(boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>())),
46  mPtrComparisonId(0)
47 {
48  this->mpFlowProperties = boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>());
49 }
50 
51 template<unsigned DIM>
52 VesselNode<DIM>::VesselNode(double v1, double v2, double v3) : AbstractVesselNetworkComponent<DIM>(),
53  mLocation(DimensionalChastePoint<DIM>(v1 ,v2, v3)),
54  mSegments(std::vector<boost::weak_ptr<VesselSegment<DIM> > >()),
55  mIsMigrating(false),
56  mpFlowProperties(boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>())),
58 {
59  this->mpFlowProperties = boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>());
60 }
61 
62 template<unsigned DIM>
64  mLocation(location),
65  mSegments(std::vector<boost::weak_ptr<VesselSegment<DIM> > >()),
66  mIsMigrating(false),
67  mpFlowProperties(boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>())),
69 {
70  this->mpFlowProperties = boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>());
71 }
72 
73 template<unsigned DIM>
75  boost::enable_shared_from_this<VesselNode<DIM> >(), AbstractVesselNetworkComponent<DIM>(),
76  mLocation(rExistingNode.rGetLocation()),
77  mSegments(std::vector<boost::weak_ptr<VesselSegment<DIM> > >()),
78  mIsMigrating(false),
79  mpFlowProperties(boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>())),
81 {
82  SetFlowProperties(*(rExistingNode.GetFlowProperties()));
83  mIsMigrating = rExistingNode.IsMigrating();
84 }
85 
86 
87 template<unsigned DIM>
89 {
90 }
91 
92 template<unsigned DIM>
93 boost::shared_ptr<VesselNode<DIM> > VesselNode<DIM>::Create(double v1, double v2, double v3, units::quantity<unit::length> referenceLength)
94 {
95  MAKE_PTR_ARGS(VesselNode<DIM>, pSelf, (v1, v2, v3, referenceLength));
96  return pSelf;
97 }
98 
99 template<unsigned DIM>
100 boost::shared_ptr<VesselNode<DIM> > VesselNode<DIM>::Create(double v1, double v2, double v3)
101 {
102  MAKE_PTR_ARGS(VesselNode<DIM>, pSelf, (v1, v2, v3));
103  return pSelf;
104 }
105 
106 template<unsigned DIM>
107 boost::shared_ptr<VesselNode<DIM> > VesselNode<DIM>::Create(const DimensionalChastePoint<DIM>& location)
108 {
109  MAKE_PTR_ARGS(VesselNode<DIM>, pSelf, (location));
110  return pSelf;
111 }
112 
113 template<unsigned DIM>
114 boost::shared_ptr<VesselNode<DIM> > VesselNode<DIM>::Create(const VesselNode<DIM>& rExistingNode)
115 {
116  MAKE_PTR_ARGS(VesselNode<DIM>, pSelf, (rExistingNode));
117  return pSelf;
118 }
119 
120 template<unsigned DIM>
121 boost::shared_ptr<VesselNode<DIM> > VesselNode<DIM>::Create(boost::shared_ptr<VesselNode<DIM> > pExistingNode)
122 {
123  if(!pExistingNode)
124  {
125  EXCEPTION("A Null pointer cannot be used when copying nodes.");
126  }
127  MAKE_PTR_ARGS(VesselNode<DIM>, pSelf, (*pExistingNode));
128  return pSelf;
129 }
130 
131 template<unsigned DIM>
132 void VesselNode<DIM>::AddSegment(boost::shared_ptr<VesselSegment<DIM> > pVesselSegment)
133 {
134  // Vessel segments can only be attached to a node once. Note use of lock to get shared_ptr from
135  // weak_ptr.
136  for (unsigned idx = 0; idx < mSegments.size(); idx++)
137  {
138  if (mSegments[idx].lock() == pVesselSegment)
139  {
140  EXCEPTION("This segment is already attached to this node.");
141  }
142  }
143  mSegments.push_back(boost::weak_ptr<VesselSegment<DIM> >(pVesselSegment));
144 }
145 
146 template<unsigned DIM>
148 {
149  return mPtrComparisonId;
150 }
151 
152 template<unsigned DIM>
153 units::quantity<unit::length> VesselNode<DIM>::GetDistance(const DimensionalChastePoint<DIM>& rLocation) const
154 {
155  return mLocation.GetDistance(rLocation);
156 }
157 
158 template<unsigned DIM>
159 boost::shared_ptr<NodeFlowProperties<DIM> > VesselNode<DIM>::GetFlowProperties() const
160 {
161  return this->mpFlowProperties;
162 }
163 
164 template<unsigned DIM>
166 {
167  return mLocation;
168 }
169 
170 template<unsigned DIM>
172 {
173  return mSegments.size();
174 }
175 
176 template<unsigned DIM>
177 std::map<std::string, double> VesselNode<DIM>::GetOutputData()
178 {
179  this->mOutputData.clear();
180  std::map<std::string, double> flow_data = this->mpFlowProperties->GetOutputData();
181  this->mOutputData.insert(flow_data.begin(), flow_data.end());
182  this->mOutputData["Node Id"] = double(this->GetId());
183  this->mOutputData["Node Radius m"] = this->GetRadius() / unit::metres;
184  this->mOutputData["Node Is Migrating"] = double(this->IsMigrating());
185  return this->mOutputData;
186 }
187 
188 template<unsigned DIM>
189 units::quantity<unit::length> VesselNode<DIM>::GetReferenceLengthScale() const
190 {
191  return mLocation.GetReferenceLengthScale();
192 }
193 
194 template<unsigned DIM>
195 boost::shared_ptr<VesselSegment<DIM> > VesselNode<DIM>::GetSegment(unsigned index) const
196 {
197  if(index >= mSegments.size())
198  {
199  EXCEPTION("Requested segment index out of range");
200  }
201  else
202  {
203  // Convert to shared ptr from weak ptr
204  return mSegments[index].lock();
205  }
206 }
207 
208 template<unsigned DIM>
209 std::vector<boost::shared_ptr<VesselSegment<DIM> > > VesselNode<DIM>::GetSegments() const
210 {
211  // Need to do it this way because of weak pointers, can't just return mSegments
212  std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments(mSegments.size());
213  for(unsigned idx=0; idx<segments.size(); idx++)
214  {
215  segments[idx] = mSegments[idx].lock();
216  }
217  return segments;
218 }
219 
220 template<unsigned DIM>
221 bool VesselNode<DIM>::IsAttachedTo(const boost::shared_ptr<VesselSegment<DIM> > pSegment) const
222 {
223  // Need to get shared ptr from current node to allow for comparison
224  return (pSegment->GetNode(0) == this->shared_from_this() || pSegment->GetNode(1) == this->shared_from_this());
225 }
226 
227 template<unsigned DIM>
229 {
230  return this->mLocation.IsCoincident(rLocation);
231 }
232 
233 template<unsigned DIM>
235 {
236  return mIsMigrating;
237 }
238 
239 template<unsigned DIM>
240 void VesselNode<DIM>::RemoveSegment(boost::shared_ptr<VesselSegment<DIM> > pVesselSegment)
241 {
242  // Need to do it this way due to weak pointer use
243  for (unsigned idx = 0; idx < mSegments.size(); idx++)
244  {
245  if (mSegments[idx].lock() == pVesselSegment)
246  {
247  mSegments.erase(mSegments.begin() + idx);
248  break;
249  }
250  }
251 }
252 
253 template<unsigned DIM>
255 {
256  mPtrComparisonId = id;
257 }
258 
259 template<unsigned DIM>
261 {
262  this->mpFlowProperties = boost::shared_ptr<NodeFlowProperties<DIM> >(new NodeFlowProperties<DIM>(rFlowProperties));
263 }
264 
265 template<unsigned DIM>
267 {
268  this->mLocation = DimensionalChastePoint<DIM>(location);
269 }
270 
271 template<unsigned DIM>
272 void VesselNode<DIM>::SetLocation(double x, double y, double z, units::quantity<unit::length> referenceLength)
273 {
274  this->mLocation = DimensionalChastePoint<DIM>(x,y,z,referenceLength);
275 }
276 
277 template<unsigned DIM>
278 void VesselNode<DIM>::SetIsMigrating(bool isMigrating)
279 {
280  mIsMigrating = isMigrating;
281 }
282 
283 template<unsigned DIM>
284 void VesselNode<DIM>::SetReferenceLengthScale(units::quantity<unit::length> lengthScale)
285 {
286  this->mLocation.SetReferenceLengthScale(lengthScale);
287 }
288 
289 // Explicit instantiation
290 template class VesselNode<2>;
291 template class VesselNode<3>;
292 
293 #include "SerializationExportWrapperForCpp.hpp"
294 EXPORT_TEMPLATE_CLASS1(VesselNode, 2)
295 EXPORT_TEMPLATE_CLASS1(VesselNode, 3)
bool IsCoincident(const DimensionalChastePoint< DIM > &rLocation) const
Definition: VesselNode.cpp:228
unsigned GetNumberOfSegments() const
Definition: VesselNode.cpp:171
static boost::shared_ptr< VesselNode< DIM > > Create(double v1=0.0, double v2=0.0, double v3=0.0)
Definition: VesselNode.cpp:100
DimensionalChastePoint< DIM > mLocation
Definition: VesselNode.hpp:98
void SetComparisonId(unsigned id)
Definition: VesselNode.cpp:254
bool IsMigrating() const
Definition: VesselNode.cpp:234
unsigned GetComparisonId()
Definition: VesselNode.cpp:147
void SetLocation(const DimensionalChastePoint< DIM > &rLocation)
Definition: VesselNode.cpp:266
bool IsAttachedTo(const boost::shared_ptr< VesselSegment< DIM > > pSegment) const
Definition: VesselNode.cpp:221
void RemoveSegment(boost::shared_ptr< VesselSegment< DIM > > pVesselSegment)
Definition: VesselNode.cpp:240
units::quantity< unit::length > GetDistance(const DimensionalChastePoint< DIM > &rLocation) const
Definition: VesselNode.cpp:153
std::vector< boost::shared_ptr< VesselSegment< DIM > > > GetSegments() const
Definition: VesselNode.cpp:209
boost::shared_ptr< NodeFlowProperties< DIM > > mpFlowProperties
Definition: VesselNode.hpp:113
void AddSegment(boost::shared_ptr< VesselSegment< DIM > > pVesselSegment)
Definition: VesselNode.cpp:132
bool mIsMigrating
Definition: VesselNode.hpp:108
std::map< std::string, double > mOutputData
boost::shared_ptr< NodeFlowProperties< DIM > > GetFlowProperties() const
Definition: VesselNode.cpp:159
std::map< std::string, double > GetOutputData()
Definition: VesselNode.cpp:177
VesselNode(double v1, double v2, double v3, units::quantity< unit::length > referenceLength)
Definition: VesselNode.cpp:41
const DimensionalChastePoint< DIM > & rGetLocation() const
Definition: VesselNode.cpp:165
units::quantity< unit::length > GetReferenceLengthScale() const
Definition: VesselNode.cpp:189
unsigned mPtrComparisonId
Definition: VesselNode.hpp:119
void SetReferenceLengthScale(units::quantity< unit::length > lenthScale)
Definition: VesselNode.cpp:284
virtual units::quantity< unit::length > GetRadius() const
std::vector< boost::weak_ptr< VesselSegment< DIM > > > mSegments
Definition: VesselNode.hpp:103
void SetIsMigrating(bool isMigrating)
Definition: VesselNode.cpp:278
void SetFlowProperties(const NodeFlowProperties< DIM > &rFlowProperties)
Definition: VesselNode.cpp:260
boost::shared_ptr< VesselSegment< DIM > > GetSegment(unsigned index) const
Definition: VesselNode.cpp:195