33 #include "algebraCore.h"
70 void insert(
const int i,
const int j,
const double val)
72 assert(i >= 0 && i <
rows.size());
73 assert(j >= 0 && j <
rows.size());
79 std::vector<SparseVector>
rows;
114 assert(it !=
indices.end() && *it == j);
124 for (
size_t i = 0; i < source.
rows.size(); ++i)
128 row.
indices.reserve(source_row.size());
129 row.
values.reserve(source_row.size());
130 for (
auto it = source_row.begin(); it != source_row.end(); ++it)
132 row.
indices.push_back(it->first);
133 row.
values.push_back(it->second);
141 for (
size_t i = 0; i < shape.size(); ++i)
143 const std::set<int>& row_shape = shape[i];
145 row.
indices.reserve(row_shape.size());
146 for (
auto it = row_shape.begin(); it != row_shape.end(); ++it)
148 row.
values.resize(row_shape.size());
156 for (
double& value: row.values)
163 void set(
int i,
int j,
double val)
165 assert(i >= 0 && i <
rows.size());
166 assert(j >= 0 && j <
rows.size());
174 void add(
int i,
int j,
double val)
176 assert(i >= 0 && i <
rows.size());
177 assert(j >= 0 && j <
rows.size());
179 std::mutex& mutex = row.
mutex;
180 double& value = row[j];
187 void print(std::ostream & flux = std::cout)
const
193 for (
size_t k = 0; k < row.indices.size(); ++k)
195 flux << row.indices[k] <<
": " << row.values[k];
196 flux << (k < row.indices.size()-1 ?
", " :
"\n");
206 assert(i >= 0 && i <
rows.size());
207 assert(j >= 0 && j <
rows.size());
209 auto it = std::lower_bound(row.
indices.begin(), row.
indices.end(), j);
210 if (it == row.
indices.end() || *it != j)
212 int k = it - row.
indices.begin();
217 template <
typename T>
218 void mult(std::vector<T>
const& X, std::vector<T> &Y)
220 assert(X.size() ==
rows.size());
221 assert(Y.size() ==
rows.size());
222 std::transform(EXEC_POL,
rows.begin(),
rows.end(), Y.begin(),
226 for (size_t k = 0; k < row.indices.size(); ++k)
227 val += row.values[k] * X[row.indices[k]];
233 template <
typename T>
236 assert(
D.size() ==
rows.size());
237 for (
size_t i = 0; i <
rows.size(); ++i)
239 const double c = (*this)(i,i);
250 std::vector<SparseVector>
rows;
Read-mode square sparse matrix.
Definition: sparseMat.h:89
r_sparseMat(const MatrixShape &shape)
Definition: sparseMat.h:139
void mult(std::vector< T > const &X, std::vector< T > &Y)
Definition: sparseMat.h:218
std::vector< SparseVector > rows
Definition: sparseMat.h:250
void build_diag_precond(std::vector< T > &D) const
Definition: sparseMat.h:234
void clear()
Definition: sparseMat.h:153
r_sparseMat(const w_sparseMat &source)
Definition: sparseMat.h:122
void print(std::ostream &flux=std::cout) const
Definition: sparseMat.h:187
double operator()(const int i, const int j) const
Definition: sparseMat.h:204
void add(int i, int j, double val)
Definition: sparseMat.h:174
void set(int i, int j, double val)
Definition: sparseMat.h:163
Write-mode sparse matrix.
Definition: sparseMat.h:52
w_sparseMat(int N)
Definition: sparseMat.h:62
void insert(const int i, const int j, const double val)
Definition: sparseMat.h:70
std::map< int, double > SparseVector
Definition: sparseMat.h:58
std::vector< SparseVector > rows
Definition: sparseMat.h:79
const int N
Definition: facette.h:17
constexpr double D
Definition: tetra.h:32
std::vector< std::set< int > > MatrixShape
Definition: sparseMat.h:42
Definition: sparseMat.h:103
std::vector< double > values
Definition: sparseMat.h:106
double & operator[](int j)
Definition: sparseMat.h:111
std::vector< int > indices
Definition: sparseMat.h:105
std::mutex mutex
Definition: sparseMat.h:104