SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
DynamicMatrix.hpp
Go to the documentation of this file.
1/*
2 * DynamicMatrix.hpp
3 *
4 * Created on: 14 Jul 2022
5 * Author(s): Volkan Kumtepeli
6 */
7
8#pragma once
9
10#include <iostream>
11#include <vector>
12
13namespace slide {
14template <typename Tdata>
16{
17 using VarType = int;
18 using data_type = Tdata;
19 VarType m{}, n{};
20
21public:
22 std::vector<Tdata> data;
23 DynamicMatrix() = default;
24 DynamicMatrix(VarType m_) : m(m_), n(m_), data(m_ * m_) {}
25 DynamicMatrix(VarType m_, VarType n_) : m(m_), n(n_), data(m_ * n_) {}
26 DynamicMatrix(VarType m_, VarType n_, Tdata x) : m(m_), n(n_), data(m_ * n_, x) {}
27
28 inline void resize(VarType m_, VarType n_, Tdata x = 0)
29 {
30 m = m_;
31 n = n_;
32 data.resize(m_ * n_, x);
33 }
34
35 inline void reshape(VarType m_, VarType n_)
36 {
37 m = m_;
38 n = n_;
39
41 }
42
43 inline auto rows() const { return m; }
44 inline auto cols() const { return n; }
45 inline auto size() const { return m * n; }
46
47 inline auto &operator()(VarType i, VarType j)
48 {
49 return data[i + j * m];
50 }
51
52 inline auto operator()(VarType i, VarType j) const
53 {
54 return data[i + j * m];
55 }
56
57 void print(std::ostream &os = std::cout) const
58 {
59 for (VarType i = 0; i < m; i++) {
60 for (VarType j = 0; j < n; j++)
61 os << this->operator()(i, j) << ", ";
62
63 os << '\n';
64 }
65 }
66
67 template <typename TTdata>
68 friend std::ostream &operator<<(std::ostream &os, const DynamicMatrix<TTdata> &M);
69};
70
71template <typename Tdata>
72std::ostream &operator<<(std::ostream &os, const DynamicMatrix<Tdata> &M)
73{
74 M.print(os);
75 return os;
76}
77} // namespace slide
Definition: DynamicMatrix.hpp:16
DynamicMatrix(VarType m_, VarType n_, Tdata x)
Definition: DynamicMatrix.hpp:26
friend std::ostream & operator<<(std::ostream &os, const DynamicMatrix< TTdata > &M)
auto & operator()(VarType i, VarType j)
Definition: DynamicMatrix.hpp:47
void reshape(VarType m_, VarType n_)
Definition: DynamicMatrix.hpp:35
std::vector< Tdata > data
Definition: DynamicMatrix.hpp:22
void resize(VarType m_, VarType n_, Tdata x=0)
Definition: DynamicMatrix.hpp:28
DynamicMatrix(VarType m_)
Sequare matrix.
Definition: DynamicMatrix.hpp:24
auto rows() const
Definition: DynamicMatrix.hpp:43
void print(std::ostream &os=std::cout) const
Definition: DynamicMatrix.hpp:57
auto cols() const
Definition: DynamicMatrix.hpp:44
auto size() const
Definition: DynamicMatrix.hpp:45
auto operator()(VarType i, VarType j) const
Definition: DynamicMatrix.hpp:52
DynamicMatrix(VarType m_, VarType n_)
Definition: DynamicMatrix.hpp:25
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
std::ostream & operator<<(std::ostream &os, const DynamicMatrix< Tdata > &M)
Definition: DynamicMatrix.hpp:72