Line data Source code
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" 16 : #include "utility/free_functions.hpp" 17 : 18 : #include <string> 19 : #include <cstdlib> 20 : #include <vector> 21 : #include <span> 22 : #include <string_view> 23 : #include <utility> 24 : 25 : namespace slide { 26 : class StorageUnit 27 : { 28 : protected: 29 : std::string ID{ "StorageUnit" }; //!< identification string 30 : StorageUnit *parent{ nullptr }; //!< pointer to the SU 'above' this one [e.g. the module to which a cell is connected] 31 : bool blockDegAndTherm{ false }; //!< if true, degradation and the thermal ODE are ignored 32 : using setStates_t = std::span<double> &; //!< To pass states to read, non-expandable container. 33 : using getStates_t = std::vector<double> &; //!< To pass states to save, expandable container. 34 : using viewStates_t = std::span<double>; 35 0 : virtual size_t calculateNcells() { return 0; } 36 : 37 : public: 38 : //!< basic getters and setters 39 : StorageUnit() = default; 40 235 : 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 245 : virtual ~StorageUnit() = default; 45 425 : const std::string &getID() { return ID; } 46 : void setID(std::string IDi) { ID = std::move(IDi); } 47 : 48 : //!< Return the full ID string, including the ID of the parent module 49 836 : virtual std::string getFullID() { return (parent != nullptr) ? parent->getFullID() + "_" + getID() : getID(); } 50 : 51 : virtual double Cap() const = 0; // 52 : 53 62 : auto *getParent() { return parent; }; 54 : 55 : virtual double I() const = 0; // 56 : virtual double getRtot() = 0; 57 : virtual size_t getNcells() = 0; //!< return the number of single cells connected to this SU 58 : 59 17311 : inline bool isCharging() { return I() < 0; } //!< negative means charge. 60 23185 : inline bool isDischarging() { return I() > 0; } //!< positive means discharge. 61 : 62 : virtual void getStates(getStates_t s) = 0; //!< returns one long array with the states 63 0 : virtual viewStates_t viewStates() { return {}; } //!< Only for cells to see individual states. 64 0 : void setBlockDegAndTherm(bool block) { blockDegAndTherm = block; } 65 168 : virtual void setParent(StorageUnit *p) { parent = p; } //!< set the parent 66 : virtual Status setCurrent(double Inew, bool checkV = true, bool print = true) = 0; // 67 186051 : virtual Status setVoltage(double Vnew, bool checkI = true, bool print = true) 68 : { 69 186051 : return free::setVoltage_iterative(this, Vnew); 70 : } 71 : 72 : 73 : virtual Status setStates(setStates_t s, bool checkStates = true, bool print = true) = 0; //!< opposite of getStates, check the states are valid? 74 : 75 0 : virtual void backupStates() {} //!< Back-up states. 76 0 : virtual void restoreStates() {} //!< restore backed-up states. 77 : 78 : //!< virtual int getNstates() = 0; 79 : //!< virtual double SOC() = 0; 80 : //!< voltage 81 : virtual double getOCV() = 0; 82 : virtual double V() = 0; //!< print is an optional argument 83 : virtual Status checkVoltage(double &v, bool print) noexcept = 0; //!< get the voltage and check if it is valid 84 : virtual double getVhigh() = 0; //!< return the voltage of the cell with the highest voltage 85 : virtual double getVlow() = 0; //!< return the voltage of the cell with the lowest voltage 86 : 87 : virtual double Vmin() const = 0; //!< lower voltage limit of the cell 88 : virtual double VMIN() const = 0; //!< safety cut off 89 : virtual double Vmax() const = 0; //!< upper voltage limit of the cell 90 : virtual double VMAX() const = 0; //!< safety cut off 91 : 92 : //!< thermal model 93 : virtual double T() = 0; 94 : virtual double getThotSpot() = 0; //!< the T of the hottest element in the SU 95 : virtual double getThermalSurface() = 0; //!< return the 'A' for the thermal model of this SU (Q = hA*dT) 96 : virtual double thermalModel(int Nneighb, double Tneighb[], double Kneighb[], double Aneighb[], double tim) = 0; //!< calculate the thermal model of this SU 97 : virtual void setT(double Tnew) = 0; 98 : 99 : //!< functionality 100 : virtual bool validStates(bool print = true) = 0; //!< checks if a state array is valid 101 : virtual StorageUnit *copy() = 0; //!< copy this SU to a new object 102 : virtual void timeStep_CC(double dt, int steps = 1) = 0; //!< take a number of time steps 103 : 104 : //!< Data collection of cycling data (I, V, T, etc. for every cell) 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 : 113 : template <typename T, typename... Args> 114 : auto 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