12#include "../../utility/utility.hpp"
13#include "../../settings/settings.hpp"
27template <
size_t N_RC = 1>
42 Cell_ECM(
double capin,
double SOCin);
43 Cell_ECM(
double capin,
double SOCin,
double Rdc_, std::array<double, N_RC> Rp_, std::array<double, N_RC> inv_tau_);
45 Cell_ECM(std::string IDi,
double capin,
double SOCin,
double Rdc_, std::array<double, N_RC> Rp_, std::array<double, N_RC> inv_tau_)
46 :
Cell_ECM(capin, SOCin, Rdc_, Rp_, inv_tau_)
52 Cell_ECM(std::string IDi,
double capin,
double SOCin)
60 inline double I()
const override {
return st.I(); }
62 inline double SOC()
override {
return st.SOC(); }
63 inline double T()
override {
return st.T(); }
66 std::span<double>
viewStates()
override {
return std::span<double>(
st.begin(),
st.end()); }
79 Status setSOC(
double SOCnew,
bool checkV =
true,
bool print =
true)
override;
80 Status setCurrent(
double Inew,
bool checkV =
true,
bool print =
true)
override;
81 Status setVoltage(
double Vnew,
bool checkI =
true,
bool print =
true)
override;
83 inline void setT(
double Tnew)
override {
st.T() = Tnew; }
85 virtual bool validStates(
bool print =
true)
override;
86 void timeStep_CC(
double dt,
int steps = 1)
override;
101 ID =
"Cell_ECM<" + std::to_string(N_RC) +
">";
107 if constexpr (N_RC >= 1) {
108 constexpr double Cp0 = 38e3;
110 inv_tau[0] = 1.0 / (Rp[0] * Cp0);
113 if constexpr (N_RC == 2) {
115 inv_tau[1] = 1.0 / 100.0;
118 OCV.check_is_fixed();
119 cellData.initialise(*
this);
127template <
size_t N_RC>
145template <
size_t N_RC>
147 std::array<double, N_RC> Rp_,
148 std::array<double, N_RC> inv_tau_)
181template <
size_t N_RC>
184 const double Iold =
I();
187 const auto status = checkCurrent(checkV, print);
202template <
size_t N_RC>
205 const double Iold = st.I();
208 const double ocv = getOCV();
209 double v_now = ocv - Vnew;
211 for (
size_t i{}; i < N_RC; i++)
212 v_now -= Rp[i] * st.Ir(i);
214 const auto Inew = v_now / Rdc;
218 const auto status = checkCurrent(checkI, print);
239template <
size_t N_RC>
245 const double SOCold = st.SOC();
251 const auto status = checkVoltage(v, print);
269template <
size_t N_RC>
274 const double ocv = getOCV();
275 double v_now = ocv - Rdc * st.I();
277 for (
size_t i{}; i < N_RC; i++)
278 v_now -= Rp[i] * st.Ir(i);
283 std::cerr <<
"ERROR in Cell_ECM::getV when getting the OCV.\n";
288template <
size_t N_RC>
293 const auto st_old = st;
295 std::copy(s.begin(), s.begin() + st.size(), st.begin());
296 s = s.last(s.size() - st.size());
306template <
size_t N_RC>
321 if (T() < Tmin() || T() > Tmax()) {
323 std::cerr <<
"ERROR in Cell_ECM::validState, T is outside of the range, "
324 << Tmin() <<
" <= T <= " << Tmax()
325 <<
", value is " << T() <<
'\n';
333template <
size_t N_RC>
341 std::cerr <<
"ERROR in Cell_ECM::timeStep_CC, the time step dt must be "
342 <<
"0 or positive, but has value " << dt <<
'\n';
346 const auto dth = dt / 3600.0;
348 for (
int t = 0; t < nstep; t++) {
350 const auto dAh = st.I() * dth;
351 st.SOC() -= dAh / Cap();
353 for (
size_t i{}; i < N_RC; i++)
354 st.Ir(i) += dt * inv_tau[i] * (st.I() - st.Ir(i));
359 st.Ah() += std::abs(dAh);
360 st.Wh() += std::abs(dAh *
V());
State_ECM class definition.
Definition: Cell_ECM.hpp:29
ThroughputData getThroughputs() override
Definition: Cell_ECM.hpp:88
State_ECM< N_RC > st
parameters:
Definition: Cell_ECM.hpp:32
std::span< double > viewStates() override
Only for cells to see individual states.
Definition: Cell_ECM.hpp:66
Cell_ECM(std::string IDi, double capin, double SOCin)
Definition: Cell_ECM.hpp:52
double T() override
overwrite from Cell
Definition: Cell_ECM.hpp:63
Cell_ECM(std::string IDi)
Definition: Cell_ECM.hpp:58
Cell_ECM(std::string IDi, double capin, double SOCin, double Rdc_, std::array< double, N_RC > Rp_, std::array< double, N_RC > inv_tau_)
Definition: Cell_ECM.hpp:45
void timeStep_CC(double dt, int steps=1) override
take a number of time steps
Definition: Cell_ECM.hpp:334
double getThermalSurface() override
return the 'A' for the thermal model of this SU (Q = hA*dT)
Definition: Cell_ECM.hpp:76
void setT(double Tnew) override
functionality
Definition: Cell_ECM.hpp:83
Cell_ECM()
Definition: Cell_ECM.hpp:99
Status setSOC(double SOCnew, bool checkV=true, bool print=true) override
Definition: Cell_ECM.hpp:240
Status setVoltage(double Vnew, bool checkI=true, bool print=true) override
Definition: Cell_ECM.hpp:203
auto & getStateObj()
Definition: Cell_ECM.hpp:69
double V() override
crit is an optional argument
Definition: Cell_ECM.hpp:270
double I() const override
Definition: Cell_ECM.hpp:60
virtual bool validStates(bool print=true) override
checks if a state array is valid
Definition: Cell_ECM.hpp:307
std::array< double, N_RC > inv_tau
Definition: Cell_ECM.hpp:35
Status setStates(setStates_t s, bool checkStates=true, bool print=true) override
opposite of getStates, check the states are valid?
Definition: Cell_ECM.hpp:289
std::array< double, N_RC > Rp
Definition: Cell_ECM.hpp:35
XYdata_ff OCV
SOC vs voltage curve.
Definition: Cell_ECM.hpp:37
double Rdc
DC resistance [Ohm].
Definition: Cell_ECM.hpp:38
Status setCurrent(double Inew, bool checkV=true, bool print=true) override
Definition: Cell_ECM.hpp:182
void getStates(getStates_t s) override
returns one long array with the states
Definition: Cell_ECM.hpp:67
double SOC() override
Definition: Cell_ECM.hpp:62
Cell_ECM< N_RC > * copy() override
copy this SU to a new object
Definition: Cell_ECM.hpp:90
double getRtot() override
Return the total resistance, V = OCV - I*Rtot.
Definition: Cell_ECM.hpp:74
double getThotSpot() override
the T of the hottest element in the SU
Definition: Cell_ECM.hpp:75
double getOCV() override
Not implemented?
Definition: Cell_ECM.hpp:77
double getIr()
current through the parallel resistance
Definition: Cell_ECM.hpp:61
Abstract Class representing a single battery cell.
Definition: Cell.hpp:33
void setCapacity(double capacity)
Definition: Cell.hpp:48
std::string ID
identification string
Definition: StorageUnit.hpp:29
std::span< double > & setStates_t
To pass states to read, non-expandable container.
Definition: StorageUnit.hpp:32
std::vector< double > & getStates_t
To pass states to save, expandable container.
Definition: StorageUnit.hpp:33
double interp(double x_i, bool print=false, bool bound=true)
Definition: XYdata.hpp:64
auto check_SOC(double SOCnew, double SOC_min=0, double SOC_max=1)
Definition: free_functions.hpp:104
auto check_Cell_states(auto &su, bool checkV)
Definition: free_functions.hpp:118
constexpr bool storeCumulativeData
Definition: derived_settings.hpp:19
constexpr auto printCrit
threshold of verbose of when to print error messages for critical errors
Definition: derived_settings.hpp:30
constexpr double T_ENV
environmental temperature
Definition: settings.hpp:70
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
bool isStatusBad(Status status)
Definition: Status.hpp:50
FixedData< double > linspace_fix(double x1, double x2, int N)
Definition: util.hpp:108
Status
Definition: Status.hpp:15
out SOC
Definition: squeeze_variables.m:15
out I
Definition: squeeze_variables.m:14
out V
Definition: squeeze_variables.m:16
State_ECM template class for holding the states of the ECM model.
Definition: State_ECM.hpp:20