SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
StorageUnit.hpp
Go to the documentation of this file.
1/*
2 * StorageUnit.hpp
3 *
4 * parent class for all cells and modules, interface (ie only defines very general functions)
5 *
6 * Created on: 9 Dec 2019
7 * Author(s): Jorn Reniers, Volkan Kumtepeli
8 *
9 */
10
11#pragma once
12
13#include "settings/settings.hpp"
14#include "types/Status.hpp"
15#include "types/Deep_ptr.hpp"
17
18#include <string>
19#include <cstdlib>
20#include <vector>
21#include <span>
22#include <string_view>
23#include <utility>
24
25namespace slide {
27{
28protected:
29 std::string ID{ "StorageUnit" };
30 StorageUnit *parent{ nullptr };
31 bool blockDegAndTherm{ false };
32 using setStates_t = std::span<double> &;
33 using getStates_t = std::vector<double> &;
34 using viewStates_t = std::span<double>;
35 virtual size_t calculateNcells() { return 0; }
36
37public:
39 StorageUnit() = default;
40 StorageUnit(std::string_view ID_) : ID(ID_) {}
41 StorageUnit(std::string_view ID_, StorageUnit *parent_, bool blockDegAndTherm_)
42 : ID(ID_), parent(parent_), blockDegAndTherm(blockDegAndTherm_) {}
43
44 virtual ~StorageUnit() = default;
45 const std::string &getID() { return ID; }
46 void setID(std::string IDi) { ID = std::move(IDi); }
47
49 virtual std::string getFullID() { return (parent != nullptr) ? parent->getFullID() + "_" + getID() : getID(); }
50
51 virtual double Cap() const = 0; //
52
53 auto *getParent() { return parent; };
54
55 virtual double I() const = 0; //
56 virtual double getRtot() = 0;
57 virtual size_t getNcells() = 0;
58
59 inline bool isCharging() { return I() < 0; }
60 inline bool isDischarging() { return I() > 0; }
61
62 virtual void getStates(getStates_t s) = 0;
63 virtual viewStates_t viewStates() { return {}; }
64 void setBlockDegAndTherm(bool block) { blockDegAndTherm = block; }
65 virtual void setParent(StorageUnit *p) { parent = p; }
66 virtual Status setCurrent(double Inew, bool checkV = true, bool print = true) = 0; //
67 virtual Status setVoltage(double Vnew, bool checkI = true, bool print = true)
68 {
69 return free::setVoltage_iterative(this, Vnew);
70 }
71
72
73 virtual Status setStates(setStates_t s, bool checkStates = true, bool print = true) = 0;
74
75 virtual void backupStates() {}
76 virtual void restoreStates() {}
77
81 virtual double getOCV() = 0;
82 virtual double V() = 0;
83 virtual Status checkVoltage(double &v, bool print) noexcept = 0;
84 virtual double getVhigh() = 0;
85 virtual double getVlow() = 0;
87 virtual double Vmin() const = 0;
88 virtual double VMIN() const = 0;
89 virtual double Vmax() const = 0;
90 virtual double VMAX() const = 0;
93 virtual double T() = 0;
94 virtual double getThotSpot() = 0;
95 virtual double getThermalSurface() = 0;
96 virtual double thermalModel(int Nneighb, double Tneighb[], double Kneighb[], double Aneighb[], double tim) = 0;
97 virtual void setT(double Tnew) = 0;
100 virtual bool validStates(bool print = true) = 0;
101 virtual StorageUnit *copy() = 0;
102 virtual void timeStep_CC(double dt, int steps = 1) = 0;
105 virtual void storeData() = 0;
106 virtual void writeData(const std::string &prefix) = 0;
107};
108
109// Free functions:
110// template <typename T, typename... Args>
111// auto make_SU(Args &&...args) { return Deep_ptr<StorageUnit>(new T(std::forward<Args>(args)...)); }
112
113template <typename T, typename... Args>
114auto make_SU(Args &&...args)
115{
116 return Deep_ptr<StorageUnit>(std::unique_ptr<T>(new T(std::forward<Args>(args)...)));
117}
118
119} // namespace slide
Definition: Deep_ptr.hpp:23
Definition: StorageUnit.hpp:27
virtual double getThotSpot()=0
the T of the hottest element in the SU
bool blockDegAndTherm
if true, degradation and the thermal ODE are ignored
Definition: StorageUnit.hpp:31
std::span< double > viewStates_t
Definition: StorageUnit.hpp:34
virtual void setT(double Tnew)=0
functionality
virtual void writeData(const std::string &prefix)=0
StorageUnit * parent
pointer to the SU 'above' this one [e.g. the module to which a cell is connected]
Definition: StorageUnit.hpp:30
const std::string & getID()
Definition: StorageUnit.hpp:45
virtual Status setVoltage(double Vnew, bool checkI=true, bool print=true)
Definition: StorageUnit.hpp:67
StorageUnit()=default
< basic getters and setters
virtual void timeStep_CC(double dt, int steps=1)=0
take a number of time steps
virtual double getOCV()=0
std::string ID
identification string
Definition: StorageUnit.hpp:29
virtual ~StorageUnit()=default
virtual double getThermalSurface()=0
return the 'A' for the thermal model of this SU (Q = hA*dT)
virtual double Vmin() const =0
lower voltage limit of the cell
virtual double I() const =0
virtual size_t getNcells()=0
return the number of single cells connected to this SU
virtual size_t calculateNcells()
Definition: StorageUnit.hpp:35
virtual void backupStates()
Back-up states.
Definition: StorageUnit.hpp:75
virtual double thermalModel(int Nneighb, double Tneighb[], double Kneighb[], double Aneighb[], double tim)=0
calculate the thermal model of this SU
virtual double getVhigh()=0
return the voltage of the cell with the highest voltage
virtual void restoreStates()
restore backed-up states.
Definition: StorageUnit.hpp:76
virtual void setParent(StorageUnit *p)
set the parent
Definition: StorageUnit.hpp:65
virtual double VMAX() const =0
safety cut off
virtual viewStates_t viewStates()
Only for cells to see individual states.
Definition: StorageUnit.hpp:63
virtual void getStates(getStates_t s)=0
returns one long array with the states
bool isCharging()
negative means charge.
Definition: StorageUnit.hpp:59
bool isDischarging()
positive means discharge.
Definition: StorageUnit.hpp:60
virtual void storeData()=0
virtual Status setStates(setStates_t s, bool checkStates=true, bool print=true)=0
opposite of getStates, check the states are valid?
virtual double Vmax() const =0
upper voltage limit of the cell
auto * getParent()
Definition: StorageUnit.hpp:53
virtual double getVlow()=0
return the voltage of the cell with the lowest voltage
virtual Status setCurrent(double Inew, bool checkV=true, bool print=true)=0
virtual double Cap() const =0
virtual double VMIN() const =0
safety cut off
std::span< double > & setStates_t
To pass states to read, non-expandable container.
Definition: StorageUnit.hpp:32
virtual StorageUnit * copy()=0
copy this SU to a new object
virtual std::string getFullID()
Definition: StorageUnit.hpp:49
virtual double T()=0
StorageUnit(std::string_view ID_, StorageUnit *parent_, bool blockDegAndTherm_)
Definition: StorageUnit.hpp:41
void setBlockDegAndTherm(bool block)
Definition: StorageUnit.hpp:64
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
StorageUnit(std::string_view ID_)
Definition: StorageUnit.hpp:40
virtual Status checkVoltage(double &v, bool print) noexcept=0
get the voltage and check if it is valid
void setID(std::string IDi)
Return the full ID string, including the ID of the parent module.
Definition: StorageUnit.hpp:46
virtual bool validStates(bool print=true)=0
checks if a state array is valid
virtual double getRtot()=0
Status setVoltage_iterative(Tsu *su, double Vset)
Definition: free_functions.hpp:25
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
auto make_SU(Args &&...args)
Definition: StorageUnit.hpp:114
Status
Definition: Status.hpp:15