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<EnergySourceContainer> batteryContainer = CreateObject<EnergySourceContainer>();
54 for (auto i = c.Begin(); i != c.End(); i++)
55 {
56 batteryContainer->Add(DoInstall(*i));
57 }
58 return batteryContainer;
59}
60
63{
64 NS_ASSERT(node != nullptr);
66 NS_ASSERT(energySource != nullptr);
67
68 energySource->SetAttribute("FullVoltage", DoubleValue(g_batteryPreset[bm].vFull));
69 energySource->SetAttribute("MaxCapacity", DoubleValue(g_batteryPreset[bm].qMax));
70
71 energySource->SetAttribute("NominalVoltage", DoubleValue(g_batteryPreset[bm].vNom));
72 energySource->SetAttribute("NominalCapacity", DoubleValue(g_batteryPreset[bm].qNom));
73
74 energySource->SetAttribute("ExponentialVoltage", DoubleValue(g_batteryPreset[bm].vExp));
75 energySource->SetAttribute("ExponentialCapacity", DoubleValue(g_batteryPreset[bm].qExp));
76
77 energySource->SetAttribute("InternalResistance",
78 DoubleValue(g_batteryPreset[bm].internalResistance));
79 energySource->SetAttribute("TypicalDischargeCurrent",
80 DoubleValue(g_batteryPreset[bm].typicalCurrent));
81 energySource->SetAttribute("CutoffVoltage", DoubleValue(g_batteryPreset[bm].cuttoffVoltage));
82
83 energySource->SetAttribute("BatteryType", EnumValue(g_batteryPreset[bm].batteryType));
84
85 energySource->SetNode(node);
86 return energySource;
87}
88
91{
92 EnergySourceContainer batteryContainer;
93 for (auto i = c.Begin(); i != c.End(); i++)
94 {
95 Ptr<EnergySource> energySource = Install(*i, bm);
96 batteryContainer.Add(energySource);
97 }
98 return batteryContainer;
99}
100
101void
103 uint8_t series,
104 uint8_t parallel) const
105{
106 NS_ASSERT_MSG(series > 0, "The value of cells in series must be > 0");
107 NS_ASSERT_MSG(parallel > 0, "The value of cells in parallel must be > 0");
108 NS_ASSERT(energySource != nullptr);
109
110 DoubleValue vFull;
111 DoubleValue q;
112 DoubleValue vExp;
113 DoubleValue qExp;
114 DoubleValue vNom;
115 DoubleValue qNom;
116 DoubleValue r;
117
118 // Get the present values of the battery cell
119 energySource->GetAttribute("FullVoltage", vFull);
120 energySource->GetAttribute("MaxCapacity", q);
121
122 energySource->GetAttribute("NominalVoltage", vNom);
123 energySource->GetAttribute("NominalCapacity", qNom);
124
125 energySource->GetAttribute("ExponentialVoltage", vExp);
126 energySource->GetAttribute("ExponentialCapacity", qExp);
127
128 energySource->GetAttribute("InternalResistance", r);
129
130 // Configuring the Cell packs
131 energySource->SetAttribute("FullVoltage", DoubleValue(vFull.Get() * series));
132 energySource->SetAttribute("MaxCapacity", DoubleValue(q.Get() * parallel));
133
134 energySource->SetAttribute("NominalVoltage", DoubleValue(vNom.Get() * series));
135 energySource->SetAttribute("NominalCapacity", DoubleValue(qNom.Get() * parallel));
136
137 energySource->SetAttribute("ExponentialVoltage", DoubleValue(vExp.Get() * series));
138 energySource->SetAttribute("ExponentialCapacity", DoubleValue(qExp.Get() * parallel));
139
140 energySource->SetAttribute("InternalResistance", DoubleValue(r.Get() * (series / parallel)));
141}
142
143void
145 uint8_t series,
146 uint8_t parallel) const
147{
148 NS_ASSERT_MSG(energySourceContainer.GetN() > 0, "This energy container is empty");
149
150 for (auto i = energySourceContainer.Begin(); i != energySourceContainer.End(); i++)
151 {
152 SetCellPack(*i, series, parallel);
153 }
154}
155
156} // 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
Holds a vector of ns3::EnergySource pointers.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
void Add(EnergySourceContainer container)
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Introspection did not find any typical Config paths.
Definition: energy-source.h:87
Hold variables of type enum.
Definition: enum.h:62
Ptr< EnergySource > DoInstall(Ptr< Node > node) const override
Child classes of EnergySourceHelper only have to implement this function, to create and aggregate an ...
void Set(std::string name, const AttributeValue &v) override
Sets one of the attributes of underlying EnergySource.
ObjectFactory m_batteryModel
The energy source (battery) used by this helper.
void SetCellPack(Ptr< 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...
Ptr< 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
#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.