A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
generic-battery-model-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Tokushima University, Japan.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
7 */
8
10
11namespace ns3
12{
13
15{
16 m_batteryModel.SetTypeId("ns3::energy::GenericBatteryModel");
17}
18
22
23void
25{
26 m_batteryModel.Set(name, v);
27}
28
31{
32 NS_ASSERT(node != nullptr);
34 NS_ASSERT(energySource != nullptr);
35 energySource->SetNode(node);
36 return energySource;
37}
38
41{
42 Ptr<energy::EnergySourceContainer> batteryContainer =
44 for (auto i = c.Begin(); i != c.End(); i++)
45 {
46 batteryContainer->Add(DoInstall(*i));
47 }
48 return batteryContainer;
49}
50
53{
54 NS_ASSERT(node != nullptr);
56 NS_ASSERT(energySource != nullptr);
57
58 energySource->SetAttribute("FullVoltage", DoubleValue(energy::g_batteryPreset[bm].vFull));
59 energySource->SetAttribute("MaxCapacity", DoubleValue(energy::g_batteryPreset[bm].qMax));
60
61 energySource->SetAttribute("NominalVoltage", DoubleValue(energy::g_batteryPreset[bm].vNom));
62 energySource->SetAttribute("NominalCapacity", DoubleValue(energy::g_batteryPreset[bm].qNom));
63
64 energySource->SetAttribute("ExponentialVoltage", DoubleValue(energy::g_batteryPreset[bm].vExp));
65 energySource->SetAttribute("ExponentialCapacity",
67
68 energySource->SetAttribute("InternalResistance",
69 DoubleValue(energy::g_batteryPreset[bm].internalResistance));
70 energySource->SetAttribute("TypicalDischargeCurrent",
71 DoubleValue(energy::g_batteryPreset[bm].typicalCurrent));
72 energySource->SetAttribute("CutoffVoltage",
73 DoubleValue(energy::g_batteryPreset[bm].cuttoffVoltage));
74
75 energySource->SetAttribute("BatteryType", EnumValue(energy::g_batteryPreset[bm].batteryType));
76
77 energySource->SetNode(node);
78 return energySource;
79}
80
83{
84 energy::EnergySourceContainer batteryContainer;
85 for (auto i = c.Begin(); i != c.End(); i++)
86 {
87 Ptr<energy::EnergySource> energySource = Install(*i, bm);
88 batteryContainer.Add(energySource);
89 }
90 return batteryContainer;
91}
92
93void
95 uint8_t series,
96 uint8_t parallel) const
97{
98 NS_ASSERT_MSG(series > 0, "The value of cells in series must be > 0");
99 NS_ASSERT_MSG(parallel > 0, "The value of cells in parallel must be > 0");
100 NS_ASSERT(energySource != nullptr);
101
102 DoubleValue vFull;
103 DoubleValue q;
104 DoubleValue vExp;
105 DoubleValue qExp;
106 DoubleValue vNom;
107 DoubleValue qNom;
108 DoubleValue r;
109
110 // Get the present values of the battery cell
111 energySource->GetAttribute("FullVoltage", vFull);
112 energySource->GetAttribute("MaxCapacity", q);
113
114 energySource->GetAttribute("NominalVoltage", vNom);
115 energySource->GetAttribute("NominalCapacity", qNom);
116
117 energySource->GetAttribute("ExponentialVoltage", vExp);
118 energySource->GetAttribute("ExponentialCapacity", qExp);
119
120 energySource->GetAttribute("InternalResistance", r);
121
122 // Configuring the Cell packs
123 energySource->SetAttribute("FullVoltage", DoubleValue(vFull.Get() * series));
124 energySource->SetAttribute("MaxCapacity", DoubleValue(q.Get() * parallel));
125
126 energySource->SetAttribute("NominalVoltage", DoubleValue(vNom.Get() * series));
127 energySource->SetAttribute("NominalCapacity", DoubleValue(qNom.Get() * parallel));
128
129 energySource->SetAttribute("ExponentialVoltage", DoubleValue(vExp.Get() * series));
130 energySource->SetAttribute("ExponentialCapacity", DoubleValue(qExp.Get() * parallel));
131
132 energySource->SetAttribute("InternalResistance", DoubleValue(r.Get() * (series / parallel)));
133}
134
135void
137 uint8_t series,
138 uint8_t parallel) const
139{
140 NS_ASSERT_MSG(energySourceContainer.GetN() > 0, "This energy container is empty");
141
142 for (auto i = energySourceContainer.Begin(); i != energySourceContainer.End(); i++)
143 {
144 SetCellPack(*i, series, parallel);
145 }
146}
147
148} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
double Get() const
Definition double.cc:26
Hold variables of type enum.
Definition enum.h:52
void Set(std::string name, const AttributeValue &v) override
Sets one of the attributes of underlying EnergySource.
void SetCellPack(Ptr< energy::EnergySource > energySource, uint8_t series, uint8_t parallel) const
This function takes an existing energy source and transform its values to form a group of connected i...
ObjectFactory m_batteryModel
The energy source (battery) used by this helper.
Ptr< energy::EnergySource > DoInstall(Ptr< Node > node) const override
Child classes of EnergySourceHelper only have to implement this function, to create and aggregate an ...
Ptr< energy::EnergySourceContainer > Install(NodeContainer c) const
This function installs energy sources in a group of nodes in a node container.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Holds a vector of ns3::EnergySource pointers.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
void Add(EnergySourceContainer container)
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Energy source base class.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
static BatteryPresets g_batteryPreset[]
Contains the values that form the battery presents available in this module.
BatteryModel
Battery models that described the parameters of the the battery presets.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.