SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
StateStorage.hpp
Go to the documentation of this file.
1/*
2 * StateStorage.hpp
3 *
4 * Created on: 24 May 2022
5 * Author(s): Jorn Reniers, Volkan Kumtepeli
6 */
7
8#pragma once
9
10#include <vector>
11#include <span>
12#include <type_traits>
13#include <algorithm>
14
15namespace slide {
17{
18 std::vector<std::span<double>> state_span;
19 std::vector<double> states;
20
21public:
22 size_t index{ 0 };
23 constexpr void clear() noexcept
24 {
25 state_span.clear();
26 states.clear();
27 index = 0;
28 }
29
30 template <typename T>
31 void add(T &x)
32 {
33 add({ &x, 1 });
34 }
35
36 template <typename T>
37 void add(std::span<T> x)
38 {
39 state_span.emplace_back(x);
40 states.insert(states.end(), x.begin(), x.end());
41 }
42
43 [[nodiscard]] constexpr auto begin() noexcept { return states.begin(); }
44 [[nodiscard]] constexpr auto end() noexcept { return states.end(); }
45
46 void restore()
47 {
48 size_t i{ 0 };
49
50 for (auto spn : state_span) {
51 std::copy_n(states.begin() + i, spn.size(), spn.begin());
52 i += spn.size();
53 }
54 }
55};
56} // namespace slide
Definition: StateStorage.hpp:17
constexpr void clear() noexcept
Definition: StateStorage.hpp:23
void add(std::span< T > x)
Definition: StateStorage.hpp:37
size_t index
Definition: StateStorage.hpp:22
constexpr auto end() noexcept
Definition: StateStorage.hpp:44
void add(T &x)
Definition: StateStorage.hpp:31
void restore()
Definition: StateStorage.hpp:46
constexpr auto begin() noexcept
Definition: StateStorage.hpp:43
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27