View | Details | Raw Unified | Return to bug 2409
Collapse All | Expand All

(-)4f7ab094386f (+59 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "resonant-charger-helper.h"
20
#include "ns3/resonant-charger-energy-model.h"
21
22
namespace ns3 {
23
24
ResonantChargerHelper::ResonantChargerHelper ()
25
{
26
}
27
28
DeviceEnergyModelContainer
29
ResonantChargerHelper::Install (NodeContainer c) const
30
{
31
  DeviceEnergyModelContainer tmp;
32
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
33
    {
34
      tmp.Add (Install (*i));
35
    }
36
  return tmp;
37
}
38
39
Ptr<DeviceEnergyModel>
40
ResonantChargerHelper::Install (std::string nodeName) const
41
{
42
  Ptr<Node> node = Names::Find<Node> (nodeName);
43
  return Install (node);
44
}
45
46
Ptr<DeviceEnergyModel>
47
ResonantChargerHelper::Install (Ptr<Node> node) const
48
{
49
  NS_ASSERT (node != NULL);
50
  Ptr<ResonantChargerEnergyModel> resonantChargerEnergyModel = CreateObject<ResonantChargerEnergyModel> ();
51
  Ptr<EnergySource> energySource = node->GetObject<EnergySourceContainer> ()->Get (0);
52
  NS_ASSERT (energySource != NULL);
53
  resonantChargerEnergyModel->SetEnergySource (energySource);
54
  energySource->AppendDeviceEnergyModel (resonantChargerEnergyModel);
55
  resonantChargerEnergyModel->SetNode (node);
56
  return resonantChargerEnergyModel;
57
}
58
59
} // namespace ns3
(-)4f7ab094386f (+72 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef RESONANT_CHARGER_HELPER_H
20
#define RESONANT_CHARGER_HELPER_H
21
22
#include "ns3/names.h"
23
24
#include "ns3/node-container.h"
25
#include "ns3/object-factory.h"
26
#include "ns3/device-energy-model.h"
27
#include "ns3/device-energy-model-container.h"
28
29
namespace ns3 {
30
31
/**
32
 * \ingroup energy
33
 * Install into a node (or set of nodes) the resonant charger energy model
34
 */
35
36
class ResonantChargerHelper
37
{
38
public:
39
  ResonantChargerHelper ();
40
41
  /**
42
   * Install the resonant charger energy model into a set of nodes.
43
   * 
44
   * \param c NodeContainer where to install.
45
   * 
46
   * \returns DeviceEnergyModelContainer.
47
   */
48
  DeviceEnergyModelContainer Install (NodeContainer c) const;
49
50
  /**
51
   * Install the resonant charger energy model into a single node.
52
   *
53
   * \param nodeName Name of the node where to install.
54
   * 
55
   * \returns a pointer to DeviceEnergyModel.
56
   */
57
  Ptr<DeviceEnergyModel> Install (std::string nodeName) const;
58
59
  /**
60
   * Install the resonant charger energy model into a single node.
61
   *
62
   * \param node Pointer of the node where to install.
63
   * 
64
   * \returns a pointer to DeviceEnergyModel.
65
   */
66
  Ptr<DeviceEnergyModel> Install (Ptr<Node> node) const;
67
68
};
69
70
} // namespace ns3
71
72
#endif /* RESONANT_CHARGER_HELPER_H */
(-)4f7ab094386f (+56 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "resonant-energy-harvester-helper.h"
20
#include "ns3/resonant-energy-harvester.h"
21
22
namespace ns3 {
23
24
ResonantEnergyHarvesterHelper::ResonantEnergyHarvesterHelper ()
25
{
26
  m_resonantEnergyHarvester.SetTypeId ("ns3::ResonantEnergyHarvester");
27
}
28
29
ResonantEnergyHarvesterHelper::~ResonantEnergyHarvesterHelper ()
30
{
31
}
32
33
void
34
ResonantEnergyHarvesterHelper::Set (std::string name, const AttributeValue &v)
35
{
36
  m_resonantEnergyHarvester.Set (name, v);
37
}
38
39
Ptr<EnergyHarvester>
40
ResonantEnergyHarvesterHelper::DoInstall (Ptr<EnergySource> source) const
41
{
42
  NS_ASSERT (source != NULL);
43
  Ptr<Node> node = source->GetNode ();
44
45
  // Create a new Basic Energy Harvester
46
  Ptr<EnergyHarvester> harvester = m_resonantEnergyHarvester.Create<EnergyHarvester> ();
47
  NS_ASSERT (harvester != NULL);
48
49
  // Connect the Basic Energy Harvester to the Energy Source
50
  source->ConnectEnergyHarvester (harvester);
51
  harvester->SetNode (node);
52
  harvester->SetEnergySource (source);
53
  return harvester;
54
}
55
56
} // namespace ns3
(-)4f7ab094386f (+49 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef RESONANT_ENERGY_HARVESTER_HELPER_H
20
#define RESONANT_ENERGY_HARVESTER_HELPER_H
21
22
#include "ns3/energy-harvester-helper.h"
23
#include "ns3/energy-source.h"
24
25
namespace ns3 {
26
27
/**
28
 * \ingroup energy
29
 * \brief Creates a ResonantEnergyHarvester object.
30
 */
31
class ResonantEnergyHarvesterHelper : public EnergyHarvesterHelper
32
{
33
public:
34
  ResonantEnergyHarvesterHelper ();
35
  ~ResonantEnergyHarvesterHelper ();
36
37
  void Set (std::string name, const AttributeValue &v);
38
39
private:
40
  virtual Ptr<EnergyHarvester> DoInstall (Ptr<EnergySource> source) const;
41
42
private:
43
  ObjectFactory m_resonantEnergyHarvester;
44
45
};
46
47
} // namespace ns3
48
49
#endif /* defined(RESONANT_ENERGY_HARVESTER_HELPER_H) */
(-)4f7ab094386f (+56 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "solar-energy-harvester-helper.h"
20
#include "ns3/solar-energy-harvester.h"
21
22
namespace ns3 {
23
24
SolarEnergyHarvesterHelper::SolarEnergyHarvesterHelper ()
25
{
26
  m_solarEnergyHarvester.SetTypeId ("ns3::SolarEnergyHarvester");
27
}
28
29
SolarEnergyHarvesterHelper::~SolarEnergyHarvesterHelper ()
30
{
31
}
32
33
void
34
SolarEnergyHarvesterHelper::Set (std::string name, const AttributeValue &v)
35
{
36
  m_solarEnergyHarvester.Set (name, v);
37
}
38
39
Ptr<EnergyHarvester>
40
SolarEnergyHarvesterHelper::DoInstall (Ptr<EnergySource> source) const
41
{
42
  NS_ASSERT (source != NULL);
43
  Ptr<Node> node = source->GetNode ();
44
45
  // Create a new Basic Energy Harvester
46
  Ptr<EnergyHarvester> harvester = m_solarEnergyHarvester.Create<EnergyHarvester> ();
47
  NS_ASSERT (harvester != NULL);
48
49
  // Connect the Basic Energy Harvester to the Energy Source
50
  source->ConnectEnergyHarvester (harvester);
51
  harvester->SetNode (node);
52
  harvester->SetEnergySource (source);
53
  return harvester;
54
}
55
56
} // namespace ns3
(-)4f7ab094386f (+49 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef SOLAR_ENERGY_HARVESTER_HELPER_H
20
#define SOLAR_ENERGY_HARVESTER_HELPER_H
21
22
#include "ns3/energy-harvester-helper.h"
23
#include "ns3/energy-source.h"
24
25
namespace ns3 {
26
27
/**
28
 * \ingroup energy
29
 * \brief Creates a SolarEnergyHarvester object.
30
 */
31
class SolarEnergyHarvesterHelper : public EnergyHarvesterHelper
32
{
33
public:
34
  SolarEnergyHarvesterHelper ();
35
  ~SolarEnergyHarvesterHelper ();
36
37
  void Set (std::string name, const AttributeValue &v);
38
39
private:
40
  virtual Ptr<EnergyHarvester> DoInstall (Ptr<EnergySource> source) const;
41
42
private:
43
  ObjectFactory m_solarEnergyHarvester;
44
45
};
46
47
} // namespace ns3
48
49
#endif /* defined(SOLAR_ENERGY_HARVESTER_HELPER_H) */
(-)4f7ab094386f (+296 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
#include "resonant-charger-energy-model.h"
19
#include "ns3/mobility-model.h"
20
#include "ns3/energy-harvester-container.h"
21
#include "ns3/resonant-energy-harvester.h"
22
#include "src/core/model/callback.h"
23
24
NS_LOG_COMPONENT_DEFINE ("ResonantChargerEnergyModel");
25
26
namespace ns3 {
27
28
NS_OBJECT_ENSURE_REGISTERED (ResonantChargerEnergyModel);
29
30
TypeId
31
ResonantChargerEnergyModel::GetTypeId (void)
32
{
33
  static TypeId tid = TypeId ("ns3::ResonantChargerEnergyModel")
34
    .SetParent<DeviceEnergyModel> ()
35
    .AddConstructor<ResonantChargerEnergyModel> ()
36
    .AddAttribute ("ResonantCharger Power Consumption",
37
                   "Consumed power by the Resonant Charger",
38
                   DoubleValue (51.0),
39
                   MakeDoubleAccessor (&ResonantChargerEnergyModel::m_resonatorPowerRate),
40
                   MakeDoubleChecker<double> ())
41
    .AddAttribute ("Power Loss Per Distance",
42
                   "The power loss per unit distance",
43
                   DoubleValue (20.4),
44
                   MakeDoubleAccessor (&ResonantChargerEnergyModel::m_powerLossPerDistance),
45
                   MakeDoubleChecker<double> ())
46
47
    //The energy loss per unit distance
48
  ;
49
  return tid;
50
}
51
52
ResonantChargerEnergyModel::ResonantChargerEnergyModel ()
53
  : m_node (NULL),
54
    m_source (NULL),
55
    m_lastUpdateTime (Simulator::Now ()),
56
    m_state (OFF)
57
{
58
  NS_LOG_FUNCTION (this);
59
  m_energyDepletionCallback.Nullify ();
60
  m_energyRechargeCallback.Nullify ();
61
}
62
63
ResonantChargerEnergyModel::~ResonantChargerEnergyModel ()
64
{
65
  m_energyDepletionCallback.Nullify ();
66
  m_energyRechargeCallback.Nullify ();
67
  m_node = NULL;
68
  m_source = NULL;
69
}
70
void
71
ResonantChargerEnergyModel::SetNode (Ptr<Node> node)
72
{
73
  NS_LOG_FUNCTION (this << node);
74
  NS_ASSERT (node != NULL);
75
  m_node = node;
76
  Charge ();
77
}
78
79
Ptr<Node>
80
ResonantChargerEnergyModel::GetNode (void) const
81
{
82
  return m_node;
83
}
84
85
void
86
ResonantChargerEnergyModel::SetEnergySource (Ptr<EnergySource> source)
87
{
88
  NS_LOG_FUNCTION (this << source);
89
  NS_ASSERT (source != NULL);
90
  m_source = source;
91
}
92
93
double
94
ResonantChargerEnergyModel::GetTotalEnergyConsumption (void) const
95
{
96
  NS_LOG_FUNCTION (this);
97
  return m_totalEnergyConsumption;
98
}
99
100
void
101
ResonantChargerEnergyModel::ChangeState (int newState)
102
{
103
104
}
105
106
void
107
ResonantChargerEnergyModel::SetState (State state)
108
{
109
  NS_LOG_FUNCTION (this);
110
111
  if (m_state != DISABLED)
112
    {
113
      m_state = state;
114
    }
115
116
}
117
118
ResonantChargerEnergyModel::State
119
ResonantChargerEnergyModel::GetState ()
120
{
121
  NS_LOG_FUNCTION (this);
122
123
  return m_state;
124
}
125
126
void
127
ResonantChargerEnergyModel::ChangeEnergyConsumption ()
128
{
129
  Time duration = Simulator::Now () - m_lastUpdateTime;
130
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
131
132
  double energyToDecrease = duration.GetSeconds () * m_resonatorPowerRate;
133
134
  // charger is not active
135
  if(m_state == OFF || m_state == DISABLED)
136
    {
137
      energyToDecrease = 0;
138
    }
139
140
  // update total energy consumption
141
  m_totalEnergyConsumption += energyToDecrease;
142
143
  // update current drain
144
  double supplyVoltage = m_source->GetSupplyVoltage ();
145
  m_actualCurrentDrain = m_resonatorPowerRate / supplyVoltage;
146
147
  // update last update time stamp
148
  m_lastUpdateTime = Simulator::Now ();
149
150
  // notify energy source
151
  m_source->UpdateEnergySource ();
152
153
  // some debug message
154
  NS_LOG_DEBUG ("ResonantChargerEnergyModel:Total energy consumption at node #" <<
155
                m_node->GetId () << " is " << m_totalEnergyConsumption << "J");
156
}
157
158
void
159
ResonantChargerEnergyModel::SetEnergyDepletionCallback (ResonantChargerEnergyDepletionCallback callback)
160
{
161
  NS_LOG_FUNCTION (this);
162
  if (callback.IsNull ())
163
    {
164
      NS_LOG_DEBUG ("ResonantChargerEnergyModel:Setting NULL energy depletion callback!");
165
    }
166
  m_energyDepletionCallback = callback;
167
}
168
169
void
170
ResonantChargerEnergyModel::SetEnergyRechargeCallback (ResonantChargerEnergyRechargeCallback callback)
171
{
172
  NS_LOG_FUNCTION (this);
173
  if (callback.IsNull ())
174
    {
175
      NS_LOG_DEBUG ("ResonantChargerEnergyModel:Setting NULL energy recharge callback!");
176
    }
177
  m_energyRechargeCallback = callback;
178
}
179
180
void
181
ResonantChargerEnergyModel::HandleEnergyDepletion (void)
182
{
183
  NS_LOG_FUNCTION (this);
184
  NS_LOG_DEBUG ("ResonantChargerEnergyModel:Energy is depleted at node #" <<
185
                m_node->GetId ());
186
  m_state = DISABLED;
187
  // invoke energy depletion callback, if set.
188
  if (!m_energyDepletionCallback.IsNull ())
189
    {
190
      m_energyDepletionCallback ();
191
    }
192
}
193
194
void
195
ResonantChargerEnergyModel::HandleEnergyRecharged (void)
196
{
197
  NS_LOG_FUNCTION (this);
198
  NS_LOG_DEBUG ("ResonantChargerEnergyModel:Energy is recharged at node #" <<
199
                m_node->GetId ());
200
  m_state = OFF;
201
  // invoke energy recharge callback, if set.
202
  if (!m_energyRechargeCallback.IsNull ())
203
    {
204
      m_energyRechargeCallback ();
205
    }
206
}
207
208
/*
209
 * Private functions start here.
210
 */
211
212
void
213
ResonantChargerEnergyModel::DoDispose (void)
214
{
215
  NS_LOG_FUNCTION (this);
216
}
217
218
double
219
ResonantChargerEnergyModel::DoGetCurrentA (void) const
220
{
221
  NS_LOG_FUNCTION (this);
222
223
  return m_actualCurrentDrain;
224
}
225
226
double
227
ResonantChargerEnergyModel::GetChargingPowerRate ()
228
{
229
  NS_LOG_FUNCTION (this);
230
231
  return m_resonatorPowerRate;
232
}
233
234
void
235
ResonantChargerEnergyModel::SetChargingPowerRate (double power)
236
{
237
  NS_LOG_FUNCTION (this);
238
239
  m_resonatorPowerRate = power;
240
}
241
242
void
243
ResonantChargerEnergyModel::AddRechargableNodes (const NodeContainer nodeContainer)
244
{
245
  m_nodeContainer.Add (nodeContainer);
246
}
247
248
void
249
ResonantChargerEnergyModel::AddRechargableNode (const Ptr<Node> node)
250
{
251
  NS_ASSERT (node != NULL);
252
  m_nodeContainer.Add (node);
253
}
254
255
double
256
ResonantChargerEnergyModel::CalculateDistance (const Ptr<Node> node)
257
{
258
  NS_ASSERT (GetNode ()->GetObject<MobilityModel> () != NULL);
259
  NS_ASSERT (node->GetObject<MobilityModel> () != NULL);
260
261
  double distance = GetNode ()->GetObject<MobilityModel> ()
262
    ->GetDistanceFrom (node->GetObject<MobilityModel> ());
263
264
  return distance;
265
}
266
267
void
268
ResonantChargerEnergyModel::Charge ()
269
{
270
  NodeContainer::Iterator i = m_nodeContainer.Begin ();
271
  while (i != m_nodeContainer.End ())
272
    {
273
      DoCharge (*i);
274
      i++;
275
    }
276
  Simulator::Schedule (Seconds (1), &ResonantChargerEnergyModel::Charge, this);
277
}
278
279
void
280
ResonantChargerEnergyModel::DoCharge (const Ptr<Node> node)
281
{
282
  double power = m_resonatorPowerRate - (CalculateDistance (node) * m_powerLossPerDistance);
283
  if (power < 0 || m_state == OFF || m_state == DISABLED)
284
    {
285
      power = 0;
286
    }
287
  Ptr<ResonantEnergyHarvester> resonantHarvester = node->GetObject<EnergyHarvesterContainer> ()->Get (0)
288
    ->GetObject<ResonantEnergyHarvester> ();
289
290
  if(resonantHarvester != NULL)
291
    {
292
      resonantHarvester->SetHarvestablePower (power);
293
    }
294
}
295
296
} // namespace ns3
(-)4f7ab094386f (+236 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef RESONANT_CHARGER_ENERGY_MODEL_H
20
#define RESONANT_CHARGER_ENERGY_MODEL_H
21
22
#include "ns3/device-energy-model.h"
23
#include "ns3/energy-source.h"
24
#include "ns3/event-id.h"
25
#include "ns3/traced-value.h"
26
#include "ns3/log.h"
27
#include "ns3/simulator.h"
28
#include "ns3/node-container.h"
29
30
namespace ns3 {
31
32
/**
33
 * \ingroup energy
34
 * \brief Keeps track of the SAUV energy consumption
35
 *
36
 * The class model the energy consumed by the Resonant Charger.
37
 *
38
 * 
39
 */
40
class ResonantChargerEnergyModel : public DeviceEnergyModel
41
{
42
public:
43
  // / Callback type for energy depletion handling.
44
  typedef Callback<void> ResonantChargerEnergyDepletionCallback;
45
  // / Callback type for energy recharge handling.
46
  typedef Callback<void> ResonantChargerEnergyRechargeCallback;
47
48
  enum State
49
  {
50
    OFF,      //!< OFF.
51
    ON,       //!< ON.
52
    DISABLED  //!< Disabled.
53
  };
54
55
public:
56
  static TypeId GetTypeId (void);
57
  ResonantChargerEnergyModel ();
58
  virtual ~ResonantChargerEnergyModel ();
59
60
  /**
61
   * \brief Sets pointer to node.
62
   *
63
   * \param node Pointer to node.
64
   *
65
   * Implements DeviceEnergyModel::SetNode.
66
   */
67
  virtual void SetNode (Ptr<Node> node);
68
69
  /**
70
   * \brief Gets pointer to node.
71
   *
72
   * \returns Pointer to node.
73
   *
74
   * Implements DeviceEnergyModel::GetNode.
75
   */
76
  virtual Ptr<Node> GetNode (void) const;
77
78
  /**
79
   * \brief Sets pointer to EnergySouce installed on node.
80
   *
81
   * \param source Pointer to EnergySource installed on node.
82
   *
83
   * Implements DeviceEnergyModel::SetEnergySource.
84
   */
85
  virtual void SetEnergySource (Ptr<EnergySource> source);
86
87
  /**
88
   * \returns Total energy consumption of the vehicle.
89
   *
90
   * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
91
   */
92
  virtual double GetTotalEnergyConsumption (void) const;
93
94
  /**
95
   * \param newState New state the device is in.
96
   *
97
   * DeviceEnergyModel is a state based model. This function is implemented by
98
   * all child of DeviceEnergyModel to change the model's state. States are to
99
   * be defined by each child using an enum (int).
100
   */
101
  virtual void ChangeState (int newState);
102
103
  /**
104
   *
105
   * Update the energy consumption.
106
   */
107
  void ChangeEnergyConsumption ();
108
109
  /**
110
   * \param callback Callback function.
111
   *
112
   * Sets callback for energy depletion handling.
113
   */
114
  void SetEnergyDepletionCallback (ResonantChargerEnergyDepletionCallback callback);
115
116
  /**
117
   * \param callback Callback function.
118
   *
119
   * Sets callback for energy recharge handling.
120
   */
121
  void SetEnergyRechargeCallback (ResonantChargerEnergyRechargeCallback callback);
122
123
  /**
124
   * \brief Handles energy depletion.
125
   *
126
   * Implements DeviceEnergyModel::HandleEnergyDepletion
127
   */
128
  virtual void HandleEnergyDepletion (void);
129
130
  /**
131
   * \brief Handles energy recharge.
132
   *
133
   * Implements DeviceEnergyModel::HandleEnergyRecharged
134
   */
135
  virtual void HandleEnergyRecharged (void);
136
137
  /**
138
   * \param the power rate of the charger.
139
   *
140
   * Sets the charging rate of the charger.
141
   */
142
  void SetChargingPowerRate (double power);
143
  /**
144
   * \returns the power rate of the charger.
145
   *
146
   * Gets the charging rate of the charger.
147
   */
148
  double GetChargingPowerRate ();
149
  /**
150
   * \param the status of the charger.
151
   *
152
   * Sets the status of the charger.
153
   */
154
  void SetState (State state);
155
  /**
156
   * \returns the status charger.
157
   *
158
   * Gets the status of the charger.
159
   */
160
  State GetState ();
161
  /**
162
   * \param the nodes to be charged.
163
   *
164
   * Adds the nodes to be charged.
165
   */
166
  void AddRechargableNodes (const NodeContainer nodeContainer);
167
  /**
168
  * \param a node to be charged.
169
  *
170
  * Adds a node to be charged.
171
  */
172
  void AddRechargableNode (const Ptr<Node> node);
173
174
private:
175
176
  void DoDispose (void);
177
178
  /**
179
   * \returns Current draw of device, at current state.
180
   *
181
   * Implements DeviceEnergyModel::GetCurrentA.
182
   */
183
  virtual double DoGetCurrentA (void) const;
184
185
  /**
186
   * \returns the distance to the node.
187
   * \param the node
188
   *
189
   * Calculate the distance to the node
190
   */
191
  double CalculateDistance (const Ptr<Node> node);
192
  /**
193
  * \param the node to be recharged
194
  *
195
  * charge the the node
196
  */
197
  void DoCharge (const Ptr<Node> node);
198
  /**
199
   * Charge all the nodes
200
   */
201
  void Charge ();
202
203
private:
204
  Ptr<Node> m_node;
205
  Ptr<EnergySource> m_source;
206
207
  // This variable keeps track of the total energy consumed by this particular model.
208
  TracedValue<double> m_totalEnergyConsumption;
209
210
  // actual current drain
211
  double m_actualCurrentDrain;
212
213
  // time stamp of previous energy update
214
  Time m_lastUpdateTime;
215
  // power rate of the resonator
216
  double m_resonatorPowerRate;
217
218
  // The power loss per unit distance
219
  double m_powerLossPerDistance;
220
221
  // the status of the resonator
222
  State m_state;
223
224
  // energy depletion callback
225
  ResonantChargerEnergyDepletionCallback m_energyDepletionCallback;
226
227
  // energy recharge callback
228
  ResonantChargerEnergyRechargeCallback m_energyRechargeCallback;
229
230
  // The nodes to be recharged
231
  NodeContainer m_nodeContainer;
232
};
233
234
} // namespace ns3
235
236
#endif /* RESONANT_CHARGER_ENERGY_MODEL_H */
(-)4f7ab094386f (+171 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "resonant-energy-harvester.h"
20
#include "ns3/log.h"
21
#include "ns3/simulator.h"
22
23
namespace ns3 {
24
25
NS_LOG_COMPONENT_DEFINE ("ResonantEnergyHarvester");
26
27
NS_OBJECT_ENSURE_REGISTERED (ResonantEnergyHarvester);
28
29
TypeId
30
ResonantEnergyHarvester::GetTypeId (void)
31
{
32
  static TypeId tid = TypeId ("ns3::ResonantEnergyHarvester")
33
    .SetParent<EnergyHarvester> ()
34
    .SetGroupName ("AUV")
35
    .AddConstructor<ResonantEnergyHarvester> ()
36
    .AddAttribute ("PeriodicHarvestedPowerUpdateInterval",
37
                   "Time between two consecutive periodic updates of the harvested power. By default, the value is updated every 1 s",
38
                   TimeValue (Seconds (1.0)),
39
                   MakeTimeAccessor (&ResonantEnergyHarvester::SetHarvestedPowerUpdateInterval,
40
                                     &ResonantEnergyHarvester::GetHarvestedPowerUpdateInterval),
41
                   MakeTimeChecker ())
42
    .AddTraceSource ("HarvestedPower",
43
                     "Harvested power by the ResonantEnergyHarvester.",
44
                     MakeTraceSourceAccessor (&ResonantEnergyHarvester::m_harvestedPower),
45
                     "ns3::TracedValueCallback::Double")
46
    .AddTraceSource ("TotalEnergyHarvested",
47
                     "Total energy harvested by the harvester.",
48
                     MakeTraceSourceAccessor (&ResonantEnergyHarvester::m_totalEnergyHarvestedJ),
49
                     "ns3::TracedValueCallback::Double")
50
  ;
51
  return tid;
52
}
53
54
ResonantEnergyHarvester::ResonantEnergyHarvester ()
55
  : m_harvestablePower (0)
56
{
57
  NS_LOG_FUNCTION (this);
58
}
59
60
ResonantEnergyHarvester::ResonantEnergyHarvester (Time updateInterval)
61
  : m_harvestablePower (0)
62
{
63
  NS_LOG_FUNCTION (this << updateInterval);
64
  m_harvestedPowerUpdateInterval = updateInterval;
65
}
66
67
ResonantEnergyHarvester::~ResonantEnergyHarvester ()
68
{
69
  NS_LOG_FUNCTION (this);
70
}
71
72
void
73
ResonantEnergyHarvester::SetHarvestedPowerUpdateInterval (Time updateInterval)
74
{
75
  NS_LOG_FUNCTION (this << updateInterval);
76
77
  m_harvestedPowerUpdateInterval = updateInterval;
78
}
79
80
Time
81
ResonantEnergyHarvester::GetHarvestedPowerUpdateInterval (void) const
82
{
83
  NS_LOG_FUNCTION (this << m_harvestedPowerUpdateInterval);
84
85
  return m_harvestedPowerUpdateInterval;
86
}
87
88
void
89
ResonantEnergyHarvester::SetHarvestablePower (double power)
90
{
91
  NS_LOG_FUNCTION (this);
92
93
  m_harvestablePower = power;
94
}
95
96
/*
97
 * Private functions start here.
98
 */
99
100
void
101
ResonantEnergyHarvester::UpdateHarvestedPower (void)
102
{
103
  NS_LOG_FUNCTION (this);
104
  NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
105
                << "s ResonantEnergyHarvester(" << GetNode ()->GetId () << "): Updating harvesting power.");
106
107
  Time duration = Simulator::Now () - m_lastHarvestingUpdateTime;
108
109
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
110
111
  double energyHarvested = 0.0;
112
113
  // do not update if simulation has finished
114
  if (Simulator::IsFinished ())
115
    {
116
      NS_LOG_DEBUG ("ResonantEnergyHarvester: Simulation Finished.");
117
      return;
118
    }
119
120
  m_energyHarvestingUpdateEvent.Cancel ();
121
122
  if(GetEnergySource ()->GetEnergyFraction () >= 1)
123
    {
124
      m_harvestedPower = 0;
125
    }
126
  else
127
    {
128
      m_harvestedPower = m_harvestablePower;
129
    }
130
131
  energyHarvested = duration.GetSeconds () * m_harvestedPower;
132
133
  // update total energy harvested
134
  m_totalEnergyHarvestedJ += energyHarvested;
135
136
  // notify energy source
137
  GetEnergySource ()->UpdateEnergySource ();
138
139
  // update last harvesting time stamp
140
  m_lastHarvestingUpdateTime = Simulator::Now ();
141
142
  m_energyHarvestingUpdateEvent = Simulator::Schedule (m_harvestedPowerUpdateInterval,
143
                                                       &ResonantEnergyHarvester::UpdateHarvestedPower,
144
                                                       this);
145
}
146
147
void
148
ResonantEnergyHarvester::DoInitialize (void)
149
{
150
  NS_LOG_FUNCTION (this);
151
152
  m_lastHarvestingUpdateTime = Simulator::Now ();
153
154
  UpdateHarvestedPower ();  // start periodic harvesting update
155
}
156
157
void
158
ResonantEnergyHarvester::DoDispose (void)
159
{
160
  NS_LOG_FUNCTION (this);
161
}
162
163
164
double
165
ResonantEnergyHarvester::DoGetPower (void) const
166
{
167
  NS_LOG_FUNCTION (this);
168
  return m_harvestedPower;
169
}
170
171
} // namespace ns3
(-)4f7ab094386f (+110 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef RESONANT_ENERGY_HARVESTER
20
#define RESONANT_ENERGY_HARVESTER
21
22
#include "ns3/traced-value.h"
23
#include "ns3/nstime.h"
24
#include "ns3/event-id.h"
25
#include "ns3/energy-harvester.h"
26
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup energy
32
 * ResonantEnergyHarvester increases remaining energy stored in an associated
33
 * Energy Source. The ResonantEnergyHarvester implements a simple model in which
34
 * the amount of power provided by the harvester is constant over time according
35
 *
36
 * Unit of power is chosen as Watt since energy models typically calculate
37
 * energy as (time in seconds * power in Watt).
38
 *
39
 */
40
class ResonantEnergyHarvester: public EnergyHarvester
41
{
42
public:
43
  static TypeId GetTypeId (void);
44
45
  ResonantEnergyHarvester ();
46
47
  /**
48
   * \param updateInterval Energy harvesting update interval.
49
   *
50
   * ResonantEnergyHarvester constructor function that sets the interval
51
   * between each update of the value of the power harvested by this
52
   * energy harvester.
53
   */
54
  ResonantEnergyHarvester (Time updateInterval);
55
56
  virtual ~ResonantEnergyHarvester ();
57
58
  /**
59
   * \param updateInterval Energy harvesting update interval.
60
   *
61
   * This function sets the interval between each update of the value of the
62
   * power harvested by this energy harvester.
63
   */
64
  void SetHarvestedPowerUpdateInterval (Time updateInterval);
65
66
  /**
67
   * \returns The interval between each update of the harvested power.
68
   *
69
   * This function returns the interval between each update of the value of the
70
   * power harvested by this energy harvester.
71
   */
72
  Time GetHarvestedPowerUpdateInterval (void) const;
73
74
  void SetHarvestablePower (double power);
75
76
private:
77
  /// Defined in ns3::Object
78
  void DoInitialize (void);
79
80
  /// Defined in ns3::Object
81
  void DoDispose (void);
82
83
  /**
84
   * \returns m_harvestedPower The power currently provided by the Resonant Energy Harvester.
85
   * Implements DoGetPower defined in EnergyHarvester.
86
   */
87
  virtual double DoGetPower (void) const;
88
89
  /**
90
   * This function is called every m_energyHarvestingUpdateInterval in order to
91
   * update the amount of power that will be provided by the harvester in the
92
   * next interval.
93
   */
94
  void UpdateHarvestedPower (void);
95
96
private:
97
98
  double m_harvestablePower;                    // harvestable power in Watt
99
  TracedValue<double> m_harvestedPower;         // current harvested power, in Watt
100
  TracedValue<double> m_totalEnergyHarvestedJ;  // total harvested energy, in Joule
101
102
  EventId m_energyHarvestingUpdateEvent;        // energy harvesting event
103
  Time m_lastHarvestingUpdateTime;              // last harvesting time
104
  Time m_harvestedPowerUpdateInterval;          // harvestable energy update interval
105
106
};
107
108
} // namespace ns3
109
110
#endif /* defined(RESONANT_ENERGY_HARVESTER) */
(-)4f7ab094386f (+211 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
#include "solar-energy-harvester.h"
19
#include "ns3/mobility-model.h"
20
21
namespace ns3 {
22
23
NS_LOG_COMPONENT_DEFINE ("SolarEnergyHarvester");
24
25
NS_OBJECT_ENSURE_REGISTERED (SolarEnergyHarvester);
26
27
TypeId
28
SolarEnergyHarvester::GetTypeId (void)
29
{
30
  static TypeId tid = TypeId ("ns3::SolarEnergyHarvester")
31
    .SetParent<EnergyHarvester> ()
32
    .SetGroupName ("AUV")
33
    .AddConstructor<SolarEnergyHarvester> ()
34
    .AddAttribute ("PeriodicHarvestedPowerUpdateInterval",
35
                   "Time between two consecutive periodic updates of the harvested power. By default, the value is updated every 1 s",
36
                   TimeValue (Seconds (1.0)),
37
                   MakeTimeAccessor (&SolarEnergyHarvester::SetHarvestedPowerUpdateInterval,
38
                                     &SolarEnergyHarvester::GetHarvestedPowerUpdateInterval),
39
                   MakeTimeChecker ())
40
    .AddAttribute ("HarvestablePower",
41
                   "The harvestable power [Watts] that the solar energy harvester is allowed to harvest.",
42
                   DoubleValue (85),
43
                   MakeDoubleAccessor (&SolarEnergyHarvester::m_harvestablePower),
44
                   MakeDoubleChecker<double> ())
45
    .AddAttribute ("SunriseHour",
46
                   "The sunrise Hour in 24 hours format.",
47
                   IntegerValue (7),
48
                   MakeIntegerAccessor (&SolarEnergyHarvester::m_sunriseHour),
49
                   MakeIntegerChecker<int> ())
50
    .AddAttribute ("SunsetHour",
51
                   "The sunset Hour in 24 hours format.",
52
                   IntegerValue (17),
53
                   MakeIntegerAccessor (&SolarEnergyHarvester::m_sunsetHour),
54
                   MakeIntegerChecker<int> ())
55
    .AddAttribute ("UnderwaterMode",
56
                   "Disable energy harvesting when depth < 0.",
57
                   BooleanValue (false),
58
                   MakeBooleanAccessor (&SolarEnergyHarvester::m_underwaterMode),
59
                   MakeBooleanChecker ())
60
    .AddTraceSource ("HarvestedPower",
61
                     "Harvested power by the SolarEnergyHarvester.",
62
                     MakeTraceSourceAccessor (&SolarEnergyHarvester::m_harvestedPower),
63
                     "ns3::TracedValueCallback::Double")
64
    .AddTraceSource ("TotalEnergyHarvested",
65
                     "Total energy harvested by the harvester.",
66
                     MakeTraceSourceAccessor (&SolarEnergyHarvester::m_totalEnergyHarvestedJ),
67
                     "ns3::TracedValueCallback::Double")
68
  ;
69
  return tid;
70
}
71
72
SolarEnergyHarvester::SolarEnergyHarvester ()
73
{
74
  NS_LOG_FUNCTION (this);
75
}
76
77
SolarEnergyHarvester::SolarEnergyHarvester (Time updateInterval)
78
{
79
  NS_LOG_FUNCTION (this << updateInterval);
80
  m_harvestedPowerUpdateInterval = updateInterval;
81
}
82
83
SolarEnergyHarvester::~SolarEnergyHarvester ()
84
{
85
  NS_LOG_FUNCTION (this);
86
}
87
88
void
89
SolarEnergyHarvester::SetHarvestedPowerUpdateInterval (Time updateInterval)
90
{
91
  NS_LOG_FUNCTION (this << updateInterval);
92
  m_harvestedPowerUpdateInterval = updateInterval;
93
}
94
95
Time
96
SolarEnergyHarvester::GetHarvestedPowerUpdateInterval (void) const
97
{
98
  NS_LOG_FUNCTION (this);
99
  return m_harvestedPowerUpdateInterval;
100
}
101
102
103
void
104
SolarEnergyHarvester::SetHarvestablePower (double power)
105
{
106
  m_harvestablePower = power;
107
}
108
109
/*
110
 * Private functions start here.
111
 */
112
113
void
114
SolarEnergyHarvester::UpdateHarvestedPower (void)
115
{
116
  NS_LOG_FUNCTION (this);
117
  NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
118
                << "s SolarEnergyHarvester(" << GetNode ()->GetId () << "): Updating harvesting power.");
119
120
  Time duration = Simulator::Now () - m_lastHarvestingUpdateTime;
121
122
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
123
124
  double energyHarvested = 0.0;
125
126
  // do not update if simulation has finished
127
  if (Simulator::IsFinished ())
128
    {
129
      NS_LOG_DEBUG ("SolarEnergyHarvester: Simulation Finished.");
130
      return;
131
    }
132
133
  Ptr<MobilityModel> mob = GetNode ()->GetObject<MobilityModel>();
134
  NS_ASSERT (mob != NULL);
135
  Vector position = mob->GetPosition ();
136
  double depth = position.z;
137
138
  m_energyHarvestingUpdateEvent.Cancel ();
139
140
  if(!m_sunlight || (m_underwaterMode && depth < 0) || GetEnergySource ()->GetEnergyFraction () >= 1)
141
    {
142
      m_harvestedPower = 0;
143
    }
144
  else
145
    {
146
      m_harvestedPower = m_harvestablePower;
147
    }
148
 
149
  energyHarvested = duration.GetSeconds () * m_harvestedPower;
150
151
  // update total energy harvested
152
  m_totalEnergyHarvestedJ += energyHarvested;
153
154
  // notify energy source
155
  GetEnergySource ()->UpdateEnergySource ();
156
157
  // update last harvesting time stamp
158
  m_lastHarvestingUpdateTime = Simulator::Now ();
159
160
  m_energyHarvestingUpdateEvent = Simulator::Schedule (m_harvestedPowerUpdateInterval,
161
                                                       &SolarEnergyHarvester::UpdateHarvestedPower,
162
                                                       this);
163
}
164
165
void
166
SolarEnergyHarvester::DoInitialize (void)
167
{
168
  NS_LOG_FUNCTION (this);
169
  m_lastHarvestingUpdateTime = Simulator::Now ();
170
  SwitchDayNight ();
171
  UpdateHarvestedPower ();  // start periodic harvesting update
172
}
173
174
void
175
SolarEnergyHarvester::DoDispose (void)
176
{
177
  NS_LOG_FUNCTION (this);
178
}
179
180
181
double
182
SolarEnergyHarvester::DoGetPower (void) const
183
{
184
  NS_LOG_FUNCTION (this);
185
  return m_harvestedPower;
186
}
187
188
void
189
SolarEnergyHarvester::SetSolarHavestingHours (int sunriseHour, int sunsetHour)
190
{
191
  m_sunriseHour = sunriseHour;
192
  m_sunsetHour = sunsetHour;
193
}
194
195
void
196
SolarEnergyHarvester::SwitchDayNight (void)
197
{
198
  int hours = Simulator::Now ().GetHours ();
199
  hours %= 24;
200
  if(hours >= m_sunriseHour && hours <= m_sunsetHour)
201
    {
202
      m_sunlight = true;
203
    }
204
  else
205
    {
206
      m_sunlight = false;
207
    }
208
  Simulator::Schedule (Hours (1), &SolarEnergyHarvester::SwitchDayNight, this );
209
}
210
211
} // namespace ns3
(-)4f7ab094386f (+135 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef SOLAR_ENERGY_HARVESTER
20
#define SOLAR_ENERGY_HARVESTER
21
22
#include "ns3/traced-value.h"
23
#include "ns3/event-id.h"
24
#include "ns3/energy-harvester.h"
25
#include "ns3/log.h"
26
#include "ns3/simulator.h"
27
28
29
namespace ns3 {
30
31
/**
32
 * \ingroup energy
33
 * SolarEnergyHarvester increases remaining energy stored in an associated
34
 * Energy Source. The SolarEnergyHarvester implements a simple model in which
35
 * the amount of power provided by the harvester is constant over time according
36
 *
37
 * Unit of power is chosen as Watt since energy models typically calculate
38
 * energy as (time in seconds * power in Watt).
39
 *
40
 */
41
class SolarEnergyHarvester: public EnergyHarvester
42
{
43
public:
44
  static TypeId GetTypeId (void);
45
46
  SolarEnergyHarvester ();
47
48
  /**
49
   * \param updateInterval Energy harvesting update interval.
50
   *
51
   * ResonantEnergyHarvester constructor function that sets the interval
52
   * between each update of the value of the power harvested by this
53
   * energy harvester.
54
   */
55
  SolarEnergyHarvester (Time updateInterval);
56
57
  virtual ~SolarEnergyHarvester ();
58
59
  /**
60
   * \param updateInterval Energy harvesting update interval.
61
   *
62
   * This function sets the interval between each update of the value of the
63
   * power harvested by this energy harvester.
64
   */
65
  void SetHarvestedPowerUpdateInterval (Time updateInterval);
66
67
  /**
68
   * \returns The interval between each update of the harvested power.
69
   *
70
   * This function returns the interval between each update of the value of the
71
   * power harvested by this energy harvester.
72
   */
73
  Time GetHarvestedPowerUpdateInterval (void) const;
74
75
  /**
76
   * \param sunriseHour The sunriseHour in 24 hours format.
77
   * \param sunsetHour The sunsetHour in 24 hours format.
78
   *
79
   * This function sets the sunriseHour and sunsetHour
80
   * Solar energy can be harvested between these hours.
81
   */
82
  void SetSolarHavestingHours (int sunriseHour, int sunsetHour);
83
84
  /**
85
   * \param power The maximum harvestable solar power
86
   *
87
   * This function sets the maximum solar power that can be harvested
88
   */
89
  void SetHarvestablePower (double power);
90
91
private:
92
  /// Defined in ns3::Object
93
  void DoInitialize (void);
94
95
  /// Defined in ns3::Object
96
  void DoDispose (void);
97
98
  /**
99
   * This function simulates the availability of the sunlight during
100
   * the day
101
   */
102
  void SwitchDayNight (void);
103
104
  /**
105
   * \returns m_harvestedPower The power currently provided by the Resonant Energy Harvester.
106
   * Implements DoGetPower defined in EnergyHarvester.
107
   */
108
  virtual double DoGetPower (void) const;
109
110
  /**
111
   * This function is called every m_energyHarvestingUpdateInterval in order to
112
   * update the amount of power that will be provided by the harvester in the
113
   * next interval.
114
   */
115
  void UpdateHarvestedPower (void);
116
117
private:
118
119
  double m_harvestablePower;                    // harvestable power in Watt
120
  TracedValue<double> m_harvestedPower;         // current harvested power, in Watt
121
  TracedValue<double> m_totalEnergyHarvestedJ;  // total harvested energy, in Joule
122
123
  EventId m_energyHarvestingUpdateEvent;        // energy harvesting event
124
  Time m_lastHarvestingUpdateTime;              // last harvesting time
125
  Time m_harvestedPowerUpdateInterval;          // harvestable energy update interval
126
  bool m_sunlight;                              // availability of the sunlight
127
  int m_sunriseHour;                            // sunrise hour in 24 hours format
128
  int m_sunsetHour;                             // sunset hour in 24 hours format
129
  bool m_underwaterMode;                        // underwater mode
130
131
};
132
133
} // namespace ns3
134
135
#endif /* defined(SOLAR_ENERGY_HARVESTER) */
(-)a/src/energy/wscript (+12 lines)
 Lines 12-17    Link Here 
12
        'model/simple-device-energy-model.cc',
12
        'model/simple-device-energy-model.cc',
13
        'model/energy-harvester.cc',
13
        'model/energy-harvester.cc',
14
        'model/basic-energy-harvester.cc',
14
        'model/basic-energy-harvester.cc',
15
		'model/resonant-charger-energy-model.cc',
16
		'model/resonant-energy-harvester.cc',
17
		'model/solar-energy-harvester.cc',
15
        'helper/energy-source-container.cc',
18
        'helper/energy-source-container.cc',
16
        'helper/energy-model-helper.cc',
19
        'helper/energy-model-helper.cc',
17
        'helper/basic-energy-source-helper.cc',
20
        'helper/basic-energy-source-helper.cc',
 Lines 20-25    Link Here 
20
        'helper/energy-harvester-container.cc',
23
        'helper/energy-harvester-container.cc',
21
        'helper/energy-harvester-helper.cc',
24
        'helper/energy-harvester-helper.cc',
22
        'helper/basic-energy-harvester-helper.cc',
25
        'helper/basic-energy-harvester-helper.cc',
26
		'helper/resonant-charger-helper.cc',
27
		'helper/resonant-energy-harvester-helper.cc',
28
		'helper/solar-energy-harvester-helper.cc',
23
        ]
29
        ]
24
30
25
    obj_test = bld.create_ns3_module_test_library('energy')
31
    obj_test = bld.create_ns3_module_test_library('energy')
 Lines 40-45    Link Here 
40
        'model/simple-device-energy-model.h',
46
        'model/simple-device-energy-model.h',
41
        'model/energy-harvester.h',
47
        'model/energy-harvester.h',
42
        'model/basic-energy-harvester.h',
48
        'model/basic-energy-harvester.h',
49
		'model/resonant-charger-energy-model.h',
50
		'model/resonant-energy-harvester.h',
51
		'model/solar-energy-harvester.h',
43
        'helper/energy-source-container.h',
52
        'helper/energy-source-container.h',
44
        'helper/energy-model-helper.h',
53
        'helper/energy-model-helper.h',
45
        'helper/basic-energy-source-helper.h',
54
        'helper/basic-energy-source-helper.h',
 Lines 48-53    Link Here 
48
        'helper/energy-harvester-container.h',
57
        'helper/energy-harvester-container.h',
49
        'helper/energy-harvester-helper.h',
58
        'helper/energy-harvester-helper.h',
50
        'helper/basic-energy-harvester-helper.h',
59
        'helper/basic-energy-harvester-helper.h',
60
		'helper/resonant-charger-helper.h',
61
		'helper/resonant-energy-harvester-helper.h',
62
		'helper/solar-energy-harvester-helper.h',
51
        ]
63
        ]
52
64
53
    if (bld.env['ENABLE_EXAMPLES']):
65
    if (bld.env['ENABLE_EXAMPLES']):

Return to bug 2409