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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
18 */
19
21
22namespace ns3
23{
24
26{
27 m_batteryModel.SetTypeId("ns3::GenericBatteryModel");
28}
29
31{
32}
33
34void
36{
37 m_batteryModel.Set(name, v);
38}
39
42{
43 NS_ASSERT(node != nullptr);
45 NS_ASSERT(energySource != nullptr);
46 energySource->SetNode(node);
47 return energySource;
48}
49
52{
53 Ptr<energy::EnergySourceContainer> batteryContainer =
54 CreateObject<energy::EnergySourceContainer>();
55 for (auto i = c.Begin(); i != c.End(); i++)
56 {
57 batteryContainer->Add(DoInstall(*i));
58 }
59 return batteryContainer;
60}
61
64{
65 NS_ASSERT(node != nullptr);
67 NS_ASSERT(energySource != nullptr);
68
69 energySource->SetAttribute("FullVoltage", DoubleValue(energy::g_batteryPreset[bm].vFull));
70 energySource->SetAttribute("MaxCapacity", DoubleValue(energy::g_batteryPreset[bm].qMax));
71
72 energySource->SetAttribute("NominalVoltage", DoubleValue(energy::g_batteryPreset[bm].vNom));
73 energySource->SetAttribute("NominalCapacity", DoubleValue(energy::g_batteryPreset[bm].qNom));
74
75 energySource->SetAttribute("ExponentialVoltage", DoubleValue(energy::g_batteryPreset[bm].vExp));
76 energySource->SetAttribute("ExponentialCapacity",
78
79 energySource->SetAttribute("InternalResistance",
80 DoubleValue(energy::g_batteryPreset[bm].internalResistance));
81 energySource->SetAttribute("TypicalDischargeCurrent",
82 DoubleValue(energy::g_batteryPreset[bm].typicalCurrent));
83 energySource->SetAttribute("CutoffVoltage",
84 DoubleValue(energy::g_batteryPreset[bm].cuttoffVoltage));
85
86 energySource->SetAttribute("BatteryType", EnumValue(energy::g_batteryPreset[bm].batteryType));
87
88 energySource->SetNode(node);
89 return energySource;
90}
91
94{
95 energy::EnergySourceContainer batteryContainer;
96 for (auto i = c.Begin(); i != c.End(); i++)
97 {
98 Ptr<energy::EnergySource> energySource = Install(*i, bm);
99 batteryContainer.Add(energySource);
100 }
101 return batteryContainer;
102}
103
104void
106 uint8_t series,
107 uint8_t parallel) const
108{
109 NS_ASSERT_MSG(series > 0, "The value of cells in series must be > 0");
110 NS_ASSERT_MSG(parallel > 0, "The value of cells in parallel must be > 0");
111 NS_ASSERT(energySource != nullptr);
112
113 DoubleValue vFull;
114 DoubleValue q;
115 DoubleValue vExp;
116 DoubleValue qExp;
117 DoubleValue vNom;
118 DoubleValue qNom;
119 DoubleValue r;
120
121 // Get the present values of the battery cell
122 energySource->GetAttribute("FullVoltage", vFull);
123 energySource->GetAttribute("MaxCapacity", q);
124
125 energySource->GetAttribute("NominalVoltage", vNom);
126 energySource->GetAttribute("NominalCapacity", qNom);
127
128 energySource->GetAttribute("ExponentialVoltage", vExp);
129 energySource->GetAttribute("ExponentialCapacity", qExp);
130
131 energySource->GetAttribute("InternalResistance", r);
132
133 // Configuring the Cell packs
134 energySource->SetAttribute("FullVoltage", DoubleValue(vFull.Get() * series));
135 energySource->SetAttribute("MaxCapacity", DoubleValue(q.Get() * parallel));
136
137 energySource->SetAttribute("NominalVoltage", DoubleValue(vNom.Get() * series));
138 energySource->SetAttribute("NominalCapacity", DoubleValue(qNom.Get() * parallel));
139
140 energySource->SetAttribute("ExponentialVoltage", DoubleValue(vExp.Get() * series));
141 energySource->SetAttribute("ExponentialCapacity", DoubleValue(qExp.Get() * parallel));
142
143 energySource->SetAttribute("InternalResistance", DoubleValue(r.Get() * (series / parallel)));
144}
145
146void
148 uint8_t series,
149 uint8_t parallel) const
150{
151 NS_ASSERT_MSG(energySourceContainer.GetN() > 0, "This energy container is empty");
152
153 for (auto i = energySourceContainer.Begin(); i != energySourceContainer.End(); i++)
154 {
155 SetCellPack(*i, series, parallel);
156 }
157}
158
159} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double Get() const
Definition: double.cc:37
Hold variables of type enum.
Definition: enum.h:62
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.
Definition: ptr.h:77
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.
Definition: energy-source.h:88
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.