SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
Module.hpp
Go to the documentation of this file.
1/*
2 * Module.hpp
3 *
4 * Created on: 29 Nov 2019
5 * Author(s): Jorn Reniers, Volkan Kumtepeli
6 */
7
8#pragma once
9
10#include "../StorageUnit.hpp"
11#include "../cooling/cooling.hpp"
12#include "../types/State.hpp"
13#include "../settings/settings.hpp"
14#include "../utility/utility.hpp"
15
16
17#include <vector>
18#include <cstdlib>
19#include <memory>
20#include <iostream>
21#include <span>
22
23
24namespace slide {
26{
27 double k_cell2cell{ 5 };
28 double A{ 0.0042 * 10 * settings::MODULE_NSUs_MAX };
29 double Qcontact{ 0 };
30 double time{ 0 };
31};
32
33class Module : public StorageUnit
34{
35
36public:
38 using SU_t = Deep_ptr<StorageUnit>; // #TODO in future it should store directly storage unit itself.
39 using SUs_t = std::vector<SU_t>;
40 using SUs_span_t = std::span<SU_t>;
42
43protected:
45 std::vector<double> Rcontact;
46
48 CoolSystem_t cool{ nullptr };
50
52 size_t Ncells;
53 double Vmodule{ 0 };
54 bool Vmodule_valid{ false };
55 bool par{ true };
57
59 std::vector<double> data;
60
61
62 size_t calculateNcells() override
63 {
64 /* return the number of cells connected to this module
65 * e.g. if this module has 3 child-modules, each with 2 cells.
66 * then getNSUs = 3 but getNcells = 6
67 */
69 return Ncells = transform_sum(SUs, free::get_Ncells<SU_t>);
70 }
71
72 double thermalModel_cell();
73 double thermalModel_coupled(int Nneighbours, double Tneighbours[], double Kneighbours[], double Aneighb[], double tim);
74
75public:
76 Module() : StorageUnit("Module") {}
77 Module(std::string_view ID_) : StorageUnit(ID_) {}
78 Module(std::string_view ID_, double Ti, bool print, bool pari, int Ncells, int coolControl, int cooltype);
79 Module(std::string_view ID_, double Ti, bool print, bool pari, int Ncells, CoolSystem_t &&coolControlPtr, int cooltype);
80
82 size_t getNSUs() { return SUs.size(); }
83 SUs_t &getSUs() { return SUs; }
84
85 const auto &operator[](size_t i) const { return SUs[i]; }
86 auto &operator[](size_t i) { return SUs[i]; }
87
88 virtual Status checkVoltage(double &v, bool print) noexcept override;
89 double getVhigh() override;
90 double getVlow() override;
91 void getStates(getStates_t &s) override;
92 // [s0 s1 s2 ... sn T], where s1 = cells[0].getStates()
93
94 // int Vstatus
95
96 virtual bool validStates(bool print = true) override;
97 virtual Status setStates(setStates_t s, bool checkV = true, bool print = true) override;
102
104 double T() override { return cool->T(); }
105
106 double getThermalSurface() override { return therm.A; };
107 double getCoolingLoad();
108 double thermalModel(int Nneighbours, double Tneighbours[], double Kneighbours[], double Aneighb[], double tim) override;
109
110 virtual void setSUs(SUs_span_t c, bool checkCells = true, bool print = true);
115
117
118 void setRcontact(std::span<double> Rc)
119 {
120 /*
121 * Set the contact resistance of each cell.
122 * In parallel modules, this is the 'horizontal' resistance through which all currents of the cells 'behind it' goes.
123 */
124 assert(Rc.size() == getNSUs());
125 Rcontact.resize(Rc.size());
126 std::copy(Rc.begin(), Rc.end(), Rcontact.begin());
127 Vmodule_valid = false;
128 }
129
130 virtual Module *copy() override = 0;
131
132 void storeData() override
133 {
134 for (const auto &SU : SUs)
135 SU->storeData();
136
139
141 data.insert(data.end(), { st_module.Ah(), st_module.Wh(), st_module.time(), I(), V(), T() });
142 }
143
144 void writeData(const std::string &prefix) override
145 {
146 for (const auto &SU : SUs)
147 SU->writeData(prefix);
148
149
151 {
152 std::string name = prefix + "_" + getFullID() + "_ModuleData.csv";
153
155 std::ofstream file(name, std::ios_base::app); // #TODO if first time open + header, if not append.
156
157 if (!file.is_open()) {
158 std::cerr << "ERROR in Module::writeData, could not open file " << name << '\n';
159 throw 11;
160 }
161
162 free::write_data(file, data, 6);
163
164 file.close();
165 }
166
168#if 0
169 cool->writeData(prefix + '_' + getFullID());
170#endif
171 }
172
173 void setBlockDegAndTherm(bool block)
174 {
175 for (auto &SU : SUs)
176 SU->setBlockDegAndTherm(block);
177
178 blockDegAndTherm = block;
179 }
180
181 /*****************************************************************
182 * Set the temperature of the coolant in this module.
183 * Note that it does NOT immediately change the temperatures of the child-SUs.
184 * That is done by the thermal model over time
185 *****************************************************************/
186 void setT(double Tnew) override { cool->setT(Tnew); }
187
188 /*****************************************************************
189 * return the number of cells connected to this module
190 * e.g. if this module has 3 child-modules, each with 2 cells.
191 * then getNSUs = 3 but getNcells = 6
192 *****************************************************************/
193 size_t getNcells() override { return Ncells; }
194
198 double getThotSpot() override
199 {
200 double Thot = cool->T();
201 for (const auto &SU : SUs)
202 Thot = std::max(Thot, SU->getThotSpot());
203
204 return Thot;
205 }
206};
207} // namespace slide
Definition: CoolSystem.hpp:22
virtual void storeData(size_t Ncells)
Definition: CoolSystem.cpp:282
void setT(double Tnew)
Definition: CoolSystem.cpp:110
virtual void writeData(const std::string &prefix)
Definition: CoolSystem.cpp:315
double T()
Definition: CoolSystem.hpp:59
Definition: Deep_ptr.hpp:23
T * get() const
Get the raw pointer.
Definition: Deep_ptr.hpp:76
Definition: Module.hpp:34
double Vmodule
voltage of the module
Definition: Module.hpp:53
double getVlow() override
return the voltage of the cell with the lowest voltage
Definition: Module.cpp:151
ModuleThermalParam therm
voltage
Definition: Module.hpp:49
const auto & operator[](size_t i) const
Definition: Module.hpp:85
size_t getNSUs()
note that these child-SUs can be modules themselves (or they can be cells)
Definition: Module.hpp:82
double getVhigh() override
return the voltage of the cell with the highest voltage
Definition: Module.cpp:140
size_t Ncells
Number of cells this module contains.
Definition: Module.hpp:52
double T() override
get the temperature of this module
Definition: Module.hpp:104
void setT(double Tnew) override
set a module temperature
Definition: Module.hpp:186
bool Vmodule_valid
boolean indicating if stored the voltage of the module is valid
Definition: Module.hpp:54
Module(std::string_view ID_)
Definition: Module.hpp:77
void getStates(getStates_t &s) override
returns one long array with the states: getStates-array of each cell followed by the states of the mo...
Definition: Module.cpp:161
double getThermalSurface() override
return the 'A' for the thermal model of this SU (Q = hA*dT)
Definition: Module.hpp:106
std::vector< double > data
Time data.
Definition: Module.hpp:59
virtual Status checkVoltage(double &v, bool print) noexcept override
get the voltage and check if it is valid
Definition: Module.cpp:113
double thermalModel_cell()
Definition: Module.cpp:270
State< 0, settings::data::N_CumulativeModule > st_module
Definition: Module.hpp:58
double getCoolingLoad()
return the energy required to run the entire coolingsystem of this module and all its children
Definition: Module.cpp:482
size_t getNcells() override
Definition: Module.hpp:193
auto & operator[](size_t i)
Definition: Module.hpp:86
void setRcontact(std::span< double > Rc)
Definition: Module.hpp:118
double thermalModel(int Nneighbours, double Tneighbours[], double Kneighbours[], double Aneighb[], double tim) override
calculate the thermal model of this SU
Definition: Module.cpp:456
virtual Module * copy() override=0
copy this SU to a new object
virtual bool validStates(bool print=true) override
check if a state-array is valid for this module (uses setStates)
Definition: Module.cpp:174
bool par
Definition: Module.hpp:55
double thermalModel_coupled(int Nneighbours, double Tneighbours[], double Kneighbours[], double Aneighb[], double tim)
Definition: Module.cpp:306
Deep_ptr< CoolSystem > CoolSystem_t
Definition: Module.hpp:41
void setBlockDegAndTherm(bool block)
Definition: Module.hpp:173
SUs_t SUs
Definition: Module.hpp:44
SUs_t & getSUs()
Definition: Module.hpp:83
Module()
Definition: Module.hpp:76
void storeData() override
Definition: Module.hpp:132
virtual void setSUs(SUs_span_t c, bool checkCells=true, bool print=true)
Definition: Module.cpp:66
std::vector< double > Rcontact
array with the contact resistance for cell i
Definition: Module.hpp:45
std::span< SU_t > SUs_span_t
Definition: Module.hpp:40
virtual Status setStates(setStates_t s, bool checkV=true, bool print=true) override
thermal model
Definition: Module.cpp:193
size_t calculateNcells() override
Definition: Module.hpp:62
CoolSystem_t cool
cooling system of this module //!< make<CoolSystem>(settings::MODULE_NSUs_MAX, 1);
Definition: Module.hpp:48
CoolSystem * getCoolSystem()
Definition: Module.hpp:116
double getThotSpot() override
< get the maximum temperature of the cells or the module
Definition: Module.hpp:198
void writeData(const std::string &prefix) override
Definition: Module.hpp:144
std::vector< SU_t > SUs_t
Definition: Module.hpp:39
Definition: StorageUnit.hpp:27
bool blockDegAndTherm
if true, degradation and the thermal ODE are ignored
Definition: StorageUnit.hpp:31
virtual double I() const =0
std::span< double > & setStates_t
To pass states to read, non-expandable container.
Definition: StorageUnit.hpp:32
virtual std::string getFullID()
Definition: StorageUnit.hpp:49
std::vector< double > & getStates_t
To pass states to save, expandable container.
Definition: StorageUnit.hpp:33
virtual double V()=0
print is an optional argument
void write_data(std::ofstream &file, std::vector< double > &data, size_t N=1)
Definition: free_functions.hpp:49
constexpr auto DATASTORE_MODULE
See moduleDataStorageLevel for different options.
Definition: settings.hpp:56
constexpr int MODULE_NSUs_MAX
Definition: settings.hpp:66
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
auto transform_sum(const auto &SUs, auto &function)
Definition: slide_algorithms.hpp:17
Status
Definition: Status.hpp:15
testNow Rc
Definition: simulate_ECM_modules.m:13
Definition: Module.hpp:26
double A
thermally active surface area of this module. The first number is the thermal active surface area of ...
Definition: Module.hpp:28
double time
time since the last update of the thermal model [s]
Definition: Module.hpp:30
double Qcontact
heat energy generated in the contact resistances since the last time the thermal model was solved
Definition: Module.hpp:29
double k_cell2cell
conductive heat transfer coefficient for heat transfer betweenthe child SUs
Definition: Module.hpp:27
Definition: State.hpp:24
auto Wh() const
Energy throughput [Wh].
Definition: State.hpp:35
auto Ah() const
Current throughput [Ah].
Definition: State.hpp:34
auto time() const
time [s]
Definition: State.hpp:33