12#include "../settings/settings.hpp"
13#include "../types/Status.hpp"
24template <
typename Tsu>
29 constexpr int maxIteration = 50;
32 for (
int iter{ 0 }; iter < maxIteration; iter++) {
33 const auto Va = su->V();
34 if (std::abs(Vset - Va) < 1e-6)
37 const auto Ib = (Vset > Va) ? Ia - 0.01 * su->Cap() : Ia + 0.01 * su->Cap();
39 const auto Vb = su->V();
41 const double slope = (Ia - Ib) / (Va - Vb);
42 Ia = Ib - (Vb - Vset) * slope;
49inline void write_data(std::ofstream &file, std::vector<double> &data,
size_t N = 1)
51 for (
size_t i{}; i < data.size(); i++) {
71 return SU->getNcells();
75auto get_V(T
const &SU) {
return SU.V(); }
78auto get_T(T
const &SU) {
return SU->T(); }
82auto get_Vmin(
const T &SU) {
return SU->Vmin(); }
85auto get_VMIN(
const T &SU) {
return SU->VMIN(); }
88auto get_Vmax(
const T &SU) {
return SU->Vmax(); }
91auto get_VMAX(
const T &SU) {
return SU->VMAX(); }
94auto get_Cap(
const T &SU) {
return SU->Cap(); }
97auto get_OCV(
const T &SU) {
return SU->getOCV(); }
100auto get_I(
const T &SU) {
return SU->I(); }
103template <
bool Pr
int = settings::pr
intBool::pr
intCrit>
104auto inline check_SOC(
double SOCnew,
double SOC_min = 0,
double SOC_max = 1)
106 if (SOCnew < SOC_min || SOCnew > SOC_max)
109 std::cerr <<
"ERROR in some Cell, illegal input value of SOC: "
110 << SOCnew <<
" while the minimum is " << SOC_min
111 <<
" and maximum is " << SOC_max <<
".\n";
117template <
bool Pr
int = settings::pr
intBool::pr
intCrit>
120 if (!su.validStates(Print))
123 std::cerr <<
"ERROR in " << su.getID() <<
"::setStates, illegal State.\n";
131 return su.checkVoltage(v, Print);
137template <
bool Pr
int = true>
157 std::cout <<
"We could not calculate voltage!!!\n";
163 std::cout <<
"Error in Cell::setStates when getting the voltage, which is "
164 << v <<
" restoring the old states.\n";
172 }
else if (v < su.VMIN() && su.isDischarging())
175 std::cout <<
"The voltage of cell " << su.getFullID() <<
" is " << v
176 <<
"V which is below its safety limit of "
177 << su.VMIN() <<
", cell temperature = " <<
K_to_Celsius(su.T())
178 <<
" centigrade and I = " << su.I() <<
'\n';
181 }
else if (v > su.VMAX() && su.isCharging())
184 std::cout <<
"The voltage of cell " << su.getFullID() <<
" is " << v
185 <<
"V which is above its safety limit of "
186 << su.VMAX() <<
", cell temperature = " <<
K_to_Celsius(su.T())
187 <<
" centigrade and I = " << su.I() <<
'\n';
192 std::cout <<
"The voltage of cell " << su.getFullID() <<
" is " << v
193 <<
"V which is below its minimum voltage of "
194 << su.Vmin() <<
", cell temperature = " <<
K_to_Celsius(su.T())
195 <<
" centigrade and I = " << su.I() <<
'\n';
201 std::cout <<
"The voltage of cell " << su.getFullID() <<
" is " << v
202 <<
"V which is above its maximum voltage of "
203 << su.Vmax() <<
", cell temperature = " <<
K_to_Celsius(su.T())
204 <<
" centigrade and I = " << su.I() <<
'\n';
212template <
bool Pr
int = settings::pr
intBool::pr
intCrit>
215 const auto SafetyVmin = cyc.getSafetyVmin();
216 const auto SafetyVmax = cyc.getSafetyVmax();
221 std::cout <<
"Error in Cycler::??, the voltage of " << vi
222 <<
" V is smaller than the minimum safety voltage of the cycler of "
223 << SafetyVmin <<
" V." <<
'\n';
226 }
else if (vi > SafetyVmax)
229 std::cout <<
"Error in Cycler::??, the voltage of " << vi
230 <<
" V is larger than the maximum safety voltage of the cycler of "
231 << SafetyVmax <<
" V." <<
'\n';
238template <
bool Pr
int = true>
245inline std::ofstream
openFile(
auto &SU,
const auto &folder,
const std::string &prefix,
const std::string &suffix)
247 const auto name = PathVar::results / (prefix +
"_" + SU.getFullID() +
"_" + suffix);
250 std::ofstream file(name, std::ios_base::app);
252 if (!file.is_open()) {
253 std::cerr <<
"ERROR in Cell::writeData, could not open file "
Definition: free_functions.hpp:22
auto get_V(T const &SU)
Definition: free_functions.hpp:75
auto check_SOC(double SOCnew, double SOC_min=0, double SOC_max=1)
Definition: free_functions.hpp:104
auto get_VMAX(const T &SU)
Definition: free_functions.hpp:91
auto get_Cap(const T &SU)
Definition: free_functions.hpp:94
auto check_Cell_states(auto &su, bool checkV)
Definition: free_functions.hpp:118
auto get_Vmin(const T &SU)
Definition: free_functions.hpp:82
auto check_current(bool checkV, auto &su)
Definition: free_functions.hpp:239
void write_data(std::ofstream &file, std::vector< double > &data, size_t N=1)
Definition: free_functions.hpp:49
std::ofstream openFile(auto &SU, const auto &folder, const std::string &prefix, const std::string &suffix)
Definition: free_functions.hpp:245
auto check_voltage(double &v, auto &su)
Definition: free_functions.hpp:138
auto get_VMIN(const T &SU)
Definition: free_functions.hpp:85
auto get_T(T const &SU)
Definition: free_functions.hpp:78
size_t get_Ncells(T const &SU)
Definition: free_functions.hpp:65
Status setVoltage_iterative(Tsu *su, double Vset)
Definition: free_functions.hpp:25
auto get_OCV(const T &SU)
Definition: free_functions.hpp:97
auto get_Vmax(const T &SU)
Definition: free_functions.hpp:88
auto check_safety(double vi, auto &cyc)
Definition: free_functions.hpp:213
auto get_I(const T &SU)
Definition: free_functions.hpp:100
constexpr auto printCrit
threshold of verbose of when to print error messages for critical errors
Definition: derived_settings.hpp:30
constexpr auto printNonCrit
threshold of verbose of when to print error messages for noncritical errors
Definition: derived_settings.hpp:31
constexpr double MODULE_P_V_ABSTOL
Definition: tolerances.hpp:26
Status
Definition: Status.hpp:15
@ RedistributeCurrent_failed
@ SafeVoltage
Upper part is from cycler!
@ VMAXsafety_violation
1.01 VMAX
@ VMINsafety_violation
0.99 VMIN
constexpr double K_to_Celsius(auto Kelvin)
Definition: units.hpp:31