#ifndef OERSTED_MATRIXGROUP_H #define OERSTED_MATRIXGROUP_H #include "Eigen" #include "Eigen/Sparse" class SparseMatrixGroup { public: SparseMatrixGroup(size_t const Q, size_t const rows, size_t const cols, size_t const nnz) { Matrices.resize(Q); for (size_t i = 0; i != Matrices.size(); ++i) { Matrices[i].resize(rows, cols); Matrices[i].reserve(Eigen::VectorXi::Constant(cols, nnz)); } }; double &operator()(size_t const q, size_t const i, size_t const j) { return Matrices[q].coeffRef(i, j); }; auto &operator[](size_t const q) { return Matrices[q]; }; auto &operator[](size_t const q) const { return Matrices[q]; }; void transform(Eigen::SparseMatrix &A) { for (size_t i = 0; i != Matrices.size(); ++i) { Matrices[i] = A * Matrices[i]; } } protected: std::vector> Matrices; }; class DiagonalMatrixGroup { public: DiagonalMatrixGroup(size_t Q, size_t const dim) { Matrices.resize(Q); for (size_t i = 0; i != Matrices.size(); ++i) { Matrices[i].resize(dim); } } auto &operator()(size_t const q) const { return Matrices[q]; }; auto &operator()(size_t const q) { return Matrices[q]; }; protected: std::vector Matrices; }; class DerivativeMatrixGroup { public: DerivativeMatrixGroup(size_t const Q, size_t const rows, size_t const cols, size_t const nnz) : Dx{Q, rows, cols, nnz}, Dy{Q, rows, cols, nnz} {}; auto const &dx(size_t const q) const { return Dx[q]; }; auto const &dy(size_t const q) const { return Dy[q]; }; auto &dx(size_t const q, size_t const i, size_t const j) { return Dx(q, i, j); }; auto &dy(size_t const q, size_t const i, size_t const j) { return Dy(q, i, j); }; void transform(Eigen::SparseMatrix &A) { Dx.transform(A); Dy.transform(A); } protected: SparseMatrixGroup Dx; SparseMatrixGroup Dy; }; #endif //OERSTED_MATRIXGROUP_H