Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2006, 2007 INRIA |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: |
| 19 | */ |
| 20 | #ifndef SPRING_MOBILITY_MODEL_H |
| 21 | #define SPRING_MOBILITY_MODEL_H |
| 22 | |
| 23 | #include "ns3/mobility-model.h" |
| 24 | #include "ns3/nstime.h" |
| 25 | #include "ns3/event-id.h" |
| 26 | |
| 27 | namespace ns3 { |
| 28 | |
| 29 | /** |
| 30 | * \ingroup mobility |
| 31 | * |
| 32 | * \brief |
| 33 | */ |
| 34 | class SpringMobilityModel : public MobilityModel |
| 35 | { |
| 36 | public: |
| 37 | static TypeId GetTypeId (void); |
| 38 | |
| 39 | /** |
| 40 | * Create a position located at coordinates (0,0,0) with velocity (0,0,0) |
| 41 | */ |
| 42 | SpringMobilityModel (); |
| 43 | virtual ~SpringMobilityModel (); |
| 44 | |
| 45 | /** |
| 46 | * \brief Attach node by a spring |
| 47 | * \param node MobilityModel layer of the attaching node |
| 48 | */ |
| 49 | void |
| 50 | AddSpring (Ptr<MobilityModel> node); |
| 51 | |
| 52 | private: |
| 53 | // from Object |
| 54 | virtual void |
| 55 | DoStart (); |
| 56 | |
| 57 | // from MobilityModel |
| 58 | virtual Vector |
| 59 | DoGetPosition (void) const; |
| 60 | |
| 61 | virtual void |
| 62 | DoSetPosition (const Vector &position); |
| 63 | |
| 64 | virtual Vector |
| 65 | DoGetVelocity (void) const; |
| 66 | |
| 67 | // Updating positions |
| 68 | void |
| 69 | Update (void) const; |
| 70 | |
| 71 | private: |
| 72 | double m_epsilon; |
| 73 | |
| 74 | double m_nodeMass; |
| 75 | double m_nodeCharge; |
| 76 | double m_springNormalLength; |
| 77 | double m_springConstant; |
| 78 | double m_dampingFactor; |
| 79 | |
| 80 | static double m_totalKineticEnergy; |
| 81 | |
| 82 | mutable Vector m_position; |
| 83 | mutable Vector m_velocity; |
| 84 | mutable bool m_stable; |
| 85 | mutable Time m_lastTime; |
| 86 | |
| 87 | EventId m_updateEvent; |
| 88 | |
| 89 | std::list<Ptr<MobilityModel> > m_springs; |
| 90 | }; |
| 91 | |
| 92 | } // namespace ns3 |
| 93 | |
| 94 | #endif // SPRING_MOBILITY_MODEL_H |