Line data Source code
1 : /* 2 : * State_SPM.hpp 3 : * 4 : * Implements a class State which defines the state-variables of a cell for the state-space model formulation 5 : * 6 : * Created on: 12 Apr 2022 7 : * Author(s): Jorn Reniers, Volkan Kumtepeli 8 : */ 9 : 10 : #pragma once 11 : 12 : #include "../../settings/settings.hpp" 13 : #include "../../types/State.hpp" 14 : 15 : #include <cstdlib> 16 : #include <array> 17 : #include <span> 18 : 19 : namespace slide { 20 : class State_SPM : public State<29> //!< #TODO how can we make this so it takes 29=N_states from enum? 21 : { 22 : public: 23 : constexpr static auto nch = settings::nch; 24 : 25 : enum Index : size_t //!< Index variables for: 26 : { 27 : i_I, 28 : i_V, 29 : i_T, //!< cell temperature [K] 30 : i_delta, //!< thickness of the SEI layer [m] 31 : i_LLI, //!< lost lithium inventory [As] 32 : i_thickp, //!< thickness of the cathode [m] 33 : i_thickn, //!< thickness of the anode [m] 34 : i_ep, //!< volume fraction of active material in the cathode [-] 35 : i_en, //!< volume fraction of active material in the anode [-] 36 : i_ap, //!< effective surface area of the porous cathode [m2 m-3] 37 : i_an, //!< effective surface area of the porous anode [m2 m-3] 38 : i_CS, //!< surface area of the cracks at the surface of the negative particle [m2] 39 : i_Dp, //!< diffusion constant of the cathode at reference temperature [m s-1] 40 : i_Dn, //!< diffusion constant of the anode at reference temperature [m s-1] 41 : i_delta_pl, //!< thickness of the plated lithium layer [m] 42 : i_zp, //!< transformed concentration at the positive inner Chebyshev nodes of the positive particle 43 : i_zn = i_zp + nch, //!< transformed concentration at the positive inner Chebyshev nodes of the negative particle 44 : i_rDCp = i_zn + nch, //!< (ONLY CATHODE) specific resistance of both electrodes combined [Ohm m2] 45 : i_rDCn, //!< (ONLY ANODE) specific resistance of both electrodes combined [Ohm m2] 46 : i_rDCcc, //!< (ONLY SEPARATOR) specific resistance of both electrodes combined [Ohm m2] 47 : i_SOC, 48 : N_states, 49 : N_save = i_zp //!< Save until i_zp 50 : }; 51 : 52 : /* (OLD NOTE) Note on ri: 53 : * this is the resistance times the electrode surface, averaged between both electrodes. 54 : * The total cell resistance is (see Cell::getR() ): r /( (thickp*ap*elec_surf + thickn*an*elec_surf)/2 ) 55 : * with r the resistance times the average electrode surface 56 : * thicki the thickness of electrode i 57 : * ai the specific surface area of electrode i 58 : * elec_surf the geometric surface area of the electrode (height of the electrode * width of the electrode) 59 : * so if the measured DC resistance of the cell is R, the value of r can be calculated using: 60 : * ri = R * ( (thickp*ap*elec_surf + thickn*an*elec_surf)/2 ) 61 : */ 62 : 63 : using z_type = std::array<value_type, nch>; 64 : using states_type = std::array<value_type, N_states>; 65 : 66 : //!< State() = default; //!< Default constructor which DOESN'T initialise the states. All states are set to 0 67 : //!< State(const slide::states_type &s) : x{s} {} 68 : 69 130 : inline auto &zp(size_t i) { return (*this)[i_zp + i]; } //!< z_type, transformed li concentration at the positive inner nodes of the positive particle 70 140 : inline auto &zn(size_t i) { return (*this)[i_zn + i]; } //!< z_type, transformed li concentration at the positive inner nodes of the negative particle 71 : inline auto &z(size_t i) { return (*this)[i_zp + i]; } //!< Both z_p and z_n; 72 : 73 : inline auto zp() { return std::span<double>(&zp(0), &zn(0)); } 74 : inline auto zn() { return std::span<double>(&zn(0), &zn(0) + nch); } 75 : inline auto z() { return std::span<double>(&zp(0), &zn(0) + nch); } 76 : 77 : 78 83 : inline auto &T() { return (*this)[i_T]; } //!< cell temperature [K] 79 21 : inline auto &delta() { return (*this)[i_delta]; } //!< thickness of the SEI layer [m] 80 10 : inline auto &LLI() { return (*this)[i_LLI]; } //!< lost lithium [As] 81 48 : inline auto &thickp() { return (*this)[i_thickp]; } //!< thickness of the cathode [m] 82 73 : inline auto &thickn() { return (*this)[i_thickn]; } //!< thickness of the anode [m] 83 17 : inline auto &ep() { return (*this)[i_ep]; } //!< volume fraction of active material in the cathode [-] 84 17 : inline auto &en() { return (*this)[i_en]; } //!< volume fraction of active material in the anode [-] 85 50 : inline auto &ap() { return (*this)[i_ap]; } //!< effective surface area of the cathode [m2 m-3] 86 75 : inline auto &an() { return (*this)[i_an]; } //!< effective surface area of the anode [m2 m-3] 87 10 : inline auto &CS() { return (*this)[i_CS]; } //!< surface area of the cracks at the surface of the negative particle [m2] 88 25 : inline auto &Dp() { return (*this)[i_Dp]; } //!< diffusion constant at reference temperature of the cathode [m s-1] 89 25 : inline auto &Dn() { return (*this)[i_Dn]; } //!< diffusion constant at reference temperature of the anode [m s-1] 90 21 : inline auto &rDCp() { return (*this)[i_rDCp]; } //!< specific resistance (resistance times real surface area of the combined electrodes) [Ohm m2] 91 21 : inline auto &rDCn() { return (*this)[i_rDCn]; } //!< specific resistance (resistance times real surface area of the combined electrodes) [Ohm m2] 92 21 : inline auto &rDCcc() { return (*this)[i_rDCcc]; } //!< specific resistance (resistance times real surface area of the combined electrodes) [Ohm m2] 93 11 : inline auto &delta_pl() { return (*this)[i_delta_pl]; } //!< thickness of the plated lithium layer [m] 94 20 : inline auto &SOC() { return (*this)[i_SOC]; } //!< thickness of the plated lithium layer [m] 95 17 : inline auto &I() { return (*this)[i_I]; } //!< current [A] 96 : inline auto &V() { return (*this)[i_V]; } //!< voltage [V] 97 : 98 : //!< void setT(double Ti); //!< set the temperature 99 : void overwriteGeometricStates(double thickpi, double thickni, double epi, double eni, double api, double ani); //!< overwrite the states related to the geometry of a cell 100 : void overwriteCharacterisationStates(double Dpi, double Dni, double ri); //!< overwrite the states related to the characterisation of a cell 101 : 102 : std::span<double> viewGeometricStates() { return std::span<double>(&delta(), &delta_pl() + 1); } //!< #Check and fix. Why this also checks SOC? 103 : 104 : // Const methods: 105 : 106 44 : inline auto I() const { return (*this)[i_I]; } //!< current [A] 107 : }; 108 : 109 : inline void State_SPM::overwriteGeometricStates(double thickpi, double thickni, double epi, double eni, double api, double ani) 110 : { 111 : /* 112 : * Function to overwrite the geometric parameters of the state. 113 : * It also overwrites the initial states, so use it with extreme caution. 114 : * It should only be called when you are parametrising a cell (determineCharacterisation.cpp), never while cycling a cell. 115 : * 116 : * IN 117 : * thickpi thickness of the cathode [m] 118 : * thickni thickness of the anode [m] 119 : * epi volume fraction of active material in the cathode [-] 120 : * eni volume fraction of active material in the anode [-] 121 : * api effective surface area of the porous cathode [m2 m-3] 122 : * ani effective surface area of the porous anode [m2 m-3] 123 : */ 124 : 125 : //!< set the states 126 : this->thickp() = thickpi; 127 : this->thickn() = thickni; 128 : this->ep() = epi; 129 : this->en() = eni; 130 : this->ap() = api; 131 : this->an() = ani; 132 : } 133 : 134 : inline void State_SPM::overwriteCharacterisationStates(double Dpi, double Dni, double ri) 135 : { 136 : /* 137 : * Function to overwrite the parameters related to the characterisation of the cell. 138 : * The states and initial states are overwritten so use this function with caution. 139 : * It should only be called when you are parametrising a cell (determineCharacterisation.cpp), never while cycling a cell. 140 : * 141 : * IN 142 : * Dpi diffusion constant of the cathode at rate temperature [m s-1] 143 : * Dni diffusion constant of the anode at rate temperature [m s-1] 144 : * r specific resistance of the combined electrodes [Ohm m2] 145 : */ 146 : 147 : //!< Set the states 148 : this->Dp() = Dpi; 149 : this->Dn() = Dni; 150 : this->rDCp() = ri; //!< Considering both anode and cathode r is same. 151 : this->rDCn() = ri; 152 : //!< #TODO -> r was //!< the specific resistance (resistance times real surface area of the combined electrodes) [Ohm m2] 153 : } 154 : } // namespace slide