29 #include "algebraCore.h"
71 assert(it !=
indices.end() && *it == j);
81 for (
size_t i = 0; i < shape.size(); ++i)
83 const std::set<int>& row_shape = shape[i];
85 row.
indices.reserve(row_shape.size());
86 for (
auto it = row_shape.begin(); it != row_shape.end(); ++it)
88 row.
values.resize(row_shape.size());
96 for (
double& value: row.values)
103 void set(
int i,
int j,
double val)
105 assert(i >= 0 && i <
rows.size());
106 assert(j >= 0 && j <
rows.size());
114 void add(
int i,
int j,
double val)
116 assert(i >= 0 && i <
rows.size());
117 assert(j >= 0 && j <
rows.size());
119 std::mutex& mutex = row.
mutex;
120 double& value = row[j];
127 void print(std::ostream & flux = std::cout)
const
133 for (
size_t k = 0; k < row.indices.size(); ++k)
135 flux << row.indices[k] <<
": " << row.values[k];
136 flux << (k < row.indices.size()-1 ?
", " :
"\n");
146 assert(i >= 0 && i <
rows.size());
147 assert(j >= 0 && j <
rows.size());
149 auto it = std::lower_bound(row.
indices.begin(), row.
indices.end(), j);
150 if (it == row.
indices.end() || *it != j)
152 int k = it - row.
indices.begin();
157 template <
typename T>
158 void mult(std::vector<T>
const& X, std::vector<T> &Y)
160 assert(X.size() ==
rows.size());
161 assert(Y.size() ==
rows.size());
162 std::transform(EXEC_POL,
rows.begin(),
rows.end(), Y.begin(),
166 for (size_t k = 0; k < row.indices.size(); ++k)
167 val += row.values[k] * X[row.indices[k]];
173 template <
typename T>
176 assert(
D.size() ==
rows.size());
177 for (
size_t i = 0; i <
rows.size(); ++i)
179 const double c = (*this)(i,i);
190 std::vector<SparseVector>
rows;
Square sparse matrix.
Definition: sparseMat.h:46
void build_diag_precond(std::vector< T > &D) const
Definition: sparseMat.h:174
void clear()
Definition: sparseMat.h:93
void set(int i, int j, double val)
Definition: sparseMat.h:103
void mult(std::vector< T > const &X, std::vector< T > &Y)
Definition: sparseMat.h:158
std::vector< SparseVector > rows
Definition: sparseMat.h:190
void add(int i, int j, double val)
Definition: sparseMat.h:114
void print(std::ostream &flux=std::cout) const
Definition: sparseMat.h:127
SparseMatrix(const MatrixShape &shape)
Definition: sparseMat.h:79
double operator()(const int i, const int j) const
Definition: sparseMat.h:144
constexpr double D
Definition: tetra.h:54
std::vector< std::set< int > > MatrixShape
Definition: sparseMat.h:38
Definition: sparseMat.h:60
double & operator[](int j)
Definition: sparseMat.h:68
std::vector< int > indices
Definition: sparseMat.h:62
std::mutex mutex
Definition: sparseMat.h:61
std::vector< double > values
Definition: sparseMat.h:63