A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
generic-battery-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 Tokushima University, Japan
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
7
* Based on the works of Andrea Sacco (2010)
8
*/
9
10
#include "ns3/core-module.h"
11
#include "ns3/energy-module.h"
12
13
using namespace
ns3
;
14
using namespace
ns3::energy
;
15
16
/**
17
* @ingroup energy-tests
18
*
19
* @brief Discharge a battery test
20
*/
21
class
DischargeBatteryTestCase
:
public
TestCase
22
{
23
public
:
24
DischargeBatteryTestCase
();
25
26
void
DoRun
()
override
;
27
28
Ptr<Node>
m_node
;
//!< Node to aggregate the source to.
29
};
30
31
DischargeBatteryTestCase::DischargeBatteryTestCase
()
32
:
TestCase
(
"Discharge a Li-Ion Panasonic CGR18650DA battery"
)
33
{
34
}
35
36
void
37
DischargeBatteryTestCase::DoRun
()
38
{
39
// This test demonstrates that the battery reach its cutoff voltage in a little less than 1
40
// hour. When discharged with a constant current of 2.33 A (Equivalent to 1C).
41
// Note: The cutoff voltage is only reached within this time for the specified battery
42
// (PANASONIC CGR18650DA Li-Ion).
43
44
Ptr<Node>
node =
CreateObject<Node>
();
45
GenericBatteryModelHelper
batteryHelper;
46
Ptr<GenericBatteryModel>
batteryModel =
47
DynamicCast<GenericBatteryModel>
(batteryHelper.
Install
(node,
PANASONIC_CGR18650DA_LION
));
48
49
Ptr<SimpleDeviceEnergyModel>
consumptionEnergyModel =
CreateObject<SimpleDeviceEnergyModel>
();
50
consumptionEnergyModel->SetEnergySource(batteryModel);
51
batteryModel->AppendDeviceEnergyModel(consumptionEnergyModel);
52
consumptionEnergyModel->SetNode(node);
53
54
// Discharge the battery with a constant current of 2.33 A (1C)
55
consumptionEnergyModel->SetCurrentA(2.33);
56
57
Simulator::Stop
(
Seconds
(3459));
58
Simulator::Run
();
59
Simulator::Destroy
();
60
61
NS_TEST_ASSERT_MSG_EQ_TOL
(batteryModel->GetSupplyVoltage(),
62
3.0,
63
1.0e-2,
64
"Cutoff voltage not reached"
);
65
}
66
67
/**
68
* @ingroup energy-tests
69
*
70
* @brief Generic battery TestSuite
71
*/
72
class
GenericBatteryTestSuite
:
public
TestSuite
73
{
74
public
:
75
GenericBatteryTestSuite
();
76
};
77
78
GenericBatteryTestSuite::GenericBatteryTestSuite
()
79
:
TestSuite
(
"generic-battery-test"
,
Type
::UNIT)
80
{
81
AddTestCase
(
new
DischargeBatteryTestCase
, TestCase::Duration::QUICK);
82
}
83
84
/// create an instance of the test suite
85
static
GenericBatteryTestSuite
g_genericBatteryTestSuite
;
DischargeBatteryTestCase
Discharge a battery test.
Definition
generic-battery-test.cc:22
DischargeBatteryTestCase::DischargeBatteryTestCase
DischargeBatteryTestCase()
Definition
generic-battery-test.cc:31
DischargeBatteryTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
generic-battery-test.cc:37
DischargeBatteryTestCase::m_node
Ptr< Node > m_node
Node to aggregate the source to.
Definition
generic-battery-test.cc:28
GenericBatteryTestSuite
Generic battery TestSuite.
Definition
generic-battery-test.cc:73
GenericBatteryTestSuite::GenericBatteryTestSuite
GenericBatteryTestSuite()
Definition
generic-battery-test.cc:78
ns3::GenericBatteryModelHelper
Creates and assign an assortment of BatteryModels to Nodes.
Definition
generic-battery-model-helper.h:26
ns3::GenericBatteryModelHelper::Install
Ptr< energy::EnergySourceContainer > Install(NodeContainer c) const
This function installs energy sources in a group of nodes in a node container.
Definition
generic-battery-model-helper.cc:40
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
g_genericBatteryTestSuite
static GenericBatteryTestSuite g_genericBatteryTestSuite
create an instance of the test suite
Definition
generic-battery-test.cc:85
ns3::energy::PANASONIC_CGR18650DA_LION
@ PANASONIC_CGR18650DA_LION
Panasonic CGR18650DA Li-Ion battery.
Definition
generic-battery-model.h:49
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
NS_TEST_ASSERT_MSG_EQ_TOL
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition
test.h:327
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1345
ns3::energy
Definition
energy-harvester-container.cc:18
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:585
src
energy
test
generic-battery-test.cc
Generated on Mon Jun 16 2025 11:06:56 for ns-3 by
1.11.0