28 init(other, copy_main_cache_ptr);
45 size_ = rows == cols ? rows : 0;
46 tmp_.resize(rows, cols);
47 mat_.resize(rows, cols);
53 assert(
this != &other);
61 assert(
this != &other);
62 if (copy_main_cache_ptr)
123 tmp_.makeCompressed();
127 tmp_.data().squeeze();
128 mat_.makeCompressed();
132 mat_.makeCompressed();
143 if (compute_mapping &&
size_ > 0)
153 const auto inn_ptr =
mat_.innerIndexPtr();
154 const auto out_ptr =
mat_.outerIndexPtr();
160 for (
size_t i = 0; i <
mat_.cols(); ++i)
166 for (
size_t ii = start; ii < end; ++ii)
171 map.emplace_back(i, index);
176 logger().trace(
"Cache computed");
186 const int i = p.first;
187 const int j = p.second;
190 const auto &map =
mapping()[i];
194 for (
const auto &p : map)
199 assert(p.second <
values_.size());
213 logger().trace(
"Second cache computed");
223 assert(
mat_.isCompressed());
225 assert(outer_index.size() ==
size_ + 1);
226 assert(inner_index.size() ==
values_.size());
228 std::copy(outer_index.begin(), outer_index.end(),
mat_.outerIndexPtr());
231 std::copy(inner_index.begin(), inner_index.end(),
mat_.innerIndexPtr());
250 std::shared_ptr<SparseMatrixCache> out = std::make_shared<SparseMatrixCache>(a);
258 out->second_cache_entries_.resize(std::max(this_e_size, a_e_size));
259 for (
int e = 0; e < std::min(this_e_size, a_e_size); ++e)
266 for (
int e = std::min(this_e_size, a_e_size); e < std::max(this_e_size, a_e_size); ++e)
280 assert(ainner_index.size() == inner_index.size());
281 assert(aouter_index.size() == outer_index.size());
285 for (int i = start; i < end; ++i)
287 out->values_[i] = a.values_[i] + values_[i];
311 for (
int e = 0; e < o_e_size; ++e)
323 assert(inner_index.size() == oinner_index.size());
324 assert(outer_index.size() == oouter_index.size());
328 for (int i = start; i < end; ++i)
330 values_[i] += o.values_[i];
340 mat_.setZero(size, size);
345 mat_.setZero(rows, cols);
360 mat_.setZero(size, size);
365 mat_.setZero(rows, cols);
392 return mat_.sparseView();
402 std::shared_ptr<DenseMatrixCache> out = std::make_shared<DenseMatrixCache>(a);
std::shared_ptr< MatrixCache > operator+(const MatrixCache &a) const override
void init(const size_t size) override
StiffnessMatrix get_matrix(const bool compute_mapping=true) override
void add_value(const int e, const int i, const int j, const double value) override
void operator+=(const MatrixCache &o) override
abstract class used for caching
void operator+=(const MatrixCache &o) override
void add_value(const int e, const int i, const int j, const double value) override
e = element_index, i = global row_index, j = global column_index, value = value to add to matrix if t...
void set_zero() override
set matrix values to zero modifies tmp_, mat_, and values (setting all to zero)
std::vector< int > outer_index_
saves inner/outer indices for sparse matrix
void prune() override
if caches have yet to be constructed, add the saved triplets to mat_ modifies tmp_ and mat_,...
const SparseMatrixCache * main_cache_
std::shared_ptr< MatrixCache > operator+(const MatrixCache &a) const override
const std::vector< std::vector< std::pair< int, size_t > > > & mapping() const
std::vector< std::vector< std::pair< int, int > > > second_cache_entries_
maps element indices to global matrix indices
const SparseMatrixCache * main_cache() const
std::vector< double > values_
buffer for values (corresponds to inner/outer_index_ structure for sparse matrix)
const std::vector< std::vector< int > > & second_cache() const
std::vector< Eigen::Triplet< double > > entries_
contains global matrix indices and corresponding value
std::vector< int > inner_index_
StiffnessMatrix get_matrix(const bool compute_mapping=true) override
if the cache is yet to be constructed, save the cached (ordered) indices in inner_index_ and outer_in...
void init(const size_t size) override
set matrix to be size x size
std::vector< std::vector< int > > second_cache_
maps element index to local index
std::vector< std::vector< std::pair< int, size_t > > > mapping_
maps row indices to column index/local index pairs
void maybe_parallel_for(int size, const std::function< void(int, int, int)> &partial_for)
spdlog::logger & logger()
Retrieves the current logger.
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix